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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 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 explicit HiddenWebContents(Profile* profile);
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 // Start rendering the contents in the prerendered state. |size|
50 // indicates the rectangular dimensions that the hidden renderer's page should
51 // be. |session_storage_namespace| indicates the namespace that the hidden
52 // renderer's page should be part of.
53 virtual void StartRendering(
54 const gfx::Size& size,
55 content::SessionStorageNamespace* session_storage_namespace);
56
57 // content::WebContentsObserver implementation.
58 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
59 void DidStopLoading() override;
60 void DocumentLoadedInFrame(
61 content::RenderFrameHost* render_frame_host) override;
62 void DidStartProvisionalLoadForFrame(
63 content::RenderFrameHost* render_frame_host,
64 const GURL& validated_url,
65 bool is_error_page,
66 bool is_iframe_srcdoc) override;
67 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
68 const GURL& validated_url) override;
69 void DidNavigateMainFrame(
70 const content::LoadCommittedDetails& details,
71 const content::FrameNavigateParams& params) override;
72 void DidGetRedirectForResourceRequest(
73 content::RenderFrameHost* render_frame_host,
74 const content::ResourceRedirectDetails& details) override;
75
76 void RenderProcessGone(base::TerminationStatus status) override;
77
78 // content::NotificationObserver
79 void Observe(int type,
80 const content::NotificationSource& source,
81 const content::NotificationDetails& details) override;
82
83 // The hidden WebContents (may be NULL).
84 content::WebContents* web_contents() {
85 return web_contents_.get();
86 }
87
88 bool rendering_has_been_cancelled() const {
89 return rendering_has_been_cancelled_;
90 }
91
92 // Sets the final status, calls OnDestroy and adds |this| to the
93 // PrerenderManager's pending deletes list.
94 void Destroy();
95
96 protected:
97 // These call out to methods on our Observers, using our observer_list_. Note
98 // that NotifyStop() also clears the observer list.
99 void NotifyStart();
100 void NotifyFail();
101 void NotifyFinishedLoad();
102
103 void ScheduleNotifyFinishLoad();
104
105 content::NotificationRegistrar& notification_registrar() {
106 return notification_registrar_;
107 }
108
109 content::WebContents* CreateWebContents(
110 content::SessionStorageNamespace* session_storage_namespace);
111
112 bool rendering_has_started_;
113
114 // The hidden rendered WebContents; may be null.
115 scoped_ptr<content::WebContents> web_contents_;
116
117 // The session storage namespace id for use in matching. We must save it
118 // rather than get it from the RenderViewHost since in the control group
119 // we won't have a RenderViewHost.
120 int64 session_storage_namespace_id_;
121
122 private:
123 class WebContentsDelegateImpl;
124
125 base::ObserverList<Observer> observer_list_;
126
127 // The profile being used
128 Profile* profile_;
129
130 content::NotificationRegistrar notification_registrar_;
131
132 // True when the main frame has finished loading.
133 bool has_finished_loading_;
134
135 // Tracks whether or not rendering has been cancelled by calling Destroy.
136 // Used solely to prevent double deletion.
137 bool rendering_has_been_cancelled_;
138
139 scoped_ptr<WebContentsDelegateImpl> web_contents_delegate_;
140
141 // The size of the WebView from the launching page.
142 gfx::Size size_;
143
144 DISALLOW_COPY_AND_ASSIGN(HiddenWebContents);
145 };
146
147 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HIDDEN_WEB_CONTENTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698