OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 virtual void WasHidden() OVERRIDE { | 58 virtual void WasHidden() OVERRIDE { |
59 browser_plugin_guest_->EmbedderVisibilityChanged(false); | 59 browser_plugin_guest_->EmbedderVisibilityChanged(false); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 BrowserPluginGuest* browser_plugin_guest_; | 63 BrowserPluginGuest* browser_plugin_guest_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); | 65 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); |
66 }; | 66 }; |
67 | 67 |
68 BrowserPluginGuest::BrowserPluginGuest( | 68 BrowserPluginGuest::BrowserPluginGuest(int guest_instance_id, |
69 int instance_id, | 69 bool has_render_view, |
70 bool has_render_view, | 70 WebContentsImpl* web_contents, |
71 WebContentsImpl* web_contents, | 71 BrowserPluginGuestDelegate* delegate) |
72 BrowserPluginGuestDelegate* delegate) | |
73 : WebContentsObserver(web_contents), | 72 : WebContentsObserver(web_contents), |
74 embedder_web_contents_(NULL), | 73 embedder_web_contents_(NULL), |
75 instance_id_(instance_id), | 74 guest_instance_id_(guest_instance_id), |
76 guest_device_scale_factor_(1.0f), | 75 guest_device_scale_factor_(1.0f), |
77 focused_(false), | 76 focused_(false), |
78 mouse_locked_(false), | 77 mouse_locked_(false), |
79 pending_lock_request_(false), | 78 pending_lock_request_(false), |
80 guest_visible_(false), | 79 guest_visible_(false), |
81 guest_opaque_(true), | 80 guest_opaque_(true), |
82 embedder_visible_(true), | 81 embedder_visible_(true), |
83 auto_size_enabled_(false), | 82 auto_size_enabled_(false), |
84 copy_request_id_(0), | 83 copy_request_id_(0), |
85 has_render_view_(has_render_view), | 84 has_render_view_(has_render_view), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 OnSetContentsOpaque) | 158 OnSetContentsOpaque) |
160 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 159 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
161 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) | 160 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
162 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) | 161 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
163 IPC_MESSAGE_UNHANDLED(handled = false) | 162 IPC_MESSAGE_UNHANDLED(handled = false) |
164 IPC_END_MESSAGE_MAP() | 163 IPC_END_MESSAGE_MAP() |
165 return handled; | 164 return handled; |
166 } | 165 } |
167 | 166 |
168 void BrowserPluginGuest::Initialize( | 167 void BrowserPluginGuest::Initialize( |
| 168 int browser_plugin_instance_id, |
169 const BrowserPluginHostMsg_Attach_Params& params, | 169 const BrowserPluginHostMsg_Attach_Params& params, |
170 WebContentsImpl* embedder_web_contents, | 170 WebContentsImpl* embedder_web_contents) { |
171 const base::DictionaryValue& extra_params) { | |
172 focused_ = params.focused; | 171 focused_ = params.focused; |
173 guest_visible_ = params.visible; | 172 guest_visible_ = params.visible; |
174 guest_opaque_ = params.opaque; | 173 guest_opaque_ = params.opaque; |
175 guest_window_rect_ = gfx::Rect(params.origin, | 174 guest_window_rect_ = gfx::Rect(params.origin, |
176 params.resize_guest_params.view_size); | 175 params.resize_guest_params.view_size); |
177 | 176 |
178 auto_size_enabled_ = params.auto_size_params.enable; | 177 auto_size_enabled_ = params.auto_size_params.enable; |
179 max_auto_size_ = params.auto_size_params.max_size; | 178 max_auto_size_ = params.auto_size_params.max_size; |
180 min_auto_size_ = params.auto_size_params.min_size; | 179 min_auto_size_ = params.auto_size_params.min_size; |
181 | 180 |
(...skipping 23 matching lines...) Expand all Loading... |
205 renderer_prefs->report_frame_name_changes = true; | 204 renderer_prefs->report_frame_name_changes = true; |
206 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 205 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
207 // navigations still continue to function inside the app. | 206 // navigations still continue to function inside the app. |
208 renderer_prefs->browser_handles_all_top_level_requests = false; | 207 renderer_prefs->browser_handles_all_top_level_requests = false; |
209 // Disable "client blocked" error page for browser plugin. | 208 // Disable "client blocked" error page for browser plugin. |
210 renderer_prefs->disable_client_blocked_error_page = true; | 209 renderer_prefs->disable_client_blocked_error_page = true; |
211 | 210 |
212 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); | 211 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); |
213 | 212 |
214 OnSetAutoSize( | 213 OnSetAutoSize( |
215 instance_id_, params.auto_size_params, params.resize_guest_params); | 214 guest_instance_id_, params.auto_size_params, params.resize_guest_params); |
216 | 215 |
217 // Create a swapped out RenderView for the guest in the embedder render | 216 // Create a swapped out RenderView for the guest in the embedder render |
218 // process, so that the embedder can access the guest's window object. | 217 // process, so that the embedder can access the guest's window object. |
219 int guest_routing_id = | 218 int guest_routing_id = |
220 GetWebContents()->CreateSwappedOutRenderView( | 219 GetWebContents()->CreateSwappedOutRenderView( |
221 embedder_web_contents_->GetSiteInstance()); | 220 embedder_web_contents_->GetSiteInstance()); |
222 SendMessageToEmbedder( | |
223 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, | |
224 guest_routing_id)); | |
225 | 221 |
226 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); | 222 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); |
227 prefs.navigate_on_drag_drop = false; | 223 prefs.navigate_on_drag_drop = false; |
228 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); | 224 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); |
229 | 225 |
230 // Enable input method for guest if it's enabled for the embedder. | 226 // Enable input method for guest if it's enabled for the embedder. |
231 if (static_cast<RenderViewHostImpl*>( | 227 if (static_cast<RenderViewHostImpl*>( |
232 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { | 228 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { |
233 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 229 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
234 GetWebContents()->GetRenderViewHost()); | 230 GetWebContents()->GetRenderViewHost()); |
235 guest_rvh->SetInputMethodActive(true); | 231 guest_rvh->SetInputMethodActive(true); |
236 } | 232 } |
237 | 233 |
238 // Inform the embedder of the guest's attachment. | 234 // Inform the embedder of the guest's attachment. |
239 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_)); | 235 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK( |
| 236 browser_plugin_instance_id, guest_instance_id_)); |
| 237 |
| 238 SendMessageToEmbedder(new BrowserPluginMsg_GuestContentWindowReady( |
| 239 guest_instance_id_, guest_routing_id)); |
240 } | 240 } |
241 | 241 |
242 BrowserPluginGuest::~BrowserPluginGuest() { | 242 BrowserPluginGuest::~BrowserPluginGuest() { |
243 } | 243 } |
244 | 244 |
245 // static | 245 // static |
246 BrowserPluginGuest* BrowserPluginGuest::Create( | 246 BrowserPluginGuest* BrowserPluginGuest::Create( |
247 int instance_id, | 247 int instance_id, |
248 WebContentsImpl* web_contents, | 248 WebContentsImpl* web_contents, |
249 BrowserPluginGuestDelegate* delegate) { | 249 BrowserPluginGuestDelegate* delegate) { |
(...skipping 13 matching lines...) Expand all Loading... |
263 render_view_host))); | 263 render_view_host))); |
264 } | 264 } |
265 | 265 |
266 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { | 266 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { |
267 if (!attached()) | 267 if (!attached()) |
268 return NULL; | 268 return NULL; |
269 return embedder_web_contents_->GetRenderWidgetHostView(); | 269 return embedder_web_contents_->GetRenderWidgetHostView(); |
270 } | 270 } |
271 | 271 |
272 void BrowserPluginGuest::UpdateVisibility() { | 272 void BrowserPluginGuest::UpdateVisibility() { |
273 OnSetVisibility(instance_id_, visible()); | 273 OnSetVisibility(guest_instance_id_, visible()); |
274 } | 274 } |
275 | 275 |
276 void BrowserPluginGuest::CopyFromCompositingSurface( | 276 void BrowserPluginGuest::CopyFromCompositingSurface( |
277 gfx::Rect src_subrect, | 277 gfx::Rect src_subrect, |
278 gfx::Size dst_size, | 278 gfx::Size dst_size, |
279 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 279 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
280 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); | 280 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); |
281 SendMessageToEmbedder( | 281 SendMessageToEmbedder( |
282 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), | 282 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), |
283 copy_request_id_, src_subrect, dst_size)); | 283 copy_request_id_, src_subrect, dst_size)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 382 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
383 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 383 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
384 // here (see http://crbug.com/158151). | 384 // here (see http://crbug.com/158151). |
385 Send(new InputMsg_SetFocus(routing_id(), focused_)); | 385 Send(new InputMsg_SetFocus(routing_id(), focused_)); |
386 UpdateVisibility(); | 386 UpdateVisibility(); |
387 if (auto_size_enabled_) | 387 if (auto_size_enabled_) |
388 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | 388 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
389 else | 389 else |
390 rvh->DisableAutoResize(full_size_); | 390 rvh->DisableAutoResize(full_size_); |
391 | 391 |
392 OnSetContentsOpaque(instance_id_, guest_opaque_); | 392 OnSetContentsOpaque(guest_instance_id_, guest_opaque_); |
393 | 393 |
394 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( | 394 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( |
395 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); | 395 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); |
396 } | 396 } |
397 | 397 |
398 void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { | 398 void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { |
399 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id())); | 399 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id())); |
400 switch (status) { | 400 switch (status) { |
401 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 401 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
402 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); | 402 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, | 466 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, |
467 OnTextInputStateChanged) | 467 OnTextInputStateChanged) |
468 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 468 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
469 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 469 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
470 IPC_MESSAGE_UNHANDLED(handled = false) | 470 IPC_MESSAGE_UNHANDLED(handled = false) |
471 IPC_END_MESSAGE_MAP() | 471 IPC_END_MESSAGE_MAP() |
472 return handled; | 472 return handled; |
473 } | 473 } |
474 | 474 |
475 void BrowserPluginGuest::Attach( | 475 void BrowserPluginGuest::Attach( |
| 476 int browser_plugin_instance_id, |
476 WebContentsImpl* embedder_web_contents, | 477 WebContentsImpl* embedder_web_contents, |
477 const BrowserPluginHostMsg_Attach_Params& params, | 478 const BrowserPluginHostMsg_Attach_Params& params) { |
478 const base::DictionaryValue& extra_params) { | |
479 if (attached()) | 479 if (attached()) |
480 return; | 480 return; |
481 | 481 |
482 if (delegate_) | 482 if (delegate_) |
483 delegate_->WillAttach(embedder_web_contents, extra_params); | 483 delegate_->WillAttach(embedder_web_contents); |
484 | 484 |
485 // If a RenderView has already been created for this new window, then we need | 485 // If a RenderView has already been created for this new window, then we need |
486 // to initialize the browser-side state now so that the RenderFrameHostManager | 486 // to initialize the browser-side state now so that the RenderFrameHostManager |
487 // does not create a new RenderView on navigation. | 487 // does not create a new RenderView on navigation. |
488 if (has_render_view_) { | 488 if (has_render_view_) { |
489 static_cast<RenderViewHostImpl*>( | 489 static_cast<RenderViewHostImpl*>( |
490 GetWebContents()->GetRenderViewHost())->Init(); | 490 GetWebContents()->GetRenderViewHost())->Init(); |
491 WebContentsViewGuest* new_view = | 491 WebContentsViewGuest* new_view = |
492 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 492 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
493 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 493 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
494 } | 494 } |
495 | 495 |
496 Initialize(params, embedder_web_contents, extra_params); | 496 Initialize(browser_plugin_instance_id, params, embedder_web_contents); |
497 | 497 |
498 SendQueuedMessages(); | 498 SendQueuedMessages(); |
499 | 499 |
500 if (delegate_) | 500 if (delegate_) |
501 delegate_->DidAttach(); | 501 delegate_->DidAttach(); |
502 | 502 |
503 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 503 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
504 } | 504 } |
505 | 505 |
506 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 506 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 // the guest to completely repaint itself. | 743 // the guest to completely repaint itself. |
744 // Ideally, we shouldn't need to do this unless |max_auto_size_| has | 744 // Ideally, we shouldn't need to do this unless |max_auto_size_| has |
745 // changed. | 745 // changed. |
746 // However, even in that case, layout may not change and so we may | 746 // However, even in that case, layout may not change and so we may |
747 // not get a full frame worth of pixels. | 747 // not get a full frame worth of pixels. |
748 Send(new ViewMsg_Repaint(routing_id(), max_auto_size_)); | 748 Send(new ViewMsg_Repaint(routing_id(), max_auto_size_)); |
749 } else if (!auto_size_enabled_ && old_auto_size_enabled) { | 749 } else if (!auto_size_enabled_ && old_auto_size_enabled) { |
750 GetWebContents()->GetRenderViewHost()->DisableAutoResize( | 750 GetWebContents()->GetRenderViewHost()->DisableAutoResize( |
751 resize_guest_params.view_size); | 751 resize_guest_params.view_size); |
752 } | 752 } |
753 OnResizeGuest(instance_id_, resize_guest_params); | 753 OnResizeGuest(guest_instance_id_, resize_guest_params); |
754 } | 754 } |
755 | 755 |
756 void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( | 756 void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( |
757 int instance_id, | 757 int instance_id, |
758 const std::vector<EditCommand>& edit_commands) { | 758 const std::vector<EditCommand>& edit_commands) { |
759 Send(new InputMsg_SetEditCommandsForNextKeyEvent(routing_id(), | 759 Send(new InputMsg_SetEditCommandsForNextKeyEvent(routing_id(), |
760 edit_commands)); | 760 edit_commands)); |
761 } | 761 } |
762 | 762 |
763 void BrowserPluginGuest::OnSetContentsOpaque(int instance_id, bool opaque) { | 763 void BrowserPluginGuest::OnSetContentsOpaque(int instance_id, bool opaque) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 889 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
890 const gfx::Range& range, | 890 const gfx::Range& range, |
891 const std::vector<gfx::Rect>& character_bounds) { | 891 const std::vector<gfx::Rect>& character_bounds) { |
892 static_cast<RenderWidgetHostViewBase*>( | 892 static_cast<RenderWidgetHostViewBase*>( |
893 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 893 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
894 range, character_bounds); | 894 range, character_bounds); |
895 } | 895 } |
896 #endif | 896 #endif |
897 | 897 |
898 } // namespace content | 898 } // namespace content |
OLD | NEW |