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

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

Issue 564973004: Move ContentWindow from BrowserPlugin To GuestView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More cleanup Created 6 years, 3 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 | « extensions/browser/guest_view/guest_view_base.h ('k') | extensions/common/extension_messages.h » ('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 #include "extensions/browser/guest_view/guest_view_base.h" 5 #include "extensions/browser/guest_view/guest_view_base.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/render_frame_host.h" 9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_process_host.h" 10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/url_constants.h" 13 #include "content/public/common/url_constants.h"
14 #include "extensions/browser/api/extensions_api_client.h" 14 #include "extensions/browser/api/extensions_api_client.h"
15 #include "extensions/browser/event_router.h" 15 #include "extensions/browser/event_router.h"
16 #include "extensions/browser/extension_registry.h" 16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/guest_view/app_view/app_view_guest.h" 17 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
18 #include "extensions/browser/guest_view/extension_options/extension_options_gues t.h" 18 #include "extensions/browser/guest_view/extension_options/extension_options_gues t.h"
19 #include "extensions/browser/guest_view/guest_view_manager.h" 19 #include "extensions/browser/guest_view/guest_view_manager.h"
20 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h" 20 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h"
21 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 21 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
22 #include "extensions/browser/process_map.h" 22 #include "extensions/browser/process_map.h"
23 #include "extensions/common/extension_messages.h"
23 #include "extensions/common/features/feature.h" 24 #include "extensions/common/features/feature.h"
24 #include "extensions/common/features/feature_provider.h" 25 #include "extensions/common/features/feature_provider.h"
25 #include "extensions/common/guest_view/guest_view_constants.h" 26 #include "extensions/common/guest_view/guest_view_constants.h"
26 #include "third_party/WebKit/public/web/WebInputEvent.h" 27 #include "third_party/WebKit/public/web/WebInputEvent.h"
27 28
28 using content::WebContents; 29 using content::WebContents;
29 30
30 namespace extensions { 31 namespace extensions {
31 32
32 namespace { 33 namespace {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); 99 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver);
99 }; 100 };
100 101
101 GuestViewBase::GuestViewBase(content::BrowserContext* browser_context, 102 GuestViewBase::GuestViewBase(content::BrowserContext* browser_context,
102 int guest_instance_id) 103 int guest_instance_id)
103 : embedder_web_contents_(NULL), 104 : embedder_web_contents_(NULL),
104 embedder_render_process_id_(0), 105 embedder_render_process_id_(0),
105 browser_context_(browser_context), 106 browser_context_(browser_context),
106 guest_instance_id_(guest_instance_id), 107 guest_instance_id_(guest_instance_id),
107 view_instance_id_(guestview::kInstanceIDNone), 108 view_instance_id_(guestview::kInstanceIDNone),
109 element_instance_id_(guestview::kInstanceIDNone),
108 initialized_(false), 110 initialized_(false),
109 auto_size_enabled_(false), 111 auto_size_enabled_(false),
110 weak_ptr_factory_(this) { 112 weak_ptr_factory_(this) {
111 } 113 }
112 114
113 void GuestViewBase::Init(const std::string& embedder_extension_id, 115 void GuestViewBase::Init(const std::string& embedder_extension_id,
114 content::WebContents* embedder_web_contents, 116 content::WebContents* embedder_web_contents,
115 const base::DictionaryValue& create_params, 117 const base::DictionaryValue& create_params,
116 const WebContentsCreatedCallback& callback) { 118 const WebContentsCreatedCallback& callback) {
117 if (initialized_) 119 if (initialized_)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 destruction_callback_.Run(); 306 destruction_callback_.Run();
305 307
306 webcontents_guestview_map.Get().erase(web_contents()); 308 webcontents_guestview_map.Get().erase(web_contents());
307 GuestViewManager::FromBrowserContext(browser_context_)-> 309 GuestViewManager::FromBrowserContext(browser_context_)->
308 RemoveGuest(guest_instance_id_); 310 RemoveGuest(guest_instance_id_);
309 pending_events_.clear(); 311 pending_events_.clear();
310 312
311 delete web_contents(); 313 delete web_contents();
312 } 314 }
313 315
314 void GuestViewBase::DidAttach() { 316 void GuestViewBase::DidAttach(int guest_proxy_routing_id) {
315 // Give the derived class an opportunity to perform some actions. 317 // Give the derived class an opportunity to perform some actions.
316 DidAttachToEmbedder(); 318 DidAttachToEmbedder();
317 319
320 // Inform the associated GuestViewContainer that the contentWindow is ready.
321 embedder_web_contents()->Send(new ExtensionMsg_GuestAttached(
322 embedder_web_contents()->GetMainFrame()->GetRoutingID(),
323 element_instance_id_,
324 guest_proxy_routing_id));
325
318 SendQueuedEvents(); 326 SendQueuedEvents();
319 } 327 }
320 328
321 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, 329 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size,
322 const gfx::Size& new_size) { 330 const gfx::Size& new_size) {
323 element_size_ = new_size; 331 element_size_ = new_size;
324 } 332 }
325 333
326 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, 334 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size,
327 const gfx::Size& new_size) { 335 const gfx::Size& new_size) {
(...skipping 15 matching lines...) Expand all
343 return; 351 return;
344 } 352 }
345 opener_ = base::WeakPtr<GuestViewBase>(); 353 opener_ = base::WeakPtr<GuestViewBase>();
346 } 354 }
347 355
348 void GuestViewBase::RegisterDestructionCallback( 356 void GuestViewBase::RegisterDestructionCallback(
349 const DestructionCallback& callback) { 357 const DestructionCallback& callback) {
350 destruction_callback_ = callback; 358 destruction_callback_ = callback;
351 } 359 }
352 360
353 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents) { 361 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents,
362 int element_instance_id) {
354 // After attachment, this GuestViewBase's lifetime is restricted to the 363 // After attachment, this GuestViewBase's lifetime is restricted to the
355 // lifetime of its embedder WebContents. Observing the RenderProcessHost 364 // lifetime of its embedder WebContents. Observing the RenderProcessHost
356 // of the embedder is no longer necessary. 365 // of the embedder is no longer necessary.
357 embedder_web_contents->GetRenderProcessHost()->RemoveObserver(this); 366 embedder_web_contents->GetRenderProcessHost()->RemoveObserver(this);
358 embedder_web_contents_ = embedder_web_contents; 367 embedder_web_contents_ = embedder_web_contents;
359 embedder_web_contents_observer_.reset( 368 embedder_web_contents_observer_.reset(
360 new EmbedderWebContentsObserver(this)); 369 new EmbedderWebContentsObserver(this));
370 element_instance_id_ = element_instance_id;
361 371
362 WillAttachToEmbedder(); 372 WillAttachToEmbedder();
363 } 373 }
364 374
365 void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) { 375 void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) {
366 if (!IsDragAndDropEnabled()) { 376 if (!IsDragAndDropEnabled()) {
367 const char script[] = "window.addEventListener('dragstart', function() { " 377 const char script[] = "window.addEventListener('dragstart', function() { "
368 " window.event.preventDefault(); " 378 " window.event.preventDefault(); "
369 "});"; 379 "});";
370 render_view_host->GetMainFrame()->ExecuteJavaScript( 380 render_view_host->GetMainFrame()->ExecuteJavaScript(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 489
480 // static 490 // static
481 void GuestViewBase::RegisterGuestViewTypes() { 491 void GuestViewBase::RegisterGuestViewTypes() {
482 AppViewGuest::Register(); 492 AppViewGuest::Register();
483 ExtensionOptionsGuest::Register(); 493 ExtensionOptionsGuest::Register();
484 MimeHandlerViewGuest::Register(); 494 MimeHandlerViewGuest::Register();
485 WebViewGuest::Register(); 495 WebViewGuest::Register();
486 } 496 }
487 497
488 } // namespace extensions 498 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_base.h ('k') | extensions/common/extension_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698