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

Side by Side Diff: components/guest_view/browser/guest_view_base.h

Issue 1392343002: Reduce the public method footprint of GuestViewBase and derived types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Reverted reordering in cc files. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | components/guest_view/browser/guest_view_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_ 5 #ifndef COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_
6 #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_ 6 #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 static GuestViewBase* From(int owner_process_id, int instance_id); 75 static GuestViewBase* From(int owner_process_id, int instance_id);
76 76
77 // Given a |web_contents|, returns the top level owner WebContents. If 77 // Given a |web_contents|, returns the top level owner WebContents. If
78 // |web_contents| does not belong to a GuestView, it will be returned 78 // |web_contents| does not belong to a GuestView, it will be returned
79 // unchanged. 79 // unchanged.
80 static content::WebContents* GetTopLevelWebContents( 80 static content::WebContents* GetTopLevelWebContents(
81 content::WebContents* web_contents); 81 content::WebContents* web_contents);
82 82
83 static bool IsGuest(content::WebContents* web_contents); 83 static bool IsGuest(content::WebContents* web_contents);
84 84
85 // Returns the name of the derived type of this GuestView.
85 virtual const char* GetViewType() const = 0; 86 virtual const char* GetViewType() const = 0;
86 87
87 // This method is called after the guest has been attached to an embedder and
88 // suspended resource loads have been resumed.
89 //
90 // This method can be overriden by subclasses. This gives the derived class
91 // an opportunity to perform setup actions after attachment.
92 virtual void DidAttachToEmbedder() {}
93
94 // This method is called after this GuestViewBase has been initiated.
95 //
96 // This gives the derived class an opportunity to perform additional
97 // initialization.
98 virtual void DidInitialize(const base::DictionaryValue& create_params) {}
99
100 // This method is called when the initial set of frames within the page have
101 // completed loading.
102 virtual void GuestViewDidStopLoading() {}
103
104 // This method is called when the embedder's zoom changes.
105 virtual void EmbedderZoomChanged(double old_zoom_level,
106 double new_zoom_level) {}
107
108 // This method is called when the guest WebContents has been destroyed. This
109 // object will be destroyed after this call returns.
110 //
111 // This gives the derived class an opportunity to perform some cleanup.
112 virtual void GuestDestroyed() {}
113
114 // This method is invoked when the guest RenderView is ready, e.g. because we
115 // recreated it after a crash or after reattachment.
116 //
117 // This gives the derived class an opportunity to perform some initialization
118 // work.
119 virtual void GuestReady() {}
120
121 // This method is called when the guest's zoom changes.
122 virtual void GuestZoomChanged(double old_zoom_level, double new_zoom_level) {}
123
124 // This method is called when embedder WebContents's fullscreen is toggled.
125 //
126 // If the guest asked the embedder to enter fullscreen, the guest uses this
127 // signal to exit fullscreen state.
128 virtual void EmbedderFullscreenToggled(bool entered_fullscreen) {}
129
130 // This method is invoked when the contents auto-resized to give the container
131 // an opportunity to match it if it wishes.
132 //
133 // This gives the derived class an opportunity to inform its container element
134 // or perform other actions.
135 virtual void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
136 const gfx::Size& new_size) {}
137
138 // This method queries whether autosize is supported for this particular view. 88 // This method queries whether autosize is supported for this particular view.
139 // By default, autosize is not supported. Derived classes can override this 89 // By default, autosize is not supported. Derived classes can override this
140 // behavior to support autosize. 90 // behavior to support autosize.
141 virtual bool IsAutoSizeSupported() const; 91 virtual bool IsAutoSizeSupported() const;
142 92
143 // This method is invoked when the contents preferred size changes. This will
144 // only ever fire if IsPreferredSizeSupported returns true.
145 virtual void OnPreferredSizeChanged(const gfx::Size& pref_size) {}
146
147 // This method queries whether preferred size events are enabled for this 93 // This method queries whether preferred size events are enabled for this
148 // view. By default, preferred size events are disabled, since they add a 94 // view. By default, preferred size events are disabled, since they add a
149 // small amount of overhead. 95 // small amount of overhead.
150 virtual bool IsPreferredSizeModeEnabled() const; 96 virtual bool IsPreferredSizeModeEnabled() const;
151 97
152 // This method is called immediately before suspended resource loads have been 98 // This indicates whether zoom should propagate from the embedder to the guest
153 // resumed on attachment to an embedder. 99 // content.
154 //
155 // This method can be overriden by subclasses. This gives the derived class
156 // an opportunity to perform setup actions before attachment.
157 virtual void WillAttachToEmbedder() {}
158
159 // This method is called when the guest WebContents is about to be destroyed.
160 //
161 // This gives the derived class an opportunity to perform some cleanup prior
162 // to destruction.
163 virtual void WillDestroy() {}
164
165 // This method is to be implemented by the derived class. This indicates
166 // whether zoom should propagate from the embedder to the guest content.
167 virtual bool ZoomPropagatesFromEmbedderToGuest() const; 100 virtual bool ZoomPropagatesFromEmbedderToGuest() const;
168 101
169 // This method is to be implemented by the derived class. Access to guest 102 // Access to guest views are determined by the availability of the internal
170 // views are determined by the availability of the internal extension API 103 // extension API used to implement the guest view.
171 // used to implement the guest view.
172 // 104 //
173 // This should be the name of the API as it appears in the _api_features.json 105 // This should be the name of the API as it appears in the _api_features.json
174 // file. 106 // file.
175 virtual const char* GetAPINamespace() const = 0; 107 virtual const char* GetAPINamespace() const = 0;
176 108
177 // This method is to be implemented by the derived class. This method is the 109 // This method is the task prefix to show for a task produced by this
178 // task prefix to show for a task produced by this GuestViewBase's derived 110 // GuestViewBase's derived type.
179 // type.
180 virtual int GetTaskPrefix() const = 0; 111 virtual int GetTaskPrefix() const = 0;
181 112
182 // This method is to be implemented by the derived class. Given a set of 113 // Dispatches an event to the guest proxy.
183 // initialization parameters, a concrete subclass of GuestViewBase can 114 void DispatchEventToGuestProxy(GuestViewEvent* event);
184 // create a specialized WebContents that it returns back to GuestViewBase. 115
185 using WebContentsCreatedCallback = 116 // Dispatches an event to the view.
186 base::Callback<void(content::WebContents*)>; 117 void DispatchEventToView(GuestViewEvent* event);
187 virtual void CreateWebContents(
188 const base::DictionaryValue& create_params,
189 const WebContentsCreatedCallback& callback) = 0;
190 118
191 // This creates a WebContents and initializes |this| GuestViewBase to use the 119 // This creates a WebContents and initializes |this| GuestViewBase to use the
192 // newly created WebContents. 120 // newly created WebContents.
121 using WebContentsCreatedCallback =
122 base::Callback<void(content::WebContents*)>;
193 void Init(const base::DictionaryValue& create_params, 123 void Init(const base::DictionaryValue& create_params,
194 const WebContentsCreatedCallback& callback); 124 const WebContentsCreatedCallback& callback);
195 125
196 void InitWithWebContents(const base::DictionaryValue& create_params, 126 void InitWithWebContents(const base::DictionaryValue& create_params,
197 content::WebContents* guest_web_contents); 127 content::WebContents* guest_web_contents);
198 128
199 void LoadURLWithParams(
200 const content::NavigationController::LoadURLParams& load_params);
201
202 bool IsViewType(const char* const view_type) const { 129 bool IsViewType(const char* const view_type) const {
203 return !strcmp(GetViewType(), view_type); 130 return !strcmp(GetViewType(), view_type);
204 } 131 }
205 132
206 // Used to toggle autosize mode for this GuestView, and set both the automatic 133 // Used to toggle autosize mode for this GuestView, and set both the automatic
207 // and normal sizes. 134 // and normal sizes.
208 void SetSize(const SetSizeParams& params); 135 void SetSize(const SetSizeParams& params);
209 136
210 bool initialized() const { return initialized_; } 137 bool initialized() const { return initialized_; }
211 138
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // This value is only valid after attachment or first navigation. 191 // This value is only valid after attachment or first navigation.
265 int proxy_routing_id() const { return guest_proxy_routing_id_; } 192 int proxy_routing_id() const { return guest_proxy_routing_id_; }
266 193
267 // Destroy this guest. 194 // Destroy this guest.
268 void Destroy(); 195 void Destroy();
269 196
270 // Saves the attach state of the custom element hosting this GuestView. 197 // Saves the attach state of the custom element hosting this GuestView.
271 void SetAttachParams(const base::DictionaryValue& params); 198 void SetAttachParams(const base::DictionaryValue& params);
272 void SetOpener(GuestViewBase* opener); 199 void SetOpener(GuestViewBase* opener);
273 200
274 content::WebContents* CreateNewGuestWindow(
275 const content::WebContents::CreateParams& create_params) final;
276 void DidAttach(int guest_proxy_routing_id) final;
277 void DidDetach() final;
278 content::WebContents* GetOwnerWebContents() const final;
279 bool Find(int request_id,
280 const base::string16& search_text,
281 const blink::WebFindOptions& options) final;
282 bool StopFinding(content::StopFindAction action) final;
283 void GuestSizeChanged(const gfx::Size& new_size) final;
284 void SetGuestHost(content::GuestHost* guest_host) final;
285 void WillAttach(content::WebContents* embedder_web_contents,
286 int browser_plugin_instance_id,
287 bool is_full_page_plugin,
288 const base::Closure& callback) final;
289
290 // ui_zoom::ZoomObserver implementation.
291 void OnZoomChanged(
292 const ui_zoom::ZoomController::ZoomChangedEventData& data) final;
293
294 // Dispatches an event to the guest proxy.
295 void DispatchEventToGuestProxy(GuestViewEvent* event);
296
297 // Dispatches an event to the view.
298 void DispatchEventToView(GuestViewEvent* event);
299
300 protected: 201 protected:
301 explicit GuestViewBase(content::WebContents* owner_web_contents); 202 explicit GuestViewBase(content::WebContents* owner_web_contents);
302 203
303 ~GuestViewBase() override; 204 ~GuestViewBase() override;
304 205
206 // BrowserPluginGuestDelegate implementation.
207 void SetContextMenuPosition(const gfx::Point& position) override;
208
209 // WebContentsDelegate implementation.
210 void HandleKeyboardEvent(
211 content::WebContents* source,
212 const content::NativeWebKeyboardEvent& event) override;
213 bool PreHandleGestureEvent(content::WebContents* source,
214 const blink::WebGestureEvent& event) override;
215 void FindReply(content::WebContents* source,
216 int request_id,
217 int number_of_matches,
218 const gfx::Rect& selection_rect,
219 int active_match_ordinal,
220 bool final_update) override;
221
222 // WebContentsObserver implementation.
223 void DidNavigateMainFrame(
224 const content::LoadCommittedDetails& details,
225 const content::FrameNavigateParams& params) override;
226
227 // Given a set of initialization parameters, a concrete subclass of
228 // GuestViewBase can create a specialized WebContents that it returns back to
229 // GuestViewBase.
230 virtual void CreateWebContents(
231 const base::DictionaryValue& create_params,
232 const WebContentsCreatedCallback& callback) = 0;
233
234 // This method is called after the guest has been attached to an embedder and
235 // suspended resource loads have been resumed.
236 //
237 // This method can be overriden by subclasses. This gives the derived class
238 // an opportunity to perform setup actions after attachment.
239 virtual void DidAttachToEmbedder() {}
240
241 // This method is called after this GuestViewBase has been initiated.
242 //
243 // This gives the derived class an opportunity to perform additional
244 // initialization.
245 virtual void DidInitialize(const base::DictionaryValue& create_params) {}
246
247 // This method is called when embedder WebContents's fullscreen is toggled.
248 //
249 // If the guest asked the embedder to enter fullscreen, the guest uses this
250 // signal to exit fullscreen state.
251 virtual void EmbedderFullscreenToggled(bool entered_fullscreen) {}
252
253 // This method is called when the initial set of frames within the page have
254 // completed loading.
255 virtual void GuestViewDidStopLoading() {}
256
257 // This method is called when the guest WebContents has been destroyed. This
258 // object will be destroyed after this call returns.
259 //
260 // This gives the derived class an opportunity to perform some cleanup.
261 virtual void GuestDestroyed() {}
262
263 // This method is invoked when the guest RenderView is ready, e.g. because we
264 // recreated it after a crash or after reattachment.
265 //
266 // This gives the derived class an opportunity to perform some initialization
267 // work.
268 virtual void GuestReady() {}
269
270 // This method is called when the guest's zoom changes.
271 virtual void GuestZoomChanged(double old_zoom_level, double new_zoom_level) {}
272
273 // This method is invoked when the contents auto-resized to give the container
274 // an opportunity to match it if it wishes.
275 //
276 // This gives the derived class an opportunity to inform its container element
277 // or perform other actions.
278 virtual void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
279 const gfx::Size& new_size) {}
280
281 // This method is invoked when the contents preferred size changes. This will
282 // only ever fire if IsPreferredSizeSupported returns true.
283 virtual void OnPreferredSizeChanged(const gfx::Size& pref_size) {}
284
285 // Signals that the guest view is ready. The default implementation signals
286 // immediately, but derived class can override this if they need to do
287 // asynchronous setup.
288 virtual void SignalWhenReady(const base::Closure& callback);
289
290 // Returns true if this guest should handle find requests for its
291 // embedder. This should generally be true for guests that make up the
292 // entirety of the embedder's content.
293 virtual bool ShouldHandleFindRequestsForEmbedder() const;
294
295 // This method is called immediately before suspended resource loads have been
296 // resumed on attachment to an embedder.
297 //
298 // This method can be overriden by subclasses. This gives the derived class
299 // an opportunity to perform setup actions before attachment.
300 virtual void WillAttachToEmbedder() {}
301
302 // This method is called when the guest WebContents is about to be destroyed.
303 //
304 // This gives the derived class an opportunity to perform some cleanup prior
305 // to destruction.
306 virtual void WillDestroy() {}
307
308 void LoadURLWithParams(
309 const content::NavigationController::LoadURLParams& load_params);
310
305 // Convert sizes in pixels from logical to physical numbers of pixels. 311 // Convert sizes in pixels from logical to physical numbers of pixels.
306 // Note that a size can consist of a fractional number of logical pixels 312 // Note that a size can consist of a fractional number of logical pixels
307 // (hence |logical_pixels| is represented as a double), but will always 313 // (hence |logical_pixels| is represented as a double), but will always
308 // consist of an integral number of physical pixels (hence the return value 314 // consist of an integral number of physical pixels (hence the return value
309 // is represented as an int). 315 // is represented as an int).
310 int LogicalPixelsToPhysicalPixels(double logical_pixels) const; 316 int LogicalPixelsToPhysicalPixels(double logical_pixels) const;
311 317
312 // Convert sizes in pixels from physical to logical numbers of pixels. 318 // Convert sizes in pixels from physical to logical numbers of pixels.
313 // Note that a size can consist of a fractional number of logical pixels 319 // Note that a size can consist of a fractional number of logical pixels
314 // (hence the return value is represented as a double), but will always 320 // (hence the return value is represented as a double), but will always
315 // consist of an integral number of physical pixels (hence |physical_pixels| 321 // consist of an integral number of physical pixels (hence |physical_pixels|
316 // is represented as an int). 322 // is represented as an int).
317 double PhysicalPixelsToLogicalPixels(int physical_pixels) const; 323 double PhysicalPixelsToLogicalPixels(int physical_pixels) const;
318 324
325 void SetGuestZoomLevelToMatchEmbedder();
326
327 private:
328 friend class GuestViewMessageFilter;
329
330 class OwnerContentsObserver;
331 class OpenerLifetimeObserver;
332
333 // BrowserPluginGuestDelegate implementation.
334 content::WebContents* CreateNewGuestWindow(
335 const content::WebContents::CreateParams& create_params) final;
336 void DidAttach(int guest_proxy_routing_id) final;
337 void DidDetach() final;
338 content::WebContents* GetOwnerWebContents() const final;
339 bool HandleFindForEmbedder(int request_id,
340 const base::string16& search_text,
341 const blink::WebFindOptions& options) final;
342 bool HandleStopFindingForEmbedder(content::StopFindAction action) final;
343 void GuestSizeChanged(const gfx::Size& new_size) final;
344 void SetGuestHost(content::GuestHost* guest_host) final;
345 void WillAttach(content::WebContents* embedder_web_contents,
346 int browser_plugin_instance_id,
347 bool is_full_page_plugin,
348 const base::Closure& callback) final;
349
350 // WebContentsDelegate implementation.
351 void ActivateContents(content::WebContents* contents) final;
352 void ContentsMouseEvent(content::WebContents* source,
353 const gfx::Point& location,
354 bool motion) final;
355 void ContentsZoomChange(bool zoom_in) final;
356 void LoadingStateChanged(content::WebContents* source,
357 bool to_different_document) final;
358 content::ColorChooser* OpenColorChooser(
359 content::WebContents* web_contents,
360 SkColor color,
361 const std::vector<content::ColorSuggestion>& suggestions) final;
362 void ResizeDueToAutoResize(content::WebContents* web_contents,
363 const gfx::Size& new_size) final;
364 void RunFileChooser(content::WebContents* web_contents,
365 const content::FileChooserParams& params) final;
366 bool ShouldFocusPageAfterCrash() final;
367 void UpdatePreferredSize(content::WebContents* web_contents,
368 const gfx::Size& pref_size) final;
369 void UpdateTargetURL(content::WebContents* source, const GURL& url) final;
370 bool ShouldResumeRequestsForCreatedWindow() final;
371
319 // WebContentsObserver implementation. 372 // WebContentsObserver implementation.
320 void DidStopLoading() final; 373 void DidStopLoading() final;
321 void RenderViewReady() final; 374 void RenderViewReady() final;
322 void WebContentsDestroyed() final; 375 void WebContentsDestroyed() final;
323 void DidNavigateMainFrame(
324 const content::LoadCommittedDetails& details,
325 const content::FrameNavigateParams& params) override;
326 376
327 // WebContentsDelegate implementation. 377 // ui_zoom::ZoomObserver implementation.
328 void ActivateContents(content::WebContents* contents) final; 378 void OnZoomChanged(
329 void ContentsMouseEvent(content::WebContents* source, 379 const ui_zoom::ZoomController::ZoomChangedEventData& data) final;
330 const gfx::Point& location,
331 bool motion) override;
332 void ContentsZoomChange(bool zoom_in) override;
333 void HandleKeyboardEvent(
334 content::WebContents* source,
335 const content::NativeWebKeyboardEvent& event) override;
336 void LoadingStateChanged(content::WebContents* source,
337 bool to_different_document) final;
338 content::ColorChooser* OpenColorChooser(
339 content::WebContents* web_contents,
340 SkColor color,
341 const std::vector<content::ColorSuggestion>& suggestions) override;
342 void ResizeDueToAutoResize(content::WebContents* web_contents,
343 const gfx::Size& new_size) override;
344 void RunFileChooser(content::WebContents* web_contents,
345 const content::FileChooserParams& params) override;
346 bool ShouldFocusPageAfterCrash() final;
347 bool PreHandleGestureEvent(content::WebContents* source,
348 const blink::WebGestureEvent& event) override;
349 void UpdatePreferredSize(content::WebContents* web_contents,
350 const gfx::Size& pref_size) final;
351 void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
352 bool ShouldResumeRequestsForCreatedWindow() override;
353 void FindReply(content::WebContents* source,
354 int request_id,
355 int number_of_matches,
356 const gfx::Rect& selection_rect,
357 int active_match_ordinal,
358 bool final_update) override;
359
360 void SetGuestZoomLevelToMatchEmbedder();
361
362 // Signals that the guest view is ready. The default implementation signals
363 // immediately, but derived class can override this if they need to do
364 // asynchronous setup.
365 virtual void SignalWhenReady(const base::Closure& callback);
366
367 // Returns true if this guest should handle find requests for its
368 // embedder. This should generally be true for guests that make up the
369 // entirety of the embedder's content.
370 virtual bool ShouldHandleFindRequestsForEmbedder() const;
371
372 // BrowserPluginGuestDelegate implementation.
373 void SetContextMenuPosition(const gfx::Point& position) override;
374
375 private:
376 class OwnerContentsObserver;
377
378 class OpenerLifetimeObserver;
379 380
380 void SendQueuedEvents(); 381 void SendQueuedEvents();
381 382
382 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, 383 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params,
383 const WebContentsCreatedCallback& callback, 384 const WebContentsCreatedCallback& callback,
384 content::WebContents* guest_web_contents); 385 content::WebContents* guest_web_contents);
385 386
386 // Dispatches the onResize event to the embedder. 387 // Dispatches the onResize event to the embedder.
387 void DispatchOnResizeEvent(const gfx::Size& old_size, 388 void DispatchOnResizeEvent(const gfx::Size& old_size,
388 const gfx::Size& new_size); 389 const gfx::Size& new_size);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // This is used to ensure pending tasks will not fire after this object is 476 // This is used to ensure pending tasks will not fire after this object is
476 // destroyed. 477 // destroyed.
477 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; 478 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_;
478 479
479 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); 480 DISALLOW_COPY_AND_ASSIGN(GuestViewBase);
480 }; 481 };
481 482
482 } // namespace guest_view 483 } // namespace guest_view
483 484
484 #endif // COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_ 485 #endif // COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_
OLDNEW
« no previous file with comments | « no previous file | components/guest_view/browser/guest_view_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698