60
void OxideQQuickWebViewPrivate::contextInitialized() {
61
completeConstruction();
64
void OxideQQuickWebViewPrivate::contextWillBeDestroyed() {
65
Q_Q(OxideQQuickWebView);
67
// XXX: Our underlying BrowserContext lives on, so we're left in a
68
// bit of a weird state here (WebView.context will return no context,
71
emit q->contextChanged();
74
void OxideQQuickWebViewPrivate::detachContextSignals() {
75
Q_Q(OxideQQuickWebView);
78
QObject::disconnect(OxideQQuickWebContextPrivate::get(context),
79
SIGNAL(initialized()),
80
q, SLOT(contextInitialized()));
81
QObject::disconnect(OxideQQuickWebContextPrivate::get(context),
82
SIGNAL(willBeDestroyed()),
83
q, SLOT(contextWillBeDestroyed()));
87
62
OxideQQuickWebViewPrivate::OxideQQuickWebViewPrivate(
88
63
OxideQQuickWebView* view) :
89
64
oxide::qt::WebViewAdapter(view),
91
navigationHistory(view),
96
before_unload_dialog(NULL),
97
init_props_(new InitData()),
100
OxideQQuickWebViewPrivate::~OxideQQuickWebViewPrivate() {
103
oxide::qt::RenderWidgetHostViewDelegate*
104
OxideQQuickWebViewPrivate::CreateRenderWidgetHostViewDelegate() {
105
Q_Q(OxideQQuickWebView);
107
return new oxide::qquick::RenderViewItem(q);
67
navigation_history_(view),
70
confirm_dialog_(NULL),
72
before_unload_dialog_(NULL),
110
75
oxide::qt::WebPopupMenuDelegate*
111
76
OxideQQuickWebViewPrivate::CreateWebPopupMenuDelegate() {
138
103
return new oxide::qquick::BeforeUnloadDialogDelegate(q);
106
oxide::qt::FilePickerDelegate*
107
OxideQQuickWebViewPrivate::CreateFilePickerDelegate() {
108
Q_Q(OxideQQuickWebView);
110
return new oxide::qquick::FilePickerDelegate(q);
113
void OxideQQuickWebViewPrivate::OnInitialized(
115
oxide::qt::WebContextAdapter* orig_context) {
116
Q_Q(OxideQQuickWebView);
118
// Make the webview the QObject parent of the new root frame,
119
// to stop Qml from collecting the frame tree
120
q->rootFrame()->setParent(q);
122
// Initialization created the root frame. This is the only time
124
emit q->rootFrameChanged();
126
if (orig_incognito != incognito()) {
127
emit q->incognitoChanged();
129
if (orig_context != context()) {
130
detachContextSignals(static_cast<OxideQQuickWebContextPrivate *>(orig_context));
131
attachContextSignals(static_cast<OxideQQuickWebContextPrivate *>(context()));
133
emit q->contextChanged();
141
137
void OxideQQuickWebViewPrivate::URLChanged() {
142
138
Q_Q(OxideQQuickWebView);
169
165
emit q->loadingChanged(event);
168
void OxideQQuickWebViewPrivate::AddMessageToConsole(
170
const QString& message,
172
const QString& source_id) {
173
Q_Q(OxideQQuickWebView);
175
OxideQQuickWebView::LogMessageSeverityLevel oxideLevel =
176
OxideQQuickWebView::LogSeverityInfo;
177
if (level >= 0 && level <= OxideQQuickWebView::LogSeverityFatal) {
178
oxideLevel = static_cast<OxideQQuickWebView::LogMessageSeverityLevel>(level);
180
emit q->javaScriptConsoleMessage(
172
187
void OxideQQuickWebViewPrivate::NavigationEntryCommitted() {
173
navigationHistory.onNavigationEntryCommitted();
188
navigation_history_.onNavigationEntryCommitted();
176
191
void OxideQQuickWebViewPrivate::NavigationListPruned(bool from_front, int count) {
177
navigationHistory.onNavigationListPruned(from_front, count);
192
navigation_history_.onNavigationListPruned(from_front, count);
180
195
void OxideQQuickWebViewPrivate::NavigationEntryChanged(int index) {
181
navigationHistory.onNavigationEntryChanged(index);
196
navigation_history_.onNavigationEntryChanged(index);
184
199
oxide::qt::WebFrameAdapter* OxideQQuickWebViewPrivate::CreateWebFrame() {
220
241
emit q->frameRemoved(adapterToQObject<OxideQQuickWebFrame>(frame));
244
bool OxideQQuickWebViewPrivate::CanCreateWindows() const {
245
Q_Q(const OxideQQuickWebView);
247
static const QMetaMethod signal =
248
QMetaMethod::fromSignal(&OxideQQuickWebView::newViewRequested);
249
return q->isSignalConnected(signal);
252
void OxideQQuickWebViewPrivate::NavigationRequested(
253
OxideQNavigationRequest* request) {
254
Q_Q(OxideQQuickWebView);
256
emit q->navigationRequested(request);
259
void OxideQQuickWebViewPrivate::NewViewRequested(
260
OxideQNewViewRequest* request) {
261
Q_Q(OxideQQuickWebView);
263
emit q->newViewRequested(request);
223
266
void OxideQQuickWebViewPrivate::completeConstruction() {
224
267
Q_Q(OxideQQuickWebView);
226
Q_ASSERT(init_props_);
228
OxideQQuickWebContext* context_in_use = context;
229
if (!context_in_use) {
230
// The default context is reference counted and not exposed to the
232
default_context_ = OxideQQuickWebContext::defaultContext();
233
context_in_use = default_context_.data();
270
OxideQQuickWebContext* c = OxideQQuickWebContext::defaultContext(true);
271
setContext(OxideQQuickWebContextPrivate::get(c));
236
init(OxideQQuickWebContextPrivate::get(context_in_use),
237
QSizeF(q->width(), q->height()).toSize(),
238
init_props_->incognito,
244
// Make the webview the QObject parent of the new root frame,
245
// to stop Qml from collecting the frame tree
246
q->rootFrame()->setParent(q);
248
// Initialization created the root frame. This is the only time
250
emit q->rootFrameChanged();
329
void OxideQQuickWebViewPrivate::contextConstructed() {
331
completeConstruction();
335
void OxideQQuickWebViewPrivate::contextWillBeDestroyed() {
336
Q_Q(OxideQQuickWebView);
338
// XXX: Our underlying BrowserContext lives on, so we're left in a
339
// bit of a weird state here (WebView.context will return no context,
341
emit q->contextChanged();
344
void OxideQQuickWebViewPrivate::attachContextSignals(
345
OxideQQuickWebContextPrivate* context) {
346
Q_Q(OxideQQuickWebView);
352
QObject::connect(context, SIGNAL(willBeDestroyed()),
353
q, SLOT(contextWillBeDestroyed()));
354
QObject::connect(context, SIGNAL(constructed()),
355
q, SLOT(contextConstructed()));
358
void OxideQQuickWebViewPrivate::detachContextSignals(
359
OxideQQuickWebContextPrivate* context) {
360
Q_Q(OxideQQuickWebView);
366
QObject::disconnect(context, SIGNAL(constructed()),
367
q, SLOT(contextConstructed()));
368
QObject::disconnect(context, SIGNAL(willBeDestroyed()),
369
q, SLOT(contextWillBeDestroyed()));
372
OxideQQuickWebViewPrivate::~OxideQQuickWebViewPrivate() {}
306
375
OxideQQuickWebViewPrivate* OxideQQuickWebViewPrivate::get(
307
376
OxideQQuickWebView* view) {
345
419
// else we'll crash
346
420
OxideQQuickWebContextPrivate::ensureChromiumStarted();
347
421
d_ptr.reset(new OxideQQuickWebViewPrivate(this));
348
QObject::connect(this, SIGNAL(visibleChanged()),
349
this, SLOT(visibilityChangedListener()));
352
424
OxideQQuickWebView::~OxideQQuickWebView() {
353
425
Q_D(OxideQQuickWebView);
355
disconnect(this, SIGNAL(visibleChanged()),
356
this, SLOT(visibilityChangedListener()));
357
d->detachContextSignals();
427
d->detachContextSignals(
428
static_cast<OxideQQuickWebContextPrivate *>(d->context()));
359
430
// Do this before our d_ptr is cleared, as these call back in to us
360
431
// when they are deleted
512
576
QQmlComponent* OxideQQuickWebView::popupMenu() const {
513
577
Q_D(const OxideQQuickWebView);
515
return d->popup_menu;
579
return d->popup_menu_;
518
582
void OxideQQuickWebView::setPopupMenu(QQmlComponent* popup_menu) {
519
583
Q_D(OxideQQuickWebView);
521
if (d->popup_menu == popup_menu) {
585
if (d->popup_menu_ == popup_menu) {
525
d->popup_menu = popup_menu;
589
d->popup_menu_ = popup_menu;
526
590
emit popupMenuChanged();
529
593
QQmlComponent* OxideQQuickWebView::alertDialog() const {
530
594
Q_D(const OxideQQuickWebView);
532
return d->alert_dialog;
596
return d->alert_dialog_;
535
599
void OxideQQuickWebView::setAlertDialog(QQmlComponent* alert_dialog) {
536
600
Q_D(OxideQQuickWebView);
538
if (d->alert_dialog == alert_dialog) {
602
if (d->alert_dialog_ == alert_dialog) {
542
d->alert_dialog = alert_dialog;
606
d->alert_dialog_ = alert_dialog;
543
607
emit alertDialogChanged();
546
610
QQmlComponent* OxideQQuickWebView::confirmDialog() const {
547
611
Q_D(const OxideQQuickWebView);
549
return d->confirm_dialog;
613
return d->confirm_dialog_;
552
616
void OxideQQuickWebView::setConfirmDialog(QQmlComponent* confirm_dialog) {
553
617
Q_D(OxideQQuickWebView);
555
if (d->confirm_dialog == confirm_dialog) {
619
if (d->confirm_dialog_ == confirm_dialog) {
559
d->confirm_dialog = confirm_dialog;
623
d->confirm_dialog_ = confirm_dialog;
560
624
emit confirmDialogChanged();
563
627
QQmlComponent* OxideQQuickWebView::promptDialog() const {
564
628
Q_D(const OxideQQuickWebView);
566
return d->prompt_dialog;
630
return d->prompt_dialog_;
569
633
void OxideQQuickWebView::setPromptDialog(QQmlComponent* prompt_dialog) {
570
634
Q_D(OxideQQuickWebView);
572
if (d->prompt_dialog == prompt_dialog) {
636
if (d->prompt_dialog_ == prompt_dialog) {
576
d->prompt_dialog = prompt_dialog;
640
d->prompt_dialog_ = prompt_dialog;
577
641
emit promptDialogChanged();
580
644
QQmlComponent* OxideQQuickWebView::beforeUnloadDialog() const {
581
645
Q_D(const OxideQQuickWebView);
583
return d->before_unload_dialog;
647
return d->before_unload_dialog_;
586
650
void OxideQQuickWebView::setBeforeUnloadDialog(
587
651
QQmlComponent* before_unload_dialog) {
588
652
Q_D(OxideQQuickWebView);
590
if (d->before_unload_dialog == before_unload_dialog) {
654
if (d->before_unload_dialog_ == before_unload_dialog) {
594
d->before_unload_dialog = before_unload_dialog;
658
d->before_unload_dialog_ = before_unload_dialog;
595
659
emit beforeUnloadDialogChanged();
662
QQmlComponent* OxideQQuickWebView::filePicker() const {
663
Q_D(const OxideQQuickWebView);
665
return d->file_picker_;
668
void OxideQQuickWebView::setFilePicker(QQmlComponent* file_picker) {
669
Q_D(OxideQQuickWebView);
671
if (d->file_picker_ == file_picker) {
675
d->file_picker_ = file_picker;
676
emit filePickerChanged();
598
679
OxideQQuickWebContext* OxideQQuickWebView::context() const {
599
680
Q_D(const OxideQQuickWebView);
682
OxideQQuickWebContext* c =
683
adapterToQObject<OxideQQuickWebContext>(d->context());
684
if (c == OxideQQuickWebContext::defaultContext(false)) {
604
691
void OxideQQuickWebView::setContext(OxideQQuickWebContext* context) {
605
692
Q_D(OxideQQuickWebView);
607
if (!d->init_props()) {
608
qWarning() << "The context can only be set at construction time";
612
if (context == d->context) {
616
d->detachContextSignals();
694
if (d->isInitialized()) {
695
qWarning() << "WebView context must be set during construction";
699
if (context == OxideQQuickWebContext::defaultContext(false)) {
701
"Setting WebView context to default context is unnecessary. WebView "
702
"will automatically use the default context if it is created without "
707
oxide::qt::WebContextAdapter* old = d->context();
708
if (context == adapterToQObject<OxideQQuickWebContext>(old)) {
711
d->detachContextSignals(static_cast<OxideQQuickWebContextPrivate *>(old));
713
OxideQQuickWebContextPrivate* cd = NULL;
618
connect(OxideQQuickWebContextPrivate::get(context), SIGNAL(willBeDestroyed()),
619
this, SLOT(contextWillBeDestroyed()));
715
cd = OxideQQuickWebContextPrivate::get(context);
717
d->attachContextSignals(cd);
622
d->context = context;
623
720
emit contextChanged();