[email protected] | 945604a | 2014-04-28 12:29:59 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 5 | #ifndef COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_ |
| 6 | #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_ |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 7 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 8 | #include <queue> |
| 9 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 10 | #include "base/macros.h" |
dcheng | 25889412 | 2016-02-02 17:42:24 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 13 | #include "base/values.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 14 | #include "components/guest_view/common/guest_view_constants.h" |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 15 | #include "components/ui/zoom/zoom_observer.h" |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 16 | #include "content/public/browser/browser_plugin_guest_delegate.h" |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 17 | #include "content/public/browser/guest_host.h" |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 18 | #include "content/public/browser/render_process_host_observer.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 19 | #include "content/public/browser/web_contents.h" |
[email protected] | aec80ed | 2014-05-27 00:01:15 | [diff] [blame] | 20 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 21 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 22 | |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 23 | struct RendererContentSettingRules; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 24 | |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 25 | namespace guest_view { |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 26 | |
fsamuel | b535c74 | 2015-04-15 18:56:54 | [diff] [blame] | 27 | class GuestViewEvent; |
| 28 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 29 | // A struct of parameters for SetSize(). The parameters are all declared as |
| 30 | // scoped pointers since they are all optional. Null pointers indicate that the |
| 31 | // parameter has not been provided, and the last used value should be used. Note |
| 32 | // that when |enable_auto_size| is true, providing |normal_size| is not |
| 33 | // meaningful. This is because the normal size of the guestview is overridden |
| 34 | // whenever autosizing occurs. |
| 35 | struct SetSizeParams { |
| 36 | SetSizeParams(); |
| 37 | ~SetSizeParams(); |
| 38 | |
| 39 | scoped_ptr<bool> enable_auto_size; |
| 40 | scoped_ptr<gfx::Size> min_size; |
| 41 | scoped_ptr<gfx::Size> max_size; |
| 42 | scoped_ptr<gfx::Size> normal_size; |
| 43 | }; |
| 44 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 45 | // A GuestViewBase is the base class browser-side API implementation for a |
| 46 | // <*view> tag. GuestViewBase maintains an association between a guest |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 47 | // WebContents and an owner WebContents. It receives events issued from |
| 48 | // the guest and relays them to the owner. GuestViewBase tracks the lifetime |
| 49 | // of its owner. A GuestViewBase's owner is referred to as an embedder if |
| 50 | // it is attached to a container within the owner's WebContents. |
[email protected] | aec80ed | 2014-05-27 00:01:15 | [diff] [blame] | 51 | class GuestViewBase : public content::BrowserPluginGuestDelegate, |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 52 | public content::WebContentsDelegate, |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 53 | public content::WebContentsObserver, |
| 54 | public ui_zoom::ZoomObserver { |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 55 | public: |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 56 | // Returns a *ViewGuest if this GuestView is of the given view type. |
| 57 | template <typename T> |
| 58 | T* As() { |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 59 | if (IsViewType(T::Type)) |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 60 | return static_cast<T*>(this); |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 61 | |
fsamuel | 003b8cc | 2015-01-27 15:08:38 | [diff] [blame] | 62 | return nullptr; |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 63 | } |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 64 | |
paulmeyer | 598af4c | 2015-06-10 20:11:58 | [diff] [blame] | 65 | // Cleans up state when this GuestView is being destroyed. |
| 66 | // Note that this cannot be done in the destructor since a GuestView could |
| 67 | // potentially be created and destroyed in JavaScript before getting a |
| 68 | // GuestViewBase instance. This method can be hidden by a CleanUp() method in |
| 69 | // a derived class, in which case the derived method should call this one. |
paulmeyer | bc4600a | 2015-07-21 15:41:31 | [diff] [blame] | 70 | static void CleanUp(content::BrowserContext* browser_context, |
| 71 | int embedder_process_id, |
| 72 | int view_instance_id); |
paulmeyer | 598af4c | 2015-06-10 20:11:58 | [diff] [blame] | 73 | |
lazyboy | e2021e6 | 2015-03-20 22:17:34 | [diff] [blame] | 74 | static GuestViewBase* FromWebContents( |
| 75 | const content::WebContents* web_contents); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 76 | |
fsamuel | 4a5c599 | 2015-01-20 19:21:49 | [diff] [blame] | 77 | static GuestViewBase* From(int owner_process_id, int instance_id); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 78 | |
paulmeyer | f8bf5839 | 2015-04-21 20:56:28 | [diff] [blame] | 79 | // Given a |web_contents|, returns the top level owner WebContents. If |
| 80 | // |web_contents| does not belong to a GuestView, it will be returned |
| 81 | // unchanged. |
| 82 | static content::WebContents* GetTopLevelWebContents( |
| 83 | content::WebContents* web_contents); |
| 84 | |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 85 | static bool IsGuest(content::WebContents* web_contents); |
| 86 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 87 | // Returns the name of the derived type of this GuestView. |
[email protected] | 38fe437 | 2014-05-01 08:38:32 | [diff] [blame] | 88 | virtual const char* GetViewType() const = 0; |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 89 | |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 90 | // This method queries whether autosize is supported for this particular view. |
| 91 | // By default, autosize is not supported. Derived classes can override this |
| 92 | // behavior to support autosize. |
| 93 | virtual bool IsAutoSizeSupported() const; |
| 94 | |
kalman | c2c7884 | 2015-01-09 23:57:35 | [diff] [blame] | 95 | // This method queries whether preferred size events are enabled for this |
| 96 | // view. By default, preferred size events are disabled, since they add a |
| 97 | // small amount of overhead. |
| 98 | virtual bool IsPreferredSizeModeEnabled() const; |
| 99 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 100 | // This indicates whether zoom should propagate from the embedder to the guest |
| 101 | // content. |
fsamuel | 67993a9 | 2014-12-17 01:33:20 | [diff] [blame] | 102 | virtual bool ZoomPropagatesFromEmbedderToGuest() const; |
| 103 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 104 | // Access to guest views are determined by the availability of the internal |
| 105 | // extension API used to implement the guest view. |
[email protected] | 755211fe | 2014-08-08 19:01:49 | [diff] [blame] | 106 | // |
| 107 | // This should be the name of the API as it appears in the _api_features.json |
| 108 | // file. |
fsamuel | 99492be | 2014-08-28 03:50:27 | [diff] [blame] | 109 | virtual const char* GetAPINamespace() const = 0; |
| 110 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 111 | // This method is the task prefix to show for a task produced by this |
| 112 | // GuestViewBase's derived type. |
fsamuel | 99492be | 2014-08-28 03:50:27 | [diff] [blame] | 113 | virtual int GetTaskPrefix() const = 0; |
[email protected] | a2be2f11 | 2014-07-12 01:10:05 | [diff] [blame] | 114 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 115 | // Dispatches an event to the guest proxy. |
dcheng | 25889412 | 2016-02-02 17:42:24 | [diff] [blame] | 116 | void DispatchEventToGuestProxy(scoped_ptr<GuestViewEvent> event); |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 117 | |
| 118 | // Dispatches an event to the view. |
dcheng | 25889412 | 2016-02-02 17:42:24 | [diff] [blame] | 119 | void DispatchEventToView(scoped_ptr<GuestViewEvent> event); |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 120 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 121 | // This creates a WebContents and initializes |this| GuestViewBase to use the |
| 122 | // newly created WebContents. |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 123 | using WebContentsCreatedCallback = |
| 124 | base::Callback<void(content::WebContents*)>; |
fsamuel | 840c1af | 2014-12-24 01:39:41 | [diff] [blame] | 125 | void Init(const base::DictionaryValue& create_params, |
[email protected] | 38177c3 | 2014-06-25 23:20:23 | [diff] [blame] | 126 | const WebContentsCreatedCallback& callback); |
[email protected] | a868c6c | 2014-06-04 13:07:43 | [diff] [blame] | 127 | |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 128 | void InitWithWebContents(const base::DictionaryValue& create_params, |
| 129 | content::WebContents* guest_web_contents); |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 130 | |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 131 | bool IsViewType(const char* const view_type) const { |
| 132 | return !strcmp(GetViewType(), view_type); |
| 133 | } |
| 134 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 135 | // Used to toggle autosize mode for this GuestView, and set both the automatic |
| 136 | // and normal sizes. |
| 137 | void SetSize(const SetSizeParams& params); |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 138 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 139 | bool initialized() const { return initialized_; } |
| 140 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 141 | content::WebContents* embedder_web_contents() const { |
fsamuel | 003b8cc | 2015-01-27 15:08:38 | [diff] [blame] | 142 | return attached() ? owner_web_contents_ : nullptr; |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | content::WebContents* owner_web_contents() const { |
| 146 | return owner_web_contents_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 147 | } |
| 148 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 149 | content::GuestHost* host() const { |
| 150 | return guest_host_; |
| 151 | } |
| 152 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 153 | // Returns the parameters associated with the element hosting this GuestView |
| 154 | // passed in from JavaScript. |
| 155 | base::DictionaryValue* attach_params() const { return attach_params_.get(); } |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 156 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 157 | // Returns whether this guest has an associated embedder. |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 158 | bool attached() const { |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 159 | return element_instance_id_ != kInstanceIDNone; |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 160 | } |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 161 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 162 | // Returns the instance ID of the <*view> element. |
| 163 | int view_instance_id() const { return view_instance_id_; } |
| 164 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 165 | // Returns the instance ID of this GuestViewBase. |
| 166 | int guest_instance_id() const { return guest_instance_id_; } |
| 167 | |
raymes | 9d460f9 | 2014-12-23 04:13:55 | [diff] [blame] | 168 | // Returns the instance ID of the GuestViewBase's element. |
| 169 | int element_instance_id() const { return element_instance_id_; } |
| 170 | |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 171 | bool can_owner_receive_events() const { return !!view_instance_id_; } |
| 172 | |
paulmeyer | 1f8c6fa6 | 2015-05-05 23:36:01 | [diff] [blame] | 173 | gfx::Size size() const { return guest_size_; } |
| 174 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 175 | // Returns the user browser context of the embedder. |
| 176 | content::BrowserContext* browser_context() const { return browser_context_; } |
| 177 | |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 178 | GuestViewBase* GetOpener() const { |
| 179 | return opener_.get(); |
| 180 | } |
| 181 | |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 182 | // Returns the URL of the owner WebContents. |
| 183 | const GURL& GetOwnerSiteURL() const; |
| 184 | |
fsamuel | 9a3c81e | 2015-04-24 12:30:11 | [diff] [blame] | 185 | // Returns the host of the owner WebContents. For extensions, this is the |
| 186 | // extension ID. |
| 187 | std::string owner_host() const { return owner_host_; } |
| 188 | |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 189 | // Whether the guest view is inside a plugin document. |
paulmeyer | cd7a39a | 2015-04-11 02:14:39 | [diff] [blame] | 190 | bool is_full_page_plugin() const { return is_full_page_plugin_; } |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 191 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 192 | // Returns the routing ID of the guest proxy in the owner's renderer process. |
| 193 | // This value is only valid after attachment or first navigation. |
| 194 | int proxy_routing_id() const { return guest_proxy_routing_id_; } |
| 195 | |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 196 | // Destroy this guest. |
| 197 | void Destroy(); |
| 198 | |
| 199 | // Saves the attach state of the custom element hosting this GuestView. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 200 | void SetAttachParams(const base::DictionaryValue& params); |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 201 | void SetOpener(GuestViewBase* opener); |
| 202 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 203 | protected: |
fsamuel | c75dc1d | 2015-01-27 06:22:15 | [diff] [blame] | 204 | explicit GuestViewBase(content::WebContents* owner_web_contents); |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 205 | |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 206 | ~GuestViewBase() override; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 207 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 208 | // BrowserPluginGuestDelegate implementation. |
| 209 | void SetContextMenuPosition(const gfx::Point& position) override; |
| 210 | |
| 211 | // WebContentsDelegate implementation. |
| 212 | void HandleKeyboardEvent( |
| 213 | content::WebContents* source, |
| 214 | const content::NativeWebKeyboardEvent& event) override; |
| 215 | bool PreHandleGestureEvent(content::WebContents* source, |
| 216 | const blink::WebGestureEvent& event) override; |
| 217 | void FindReply(content::WebContents* source, |
| 218 | int request_id, |
| 219 | int number_of_matches, |
| 220 | const gfx::Rect& selection_rect, |
| 221 | int active_match_ordinal, |
| 222 | bool final_update) override; |
| 223 | |
| 224 | // WebContentsObserver implementation. |
| 225 | void DidNavigateMainFrame( |
| 226 | const content::LoadCommittedDetails& details, |
| 227 | const content::FrameNavigateParams& params) override; |
| 228 | |
| 229 | // Given a set of initialization parameters, a concrete subclass of |
| 230 | // GuestViewBase can create a specialized WebContents that it returns back to |
| 231 | // GuestViewBase. |
| 232 | virtual void CreateWebContents( |
| 233 | const base::DictionaryValue& create_params, |
| 234 | const WebContentsCreatedCallback& callback) = 0; |
| 235 | |
| 236 | // This method is called after the guest has been attached to an embedder and |
| 237 | // suspended resource loads have been resumed. |
| 238 | // |
| 239 | // This method can be overriden by subclasses. This gives the derived class |
| 240 | // an opportunity to perform setup actions after attachment. |
| 241 | virtual void DidAttachToEmbedder() {} |
| 242 | |
| 243 | // This method is called after this GuestViewBase has been initiated. |
| 244 | // |
| 245 | // This gives the derived class an opportunity to perform additional |
| 246 | // initialization. |
| 247 | virtual void DidInitialize(const base::DictionaryValue& create_params) {} |
| 248 | |
| 249 | // This method is called when embedder WebContents's fullscreen is toggled. |
| 250 | // |
| 251 | // If the guest asked the embedder to enter fullscreen, the guest uses this |
| 252 | // signal to exit fullscreen state. |
| 253 | virtual void EmbedderFullscreenToggled(bool entered_fullscreen) {} |
| 254 | |
| 255 | // This method is called when the initial set of frames within the page have |
| 256 | // completed loading. |
| 257 | virtual void GuestViewDidStopLoading() {} |
| 258 | |
| 259 | // This method is called when the guest WebContents has been destroyed. This |
| 260 | // object will be destroyed after this call returns. |
| 261 | // |
| 262 | // This gives the derived class an opportunity to perform some cleanup. |
| 263 | virtual void GuestDestroyed() {} |
| 264 | |
| 265 | // This method is invoked when the guest RenderView is ready, e.g. because we |
| 266 | // recreated it after a crash or after reattachment. |
| 267 | // |
| 268 | // This gives the derived class an opportunity to perform some initialization |
| 269 | // work. |
| 270 | virtual void GuestReady() {} |
| 271 | |
| 272 | // This method is called when the guest's zoom changes. |
| 273 | virtual void GuestZoomChanged(double old_zoom_level, double new_zoom_level) {} |
| 274 | |
| 275 | // This method is invoked when the contents auto-resized to give the container |
| 276 | // an opportunity to match it if it wishes. |
| 277 | // |
| 278 | // This gives the derived class an opportunity to inform its container element |
| 279 | // or perform other actions. |
| 280 | virtual void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, |
| 281 | const gfx::Size& new_size) {} |
| 282 | |
| 283 | // This method is invoked when the contents preferred size changes. This will |
| 284 | // only ever fire if IsPreferredSizeSupported returns true. |
| 285 | virtual void OnPreferredSizeChanged(const gfx::Size& pref_size) {} |
| 286 | |
| 287 | // Signals that the guest view is ready. The default implementation signals |
| 288 | // immediately, but derived class can override this if they need to do |
| 289 | // asynchronous setup. |
| 290 | virtual void SignalWhenReady(const base::Closure& callback); |
| 291 | |
| 292 | // Returns true if this guest should handle find requests for its |
| 293 | // embedder. This should generally be true for guests that make up the |
| 294 | // entirety of the embedder's content. |
| 295 | virtual bool ShouldHandleFindRequestsForEmbedder() const; |
| 296 | |
| 297 | // This method is called immediately before suspended resource loads have been |
| 298 | // resumed on attachment to an embedder. |
| 299 | // |
| 300 | // This method can be overriden by subclasses. This gives the derived class |
| 301 | // an opportunity to perform setup actions before attachment. |
| 302 | virtual void WillAttachToEmbedder() {} |
| 303 | |
| 304 | // This method is called when the guest WebContents is about to be destroyed. |
| 305 | // |
| 306 | // This gives the derived class an opportunity to perform some cleanup prior |
| 307 | // to destruction. |
| 308 | virtual void WillDestroy() {} |
| 309 | |
| 310 | void LoadURLWithParams( |
| 311 | const content::NavigationController::LoadURLParams& load_params); |
| 312 | |
paulmeyer | f018aaa | 2015-02-19 19:55:31 | [diff] [blame] | 313 | // Convert sizes in pixels from logical to physical numbers of pixels. |
| 314 | // Note that a size can consist of a fractional number of logical pixels |
| 315 | // (hence |logical_pixels| is represented as a double), but will always |
| 316 | // consist of an integral number of physical pixels (hence the return value |
| 317 | // is represented as an int). |
paulmeyer | cd7a39a | 2015-04-11 02:14:39 | [diff] [blame] | 318 | int LogicalPixelsToPhysicalPixels(double logical_pixels) const; |
paulmeyer | f018aaa | 2015-02-19 19:55:31 | [diff] [blame] | 319 | |
| 320 | // Convert sizes in pixels from physical to logical numbers of pixels. |
| 321 | // Note that a size can consist of a fractional number of logical pixels |
| 322 | // (hence the return value is represented as a double), but will always |
| 323 | // consist of an integral number of physical pixels (hence |physical_pixels| |
| 324 | // is represented as an int). |
paulmeyer | cd7a39a | 2015-04-11 02:14:39 | [diff] [blame] | 325 | double PhysicalPixelsToLogicalPixels(int physical_pixels) const; |
paulmeyer | f018aaa | 2015-02-19 19:55:31 | [diff] [blame] | 326 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 327 | void SetGuestZoomLevelToMatchEmbedder(); |
| 328 | |
| 329 | private: |
| 330 | friend class GuestViewMessageFilter; |
| 331 | |
| 332 | class OwnerContentsObserver; |
| 333 | class OpenerLifetimeObserver; |
| 334 | |
| 335 | // BrowserPluginGuestDelegate implementation. |
| 336 | content::WebContents* CreateNewGuestWindow( |
| 337 | const content::WebContents::CreateParams& create_params) final; |
| 338 | void DidAttach(int guest_proxy_routing_id) final; |
| 339 | void DidDetach() final; |
| 340 | content::WebContents* GetOwnerWebContents() const final; |
| 341 | bool HandleFindForEmbedder(int request_id, |
| 342 | const base::string16& search_text, |
| 343 | const blink::WebFindOptions& options) final; |
| 344 | bool HandleStopFindingForEmbedder(content::StopFindAction action) final; |
| 345 | void GuestSizeChanged(const gfx::Size& new_size) final; |
| 346 | void SetGuestHost(content::GuestHost* guest_host) final; |
| 347 | void WillAttach(content::WebContents* embedder_web_contents, |
| 348 | int browser_plugin_instance_id, |
| 349 | bool is_full_page_plugin, |
| 350 | const base::Closure& callback) final; |
fsamuel | 4a1650f | 2015-01-23 21:57:49 | [diff] [blame] | 351 | |
| 352 | // WebContentsDelegate implementation. |
| 353 | void ActivateContents(content::WebContents* contents) final; |
fsamuel | 67ef1b0 | 2015-01-30 22:09:22 | [diff] [blame] | 354 | void ContentsMouseEvent(content::WebContents* source, |
| 355 | const gfx::Point& location, |
mgiuca | 1c92cab4 | 2016-01-07 03:18:27 | [diff] [blame] | 356 | bool motion, |
| 357 | bool exited) final; |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 358 | void ContentsZoomChange(bool zoom_in) final; |
fsamuel | 67ef1b0 | 2015-01-30 22:09:22 | [diff] [blame] | 359 | void LoadingStateChanged(content::WebContents* source, |
| 360 | bool to_different_document) final; |
fsamuel | 9549ee3 | 2015-01-31 00:09:30 | [diff] [blame] | 361 | content::ColorChooser* OpenColorChooser( |
| 362 | content::WebContents* web_contents, |
| 363 | SkColor color, |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 364 | const std::vector<content::ColorSuggestion>& suggestions) final; |
lazyboy | a920682 | 2015-09-16 20:07:20 | [diff] [blame] | 365 | void ResizeDueToAutoResize(content::WebContents* web_contents, |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 366 | const gfx::Size& new_size) final; |
fsamuel | 4a1650f | 2015-01-23 21:57:49 | [diff] [blame] | 367 | void RunFileChooser(content::WebContents* web_contents, |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 368 | const content::FileChooserParams& params) final; |
fsamuel | 4a1650f | 2015-01-23 21:57:49 | [diff] [blame] | 369 | bool ShouldFocusPageAfterCrash() final; |
fsamuel | 4a1650f | 2015-01-23 21:57:49 | [diff] [blame] | 370 | void UpdatePreferredSize(content::WebContents* web_contents, |
| 371 | const gfx::Size& pref_size) final; |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 372 | void UpdateTargetURL(content::WebContents* source, const GURL& url) final; |
| 373 | bool ShouldResumeRequestsForCreatedWindow() final; |
fsamuel | 4a1650f | 2015-01-23 21:57:49 | [diff] [blame] | 374 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 375 | // WebContentsObserver implementation. |
| 376 | void DidStopLoading() final; |
| 377 | void RenderViewReady() final; |
| 378 | void WebContentsDestroyed() final; |
wjmaclean | d99eafd | 2015-03-26 15:27:17 | [diff] [blame] | 379 | |
paulmeyer | d7523c2b | 2015-10-21 22:58:05 | [diff] [blame] | 380 | // ui_zoom::ZoomObserver implementation. |
| 381 | void OnZoomChanged( |
| 382 | const ui_zoom::ZoomController::ZoomChangedEventData& data) final; |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 383 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 384 | void SendQueuedEvents(); |
| 385 | |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 386 | void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, |
| 387 | const WebContentsCreatedCallback& callback, |
[email protected] | 3d888fa | 2014-07-11 19:27:16 | [diff] [blame] | 388 | content::WebContents* guest_web_contents); |
[email protected] | 38177c3 | 2014-06-25 23:20:23 | [diff] [blame] | 389 | |
paulmeyer | 1b61eb24 | 2015-01-22 19:13:00 | [diff] [blame] | 390 | // Dispatches the onResize event to the embedder. |
| 391 | void DispatchOnResizeEvent(const gfx::Size& old_size, |
| 392 | const gfx::Size& new_size); |
| 393 | |
paulmeyer | cd7a39a | 2015-04-11 02:14:39 | [diff] [blame] | 394 | // Returns the default size of the guestview. |
| 395 | gfx::Size GetDefaultSize() const; |
| 396 | |
paulmeyer | 1451fda | 2015-02-18 14:30:36 | [diff] [blame] | 397 | // Get the zoom factor for the embedder's web contents. |
paulmeyer | cd7a39a | 2015-04-11 02:14:39 | [diff] [blame] | 398 | double GetEmbedderZoomFactor() const; |
paulmeyer | 1451fda | 2015-02-18 14:30:36 | [diff] [blame] | 399 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 400 | void SetUpSizing(const base::DictionaryValue& params); |
paulmeyer | 70fcd54 | 2015-01-09 19:26:54 | [diff] [blame] | 401 | |
fsamuel | 67993a9 | 2014-12-17 01:33:20 | [diff] [blame] | 402 | void StartTrackingEmbedderZoomLevel(); |
| 403 | void StopTrackingEmbedderZoomLevel(); |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 404 | |
lazyboy | a920682 | 2015-09-16 20:07:20 | [diff] [blame] | 405 | void UpdateGuestSize(const gfx::Size& new_size, bool due_to_auto_resize); |
| 406 | |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 407 | // This guest tracks the lifetime of the WebContents specified by |
| 408 | // |owner_web_contents_|. If |owner_web_contents_| is destroyed then this |
| 409 | // guest will also self-destruct. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 410 | content::WebContents* owner_web_contents_; |
fsamuel | 9a3c81e | 2015-04-24 12:30:11 | [diff] [blame] | 411 | std::string owner_host_; |
fsamuel | 09525e3 | 2015-01-21 22:23:39 | [diff] [blame] | 412 | content::BrowserContext* const browser_context_; |
fsamuel | 212c6da | 2014-09-18 16:16:15 | [diff] [blame] | 413 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 414 | // |guest_instance_id_| is a profile-wide unique identifier for a guest |
| 415 | // WebContents. |
| 416 | const int guest_instance_id_; |
fsamuel | 212c6da | 2014-09-18 16:16:15 | [diff] [blame] | 417 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 418 | // |view_instance_id_| is an identifier that's unique within a particular |
| 419 | // embedder RenderViewHost for a particular <*view> instance. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 420 | int view_instance_id_; |
| 421 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 422 | // |element_instance_id_| is an identifer that's unique to a particular |
fsamuel | 212c6da | 2014-09-18 16:16:15 | [diff] [blame] | 423 | // GuestViewContainer element. |
| 424 | int element_instance_id_; |
| 425 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 426 | // |initialized_| indicates whether GuestViewBase::Init has been called for |
| 427 | // this object. |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 428 | bool initialized_; |
| 429 | |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 430 | // Indicates that this guest is in the process of being destroyed. |
| 431 | bool is_being_destroyed_; |
| 432 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 433 | // This is a queue of Events that are destined to be sent to the embedder once |
| 434 | // the guest is attached to a particular embedder. |
dcheng | 25889412 | 2016-02-02 17:42:24 | [diff] [blame] | 435 | std::deque<scoped_ptr<GuestViewEvent>> pending_events_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 436 | |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 437 | // The opener guest view. |
| 438 | base::WeakPtr<GuestViewBase> opener_; |
| 439 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 440 | // The parameters associated with the element hosting this GuestView that |
| 441 | // are passed in from JavaScript. This will typically be the view instance ID, |
| 442 | // and element-specific parameters. These parameters are passed along to new |
| 443 | // guests that are created from this guest. |
| 444 | scoped_ptr<base::DictionaryValue> attach_params_; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 445 | |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 446 | // This observer ensures that this guest self-destructs if the embedder goes |
| 447 | // away. |
lazyboy | 6d745d6 | 2015-03-19 03:21:01 | [diff] [blame] | 448 | scoped_ptr<OwnerContentsObserver> owner_contents_observer_; |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 449 | |
| 450 | // This observer ensures that if the guest is unattached and its opener goes |
| 451 | // away then this guest also self-destructs. |
| 452 | scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 453 | |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 454 | // The size of the guest content. Note: In autosize mode, the container |
| 455 | // element may not match the size of the guest. |
| 456 | gfx::Size guest_size_; |
| 457 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 458 | // A pointer to the guest_host. |
| 459 | content::GuestHost* guest_host_; |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 460 | |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 461 | // Indicates whether autosize mode is enabled or not. |
| 462 | bool auto_size_enabled_; |
| 463 | |
| 464 | // The maximum size constraints of the container element in autosize mode. |
| 465 | gfx::Size max_auto_size_; |
| 466 | |
| 467 | // The minimum size constraints of the container element in autosize mode. |
| 468 | gfx::Size min_auto_size_; |
| 469 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 470 | // The size that will be used when autosize mode is disabled. |
| 471 | gfx::Size normal_size_; |
| 472 | |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 473 | // Whether the guest view is inside a plugin document. |
| 474 | bool is_full_page_plugin_; |
| 475 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 476 | // The routing ID of the proxy to the guest in the owner's renderer process. |
| 477 | int guest_proxy_routing_id_; |
| 478 | |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 479 | // This is used to ensure pending tasks will not fire after this object is |
| 480 | // destroyed. |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 481 | base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 482 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 483 | DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 484 | }; |
| 485 | |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 486 | } // namespace guest_view |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 487 | |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 488 | #endif // COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_BASE_H_ |