OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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) | |
Charlie Reis
2015/03/09 18:52:58
nit: Move these two lines above the previous comme
Fady Samuel
2015/03/09 23:02:41
Done.
| |
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_; | |
123 } | |
124 | |
125 int BrowserPluginGuest::LoadURLWithParams( | |
126 const NavigationController::LoadURLParams& load_params) { | |
127 GetWebContents()->GetController().LoadURLWithParams(load_params); | |
128 return GetGuestProxyRoutingID(); | |
Charlie Reis
2015/03/09 18:52:58
Should we be calling this before the navigation?
Fady Samuel
2015/03/09 23:02:41
As discussed offline, this should happen after nav
| |
105 } | 129 } |
106 | 130 |
107 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { | 131 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { |
108 GetWebContents()->GetView()->SizeContents(new_size); | 132 GetWebContents()->GetView()->SizeContents(new_size); |
109 } | 133 } |
110 | 134 |
135 void BrowserPluginGuest::WillDestroy() { | |
136 is_in_destruction_ = true; | |
137 owner_web_contents_ = nullptr; | |
138 attached_ = false; | |
139 } | |
140 | |
111 void BrowserPluginGuest::Init() { | 141 void BrowserPluginGuest::Init() { |
112 if (initialized_) | 142 if (initialized_) |
113 return; | 143 return; |
114 initialized_ = true; | 144 initialized_ = true; |
115 | 145 |
116 // TODO(fsamuel): Initiailization prior to attachment should be behind a | 146 // TODO(fsamuel): Initiailization prior to attachment should be behind a |
117 // command line flag once we introduce experimental guest types that rely on | 147 // command line flag once we introduce experimental guest types that rely on |
118 // this functionality. | 148 // this functionality. |
119 if (!delegate_->CanRunInDetachedState()) | 149 if (!delegate_->CanRunInDetachedState()) |
120 return; | 150 return; |
121 | 151 |
122 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>( | 152 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>( |
123 delegate_->GetOwnerWebContents()); | 153 delegate_->GetOwnerWebContents()); |
154 owner_web_contents->CreateBrowserPluginEmbedderIfNecessary(); | |
124 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents); | 155 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents); |
125 } | 156 } |
126 | 157 |
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() { | 158 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
134 return weak_ptr_factory_.GetWeakPtr(); | 159 return weak_ptr_factory_.GetWeakPtr(); |
135 } | 160 } |
136 | 161 |
137 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, | 162 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, |
138 bool focused, | 163 bool focused, |
139 blink::WebFocusType focus_type) { | 164 blink::WebFocusType focus_type) { |
140 focused_ = focused; | 165 focused_ = focused; |
141 if (!rwh) | 166 if (!rwh) |
142 return; | 167 return; |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 web_contents_view->CreateViewForWidget( | 638 web_contents_view->CreateViewForWidget( |
614 web_contents()->GetRenderViewHost(), true); | 639 web_contents()->GetRenderViewHost(), true); |
615 } | 640 } |
616 } | 641 } |
617 | 642 |
618 InitInternal(params, embedder_web_contents); | 643 InitInternal(params, embedder_web_contents); |
619 | 644 |
620 attached_ = true; | 645 attached_ = true; |
621 SendQueuedMessages(); | 646 SendQueuedMessages(); |
622 | 647 |
623 // Create a swapped out RenderView for the guest in the embedder render | 648 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 | 649 |
636 has_render_view_ = true; | 650 has_render_view_ = true; |
637 | 651 |
638 // Enable input method for guest if it's enabled for the embedder. | 652 // Enable input method for guest if it's enabled for the embedder. |
639 if (static_cast<RenderViewHostImpl*>( | 653 if (static_cast<RenderViewHostImpl*>( |
640 owner_web_contents_->GetRenderViewHost())->input_method_active()) { | 654 owner_web_contents_->GetRenderViewHost())->input_method_active()) { |
641 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 655 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
642 GetWebContents()->GetRenderViewHost()); | 656 GetWebContents()->GetRenderViewHost()); |
643 guest_rvh->SetInputMethodActive(true); | 657 guest_rvh->SetInputMethodActive(true); |
644 } | 658 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
887 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 901 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
888 const gfx::Range& range, | 902 const gfx::Range& range, |
889 const std::vector<gfx::Rect>& character_bounds) { | 903 const std::vector<gfx::Rect>& character_bounds) { |
890 static_cast<RenderWidgetHostViewBase*>( | 904 static_cast<RenderWidgetHostViewBase*>( |
891 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 905 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
892 range, character_bounds); | 906 range, character_bounds); |
893 } | 907 } |
894 #endif | 908 #endif |
895 | 909 |
896 } // namespace content | 910 } // namespace content |
OLD | NEW |