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 "content/public/browser/browser_plugin_guest_delegate.h" | 12 #include "content/public/browser/browser_plugin_guest_delegate.h" |
13 #include "content/public/browser/render_process_host_observer.h" | 13 #include "content/public/browser/render_process_host_observer.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_delegate.h" | 15 #include "content/public/browser/web_contents_delegate.h" |
16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
17 | 17 |
18 struct RendererContentSettingRules; | 18 struct RendererContentSettingRules; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 // A GuestViewBase is the base class browser-side API implementation for a | 22 // A GuestViewBase is the base class browser-side API implementation for a |
23 // <*view> tag. GuestViewBase maintains an association between a guest | 23 // <*view> tag. GuestViewBase maintains an association between a guest |
24 // WebContents and an embedder WebContents. It receives events issued from | 24 // WebContents and an embedder WebContents. It receives events issued from |
25 // the guest and relays them to the embedder. GuestViewBase tracks the lifetime | 25 // the guest and relays them to the embedder. GuestViewBase tracks the lifetime |
26 // of its embedder render process until it is attached to a particular embedder | 26 // of its embedder render process until it is attached to a particular embedder |
27 // WebContents. At that point, its lifetime is restricted in scope to the | 27 // WebContents. At that point, its lifetime is restricted in scope to the |
28 // lifetime of its embedder WebContents. | 28 // lifetime of its embedder WebContents. |
29 class GuestViewBase : public content::BrowserPluginGuestDelegate, | 29 class GuestViewBase : public content::BrowserPluginGuestDelegate, |
30 public content::RenderProcessHostObserver, | |
31 public content::WebContentsDelegate, | 30 public content::WebContentsDelegate, |
32 public content::WebContentsObserver { | 31 public content::WebContentsObserver { |
33 public: | 32 public: |
34 class Event { | 33 class Event { |
35 public: | 34 public: |
36 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); | 35 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); |
37 ~Event(); | 36 ~Event(); |
38 | 37 |
39 const std::string& name() const { return name_; } | 38 const std::string& name() const { return name_; } |
40 | 39 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 const base::DictionaryValue& create_params, | 163 const base::DictionaryValue& create_params, |
165 const WebContentsCreatedCallback& callback) = 0; | 164 const WebContentsCreatedCallback& callback) = 0; |
166 | 165 |
167 // This creates a WebContents and initializes |this| GuestViewBase to use the | 166 // This creates a WebContents and initializes |this| GuestViewBase to use the |
168 // newly created WebContents. | 167 // newly created WebContents. |
169 void Init(const std::string& embedder_extension_id, | 168 void Init(const std::string& embedder_extension_id, |
170 content::WebContents* embedder_web_contents, | 169 content::WebContents* embedder_web_contents, |
171 const base::DictionaryValue& create_params, | 170 const base::DictionaryValue& create_params, |
172 const WebContentsCreatedCallback& callback); | 171 const WebContentsCreatedCallback& callback); |
173 | 172 |
174 void InitWithWebContents( | 173 void InitWithWebContents(const std::string& embedder_extension_id, |
175 const std::string& embedder_extension_id, | 174 int embedder_render_process_id, |
Fady Samuel
2014/10/08 21:45:32
Remove this.
lfg
2014/10/08 23:25:36
Done.
| |
176 int embedder_render_process_id, | 175 content::WebContents* embedder_web_contents, |
177 content::WebContents* guest_web_contents); | 176 content::WebContents* guest_web_contents); |
178 | 177 |
179 bool IsViewType(const char* const view_type) const { | 178 bool IsViewType(const char* const view_type) const { |
180 return !strcmp(GetViewType(), view_type); | 179 return !strcmp(GetViewType(), view_type); |
181 } | 180 } |
182 | 181 |
183 // Toggles autosize mode for this GuestView. | 182 // Toggles autosize mode for this GuestView. |
184 void SetAutoSize(bool enabled, | 183 void SetAutoSize(bool enabled, |
185 const gfx::Size& min_size, | 184 const gfx::Size& min_size, |
186 const gfx::Size& max_size); | 185 const gfx::Size& max_size); |
187 | 186 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 return opener_.get(); | 221 return opener_.get(); |
223 } | 222 } |
224 | 223 |
225 // Destroy this guest. | 224 // Destroy this guest. |
226 void Destroy(); | 225 void Destroy(); |
227 | 226 |
228 // Saves the attach state of the custom element hosting this GuestView. | 227 // Saves the attach state of the custom element hosting this GuestView. |
229 void SetAttachParams(const base::DictionaryValue& params); | 228 void SetAttachParams(const base::DictionaryValue& params); |
230 void SetOpener(GuestViewBase* opener); | 229 void SetOpener(GuestViewBase* opener); |
231 | 230 |
232 // RenderProcessHostObserver implementation | |
233 virtual void RenderProcessExited(content::RenderProcessHost* host, | |
234 base::ProcessHandle handle, | |
235 base::TerminationStatus status, | |
236 int exit_code) override; | |
237 | |
238 // BrowserPluginGuestDelegate implementation. | 231 // BrowserPluginGuestDelegate implementation. |
239 virtual void DidAttach(int guest_proxy_routing_id) override final; | 232 virtual void DidAttach(int guest_proxy_routing_id) override final; |
240 virtual void ElementSizeChanged(const gfx::Size& old_size, | 233 virtual void ElementSizeChanged(const gfx::Size& old_size, |
241 const gfx::Size& new_size) override final; | 234 const gfx::Size& new_size) override final; |
242 virtual void GuestSizeChanged(const gfx::Size& old_size, | 235 virtual void GuestSizeChanged(const gfx::Size& old_size, |
243 const gfx::Size& new_size) override final; | 236 const gfx::Size& new_size) override final; |
244 virtual void RegisterDestructionCallback( | 237 virtual void RegisterDestructionCallback( |
245 const DestructionCallback& callback) override final; | 238 const DestructionCallback& callback) override final; |
246 virtual void WillAttach( | 239 virtual void WillAttach( |
247 content::WebContents* embedder_web_contents, | 240 content::WebContents* embedder_web_contents, |
248 int browser_plugin_instance_id) override final; | 241 int browser_plugin_instance_id) override final; |
249 | 242 |
250 // Dispatches an event |event_name| to the embedder with the |event| fields. | 243 // Dispatches an event |event_name| to the embedder with the |event| fields. |
251 void DispatchEventToEmbedder(Event* event); | 244 void DispatchEventToEmbedder(Event* event); |
252 | 245 |
253 protected: | 246 protected: |
254 GuestViewBase(content::BrowserContext* browser_context, | 247 GuestViewBase(content::BrowserContext* browser_context, |
255 int guest_instance_id); | 248 int guest_instance_id); |
256 | 249 |
257 virtual ~GuestViewBase(); | 250 virtual ~GuestViewBase(); |
258 | 251 |
259 private: | 252 private: |
260 class EmbedderWebContentsObserver; | 253 class EmbedderWebContentsObserver; |
261 | 254 |
262 void SendQueuedEvents(); | 255 void SendQueuedEvents(); |
263 | 256 |
264 void CompleteInit(const std::string& embedder_extension_id, | 257 void CompleteInit(const std::string& embedder_extension_id, |
265 int embedder_render_process_id, | 258 int embedder_render_process_id, |
Fady Samuel
2014/10/08 21:45:32
Remove this.
lfg
2014/10/08 23:25:36
Done.
| |
259 content::WebContents* embedder_web_contents, | |
266 const WebContentsCreatedCallback& callback, | 260 const WebContentsCreatedCallback& callback, |
267 content::WebContents* guest_web_contents); | 261 content::WebContents* guest_web_contents); |
268 | 262 |
269 static void RegisterGuestViewTypes(); | 263 static void RegisterGuestViewTypes(); |
270 | 264 |
271 // WebContentsObserver implementation. | 265 // WebContentsObserver implementation. |
272 virtual void DidStopLoading( | 266 virtual void DidStopLoading( |
273 content::RenderViewHost* render_view_host) override final; | 267 content::RenderViewHost* render_view_host) override final; |
274 virtual void RenderViewReady() override final; | 268 virtual void RenderViewReady() override final; |
275 virtual void WebContentsDestroyed() override final; | 269 virtual void WebContentsDestroyed() override final; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 // This is used to ensure pending tasks will not fire after this object is | 335 // This is used to ensure pending tasks will not fire after this object is |
342 // destroyed. | 336 // destroyed. |
343 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 337 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
344 | 338 |
345 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 339 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
346 }; | 340 }; |
347 | 341 |
348 } // namespace extensions | 342 } // namespace extensions |
349 | 343 |
350 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 344 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |