[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | |
[email protected] | 95f861e | 2013-07-18 02:07:17 | [diff] [blame] | 9 | #include "base/message_loop/message_loop.h" |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 10 | #include "base/pickle.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
[email protected] | c88b2a56 | 2012-10-27 03:36:56 | [diff] [blame] | 12 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
[email protected] | f85f503 | 2013-04-03 09:01:54 | [diff] [blame] | 13 | #include "content/browser/browser_thread_impl.h" |
[email protected] | 4b49962 | 2013-08-22 02:25:59 | [diff] [blame] | 14 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | e5e438d6 | 2014-03-27 21:47:16 | [diff] [blame] | 15 | #include "content/browser/frame_host/render_frame_host_impl.h" |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 16 | #include "content/browser/frame_host/render_widget_host_view_guest.h" |
[email protected] | f85f503 | 2013-04-03 09:01:54 | [diff] [blame] | 17 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 18 | #include "content/browser/renderer_host/render_view_host_impl.h" |
| 19 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 20 | #include "content/browser/renderer_host/render_widget_host_view_base.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 21 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 22 | #include "content/browser/web_contents/web_contents_view_guest.h" |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 23 | #include "content/common/browser_plugin/browser_plugin_constants.h" |
[email protected] | 703dd66 | 2013-03-05 07:37:42 | [diff] [blame] | 24 | #include "content/common/browser_plugin/browser_plugin_messages.h" |
[email protected] | f8501b1 | 2012-12-07 04:55:43 | [diff] [blame] | 25 | #include "content/common/content_constants_internal.h" |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 26 | #include "content/common/drag_messages.h" |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 27 | #include "content/common/frame_messages.h" |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 28 | #include "content/common/host_shared_bitmap_manager.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 29 | #include "content/common/input_messages.h" |
[email protected] | c006fb5 | 2013-03-01 09:36:45 | [diff] [blame] | 30 | #include "content/common/view_messages.h" |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 31 | #include "content/public/browser/browser_context.h" |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 32 | #include "content/public/browser/browser_plugin_guest_manager.h" |
[email protected] | 44703cc7 | 2013-01-24 04:56:06 | [diff] [blame] | 33 | #include "content/public/browser/content_browser_client.h" |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 34 | #include "content/public/browser/guest_host.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 35 | #include "content/public/browser/render_widget_host_view.h" |
[email protected] | 2fae2c4 | 2012-10-03 21:20:04 | [diff] [blame] | 36 | #include "content/public/browser/user_metrics.h" |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 37 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 38 | #include "content/public/common/drop_data.h" |
fsamuel | 656670b | 2014-09-10 20:47:54 | [diff] [blame] | 39 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 40 | |
[email protected] | 4f89d9d | 2012-12-12 01:38:48 | [diff] [blame] | 41 | #if defined(OS_MACOSX) |
| 42 | #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| 43 | #endif |
| 44 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 45 | namespace content { |
| 46 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 47 | class BrowserPluginGuest::EmbedderVisibilityObserver |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 48 | : public WebContentsObserver { |
[email protected] | ce0e260 | 2013-03-15 20:53:27 | [diff] [blame] | 49 | public: |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 50 | explicit EmbedderVisibilityObserver(BrowserPluginGuest* guest) |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 51 | : WebContentsObserver(guest->embedder_web_contents()), |
[email protected] | ce0e260 | 2013-03-15 20:53:27 | [diff] [blame] | 52 | browser_plugin_guest_(guest) { |
| 53 | } |
| 54 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 55 | ~EmbedderVisibilityObserver() override {} |
[email protected] | ce0e260 | 2013-03-15 20:53:27 | [diff] [blame] | 56 | |
[email protected] | 70ab264 | 2014-05-30 08:06:58 | [diff] [blame] | 57 | // WebContentsObserver implementation. |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 58 | void WasShown() override { |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 59 | browser_plugin_guest_->EmbedderVisibilityChanged(true); |
| 60 | } |
| 61 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 62 | void WasHidden() override { |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 63 | browser_plugin_guest_->EmbedderVisibilityChanged(false); |
| 64 | } |
| 65 | |
[email protected] | ce0e260 | 2013-03-15 20:53:27 | [diff] [blame] | 66 | private: |
| 67 | BrowserPluginGuest* browser_plugin_guest_; |
| 68 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 69 | DISALLOW_COPY_AND_ASSIGN(EmbedderVisibilityObserver); |
[email protected] | ce0e260 | 2013-03-15 20:53:27 | [diff] [blame] | 70 | }; |
| 71 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 72 | BrowserPluginGuest::BrowserPluginGuest(bool has_render_view, |
| 73 | WebContentsImpl* web_contents, |
| 74 | BrowserPluginGuestDelegate* delegate) |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 75 | : WebContentsObserver(web_contents), |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 76 | owner_web_contents_(nullptr), |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 77 | attached_(false), |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 78 | browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 79 | focused_(false), |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 80 | mouse_locked_(false), |
[email protected] | a25acea7 | 2013-03-10 23:41:28 | [diff] [blame] | 81 | pending_lock_request_(false), |
[email protected] | 2ef8ba5 | 2014-05-13 22:39:48 | [diff] [blame] | 82 | guest_visible_(false), |
[email protected] | 93564f7 | 2013-02-15 13:26:19 | [diff] [blame] | 83 | embedder_visible_(true), |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 84 | is_full_page_plugin_(false), |
[email protected] | 6344972 | 2013-08-13 02:31:32 | [diff] [blame] | 85 | has_render_view_(has_render_view), |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 86 | is_in_destruction_(false), |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 87 | initialized_(false), |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 88 | last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 89 | last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 90 | last_input_flags_(0), |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 91 | last_can_compose_inline_(true), |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 92 | guest_proxy_routing_id_(MSG_ROUTING_NONE), |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 93 | last_drag_status_(blink::WebDragStatusUnknown), |
| 94 | seen_embedder_system_drag_ended_(false), |
| 95 | seen_embedder_drag_source_ended_at_(false), |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 96 | delegate_(delegate), |
[email protected] | f21d36e | 2014-01-16 19:24:04 | [diff] [blame] | 97 | weak_ptr_factory_(this) { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 98 | DCHECK(web_contents); |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 99 | DCHECK(delegate); |
| 100 | RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
| 101 | web_contents->SetBrowserPluginGuest(this); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 102 | delegate->SetGuestHost(this); |
| 103 | } |
| 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(); |
paulmeyer | 0968abad | 2015-01-10 00:02:45 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { |
| 133 | GetWebContents()->GetView()->SizeContents(new_size); |
[email protected] | eb72af63 | 2013-04-30 01:05:21 | [diff] [blame] | 134 | } |
| 135 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 136 | void BrowserPluginGuest::WillDestroy() { |
| 137 | is_in_destruction_ = true; |
| 138 | owner_web_contents_ = nullptr; |
| 139 | attached_ = false; |
| 140 | } |
| 141 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 142 | void 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()); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 155 | owner_web_contents->CreateBrowserPluginEmbedderIfNecessary(); |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 156 | InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents); |
| 157 | } |
| 158 | |
[email protected] | 8fb60c3 | 2014-02-02 17:46:40 | [diff] [blame] | 159 | base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
| 160 | return weak_ptr_factory_.GetWeakPtr(); |
| 161 | } |
| 162 | |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 163 | void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, |
| 164 | bool focused, |
| 165 | blink::WebFocusType focus_type) { |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 166 | focused_ = focused; |
fsamuel | 66602da3 | 2014-09-12 22:02:43 | [diff] [blame] | 167 | if (!rwh) |
| 168 | return; |
| 169 | |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 170 | if ((focus_type == blink::WebFocusTypeForward) || |
| 171 | (focus_type == blink::WebFocusTypeBackward)) { |
| 172 | static_cast<RenderViewHostImpl*>(RenderViewHost::From(rwh))-> |
| 173 | SetInitialFocus(focus_type == blink::WebFocusTypeBackward); |
| 174 | } |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 175 | 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*>( |
fsamuel | 66602da3 | 2014-09-12 22:02:43 | [diff] [blame] | 181 | rwh->GetView()); |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 182 | if (rwhv) { |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 183 | rwhv->TextInputTypeChanged(last_text_input_type_, last_input_mode_, |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 184 | last_can_compose_inline_, last_input_flags_); |
fsamuel | 9e3d9ad | 2014-09-11 00:59:30 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
paulmeyer | 66bf6fb | 2014-10-09 04:42:40 | [diff] [blame] | 188 | void BrowserPluginGuest::SetTooltipText(const base::string16& tooltip_text) { |
paulmeyer | e80cfc9 | 2014-10-10 03:37:43 | [diff] [blame] | 189 | if (tooltip_text == current_tooltip_text_) |
| 190 | return; |
| 191 | current_tooltip_text_ = tooltip_text; |
| 192 | |
paulmeyer | 66bf6fb | 2014-10-09 04:42:40 | [diff] [blame] | 193 | SendMessageToEmbedder(new BrowserPluginMsg_SetTooltipText( |
| 194 | browser_plugin_instance_id_, tooltip_text)); |
| 195 | } |
| 196 | |
[email protected] | 660f18e | 2014-05-15 20:53:05 | [diff] [blame] | 197 | bool 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] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 204 | WebContentsImpl* 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] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 212 | bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 213 | const IPC::Message& message) { |
fsamuel | 90e100b | 2014-09-10 14:25:44 | [diff] [blame] | 214 | 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] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 224 | bool handled = true; |
| 225 | IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 226 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, |
| 227 | OnCompositorFrameSwappedACK) |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 228 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 229 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 230 | OnDragStatusUpdate) |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 231 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, |
| 232 | OnExecuteEditCommand) |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 233 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, |
| 234 | OnExtendSelectionAndDelete) |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 235 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, |
| 236 | OnImeConfirmComposition) |
| 237 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, |
| 238 | OnImeSetComposition) |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 239 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 240 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, |
| 241 | OnReclaimCompositorResources) |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 242 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, |
| 243 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 244 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) |
| 245 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 246 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 247 | IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 248 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 249 | IPC_END_MESSAGE_MAP() |
| 250 | return handled; |
| 251 | } |
| 252 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 253 | void BrowserPluginGuest::InitInternal( |
[email protected] | c61b317c7 | 2013-11-14 06:40:46 | [diff] [blame] | 254 | const BrowserPluginHostMsg_Attach_Params& params, |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 255 | WebContentsImpl* owner_web_contents) { |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 256 | focused_ = params.focused; |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 257 | OnSetFocus(browser_plugin::kInstanceIDNone, |
| 258 | focused_, |
| 259 | blink::WebFocusTypeNone); |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 260 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 261 | guest_visible_ = params.visible; |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 262 | UpdateVisibility(); |
| 263 | |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 264 | is_full_page_plugin_ = params.is_full_page_plugin; |
fsamuel | 49745bbf | 2015-02-25 20:07:03 | [diff] [blame] | 265 | guest_window_rect_ = params.view_rect; |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 266 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 267 | 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()); |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 272 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 273 | // 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] | 2b3c7b3 | 2013-07-24 23:47:42 | [diff] [blame] | 278 | |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 279 | RendererPreferences* renderer_prefs = |
| 280 | GetWebContents()->GetMutableRendererPrefs(); |
[email protected] | 0d2f55e9 | 2013-09-26 03:13:17 | [diff] [blame] | 281 | std::string guest_user_agent_override = renderer_prefs->user_agent_override; |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 282 | // 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. |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 288 | *renderer_prefs = *owner_web_contents_->GetMutableRendererPrefs(); |
[email protected] | 0d2f55e9 | 2013-09-26 03:13:17 | [diff] [blame] | 289 | renderer_prefs->user_agent_override = guest_user_agent_override; |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 290 | |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 291 | // 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] | 7fdb6ac | 2014-02-07 18:33:32 | [diff] [blame] | 295 | // 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] | f677288e | 2013-09-18 02:11:00 | [diff] [blame] | 298 | // Disable "client blocked" error page for browser plugin. |
| 299 | renderer_prefs->disable_client_blocked_error_page = true; |
[email protected] | 31942c8 | 2012-10-05 17:01:54 | [diff] [blame] | 300 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 301 | embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this)); |
[email protected] | 93564f7 | 2013-02-15 13:26:19 | [diff] [blame] | 302 | |
paulmeyer | 9ef6e446 | 2015-02-24 19:15:10 | [diff] [blame] | 303 | 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] | 44703cc7 | 2013-01-24 04:56:06 | [diff] [blame] | 309 | |
[email protected] | 9e797d2 | 2014-08-08 21:31:30 | [diff] [blame] | 310 | // 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] | f1b6aa7c | 2014-02-20 22:10:26 | [diff] [blame] | 314 | prefs.navigate_on_drag_drop = false; |
[email protected] | f1b6aa7c | 2014-02-20 22:10:26 | [diff] [blame] | 315 | GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | BrowserPluginGuest::~BrowserPluginGuest() { |
| 319 | } |
| 320 | |
| 321 | // static |
| 322 | BrowserPluginGuest* BrowserPluginGuest::Create( |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 323 | WebContentsImpl* web_contents, |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 324 | BrowserPluginGuestDelegate* delegate) { |
| 325 | return new BrowserPluginGuest( |
fsamuel | 7df36b2 | 2015-01-21 20:13:07 | [diff] [blame] | 326 | web_contents->opener() != nullptr, web_contents, delegate); |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 329 | // static |
| 330 | bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { |
| 331 | return web_contents && web_contents->GetBrowserPluginGuest(); |
| 332 | } |
| 333 | |
| 334 | // static |
| 335 | bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { |
| 336 | return render_view_host && IsGuest( |
| 337 | static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( |
| 338 | render_view_host))); |
| 339 | } |
| 340 | |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 341 | RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { |
| 342 | if (!owner_web_contents_) |
fsamuel | 7df36b2 | 2015-01-21 20:13:07 | [diff] [blame] | 343 | return nullptr; |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 344 | return owner_web_contents_->GetRenderWidgetHostView(); |
[email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 345 | } |
| 346 | |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 347 | void BrowserPluginGuest::UpdateVisibility() { |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 348 | OnSetVisibility(browser_plugin_instance_id(), visible()); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 349 | } |
| 350 | |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 351 | BrowserPluginGuestManager* |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 352 | BrowserPluginGuest::GetBrowserPluginGuestManager() const { |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 353 | return GetWebContents()->GetBrowserContext()->GetGuestManager(); |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | e0c6dc9 | 2013-10-10 21:17:51 | [diff] [blame] | 356 | void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
| 357 | embedder_visible_ = visible; |
| 358 | UpdateVisibility(); |
[email protected] | 31942c8 | 2012-10-05 17:01:54 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 7a128089 | 2014-04-16 17:18:25 | [diff] [blame] | 361 | void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { |
| 362 | SendMessageToEmbedder( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 363 | new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow)); |
[email protected] | 7a128089 | 2014-04-16 17:18:25 | [diff] [blame] | 364 | } |
| 365 | |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 366 | void BrowserPluginGuest::SwapCompositorFrame( |
| 367 | uint32 output_surface_id, |
| 368 | int host_process_id, |
| 369 | int host_routing_id, |
| 370 | scoped_ptr<cc::CompositorFrame> frame) { |
fsamuel | 478927e | 2014-09-06 13:16:17 | [diff] [blame] | 371 | cc::RenderPass* root_pass = |
| 372 | frame->delegated_frame_data->render_pass_list.back(); |
fsamuel | 656670b | 2014-09-10 20:47:54 | [diff] [blame] | 373 | gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize( |
| 374 | root_pass->output_rect.size(), |
| 375 | 1.0f / frame->metadata.device_scale_factor))); |
| 376 | |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 377 | if (last_seen_view_size_ != view_size) { |
paulmeyer | 647b4f1 | 2015-01-26 21:40:08 | [diff] [blame] | 378 | delegate_->GuestSizeChanged(view_size); |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 379 | last_seen_view_size_ = view_size; |
| 380 | } |
| 381 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 382 | 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 | |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 388 | SendMessageToEmbedder( |
| 389 | new BrowserPluginMsg_CompositorFrameSwapped( |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 390 | browser_plugin_instance_id(), *last_pending_frame_)); |
fsamuel | 04a6f5f | 2014-09-04 22:42:14 | [diff] [blame] | 391 | } |
| 392 | |
fsamuel | 516005f | 2014-09-20 16:57:58 | [diff] [blame] | 393 | void BrowserPluginGuest::SetContentsOpaque(bool opaque) { |
| 394 | SendMessageToEmbedder( |
| 395 | new BrowserPluginMsg_SetContentsOpaque( |
| 396 | browser_plugin_instance_id(), opaque)); |
| 397 | } |
| 398 | |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 399 | bool BrowserPluginGuest::Find(int request_id, |
| 400 | const base::string16& search_text, |
| 401 | const blink::WebFindOptions& options) { |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 402 | return delegate_->Find(request_id, search_text, options); |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 403 | } |
| 404 | |
raymes | 2bc6418 | 2015-02-06 01:23:01 | [diff] [blame] | 405 | bool BrowserPluginGuest::StopFinding(StopFindAction action) { |
| 406 | return delegate_->StopFinding(action); |
| 407 | } |
| 408 | |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 409 | WebContentsImpl* BrowserPluginGuest::GetWebContents() const { |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 410 | return static_cast<WebContentsImpl*>(web_contents()); |
[email protected] | e17b7c6 | 2012-09-21 21:05:46 | [diff] [blame] | 411 | } |
| 412 | |
[email protected] | ca61ce14 | 2012-11-27 21:32:57 | [diff] [blame] | 413 | gfx::Point BrowserPluginGuest::GetScreenCoordinates( |
| 414 | const gfx::Point& relative_position) const { |
[email protected] | 3d888fa | 2014-07-11 19:27:16 | [diff] [blame] | 415 | if (!attached()) |
| 416 | return relative_position; |
| 417 | |
[email protected] | ca61ce14 | 2012-11-27 21:32:57 | [diff] [blame] | 418 | gfx::Point screen_pos(relative_position); |
| 419 | screen_pos += guest_window_rect_.OffsetFromOrigin(); |
[email protected] | 3d888fa | 2014-07-11 19:27:16 | [diff] [blame] | 420 | 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] | ca61ce14 | 2012-11-27 21:32:57 | [diff] [blame] | 425 | return screen_pos; |
| 426 | } |
| 427 | |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 428 | void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 429 | if (!attached()) { |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 430 | // 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] | 10b21b3 | 2014-06-07 09:54:33 | [diff] [blame] | 435 | pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 436 | return; |
| 437 | } |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 438 | owner_web_contents_->Send(msg); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 439 | } |
| 440 | |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 441 | void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 442 | int screen_x, int screen_y, blink::WebDragOperation operation) { |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 443 | web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
| 444 | screen_x, screen_y, operation); |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 445 | seen_embedder_drag_source_ended_at_ = true; |
| 446 | EndSystemDragIfApplicable(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 447 | } |
| 448 | |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 449 | void 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(); |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 474 | last_drag_status_ = blink::WebDragStatusUnknown; |
| 475 | seen_embedder_system_drag_ended_ = false; |
| 476 | seen_embedder_drag_source_ended_at_ = false; |
fsamuel | bdfc1ad | 2015-02-24 02:10:02 | [diff] [blame] | 477 | dragged_url_ = GURL(); |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
| 481 | void BrowserPluginGuest::EmbedderSystemDragEnded() { |
| 482 | seen_embedder_system_drag_ended_ = true; |
| 483 | EndSystemDragIfApplicable(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 484 | } |
| 485 | |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 486 | void BrowserPluginGuest::SendQueuedMessages() { |
| 487 | if (!attached()) |
| 488 | return; |
| 489 | |
| 490 | while (!pending_messages_.empty()) { |
[email protected] | 10b21b3 | 2014-06-07 09:54:33 | [diff] [blame] | 491 | linked_ptr<IPC::Message> message_ptr = pending_messages_.front(); |
| 492 | pending_messages_.pop_front(); |
| 493 | SendMessageToEmbedder(message_ptr.release()); |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 497 | void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( |
[email protected] | 860234a | 2014-07-01 00:35:31 | [diff] [blame] | 498 | RenderFrameHost* render_frame_host, |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 499 | const GURL& url, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 500 | ui::PageTransition transition_type) { |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 501 | RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 502 | } |
| 503 | |
[email protected] | c88b2a56 | 2012-10-27 03:36:56 | [diff] [blame] | 504 | void BrowserPluginGuest::RenderViewReady() { |
[email protected] | 543afaf | 2013-12-13 14:03:22 | [diff] [blame] | 505 | RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
[email protected] | c88b2a56 | 2012-10-27 03:36:56 | [diff] [blame] | 506 | // TODO(fsamuel): Investigate whether it's possible to update state earlier |
[email protected] | dba9bd2 | 2012-12-06 23:04:03 | [diff] [blame] | 507 | // here (see http://crbug.com/158151). |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 508 | Send(new InputMsg_SetFocus(routing_id(), focused_)); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 509 | UpdateVisibility(); |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 510 | |
jdduke | d20d7b3 | 2015-03-09 23:55:13 | [diff] [blame] | 511 | RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay( |
[email protected] | 2ef8ba5 | 2014-05-13 22:39:48 | [diff] [blame] | 512 | base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); |
[email protected] | c88b2a56 | 2012-10-27 03:36:56 | [diff] [blame] | 513 | } |
| 514 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 515 | void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 516 | SendMessageToEmbedder( |
| 517 | new BrowserPluginMsg_GuestGone(browser_plugin_instance_id())); |
[email protected] | 2fae2c4 | 2012-10-03 21:20:04 | [diff] [blame] | 518 | switch (status) { |
| 519 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 520 | RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); |
[email protected] | 2fae2c4 | 2012-10-03 21:20:04 | [diff] [blame] | 521 | break; |
| 522 | case base::TERMINATION_STATUS_PROCESS_CRASHED: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 523 | RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Crashed")); |
[email protected] | 2fae2c4 | 2012-10-03 21:20:04 | [diff] [blame] | 524 | break; |
| 525 | case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 526 | RecordAction( |
| 527 | base::UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath")); |
[email protected] | 2fae2c4 | 2012-10-03 21:20:04 | [diff] [blame] | 528 | break; |
| 529 | default: |
| 530 | break; |
| 531 | } |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 532 | } |
| 533 | |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 534 | // static |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 535 | bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( |
| 536 | const IPC::Message& message) { |
| 537 | switch (message.type()) { |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 538 | case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 539 | case BrowserPluginHostMsg_Detach::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 540 | case BrowserPluginHostMsg_DragStatusUpdate::ID: |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 541 | case BrowserPluginHostMsg_ExecuteEditCommand::ID: |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 542 | case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 543 | case BrowserPluginHostMsg_HandleInputEvent::ID: |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 544 | case BrowserPluginHostMsg_ImeConfirmComposition::ID: |
| 545 | case BrowserPluginHostMsg_ImeSetComposition::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 546 | case BrowserPluginHostMsg_LockMouse_ACK::ID: |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 547 | case BrowserPluginHostMsg_ReclaimCompositorResources::ID: |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 548 | case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 549 | case BrowserPluginHostMsg_SetFocus::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 550 | case BrowserPluginHostMsg_SetVisibility::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 551 | case BrowserPluginHostMsg_UnlockMouse_ACK::ID: |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 552 | case BrowserPluginHostMsg_UpdateGeometry::ID: |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 553 | return true; |
| 554 | default: |
[email protected] | c61b317c7 | 2013-11-14 06:40:46 | [diff] [blame] | 555 | return false; |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 556 | } |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 559 | bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
| 560 | bool handled = true; |
| 561 | IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 562 | 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] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 568 | IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
| 569 | OnHasTouchEventHandlers) |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 570 | IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 571 | IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 572 | IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 573 | IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputTypeChanged, |
| 574 | OnTextInputTypeChanged) |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 575 | IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 576 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 577 | IPC_END_MESSAGE_MAP() |
| 578 | return handled; |
| 579 | } |
| 580 | |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 581 | bool 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] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 607 | void BrowserPluginGuest::Attach( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 608 | int browser_plugin_instance_id, |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 609 | WebContentsImpl* embedder_web_contents, |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 610 | const BrowserPluginHostMsg_Attach_Params& params) { |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 611 | 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 | } |
sammc | e209251 | 2014-11-24 22:18:24 | [diff] [blame] | 626 | delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, |
| 627 | params.is_full_page_plugin); |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 628 | |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 629 | // If a RenderView has already been created for this new window, then we need |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 630 | // to initialize the browser-side state now so that the RenderFrameHostManager |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 631 | // does not create a new RenderView on navigation. |
| 632 | if (has_render_view_) { |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 633 | // This will trigger a callback to RenderViewReady after a round-trip IPC. |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 634 | static_cast<RenderViewHostImpl*>( |
| 635 | GetWebContents()->GetRenderViewHost())->Init(); |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 636 | WebContentsViewGuest* web_contents_view = |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 637 | static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 638 | if (!web_contents()->GetRenderViewHost()->GetView()) { |
| 639 | web_contents_view->CreateViewForWidget( |
lazyboy | 549b3b4 | 2014-10-20 17:16:04 | [diff] [blame] | 640 | web_contents()->GetRenderViewHost(), true); |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 641 | } |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 642 | } |
[email protected] | 0c6d4175 | 2013-05-01 15:49:09 | [diff] [blame] | 643 | |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 644 | InitInternal(params, embedder_web_contents); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 645 | |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 646 | attached_ = true; |
[email protected] | 697f16b5 | 2013-05-10 06:01:18 | [diff] [blame] | 647 | SendQueuedMessages(); |
[email protected] | abc7d5c | 2013-05-15 09:19:25 | [diff] [blame] | 648 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 649 | delegate_->DidAttach(GetGuestProxyRoutingID()); |
fsamuel | a8484dd | 2014-10-02 00:51:33 | [diff] [blame] | 650 | |
| 651 | has_render_view_ = true; |
[email protected] | d84d57b | 2014-06-20 22:42:39 | [diff] [blame] | 652 | |
lazyboy | 8b0b5d0 | 2015-02-07 00:02:12 | [diff] [blame] | 653 | // 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] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 661 | RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 662 | } |
| 663 | |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 664 | void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 665 | int browser_plugin_instance_id, |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 666 | 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); |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 671 | last_pending_frame_.reset(); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 672 | } |
| 673 | |
fsamuel | a95fef4 | 2014-12-03 20:16:52 | [diff] [blame] | 674 | void 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] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 685 | void BrowserPluginGuest::OnDragStatusUpdate(int browser_plugin_instance_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 686 | blink::WebDragStatus drag_status, |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 687 | const DropData& drop_data, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 688 | blink::WebDragOperationsMask mask, |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 689 | const gfx::Point& location) { |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 690 | RenderViewHost* host = GetWebContents()->GetRenderViewHost(); |
fsamuel | bdfc1ad | 2015-02-24 02:10:02 | [diff] [blame] | 691 | auto embedder = owner_web_contents_->GetBrowserPluginEmbedder(); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 692 | switch (drag_status) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 693 | case blink::WebDragStatusEnter: |
fsamuel | bdfc1ad | 2015-02-24 02:10:02 | [diff] [blame] | 694 | // 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] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 698 | host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
| 699 | break; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 700 | case blink::WebDragStatusOver: |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 701 | host->DragTargetDragOver(location, location, mask, 0); |
| 702 | break; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 703 | case blink::WebDragStatusLeave: |
fsamuel | bdfc1ad | 2015-02-24 02:10:02 | [diff] [blame] | 704 | embedder->DragLeftGuest(this); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 705 | host->DragTargetDragLeave(); |
| 706 | break; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 707 | case blink::WebDragStatusDrop: |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 708 | host->DragTargetDrop(location, location, 0); |
fsamuel | bdfc1ad | 2015-02-24 02:10:02 | [diff] [blame] | 709 | if (dragged_url_.is_valid()) { |
| 710 | delegate_->DidDropLink(dragged_url_); |
| 711 | dragged_url_ = GURL(); |
| 712 | } |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 713 | break; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 714 | case blink::WebDragStatusUnknown: |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 715 | NOTREACHED(); |
| 716 | } |
lazyboy | f569b4f6 | 2015-02-03 17:22:54 | [diff] [blame] | 717 | last_drag_status_ = drag_status; |
| 718 | EndSystemDragIfApplicable(); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 719 | } |
| 720 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 721 | void BrowserPluginGuest::OnExecuteEditCommand(int browser_plugin_instance_id, |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 722 | const std::string& name) { |
sammc | bc9e9933 | 2014-12-18 00:55:24 | [diff] [blame] | 723 | 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] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 729 | } |
| 730 | |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 731 | void BrowserPluginGuest::OnImeSetComposition( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 732 | int browser_plugin_instance_id, |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 733 | const std::string& text, |
| 734 | const std::vector<blink::WebCompositionUnderline>& underlines, |
| 735 | int selection_start, |
| 736 | int selection_end) { |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 737 | Send(new InputMsg_ImeSetComposition(routing_id(), |
| 738 | base::UTF8ToUTF16(text), underlines, |
| 739 | selection_start, selection_end)); |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void BrowserPluginGuest::OnImeConfirmComposition( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 743 | int browser_plugin_instance_id, |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 744 | const std::string& text, |
| 745 | bool keep_selection) { |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 746 | Send(new InputMsg_ImeConfirmComposition(routing_id(), |
| 747 | base::UTF8ToUTF16(text), |
| 748 | gfx::Range::InvalidRange(), |
| 749 | keep_selection)); |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | void BrowserPluginGuest::OnExtendSelectionAndDelete( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 753 | int browser_plugin_instance_id, |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 754 | int before, |
| 755 | int after) { |
[email protected] | e5e438d6 | 2014-03-27 21:47:16 | [diff] [blame] | 756 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( |
| 757 | web_contents()->GetFocusedFrame()); |
| 758 | if (rfh) |
| 759 | rfh->ExtendSelectionAndDelete(before, after); |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 762 | void BrowserPluginGuest::OnReclaimCompositorResources( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 763 | int browser_plugin_instance_id, |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 764 | 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] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 769 | } |
| 770 | |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 771 | void BrowserPluginGuest::OnLockMouse(bool user_gesture, |
| 772 | bool last_unlocked_by_target, |
| 773 | bool privileged) { |
[email protected] | 02768b76 | 2013-10-02 20:39:34 | [diff] [blame] | 774 | if (pending_lock_request_) { |
[email protected] | a25acea7 | 2013-03-10 23:41:28 | [diff] [blame] | 775 | // 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] | a25acea7 | 2013-03-10 23:41:28 | [diff] [blame] | 780 | |
[email protected] | 7a128089 | 2014-04-16 17:18:25 | [diff] [blame] | 781 | 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] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 788 | } |
| 789 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 790 | void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id, |
| 791 | bool succeeded) { |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 792 | Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); |
[email protected] | a25acea7 | 2013-03-10 23:41:28 | [diff] [blame] | 793 | pending_lock_request_ = false; |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 794 | if (succeeded) |
| 795 | mouse_locked_ = true; |
| 796 | } |
| 797 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 798 | void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id, |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 799 | bool focused, |
| 800 | blink::WebFocusType focus_type) { |
fsamuel | 66602da3 | 2014-09-12 22:02:43 | [diff] [blame] | 801 | RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView(); |
fsamuel | 7df36b2 | 2015-01-21 20:13:07 | [diff] [blame] | 802 | RenderWidgetHost* rwh = rwhv ? rwhv->GetRenderWidgetHost() : nullptr; |
fsamuel | 5ec049d | 2015-01-19 16:57:41 | [diff] [blame] | 803 | SetFocus(rwh, focused, focus_type); |
[email protected] | 42383847 | 2013-01-09 00:16:46 | [diff] [blame] | 804 | } |
| 805 | |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 806 | void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 807 | int browser_plugin_instance_id, |
[email protected] | b77fac5 | 2013-06-01 01:03:46 | [diff] [blame] | 808 | const std::vector<EditCommand>& edit_commands) { |
| 809 | Send(new InputMsg_SetEditCommandsForNextKeyEvent(routing_id(), |
| 810 | edit_commands)); |
| 811 | } |
| 812 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 813 | void BrowserPluginGuest::OnSetVisibility(int browser_plugin_instance_id, |
| 814 | bool visible) { |
[email protected] | 93564f7 | 2013-02-15 13:26:19 | [diff] [blame] | 815 | guest_visible_ = visible; |
| 816 | if (embedder_visible_ && guest_visible_) |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 817 | GetWebContents()->WasShown(); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 818 | else |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 819 | GetWebContents()->WasHidden(); |
[email protected] | 3997b1b2 | 2012-12-20 01:02:54 | [diff] [blame] | 820 | } |
| 821 | |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 822 | void BrowserPluginGuest::OnUnlockMouse() { |
[email protected] | b60b8894 | 2013-07-20 05:58:42 | [diff] [blame] | 823 | SendMessageToEmbedder( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 824 | new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), false)); |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 825 | } |
| 826 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 827 | void BrowserPluginGuest::OnUnlockMouseAck(int browser_plugin_instance_id) { |
[email protected] | 861f978 | 2013-03-05 03:29:54 | [diff] [blame] | 828 | // 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] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 836 | void BrowserPluginGuest::OnUpdateGeometry(int browser_plugin_instance_id, |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 837 | 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] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 847 | void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { |
| 848 | SendMessageToEmbedder( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 849 | new BrowserPluginMsg_ShouldAcceptTouchEvents( |
| 850 | browser_plugin_instance_id(), accept)); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 851 | } |
| 852 | |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 853 | #if defined(OS_MACOSX) |
| 854 | void BrowserPluginGuest::OnShowPopup( |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 855 | RenderFrameHost* render_frame_host, |
| 856 | const FrameHostMsg_ShowPopup_Params& params) { |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 857 | gfx::Rect translated_bounds(params.bounds); |
| 858 | translated_bounds.Offset(guest_window_rect_.OffsetFromOrigin()); |
| 859 | BrowserPluginPopupMenuHelper popup_menu_helper( |
fsamuel | ad4f33f | 2014-11-28 19:32:21 | [diff] [blame] | 860 | owner_web_contents_->GetRenderViewHost(), render_frame_host); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 861 | 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 | |
| 871 | void BrowserPluginGuest::OnShowWidget(int route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 872 | const gfx::Rect& initial_rect) { |
| 873 | GetWebContents()->ShowCreatedWidget(route_id, initial_rect); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
| 877 | SendMessageToEmbedder( |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 878 | new BrowserPluginMsg_AdvanceFocus(browser_plugin_instance_id(), reverse)); |
[email protected] | a7fac9a | 2012-12-18 23:26:07 | [diff] [blame] | 879 | } |
| 880 | |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 881 | void BrowserPluginGuest::OnTextInputTypeChanged(ui::TextInputType type, |
| 882 | ui::TextInputMode input_mode, |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 883 | bool can_compose_inline, |
| 884 | int flags) { |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 885 | // Save the state of text input so we can restore it on focus. |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 886 | last_text_input_type_ = type; |
| 887 | last_input_mode_ = input_mode; |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 888 | last_input_flags_ = flags; |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 889 | last_can_compose_inline_ = can_compose_inline; |
[email protected] | 63c33bd6 | 2014-02-08 04:45:40 | [diff] [blame] | 890 | |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 891 | static_cast<RenderWidgetHostViewBase*>( |
shuchen | 3517bb6 | 2014-10-15 03:55:57 | [diff] [blame] | 892 | web_contents()->GetRenderWidgetHostView())->TextInputTypeChanged( |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 893 | type, input_mode, can_compose_inline, flags); |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | void BrowserPluginGuest::OnImeCancelComposition() { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 897 | static_cast<RenderWidgetHostViewBase*>( |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 898 | web_contents()->GetRenderWidgetHostView())->ImeCancelComposition(); |
| 899 | } |
| 900 | |
[email protected] | f9db7d2d | 2014-04-11 16:07:11 | [diff] [blame] | 901 | #if defined(OS_MACOSX) || defined(USE_AURA) |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 902 | void BrowserPluginGuest::OnImeCompositionRangeChanged( |
| 903 | const gfx::Range& range, |
| 904 | const std::vector<gfx::Rect>& character_bounds) { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 905 | static_cast<RenderWidgetHostViewBase*>( |
[email protected] | d260f04 | 2013-12-14 01:31:36 | [diff] [blame] | 906 | web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
| 907 | range, character_bounds); |
| 908 | } |
| 909 | #endif |
| 910 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 911 | } // namespace content |