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

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

Issue 857093003: Implemented explicit resizing from guestview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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 EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 6 #define EXTENSIONS_BROWSER_GUEST_VIEW_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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/ui/zoom/zoom_observer.h" 12 #include "components/ui/zoom/zoom_observer.h"
13 #include "content/public/browser/browser_plugin_guest_delegate.h" 13 #include "content/public/browser/browser_plugin_guest_delegate.h"
14 #include "content/public/browser/guest_sizer.h" 14 #include "content/public/browser/guest_sizer.h"
15 #include "content/public/browser/render_process_host_observer.h" 15 #include "content/public/browser/render_process_host_observer.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_delegate.h" 17 #include "content/public/browser/web_contents_delegate.h"
18 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
19 #include "extensions/common/guest_view/guest_view_constants.h" 19 #include "extensions/common/guest_view/guest_view_constants.h"
20 20
21 struct RendererContentSettingRules; 21 struct RendererContentSettingRules;
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 // A struct of parameters for SetSize(). The parameters are all declared as
26 // scoped pointers since they are all optional. Null pointers indicate that the
27 // parameter has not been provided, and the last used value should be used. Note
28 // that when |enable_auto_size| is true, providing |normal_size| is not
29 // meaningful. This is because the normal size of the guestview is overridden
30 // whenever autosizing occurs.
31 struct SetSizeParams {
32 SetSizeParams();
33 ~SetSizeParams();
34
35 scoped_ptr<bool> enable_auto_size;
36 scoped_ptr<gfx::Size> min_size;
37 scoped_ptr<gfx::Size> max_size;
38 scoped_ptr<gfx::Size> normal_size;
39 };
40
25 // A GuestViewBase is the base class browser-side API implementation for a 41 // A GuestViewBase is the base class browser-side API implementation for a
26 // <*view> tag. GuestViewBase maintains an association between a guest 42 // <*view> tag. GuestViewBase maintains an association between a guest
27 // WebContents and an owner WebContents. It receives events issued from 43 // WebContents and an owner WebContents. It receives events issued from
28 // the guest and relays them to the owner. GuestViewBase tracks the lifetime 44 // the guest and relays them to the owner. GuestViewBase tracks the lifetime
29 // of its owner. A GuestViewBase's owner is referred to as an embedder if 45 // of its owner. A GuestViewBase's owner is referred to as an embedder if
30 // it is attached to a container within the owner's WebContents. 46 // it is attached to a container within the owner's WebContents.
31 class GuestViewBase : public content::BrowserPluginGuestDelegate, 47 class GuestViewBase : public content::BrowserPluginGuestDelegate,
32 public content::WebContentsDelegate, 48 public content::WebContentsDelegate,
33 public content::WebContentsObserver, 49 public content::WebContentsObserver,
34 public ui_zoom::ZoomObserver { 50 public ui_zoom::ZoomObserver {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 void Init(const base::DictionaryValue& create_params, 199 void Init(const base::DictionaryValue& create_params,
184 const WebContentsCreatedCallback& callback); 200 const WebContentsCreatedCallback& callback);
185 201
186 void InitWithWebContents(const base::DictionaryValue& create_params, 202 void InitWithWebContents(const base::DictionaryValue& create_params,
187 content::WebContents* guest_web_contents); 203 content::WebContents* guest_web_contents);
188 204
189 bool IsViewType(const char* const view_type) const { 205 bool IsViewType(const char* const view_type) const {
190 return !strcmp(GetViewType(), view_type); 206 return !strcmp(GetViewType(), view_type);
191 } 207 }
192 208
193 // Toggles autosize mode for this GuestView. 209 // Used to toggle autosize mode for this GuestView, and set both the automatic
194 void SetAutoSize(bool enabled, 210 // and normal sizes.
195 const gfx::Size& min_size, 211 void SetSize(const SetSizeParams& params);
196 const gfx::Size& max_size);
197 212
198 bool initialized() const { return initialized_; } 213 bool initialized() const { return initialized_; }
199 214
200 content::WebContents* embedder_web_contents() const { 215 content::WebContents* embedder_web_contents() const {
201 return attached() ? owner_web_contents_ : NULL; 216 return attached() ? owner_web_contents_ : NULL;
202 } 217 }
203 218
204 content::WebContents* owner_web_contents() const { 219 content::WebContents* owner_web_contents() const {
205 return owner_web_contents_; 220 return owner_web_contents_;
206 } 221 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 void SendQueuedEvents(); 310 void SendQueuedEvents();
296 311
297 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, 312 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params,
298 const WebContentsCreatedCallback& callback, 313 const WebContentsCreatedCallback& callback,
299 content::WebContents* guest_web_contents); 314 content::WebContents* guest_web_contents);
300 315
301 // Dispatches the onResize event to the embedder. 316 // Dispatches the onResize event to the embedder.
302 void DispatchOnResizeEvent(const gfx::Size& old_size, 317 void DispatchOnResizeEvent(const gfx::Size& old_size,
303 const gfx::Size& new_size); 318 const gfx::Size& new_size);
304 319
305 void SetUpAutoSize(const base::DictionaryValue& params); 320 void SetUpSizing(const base::DictionaryValue& params);
306 321
307 void StartTrackingEmbedderZoomLevel(); 322 void StartTrackingEmbedderZoomLevel();
308 void StopTrackingEmbedderZoomLevel(); 323 void StopTrackingEmbedderZoomLevel();
309 324
310 static void RegisterGuestViewTypes(); 325 static void RegisterGuestViewTypes();
311 326
312 // WebContentsObserver implementation. 327 // WebContentsObserver implementation.
313 void DidStopLoading(content::RenderViewHost* render_view_host) final; 328 void DidStopLoading(content::RenderViewHost* render_view_host) final;
314 void RenderViewReady() final; 329 void RenderViewReady() final;
315 void WebContentsDestroyed() final; 330 void WebContentsDestroyed() final;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 scoped_ptr<base::DictionaryValue> attach_params_; 382 scoped_ptr<base::DictionaryValue> attach_params_;
368 383
369 // This observer ensures that this guest self-destructs if the embedder goes 384 // This observer ensures that this guest self-destructs if the embedder goes
370 // away. 385 // away.
371 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; 386 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_;
372 387
373 // This observer ensures that if the guest is unattached and its opener goes 388 // This observer ensures that if the guest is unattached and its opener goes
374 // away then this guest also self-destructs. 389 // away then this guest also self-destructs.
375 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; 390 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_;
376 391
377 // The size of the container element.
378 gfx::Size element_size_;
379
380 // The size of the guest content. Note: In autosize mode, the container 392 // The size of the guest content. Note: In autosize mode, the container
381 // element may not match the size of the guest. 393 // element may not match the size of the guest.
382 gfx::Size guest_size_; 394 gfx::Size guest_size_;
383 395
384 // A pointer to the guest_sizer. 396 // A pointer to the guest_sizer.
385 content::GuestSizer* guest_sizer_; 397 content::GuestSizer* guest_sizer_;
386 398
387 // Indicates whether autosize mode is enabled or not. 399 // Indicates whether autosize mode is enabled or not.
388 bool auto_size_enabled_; 400 bool auto_size_enabled_;
389 401
390 // The maximum size constraints of the container element in autosize mode. 402 // The maximum size constraints of the container element in autosize mode.
391 gfx::Size max_auto_size_; 403 gfx::Size max_auto_size_;
392 404
393 // The minimum size constraints of the container element in autosize mode. 405 // The minimum size constraints of the container element in autosize mode.
394 gfx::Size min_auto_size_; 406 gfx::Size min_auto_size_;
395 407
408 // The size that will be used when autosize mode is disabled.
409 gfx::Size normal_size_;
410
396 // Whether the guest view is inside a plugin document. 411 // Whether the guest view is inside a plugin document.
397 bool is_full_page_plugin_; 412 bool is_full_page_plugin_;
398 413
399 // This is used to ensure pending tasks will not fire after this object is 414 // This is used to ensure pending tasks will not fire after this object is
400 // destroyed. 415 // destroyed.
401 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; 416 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_;
402 417
403 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); 418 DISALLOW_COPY_AND_ASSIGN(GuestViewBase);
404 }; 419 };
405 420
406 } // namespace extensions 421 } // namespace extensions
407 422
408 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 423 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698