Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: extensions/browser/guest_view/guest_view_base.h

Issue 642573002: Remove the RenderProcessHost observer and attach the WebContentsObserver earlier to the GuestView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tests_other0
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | extensions/browser/guest_view/guest_view_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 content::WebContents* embedder_web_contents,
176 int embedder_render_process_id, 175 content::WebContents* guest_web_contents);
177 content::WebContents* guest_web_contents);
178 176
179 bool IsViewType(const char* const view_type) const { 177 bool IsViewType(const char* const view_type) const {
180 return !strcmp(GetViewType(), view_type); 178 return !strcmp(GetViewType(), view_type);
181 } 179 }
182 180
183 // Toggles autosize mode for this GuestView. 181 // Toggles autosize mode for this GuestView.
184 void SetAutoSize(bool enabled, 182 void SetAutoSize(bool enabled,
185 const gfx::Size& min_size, 183 const gfx::Size& min_size,
186 const gfx::Size& max_size); 184 const gfx::Size& max_size);
187 185
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 return opener_.get(); 220 return opener_.get();
223 } 221 }
224 222
225 // Destroy this guest. 223 // Destroy this guest.
226 void Destroy(); 224 void Destroy();
227 225
228 // Saves the attach state of the custom element hosting this GuestView. 226 // Saves the attach state of the custom element hosting this GuestView.
229 void SetAttachParams(const base::DictionaryValue& params); 227 void SetAttachParams(const base::DictionaryValue& params);
230 void SetOpener(GuestViewBase* opener); 228 void SetOpener(GuestViewBase* opener);
231 229
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. 230 // BrowserPluginGuestDelegate implementation.
239 virtual void DidAttach(int guest_proxy_routing_id) override final; 231 virtual void DidAttach(int guest_proxy_routing_id) override final;
240 virtual void ElementSizeChanged(const gfx::Size& old_size, 232 virtual void ElementSizeChanged(const gfx::Size& old_size,
241 const gfx::Size& new_size) override final; 233 const gfx::Size& new_size) override final;
242 virtual void GuestSizeChanged(const gfx::Size& old_size, 234 virtual void GuestSizeChanged(const gfx::Size& old_size,
243 const gfx::Size& new_size) override final; 235 const gfx::Size& new_size) override final;
244 virtual void RegisterDestructionCallback( 236 virtual void RegisterDestructionCallback(
245 const DestructionCallback& callback) override final; 237 const DestructionCallback& callback) override final;
246 virtual void WillAttach( 238 virtual void WillAttach(
247 content::WebContents* embedder_web_contents, 239 content::WebContents* embedder_web_contents,
248 int browser_plugin_instance_id) override final; 240 int browser_plugin_instance_id) override final;
249 241
250 // Dispatches an event |event_name| to the embedder with the |event| fields. 242 // Dispatches an event |event_name| to the embedder with the |event| fields.
251 void DispatchEventToEmbedder(Event* event); 243 void DispatchEventToEmbedder(Event* event);
252 244
253 protected: 245 protected:
254 GuestViewBase(content::BrowserContext* browser_context, 246 GuestViewBase(content::BrowserContext* browser_context,
255 int guest_instance_id); 247 int guest_instance_id);
256 248
257 virtual ~GuestViewBase(); 249 virtual ~GuestViewBase();
258 250
259 private: 251 private:
260 class EmbedderWebContentsObserver; 252 class EmbedderLifetimeObserver;
261 253
262 void SendQueuedEvents(); 254 void SendQueuedEvents();
263 255
264 void CompleteInit(const std::string& embedder_extension_id, 256 void CompleteInit(const std::string& embedder_extension_id,
265 int embedder_render_process_id, 257 content::WebContents* embedder_web_contents,
266 const WebContentsCreatedCallback& callback, 258 const WebContentsCreatedCallback& callback,
267 content::WebContents* guest_web_contents); 259 content::WebContents* guest_web_contents);
268 260
269 static void RegisterGuestViewTypes(); 261 static void RegisterGuestViewTypes();
270 262
271 // WebContentsObserver implementation. 263 // WebContentsObserver implementation.
272 virtual void DidStopLoading( 264 virtual void DidStopLoading(
273 content::RenderViewHost* render_view_host) override final; 265 content::RenderViewHost* render_view_host) override final;
274 virtual void RenderViewReady() override final; 266 virtual void RenderViewReady() override final;
275 virtual void WebContentsDestroyed() override final; 267 virtual void WebContentsDestroyed() override final;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 base::WeakPtr<GuestViewBase> opener_; 305 base::WeakPtr<GuestViewBase> opener_;
314 306
315 DestructionCallback destruction_callback_; 307 DestructionCallback destruction_callback_;
316 308
317 // The parameters associated with the element hosting this GuestView that 309 // The parameters associated with the element hosting this GuestView that
318 // are passed in from JavaScript. This will typically be the view instance ID, 310 // are passed in from JavaScript. This will typically be the view instance ID,
319 // and element-specific parameters. These parameters are passed along to new 311 // and element-specific parameters. These parameters are passed along to new
320 // guests that are created from this guest. 312 // guests that are created from this guest.
321 scoped_ptr<base::DictionaryValue> attach_params_; 313 scoped_ptr<base::DictionaryValue> attach_params_;
322 314
323 scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; 315 scoped_ptr<EmbedderLifetimeObserver> embedder_web_contents_observer_;
324 316
325 // The size of the container element. 317 // The size of the container element.
326 gfx::Size element_size_; 318 gfx::Size element_size_;
327 319
328 // The size of the guest content. Note: In autosize mode, the container 320 // The size of the guest content. Note: In autosize mode, the container
329 // element may not match the size of the guest. 321 // element may not match the size of the guest.
330 gfx::Size guest_size_; 322 gfx::Size guest_size_;
331 323
332 // Indicates whether autosize mode is enabled or not. 324 // Indicates whether autosize mode is enabled or not.
333 bool auto_size_enabled_; 325 bool auto_size_enabled_;
334 326
335 // The maximum size constraints of the container element in autosize mode. 327 // The maximum size constraints of the container element in autosize mode.
336 gfx::Size max_auto_size_; 328 gfx::Size max_auto_size_;
337 329
338 // The minimum size constraints of the container element in autosize mode. 330 // The minimum size constraints of the container element in autosize mode.
339 gfx::Size min_auto_size_; 331 gfx::Size min_auto_size_;
340 332
341 // This is used to ensure pending tasks will not fire after this object is 333 // This is used to ensure pending tasks will not fire after this object is
342 // destroyed. 334 // destroyed.
343 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; 335 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_;
344 336
345 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); 337 DISALLOW_COPY_AND_ASSIGN(GuestViewBase);
346 }; 338 };
347 339
348 } // namespace extensions 340 } // namespace extensions
349 341
350 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ 342 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/guest_view/guest_view_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698