diff options
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 103 |
1 files changed, 63 insertions, 40 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 86366abaa..a6e1fb438 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -63,6 +63,7 @@ #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/navigation_entry.h" +#include "content/public/browser/navigation_handle.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" @@ -169,10 +170,10 @@ void WebContentsDelegateQt::AddNewContents(content::WebContents* source, content void WebContentsDelegateQt::CloseContents(content::WebContents *source) { m_viewClient->close(); - GetJavaScriptDialogManager(source)->CancelDialogs(source, /* whatever?: */false, false); + GetJavaScriptDialogManager(source)->CancelDialogs(source, /* whatever?: */false); } -void WebContentsDelegateQt::LoadProgressChanged(content::WebContents* source, double progress) +void WebContentsDelegateQt::LoadProgressChanged(content::WebContents */*source*/, double progress) { if (!m_loadingErrorFrameList.isEmpty()) return; @@ -191,59 +192,82 @@ void WebContentsDelegateQt::RenderFrameDeleted(content::RenderFrameHost *render_ m_loadingErrorFrameList.removeOne(render_frame_host->GetRoutingID()); } -void WebContentsDelegateQt::DidStartProvisionalLoadForFrame(content::RenderFrameHost* render_frame_host, const GURL& validated_url, bool is_error_page, bool is_iframe_srcdoc) +void WebContentsDelegateQt::DidStartNavigation(content::NavigationHandle *navigation_handle) { - if (is_error_page) { - m_loadingErrorFrameList.append(render_frame_host->GetRoutingID()); - - // Trigger LoadStarted signal for main frame's error page only. - if (!render_frame_host->GetParent()) { - m_faviconManager->resetCandidates(); - m_viewClient->loadStarted(toQt(validated_url), true); - } - + if (!navigation_handle->IsInMainFrame()) return; - } - if (render_frame_host->GetParent()) - return; + // Error-pages are not reported as separate started navigations. + Q_ASSERT(!navigation_handle->IsErrorPage()); m_loadingErrorFrameList.clear(); m_faviconManager->resetCandidates(); - m_viewClient->loadStarted(toQt(validated_url)); + m_viewClient->loadStarted(toQt(navigation_handle->GetURL())); } -void WebContentsDelegateQt::DidCommitProvisionalLoadForFrame(content::RenderFrameHost* render_frame_host, const GURL& url, ui::PageTransition transition_type) +void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navigation_handle) { - // Make sure that we don't set the findNext WebFindOptions on a new frame. - m_lastSearchedString = QString(); + if (!navigation_handle->IsInMainFrame()) + return; + + if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) { + // VisistedLinksMaster asserts !IsOffTheRecord(). + if (navigation_handle->ShouldUpdateHistory() && m_viewClient->browserContextAdapter()->trackVisitedLinks()) + m_viewClient->browserContextAdapter()->visitedLinksManager()->addUrl(navigation_handle->GetURL()); + + // Make sure that we don't set the findNext WebFindOptions on a new frame. + m_lastSearchedString = QString(); - // This is currently used for canGoBack/Forward values, which is flattened across frames. For other purposes we might have to pass is_main_frame. - m_viewClient->loadCommitted(); + // This is currently used for canGoBack/Forward values, which is flattened across frames. For other purposes we might have to pass is_main_frame. + m_viewClient->loadCommitted(); + } + // Success is reported by DidFinishLoad, but DidFailLoad is now dead code and needs to be handled below + if (navigation_handle->GetNetErrorCode() == net::OK) + return; + + // WebContentsObserver::DidFailLoad is not called any longer so we have to report the failure here. + const net::Error error_code = navigation_handle->GetNetErrorCode(); + const std::string error_description = net::ErrorToString(error_code); + didFailLoad(toQt(navigation_handle->GetURL()), error_code, toQt(error_description)); + + // The load will succede as an error-page load later, and we reported the original error above + if (navigation_handle->IsErrorPage()) { + // Now report we are starting to load an error-page. + m_loadingErrorFrameList.append(navigation_handle->GetRenderFrameHost()->GetRoutingID()); + m_faviconManager->resetCandidates(); + m_viewClient->loadStarted(toQt(GURL(content::kUnreachableWebDataURL)), true); + + // If it is already committed we will not see another DidFinishNavigation call or a DidFinishLoad call. + if (navigation_handle->HasCommitted()) { + m_lastSearchedString = QString(); + m_viewClient->loadCommitted(); + } + } } -void WebContentsDelegateQt::DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code, const base::string16& error_description, bool was_ignored_by_handler) +void WebContentsDelegateQt::didFailLoad(const QUrl &url, int errorCode, const QString &errorDescription) { - DidFailLoad(render_frame_host, validated_url, error_code, error_description, was_ignored_by_handler); + m_viewClient->iconChanged(QUrl()); + m_viewClient->loadFinished(false /* success */ , url, false /* isErrorPage */, errorCode, errorDescription); + m_viewClient->loadProgressChanged(0); } void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code, const base::string16& error_description, bool was_ignored_by_handler) { Q_UNUSED(was_ignored_by_handler); + if (render_frame_host->GetParent()) + return; + if (validated_url.spec() == content::kUnreachableWebDataURL) { + // error-pages should only ever fail due to abort: + Q_ASSERT(error_code == -3 /* ERR_ABORTED */); m_loadingErrorFrameList.removeOne(render_frame_host->GetRoutingID()); - qCritical("Loading error-page failed. This shouldn't happen."); - if (!render_frame_host->GetParent()) - m_viewClient->loadFinished(false /* success */, toQt(validated_url), true /* isErrorPage */); + m_viewClient->iconChanged(QUrl()); + m_viewClient->loadFinished(false /* success */, toQt(validated_url), true /* isErrorPage */); return; } - if (render_frame_host->GetParent()) - return; - - m_viewClient->iconChanged(QUrl()); - m_viewClient->loadFinished(false /* success */ , toQt(validated_url), false /* isErrorPage */, error_code, toQt(error_description)); - m_viewClient->loadProgressChanged(0); + didFailLoad(toQt(validated_url), error_code, toQt(error_description)); } void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) @@ -380,14 +404,6 @@ void WebContentsDelegateQt::UpdateTargetURL(content::WebContents* source, const m_viewClient->didUpdateTargetURL(toQt(url)); } -void WebContentsDelegateQt::DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host, const content::LoadCommittedDetails& details, const content::FrameNavigateParams& params) -{ - // VisistedLinksMaster asserts !IsOffTheRecord(). - if (!params.should_update_history || !m_viewClient->browserContextAdapter()->trackVisitedLinks()) - return; - m_viewClient->browserContextAdapter()->visitedLinksManager()->addUrl(params.url); -} - void WebContentsDelegateQt::WasShown() { web_cache::WebCacheManager::GetInstance()->ObserveActivity(web_contents()->GetRenderProcessHost()->GetID()); @@ -408,6 +424,13 @@ void WebContentsDelegateQt::DidFirstVisuallyNonEmptyPaint() } } +void WebContentsDelegateQt::ActivateContents(content::WebContents* contents) +{ + WebEngineSettings *settings = m_viewClient->webEngineSettings(); + if (settings->testAttribute(settings->Attribute::AllowWindowActivationFromJavaScript)) + contents->Focus(); +} + void WebContentsDelegateQt::RequestToLockMouse(content::WebContents *web_contents, bool user_gesture, bool last_unlocked_by_target) { Q_UNUSED(user_gesture); |