~osomon/oxide/i18n

« back to all changes in this revision

Viewing changes to qt/core/glue/oxide_qt_web_view_adapter.cc

  • Committer: Olivier Tilloy
  • Date: 2014-04-08 10:03:11 UTC
  • mfrom: (312.2.173 oxide)
  • Revision ID: olivier.tilloy@canonical.com-20140408100311-b3zb7q1jfrevbrf1
Merge the latest changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "oxide_qt_web_view_adapter.h"
19
19
 
 
20
#include <QtDebug>
 
21
 
20
22
#include "base/logging.h"
21
23
#include "ui/gfx/size.h"
22
24
#include "url/gurl.h"
23
25
 
 
26
#include "qt/core/api/oxideqnewviewrequest_p.h"
24
27
#include "qt/core/api/oxideqwebpreferences.h"
25
28
#include "qt/core/api/oxideqwebpreferences_p.h"
26
29
#include "qt/core/browser/oxide_qt_web_frame.h"
27
 
#include "qt/core/glue/private/oxide_qt_web_view_adapter_p.h"
 
30
#include "qt/core/browser/oxide_qt_web_view.h"
28
31
 
29
32
#include "oxide_qt_web_context_adapter_p.h"
30
33
#include "oxide_qt_web_frame_adapter.h"
32
35
namespace oxide {
33
36
namespace qt {
34
37
 
 
38
void WebViewAdapter::Initialized() {
 
39
  DCHECK(isInitialized());
 
40
 
 
41
  OnInitialized(construct_props_->incognito,
 
42
                construct_props_->context);
 
43
  construct_props_.reset();
 
44
}
 
45
 
 
46
void WebViewAdapter::WebPreferencesChanged() {
 
47
  if (!priv->GetWebPreferences()) {
 
48
    setPreferences(new OxideQWebPreferences(adapterToQObject(this)));
 
49
  } else if (isInitialized()) {
 
50
    OnWebPreferencesChanged();
 
51
  }
 
52
}
 
53
 
35
54
WebViewAdapter::WebViewAdapter(QObject* q) :
36
55
    AdapterBase(q),
37
 
    priv(WebViewAdapterPrivate::Create(this)) {
 
56
    priv(WebView::Create(this)),
 
57
    construct_props_(new ConstructProperties()),
 
58
    created_with_new_view_request_(false) {
38
59
  setPreferences(new OxideQWebPreferences(adapterToQObject(this)));
39
60
}
40
61
 
41
62
WebViewAdapter::~WebViewAdapter() {}
42
63
 
43
 
void WebViewAdapter::init(WebContextAdapter* context,
44
 
                          const QSize& initial_size,
45
 
                          bool incognito,
46
 
                          const QUrl& initial_url,
47
 
                          bool visible) {
48
 
  if (!priv->Init(
49
 
          WebContextAdapterPrivate::get(context)->context(),
50
 
          incognito,
51
 
          gfx::Size(initial_size.width(), initial_size.height()))) {
52
 
    return;
53
 
  }
54
 
 
55
 
  if (!initial_url.isEmpty()) {
56
 
    priv->SetURL(GURL(initial_url.toString().toStdString()));
57
 
  }
58
 
 
59
 
  updateVisibility(visible);
 
64
void WebViewAdapter::init() {
 
65
  if (created_with_new_view_request_ || isInitialized()) {
 
66
    return;
 
67
  }
 
68
 
 
69
  // construct_props_ is deleted in Initialized()
 
70
  QUrl url = construct_props_->url;
 
71
 
 
72
  oxide::WebView::Params params;
 
73
  params.context =
 
74
      WebContextAdapterPrivate::get(construct_props_->context)->GetContext();
 
75
  params.incognito = construct_props_->incognito;
 
76
  if (!priv->Init(params)) {
 
77
    return;
 
78
  }
 
79
 
 
80
  if (!url.isEmpty()) {
 
81
    priv->SetURL(GURL(url.toString().toStdString()));
 
82
  }
 
83
 
60
84
}
61
85
 
62
86
QUrl WebViewAdapter::url() const {
 
87
  if (construct_props_) {
 
88
    return construct_props_->url;
 
89
  }
 
90
 
63
91
  return QUrl(QString::fromStdString(priv->GetURL().spec()));
64
92
}
65
93
 
66
94
void WebViewAdapter::setUrl(const QUrl& url) {
67
 
  priv->SetURL(GURL(url.toString().toStdString()));
 
95
  if (construct_props_) {
 
96
    construct_props_->url = url;
 
97
  } else {
 
98
    priv->SetURL(GURL(url.toString().toStdString()));
 
99
  }
68
100
}
69
101
 
70
102
QString WebViewAdapter::title() const {
80
112
}
81
113
 
82
114
bool WebViewAdapter::incognito() const {
83
 
  return priv->IsIncognito();
 
115
  if (construct_props_) {
 
116
    return construct_props_->incognito;
 
117
  }
 
118
 
 
119
  return priv->IsIncognito();  
 
120
}
 
121
 
 
122
void WebViewAdapter::setIncognito(bool incognito) {
 
123
  if (!construct_props_) {
 
124
    qWarning() << "Cannot change incognito mode after WebView is initialized";
 
125
    return;
 
126
  }
 
127
 
 
128
  construct_props_->incognito = incognito;
84
129
}
85
130
 
86
131
bool WebViewAdapter::loading() const {
93
138
    return NULL;
94
139
  }
95
140
 
96
 
  return frame->GetAdapter();
 
141
  return frame->adapter();
 
142
}
 
143
 
 
144
WebContextAdapter* WebViewAdapter::context() const {
 
145
  if (construct_props_) {
 
146
    return construct_props_->context;
 
147
  }
 
148
 
 
149
  WebContextAdapterPrivate* context =
 
150
      WebContextAdapterPrivate::FromBrowserContext(priv->GetBrowserContext());
 
151
  if (!context) {
 
152
    return NULL;
 
153
  }
 
154
 
 
155
  return context->adapter();
 
156
}
 
157
 
 
158
void WebViewAdapter::setContext(WebContextAdapter* context) {
 
159
  DCHECK(construct_props_);
 
160
  construct_props_->context = context;
97
161
}
98
162
 
99
163
void WebViewAdapter::updateSize(const QSize& size) {
101
165
}
102
166
 
103
167
void WebViewAdapter::updateVisibility(bool visible) {
104
 
  if (visible) {
105
 
    priv->Shown();
106
 
  } else {
107
 
    priv->Hidden();
108
 
  }
 
168
  priv->UpdateVisibility(visible);
109
169
}
110
170
 
111
171
void WebViewAdapter::goBack() {
189
249
  }
190
250
}
191
251
 
192
 
void WebViewAdapter::WebPreferencesChanged() {
193
 
  if (!priv->GetWebPreferences()) {
194
 
    setPreferences(new OxideQWebPreferences(adapterToQObject(this)));
195
 
  } else if (isInitialized()) {
196
 
    OnWebPreferencesChanged();
197
 
  }
 
252
void WebViewAdapter::setRequest(OxideQNewViewRequest* request) {
 
253
  if (isInitialized()) {
 
254
    qWarning() << "Cannot assign NewViewRequest to an already constructed WebView";
 
255
    return;
 
256
  }
 
257
 
 
258
  if (created_with_new_view_request_) {
 
259
    return;
 
260
  }
 
261
 
 
262
  OxideQNewViewRequestPrivate* rd = OxideQNewViewRequestPrivate::get(request);
 
263
  if (rd->view) {
 
264
    qWarning() << "Cannot assign NewViewRequest to more than one WebView";
 
265
    return;
 
266
  }
 
267
 
 
268
  rd->view = priv->AsWeakPtr();
 
269
  created_with_new_view_request_ = true;
198
270
}
199
271
 
200
272
} // namespace qt