summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_adapter.cpp
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-02-26 12:48:03 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-04-06 06:36:24 +0000
commit3bc5b9d4f9d481707c02e83e0cd20f60dec425f2 (patch)
treef29ba0036095fcf178133281be582d5fe650814b /src/core/web_contents_adapter.cpp
parentfbfc9ee7f06c6f36b79145bc7e8ba05c5d3fa621 (diff)
Avoid creating temporary blank WebContents
- Avoid creating a blank WebContents for new QWebEnginePages only to replace it with a different blank WebContents moments later. This problem is already solved in QQuickWebEngineView by lazy initialization, therefore the patch moves this lazy initialization into WebContentsAdapter itself so that it can be applied to both QQuickWebEngineView and QWebEnginePage. - Try to delay WebContents creation until the first navigation so that we have enough information available to pick the right initial SiteInstance when calling WebContents::Create. This is done by triggering WebContents creation from the first call to a WebContentsAdapter::load* method. - Use the SiteInstance from WebContentsDelegate::OpenURLFromTab. This method gets a SiteInstance pointer which we should give to WebContents::Create. Task-number: QTBUG-65561 Task-number: QTBUG-67163 Change-Id: Id7b351998adefb810cf27c61a1447b61d7f4c606 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r--src/core/web_contents_adapter.cpp160
1 files changed, 140 insertions, 20 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 26ae9e3c5..95bdaba53 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -104,6 +104,10 @@
namespace QtWebEngineCore {
+#define CHECK_INITIALIZED(return_value) \
+ if (!isInitialized()) \
+ return return_value
+
#define CHECK_VALID_RENDER_WIDGET_HOST_VIEW(render_view_host) \
if (!render_view_host->IsRenderViewLive() && render_view_host->GetWidget()->GetView()) { \
qWarning("Ignore navigation due to terminated render process with invalid RenderWidgetHostView."); \
@@ -406,21 +410,39 @@ WebContentsAdapter::~WebContentsAdapter()
{
}
-void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient)
+void WebContentsAdapter::setClient(WebContentsAdapterClient *adapterClient)
{
Q_D(WebContentsAdapter);
+ Q_ASSERT(!isInitialized());
d->adapterClient = adapterClient;
// We keep a reference to browserContextAdapter to keep it alive as long as we use it.
// This is needed in case the QML WebEngineProfile is garbage collected before the WebEnginePage.
d->browserContextAdapter = adapterClient->browserContextAdapter();
Q_ASSERT(d->browserContextAdapter);
- // Create our own if a WebContents wasn't provided at construction.
- if (!d->webContents)
- d->webContents.reset(createBlankWebContents(adapterClient, d->browserContextAdapter->browserContext()));
-
// This might replace any adapter that has been initialized with this WebEngineSettings.
adapterClient->webEngineSettings()->setWebContentsAdapter(this);
+}
+
+bool WebContentsAdapter::isInitialized() const
+{
+ Q_D(const WebContentsAdapter);
+ return bool(d->webContentsDelegate);
+}
+
+void WebContentsAdapter::initialize(content::SiteInstance *site)
+{
+ Q_D(WebContentsAdapter);
+ Q_ASSERT(d->adapterClient);
+ Q_ASSERT(!isInitialized());
+
+ // Create our own if a WebContents wasn't provided at construction.
+ if (!d->webContents) {
+ content::WebContents::CreateParams create_params(d->browserContextAdapter->browserContext(), site);
+ create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight);
+ create_params.context = reinterpret_cast<gfx::NativeView>(d->adapterClient);
+ d->webContents.reset(content::WebContents::Create(create_params));
+ }
content::RendererPreferences* rendererPrefs = d->webContents->GetMutableRendererPrefs();
rendererPrefs->use_custom_colors = true;
@@ -434,7 +456,7 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient)
if (commandLine->HasSwitch(switches::kForceWebRtcIPHandlingPolicy))
rendererPrefs->webrtc_ip_handling_policy = commandLine->GetSwitchValueASCII(switches::kForceWebRtcIPHandlingPolicy);
else
- rendererPrefs->webrtc_ip_handling_policy = adapterClient->webEngineSettings()->testAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly)
+ rendererPrefs->webrtc_ip_handling_policy = d->adapterClient->webEngineSettings()->testAttribute(WebEngineSettings::WebRTCPublicInterfacesOnly)
? content::kWebRTCIPHandlingDefaultPublicInterfaceOnly
: content::kWebRTCIPHandlingDefault;
#endif
@@ -450,12 +472,12 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient)
d->webContents->GetRenderViewHost()->SyncRendererPrefs();
// Create and attach observers to the WebContents.
- d->webContentsDelegate.reset(new WebContentsDelegateQt(d->webContents.get(), adapterClient));
- d->renderViewObserverHost.reset(new RenderViewObserverHostQt(d->webContents.get(), adapterClient));
+ d->webContentsDelegate.reset(new WebContentsDelegateQt(d->webContents.get(), d->adapterClient));
+ d->renderViewObserverHost.reset(new RenderViewObserverHostQt(d->webContents.get(), d->adapterClient));
// Let the WebContent's view know about the WebContentsAdapterClient.
WebContentsViewQt* contentsView = static_cast<WebContentsViewQt*>(static_cast<content::WebContentsImpl*>(d->webContents.get())->GetView());
- contentsView->initialize(adapterClient);
+ contentsView->initialize(d->adapterClient);
// This should only be necessary after having restored the history to a new WebContentsAdapter.
d->webContents->GetController().LoadIfNecessary();
@@ -475,11 +497,14 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient)
Q_ASSERT(rvh);
if (!rvh->IsRenderViewLive())
static_cast<content::WebContentsImpl*>(d->webContents.get())->CreateRenderViewForRenderManager(rvh, MSG_ROUTING_NONE, MSG_ROUTING_NONE, base::UnguessableToken::Create(), content::FrameReplicationState());
+
+ d->adapterClient->initializationFinished();
}
void WebContentsAdapter::reattachRWHV()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (content::RenderWidgetHostView *rwhv = d->webContents->GetRenderWidgetHostView())
rwhv->InitAsChild(0);
}
@@ -487,18 +512,21 @@ void WebContentsAdapter::reattachRWHV()
bool WebContentsAdapter::canGoBack() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(false);
return d->webContents->GetController().CanGoBack();
}
bool WebContentsAdapter::canGoForward() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(false);
return d->webContents->GetController().CanGoForward();
}
void WebContentsAdapter::stop()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
content::NavigationController& controller = d->webContents->GetController();
int index = controller.GetPendingEntryIndex();
@@ -512,6 +540,7 @@ void WebContentsAdapter::stop()
void WebContentsAdapter::reload()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost());
d->webContents->GetController().Reload(content::ReloadType::NORMAL, /*checkRepost = */false);
focusIfNecessary();
@@ -520,11 +549,18 @@ void WebContentsAdapter::reload()
void WebContentsAdapter::reloadAndBypassCache()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost());
d->webContents->GetController().Reload(content::ReloadType::BYPASSING_CACHE, /*checkRepost = */false);
focusIfNecessary();
}
+void WebContentsAdapter::loadDefault()
+{
+ Q_ASSERT(!isInitialized());
+ initialize(nullptr);
+}
+
void WebContentsAdapter::load(const QUrl &url)
{
QWebEngineHttpRequest request(url);
@@ -534,6 +570,14 @@ void WebContentsAdapter::load(const QUrl &url)
void WebContentsAdapter::load(const QWebEngineHttpRequest &request)
{
Q_D(WebContentsAdapter);
+
+ GURL gurl = toGurl(request.url());
+ if (!isInitialized()) {
+ scoped_refptr<content::SiteInstance> site =
+ content::SiteInstance::CreateForURL(d->browserContextAdapter->browserContext(), gurl);
+ initialize(site.get());
+ }
+
CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost());
// The situation can occur when relying on the editingFinished signal in QML to set the url
@@ -549,8 +593,6 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request)
LoadRecursionGuard guard(this);
Q_UNUSED(guard);
- GURL gurl = toGurl(request.url());
-
// Add URL scheme if missing from view-source URL.
if (request.url().scheme() == content::kViewSourceScheme) {
QUrl pageUrl = QUrl(request.url().toString().remove(0,
@@ -625,6 +667,10 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request)
void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
{
Q_D(WebContentsAdapter);
+
+ if (!isInitialized())
+ loadDefault();
+
CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost());
QByteArray encodedData = data.toPercentEncoding();
@@ -655,6 +701,7 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT
void WebContentsAdapter::save(const QString &filePath, int savePageFormat)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContentsDelegate->setSavePageInfo(SavePageInfo(filePath, savePageFormat));
d->webContents->OnSavePage();
}
@@ -662,23 +709,23 @@ void WebContentsAdapter::save(const QString &filePath, int savePageFormat)
QUrl WebContentsAdapter::activeUrl() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(QUrl());
return d->webContentsDelegate->url();
}
QUrl WebContentsAdapter::requestedUrl() const
{
Q_D(const WebContentsAdapter);
- if (d->webContents) {
- content::NavigationEntry* entry = d->webContents->GetController().GetVisibleEntry();
- content::NavigationEntry* pendingEntry = d->webContents->GetController().GetPendingEntry();
+ CHECK_INITIALIZED(QUrl());
+ content::NavigationEntry* entry = d->webContents->GetController().GetVisibleEntry();
+ content::NavigationEntry* pendingEntry = d->webContents->GetController().GetPendingEntry();
- if (entry) {
- if (!entry->GetOriginalRequestURL().is_empty())
- return toQt(entry->GetOriginalRequestURL());
+ if (entry) {
+ if (!entry->GetOriginalRequestURL().is_empty())
+ return toQt(entry->GetOriginalRequestURL());
- if (pendingEntry && pendingEntry == entry)
- return toQt(entry->GetURL());
- }
+ if (pendingEntry && pendingEntry == entry)
+ return toQt(entry->GetURL());
}
return QUrl();
}
@@ -686,6 +733,7 @@ QUrl WebContentsAdapter::requestedUrl() const
QUrl WebContentsAdapter::iconUrl() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(QUrl());
if (content::NavigationEntry* entry = d->webContents->GetController().GetVisibleEntry()) {
content::FaviconStatus favicon = entry->GetFavicon();
if (favicon.valid)
@@ -697,12 +745,14 @@ QUrl WebContentsAdapter::iconUrl() const
QString WebContentsAdapter::pageTitle() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(QString());
return d->webContentsDelegate->title();
}
QString WebContentsAdapter::selectedText() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(QString());
if (auto *rwhv = d->webContents->GetRenderWidgetHostView())
return toQt(rwhv->GetSelectedText());
return QString();
@@ -711,60 +761,70 @@ QString WebContentsAdapter::selectedText() const
void WebContentsAdapter::undo()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->Undo();
}
void WebContentsAdapter::redo()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->Redo();
}
void WebContentsAdapter::cut()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->Cut();
}
void WebContentsAdapter::copy()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->Copy();
}
void WebContentsAdapter::paste()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->Paste();
}
void WebContentsAdapter::pasteAndMatchStyle()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->PasteAndMatchStyle();
}
void WebContentsAdapter::selectAll()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->SelectAll();
}
void WebContentsAdapter::requestClose()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->DispatchBeforeUnload();
}
void WebContentsAdapter::unselect()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->CollapseSelection();
}
void WebContentsAdapter::navigateToIndex(int offset)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost());
d->webContents->GetController().GoToIndex(offset);
focusIfNecessary();
@@ -773,6 +833,7 @@ void WebContentsAdapter::navigateToIndex(int offset)
void WebContentsAdapter::navigateToOffset(int offset)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost());
d->webContents->GetController().GoToOffset(offset);
focusIfNecessary();
@@ -781,18 +842,21 @@ void WebContentsAdapter::navigateToOffset(int offset)
int WebContentsAdapter::navigationEntryCount()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
return d->webContents->GetController().GetEntryCount();
}
int WebContentsAdapter::currentNavigationEntryIndex()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
return d->webContents->GetController().GetCurrentEntryIndex();
}
QUrl WebContentsAdapter::getNavigationEntryOriginalUrl(int index)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(QUrl());
content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
return entry ? toQt(entry->GetOriginalRequestURL()) : QUrl();
}
@@ -800,6 +864,7 @@ QUrl WebContentsAdapter::getNavigationEntryOriginalUrl(int index)
QUrl WebContentsAdapter::getNavigationEntryUrl(int index)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(QUrl());
content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
return entry ? toQt(entry->GetURL()) : QUrl();
}
@@ -807,6 +872,7 @@ QUrl WebContentsAdapter::getNavigationEntryUrl(int index)
QString WebContentsAdapter::getNavigationEntryTitle(int index)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(QString());
content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
return entry ? toQt(entry->GetTitle()) : QString();
}
@@ -814,6 +880,7 @@ QString WebContentsAdapter::getNavigationEntryTitle(int index)
QDateTime WebContentsAdapter::getNavigationEntryTimestamp(int index)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(QDateTime());
content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
return entry ? toQt(entry->GetTimestamp()) : QDateTime();
}
@@ -821,6 +888,7 @@ QDateTime WebContentsAdapter::getNavigationEntryTimestamp(int index)
QUrl WebContentsAdapter::getNavigationEntryIconUrl(int index)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(QUrl());
content::NavigationEntry *entry = d->webContents->GetController().GetEntryAtIndex(index);
if (!entry)
return QUrl();
@@ -831,6 +899,7 @@ QUrl WebContentsAdapter::getNavigationEntryIconUrl(int index)
void WebContentsAdapter::clearNavigationHistory()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (d->webContents->GetController().CanPruneAllButLastCommitted())
d->webContents->GetController().PruneAllButLastCommitted();
}
@@ -838,12 +907,14 @@ void WebContentsAdapter::clearNavigationHistory()
void WebContentsAdapter::serializeNavigationHistory(QDataStream &output)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
QtWebEngineCore::serializeNavigationHistory(d->webContents->GetController(), output);
}
void WebContentsAdapter::setZoomFactor(qreal factor)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (factor < content::kMinimumZoomFactor || factor > content::kMaximumZoomFactor)
return;
@@ -860,6 +931,7 @@ void WebContentsAdapter::setZoomFactor(qreal factor)
qreal WebContentsAdapter::currentZoomFactor() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(1);
return content::ZoomLevelToZoomFactor(content::HostZoomMap::GetZoomLevel(d->webContents.get()));
}
@@ -879,6 +951,7 @@ BrowserContextAdapter* WebContentsAdapter::browserContextAdapter()
QAccessibleInterface *WebContentsAdapter::browserAccessible()
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(nullptr);
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
Q_ASSERT(rvh);
content::BrowserAccessibilityManager *manager = static_cast<content::RenderFrameHostImpl*>(rvh->GetMainFrame())->GetOrCreateBrowserAccessibilityManager();
@@ -893,6 +966,7 @@ QAccessibleInterface *WebContentsAdapter::browserAccessible()
void WebContentsAdapter::runJavaScript(const QString &javaScript, quint32 worldId)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
Q_ASSERT(rvh);
if (worldId == 0) {
@@ -907,6 +981,7 @@ void WebContentsAdapter::runJavaScript(const QString &javaScript, quint32 worldI
quint64 WebContentsAdapter::runJavaScriptCallbackResult(const QString &javaScript, quint32 worldId)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
Q_ASSERT(rvh);
content::RenderFrameHost::JavaScriptResultCallback callback = base::Bind(&callbackOnEvaluateJS, d->adapterClient, d->nextRequestId);
@@ -920,6 +995,7 @@ quint64 WebContentsAdapter::runJavaScriptCallbackResult(const QString &javaScrip
quint64 WebContentsAdapter::fetchDocumentMarkup()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
d->renderViewObserverHost->fetchDocumentMarkup(d->nextRequestId);
return d->nextRequestId++;
}
@@ -927,6 +1003,7 @@ quint64 WebContentsAdapter::fetchDocumentMarkup()
quint64 WebContentsAdapter::fetchDocumentInnerText()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
d->renderViewObserverHost->fetchDocumentInnerText(d->nextRequestId);
return d->nextRequestId++;
}
@@ -934,6 +1011,7 @@ quint64 WebContentsAdapter::fetchDocumentInnerText()
quint64 WebContentsAdapter::findText(const QString &subString, bool caseSensitively, bool findBackward)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
if (d->lastFindRequestId > d->webContentsDelegate->lastReceivedFindReply()) {
// There are cases where the render process will overwrite a previous request
// with the new search and we'll have a dangling callback, leaving the application
@@ -960,6 +1038,7 @@ quint64 WebContentsAdapter::findText(const QString &subString, bool caseSensitiv
void WebContentsAdapter::stopFinding()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContentsDelegate->setLastSearchedString(QString());
d->webContents->StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION);
}
@@ -967,6 +1046,7 @@ void WebContentsAdapter::stopFinding()
void WebContentsAdapter::updateWebPreferences(const content::WebPreferences & webPreferences)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->GetRenderViewHost()->UpdateWebkitPreferences(webPreferences);
}
@@ -975,6 +1055,7 @@ void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileN
ReferrerPolicy referrerPolicy)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
content::BrowserContext *bctx = webContents()->GetBrowserContext();
content::DownloadManager *dlm = content::BrowserContext::GetDownloadManager(bctx);
DownloadManagerDelegateQt *dlmd = d->browserContextAdapter->downloadManagerDelegate();
@@ -1021,24 +1102,28 @@ void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileN
bool WebContentsAdapter::isAudioMuted() const
{
const Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(false);
return d->webContents->IsAudioMuted();
}
void WebContentsAdapter::setAudioMuted(bool muted)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->SetAudioMuted(muted);
}
bool WebContentsAdapter::recentlyAudible()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(false);
return d->webContents->WasRecentlyAudible();
}
void WebContentsAdapter::copyImageAt(const QPoint &location)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->GetRenderViewHost()->GetMainFrame()->CopyImageAt(location.x(), location.y());
}
@@ -1051,6 +1136,7 @@ ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerControls, blink::WebMediaPlay
void WebContentsAdapter::executeMediaPlayerActionAt(const QPoint &location, MediaPlayerAction action, bool enable)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
blink::WebMediaPlayerAction blinkAction((blink::WebMediaPlayerAction::Type)action, enable);
d->webContents->GetRenderViewHost()->ExecuteMediaPlayerActionAtLocation(toGfx(location), blinkAction);
}
@@ -1058,6 +1144,7 @@ void WebContentsAdapter::executeMediaPlayerActionAt(const QPoint &location, Medi
void WebContentsAdapter::inspectElementAt(const QPoint &location)
{
Q_D(WebContentsAdapter);
+ Q_ASSERT(isInitialized());
if (d->devToolsFrontend) {
d->devToolsFrontend->InspectElementAt(location.x(), location.y());
return;
@@ -1069,6 +1156,7 @@ void WebContentsAdapter::inspectElementAt(const QPoint &location)
bool WebContentsAdapter::hasInspector() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(false);
if (d->devToolsFrontend)
return true;
if (content::DevToolsAgentHost::HasFor(d->webContents.get()))
@@ -1079,6 +1167,7 @@ bool WebContentsAdapter::hasInspector() const
void WebContentsAdapter::openDevToolsFrontend(QSharedPointer<WebContentsAdapter> frontendAdapter)
{
Q_D(WebContentsAdapter);
+ Q_ASSERT(isInitialized());
if (d->devToolsFrontend &&
d->devToolsFrontend->frontendDelegate() == frontendAdapter->webContents()->GetDelegate())
return;
@@ -1094,6 +1183,7 @@ void WebContentsAdapter::openDevToolsFrontend(QSharedPointer<WebContentsAdapter>
void WebContentsAdapter::closeDevToolsFrontend()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (d->devToolsFrontend) {
d->devToolsFrontend->DisconnectFromTarget();
d->devToolsFrontend->Close();
@@ -1103,6 +1193,7 @@ void WebContentsAdapter::closeDevToolsFrontend()
void WebContentsAdapter::devToolsFrontendDestroyed(DevToolsFrontendQt *frontend)
{
Q_D(WebContentsAdapter);
+ Q_ASSERT(isInitialized());
Q_ASSERT(frontend == d->devToolsFrontend);
Q_UNUSED(frontend);
d->devToolsFrontend = nullptr;
@@ -1111,24 +1202,28 @@ void WebContentsAdapter::devToolsFrontendDestroyed(DevToolsFrontendQt *frontend)
void WebContentsAdapter::exitFullScreen()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->ExitFullscreen(false);
}
void WebContentsAdapter::changedFullScreen()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->NotifyFullscreenChanged(false);
}
void WebContentsAdapter::wasShown()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->WasShown();
}
void WebContentsAdapter::wasHidden()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->WasHidden();
}
@@ -1136,6 +1231,7 @@ void WebContentsAdapter::printToPDF(const QPageLayout &pageLayout, const QString
{
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
PrintViewManagerQt::PrintToPDFFileCallback callback = base::Bind(&callbackOnPdfSavingFinished,
d->adapterClient,
filePath);
@@ -1152,6 +1248,7 @@ quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayo
{
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(0);
PrintViewManagerQt::PrintToPDFCallback callback = base::Bind(&callbackOnPrintingFinished,
d->adapterClient,
d->nextRequestId);
@@ -1170,6 +1267,7 @@ quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayo
QPointF WebContentsAdapter::lastScrollOffset() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(QPointF());
if (content::RenderWidgetHostView *rwhv = d->webContents->GetRenderWidgetHostView())
return toQt(rwhv->GetLastScrollOffset());
return QPointF();
@@ -1178,6 +1276,7 @@ QPointF WebContentsAdapter::lastScrollOffset() const
QSizeF WebContentsAdapter::lastContentsSize() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(QSizeF());
if (RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt *>(d->webContents->GetRenderWidgetHostView()))
return toQt(rwhv->lastContentsSize());
return QSizeF();
@@ -1186,6 +1285,7 @@ QSizeF WebContentsAdapter::lastContentsSize() const
void WebContentsAdapter::grantMediaAccessPermission(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags flags)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
// Let the permission manager remember the reply.
if (flags & WebContentsAdapterClient::MediaAudioCapture)
d->browserContextAdapter->permissionRequestReply(securityOrigin, BrowserContextAdapter::AudioCapturePermission, true);
@@ -1197,12 +1297,14 @@ void WebContentsAdapter::grantMediaAccessPermission(const QUrl &securityOrigin,
void WebContentsAdapter::runGeolocationRequestCallback(const QUrl &securityOrigin, bool allowed)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->browserContextAdapter->permissionRequestReply(securityOrigin, BrowserContextAdapter::GeolocationPermission, allowed);
}
void WebContentsAdapter::grantMouseLockPermission(bool granted)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (granted) {
if (RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt *>(d->webContents->GetRenderWidgetHostView()))
@@ -1217,6 +1319,7 @@ void WebContentsAdapter::grantMouseLockPermission(bool granted)
void WebContentsAdapter::dpiScaleChanged()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
content::RenderWidgetHostImpl* impl = NULL;
if (d->webContents->GetRenderViewHost())
impl = content::RenderWidgetHostImpl::From(d->webContents->GetRenderViewHost()->GetWidget());
@@ -1227,6 +1330,7 @@ void WebContentsAdapter::dpiScaleChanged()
void WebContentsAdapter::backgroundColorChanged()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (content::RenderWidgetHostView *rwhv = d->webContents->GetRenderWidgetHostView())
rwhv->SetBackgroundColor(toSk(d->adapterClient->backgroundColor()));
}
@@ -1246,6 +1350,7 @@ QWebChannel *WebContentsAdapter::webChannel() const
void WebContentsAdapter::setWebChannel(QWebChannel *channel, uint worldId)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (d->webChannel == channel && d->webChannelWorld == worldId)
return;
@@ -1260,6 +1365,7 @@ void WebContentsAdapter::setWebChannel(QWebChannel *channel, uint worldId)
d->webChannel = channel;
d->webChannelWorld = worldId;
+
if (!channel) {
d->webChannelTransport.reset();
return;
@@ -1301,6 +1407,7 @@ void WebContentsAdapter::startDragging(QObject *dragSource, const content::DropD
const QPoint &offset)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (d->currentDropData)
return;
@@ -1353,6 +1460,7 @@ void WebContentsAdapter::startDragging(QObject *dragSource, const content::DropD
bool WebContentsAdapter::handleDropDataFileContents(const content::DropData &dropData,
QMimeData *mimeData)
{
+ CHECK_INITIALIZED(false);
if (dropData.file_contents.empty())
return false;
@@ -1409,6 +1517,7 @@ static void fillDropDataFromMimeData(content::DropData *dropData, const QMimeDat
void WebContentsAdapter::enterDrag(QDragEnterEvent *e, const QPointF &screenPos)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
if (!d->currentDropData) {
// The drag originated outside the WebEngineView.
@@ -1463,6 +1572,7 @@ static int toWeb(Qt::KeyboardModifiers modifiers)
Qt::DropAction WebContentsAdapter::updateDragPosition(QDragMoveEvent *e, const QPointF &screenPos)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(Qt::DropAction());
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
d->lastDragClientPos = toGfx(e->posF());
d->lastDragScreenPos = toGfx(screenPos);
@@ -1475,6 +1585,7 @@ Qt::DropAction WebContentsAdapter::updateDragPosition(QDragMoveEvent *e, const Q
void WebContentsAdapter::waitForUpdateDragActionCalled()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
const qint64 timeout = 3000;
QElapsedTimer t;
t.start();
@@ -1497,6 +1608,7 @@ void WebContentsAdapter::waitForUpdateDragActionCalled()
void WebContentsAdapter::updateDragAction(int action)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->updateDragActionCalled = true;
d->currentDropAction = static_cast<blink::WebDragOperation>(action);
}
@@ -1504,6 +1616,7 @@ void WebContentsAdapter::updateDragAction(int action)
void WebContentsAdapter::endDragging(const QPointF &clientPos, const QPointF &screenPos)
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
rvh->GetWidget()->FilterDropData(d->currentDropData.get());
d->lastDragClientPos = toGfx(clientPos);
@@ -1515,6 +1628,7 @@ void WebContentsAdapter::endDragging(const QPointF &clientPos, const QPointF &sc
void WebContentsAdapter::leaveDrag()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
rvh->GetWidget()->DragTargetDragLeave(d->lastDragClientPos, d->lastDragScreenPos);
d->currentDropData.reset();
@@ -1524,6 +1638,7 @@ void WebContentsAdapter::replaceMisspelling(const QString &word)
{
#if BUILDFLAG(ENABLE_SPELLCHECK)
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->ReplaceMisspelling(toString16(word));
#endif
}
@@ -1531,6 +1646,7 @@ void WebContentsAdapter::replaceMisspelling(const QString &word)
void WebContentsAdapter::focusIfNecessary()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
const WebEngineSettings *settings = d->adapterClient->webEngineSettings();
bool focusOnNavigation = settings->testAttribute(WebEngineSettings::FocusOnNavigationEnabled);
if (focusOnNavigation)
@@ -1540,6 +1656,7 @@ void WebContentsAdapter::focusIfNecessary()
bool WebContentsAdapter::isFindTextInProgress() const
{
Q_D(const WebContentsAdapter);
+ CHECK_INITIALIZED(false);
return d->lastFindRequestId != d->webContentsDelegate->lastReceivedFindReply();
}
@@ -1578,18 +1695,21 @@ WebContentsAdapterClient::renderProcessExitStatus(int terminationStatus) {
FaviconManager *WebContentsAdapter::faviconManager()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(nullptr);
return d->webContentsDelegate->faviconManager();
}
void WebContentsAdapter::viewSource()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED();
d->webContents->GetMainFrame()->ViewSource();
}
bool WebContentsAdapter::canViewSource()
{
Q_D(WebContentsAdapter);
+ CHECK_INITIALIZED(false);
return d->webContents->GetController().CanViewSource();
}