blob: fd53a0c31a5cd16d81fd1f9a7f1e6e7f22cd68a6 [file] [log] [blame]
[email protected]7a846df2012-09-20 19:17:391// 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
3// found in the LICENSE file.
4
5#include "content/browser/browser_plugin/browser_plugin_guest.h"
6
7#include <algorithm>
8
[email protected]95f861e2013-07-18 02:07:179#include "base/message_loop/message_loop.h"
[email protected]2101c4c2014-08-22 00:16:1610#include "base/pickle.h"
[email protected]74ebfb12013-06-07 20:48:0011#include "base/strings/utf_string_conversions.h"
[email protected]c88b2a562012-10-27 03:36:5612#include "content/browser/browser_plugin/browser_plugin_embedder.h"
[email protected]f85f5032013-04-03 09:01:5413#include "content/browser/browser_thread_impl.h"
[email protected]4b499622013-08-22 02:25:5914#include "content/browser/child_process_security_policy_impl.h"
[email protected]e5e438d62014-03-27 21:47:1615#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]63c33bd62014-02-08 04:45:4016#include "content/browser/frame_host/render_widget_host_view_guest.h"
[email protected]f85f5032013-04-03 09:01:5417#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]7a846df2012-09-20 19:17:3918#include "content/browser/renderer_host/render_view_host_impl.h"
19#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4820#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/web_contents/web_contents_impl.h"
[email protected]c4538072013-03-18 02:17:5522#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]2101c4c2014-08-22 00:16:1623#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4224#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f8501b12012-12-07 04:55:4325#include "content/common/content_constants_internal.h"
[email protected]a7fac9a2012-12-18 23:26:0726#include "content/common/drag_messages.h"
avi485e5fd62014-08-25 23:26:1427#include "content/common/frame_messages.h"
fsamuel04a6f5f2014-09-04 22:42:1428#include "content/common/host_shared_bitmap_manager.h"
[email protected]c084330e02013-04-27 01:08:1529#include "content/common/input_messages.h"
[email protected]c006fb52013-03-01 09:36:4530#include "content/common/view_messages.h"
[email protected]8eb04562013-03-06 03:41:1431#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2832#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]44703cc72013-01-24 04:56:0633#include "content/public/browser/content_browser_client.h"
fsamuel60b42282015-03-10 03:29:1434#include "content/public/browser/guest_host.h"
[email protected]7a846df2012-09-20 19:17:3935#include "content/public/browser/render_widget_host_view.h"
[email protected]2fae2c42012-10-03 21:20:0436#include "content/public/browser/user_metrics.h"
[email protected]e0c6dc92013-10-10 21:17:5137#include "content/public/browser/web_contents_observer.h"
[email protected]dc293a72013-07-01 11:11:2238#include "content/public/common/drop_data.h"
fsamuel656670b2014-09-10 20:47:5439#include "ui/gfx/geometry/size_conversions.h"
[email protected]7a846df2012-09-20 19:17:3940
[email protected]4f89d9d2012-12-12 01:38:4841#if defined(OS_MACOSX)
42#include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h"
43#endif
44
[email protected]7a846df2012-09-20 19:17:3945namespace content {
46
fsamuelad4f33f2014-11-28 19:32:2147class BrowserPluginGuest::EmbedderVisibilityObserver
[email protected]e0c6dc92013-10-10 21:17:5148 : public WebContentsObserver {
[email protected]ce0e2602013-03-15 20:53:2749 public:
fsamuelad4f33f2014-11-28 19:32:2150 explicit EmbedderVisibilityObserver(BrowserPluginGuest* guest)
[email protected]e0c6dc92013-10-10 21:17:5151 : WebContentsObserver(guest->embedder_web_contents()),
[email protected]ce0e2602013-03-15 20:53:2752 browser_plugin_guest_(guest) {
53 }
54
fsamuelad4f33f2014-11-28 19:32:2155 ~EmbedderVisibilityObserver() override {}
[email protected]ce0e2602013-03-15 20:53:2756
[email protected]70ab2642014-05-30 08:06:5857 // WebContentsObserver implementation.
dchengc2282aa2014-10-21 12:07:5858 void WasShown() override {
[email protected]e0c6dc92013-10-10 21:17:5159 browser_plugin_guest_->EmbedderVisibilityChanged(true);
60 }
61
dchengc2282aa2014-10-21 12:07:5862 void WasHidden() override {
[email protected]e0c6dc92013-10-10 21:17:5163 browser_plugin_guest_->EmbedderVisibilityChanged(false);
64 }
65
[email protected]ce0e2602013-03-15 20:53:2766 private:
67 BrowserPluginGuest* browser_plugin_guest_;
68
fsamuelad4f33f2014-11-28 19:32:2169 DISALLOW_COPY_AND_ASSIGN(EmbedderVisibilityObserver);
[email protected]ce0e2602013-03-15 20:53:2770};
71
[email protected]2101c4c2014-08-22 00:16:1672BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
73 WebContentsImpl* web_contents,
74 BrowserPluginGuestDelegate* delegate)
[email protected]7a846df2012-09-20 19:17:3975 : WebContentsObserver(web_contents),
fsamuel7310a4262014-12-05 05:06:4476 owner_web_contents_(nullptr),
fsamuelad4f33f2014-11-28 19:32:2177 attached_(false),
[email protected]2101c4c2014-08-22 00:16:1678 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone),
[email protected]c4538072013-03-18 02:17:5579 focused_(false),
[email protected]861f9782013-03-05 03:29:5480 mouse_locked_(false),
[email protected]a25acea72013-03-10 23:41:2881 pending_lock_request_(false),
[email protected]2ef8ba52014-05-13 22:39:4882 guest_visible_(false),
[email protected]93564f72013-02-15 13:26:1983 embedder_visible_(true),
raymes0fa0be52014-10-13 20:38:0984 is_full_page_plugin_(false),
[email protected]63449722013-08-13 02:31:3285 has_render_view_(has_render_view),
[email protected]f21d36e2014-01-16 19:24:0486 is_in_destruction_(false),
fsamuel7310a4262014-12-05 05:06:4487 initialized_(false),
[email protected]63c33bd62014-02-08 04:45:4088 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
89 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:2090 last_input_flags_(0),
[email protected]63c33bd62014-02-08 04:45:4091 last_can_compose_inline_(true),
fsamuela8484dd2014-10-02 00:51:3392 guest_proxy_routing_id_(MSG_ROUTING_NONE),
lazyboyf569b4f62015-02-03 17:22:5493 last_drag_status_(blink::WebDragStatusUnknown),
94 seen_embedder_system_drag_ended_(false),
95 seen_embedder_drag_source_ended_at_(false),
[email protected]4858e432014-06-23 18:14:1796 delegate_(delegate),
[email protected]f21d36e2014-01-16 19:24:0497 weak_ptr_factory_(this) {
[email protected]7a846df2012-09-20 19:17:3998 DCHECK(web_contents);
[email protected]4858e432014-06-23 18:14:1799 DCHECK(delegate);
100 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
101 web_contents->SetBrowserPluginGuest(this);
fsamuel60b42282015-03-10 03:29:14102 delegate->SetGuestHost(this);
103}
104
105int 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
126int BrowserPluginGuest::LoadURLWithParams(
127 const NavigationController::LoadURLParams& load_params) {
128 GetWebContents()->GetController().LoadURLWithParams(load_params);
129 return GetGuestProxyRoutingID();
paulmeyer0968abad2015-01-10 00:02:45130}
131
132void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
133 GetWebContents()->GetView()->SizeContents(new_size);
[email protected]eb72af632013-04-30 01:05:21134}
135
fsamuel60b42282015-03-10 03:29:14136void BrowserPluginGuest::WillDestroy() {
137 is_in_destruction_ = true;
138 owner_web_contents_ = nullptr;
139 attached_ = false;
140}
141
fsamuel7310a4262014-12-05 05:06:44142void BrowserPluginGuest::Init() {
143 if (initialized_)
144 return;
145 initialized_ = true;
146
147 // TODO(fsamuel): Initiailization prior to attachment should be behind a
148 // command line flag once we introduce experimental guest types that rely on
149 // this functionality.
150 if (!delegate_->CanRunInDetachedState())
151 return;
152
153 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
154 delegate_->GetOwnerWebContents());
fsamuel60b42282015-03-10 03:29:14155 owner_web_contents->CreateBrowserPluginEmbedderIfNecessary();
fsamuel7310a4262014-12-05 05:06:44156 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
157}
158
[email protected]8fb60c32014-02-02 17:46:40159base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
160 return weak_ptr_factory_.GetWeakPtr();
161}
162
fsamuel5ec049d2015-01-19 16:57:41163void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh,
164 bool focused,
165 blink::WebFocusType focus_type) {
fsamuel9e3d9ad2014-09-11 00:59:30166 focused_ = focused;
fsamuel66602da32014-09-12 22:02:43167 if (!rwh)
168 return;
169
fsamuel5ec049d2015-01-19 16:57:41170 if ((focus_type == blink::WebFocusTypeForward) ||
171 (focus_type == blink::WebFocusTypeBackward)) {
172 static_cast<RenderViewHostImpl*>(RenderViewHost::From(rwh))->
173 SetInitialFocus(focus_type == blink::WebFocusTypeBackward);
174 }
fsamuel9e3d9ad2014-09-11 00:59:30175 rwh->Send(new InputMsg_SetFocus(rwh->GetRoutingID(), focused));
176 if (!focused && mouse_locked_)
177 OnUnlockMouse();
178
179 // Restore the last seen state of text input to the view.
180 RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>(
fsamuel66602da32014-09-12 22:02:43181 rwh->GetView());
fsamuel9e3d9ad2014-09-11 00:59:30182 if (rwhv) {
shuchen3517bb62014-10-15 03:55:57183 rwhv->TextInputTypeChanged(last_text_input_type_, last_input_mode_,
shuchen82ce8c52014-10-23 01:55:20184 last_can_compose_inline_, last_input_flags_);
fsamuel9e3d9ad2014-09-11 00:59:30185 }
186}
187
paulmeyer66bf6fb2014-10-09 04:42:40188void BrowserPluginGuest::SetTooltipText(const base::string16& tooltip_text) {
paulmeyere80cfc92014-10-10 03:37:43189 if (tooltip_text == current_tooltip_text_)
190 return;
191 current_tooltip_text_ = tooltip_text;
192
paulmeyer66bf6fb2014-10-09 04:42:40193 SendMessageToEmbedder(new BrowserPluginMsg_SetTooltipText(
194 browser_plugin_instance_id_, tooltip_text));
195}
196
[email protected]660f18e2014-05-15 20:53:05197bool BrowserPluginGuest::LockMouse(bool allowed) {
198 if (!attached() || (mouse_locked_ == allowed))
199 return false;
200
201 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed);
202}
203
[email protected]4858e432014-06-23 18:14:17204WebContentsImpl* BrowserPluginGuest::CreateNewGuestWindow(
205 const WebContents::CreateParams& params) {
206 WebContentsImpl* new_contents =
207 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params));
208 DCHECK(new_contents);
209 return new_contents;
210}
211
[email protected]3997b1b22012-12-20 01:02:54212bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
213 const IPC::Message& message) {
fsamuel90e100b2014-09-10 14:25:44214 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>(
215 web_contents()->GetRenderWidgetHostView());
216 if (rwhv &&
217 rwhv->OnMessageReceivedFromEmbedder(
218 message,
219 static_cast<RenderViewHostImpl*>(
220 embedder_web_contents()->GetRenderViewHost()))) {
221 return true;
222 }
223
[email protected]3997b1b22012-12-20 01:02:54224 bool handled = true;
225 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
[email protected]95d31822014-01-03 22:21:55226 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK,
227 OnCompositorFrameSwappedACK)
fsamuela95fef42014-12-03 20:16:52228 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach)
[email protected]3997b1b22012-12-20 01:02:54229 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
230 OnDragStatusUpdate)
[email protected]6dd17a8a2013-05-01 05:50:10231 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand,
232 OnExecuteEditCommand)
[email protected]d260f042013-12-14 01:31:36233 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete,
234 OnExtendSelectionAndDelete)
[email protected]d260f042013-12-14 01:31:36235 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition,
236 OnImeConfirmComposition)
237 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition,
238 OnImeSetComposition)
[email protected]861f9782013-03-05 03:29:54239 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck)
[email protected]b0030b72013-11-15 20:35:53240 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources,
241 OnReclaimCompositorResources)
[email protected]b77fac52013-06-01 01:03:46242 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent,
243 OnSetEditCommandsForNextKeyEvent)
[email protected]3997b1b22012-12-20 01:02:54244 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
245 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
[email protected]861f9782013-03-05 03:29:54246 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
[email protected]32deec62013-05-15 23:55:04247 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
[email protected]3997b1b22012-12-20 01:02:54248 IPC_MESSAGE_UNHANDLED(handled = false)
249 IPC_END_MESSAGE_MAP()
250 return handled;
251}
252
fsamuel7310a4262014-12-05 05:06:44253void BrowserPluginGuest::InitInternal(
[email protected]c61b317c72013-11-14 06:40:46254 const BrowserPluginHostMsg_Attach_Params& params,
fsamuel7310a4262014-12-05 05:06:44255 WebContentsImpl* owner_web_contents) {
[email protected]c4538072013-03-18 02:17:55256 focused_ = params.focused;
fsamuel5ec049d2015-01-19 16:57:41257 OnSetFocus(browser_plugin::kInstanceIDNone,
258 focused_,
259 blink::WebFocusTypeNone);
fsamuel7310a4262014-12-05 05:06:44260
[email protected]c4538072013-03-18 02:17:55261 guest_visible_ = params.visible;
fsamuel7310a4262014-12-05 05:06:44262 UpdateVisibility();
263
raymes0fa0be52014-10-13 20:38:09264 is_full_page_plugin_ = params.is_full_page_plugin;
fsamuel49745bbf2015-02-25 20:07:03265 guest_window_rect_ = params.view_rect;
[email protected]32deec62013-05-15 23:55:04266
fsamuel7310a4262014-12-05 05:06:44267 if (owner_web_contents_ != owner_web_contents) {
268 WebContentsViewGuest* new_view =
269 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
270 if (owner_web_contents_)
271 new_view->OnGuestDetached(owner_web_contents_->GetView());
fsamuela8484dd2014-10-02 00:51:33272
fsamuel7310a4262014-12-05 05:06:44273 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
274 // be attached.
275 owner_web_contents_ = owner_web_contents;
276 new_view->OnGuestAttached(owner_web_contents_->GetView());
277 }
[email protected]2b3c7b32013-07-24 23:47:42278
[email protected]8eb04562013-03-06 03:41:14279 RendererPreferences* renderer_prefs =
280 GetWebContents()->GetMutableRendererPrefs();
[email protected]0d2f55e92013-09-26 03:13:17281 std::string guest_user_agent_override = renderer_prefs->user_agent_override;
[email protected]8eb04562013-03-06 03:41:14282 // Copy renderer preferences (and nothing else) from the embedder's
283 // WebContents to the guest.
284 //
285 // For GTK and Aura this is necessary to get proper renderer configuration
286 // values for caret blinking interval, colors related to selection and
287 // focus.
fsamuelad4f33f2014-11-28 19:32:21288 *renderer_prefs = *owner_web_contents_->GetMutableRendererPrefs();
[email protected]0d2f55e92013-09-26 03:13:17289 renderer_prefs->user_agent_override = guest_user_agent_override;
[email protected]8eb04562013-03-06 03:41:14290
[email protected]8eb04562013-03-06 03:41:14291 // We would like the guest to report changes to frame names so that we can
292 // update the BrowserPlugin's corresponding 'name' attribute.
293 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed.
294 renderer_prefs->report_frame_name_changes = true;
[email protected]7fdb6ac2014-02-07 18:33:32295 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated
296 // navigations still continue to function inside the app.
297 renderer_prefs->browser_handles_all_top_level_requests = false;
[email protected]f677288e2013-09-18 02:11:00298 // Disable "client blocked" error page for browser plugin.
299 renderer_prefs->disable_client_blocked_error_page = true;
[email protected]31942c82012-10-05 17:01:54300
fsamuelad4f33f2014-11-28 19:32:21301 embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this));
[email protected]93564f72013-02-15 13:26:19302
paulmeyer9ef6e4462015-02-24 19:15:10303 DCHECK(GetWebContents()->GetRenderViewHost());
304
305 // Initialize the device scale factor by calling |NotifyScreenInfoChanged|.
306 auto render_widget_host =
307 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost());
308 render_widget_host->NotifyScreenInfoChanged();
[email protected]44703cc72013-01-24 04:56:06309
[email protected]9e797d22014-08-08 21:31:30310 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will
311 // be reset again the next time preferences are updated.
312 WebPreferences prefs =
313 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences();
[email protected]f1b6aa7c2014-02-20 22:10:26314 prefs.navigate_on_drag_drop = false;
[email protected]f1b6aa7c2014-02-20 22:10:26315 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
[email protected]7a846df2012-09-20 19:17:39316}
317
318BrowserPluginGuest::~BrowserPluginGuest() {
319}
320
321// static
322BrowserPluginGuest* BrowserPluginGuest::Create(
[email protected]738f57a2013-06-29 21:06:54323 WebContentsImpl* web_contents,
[email protected]4858e432014-06-23 18:14:17324 BrowserPluginGuestDelegate* delegate) {
325 return new BrowserPluginGuest(
fsamuel7df36b22015-01-21 20:13:07326 web_contents->opener() != nullptr, web_contents, delegate);
[email protected]7a846df2012-09-20 19:17:39327}
328
[email protected]a24efc22014-05-26 15:50:25329// static
330bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) {
331 return web_contents && web_contents->GetBrowserPluginGuest();
332}
333
334// static
335bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
336 return render_view_host && IsGuest(
337 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
338 render_view_host)));
339}
340
fsamuelad4f33f2014-11-28 19:32:21341RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
342 if (!owner_web_contents_)
fsamuel7df36b22015-01-21 20:13:07343 return nullptr;
fsamuelad4f33f2014-11-28 19:32:21344 return owner_web_contents_->GetRenderWidgetHostView();
[email protected]44327692013-02-26 21:21:22345}
346
[email protected]3997b1b22012-12-20 01:02:54347void BrowserPluginGuest::UpdateVisibility() {
[email protected]2101c4c2014-08-22 00:16:16348 OnSetVisibility(browser_plugin_instance_id(), visible());
[email protected]3997b1b22012-12-20 01:02:54349}
350
[email protected]139355f2014-05-11 14:21:28351BrowserPluginGuestManager*
[email protected]24569262014-05-06 03:31:30352BrowserPluginGuest::GetBrowserPluginGuestManager() const {
[email protected]139355f2014-05-11 14:21:28353 return GetWebContents()->GetBrowserContext()->GetGuestManager();
[email protected]24569262014-05-06 03:31:30354}
355
[email protected]e0c6dc92013-10-10 21:17:51356void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) {
357 embedder_visible_ = visible;
358 UpdateVisibility();
[email protected]31942c82012-10-05 17:01:54359}
360
[email protected]7a1280892014-04-16 17:18:25361void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) {
362 SendMessageToEmbedder(
[email protected]2101c4c2014-08-22 00:16:16363 new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow));
[email protected]7a1280892014-04-16 17:18:25364}
365
fsamuel04a6f5f2014-09-04 22:42:14366void BrowserPluginGuest::SwapCompositorFrame(
367 uint32 output_surface_id,
368 int host_process_id,
369 int host_routing_id,
370 scoped_ptr<cc::CompositorFrame> frame) {
fsamuel478927e2014-09-06 13:16:17371 cc::RenderPass* root_pass =
372 frame->delegated_frame_data->render_pass_list.back();
fsamuel656670b2014-09-10 20:47:54373 gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize(
374 root_pass->output_rect.size(),
375 1.0f / frame->metadata.device_scale_factor)));
376
fsamuel04a6f5f2014-09-04 22:42:14377 if (last_seen_view_size_ != view_size) {
paulmeyer647b4f12015-01-26 21:40:08378 delegate_->GuestSizeChanged(view_size);
fsamuel04a6f5f2014-09-04 22:42:14379 last_seen_view_size_ = view_size;
380 }
381
fsamuel7310a4262014-12-05 05:06:44382 last_pending_frame_.reset(new FrameMsg_CompositorFrameSwapped_Params());
383 frame->AssignTo(&last_pending_frame_->frame);
384 last_pending_frame_->output_surface_id = output_surface_id;
385 last_pending_frame_->producing_route_id = host_routing_id;
386 last_pending_frame_->producing_host_id = host_process_id;
387
fsamuel04a6f5f2014-09-04 22:42:14388 SendMessageToEmbedder(
389 new BrowserPluginMsg_CompositorFrameSwapped(
fsamuel7310a4262014-12-05 05:06:44390 browser_plugin_instance_id(), *last_pending_frame_));
fsamuel04a6f5f2014-09-04 22:42:14391}
392
fsamuel516005f2014-09-20 16:57:58393void BrowserPluginGuest::SetContentsOpaque(bool opaque) {
394 SendMessageToEmbedder(
395 new BrowserPluginMsg_SetContentsOpaque(
396 browser_plugin_instance_id(), opaque));
397}
398
raymes0fa0be52014-10-13 20:38:09399bool BrowserPluginGuest::Find(int request_id,
400 const base::string16& search_text,
401 const blink::WebFindOptions& options) {
sammce2092512014-11-24 22:18:24402 return delegate_->Find(request_id, search_text, options);
raymes0fa0be52014-10-13 20:38:09403}
404
raymes2bc64182015-02-06 01:23:01405bool BrowserPluginGuest::StopFinding(StopFindAction action) {
406 return delegate_->StopFinding(action);
407}
408
[email protected]24569262014-05-06 03:31:30409WebContentsImpl* BrowserPluginGuest::GetWebContents() const {
[email protected]8eb04562013-03-06 03:41:14410 return static_cast<WebContentsImpl*>(web_contents());
[email protected]e17b7c62012-09-21 21:05:46411}
412
[email protected]ca61ce142012-11-27 21:32:57413gfx::Point BrowserPluginGuest::GetScreenCoordinates(
414 const gfx::Point& relative_position) const {
[email protected]3d888fa2014-07-11 19:27:16415 if (!attached())
416 return relative_position;
417
[email protected]ca61ce142012-11-27 21:32:57418 gfx::Point screen_pos(relative_position);
419 screen_pos += guest_window_rect_.OffsetFromOrigin();
[email protected]3d888fa2014-07-11 19:27:16420 if (embedder_web_contents()->GetBrowserPluginGuest()) {
421 BrowserPluginGuest* embedder_guest =
422 embedder_web_contents()->GetBrowserPluginGuest();
423 screen_pos += embedder_guest->guest_window_rect_.OffsetFromOrigin();
424 }
[email protected]ca61ce142012-11-27 21:32:57425 return screen_pos;
426}
427
[email protected]a7fac9a2012-12-18 23:26:07428void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
[email protected]c4538072013-03-18 02:17:55429 if (!attached()) {
[email protected]697f16b52013-05-10 06:01:18430 // Some pages such as data URLs, javascript URLs, and about:blank
431 // do not load external resources and so they load prior to attachment.
432 // As a result, we must save all these IPCs until attachment and then
433 // forward them so that the embedder gets a chance to see and process
434 // the load events.
[email protected]10b21b32014-06-07 09:54:33435 pending_messages_.push_back(linked_ptr<IPC::Message>(msg));
[email protected]c4538072013-03-18 02:17:55436 return;
437 }
fsamuelad4f33f2014-11-28 19:32:21438 owner_web_contents_->Send(msg);
[email protected]a7fac9a2012-12-18 23:26:07439}
440
[email protected]cf200a562013-05-03 16:24:29441void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:46442 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:29443 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
444 screen_x, screen_y, operation);
lazyboyf569b4f62015-02-03 17:22:54445 seen_embedder_drag_source_ended_at_ = true;
446 EndSystemDragIfApplicable();
[email protected]cf200a562013-05-03 16:24:29447}
448
lazyboyf569b4f62015-02-03 17:22:54449void BrowserPluginGuest::EndSystemDragIfApplicable() {
450 // Ideally we'd want either WebDragStatusDrop or WebDragStatusLeave...
451 // Call guest RVH->DragSourceSystemDragEnded() correctly on the guest where
452 // the drag was initiated. Calling DragSourceSystemDragEnded() correctly
453 // means we call it in all cases and also make sure we only call it once.
454 // This ensures that the input state of the guest stays correct, otherwise
455 // it will go stale and won't accept any further input events.
456 //
457 // The strategy used here to call DragSourceSystemDragEnded() on the RVH
458 // is when the following conditions are met:
459 // a. Embedder has seen SystemDragEnded()
460 // b. Embedder has seen DragSourceEndedAt()
461 // c. The guest has seen some drag status update other than
462 // WebDragStatusUnknown. Note that this step should ideally be done
463 // differently: The guest has seen at least one of
464 // {WebDragStatusOver, WebDragStatusDrop}. However, if a user drags
465 // a source quickly outside of <webview> bounds, then the
466 // BrowserPluginGuest never sees any of these drag status updates,
467 // there we just check whether we've seen any drag status update or
468 // not.
469 if (last_drag_status_ != blink::WebDragStatusOver &&
470 seen_embedder_drag_source_ended_at_ && seen_embedder_system_drag_ended_) {
471 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
472 GetWebContents()->GetRenderViewHost());
473 guest_rvh->DragSourceSystemDragEnded();
lazyboyf569b4f62015-02-03 17:22:54474 last_drag_status_ = blink::WebDragStatusUnknown;
475 seen_embedder_system_drag_ended_ = false;
476 seen_embedder_drag_source_ended_at_ = false;
fsamuelbdfc1ad2015-02-24 02:10:02477 dragged_url_ = GURL();
lazyboyf569b4f62015-02-03 17:22:54478 }
479}
480
481void BrowserPluginGuest::EmbedderSystemDragEnded() {
482 seen_embedder_system_drag_ended_ = true;
483 EndSystemDragIfApplicable();
[email protected]cf200a562013-05-03 16:24:29484}
485
[email protected]697f16b52013-05-10 06:01:18486void BrowserPluginGuest::SendQueuedMessages() {
487 if (!attached())
488 return;
489
490 while (!pending_messages_.empty()) {
[email protected]10b21b32014-06-07 09:54:33491 linked_ptr<IPC::Message> message_ptr = pending_messages_.front();
492 pending_messages_.pop_front();
493 SendMessageToEmbedder(message_ptr.release());
[email protected]697f16b52013-05-10 06:01:18494 }
495}
496
[email protected]7a846df2012-09-20 19:17:39497void BrowserPluginGuest::DidCommitProvisionalLoadForFrame(
[email protected]860234a2014-07-01 00:35:31498 RenderFrameHost* render_frame_host,
[email protected]7a846df2012-09-20 19:17:39499 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35500 ui::PageTransition transition_type) {
[email protected]e6e30ac2014-01-13 21:24:39501 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate"));
[email protected]7a846df2012-09-20 19:17:39502}
503
[email protected]c88b2a562012-10-27 03:36:56504void BrowserPluginGuest::RenderViewReady() {
[email protected]543afaf2013-12-13 14:03:22505 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost();
[email protected]c88b2a562012-10-27 03:36:56506 // TODO(fsamuel): Investigate whether it's possible to update state earlier
[email protected]dba9bd22012-12-06 23:04:03507 // here (see http://crbug.com/158151).
[email protected]c084330e02013-04-27 01:08:15508 Send(new InputMsg_SetFocus(routing_id(), focused_));
[email protected]3997b1b22012-12-20 01:02:54509 UpdateVisibility();
[email protected]25bcc8f2013-01-09 02:49:25510
jdduked20d7b32015-03-09 23:55:13511 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay(
[email protected]2ef8ba52014-05-13 22:39:48512 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs));
[email protected]c88b2a562012-10-27 03:36:56513}
514
[email protected]58d5cfe2013-07-10 02:40:52515void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) {
[email protected]2101c4c2014-08-22 00:16:16516 SendMessageToEmbedder(
517 new BrowserPluginMsg_GuestGone(browser_plugin_instance_id()));
[email protected]2fae2c42012-10-03 21:20:04518 switch (status) {
519 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
[email protected]e6e30ac2014-01-13 21:24:39520 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed"));
[email protected]2fae2c42012-10-03 21:20:04521 break;
522 case base::TERMINATION_STATUS_PROCESS_CRASHED:
[email protected]e6e30ac2014-01-13 21:24:39523 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Crashed"));
[email protected]2fae2c42012-10-03 21:20:04524 break;
525 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
[email protected]e6e30ac2014-01-13 21:24:39526 RecordAction(
527 base::UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath"));
[email protected]2fae2c42012-10-03 21:20:04528 break;
529 default:
530 break;
531 }
[email protected]7a846df2012-09-20 19:17:39532}
533
[email protected]8eb04562013-03-06 03:41:14534// static
[email protected]8eb04562013-03-06 03:41:14535bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(
536 const IPC::Message& message) {
537 switch (message.type()) {
[email protected]95d31822014-01-03 22:21:55538 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID:
fsamuela95fef42014-12-03 20:16:52539 case BrowserPluginHostMsg_Detach::ID:
[email protected]8eb04562013-03-06 03:41:14540 case BrowserPluginHostMsg_DragStatusUpdate::ID:
[email protected]6dd17a8a2013-05-01 05:50:10541 case BrowserPluginHostMsg_ExecuteEditCommand::ID:
[email protected]d260f042013-12-14 01:31:36542 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID:
[email protected]8eb04562013-03-06 03:41:14543 case BrowserPluginHostMsg_HandleInputEvent::ID:
[email protected]d260f042013-12-14 01:31:36544 case BrowserPluginHostMsg_ImeConfirmComposition::ID:
545 case BrowserPluginHostMsg_ImeSetComposition::ID:
[email protected]8eb04562013-03-06 03:41:14546 case BrowserPluginHostMsg_LockMouse_ACK::ID:
[email protected]b0030b72013-11-15 20:35:53547 case BrowserPluginHostMsg_ReclaimCompositorResources::ID:
[email protected]b77fac52013-06-01 01:03:46548 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID:
[email protected]8eb04562013-03-06 03:41:14549 case BrowserPluginHostMsg_SetFocus::ID:
[email protected]8eb04562013-03-06 03:41:14550 case BrowserPluginHostMsg_SetVisibility::ID:
[email protected]8eb04562013-03-06 03:41:14551 case BrowserPluginHostMsg_UnlockMouse_ACK::ID:
[email protected]32deec62013-05-15 23:55:04552 case BrowserPluginHostMsg_UpdateGeometry::ID:
[email protected]8eb04562013-03-06 03:41:14553 return true;
554 default:
[email protected]c61b317c72013-11-14 06:40:46555 return false;
[email protected]8eb04562013-03-06 03:41:14556 }
[email protected]8eb04562013-03-06 03:41:14557}
558
[email protected]a7fac9a2012-12-18 23:26:07559bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) {
560 bool handled = true;
561 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
[email protected]a2214eb2014-06-23 18:31:22562 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition,
563 OnImeCancelComposition)
564#if defined(OS_MACOSX) || defined(USE_AURA)
565 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged,
566 OnImeCompositionRangeChanged)
567#endif
[email protected]a7fac9a2012-12-18 23:26:07568 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
569 OnHasTouchEventHandlers)
[email protected]861f9782013-03-05 03:29:54570 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse)
[email protected]a7fac9a2012-12-18 23:26:07571 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget)
572 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
shuchen3517bb62014-10-15 03:55:57573 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputTypeChanged,
574 OnTextInputTypeChanged)
[email protected]861f9782013-03-05 03:29:54575 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse)
[email protected]a7fac9a2012-12-18 23:26:07576 IPC_MESSAGE_UNHANDLED(handled = false)
577 IPC_END_MESSAGE_MAP()
578 return handled;
579}
580
avi485e5fd62014-08-25 23:26:14581bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message,
582 RenderFrameHost* render_frame_host) {
583 // This will eventually be the home for more IPC handlers that depend on
584 // RenderFrameHost. Until more are moved here, though, the IPC_* macros won't
585 // compile if there are no handlers for a platform. So we have both #if guards
586 // around the whole thing (unfortunate but temporary), and #if guards where
587 // they belong, only around the one IPC handler. TODO(avi): Move more of the
588 // frame-based handlers to this function and remove the outer #if layer.
589#if defined(OS_MACOSX)
590 bool handled = true;
591 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BrowserPluginGuest, message,
592 render_frame_host)
593#if defined(OS_MACOSX)
594 // MacOS X creates and populates platform-specific select drop-down menus
595 // whereas other platforms merely create a popup window that the guest
596 // renderer process paints inside.
597 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup)
598#endif
599 IPC_MESSAGE_UNHANDLED(handled = false)
600 IPC_END_MESSAGE_MAP()
601 return handled;
602#else
603 return false;
604#endif
605}
606
[email protected]c4538072013-03-18 02:17:55607void BrowserPluginGuest::Attach(
[email protected]2101c4c2014-08-22 00:16:16608 int browser_plugin_instance_id,
[email protected]c4538072013-03-18 02:17:55609 WebContentsImpl* embedder_web_contents,
[email protected]2101c4c2014-08-22 00:16:16610 const BrowserPluginHostMsg_Attach_Params& params) {
fsamuel7310a4262014-12-05 05:06:44611 browser_plugin_instance_id_ = browser_plugin_instance_id;
612 // If a guest is detaching from one container and attaching to another
613 // container, then late arriving ACKs may be lost if the mapping from
614 // |browser_plugin_instance_id| to |guest_instance_id| changes. Thus we
615 // ensure that we always get new frames on attachment by ACKing the pending
616 // frame if it's still waiting on the ACK.
617 if (last_pending_frame_) {
618 cc::CompositorFrameAck ack;
619 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
620 last_pending_frame_->producing_route_id,
621 last_pending_frame_->output_surface_id,
622 last_pending_frame_->producing_host_id,
623 ack);
624 last_pending_frame_.reset();
625 }
sammce2092512014-11-24 22:18:24626 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
627 params.is_full_page_plugin);
[email protected]d84d57b2014-06-20 22:42:39628
[email protected]0c6d41752013-05-01 15:49:09629 // If a RenderView has already been created for this new window, then we need
[email protected]b0936d22013-11-28 06:47:36630 // to initialize the browser-side state now so that the RenderFrameHostManager
[email protected]0c6d41752013-05-01 15:49:09631 // does not create a new RenderView on navigation.
632 if (has_render_view_) {
fsamuela8484dd2014-10-02 00:51:33633 // This will trigger a callback to RenderViewReady after a round-trip IPC.
[email protected]0c6d41752013-05-01 15:49:09634 static_cast<RenderViewHostImpl*>(
635 GetWebContents()->GetRenderViewHost())->Init();
fsamuela8484dd2014-10-02 00:51:33636 WebContentsViewGuest* web_contents_view =
[email protected]c4538072013-03-18 02:17:55637 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
fsamuela8484dd2014-10-02 00:51:33638 if (!web_contents()->GetRenderViewHost()->GetView()) {
639 web_contents_view->CreateViewForWidget(
lazyboy549b3b42014-10-20 17:16:04640 web_contents()->GetRenderViewHost(), true);
fsamuela8484dd2014-10-02 00:51:33641 }
[email protected]c4538072013-03-18 02:17:55642 }
[email protected]0c6d41752013-05-01 15:49:09643
fsamuel7310a4262014-12-05 05:06:44644 InitInternal(params, embedder_web_contents);
[email protected]c4538072013-03-18 02:17:55645
fsamuela95fef42014-12-03 20:16:52646 attached_ = true;
[email protected]697f16b52013-05-10 06:01:18647 SendQueuedMessages();
[email protected]abc7d5c2013-05-15 09:19:25648
fsamuel60b42282015-03-10 03:29:14649 delegate_->DidAttach(GetGuestProxyRoutingID());
fsamuela8484dd2014-10-02 00:51:33650
651 has_render_view_ = true;
[email protected]d84d57b2014-06-20 22:42:39652
lazyboy8b0b5d02015-02-07 00:02:12653 // Enable input method for guest if it's enabled for the embedder.
654 if (static_cast<RenderViewHostImpl*>(
655 owner_web_contents_->GetRenderViewHost())->input_method_active()) {
656 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
657 GetWebContents()->GetRenderViewHost());
658 guest_rvh->SetInputMethodActive(true);
659 }
660
[email protected]e6e30ac2014-01-13 21:24:39661 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached"));
[email protected]c4538072013-03-18 02:17:55662}
663
[email protected]95d31822014-01-03 22:21:55664void BrowserPluginGuest::OnCompositorFrameSwappedACK(
[email protected]2101c4c2014-08-22 00:16:16665 int browser_plugin_instance_id,
[email protected]95d31822014-01-03 22:21:55666 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
667 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
668 params.output_surface_id,
669 params.producing_host_id,
670 params.ack);
fsamuel7310a4262014-12-05 05:06:44671 last_pending_frame_.reset();
[email protected]f5b4b0f2013-04-02 18:16:28672}
673
fsamuela95fef42014-12-03 20:16:52674void BrowserPluginGuest::OnDetach(int browser_plugin_instance_id) {
675 if (!attached())
676 return;
677
678 // This tells BrowserPluginGuest to queue up all IPCs to BrowserPlugin until
679 // it's attached again.
680 attached_ = false;
681
682 delegate_->DidDetach();
683}
684
[email protected]2101c4c2014-08-22 00:16:16685void BrowserPluginGuest::OnDragStatusUpdate(int browser_plugin_instance_id,
[email protected]180ef242013-11-07 06:50:46686 blink::WebDragStatus drag_status,
[email protected]dc293a72013-07-01 11:11:22687 const DropData& drop_data,
[email protected]180ef242013-11-07 06:50:46688 blink::WebDragOperationsMask mask,
[email protected]3997b1b22012-12-20 01:02:54689 const gfx::Point& location) {
[email protected]8eb04562013-03-06 03:41:14690 RenderViewHost* host = GetWebContents()->GetRenderViewHost();
fsamuelbdfc1ad2015-02-24 02:10:02691 auto embedder = owner_web_contents_->GetBrowserPluginEmbedder();
[email protected]3997b1b22012-12-20 01:02:54692 switch (drag_status) {
[email protected]180ef242013-11-07 06:50:46693 case blink::WebDragStatusEnter:
fsamuelbdfc1ad2015-02-24 02:10:02694 // Only track the URL being dragged over the guest if the link isn't
695 // coming from the guest.
696 if (!embedder->DragEnteredGuest(this))
697 dragged_url_ = drop_data.url;
[email protected]3997b1b22012-12-20 01:02:54698 host->DragTargetDragEnter(drop_data, location, location, mask, 0);
699 break;
[email protected]180ef242013-11-07 06:50:46700 case blink::WebDragStatusOver:
[email protected]3997b1b22012-12-20 01:02:54701 host->DragTargetDragOver(location, location, mask, 0);
702 break;
[email protected]180ef242013-11-07 06:50:46703 case blink::WebDragStatusLeave:
fsamuelbdfc1ad2015-02-24 02:10:02704 embedder->DragLeftGuest(this);
[email protected]3997b1b22012-12-20 01:02:54705 host->DragTargetDragLeave();
706 break;
[email protected]180ef242013-11-07 06:50:46707 case blink::WebDragStatusDrop:
[email protected]3997b1b22012-12-20 01:02:54708 host->DragTargetDrop(location, location, 0);
fsamuelbdfc1ad2015-02-24 02:10:02709 if (dragged_url_.is_valid()) {
710 delegate_->DidDropLink(dragged_url_);
711 dragged_url_ = GURL();
712 }
[email protected]3997b1b22012-12-20 01:02:54713 break;
[email protected]180ef242013-11-07 06:50:46714 case blink::WebDragStatusUnknown:
[email protected]3997b1b22012-12-20 01:02:54715 NOTREACHED();
716 }
lazyboyf569b4f62015-02-03 17:22:54717 last_drag_status_ = drag_status;
718 EndSystemDragIfApplicable();
[email protected]3997b1b22012-12-20 01:02:54719}
720
[email protected]2101c4c2014-08-22 00:16:16721void BrowserPluginGuest::OnExecuteEditCommand(int browser_plugin_instance_id,
[email protected]6dd17a8a2013-05-01 05:50:10722 const std::string& name) {
sammcbc9e99332014-12-18 00:55:24723 RenderFrameHost* focused_frame = web_contents()->GetFocusedFrame();
724 if (!focused_frame)
725 return;
726
727 focused_frame->Send(new InputMsg_ExecuteNoValueEditCommand(
728 focused_frame->GetRoutingID(), name));
[email protected]6dd17a8a2013-05-01 05:50:10729}
730
[email protected]d260f042013-12-14 01:31:36731void BrowserPluginGuest::OnImeSetComposition(
[email protected]2101c4c2014-08-22 00:16:16732 int browser_plugin_instance_id,
[email protected]d260f042013-12-14 01:31:36733 const std::string& text,
734 const std::vector<blink::WebCompositionUnderline>& underlines,
735 int selection_start,
736 int selection_end) {
[email protected]a2214eb2014-06-23 18:31:22737 Send(new InputMsg_ImeSetComposition(routing_id(),
738 base::UTF8ToUTF16(text), underlines,
739 selection_start, selection_end));
[email protected]d260f042013-12-14 01:31:36740}
741
742void BrowserPluginGuest::OnImeConfirmComposition(
[email protected]2101c4c2014-08-22 00:16:16743 int browser_plugin_instance_id,
[email protected]d260f042013-12-14 01:31:36744 const std::string& text,
745 bool keep_selection) {
[email protected]a2214eb2014-06-23 18:31:22746 Send(new InputMsg_ImeConfirmComposition(routing_id(),
747 base::UTF8ToUTF16(text),
748 gfx::Range::InvalidRange(),
749 keep_selection));
[email protected]d260f042013-12-14 01:31:36750}
751
752void BrowserPluginGuest::OnExtendSelectionAndDelete(
[email protected]2101c4c2014-08-22 00:16:16753 int browser_plugin_instance_id,
[email protected]d260f042013-12-14 01:31:36754 int before,
755 int after) {
[email protected]e5e438d62014-03-27 21:47:16756 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
757 web_contents()->GetFocusedFrame());
758 if (rfh)
759 rfh->ExtendSelectionAndDelete(before, after);
[email protected]d260f042013-12-14 01:31:36760}
761
[email protected]b0030b72013-11-15 20:35:53762void BrowserPluginGuest::OnReclaimCompositorResources(
[email protected]2101c4c2014-08-22 00:16:16763 int browser_plugin_instance_id,
[email protected]bffc8302014-01-23 20:52:16764 const FrameHostMsg_ReclaimCompositorResources_Params& params) {
765 RenderWidgetHostImpl::SendReclaimCompositorResources(params.route_id,
766 params.output_surface_id,
767 params.renderer_host_id,
768 params.ack);
[email protected]b0030b72013-11-15 20:35:53769}
770
[email protected]861f9782013-03-05 03:29:54771void BrowserPluginGuest::OnLockMouse(bool user_gesture,
772 bool last_unlocked_by_target,
773 bool privileged) {
[email protected]02768b762013-10-02 20:39:34774 if (pending_lock_request_) {
[email protected]a25acea72013-03-10 23:41:28775 // Immediately reject the lock because only one pointerLock may be active
776 // at a time.
777 Send(new ViewMsg_LockMouse_ACK(routing_id(), false));
778 return;
779 }
[email protected]a25acea72013-03-10 23:41:28780
[email protected]7a1280892014-04-16 17:18:25781 pending_lock_request_ = true;
782
783 delegate_->RequestPointerLockPermission(
784 user_gesture,
785 last_unlocked_by_target,
786 base::Bind(&BrowserPluginGuest::PointerLockPermissionResponse,
787 weak_ptr_factory_.GetWeakPtr()));
[email protected]861f9782013-03-05 03:29:54788}
789
[email protected]2101c4c2014-08-22 00:16:16790void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id,
791 bool succeeded) {
[email protected]861f9782013-03-05 03:29:54792 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded));
[email protected]a25acea72013-03-10 23:41:28793 pending_lock_request_ = false;
[email protected]861f9782013-03-05 03:29:54794 if (succeeded)
795 mouse_locked_ = true;
796}
797
[email protected]2101c4c2014-08-22 00:16:16798void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id,
fsamuel5ec049d2015-01-19 16:57:41799 bool focused,
800 blink::WebFocusType focus_type) {
fsamuel66602da32014-09-12 22:02:43801 RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView();
fsamuel7df36b22015-01-21 20:13:07802 RenderWidgetHost* rwh = rwhv ? rwhv->GetRenderWidgetHost() : nullptr;
fsamuel5ec049d2015-01-19 16:57:41803 SetFocus(rwh, focused, focus_type);
[email protected]423838472013-01-09 00:16:46804}
805
[email protected]b77fac52013-06-01 01:03:46806void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent(
[email protected]2101c4c2014-08-22 00:16:16807 int browser_plugin_instance_id,
[email protected]b77fac52013-06-01 01:03:46808 const std::vector<EditCommand>& edit_commands) {
809 Send(new InputMsg_SetEditCommandsForNextKeyEvent(routing_id(),
810 edit_commands));
811}
812
[email protected]2101c4c2014-08-22 00:16:16813void BrowserPluginGuest::OnSetVisibility(int browser_plugin_instance_id,
814 bool visible) {
[email protected]93564f72013-02-15 13:26:19815 guest_visible_ = visible;
816 if (embedder_visible_ && guest_visible_)
[email protected]8eb04562013-03-06 03:41:14817 GetWebContents()->WasShown();
[email protected]3997b1b22012-12-20 01:02:54818 else
[email protected]8eb04562013-03-06 03:41:14819 GetWebContents()->WasHidden();
[email protected]3997b1b22012-12-20 01:02:54820}
821
[email protected]861f9782013-03-05 03:29:54822void BrowserPluginGuest::OnUnlockMouse() {
[email protected]b60b88942013-07-20 05:58:42823 SendMessageToEmbedder(
[email protected]2101c4c2014-08-22 00:16:16824 new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), false));
[email protected]861f9782013-03-05 03:29:54825}
826
[email protected]2101c4c2014-08-22 00:16:16827void BrowserPluginGuest::OnUnlockMouseAck(int browser_plugin_instance_id) {
[email protected]861f9782013-03-05 03:29:54828 // mouse_locked_ could be false here if the lock attempt was cancelled due
829 // to window focus, or for various other reasons before the guest was informed
830 // of the lock's success.
831 if (mouse_locked_)
832 Send(new ViewMsg_MouseLockLost(routing_id()));
833 mouse_locked_ = false;
834}
835
[email protected]2101c4c2014-08-22 00:16:16836void BrowserPluginGuest::OnUpdateGeometry(int browser_plugin_instance_id,
[email protected]32deec62013-05-15 23:55:04837 const gfx::Rect& view_rect) {
838 // The plugin has moved within the embedder without resizing or the
839 // embedder/container's view rect changing.
840 guest_window_rect_ = view_rect;
841 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
842 GetWebContents()->GetRenderViewHost());
843 if (rvh)
844 rvh->SendScreenRects();
845}
846
[email protected]a7fac9a2012-12-18 23:26:07847void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) {
848 SendMessageToEmbedder(
[email protected]2101c4c2014-08-22 00:16:16849 new BrowserPluginMsg_ShouldAcceptTouchEvents(
850 browser_plugin_instance_id(), accept));
[email protected]a7fac9a2012-12-18 23:26:07851}
852
[email protected]a7fac9a2012-12-18 23:26:07853#if defined(OS_MACOSX)
854void BrowserPluginGuest::OnShowPopup(
avi485e5fd62014-08-25 23:26:14855 RenderFrameHost* render_frame_host,
856 const FrameHostMsg_ShowPopup_Params& params) {
[email protected]a7fac9a2012-12-18 23:26:07857 gfx::Rect translated_bounds(params.bounds);
858 translated_bounds.Offset(guest_window_rect_.OffsetFromOrigin());
859 BrowserPluginPopupMenuHelper popup_menu_helper(
fsamuelad4f33f2014-11-28 19:32:21860 owner_web_contents_->GetRenderViewHost(), render_frame_host);
[email protected]a7fac9a2012-12-18 23:26:07861 popup_menu_helper.ShowPopupMenu(translated_bounds,
862 params.item_height,
863 params.item_font_size,
864 params.selected_item,
865 params.popup_items,
866 params.right_aligned,
867 params.allow_multiple_selection);
868}
869#endif
870
871void BrowserPluginGuest::OnShowWidget(int route_id,
bokan107a47f2015-02-03 23:23:39872 const gfx::Rect& initial_rect) {
873 GetWebContents()->ShowCreatedWidget(route_id, initial_rect);
[email protected]a7fac9a2012-12-18 23:26:07874}
875
876void BrowserPluginGuest::OnTakeFocus(bool reverse) {
877 SendMessageToEmbedder(
[email protected]2101c4c2014-08-22 00:16:16878 new BrowserPluginMsg_AdvanceFocus(browser_plugin_instance_id(), reverse));
[email protected]a7fac9a2012-12-18 23:26:07879}
880
shuchen3517bb62014-10-15 03:55:57881void BrowserPluginGuest::OnTextInputTypeChanged(ui::TextInputType type,
882 ui::TextInputMode input_mode,
shuchen82ce8c52014-10-23 01:55:20883 bool can_compose_inline,
884 int flags) {
[email protected]63c33bd62014-02-08 04:45:40885 // Save the state of text input so we can restore it on focus.
shuchen3517bb62014-10-15 03:55:57886 last_text_input_type_ = type;
887 last_input_mode_ = input_mode;
shuchen82ce8c52014-10-23 01:55:20888 last_input_flags_ = flags;
shuchen3517bb62014-10-15 03:55:57889 last_can_compose_inline_ = can_compose_inline;
[email protected]63c33bd62014-02-08 04:45:40890
[email protected]cfd80b02014-05-01 17:46:48891 static_cast<RenderWidgetHostViewBase*>(
shuchen3517bb62014-10-15 03:55:57892 web_contents()->GetRenderWidgetHostView())->TextInputTypeChanged(
shuchen82ce8c52014-10-23 01:55:20893 type, input_mode, can_compose_inline, flags);
[email protected]d260f042013-12-14 01:31:36894}
895
896void BrowserPluginGuest::OnImeCancelComposition() {
[email protected]cfd80b02014-05-01 17:46:48897 static_cast<RenderWidgetHostViewBase*>(
[email protected]d260f042013-12-14 01:31:36898 web_contents()->GetRenderWidgetHostView())->ImeCancelComposition();
899}
900
[email protected]f9db7d2d2014-04-11 16:07:11901#if defined(OS_MACOSX) || defined(USE_AURA)
[email protected]d260f042013-12-14 01:31:36902void BrowserPluginGuest::OnImeCompositionRangeChanged(
903 const gfx::Range& range,
904 const std::vector<gfx::Rect>& character_bounds) {
[email protected]cfd80b02014-05-01 17:46:48905 static_cast<RenderWidgetHostViewBase*>(
[email protected]d260f042013-12-14 01:31:36906 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
907 range, character_bounds);
908}
909#endif
910
[email protected]7a846df2012-09-20 19:17:39911} // namespace content