[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 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| 6 | #define EXTENSIONS_BROWSER_GUEST_VIEW_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 | |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 11 | #include "base/values.h" |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 12 | #include "components/ui/zoom/zoom_observer.h" |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 13 | #include "content/public/browser/browser_plugin_guest_delegate.h" |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 14 | #include "content/public/browser/guest_sizer.h" |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 15 | #include "content/public/browser/render_process_host_observer.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 16 | #include "content/public/browser/web_contents.h" |
[email protected] | aec80ed | 2014-05-27 00:01:15 | [diff] [blame] | 17 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 18 | #include "content/public/browser/web_contents_observer.h" |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 19 | #include "extensions/common/guest_view/guest_view_constants.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 20 | |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 21 | struct RendererContentSettingRules; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 22 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 23 | namespace extensions { |
| 24 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 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 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 41 | // A GuestViewBase is the base class browser-side API implementation for a |
| 42 | // <*view> tag. GuestViewBase maintains an association between a guest |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 43 | // WebContents and an owner WebContents. It receives events issued from |
| 44 | // the guest and relays them to the owner. GuestViewBase tracks the lifetime |
| 45 | // of its owner. A GuestViewBase's owner is referred to as an embedder if |
| 46 | // it is attached to a container within the owner's WebContents. |
[email protected] | aec80ed | 2014-05-27 00:01:15 | [diff] [blame] | 47 | class GuestViewBase : public content::BrowserPluginGuestDelegate, |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 48 | public content::WebContentsDelegate, |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 49 | public content::WebContentsObserver, |
| 50 | public ui_zoom::ZoomObserver { |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 51 | public: |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 52 | class Event { |
| 53 | public: |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 54 | Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); |
| 55 | ~Event(); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 56 | |
[email protected] | 0aad647 | 2013-12-04 18:25:38 | [diff] [blame] | 57 | const std::string& name() const { return name_; } |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 58 | |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 59 | scoped_ptr<base::DictionaryValue> GetArguments(); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 60 | |
| 61 | private: |
[email protected] | 0aad647 | 2013-12-04 18:25:38 | [diff] [blame] | 62 | const std::string name_; |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 63 | scoped_ptr<base::DictionaryValue> args_; |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 64 | }; |
| 65 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 66 | // Returns a *ViewGuest if this GuestView is of the given view type. |
| 67 | template <typename T> |
| 68 | T* As() { |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 69 | if (IsViewType(T::Type)) |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 70 | return static_cast<T*>(this); |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 71 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 72 | return NULL; |
| 73 | } |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 74 | |
fsamuel | 09525e3 | 2015-01-21 22:23:39 | [diff] [blame] | 75 | using GuestCreationCallback = |
| 76 | base::Callback<GuestViewBase*(content::WebContents*, int)>; |
[email protected] | 71c63dc | 2014-07-21 22:49:53 | [diff] [blame] | 77 | static void RegisterGuestViewType(const std::string& view_type, |
| 78 | const GuestCreationCallback& callback); |
| 79 | |
fsamuel | 09525e3 | 2015-01-21 22:23:39 | [diff] [blame] | 80 | static GuestViewBase* Create(content::WebContents* owner_web_contents, |
[email protected] | 38177c3 | 2014-06-25 23:20:23 | [diff] [blame] | 81 | int guest_instance_id, |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 82 | const std::string& view_type); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 83 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 84 | static GuestViewBase* FromWebContents(content::WebContents* web_contents); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 85 | |
fsamuel | 4a5c599 | 2015-01-20 19:21:49 | [diff] [blame] | 86 | static GuestViewBase* From(int owner_process_id, int instance_id); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 87 | |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 88 | static bool IsGuest(content::WebContents* web_contents); |
| 89 | |
[email protected] | 38fe437 | 2014-05-01 08:38:32 | [diff] [blame] | 90 | virtual const char* GetViewType() const = 0; |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 91 | |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 92 | // This method is called after the guest has been attached to an embedder and |
| 93 | // suspended resource loads have been resumed. |
| 94 | // |
| 95 | // This method can be overriden by subclasses. This gives the derived class |
| 96 | // an opportunity to perform setup actions after attachment. |
| 97 | virtual void DidAttachToEmbedder() {} |
| 98 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 99 | // This method is called after this GuestViewBase has been initiated. |
| 100 | // |
| 101 | // This gives the derived class an opportunity to perform additional |
| 102 | // initialization. |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 103 | virtual void DidInitialize(const base::DictionaryValue& create_params) {} |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 104 | |
| 105 | // This method is called when the initial set of frames within the page have |
| 106 | // completed loading. |
[email protected] | feaa8cf | 2014-05-31 03:57:14 | [diff] [blame] | 107 | virtual void DidStopLoading() {} |
| 108 | |
guohui | 02ca72f2 | 2014-10-23 16:06:45 | [diff] [blame] | 109 | // This method is called before the embedder is destroyed. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 110 | // |owner_web_contents_| should still be valid during this call. This |
guohui | 02ca72f2 | 2014-10-23 16:06:45 | [diff] [blame] | 111 | // allows the derived class to perform some cleanup related to the embedder |
| 112 | // web contents. |
| 113 | virtual void EmbedderWillBeDestroyed() {} |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 114 | |
| 115 | // This method is called when the guest WebContents has been destroyed. This |
| 116 | // object will be destroyed after this call returns. |
| 117 | // |
| 118 | // This gives the derived class an opportunity to perform some cleanup. |
| 119 | virtual void GuestDestroyed() {} |
| 120 | |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 121 | // This method is invoked when the guest RenderView is ready, e.g. because we |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 122 | // recreated it after a crash or after reattachment. |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 123 | // |
| 124 | // This gives the derived class an opportunity to perform some initialization |
| 125 | // work. |
| 126 | virtual void GuestReady() {} |
| 127 | |
| 128 | // This method is invoked when the contents auto-resized to give the container |
| 129 | // an opportunity to match it if it wishes. |
| 130 | // |
| 131 | // This gives the derived class an opportunity to inform its container element |
| 132 | // or perform other actions. |
| 133 | virtual void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, |
| 134 | const gfx::Size& new_size) {} |
| 135 | |
| 136 | // This method queries whether autosize is supported for this particular view. |
| 137 | // By default, autosize is not supported. Derived classes can override this |
| 138 | // behavior to support autosize. |
| 139 | virtual bool IsAutoSizeSupported() const; |
| 140 | |
kalman | c2c7884 | 2015-01-09 23:57:35 | [diff] [blame] | 141 | // This method is invoked when the contents preferred size changes. This will |
| 142 | // only ever fire if IsPreferredSizeSupported returns true. |
| 143 | virtual void OnPreferredSizeChanged(const gfx::Size& pref_size) {} |
| 144 | |
| 145 | // This method queries whether preferred size events are enabled for this |
| 146 | // view. By default, preferred size events are disabled, since they add a |
| 147 | // small amount of overhead. |
| 148 | virtual bool IsPreferredSizeModeEnabled() const; |
| 149 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 150 | // This method queries whether drag-and-drop is enabled for this particular |
| 151 | // view. By default, drag-and-drop is disabled. Derived classes can override |
| 152 | // this behavior to enable drag-and-drop. |
| 153 | virtual bool IsDragAndDropEnabled() const; |
| 154 | |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 155 | // This method is called immediately before suspended resource loads have been |
| 156 | // resumed on attachment to an embedder. |
| 157 | // |
| 158 | // This method can be overriden by subclasses. This gives the derived class |
| 159 | // an opportunity to perform setup actions before attachment. |
| 160 | virtual void WillAttachToEmbedder() {} |
| 161 | |
[email protected] | a868c6c | 2014-06-04 13:07:43 | [diff] [blame] | 162 | // This method is called when the guest WebContents is about to be destroyed. |
| 163 | // |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 164 | // This gives the derived class an opportunity to perform some cleanup prior |
| 165 | // to destruction. |
[email protected] | a868c6c | 2014-06-04 13:07:43 | [diff] [blame] | 166 | virtual void WillDestroy() {} |
| 167 | |
fsamuel | 67993a9 | 2014-12-17 01:33:20 | [diff] [blame] | 168 | // This method is to be implemented by the derived class. This indicates |
| 169 | // whether zoom should propagate from the embedder to the guest content. |
| 170 | virtual bool ZoomPropagatesFromEmbedderToGuest() const; |
| 171 | |
[email protected] | 755211fe | 2014-08-08 19:01:49 | [diff] [blame] | 172 | // This method is to be implemented by the derived class. Access to guest |
| 173 | // views are determined by the availability of the internal extension API |
| 174 | // used to implement the guest view. |
| 175 | // |
| 176 | // This should be the name of the API as it appears in the _api_features.json |
| 177 | // file. |
fsamuel | 99492be | 2014-08-28 03:50:27 | [diff] [blame] | 178 | virtual const char* GetAPINamespace() const = 0; |
| 179 | |
| 180 | // This method is to be implemented by the derived class. This method is the |
| 181 | // task prefix to show for a task produced by this GuestViewBase's derived |
| 182 | // type. |
| 183 | virtual int GetTaskPrefix() const = 0; |
[email protected] | a2be2f11 | 2014-07-12 01:10:05 | [diff] [blame] | 184 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 185 | // This method is to be implemented by the derived class. Given a set of |
| 186 | // initialization parameters, a concrete subclass of GuestViewBase can |
| 187 | // create a specialized WebContents that it returns back to GuestViewBase. |
fsamuel | 09525e3 | 2015-01-21 22:23:39 | [diff] [blame] | 188 | using WebContentsCreatedCallback = |
| 189 | base::Callback<void(content::WebContents*)>; |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 190 | virtual void CreateWebContents( |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 191 | const base::DictionaryValue& create_params, |
| 192 | const WebContentsCreatedCallback& callback) = 0; |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 193 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 194 | // This creates a WebContents and initializes |this| GuestViewBase to use the |
| 195 | // newly created WebContents. |
fsamuel | 840c1af | 2014-12-24 01:39:41 | [diff] [blame] | 196 | void Init(const base::DictionaryValue& create_params, |
[email protected] | 38177c3 | 2014-06-25 23:20:23 | [diff] [blame] | 197 | const WebContentsCreatedCallback& callback); |
[email protected] | a868c6c | 2014-06-04 13:07:43 | [diff] [blame] | 198 | |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 199 | void InitWithWebContents(const base::DictionaryValue& create_params, |
| 200 | content::WebContents* guest_web_contents); |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 201 | |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 202 | bool IsViewType(const char* const view_type) const { |
| 203 | return !strcmp(GetViewType(), view_type); |
| 204 | } |
| 205 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 206 | // Used to toggle autosize mode for this GuestView, and set both the automatic |
| 207 | // and normal sizes. |
| 208 | void SetSize(const SetSizeParams& params); |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 209 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 210 | bool initialized() const { return initialized_; } |
| 211 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 212 | content::WebContents* embedder_web_contents() const { |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 213 | return attached() ? owner_web_contents_ : NULL; |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | content::WebContents* owner_web_contents() const { |
| 217 | return owner_web_contents_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 218 | } |
| 219 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 220 | // Returns the parameters associated with the element hosting this GuestView |
| 221 | // passed in from JavaScript. |
| 222 | base::DictionaryValue* attach_params() const { return attach_params_.get(); } |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 223 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 224 | // Returns whether this guest has an associated embedder. |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 225 | bool attached() const { |
| 226 | return element_instance_id_ != guestview::kInstanceIDNone; |
| 227 | } |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 228 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 229 | // Returns the instance ID of the <*view> element. |
| 230 | int view_instance_id() const { return view_instance_id_; } |
| 231 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 232 | // Returns the instance ID of this GuestViewBase. |
| 233 | int guest_instance_id() const { return guest_instance_id_; } |
| 234 | |
raymes | 9d460f9 | 2014-12-23 04:13:55 | [diff] [blame] | 235 | // Returns the instance ID of the GuestViewBase's element. |
| 236 | int element_instance_id() const { return element_instance_id_; } |
| 237 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 238 | // Returns the extension ID of the embedder. |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 239 | const std::string& owner_extension_id() const { |
| 240 | return owner_extension_id_; |
[email protected] | 880331f97 | 2014-03-05 01:42:53 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Returns whether this GuestView is embedded in an extension/app. |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 244 | bool in_extension() const { return !owner_extension_id_.empty(); } |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 245 | |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 246 | bool can_owner_receive_events() const { return !!view_instance_id_; } |
| 247 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 248 | // Returns the user browser context of the embedder. |
| 249 | content::BrowserContext* browser_context() const { return browser_context_; } |
| 250 | |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 251 | GuestViewBase* GetOpener() const { |
| 252 | return opener_.get(); |
| 253 | } |
| 254 | |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 255 | // Returns the URL of the owner WebContents. |
| 256 | const GURL& GetOwnerSiteURL() const; |
| 257 | |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 258 | // Whether the guest view is inside a plugin document. |
| 259 | bool is_full_page_plugin() { return is_full_page_plugin_; } |
| 260 | |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 261 | // Destroy this guest. |
| 262 | void Destroy(); |
| 263 | |
| 264 | // Saves the attach state of the custom element hosting this GuestView. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 265 | void SetAttachParams(const base::DictionaryValue& params); |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 266 | void SetOpener(GuestViewBase* opener); |
| 267 | |
[email protected] | aec80ed | 2014-05-27 00:01:15 | [diff] [blame] | 268 | // BrowserPluginGuestDelegate implementation. |
fsamuel | fa28471 | 2015-01-15 01:24:53 | [diff] [blame] | 269 | content::WebContents* CreateNewGuestWindow( |
| 270 | const content::WebContents::CreateParams& create_params) final; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 271 | void DidAttach(int guest_proxy_routing_id) final; |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 272 | void DidDetach() final; |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 273 | void ElementSizeChanged(const gfx::Size& size) final; |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 274 | content::WebContents* GetOwnerWebContents() const final; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 275 | void GuestSizeChanged(const gfx::Size& old_size, |
| 276 | const gfx::Size& new_size) final; |
| 277 | void RegisterDestructionCallback(const DestructionCallback& callback) final; |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 278 | void SetGuestSizer(content::GuestSizer* guest_sizer) final; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 279 | void WillAttach(content::WebContents* embedder_web_contents, |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 280 | int browser_plugin_instance_id, |
| 281 | bool is_full_page_plugin) final; |
[email protected] | a868c6c | 2014-06-04 13:07:43 | [diff] [blame] | 282 | |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 283 | // ui_zoom::ZoomObserver implementation. |
| 284 | void OnZoomChanged( |
| 285 | const ui_zoom::ZoomController::ZoomChangedEventData& data) override; |
| 286 | |
paulmeyer | 1b61eb24 | 2015-01-22 19:13:00 | [diff] [blame] | 287 | // Dispatches an event to the guest proxy. |
| 288 | void DispatchEventToGuestProxy(Event* event); |
| 289 | |
| 290 | // Dispatches an event to the view. |
| 291 | void DispatchEventToView(Event* event); |
[email protected] | 7adb26a7 | 2014-07-09 17:44:35 | [diff] [blame] | 292 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 293 | protected: |
fsamuel | 09525e3 | 2015-01-21 22:23:39 | [diff] [blame] | 294 | GuestViewBase(content::WebContents* owner_web_contents, |
[email protected] | 38177c3 | 2014-06-25 23:20:23 | [diff] [blame] | 295 | int guest_instance_id); |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 296 | |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 297 | ~GuestViewBase() override; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 298 | |
fsamuel | 4a1650f | 2015-01-23 21:57:49 | [diff] [blame^] | 299 | // WebContentsObserver implementation. |
| 300 | void DidStopLoading(content::RenderViewHost* render_view_host) final; |
| 301 | void RenderViewReady() final; |
| 302 | void WebContentsDestroyed() final; |
| 303 | |
| 304 | // WebContentsDelegate implementation. |
| 305 | void ActivateContents(content::WebContents* contents) final; |
| 306 | void DeactivateContents(content::WebContents* contents) final; |
| 307 | void ContentsZoomChange(bool zoom_in) override; |
| 308 | void HandleKeyboardEvent( |
| 309 | content::WebContents* source, |
| 310 | const content::NativeWebKeyboardEvent& event) override; |
| 311 | void RunFileChooser(content::WebContents* web_contents, |
| 312 | const content::FileChooserParams& params) override; |
| 313 | bool ShouldFocusPageAfterCrash() final; |
| 314 | bool PreHandleGestureEvent(content::WebContents* source, |
| 315 | const blink::WebGestureEvent& event) final; |
| 316 | void UpdatePreferredSize(content::WebContents* web_contents, |
| 317 | const gfx::Size& pref_size) final; |
| 318 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 319 | private: |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 320 | class OwnerLifetimeObserver; |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 321 | |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 322 | class OpenerLifetimeObserver; |
| 323 | |
paulmeyer | 1b61eb24 | 2015-01-22 19:13:00 | [diff] [blame] | 324 | void DispatchEvent(Event* event, int instance_id); |
| 325 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 326 | void SendQueuedEvents(); |
| 327 | |
fsamuel | 6867dde9 | 2015-01-13 02:18:19 | [diff] [blame] | 328 | void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, |
| 329 | const WebContentsCreatedCallback& callback, |
[email protected] | 3d888fa | 2014-07-11 19:27:16 | [diff] [blame] | 330 | content::WebContents* guest_web_contents); |
[email protected] | 38177c3 | 2014-06-25 23:20:23 | [diff] [blame] | 331 | |
paulmeyer | 1b61eb24 | 2015-01-22 19:13:00 | [diff] [blame] | 332 | // Dispatches the onResize event to the embedder. |
| 333 | void DispatchOnResizeEvent(const gfx::Size& old_size, |
| 334 | const gfx::Size& new_size); |
| 335 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 336 | void SetUpSizing(const base::DictionaryValue& params); |
paulmeyer | 70fcd54 | 2015-01-09 19:26:54 | [diff] [blame] | 337 | |
fsamuel | 67993a9 | 2014-12-17 01:33:20 | [diff] [blame] | 338 | void StartTrackingEmbedderZoomLevel(); |
| 339 | void StopTrackingEmbedderZoomLevel(); |
wjmaclean | ec6bd52 | 2014-12-12 16:17:50 | [diff] [blame] | 340 | |
[email protected] | 5226331 | 2014-07-22 17:45:13 | [diff] [blame] | 341 | static void RegisterGuestViewTypes(); |
| 342 | |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 343 | // This guest tracks the lifetime of the WebContents specified by |
| 344 | // |owner_web_contents_|. If |owner_web_contents_| is destroyed then this |
| 345 | // guest will also self-destruct. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 346 | content::WebContents* owner_web_contents_; |
fsamuel | fe20ffac | 2014-12-02 01:51:22 | [diff] [blame] | 347 | std::string owner_extension_id_; |
fsamuel | 09525e3 | 2015-01-21 22:23:39 | [diff] [blame] | 348 | content::BrowserContext* const browser_context_; |
fsamuel | 212c6da | 2014-09-18 16:16:15 | [diff] [blame] | 349 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 350 | // |guest_instance_id_| is a profile-wide unique identifier for a guest |
| 351 | // WebContents. |
| 352 | const int guest_instance_id_; |
fsamuel | 212c6da | 2014-09-18 16:16:15 | [diff] [blame] | 353 | |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 354 | // |view_instance_id_| is an identifier that's unique within a particular |
| 355 | // embedder RenderViewHost for a particular <*view> instance. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 356 | int view_instance_id_; |
| 357 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 358 | // |element_instance_id_| is an identifer that's unique to a particular |
fsamuel | 212c6da | 2014-09-18 16:16:15 | [diff] [blame] | 359 | // GuestViewContainer element. |
| 360 | int element_instance_id_; |
| 361 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 362 | // |initialized_| indicates whether GuestViewBase::Init has been called for |
| 363 | // this object. |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 364 | bool initialized_; |
| 365 | |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 366 | // Indicates that this guest is in the process of being destroyed. |
| 367 | bool is_being_destroyed_; |
| 368 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 369 | // This is a queue of Events that are destined to be sent to the embedder once |
| 370 | // the guest is attached to a particular embedder. |
[email protected] | 0544ea9 | 2014-04-22 21:50:47 | [diff] [blame] | 371 | std::deque<linked_ptr<Event> > pending_events_; |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 372 | |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 373 | // The opener guest view. |
| 374 | base::WeakPtr<GuestViewBase> opener_; |
| 375 | |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 376 | DestructionCallback destruction_callback_; |
| 377 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 378 | // The parameters associated with the element hosting this GuestView that |
| 379 | // are passed in from JavaScript. This will typically be the view instance ID, |
| 380 | // and element-specific parameters. These parameters are passed along to new |
| 381 | // guests that are created from this guest. |
| 382 | scoped_ptr<base::DictionaryValue> attach_params_; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 383 | |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 384 | // This observer ensures that this guest self-destructs if the embedder goes |
| 385 | // away. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 386 | scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; |
fsamuel | 87161f87 | 2014-11-07 23:00:36 | [diff] [blame] | 387 | |
| 388 | // This observer ensures that if the guest is unattached and its opener goes |
| 389 | // away then this guest also self-destructs. |
| 390 | scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 391 | |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 392 | // The size of the guest content. Note: In autosize mode, the container |
| 393 | // element may not match the size of the guest. |
| 394 | gfx::Size guest_size_; |
| 395 | |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 396 | // A pointer to the guest_sizer. |
| 397 | content::GuestSizer* guest_sizer_; |
| 398 | |
[email protected] | 5ca0686 | 2014-08-06 19:09:55 | [diff] [blame] | 399 | // Indicates whether autosize mode is enabled or not. |
| 400 | bool auto_size_enabled_; |
| 401 | |
| 402 | // The maximum size constraints of the container element in autosize mode. |
| 403 | gfx::Size max_auto_size_; |
| 404 | |
| 405 | // The minimum size constraints of the container element in autosize mode. |
| 406 | gfx::Size min_auto_size_; |
| 407 | |
paulmeyer | eb98f911 | 2015-01-23 17:13:38 | [diff] [blame] | 408 | // The size that will be used when autosize mode is disabled. |
| 409 | gfx::Size normal_size_; |
| 410 | |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 411 | // Whether the guest view is inside a plugin document. |
| 412 | bool is_full_page_plugin_; |
| 413 | |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 414 | // This is used to ensure pending tasks will not fire after this object is |
| 415 | // destroyed. |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 416 | base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 417 | |
[email protected] | 0e99fdc | 2014-04-30 05:10:33 | [diff] [blame] | 418 | DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 419 | }; |
| 420 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 421 | } // namespace extensions |
| 422 | |
| 423 | #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |