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

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 nit 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_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->SetGuestHost(this);
103 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); 103 }
104 delegate->SetGuestSizer(this); 104
105 int BrowserPluginGuest::GetGuestProxyRoutingID() {
106 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE)
107 return guest_proxy_routing_id_;
108
109 // Create a swapped out RenderView for the guest in the embedder renderer
110 // process, so that the embedder can access the guest's window object.
111 // On reattachment, we can reuse the same swapped out RenderView because
112 // the embedder process will always be the same even if the embedder
113 // WebContents changes.
114 //
115 // TODO(fsamuel): Make sure this works for transferring guests across
116 // owners in different processes. We probably need to clear the
117 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach
118 // to enable this.
119 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance();
120 guest_proxy_routing_id_ =
121 GetWebContents()->CreateSwappedOutRenderView(owner_site_instance);
122
123 return guest_proxy_routing_id_;
124 }
125
126 int BrowserPluginGuest::LoadURLWithParams(
127 const NavigationController::LoadURLParams& load_params) {
128 GetWebContents()->GetController().LoadURLWithParams(load_params);
129 return GetGuestProxyRoutingID();
105 } 130 }
106 131
107 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 132 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
108 GetWebContents()->GetView()->SizeContents(new_size); 133 GetWebContents()->GetView()->SizeContents(new_size);
109 } 134 }
110 135
136 void BrowserPluginGuest::WillDestroy() {
137 is_in_destruction_ = true;
138 owner_web_contents_ = nullptr;
139 attached_ = false;
140 }
141
111 void BrowserPluginGuest::Init() { 142 void BrowserPluginGuest::Init() {
112 if (initialized_) 143 if (initialized_)
113 return; 144 return;
114 initialized_ = true; 145 initialized_ = true;
115 146
116 // TODO(fsamuel): Initiailization prior to attachment should be behind a 147 // TODO(fsamuel): Initiailization prior to attachment should be behind a
117 // command line flag once we introduce experimental guest types that rely on 148 // command line flag once we introduce experimental guest types that rely on
118 // this functionality. 149 // this functionality.
119 if (!delegate_->CanRunInDetachedState()) 150 if (!delegate_->CanRunInDetachedState())
120 return; 151 return;
121 152
122 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>( 153 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
123 delegate_->GetOwnerWebContents()); 154 delegate_->GetOwnerWebContents());
155 owner_web_contents->CreateBrowserPluginEmbedderIfNecessary();
124 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents); 156 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
125 } 157 }
126 158
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() { 159 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
134 return weak_ptr_factory_.GetWeakPtr(); 160 return weak_ptr_factory_.GetWeakPtr();
135 } 161 }
136 162
137 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, 163 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh,
138 bool focused, 164 bool focused,
139 blink::WebFocusType focus_type) { 165 blink::WebFocusType focus_type) {
140 focused_ = focused; 166 focused_ = focused;
141 if (!rwh) 167 if (!rwh)
142 return; 168 return;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 web_contents_view->CreateViewForWidget( 639 web_contents_view->CreateViewForWidget(
614 web_contents()->GetRenderViewHost(), true); 640 web_contents()->GetRenderViewHost(), true);
615 } 641 }
616 } 642 }
617 643
618 InitInternal(params, embedder_web_contents); 644 InitInternal(params, embedder_web_contents);
619 645
620 attached_ = true; 646 attached_ = true;
621 SendQueuedMessages(); 647 SendQueuedMessages();
622 648
623 // Create a swapped out RenderView for the guest in the embedder render 649 delegate_->DidAttach(GetGuestProxyRoutingID());
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 650
636 has_render_view_ = true; 651 has_render_view_ = true;
637 652
638 // Enable input method for guest if it's enabled for the embedder. 653 // Enable input method for guest if it's enabled for the embedder.
639 if (static_cast<RenderViewHostImpl*>( 654 if (static_cast<RenderViewHostImpl*>(
640 owner_web_contents_->GetRenderViewHost())->input_method_active()) { 655 owner_web_contents_->GetRenderViewHost())->input_method_active()) {
641 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 656 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
642 GetWebContents()->GetRenderViewHost()); 657 GetWebContents()->GetRenderViewHost());
643 guest_rvh->SetInputMethodActive(true); 658 guest_rvh->SetInputMethodActive(true);
644 } 659 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 void BrowserPluginGuest::OnImeCompositionRangeChanged( 902 void BrowserPluginGuest::OnImeCompositionRangeChanged(
888 const gfx::Range& range, 903 const gfx::Range& range,
889 const std::vector<gfx::Rect>& character_bounds) { 904 const std::vector<gfx::Rect>& character_bounds) {
890 static_cast<RenderWidgetHostViewBase*>( 905 static_cast<RenderWidgetHostViewBase*>(
891 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 906 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
892 range, character_bounds); 907 range, character_bounds);
893 } 908 }
894 #endif 909 #endif
895 910
896 } // namespace content 911 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698