OLD | NEW |
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // newly created WebContents. | 198 // newly created WebContents. |
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(content::WebContents* guest_web_contents); | 202 void InitWithWebContents(content::WebContents* guest_web_contents); |
187 | 203 |
188 bool IsViewType(const char* const view_type) const { | 204 bool IsViewType(const char* const view_type) const { |
189 return !strcmp(GetViewType(), view_type); | 205 return !strcmp(GetViewType(), view_type); |
190 } | 206 } |
191 | 207 |
192 // Toggles autosize mode for this GuestView. | 208 // Used to toggle autosize mode for this GuestView, and set both the automatic |
193 void SetAutoSize(bool enabled, | 209 // and normal sizes. |
194 const gfx::Size& min_size, | 210 void SetSize(const SetSizeParams& params); |
195 const gfx::Size& max_size); | |
196 | 211 |
197 bool initialized() const { return initialized_; } | 212 bool initialized() const { return initialized_; } |
198 | 213 |
199 content::WebContents* embedder_web_contents() const { | 214 content::WebContents* embedder_web_contents() const { |
200 return attached() ? owner_web_contents_ : NULL; | 215 return attached() ? owner_web_contents_ : NULL; |
201 } | 216 } |
202 | 217 |
203 content::WebContents* owner_web_contents() const { | 218 content::WebContents* owner_web_contents() const { |
204 return owner_web_contents_; | 219 return owner_web_contents_; |
205 } | 220 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 private: | 295 private: |
281 class OwnerLifetimeObserver; | 296 class OwnerLifetimeObserver; |
282 | 297 |
283 class OpenerLifetimeObserver; | 298 class OpenerLifetimeObserver; |
284 | 299 |
285 void SendQueuedEvents(); | 300 void SendQueuedEvents(); |
286 | 301 |
287 void CompleteInit(const WebContentsCreatedCallback& callback, | 302 void CompleteInit(const WebContentsCreatedCallback& callback, |
288 content::WebContents* guest_web_contents); | 303 content::WebContents* guest_web_contents); |
289 | 304 |
290 void SetUpAutoSize(); | 305 void SetUpSizing(); |
291 | 306 |
292 void StartTrackingEmbedderZoomLevel(); | 307 void StartTrackingEmbedderZoomLevel(); |
293 void StopTrackingEmbedderZoomLevel(); | 308 void StopTrackingEmbedderZoomLevel(); |
294 | 309 |
295 static void RegisterGuestViewTypes(); | 310 static void RegisterGuestViewTypes(); |
296 | 311 |
297 // WebContentsObserver implementation. | 312 // WebContentsObserver implementation. |
298 void DidStopLoading(content::RenderViewHost* render_view_host) final; | 313 void DidStopLoading(content::RenderViewHost* render_view_host) final; |
299 void RenderViewReady() final; | 314 void RenderViewReady() final; |
300 void WebContentsDestroyed() final; | 315 void WebContentsDestroyed() final; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 scoped_ptr<base::DictionaryValue> attach_params_; | 367 scoped_ptr<base::DictionaryValue> attach_params_; |
353 | 368 |
354 // This observer ensures that this guest self-destructs if the embedder goes | 369 // This observer ensures that this guest self-destructs if the embedder goes |
355 // away. | 370 // away. |
356 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; | 371 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; |
357 | 372 |
358 // This observer ensures that if the guest is unattached and its opener goes | 373 // This observer ensures that if the guest is unattached and its opener goes |
359 // away then this guest also self-destructs. | 374 // away then this guest also self-destructs. |
360 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; | 375 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; |
361 | 376 |
362 // The size of the container element. | |
363 gfx::Size element_size_; | |
364 | |
365 // The size of the guest content. Note: In autosize mode, the container | 377 // The size of the guest content. Note: In autosize mode, the container |
366 // element may not match the size of the guest. | 378 // element may not match the size of the guest. |
367 gfx::Size guest_size_; | 379 gfx::Size guest_size_; |
368 | 380 |
369 // A pointer to the guest_sizer. | 381 // A pointer to the guest_sizer. |
370 content::GuestSizer* guest_sizer_; | 382 content::GuestSizer* guest_sizer_; |
371 | 383 |
372 // Indicates whether autosize mode is enabled or not. | 384 // Indicates whether autosize mode is enabled or not. |
373 bool auto_size_enabled_; | 385 bool auto_size_enabled_; |
374 | 386 |
375 // The maximum size constraints of the container element in autosize mode. | 387 // The maximum size constraints of the container element in autosize mode. |
376 gfx::Size max_auto_size_; | 388 gfx::Size max_auto_size_; |
377 | 389 |
378 // The minimum size constraints of the container element in autosize mode. | 390 // The minimum size constraints of the container element in autosize mode. |
379 gfx::Size min_auto_size_; | 391 gfx::Size min_auto_size_; |
380 | 392 |
| 393 // The size that will be used when autosize mode is disabled. |
| 394 gfx::Size normal_size_; |
| 395 |
381 // Whether the guest view is inside a plugin document. | 396 // Whether the guest view is inside a plugin document. |
382 bool is_full_page_plugin_; | 397 bool is_full_page_plugin_; |
383 | 398 |
384 // This is used to ensure pending tasks will not fire after this object is | 399 // This is used to ensure pending tasks will not fire after this object is |
385 // destroyed. | 400 // destroyed. |
386 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 401 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
387 | 402 |
388 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 403 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
389 }; | 404 }; |
390 | 405 |
391 } // namespace extensions | 406 } // namespace extensions |
392 | 407 |
393 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 408 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |