| 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 copy_request_id_(0), | 82 copy_request_id_(0), |
| 84 has_render_view_(has_render_view), | 83 has_render_view_(has_render_view), |
| 85 is_in_destruction_(false), | 84 is_in_destruction_(false), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 OnSetContentsOpaque) | 155 OnSetContentsOpaque) |
| 157 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 156 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
| 158 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) | 157 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
| 159 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) | 158 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
| 160 IPC_MESSAGE_UNHANDLED(handled = false) | 159 IPC_MESSAGE_UNHANDLED(handled = false) |
| 161 IPC_END_MESSAGE_MAP() | 160 IPC_END_MESSAGE_MAP() |
| 162 return handled; | 161 return handled; |
| 163 } | 162 } |
| 164 | 163 |
| 165 void BrowserPluginGuest::Initialize( | 164 void BrowserPluginGuest::Initialize( |
| 165 int browser_plugin_instance_id, |
| 166 const BrowserPluginHostMsg_Attach_Params& params, | 166 const BrowserPluginHostMsg_Attach_Params& params, |
| 167 WebContentsImpl* embedder_web_contents, | 167 WebContentsImpl* embedder_web_contents) { |
| 168 const base::DictionaryValue& extra_params) { | |
| 169 focused_ = params.focused; | 168 focused_ = params.focused; |
| 170 guest_visible_ = params.visible; | 169 guest_visible_ = params.visible; |
| 171 guest_opaque_ = params.opaque; | 170 guest_opaque_ = params.opaque; |
| 172 guest_window_rect_ = gfx::Rect(params.origin, | 171 guest_window_rect_ = gfx::Rect(params.origin, |
| 173 params.resize_guest_params.view_size); | 172 params.resize_guest_params.view_size); |
| 174 | 173 |
| 175 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 174 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
| 176 // be attached. | 175 // be attached. |
| 177 embedder_web_contents_ = embedder_web_contents; | 176 embedder_web_contents_ = embedder_web_contents; |
| 178 | 177 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 197 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. | 196 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. |
| 198 renderer_prefs->report_frame_name_changes = true; | 197 renderer_prefs->report_frame_name_changes = true; |
| 199 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 198 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
| 200 // navigations still continue to function inside the app. | 199 // navigations still continue to function inside the app. |
| 201 renderer_prefs->browser_handles_all_top_level_requests = false; | 200 renderer_prefs->browser_handles_all_top_level_requests = false; |
| 202 // Disable "client blocked" error page for browser plugin. | 201 // Disable "client blocked" error page for browser plugin. |
| 203 renderer_prefs->disable_client_blocked_error_page = true; | 202 renderer_prefs->disable_client_blocked_error_page = true; |
| 204 | 203 |
| 205 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); | 204 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); |
| 206 | 205 |
| 207 OnResizeGuest(instance_id_, params.resize_guest_params); | 206 OnResizeGuest(guest_instance_id_, params.resize_guest_params); |
| 208 | 207 |
| 209 // Create a swapped out RenderView for the guest in the embedder render | 208 // Create a swapped out RenderView for the guest in the embedder render |
| 210 // process, so that the embedder can access the guest's window object. | 209 // process, so that the embedder can access the guest's window object. |
| 211 int guest_routing_id = | 210 int guest_routing_id = |
| 212 GetWebContents()->CreateSwappedOutRenderView( | 211 GetWebContents()->CreateSwappedOutRenderView( |
| 213 embedder_web_contents_->GetSiteInstance()); | 212 embedder_web_contents_->GetSiteInstance()); |
| 214 SendMessageToEmbedder( | |
| 215 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, | |
| 216 guest_routing_id)); | |
| 217 | 213 |
| 218 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); | 214 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); |
| 219 prefs.navigate_on_drag_drop = false; | 215 prefs.navigate_on_drag_drop = false; |
| 220 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); | 216 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); |
| 221 | 217 |
| 222 // Enable input method for guest if it's enabled for the embedder. | 218 // Enable input method for guest if it's enabled for the embedder. |
| 223 if (static_cast<RenderViewHostImpl*>( | 219 if (static_cast<RenderViewHostImpl*>( |
| 224 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { | 220 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { |
| 225 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 221 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 226 GetWebContents()->GetRenderViewHost()); | 222 GetWebContents()->GetRenderViewHost()); |
| 227 guest_rvh->SetInputMethodActive(true); | 223 guest_rvh->SetInputMethodActive(true); |
| 228 } | 224 } |
| 229 | 225 |
| 230 // Inform the embedder of the guest's attachment. | 226 // Inform the embedder of the guest's attachment. |
| 231 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_)); | 227 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(guest_instance_id_)); |
| 228 |
| 229 SendMessageToEmbedder(new BrowserPluginMsg_GuestContentWindowReady( |
| 230 guest_instance_id_, guest_routing_id)); |
| 232 } | 231 } |
| 233 | 232 |
| 234 BrowserPluginGuest::~BrowserPluginGuest() { | 233 BrowserPluginGuest::~BrowserPluginGuest() { |
| 235 } | 234 } |
| 236 | 235 |
| 237 // static | 236 // static |
| 238 BrowserPluginGuest* BrowserPluginGuest::Create( | 237 BrowserPluginGuest* BrowserPluginGuest::Create( |
| 239 int instance_id, | 238 int instance_id, |
| 240 WebContentsImpl* web_contents, | 239 WebContentsImpl* web_contents, |
| 241 BrowserPluginGuestDelegate* delegate) { | 240 BrowserPluginGuestDelegate* delegate) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 255 render_view_host))); | 254 render_view_host))); |
| 256 } | 255 } |
| 257 | 256 |
| 258 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { | 257 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { |
| 259 if (!attached()) | 258 if (!attached()) |
| 260 return NULL; | 259 return NULL; |
| 261 return embedder_web_contents_->GetRenderWidgetHostView(); | 260 return embedder_web_contents_->GetRenderWidgetHostView(); |
| 262 } | 261 } |
| 263 | 262 |
| 264 void BrowserPluginGuest::UpdateVisibility() { | 263 void BrowserPluginGuest::UpdateVisibility() { |
| 265 OnSetVisibility(instance_id_, visible()); | 264 OnSetVisibility(guest_instance_id_, visible()); |
| 266 } | 265 } |
| 267 | 266 |
| 268 void BrowserPluginGuest::CopyFromCompositingSurface( | 267 void BrowserPluginGuest::CopyFromCompositingSurface( |
| 269 gfx::Rect src_subrect, | 268 gfx::Rect src_subrect, |
| 270 gfx::Size dst_size, | 269 gfx::Size dst_size, |
| 271 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 270 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 272 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); | 271 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); |
| 273 SendMessageToEmbedder( | 272 SendMessageToEmbedder( |
| 274 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), | 273 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), |
| 275 copy_request_id_, src_subrect, dst_size)); | 274 copy_request_id_, src_subrect, dst_size)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 364 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
| 366 } | 365 } |
| 367 | 366 |
| 368 void BrowserPluginGuest::RenderViewReady() { | 367 void BrowserPluginGuest::RenderViewReady() { |
| 369 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 368 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
| 370 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 369 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 371 // here (see http://crbug.com/158151). | 370 // here (see http://crbug.com/158151). |
| 372 Send(new InputMsg_SetFocus(routing_id(), focused_)); | 371 Send(new InputMsg_SetFocus(routing_id(), focused_)); |
| 373 UpdateVisibility(); | 372 UpdateVisibility(); |
| 374 | 373 |
| 375 OnSetContentsOpaque(instance_id_, guest_opaque_); | 374 OnSetContentsOpaque(guest_instance_id_, guest_opaque_); |
| 376 | 375 |
| 377 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( | 376 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( |
| 378 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); | 377 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); |
| 379 } | 378 } |
| 380 | 379 |
| 381 void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { | 380 void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { |
| 382 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id())); | 381 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id())); |
| 383 switch (status) { | 382 switch (status) { |
| 384 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 383 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 385 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); | 384 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, | 447 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, |
| 449 OnTextInputStateChanged) | 448 OnTextInputStateChanged) |
| 450 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 449 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
| 451 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 450 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 452 IPC_MESSAGE_UNHANDLED(handled = false) | 451 IPC_MESSAGE_UNHANDLED(handled = false) |
| 453 IPC_END_MESSAGE_MAP() | 452 IPC_END_MESSAGE_MAP() |
| 454 return handled; | 453 return handled; |
| 455 } | 454 } |
| 456 | 455 |
| 457 void BrowserPluginGuest::Attach( | 456 void BrowserPluginGuest::Attach( |
| 457 int browser_plugin_instance_id, |
| 458 WebContentsImpl* embedder_web_contents, | 458 WebContentsImpl* embedder_web_contents, |
| 459 const BrowserPluginHostMsg_Attach_Params& params, | 459 const BrowserPluginHostMsg_Attach_Params& params) { |
| 460 const base::DictionaryValue& extra_params) { | |
| 461 if (attached()) | 460 if (attached()) |
| 462 return; | 461 return; |
| 463 | 462 |
| 464 if (delegate_) | 463 if (delegate_) |
| 465 delegate_->WillAttach(embedder_web_contents, extra_params); | 464 delegate_->WillAttach(embedder_web_contents); |
| 466 | 465 |
| 467 // If a RenderView has already been created for this new window, then we need | 466 // If a RenderView has already been created for this new window, then we need |
| 468 // to initialize the browser-side state now so that the RenderFrameHostManager | 467 // to initialize the browser-side state now so that the RenderFrameHostManager |
| 469 // does not create a new RenderView on navigation. | 468 // does not create a new RenderView on navigation. |
| 470 if (has_render_view_) { | 469 if (has_render_view_) { |
| 471 static_cast<RenderViewHostImpl*>( | 470 static_cast<RenderViewHostImpl*>( |
| 472 GetWebContents()->GetRenderViewHost())->Init(); | 471 GetWebContents()->GetRenderViewHost())->Init(); |
| 473 WebContentsViewGuest* new_view = | 472 WebContentsViewGuest* new_view = |
| 474 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 473 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
| 475 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 474 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
| 476 } | 475 } |
| 477 | 476 |
| 478 Initialize(params, embedder_web_contents, extra_params); | 477 Initialize(browser_plugin_instance_id, params, embedder_web_contents); |
| 479 | 478 |
| 480 SendQueuedMessages(); | 479 SendQueuedMessages(); |
| 481 | 480 |
| 482 if (delegate_) | 481 if (delegate_) |
| 483 delegate_->DidAttach(); | 482 delegate_->DidAttach(); |
| 484 | 483 |
| 485 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 484 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
| 486 } | 485 } |
| 487 | 486 |
| 488 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 487 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 833 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
| 835 const gfx::Range& range, | 834 const gfx::Range& range, |
| 836 const std::vector<gfx::Rect>& character_bounds) { | 835 const std::vector<gfx::Rect>& character_bounds) { |
| 837 static_cast<RenderWidgetHostViewBase*>( | 836 static_cast<RenderWidgetHostViewBase*>( |
| 838 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 837 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
| 839 range, character_bounds); | 838 range, character_bounds); |
| 840 } | 839 } |
| 841 #endif | 840 #endif |
| 842 | 841 |
| 843 } // namespace content | 842 } // namespace content |
| OLD | NEW |