| 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 CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 6 #define CHROME_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 "content/public/browser/browser_plugin_guest_delegate.h" | 12 #include "content/public/browser/browser_plugin_guest_delegate.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 | 14 |
| 15 class AdViewGuest; | |
| 16 class WebViewGuest; | |
| 17 struct RendererContentSettingRules; | 15 struct RendererContentSettingRules; |
| 18 | 16 |
| 19 // A GuestViewBase is the base class browser-side API implementation for a | 17 // A GuestViewBase is the base class browser-side API implementation for a |
| 20 // <*view> tag. GuestViewBase maintains an association between a guest | 18 // <*view> tag. GuestViewBase maintains an association between a guest |
| 21 // WebContents and an embedder WebContents. It receives events issued from | 19 // WebContents and an embedder WebContents. It receives events issued from |
| 22 // the guest and relays them to the embedder. | 20 // the guest and relays them to the embedder. |
| 23 class GuestViewBase : public content::BrowserPluginGuestDelegate { | 21 class GuestViewBase : public content::BrowserPluginGuestDelegate { |
| 24 public: | 22 public: |
| 25 class Event { | 23 class Event { |
| 26 public: | 24 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 | 36 |
| 39 // Returns a *ViewGuest if this GuestView is of the given view type. | 37 // Returns a *ViewGuest if this GuestView is of the given view type. |
| 40 template <typename T> | 38 template <typename T> |
| 41 T* As() { | 39 T* As() { |
| 42 if (IsViewType(T::Type)) | 40 if (IsViewType(T::Type)) |
| 43 return static_cast<T*>(this); | 41 return static_cast<T*>(this); |
| 44 | 42 |
| 45 return NULL; | 43 return NULL; |
| 46 } | 44 } |
| 47 | 45 |
| 48 static GuestViewBase* Create(content::WebContents* guest_web_contents, | 46 static GuestViewBase* Create(int guest_instance_id, |
| 47 content::WebContents* guest_web_contents, |
| 49 const std::string& embedder_extension_id, | 48 const std::string& embedder_extension_id, |
| 50 const std::string& view_type, | 49 const std::string& view_type); |
| 51 const base::WeakPtr<GuestViewBase>& opener); | |
| 52 | 50 |
| 53 static GuestViewBase* FromWebContents(content::WebContents* web_contents); | 51 static GuestViewBase* FromWebContents(content::WebContents* web_contents); |
| 54 | 52 |
| 55 static GuestViewBase* From(int embedder_process_id, int instance_id); | 53 static GuestViewBase* From(int embedder_process_id, int instance_id); |
| 56 | 54 |
| 57 // For GuestViewBases, we create special guest processes, which host the | 55 // For GuestViewBases, we create special guest processes, which host the |
| 58 // tag content separately from the main application that embeds the tag. | 56 // tag content separately from the main application that embeds the tag. |
| 59 // A GuestViewBase can specify both the partition name and whether the storage | 57 // A GuestViewBase can specify both the partition name and whether the storage |
| 60 // for that partition should be persisted. Each tag gets a SiteInstance with | 58 // for that partition should be persisted. Each tag gets a SiteInstance with |
| 61 // a specially formatted URL, based on the application it is hosted by and | 59 // a specially formatted URL, based on the application it is hosted by and |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 | 81 |
| 84 content::WebContents* embedder_web_contents() const { | 82 content::WebContents* embedder_web_contents() const { |
| 85 return embedder_web_contents_; | 83 return embedder_web_contents_; |
| 86 } | 84 } |
| 87 | 85 |
| 88 // Returns the guest WebContents. | 86 // Returns the guest WebContents. |
| 89 content::WebContents* guest_web_contents() const { | 87 content::WebContents* guest_web_contents() const { |
| 90 return guest_web_contents_; | 88 return guest_web_contents_; |
| 91 } | 89 } |
| 92 | 90 |
| 91 // Returns the extra parameters associated with this GuestView passed |
| 92 // in from JavaScript. |
| 93 base::DictionaryValue* extra_params() const { |
| 94 return extra_params_.get(); |
| 95 } |
| 96 |
| 93 // Returns whether this guest has an associated embedder. | 97 // Returns whether this guest has an associated embedder. |
| 94 bool attached() const { return !!embedder_web_contents_; } | 98 bool attached() const { return !!embedder_web_contents_; } |
| 95 | 99 |
| 96 // Returns the instance ID of the <*view> element. | 100 // Returns the instance ID of the <*view> element. |
| 97 int view_instance_id() const { return view_instance_id_; } | 101 int view_instance_id() const { return view_instance_id_; } |
| 98 | 102 |
| 99 // Returns the instance ID of the guest WebContents. | 103 // Returns the instance ID of the guest WebContents. |
| 100 int guest_instance_id() const { return guest_instance_id_; } | 104 int guest_instance_id() const { return guest_instance_id_; } |
| 101 | 105 |
| 102 // Returns the extension ID of the embedder. | 106 // Returns the extension ID of the embedder. |
| 103 const std::string& embedder_extension_id() const { | 107 const std::string& embedder_extension_id() const { |
| 104 return embedder_extension_id_; | 108 return embedder_extension_id_; |
| 105 } | 109 } |
| 106 | 110 |
| 107 // Returns whether this GuestView is embedded in an extension/app. | 111 // Returns whether this GuestView is embedded in an extension/app. |
| 108 bool in_extension() const { return !embedder_extension_id_.empty(); } | 112 bool in_extension() const { return !embedder_extension_id_.empty(); } |
| 109 | 113 |
| 110 // Returns the user browser context of the embedder. | 114 // Returns the user browser context of the embedder. |
| 111 content::BrowserContext* browser_context() const { return browser_context_; } | 115 content::BrowserContext* browser_context() const { return browser_context_; } |
| 112 | 116 |
| 113 // Returns the embedder's process ID. | 117 // Returns the embedder's process ID. |
| 114 int embedder_render_process_id() const { return embedder_render_process_id_; } | 118 int embedder_render_process_id() const { return embedder_render_process_id_; } |
| 115 | 119 |
| 120 GuestViewBase* GetOpener() const { |
| 121 return opener_.get(); |
| 122 } |
| 123 |
| 124 void SetOpener(GuestViewBase* opener); |
| 125 |
| 116 // BrowserPluginGuestDelegate implementation. | 126 // BrowserPluginGuestDelegate implementation. |
| 117 virtual content::WebContents* GetOpener() const OVERRIDE; | 127 virtual void Destroy() OVERRIDE; |
| 118 virtual void SetOpener(content::WebContents* opener) OVERRIDE; | 128 virtual void RegisterDestructionCallback( |
| 129 const DestructionCallback& callback) OVERRIDE; |
| 119 | 130 |
| 120 protected: | 131 protected: |
| 121 GuestViewBase(content::WebContents* guest_web_contents, | 132 GuestViewBase(int guest_instance_id, |
| 122 const std::string& embedder_extension_id, | 133 content::WebContents* guest_web_contents, |
| 123 const base::WeakPtr<GuestViewBase>& opener); | 134 const std::string& embedder_extension_id); |
| 124 virtual ~GuestViewBase(); | 135 virtual ~GuestViewBase(); |
| 125 | 136 |
| 126 // Dispatches an event |event_name| to the embedder with the |event| fields. | 137 // Dispatches an event |event_name| to the embedder with the |event| fields. |
| 127 void DispatchEvent(Event* event); | 138 void DispatchEvent(Event* event); |
| 128 | 139 |
| 129 private: | 140 private: |
| 130 void SendQueuedEvents(); | 141 void SendQueuedEvents(); |
| 131 | 142 |
| 132 content::WebContents* const guest_web_contents_; | 143 content::WebContents* const guest_web_contents_; |
| 133 content::WebContents* embedder_web_contents_; | 144 content::WebContents* embedder_web_contents_; |
| 134 const std::string embedder_extension_id_; | 145 const std::string embedder_extension_id_; |
| 135 int embedder_render_process_id_; | 146 int embedder_render_process_id_; |
| 136 content::BrowserContext* const browser_context_; | 147 content::BrowserContext* const browser_context_; |
| 137 // |guest_instance_id_| is a profile-wide unique identifier for a guest | 148 // |guest_instance_id_| is a profile-wide unique identifier for a guest |
| 138 // WebContents. | 149 // WebContents. |
| 139 const int guest_instance_id_; | 150 const int guest_instance_id_; |
| 140 // |view_instance_id_| is an identifier that's unique within a particular | 151 // |view_instance_id_| is an identifier that's unique within a particular |
| 141 // embedder RenderViewHost for a particular <*view> instance. | 152 // embedder RenderViewHost for a particular <*view> instance. |
| 142 int view_instance_id_; | 153 int view_instance_id_; |
| 143 | 154 |
| 144 // This is a queue of Events that are destined to be sent to the embedder once | 155 // This is a queue of Events that are destined to be sent to the embedder once |
| 145 // the guest is attached to a particular embedder. | 156 // the guest is attached to a particular embedder. |
| 146 std::deque<linked_ptr<Event> > pending_events_; | 157 std::deque<linked_ptr<Event> > pending_events_; |
| 147 | 158 |
| 148 // The opener guest view. | 159 // The opener guest view. |
| 149 base::WeakPtr<GuestViewBase> opener_; | 160 base::WeakPtr<GuestViewBase> opener_; |
| 150 | 161 |
| 162 DestructionCallback destruction_callback_; |
| 163 |
| 164 // The extra parameters associated with this GuestView passed |
| 165 // in from JavaScript. This will typically be the view instance ID, |
| 166 // the API to use, and view-specific parameters. These parameters |
| 167 // are passed along to new guests that are created from this guest. |
| 168 scoped_ptr<base::DictionaryValue> extra_params_; |
| 169 |
| 151 // This is used to ensure pending tasks will not fire after this object is | 170 // This is used to ensure pending tasks will not fire after this object is |
| 152 // destroyed. | 171 // destroyed. |
| 153 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 172 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
| 154 | 173 |
| 155 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 174 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
| 156 }; | 175 }; |
| 157 | 176 |
| 158 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 177 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| OLD | NEW |