Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: chrome/browser/ui/webui/print_preview/hidden_web_contents.h

Issue 1125343004: Add a "Simplify Page" option to the print preview dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and remove custom URL source Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2bd1c0648e153e3878d93031d267ec4103aaa5fb
--- /dev/null
+++ b/chrome/browser/ui/webui/print_preview/hidden_web_contents.h
@@ -0,0 +1,147 @@
+// Copyright (c) 2015 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;
+ };
+
+ explicit HiddenWebContents(Profile* profile);
+ ~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);
+
+ // 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);
+
+ // 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();
+
+ void ScheduleNotifyFinishLoad();
+
+ 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;
+
+ base::ObserverList<Observer> observer_list_;
+
+ // The profile being used
+ Profile* profile_;
+
+ content::NotificationRegistrar notification_registrar_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698