| Index: blimp/engine/session/page_load_tracker.cc
|
| diff --git a/blimp/engine/session/page_load_tracker.cc b/blimp/engine/session/page_load_tracker.cc
|
| index 24e3a4871aeb134c601a3479d1120608bf7fed9a..3345d06dcacfff1ced389b7631cc025d5e229e11 100644
|
| --- a/blimp/engine/session/page_load_tracker.cc
|
| +++ b/blimp/engine/session/page_load_tracker.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "blimp/engine/session/page_load_tracker.h"
|
|
|
| +#include "content/public/browser/navigation_handle.h"
|
| #include "content/public/browser/render_widget_host_view.h"
|
|
|
| namespace blimp {
|
| @@ -11,12 +12,16 @@ namespace engine {
|
|
|
| namespace {
|
|
|
| -content::RenderWidgetHost* GetRenderWidgetHostIfMainFrame(
|
| - content::RenderFrameHost* render_frame_host) {
|
| - if (render_frame_host->GetParent() != nullptr)
|
| - return nullptr;
|
| +bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle) {
|
| + // We change the progress bar for main frame navigations only.
|
| + if (!navigation_handle->IsInMainFrame())
|
| + return true;
|
|
|
| - return render_frame_host->GetView()->GetRenderWidgetHost();
|
| + // Same page navigations don't need to trigger a progress bar update.
|
| + if (navigation_handle->IsSamePage())
|
| + return true;
|
| +
|
| + return false;
|
| }
|
|
|
| } // namespace
|
| @@ -30,74 +35,40 @@ PageLoadTracker::PageLoadTracker(content::WebContents* web_contents,
|
|
|
| PageLoadTracker::~PageLoadTracker() {}
|
|
|
| -void PageLoadTracker::DidStartProvisionalLoadForFrame(
|
| - content::RenderFrameHost* render_frame_host,
|
| - const GURL& validated_url,
|
| - bool is_error_page,
|
| - bool is_iframe_srcdoc) {
|
| - content::RenderWidgetHost* render_widget_host =
|
| - GetRenderWidgetHostIfMainFrame(render_frame_host);
|
| - if (!render_widget_host)
|
| +void PageLoadTracker::DidStartNavigation(
|
| + content::NavigationHandle* navigation_handle) {
|
| + if (ShouldIgnoreNavigation(navigation_handle))
|
| return;
|
|
|
| - render_widget_load_status_[render_widget_host] = LoadStatus();
|
| -
|
| - // Notify the client that a navigation was initiated.
|
| + // Cancel any pending callbacks for the previous navigation. We will send an
|
| + // update based on the progress of this navigation.
|
| + did_paint_after_navigation_callback_.Cancel();
|
| client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADING);
|
| }
|
|
|
| -void PageLoadTracker::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
| - const GURL& validated_url) {
|
| - content::RenderWidgetHost* render_widget_host =
|
| - GetRenderWidgetHostIfMainFrame(render_frame_host);
|
| - if (!render_widget_host)
|
| +void PageLoadTracker::DidFinishNavigation(
|
| + content::NavigationHandle* navigation_handle) {
|
| + if (ShouldIgnoreNavigation(navigation_handle))
|
| return;
|
|
|
| - RenderWidgetLoadStatusMap::iterator it =
|
| - render_widget_load_status_.find(render_widget_host);
|
| - DCHECK(it != render_widget_load_status_.end());
|
| -
|
| - it->second.page_loaded = true;
|
| - if (it->second.Loaded()) {
|
| + if (navigation_handle->HasCommitted()) {
|
| + // Make sure that at least one compositor content update after the
|
| + // navigation commits is sent to the client.
|
| + // Note that a visual state update in our case implies that this callback
|
| + // will be invoked after the update is queued to be sent to the client.
|
| + did_paint_after_navigation_callback_.Reset(
|
| + base::Bind(&PageLoadTracker::DidPaintAfterNavigationCommitted,
|
| + base::Unretained(this)));
|
| + navigation_handle->GetRenderFrameHost()->InsertVisualStateCallback(
|
| + did_paint_after_navigation_callback_.callback());
|
| + } else {
|
| + // Inform the client to update the progress bar right away.
|
| client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED);
|
| - render_widget_load_status_.erase(it);
|
| }
|
| }
|
|
|
| -void PageLoadTracker::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
| - const GURL& validated_url,
|
| - int error_code,
|
| - const base::string16& error_description,
|
| - bool was_ignored_by_handler) {
|
| - content::RenderWidgetHost* render_widget_host =
|
| - GetRenderWidgetHostIfMainFrame(render_frame_host);
|
| - if (!render_widget_host)
|
| - return;
|
| -
|
| - RenderWidgetLoadStatusMap::iterator it =
|
| - render_widget_load_status_.find(render_widget_host);
|
| - DCHECK(it != render_widget_load_status_.end());
|
| -
|
| - // If the navigation failed, the client should dismiss the load indicator.
|
| +void PageLoadTracker::DidPaintAfterNavigationCommitted(bool result) {
|
| client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED);
|
| - render_widget_load_status_.erase(it);
|
| -}
|
| -
|
| -void PageLoadTracker::DidFirstPaintAfterLoad(
|
| - content::RenderWidgetHost* render_widget_host) {
|
| - RenderWidgetLoadStatusMap::iterator it =
|
| - render_widget_load_status_.find(render_widget_host);
|
| - DCHECK(it != render_widget_load_status_.end());
|
| -
|
| - it->second.did_first_paint = true;
|
| - if (it->second.Loaded()) {
|
| - client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED);
|
| - render_widget_load_status_.erase(it);
|
| - }
|
| -}
|
| -
|
| -bool PageLoadTracker::LoadStatus::Loaded() const {
|
| - return page_loaded && did_first_paint;
|
| }
|
|
|
| } // namespace engine
|
|
|