| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/engine/session/page_load_tracker.h" | |
| 6 | |
| 7 #include "content/public/browser/navigation_handle.h" | |
| 8 #include "content/public/browser/render_widget_host_view.h" | |
| 9 | |
| 10 namespace blimp { | |
| 11 namespace engine { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle) { | |
| 16 // We change the progress bar for main frame navigations only. | |
| 17 if (!navigation_handle->IsInMainFrame()) | |
| 18 return true; | |
| 19 | |
| 20 // Same page navigations don't need to trigger a progress bar update. | |
| 21 if (navigation_handle->IsSamePage()) | |
| 22 return true; | |
| 23 | |
| 24 return false; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 PageLoadTracker::PageLoadTracker(content::WebContents* web_contents, | |
| 30 PageLoadTrackerClient* client) | |
| 31 : client_(client) { | |
| 32 DCHECK(web_contents); | |
| 33 Observe(web_contents); | |
| 34 } | |
| 35 | |
| 36 PageLoadTracker::~PageLoadTracker() {} | |
| 37 | |
| 38 void PageLoadTracker::DidStartNavigation( | |
| 39 content::NavigationHandle* navigation_handle) { | |
| 40 if (ShouldIgnoreNavigation(navigation_handle)) | |
| 41 return; | |
| 42 | |
| 43 // Cancel any pending callbacks for the previous navigation. We will send an | |
| 44 // update based on the progress of this navigation. | |
| 45 did_paint_after_navigation_callback_.Cancel(); | |
| 46 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADING); | |
| 47 } | |
| 48 | |
| 49 void PageLoadTracker::DidFinishNavigation( | |
| 50 content::NavigationHandle* navigation_handle) { | |
| 51 if (ShouldIgnoreNavigation(navigation_handle)) | |
| 52 return; | |
| 53 | |
| 54 if (navigation_handle->HasCommitted()) { | |
| 55 // Make sure that at least one compositor content update after the | |
| 56 // navigation commits is sent to the client. | |
| 57 // Note that a visual state update in our case implies that this callback | |
| 58 // will be invoked after the update is queued to be sent to the client. | |
| 59 did_paint_after_navigation_callback_.Reset( | |
| 60 base::Bind(&PageLoadTracker::DidPaintAfterNavigationCommitted, | |
| 61 base::Unretained(this))); | |
| 62 navigation_handle->GetRenderFrameHost()->InsertVisualStateCallback( | |
| 63 did_paint_after_navigation_callback_.callback()); | |
| 64 } else { | |
| 65 // Inform the client to update the progress bar right away. | |
| 66 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void PageLoadTracker::DidPaintAfterNavigationCommitted(bool result) { | |
| 71 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED); | |
| 72 } | |
| 73 | |
| 74 } // namespace engine | |
| 75 } // namespace blimp | |
| OLD | NEW |