diff options
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 116 |
1 files changed, 65 insertions, 51 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 9855e3859..7b339776b 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -89,15 +89,17 @@ namespace QtWebEngineCore { -// Maps the LogSeverity defines in base/logging.h to the web engines message levels. -static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptConsoleMessageLevel(int32_t messageLevel) +static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptConsoleMessageLevel(blink::mojom::ConsoleMessageLevel log_level) { - if (messageLevel < 1) + switch (log_level) { + case blink::mojom::ConsoleMessageLevel::kVerbose: + case blink::mojom::ConsoleMessageLevel::kInfo: return WebContentsAdapterClient::Info; - else if (messageLevel > 1) + case blink::mojom::ConsoleMessageLevel::kWarning: + return WebContentsAdapterClient::Warning; + case blink::mojom::ConsoleMessageLevel::kError: return WebContentsAdapterClient::Error; - - return WebContentsAdapterClient::Warning; + } } WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents *webContents, WebContentsAdapterClient *adapterClient) @@ -187,36 +189,20 @@ static bool shouldUseActualURL(content::NavigationEntry *entry) void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source, content::InvalidateTypes changed_flags) { - if (changed_flags & content::INVALIDATE_TYPE_URL) { - content::NavigationEntry *entry = source->GetController().GetVisibleEntry(); - - QUrl newUrl; - if (source->GetVisibleURL().SchemeIs(content::kViewSourceScheme)) { - Q_ASSERT(entry); - GURL url = entry->GetURL(); - - // Strip user name, password and reference section from view-source URLs - if (url.has_password() || url.has_username() || url.has_ref()) { - GURL strippedUrl = net::SimplifyUrlForRequest(entry->GetURL()); - newUrl = QUrl(QString("%1:%2").arg(content::kViewSourceScheme, QString::fromStdString(strippedUrl.spec()))); - } - } - - // If there is a visible entry there are special cases when we dont wan't to use the actual URL - if (entry && newUrl.isEmpty()) - newUrl = shouldUseActualURL(entry) ? toQt(entry->GetURL()) : toQt(entry->GetVirtualURL()); - - if (m_url != newUrl) { - m_url = newUrl; - m_viewClient->urlChanged(m_url); - } + if (changed_flags & content::INVALIDATE_TYPE_URL && !m_pendingUrlUpdate) { + m_pendingUrlUpdate = true; + base::WeakPtr<WebContentsDelegateQt> delegate = AsWeakPtr(); + QTimer::singleShot(0, [delegate, this](){ if (delegate) m_viewClient->urlChanged();}); } if (changed_flags & content::INVALIDATE_TYPE_TITLE) { QString newTitle = toQt(source->GetTitle()); if (m_title != newTitle) { m_title = newTitle; - m_viewClient->titleChanged(m_title); + QTimer::singleShot(0, [delegate = AsWeakPtr(), title = newTitle] () { + if (delegate) + delegate->adapterClient()->titleChanged(title); + }); } } @@ -230,6 +216,25 @@ void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source, } } +QUrl WebContentsDelegateQt::url(content::WebContents* source) const { + + content::NavigationEntry *entry = source->GetController().GetVisibleEntry(); + QUrl newUrl; + if (entry) { + GURL url = entry->GetURL(); + // Strip user name, password and reference section from view-source URLs + if (source->GetVisibleURL().SchemeIs(content::kViewSourceScheme) && + (url.has_password() || url.has_username() || url.has_ref())) { + GURL strippedUrl = net::SimplifyUrlForRequest(url); + newUrl = QUrl(QString("%1:%2").arg(content::kViewSourceScheme, QString::fromStdString(strippedUrl.spec()))); + } + // If there is a visible entry there are special cases when we dont wan't to use the actual URL + if (newUrl.isEmpty()) + newUrl = shouldUseActualURL(entry) ? toQt(url) : toQt(entry->GetVirtualURL()); + } + m_pendingUrlUpdate = false; + return newUrl; +} void WebContentsDelegateQt::AddNewContents(content::WebContents* source, std::unique_ptr<content::WebContents> new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked) { Q_UNUSED(source) @@ -284,10 +289,17 @@ void WebContentsDelegateQt::RenderFrameDeleted(content::RenderFrameHost *render_ void WebContentsDelegateQt::RenderProcessGone(base::TerminationStatus status) { + // RenderProcessHost::FastShutdownIfPossible results in TERMINATION_STATUS_STILL_RUNNING + if (status != base::TERMINATION_STATUS_STILL_RUNNING) { + m_viewClient->renderProcessTerminated( + m_viewClient->renderProcessExitStatus(status), + web_contents()->GetCrashedErrorCode()); + } + // Based one TabLoadTracker::RenderProcessGone - if (status == base::TerminationStatus::TERMINATION_STATUS_NORMAL_TERMINATION - || status == base::TerminationStatus::TERMINATION_STATUS_STILL_RUNNING) { + if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION + || status == base::TERMINATION_STATUS_STILL_RUNNING) { return; } @@ -473,8 +485,10 @@ void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame return; } - if (render_frame_host->GetParent()) + if (render_frame_host->GetParent()) { + m_viewClient->updateNavigationActions(); return; + } if (!m_faviconManager->hasCandidate()) m_viewClient->iconChanged(QUrl()); @@ -537,7 +551,7 @@ void WebContentsDelegateQt::ExitFullscreenModeForTab(content::WebContents *web_c m_viewClient->requestFullScreenMode(toQt(web_contents->GetLastCommittedURL().GetOrigin()), false); } -bool WebContentsDelegateQt::IsFullscreenForTabOrPending(const content::WebContents* web_contents) const +bool WebContentsDelegateQt::IsFullscreenForTabOrPending(const content::WebContents* web_contents) { Q_UNUSED(web_contents); return m_viewClient->isFullScreenMode(); @@ -566,10 +580,11 @@ void WebContentsDelegateQt::RunFileChooser(content::RenderFrameHost * /*frameHos }); } -bool WebContentsDelegateQt::DidAddMessageToConsole(content::WebContents *source, int32_t level, const base::string16 &message, int32_t line_no, const base::string16 &source_id) +bool WebContentsDelegateQt::DidAddMessageToConsole(content::WebContents *source, blink::mojom::ConsoleMessageLevel log_level, + const base::string16 &message, int32_t line_no, const base::string16 &source_id) { Q_UNUSED(source) - m_viewClient->javaScriptConsoleMessage(mapToJavascriptConsoleMessageLevel(level), toQt(message), static_cast<int>(line_no), toQt(source_id)); + m_viewClient->javaScriptConsoleMessage(mapToJavascriptConsoleMessageLevel(log_level), toQt(message), static_cast<int>(line_no), toQt(source_id)); return false; } @@ -726,12 +741,12 @@ void WebContentsDelegateQt::BeforeUnloadFired(bool proceed, const base::TimeTick Q_UNUSED(proceed_time); } -bool WebContentsDelegateQt::CheckMediaAccessPermission(content::RenderFrameHost *, const GURL& security_origin, blink::MediaStreamType type) +bool WebContentsDelegateQt::CheckMediaAccessPermission(content::RenderFrameHost *, const GURL& security_origin, blink::mojom::MediaStreamType type) { switch (type) { - case blink::MEDIA_DEVICE_AUDIO_CAPTURE: + case blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE: return m_viewClient->profileAdapter()->checkPermission(toQt(security_origin), ProfileAdapter::AudioCapturePermission); - case blink::MEDIA_DEVICE_VIDEO_CAPTURE: + case blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE: return m_viewClient->profileAdapter()->checkPermission(toQt(security_origin), ProfileAdapter::VideoCapturePermission); default: LOG(INFO) << "WebContentsDelegateQt::CheckMediaAccessPermission: " @@ -800,7 +815,6 @@ WebContentsAdapter *WebContentsDelegateQt::webContentsAdapter() const void WebContentsDelegateQt::copyStateFrom(WebContentsDelegateQt *source) { - m_url = source->m_url; m_title = source->m_title; NavigationStateChanged(web_contents(), content::INVALIDATE_TYPE_URL); m_faviconManager->copyStateFrom(source->m_faviconManager.data()); @@ -830,28 +844,28 @@ void WebContentsDelegateQt::setLoadingState(LoadingState state) webContentsAdapter()->updateRecommendedState(); } -int &WebContentsDelegateQt::streamCount(blink::MediaStreamType type) +int &WebContentsDelegateQt::streamCount(blink::mojom::MediaStreamType type) { // Based on MediaStreamCaptureIndicator::WebContentsDeviceUsage::GetStreamCount switch (type) { - case blink::MEDIA_DEVICE_AUDIO_CAPTURE: + case blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE: return m_audioStreamCount; - case blink::MEDIA_DEVICE_VIDEO_CAPTURE: + case blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE: return m_videoStreamCount; - case blink::MEDIA_GUM_TAB_AUDIO_CAPTURE: - case blink::MEDIA_GUM_TAB_VIDEO_CAPTURE: + case blink::mojom::MediaStreamType::GUM_TAB_AUDIO_CAPTURE: + case blink::mojom::MediaStreamType::GUM_TAB_VIDEO_CAPTURE: return m_mirroringStreamCount; - case blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE: - case blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE: - case blink::MEDIA_DISPLAY_VIDEO_CAPTURE: - case blink::MEDIA_DISPLAY_AUDIO_CAPTURE: + case blink::mojom::MediaStreamType::GUM_DESKTOP_VIDEO_CAPTURE: + case blink::mojom::MediaStreamType::GUM_DESKTOP_AUDIO_CAPTURE: + case blink::mojom::MediaStreamType::DISPLAY_VIDEO_CAPTURE: + case blink::mojom::MediaStreamType::DISPLAY_AUDIO_CAPTURE: return m_desktopStreamCount; - case blink::MEDIA_NO_SERVICE: - case blink::NUM_MEDIA_TYPES: + case blink::mojom::MediaStreamType::NO_SERVICE: + case blink::mojom::MediaStreamType::NUM_MEDIA_TYPES: NOTREACHED(); return m_videoStreamCount; } |