Index: chrome/browser/ui/webui/print_preview/hidden_web_contents.h |
diff --git a/chrome/browser/ui/webui/print_preview/hidden_web_contents.h b/chrome/browser/ui/webui/print_preview/hidden_web_contents.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..23c8fefd53260d67538fbde1db5b224d45e2faa3 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/print_preview/hidden_web_contents.h |
@@ -0,0 +1,160 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_ |
+#define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_ |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/observer_list.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+#include "content/public/browser/web_contents_observer.h" |
+#include "content/public/common/referrer.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+class Profile; |
+ |
+namespace net { |
+class URLRequestContextGetter; |
+} |
+ |
+class HiddenWebContents : public content::NotificationObserver, |
+ public content::WebContentsObserver, |
+ public base::SupportsWeakPtr<HiddenWebContents> { |
+ public: |
+ class Observer { |
+ public: |
+ // Signals that the hidden renderer has stopped running prematurely. |
+ virtual void OnFail(HiddenWebContents* contents) = 0; |
+ |
+ // Signals that this hidden renderer has just finished loading. |
+ virtual void OnFinishedLoad(HiddenWebContents* contents); |
+ |
+ protected: |
+ Observer(); |
+ virtual ~Observer() = 0; |
+ }; |
+ |
+ HiddenWebContents(Profile* profile, const GURL& url); |
+ ~HiddenWebContents() override; |
+ |
+ // All observers of a HiddenWebContents are removed after the OnPrerenderStop |
+ // event is sent, so there is no need to call RemoveObserver() in the normal |
+ // use case. |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
+ bool Init(); |
+ |
+ // Start rendering the contents in the prerendered state. |size| |
+ // indicates the rectangular dimensions that the hidden renderer's page should |
+ // be. |session_storage_namespace| indicates the namespace that the hidden |
+ // renderer's page should be part of. |
+ virtual void StartRendering( |
+ const gfx::Size& size, |
+ content::SessionStorageNamespace* session_storage_namespace); |
+ |
+ const GURL& url() const { return url_; } |
+ bool has_stopped_loading() const { return has_stopped_loading_; } |
+ bool has_finished_loading() const { return has_finished_loading_; } |
+ bool rendering_has_started() const { return rendering_has_started_; } |
+ |
+ // content::WebContentsObserver implementation. |
+ void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
+ void DidStopLoading() override; |
+ void DocumentLoadedInFrame( |
+ content::RenderFrameHost* render_frame_host) override; |
+ void DidStartProvisionalLoadForFrame( |
+ content::RenderFrameHost* render_frame_host, |
+ const GURL& validated_url, |
+ bool is_error_page, |
+ bool is_iframe_srcdoc) override; |
+ void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
+ const GURL& validated_url) override; |
+ void DidNavigateMainFrame( |
+ const content::LoadCommittedDetails& details, |
+ const content::FrameNavigateParams& params) override; |
+ void DidGetRedirectForResourceRequest( |
+ content::RenderFrameHost* render_frame_host, |
+ const content::ResourceRedirectDetails& details) override; |
+ |
+ void RenderProcessGone(base::TerminationStatus status) override; |
+ |
+ // content::NotificationObserver |
+ void Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) override; |
+ |
+ // The hidden WebContents (may be NULL). |
+ content::WebContents* web_contents() { |
+ return web_contents_.get(); |
+ } |
+ |
+ bool rendering_has_been_cancelled() const { |
+ return rendering_has_been_cancelled_; |
+ } |
+ |
+ // Sets the final status, calls OnDestroy and adds |this| to the |
+ // PrerenderManager's pending deletes list. |
+ void Destroy(); |
+ |
+ protected: |
+ // These call out to methods on our Observers, using our observer_list_. Note |
+ // that NotifyStop() also clears the observer list. |
+ void NotifyStart(); |
+ void NotifyFail(); |
+ void NotifyFinishedLoad(); |
+ |
+ content::NotificationRegistrar& notification_registrar() { |
+ return notification_registrar_; |
+ } |
+ |
+ content::WebContents* CreateWebContents( |
+ content::SessionStorageNamespace* session_storage_namespace); |
+ |
+ bool rendering_has_started_; |
+ |
+ // The hidden rendered WebContents; may be null. |
+ scoped_ptr<content::WebContents> web_contents_; |
+ |
+ // The session storage namespace id for use in matching. We must save it |
+ // rather than get it from the RenderViewHost since in the control group |
+ // we won't have a RenderViewHost. |
+ int64 session_storage_namespace_id_; |
+ |
+ private: |
+ class WebContentsDelegateImpl; |
+ |
+ static bool IsValidUrl(const GURL& url); |
+ |
+ ObserverList<Observer> observer_list_; |
+ |
+ // The URL being rendered. |
+ GURL url_; |
+ |
+ // The profile being used |
+ Profile* profile_; |
+ |
+ content::NotificationRegistrar notification_registrar_; |
+ |
+ // True when the main frame has stopped loading. |
+ bool has_stopped_loading_; |
+ |
+ // True when the main frame has finished loading. |
+ bool has_finished_loading_; |
+ |
+ // Tracks whether or not rendering has been cancelled by calling Destroy. |
+ // Used solely to prevent double deletion. |
+ bool rendering_has_been_cancelled_; |
+ |
+ scoped_ptr<WebContentsDelegateImpl> web_contents_delegate_; |
+ |
+ // The size of the WebView from the launching page. |
+ gfx::Size size_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(HiddenWebContents); |
+}; |
+ |
+#endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_ |