OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 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 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" |
| 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/common/referrer.h" |
| 15 #include "ui/gfx/geometry/size.h" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace net { |
| 20 class URLRequestContextGetter; |
| 21 } |
| 22 |
| 23 class HiddenWebContents : public content::NotificationObserver, |
| 24 public content::WebContentsObserver, |
| 25 public base::SupportsWeakPtr<HiddenWebContents> { |
| 26 public: |
| 27 class Observer { |
| 28 public: |
| 29 // Signals that the hidden renderer has stopped running prematurely. |
| 30 virtual void OnFail(HiddenWebContents* contents) = 0; |
| 31 |
| 32 // Signals that this hidden renderer has just finished loading. |
| 33 virtual void OnFinishedLoad(HiddenWebContents* contents); |
| 34 |
| 35 protected: |
| 36 Observer(); |
| 37 virtual ~Observer() = 0; |
| 38 }; |
| 39 |
| 40 HiddenWebContents(Profile* profile, const GURL& url); |
| 41 ~HiddenWebContents() override; |
| 42 |
| 43 // All observers of a HiddenWebContents are removed after the OnPrerenderStop |
| 44 // event is sent, so there is no need to call RemoveObserver() in the normal |
| 45 // use case. |
| 46 void AddObserver(Observer* observer); |
| 47 void RemoveObserver(Observer* observer); |
| 48 |
| 49 bool Init(); |
| 50 |
| 51 // Start rendering the contents in the prerendered state. |size| |
| 52 // indicates the rectangular dimensions that the hidden renderer's page should |
| 53 // be. |session_storage_namespace| indicates the namespace that the hidden |
| 54 // renderer's page should be part of. |
| 55 virtual void StartRendering( |
| 56 const gfx::Size& size, |
| 57 content::SessionStorageNamespace* session_storage_namespace); |
| 58 |
| 59 const GURL& url() const { return url_; } |
| 60 bool has_stopped_loading() const { return has_stopped_loading_; } |
| 61 bool has_finished_loading() const { return has_finished_loading_; } |
| 62 bool rendering_has_started() const { return rendering_has_started_; } |
| 63 |
| 64 // content::WebContentsObserver implementation. |
| 65 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
| 66 void DidStopLoading() override; |
| 67 void DocumentLoadedInFrame( |
| 68 content::RenderFrameHost* render_frame_host) override; |
| 69 void DidStartProvisionalLoadForFrame( |
| 70 content::RenderFrameHost* render_frame_host, |
| 71 const GURL& validated_url, |
| 72 bool is_error_page, |
| 73 bool is_iframe_srcdoc) override; |
| 74 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 75 const GURL& validated_url) override; |
| 76 void DidNavigateMainFrame( |
| 77 const content::LoadCommittedDetails& details, |
| 78 const content::FrameNavigateParams& params) override; |
| 79 void DidGetRedirectForResourceRequest( |
| 80 content::RenderFrameHost* render_frame_host, |
| 81 const content::ResourceRedirectDetails& details) override; |
| 82 |
| 83 void RenderProcessGone(base::TerminationStatus status) override; |
| 84 |
| 85 // content::NotificationObserver |
| 86 void Observe(int type, |
| 87 const content::NotificationSource& source, |
| 88 const content::NotificationDetails& details) override; |
| 89 |
| 90 // The hidden WebContents (may be NULL). |
| 91 content::WebContents* web_contents() { |
| 92 return web_contents_.get(); |
| 93 } |
| 94 |
| 95 bool rendering_has_been_cancelled() const { |
| 96 return rendering_has_been_cancelled_; |
| 97 } |
| 98 |
| 99 // Sets the final status, calls OnDestroy and adds |this| to the |
| 100 // PrerenderManager's pending deletes list. |
| 101 void Destroy(); |
| 102 |
| 103 protected: |
| 104 // These call out to methods on our Observers, using our observer_list_. Note |
| 105 // that NotifyStop() also clears the observer list. |
| 106 void NotifyStart(); |
| 107 void NotifyFail(); |
| 108 void NotifyFinishedLoad(); |
| 109 |
| 110 content::NotificationRegistrar& notification_registrar() { |
| 111 return notification_registrar_; |
| 112 } |
| 113 |
| 114 content::WebContents* CreateWebContents( |
| 115 content::SessionStorageNamespace* session_storage_namespace); |
| 116 |
| 117 bool rendering_has_started_; |
| 118 |
| 119 // The hidden rendered WebContents; may be null. |
| 120 scoped_ptr<content::WebContents> web_contents_; |
| 121 |
| 122 // The session storage namespace id for use in matching. We must save it |
| 123 // rather than get it from the RenderViewHost since in the control group |
| 124 // we won't have a RenderViewHost. |
| 125 int64 session_storage_namespace_id_; |
| 126 |
| 127 private: |
| 128 class WebContentsDelegateImpl; |
| 129 |
| 130 static bool IsValidUrl(const GURL& url); |
| 131 |
| 132 ObserverList<Observer> observer_list_; |
| 133 |
| 134 // The URL being rendered. |
| 135 GURL url_; |
| 136 |
| 137 // The profile being used |
| 138 Profile* profile_; |
| 139 |
| 140 content::NotificationRegistrar notification_registrar_; |
| 141 |
| 142 // True when the main frame has stopped loading. |
| 143 bool has_stopped_loading_; |
| 144 |
| 145 // True when the main frame has finished loading. |
| 146 bool has_finished_loading_; |
| 147 |
| 148 // Tracks whether or not rendering has been cancelled by calling Destroy. |
| 149 // Used solely to prevent double deletion. |
| 150 bool rendering_has_been_cancelled_; |
| 151 |
| 152 scoped_ptr<WebContentsDelegateImpl> web_contents_delegate_; |
| 153 |
| 154 // The size of the WebView from the launching page. |
| 155 gfx::Size size_; |
| 156 |
| 157 DISALLOW_COPY_AND_ASSIGN(HiddenWebContents); |
| 158 }; |
| 159 |
| 160 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_ |
OLD | NEW |