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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 910073003: <webview>: Make contentWindow available prior to attachment (on display:none). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/common/browser_plugin/browser_plugin_messages.h" 24 #include "content/common/browser_plugin/browser_plugin_messages.h"
25 #include "content/common/content_constants_internal.h" 25 #include "content/common/content_constants_internal.h"
26 #include "content/common/drag_messages.h" 26 #include "content/common/drag_messages.h"
27 #include "content/common/frame_messages.h" 27 #include "content/common/frame_messages.h"
28 #include "content/common/host_shared_bitmap_manager.h" 28 #include "content/common/host_shared_bitmap_manager.h"
29 #include "content/common/input_messages.h" 29 #include "content/common/input_messages.h"
30 #include "content/common/view_messages.h" 30 #include "content/common/view_messages.h"
31 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
32 #include "content/public/browser/browser_plugin_guest_manager.h" 32 #include "content/public/browser/browser_plugin_guest_manager.h"
33 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
34 #include "content/public/browser/guest_sizer.h" 34 #include "content/public/browser/guest_proxy_host.h"
35 #include "content/public/browser/render_widget_host_view.h" 35 #include "content/public/browser/render_widget_host_view.h"
36 #include "content/public/browser/user_metrics.h" 36 #include "content/public/browser/user_metrics.h"
37 #include "content/public/browser/web_contents_observer.h" 37 #include "content/public/browser/web_contents_observer.h"
38 #include "content/public/common/drop_data.h" 38 #include "content/public/common/drop_data.h"
39 #include "ui/gfx/geometry/size_conversions.h" 39 #include "ui/gfx/geometry/size_conversions.h"
40 40
41 #if defined(OS_MACOSX) 41 #if defined(OS_MACOSX)
42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" 42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h"
43 #endif 43 #endif
44 44
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 guest_proxy_routing_id_(MSG_ROUTING_NONE), 92 guest_proxy_routing_id_(MSG_ROUTING_NONE),
93 last_drag_status_(blink::WebDragStatusUnknown), 93 last_drag_status_(blink::WebDragStatusUnknown),
94 seen_embedder_system_drag_ended_(false), 94 seen_embedder_system_drag_ended_(false),
95 seen_embedder_drag_source_ended_at_(false), 95 seen_embedder_drag_source_ended_at_(false),
96 delegate_(delegate), 96 delegate_(delegate),
97 weak_ptr_factory_(this) { 97 weak_ptr_factory_(this) {
98 DCHECK(web_contents); 98 DCHECK(web_contents);
99 DCHECK(delegate); 99 DCHECK(delegate);
100 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 100 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
101 web_contents->SetBrowserPluginGuest(this); 101 web_contents->SetBrowserPluginGuest(this);
102 delegate->RegisterDestructionCallback( 102 delegate->SetGuestProxyHost(this);
103 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); 103 }
104 delegate->SetGuestSizer(this); 104
105 int BrowserPluginGuest::GetGuestProxyRoutingID() {
106 // Create a swapped out RenderView for the guest in the embedder renderer
107 // process, so that the embedder can access the guest's window object.
108 // On reattachment, we can reuse the same swapped out RenderView because
109 // the embedder process will always be the same even if the embedder
110 // WebContents changes.
111 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE)
112 return guest_proxy_routing_id_;
113
114 // TODO(fsamuel): Make sure this works for transferring guests across
115 // owners in different processes. We probably need to clear the
116 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach
117 // to enable this.
118 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance();
119 guest_proxy_routing_id_ =
120 GetWebContents()->CreateSwappedOutRenderView(owner_site_instance);
121
122 return guest_proxy_routing_id_;
105 } 123 }
106 124
107 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 125 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
108 GetWebContents()->GetView()->SizeContents(new_size); 126 GetWebContents()->GetView()->SizeContents(new_size);
109 } 127 }
110 128
129 void BrowserPluginGuest::WillDestroy() {
130 is_in_destruction_ = true;
131 owner_web_contents_ = nullptr;
132 attached_ = false;
133 }
134
111 void BrowserPluginGuest::Init() { 135 void BrowserPluginGuest::Init() {
112 if (initialized_) 136 if (initialized_)
113 return; 137 return;
114 initialized_ = true; 138 initialized_ = true;
115 139
116 // TODO(fsamuel): Initiailization prior to attachment should be behind a 140 // TODO(fsamuel): Initiailization prior to attachment should be behind a
117 // command line flag once we introduce experimental guest types that rely on 141 // command line flag once we introduce experimental guest types that rely on
118 // this functionality. 142 // this functionality.
119 if (!delegate_->CanRunInDetachedState()) 143 if (!delegate_->CanRunInDetachedState())
120 return; 144 return;
121 145
122 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>( 146 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
123 delegate_->GetOwnerWebContents()); 147 delegate_->GetOwnerWebContents());
148 owner_web_contents->CreateBrowserPluginEmbedderIfNecessary();
124 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents); 149 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
125 } 150 }
126 151
127 void BrowserPluginGuest::WillDestroy() {
128 is_in_destruction_ = true;
129 owner_web_contents_ = nullptr;
130 attached_ = false;
131 }
132
133 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 152 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
134 return weak_ptr_factory_.GetWeakPtr(); 153 return weak_ptr_factory_.GetWeakPtr();
135 } 154 }
136 155
137 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, 156 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh,
138 bool focused, 157 bool focused,
139 blink::WebFocusType focus_type) { 158 blink::WebFocusType focus_type) {
140 focused_ = focused; 159 focused_ = focused;
141 if (!rwh) 160 if (!rwh)
142 return; 161 return;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 web_contents_view->CreateViewForWidget( 632 web_contents_view->CreateViewForWidget(
614 web_contents()->GetRenderViewHost(), true); 633 web_contents()->GetRenderViewHost(), true);
615 } 634 }
616 } 635 }
617 636
618 InitInternal(params, embedder_web_contents); 637 InitInternal(params, embedder_web_contents);
619 638
620 attached_ = true; 639 attached_ = true;
621 SendQueuedMessages(); 640 SendQueuedMessages();
622 641
623 // Create a swapped out RenderView for the guest in the embedder render 642 delegate_->DidAttach();
624 // process, so that the embedder can access the guest's window object.
625 // On reattachment, we can reuse the same swapped out RenderView because
626 // the embedder process will always be the same even if the embedder
627 // WebContents changes.
628 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) {
629 guest_proxy_routing_id_ =
630 GetWebContents()->CreateSwappedOutRenderView(
631 owner_web_contents_->GetSiteInstance());
632 }
633
634 delegate_->DidAttach(guest_proxy_routing_id_);
635 643
636 has_render_view_ = true; 644 has_render_view_ = true;
637 645
638 // Enable input method for guest if it's enabled for the embedder. 646 // Enable input method for guest if it's enabled for the embedder.
639 if (static_cast<RenderViewHostImpl*>( 647 if (static_cast<RenderViewHostImpl*>(
640 owner_web_contents_->GetRenderViewHost())->input_method_active()) { 648 owner_web_contents_->GetRenderViewHost())->input_method_active()) {
641 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 649 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
642 GetWebContents()->GetRenderViewHost()); 650 GetWebContents()->GetRenderViewHost());
643 guest_rvh->SetInputMethodActive(true); 651 guest_rvh->SetInputMethodActive(true);
644 } 652 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 void BrowserPluginGuest::OnImeCompositionRangeChanged( 895 void BrowserPluginGuest::OnImeCompositionRangeChanged(
888 const gfx::Range& range, 896 const gfx::Range& range,
889 const std::vector<gfx::Rect>& character_bounds) { 897 const std::vector<gfx::Rect>& character_bounds) {
890 static_cast<RenderWidgetHostViewBase*>( 898 static_cast<RenderWidgetHostViewBase*>(
891 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 899 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
892 range, character_bounds); 900 range, character_bounds);
893 } 901 }
894 #endif 902 #endif
895 903
896 } // namespace content 904 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698