| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BLIMP_ENGINE_SESSION_PAGE_LOAD_TRACKER_H_ | 5 #ifndef BLIMP_ENGINE_SESSION_PAGE_LOAD_TRACKER_H_ |
| 6 #define BLIMP_ENGINE_SESSION_PAGE_LOAD_TRACKER_H_ | 6 #define BLIMP_ENGINE_SESSION_PAGE_LOAD_TRACKER_H_ |
| 7 | 7 |
| 8 #include "base/containers/small_map.h" | 8 #include "base/cancelable_callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| 11 #include "content/public/browser/render_widget_host.h" | 11 #include "content/public/browser/render_widget_host.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 | 13 |
| 14 namespace blimp { | 14 namespace blimp { |
| 15 namespace engine { | 15 namespace engine { |
| 16 | 16 |
| 17 enum class PageLoadStatus { LOADING, LOADED }; | 17 enum class PageLoadStatus { LOADING, LOADED }; |
| 18 | 18 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // Tracks the page load status for a tab using load and paint notifications | 31 // Tracks the page load status for a tab using load and paint notifications |
| 32 // from the renderer. | 32 // from the renderer. |
| 33 class PageLoadTracker : public content::WebContentsObserver { | 33 class PageLoadTracker : public content::WebContentsObserver { |
| 34 public: | 34 public: |
| 35 explicit PageLoadTracker(content::WebContents* web_contents, | 35 explicit PageLoadTracker(content::WebContents* web_contents, |
| 36 PageLoadTrackerClient* client); | 36 PageLoadTrackerClient* client); |
| 37 ~PageLoadTracker() override; | 37 ~PageLoadTracker() override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 struct LoadStatus { | 40 // content::WebContentsObserver implementation. |
| 41 // Set to true on receiving a notification from the renderer that the load | 41 void DidStartNavigation( |
| 42 // finished. See WebContentsObserver::DidFinishLoad. | 42 content::NavigationHandle* navigation_handle) override; |
| 43 bool page_loaded = false; | 43 void DidFinishNavigation( |
| 44 content::NavigationHandle* navigation_handle) override; |
| 44 | 45 |
| 45 // Set to true on receiving a notification from the renderer that the first | 46 // Invoked when the renderer has performed at least one paint after the |
| 46 // paint after a navigation was performed. | 47 // navigation was committed. |
| 47 // See WebContentsObserver::DidFirstPaintAfterLoad. | 48 void DidPaintAfterNavigationCommitted(bool result); |
| 48 bool did_first_paint = false; | |
| 49 | 49 |
| 50 bool Loaded() const; | 50 base::CancelableCallback<void(bool)> did_paint_after_navigation_callback_; |
| 51 }; | |
| 52 | |
| 53 typedef base::SmallMap<std::map<content::RenderWidgetHost*, LoadStatus>> | |
| 54 RenderWidgetLoadStatusMap; | |
| 55 | |
| 56 // content::WebContentsObserver implementation. | |
| 57 void DidStartProvisionalLoadForFrame( | |
| 58 content::RenderFrameHost* render_frame_host, | |
| 59 const GURL& validated_url, | |
| 60 bool is_error_page, | |
| 61 bool is_iframe_srcdoc) override; | |
| 62 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | |
| 63 const GURL& validated_url) override; | |
| 64 void DidFailLoad(content::RenderFrameHost* render_frame_host, | |
| 65 const GURL& validated_url, | |
| 66 int error_code, | |
| 67 const base::string16& error_description, | |
| 68 bool was_ignored_by_handler) override; | |
| 69 void DidFirstPaintAfterLoad( | |
| 70 content::RenderWidgetHost* render_widget_host) override; | |
| 71 | |
| 72 RenderWidgetLoadStatusMap render_widget_load_status_; | |
| 73 | 51 |
| 74 PageLoadTrackerClient* client_; | 52 PageLoadTrackerClient* client_; |
| 75 | 53 |
| 76 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); | 54 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); |
| 77 }; | 55 }; |
| 78 | 56 |
| 79 } // namespace engine | 57 } // namespace engine |
| 80 } // namespace blimp | 58 } // namespace blimp |
| 81 | 59 |
| 82 #endif // BLIMP_ENGINE_SESSION_PAGE_LOAD_TRACKER_H_ | 60 #endif // BLIMP_ENGINE_SESSION_PAGE_LOAD_TRACKER_H_ |
| OLD | NEW |