| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "ui/events/keycodes/keyboard_codes.h" | 33 #include "ui/events/keycodes/keyboard_codes.h" |
| 34 | 34 |
| 35 using blink::WebCanvas; | 35 using blink::WebCanvas; |
| 36 using blink::WebPluginContainer; | 36 using blink::WebPluginContainer; |
| 37 using blink::WebPluginParams; | 37 using blink::WebPluginParams; |
| 38 using blink::WebPoint; | 38 using blink::WebPoint; |
| 39 using blink::WebRect; | 39 using blink::WebRect; |
| 40 using blink::WebURL; | 40 using blink::WebURL; |
| 41 using blink::WebVector; | 41 using blink::WebVector; |
| 42 | 42 |
| 43 namespace { |
| 44 typedef std::map<blink::WebPluginContainer*, content::BrowserPlugin*> |
| 45 PluginContainerMap; |
| 46 static base::LazyInstance<PluginContainerMap> g_plugin_container_map = |
| 47 LAZY_INSTANCE_INITIALIZER; |
| 48 |
| 49 } // namespace |
| 50 |
| 43 namespace content { | 51 namespace content { |
| 44 | 52 |
| 45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, | 53 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, |
| 46 blink::WebFrame* frame, | 54 blink::WebFrame* frame, |
| 47 bool auto_navigate) | 55 bool auto_navigate) |
| 48 : guest_instance_id_(browser_plugin::kInstanceIDNone), | 56 : guest_instance_id_(browser_plugin::kInstanceIDNone), |
| 49 attached_(false), | 57 attached_(false), |
| 58 attach_pending_(false), |
| 50 render_view_(render_view->AsWeakPtr()), | 59 render_view_(render_view->AsWeakPtr()), |
| 51 render_view_routing_id_(render_view->GetRoutingID()), | 60 render_view_routing_id_(render_view->GetRoutingID()), |
| 52 container_(NULL), | 61 container_(NULL), |
| 53 paint_ack_received_(true), | 62 paint_ack_received_(true), |
| 54 last_device_scale_factor_(GetDeviceScaleFactor()), | 63 last_device_scale_factor_(GetDeviceScaleFactor()), |
| 55 sad_guest_(NULL), | 64 sad_guest_(NULL), |
| 56 guest_crashed_(false), | 65 guest_crashed_(false), |
| 57 is_auto_size_state_dirty_(false), | 66 is_auto_size_state_dirty_(false), |
| 58 content_window_routing_id_(MSG_ROUTING_NONE), | 67 content_window_routing_id_(MSG_ROUTING_NONE), |
| 59 plugin_focused_(false), | 68 plugin_focused_(false), |
| 60 visible_(true), | 69 visible_(true), |
| 61 auto_navigate_(auto_navigate), | 70 auto_navigate_(auto_navigate), |
| 62 mouse_locked_(false), | 71 mouse_locked_(false), |
| 63 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 72 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
| 73 in_render_tree_(false), |
| 64 weak_ptr_factory_(this) { | 74 weak_ptr_factory_(this) { |
| 65 } | 75 } |
| 66 | 76 |
| 67 BrowserPlugin::~BrowserPlugin() { | 77 BrowserPlugin::~BrowserPlugin() { |
| 78 if (in_render_tree_) { |
| 79 browser_plugin_manager()->RemoveBrowserPluginInternal(instance_id_); |
| 80 } |
| 68 // If the BrowserPlugin has never navigated then the browser process and | 81 // If the BrowserPlugin has never navigated then the browser process and |
| 69 // BrowserPluginManager don't know about it and so there is nothing to do | 82 // BrowserPluginManager don't know about it and so there is nothing to do |
| 70 // here. | 83 // here. |
| 71 if (!HasGuestInstanceID()) | 84 if (!attached()) |
| 72 return; | 85 return; |
| 73 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); | 86 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); |
| 74 browser_plugin_manager()->Send( | 87 browser_plugin_manager()->Send( |
| 75 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, | 88 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, |
| 76 guest_instance_id_)); | 89 guest_instance_id_)); |
| 77 } | 90 } |
| 78 | 91 |
| 79 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 92 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
| 80 bool handled = true; | 93 bool handled = true; |
| 81 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 94 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 int BrowserPlugin::GetAdjustedMinWidth() const { | 211 int BrowserPlugin::GetAdjustedMinWidth() const { |
| 199 int min_width = GetMinWidthAttribute(); | 212 int min_width = GetMinWidthAttribute(); |
| 200 // FrameView.cpp does not allow this value to be <= 0, so when the value is | 213 // FrameView.cpp does not allow this value to be <= 0, so when the value is |
| 201 // unset (or set to 0), we set it to the container size. | 214 // unset (or set to 0), we set it to the container size. |
| 202 min_width = min_width ? min_width : width(); | 215 min_width = min_width ? min_width : width(); |
| 203 // For autosize, minWidth should not be bigger than maxWidth. | 216 // For autosize, minWidth should not be bigger than maxWidth. |
| 204 return std::min(min_width, GetAdjustedMaxWidth()); | 217 return std::min(min_width, GetAdjustedMaxWidth()); |
| 205 } | 218 } |
| 206 | 219 |
| 207 void BrowserPlugin::ParseAllowTransparencyAttribute() { | 220 void BrowserPlugin::ParseAllowTransparencyAttribute() { |
| 208 if (!HasGuestInstanceID()) | 221 if (!attached()) |
| 209 return; | 222 return; |
| 210 | 223 |
| 211 bool opaque = !GetAllowTransparencyAttribute(); | 224 bool opaque = !GetAllowTransparencyAttribute(); |
| 212 | 225 |
| 213 if (compositing_helper_) | 226 if (compositing_helper_) |
| 214 compositing_helper_->SetContentsOpaque(opaque); | 227 compositing_helper_->SetContentsOpaque(opaque); |
| 215 | 228 |
| 216 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( | 229 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( |
| 217 render_view_routing_id_, | 230 render_view_routing_id_, |
| 218 guest_instance_id_, | 231 guest_instance_id_, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 239 max_auto_size_ = params->max_size; | 252 max_auto_size_ = params->max_size; |
| 240 } else { | 253 } else { |
| 241 max_auto_size_ = gfx::Size(); | 254 max_auto_size_ = gfx::Size(); |
| 242 } | 255 } |
| 243 } | 256 } |
| 244 | 257 |
| 245 void BrowserPlugin::UpdateGuestAutoSizeState(bool auto_size_enabled) { | 258 void BrowserPlugin::UpdateGuestAutoSizeState(bool auto_size_enabled) { |
| 246 // If we haven't yet heard back from the guest about the last resize request, | 259 // If we haven't yet heard back from the guest about the last resize request, |
| 247 // then we don't issue another request until we do in | 260 // then we don't issue another request until we do in |
| 248 // BrowserPlugin::OnUpdateRect. | 261 // BrowserPlugin::OnUpdateRect. |
| 249 if (!HasGuestInstanceID() || !paint_ack_received_) | 262 if (!attached() || !paint_ack_received_) |
| 250 return; | 263 return; |
| 251 | 264 |
| 252 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 265 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 253 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 266 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 254 if (auto_size_enabled) { | 267 if (auto_size_enabled) { |
| 255 GetSizeParams(&auto_size_params, &resize_guest_params, true); | 268 GetSizeParams(&auto_size_params, &resize_guest_params, true); |
| 256 } else { | 269 } else { |
| 257 GetSizeParams(NULL, &resize_guest_params, true); | 270 GetSizeParams(NULL, &resize_guest_params, true); |
| 258 } | 271 } |
| 259 paint_ack_received_ = false; | 272 paint_ack_received_ = false; |
| 260 browser_plugin_manager()->Send( | 273 browser_plugin_manager()->Send( |
| 261 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, | 274 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, |
| 262 guest_instance_id_, | 275 guest_instance_id_, |
| 263 auto_size_params, | 276 auto_size_params, |
| 264 resize_guest_params)); | 277 resize_guest_params)); |
| 265 } | 278 } |
| 266 | 279 |
| 267 void BrowserPlugin::Attach(int guest_instance_id, | 280 void BrowserPlugin::Attach() { |
| 268 scoped_ptr<base::DictionaryValue> extra_params) { | 281 if (attach_pending_) |
| 269 CHECK(guest_instance_id != browser_plugin::kInstanceIDNone); | 282 return; |
| 270 | 283 |
| 271 // If this BrowserPlugin is already attached to a guest, then kill the guest. | 284 // If this BrowserPlugin is already attached to a guest, then kill the guest. |
| 272 if (HasGuestInstanceID()) { | 285 if (attached()) { |
| 273 if (guest_instance_id == guest_instance_id_) | |
| 274 return; | |
| 275 guest_crashed_ = false; | 286 guest_crashed_ = false; |
| 276 EnableCompositing(false); | 287 EnableCompositing(false); |
| 277 if (compositing_helper_) { | 288 if (compositing_helper_) { |
| 278 compositing_helper_->OnContainerDestroy(); | 289 compositing_helper_->OnContainerDestroy(); |
| 279 compositing_helper_ = NULL; | 290 compositing_helper_ = NULL; |
| 280 } | 291 } |
| 281 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); | 292 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); |
| 282 browser_plugin_manager()->Send(new BrowserPluginHostMsg_PluginDestroyed( | 293 browser_plugin_manager()->Send(new BrowserPluginHostMsg_PluginDestroyed( |
| 283 render_view_routing_id_, guest_instance_id_)); | 294 render_view_routing_id_, guest_instance_id_)); |
| 284 } | 295 } |
| 285 | 296 |
| 286 // This API may be called directly without setting the src attribute. | |
| 287 // In that case, we need to make sure we don't allocate another instance ID. | |
| 288 guest_instance_id_ = guest_instance_id; | |
| 289 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this); | |
| 290 | |
| 291 BrowserPluginHostMsg_Attach_Params attach_params; | 297 BrowserPluginHostMsg_Attach_Params attach_params; |
| 292 attach_params.focused = ShouldGuestBeFocused(); | 298 attach_params.focused = ShouldGuestBeFocused(); |
| 293 attach_params.visible = visible_; | 299 attach_params.visible = visible_; |
| 294 attach_params.opaque = !GetAllowTransparencyAttribute(); | 300 attach_params.opaque = !GetAllowTransparencyAttribute(); |
| 295 attach_params.origin = plugin_rect().origin(); | 301 attach_params.origin = plugin_rect().origin(); |
| 296 GetSizeParams(&attach_params.auto_size_params, | 302 GetSizeParams(&attach_params.auto_size_params, |
| 297 &attach_params.resize_guest_params, | 303 &attach_params.resize_guest_params, |
| 298 false); | 304 false); |
| 299 | 305 |
| 300 browser_plugin_manager()->Send( | 306 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( |
| 301 new BrowserPluginHostMsg_Attach(render_view_routing_id_, | 307 render_view_routing_id_, |
| 302 guest_instance_id_, attach_params, | 308 instance_id_, |
| 303 *extra_params)); | 309 attach_params)); |
| 310 |
| 311 attach_pending_ = true; |
| 304 } | 312 } |
| 305 | 313 |
| 306 void BrowserPlugin::DidCommitCompositorFrame() { | 314 void BrowserPlugin::DidCommitCompositorFrame() { |
| 307 if (compositing_helper_.get()) | 315 if (compositing_helper_.get()) |
| 308 compositing_helper_->DidCommitCompositorFrame(); | 316 compositing_helper_->DidCommitCompositorFrame(); |
| 309 } | 317 } |
| 310 | 318 |
| 311 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { | 319 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { |
| 312 DCHECK(render_view_.get()); | 320 DCHECK(render_view_.get()); |
| 313 render_view_->GetWebView()->advanceFocus(reverse); | 321 render_view_->GetWebView()->advanceFocus(reverse); |
| 314 } | 322 } |
| 315 | 323 |
| 316 void BrowserPlugin::OnAttachACK(int guest_instance_id) { | 324 void BrowserPlugin::OnAttachACK(int browser_plugin_instance_id, |
| 325 int guest_instance_id) { |
| 326 DCHECK(!attached()); |
| 327 guest_instance_id_ = guest_instance_id; |
| 328 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this); |
| 317 attached_ = true; | 329 attached_ = true; |
| 330 attach_pending_ = false; |
| 318 } | 331 } |
| 319 | 332 |
| 320 void BrowserPlugin::OnBuffersSwapped( | 333 void BrowserPlugin::OnBuffersSwapped( |
| 321 int instance_id, | 334 int instance_id, |
| 322 const FrameMsg_BuffersSwapped_Params& params) { | 335 const FrameMsg_BuffersSwapped_Params& params) { |
| 323 EnableCompositing(true); | 336 EnableCompositing(true); |
| 324 | 337 |
| 325 compositing_helper_->OnBuffersSwapped(params.size, | 338 compositing_helper_->OnBuffersSwapped(params.size, |
| 326 params.mailbox, | 339 params.mailbox, |
| 327 params.gpu_route_id, | 340 params.gpu_route_id, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 OnLockMouseACK(false); | 413 OnLockMouseACK(false); |
| 401 return; | 414 return; |
| 402 } | 415 } |
| 403 render_view_->mouse_lock_dispatcher()->UnlockMouse(this); | 416 render_view_->mouse_lock_dispatcher()->UnlockMouse(this); |
| 404 } | 417 } |
| 405 } | 418 } |
| 406 | 419 |
| 407 void BrowserPlugin::OnShouldAcceptTouchEvents(int guest_instance_id, | 420 void BrowserPlugin::OnShouldAcceptTouchEvents(int guest_instance_id, |
| 408 bool accept) { | 421 bool accept) { |
| 409 if (container()) { | 422 if (container()) { |
| 410 container()->requestTouchEventType(accept ? | 423 container()->requestTouchEventType( |
| 411 blink::WebPluginContainer::TouchEventRequestTypeRaw : | 424 accept ? WebPluginContainer::TouchEventRequestTypeRaw |
| 412 blink::WebPluginContainer::TouchEventRequestTypeNone); | 425 : WebPluginContainer::TouchEventRequestTypeNone); |
| 413 } | 426 } |
| 414 } | 427 } |
| 415 | 428 |
| 416 void BrowserPlugin::OnUpdateRect( | 429 void BrowserPlugin::OnUpdateRect( |
| 417 int guest_instance_id, | 430 int guest_instance_id, |
| 418 const BrowserPluginMsg_UpdateRect_Params& params) { | 431 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 419 // Note that there is no need to send ACK for this message. | 432 // Note that there is no need to send ACK for this message. |
| 420 // If the guest has updated pixels then it is no longer crashed. | 433 // If the guest has updated pixels then it is no longer crashed. |
| 421 guest_crashed_ = false; | 434 guest_crashed_ = false; |
| 422 | 435 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 486 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
| 474 return NULL; | 487 return NULL; |
| 475 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( | 488 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( |
| 476 content_window_routing_id_); | 489 content_window_routing_id_); |
| 477 if (!guest_render_view) | 490 if (!guest_render_view) |
| 478 return NULL; | 491 return NULL; |
| 479 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 492 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
| 480 return guest_frame->windowObject(); | 493 return guest_frame->windowObject(); |
| 481 } | 494 } |
| 482 | 495 |
| 483 bool BrowserPlugin::HasGuestInstanceID() const { | |
| 484 return guest_instance_id_ != browser_plugin::kInstanceIDNone; | |
| 485 } | |
| 486 | |
| 487 void BrowserPlugin::ShowSadGraphic() { | 496 void BrowserPlugin::ShowSadGraphic() { |
| 488 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 497 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 489 // NULL so we shouldn't attempt to access it. | 498 // NULL so we shouldn't attempt to access it. |
| 490 if (container_) | 499 if (container_) |
| 491 container_->invalidate(); | 500 container_->invalidate(); |
| 492 } | 501 } |
| 493 | 502 |
| 494 float BrowserPlugin::GetDeviceScaleFactor() const { | 503 float BrowserPlugin::GetDeviceScaleFactor() const { |
| 495 if (!render_view_.get()) | 504 if (!render_view_.get()) |
| 496 return 1.0f; | 505 return 1.0f; |
| 497 return render_view_->GetWebView()->deviceScaleFactor(); | 506 return render_view_->GetWebView()->deviceScaleFactor(); |
| 498 } | 507 } |
| 499 | 508 |
| 500 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { | 509 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { |
| 501 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) | 510 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) |
| 502 return; | 511 return; |
| 503 | 512 |
| 504 BrowserPluginHostMsg_ResizeGuest_Params params; | 513 BrowserPluginHostMsg_ResizeGuest_Params params; |
| 505 PopulateResizeGuestParameters(¶ms, plugin_size(), true); | 514 PopulateResizeGuestParameters(¶ms, plugin_size(), true); |
| 506 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 515 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 507 render_view_routing_id_, | 516 render_view_routing_id_, |
| 508 guest_instance_id_, | 517 guest_instance_id_, |
| 509 params)); | 518 params)); |
| 510 } | 519 } |
| 511 | 520 |
| 512 void BrowserPlugin::UpdateGuestFocusState() { | 521 void BrowserPlugin::UpdateGuestFocusState() { |
| 513 if (!HasGuestInstanceID()) | 522 if (!attached()) |
| 514 return; | 523 return; |
| 515 bool should_be_focused = ShouldGuestBeFocused(); | 524 bool should_be_focused = ShouldGuestBeFocused(); |
| 516 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 525 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
| 517 render_view_routing_id_, | 526 render_view_routing_id_, |
| 518 guest_instance_id_, | 527 guest_instance_id_, |
| 519 should_be_focused)); | 528 should_be_focused)); |
| 520 } | 529 } |
| 521 | 530 |
| 522 bool BrowserPlugin::ShouldGuestBeFocused() const { | 531 bool BrowserPlugin::ShouldGuestBeFocused() const { |
| 523 bool embedder_focused = false; | 532 bool embedder_focused = false; |
| 524 if (render_view_.get()) | 533 if (render_view_.get()) |
| 525 embedder_focused = render_view_->has_focus(); | 534 embedder_focused = render_view_->has_focus(); |
| 526 return plugin_focused_ && embedder_focused; | 535 return plugin_focused_ && embedder_focused; |
| 527 } | 536 } |
| 528 | 537 |
| 529 blink::WebPluginContainer* BrowserPlugin::container() const { | 538 WebPluginContainer* BrowserPlugin::container() const { |
| 530 return container_; | 539 return container_; |
| 531 } | 540 } |
| 532 | 541 |
| 533 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 542 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 534 if (!container) | 543 if (!container) |
| 535 return false; | 544 return false; |
| 536 | 545 |
| 537 // Tell |container| to allow this plugin to use script objects. | 546 // Tell |container| to allow this plugin to use script objects. |
| 538 npp_.reset(new NPP_t); | 547 npp_.reset(new NPP_t); |
| 539 container->allowScriptObjects(); | 548 container->allowScriptObjects(); |
| 540 | 549 |
| 541 bindings_.reset(new BrowserPluginBindings(this)); | 550 bindings_.reset(new BrowserPluginBindings(this)); |
| 542 container_ = container; | 551 container_ = container; |
| 543 container_->setWantsWheelEvents(true); | 552 container_->setWantsWheelEvents(true); |
| 544 // This is a way to notify observers of our attributes that we have the | 553 |
| 545 // bindings ready. This also means that this plugin is available in render | 554 g_plugin_container_map.Get().insert(std::make_pair(container_, this)); |
| 546 // tree. | 555 |
| 547 UpdateDOMAttribute("internalbindings", "true"); | 556 // This is a way to notify observers of our attributes that this plugin is |
| 557 // available in render tree. |
| 558 const int next_instance_id = browser_plugin_manager()->GetNextInstanceID(); |
| 559 instance_id_ = next_instance_id; |
| 560 UpdateDOMAttribute("internalinstanceid", |
| 561 base::StringPrintf("%d", next_instance_id)); |
| 562 in_render_tree_ = true; |
| 563 |
| 564 browser_plugin_manager()->AddBrowserPluginInternal(instance_id_, this); |
| 548 return true; | 565 return true; |
| 549 } | 566 } |
| 550 | 567 |
| 551 void BrowserPlugin::EnableCompositing(bool enable) { | 568 void BrowserPlugin::EnableCompositing(bool enable) { |
| 552 bool enabled = !!compositing_helper_; | 569 bool enabled = !!compositing_helper_; |
| 553 if (enabled == enable) | 570 if (enabled == enable) |
| 554 return; | 571 return; |
| 555 | 572 |
| 556 if (enable) { | 573 if (enable) { |
| 557 DCHECK(!compositing_helper_.get()); | 574 DCHECK(!compositing_helper_.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 570 } | 587 } |
| 571 } | 588 } |
| 572 | 589 |
| 573 void BrowserPlugin::destroy() { | 590 void BrowserPlugin::destroy() { |
| 574 // If the plugin was initialized then it has a valid |npp_| identifier, and | 591 // If the plugin was initialized then it has a valid |npp_| identifier, and |
| 575 // the |container_| must clear references to the plugin's script objects. | 592 // the |container_| must clear references to the plugin's script objects. |
| 576 DCHECK(!npp_ || container_); | 593 DCHECK(!npp_ || container_); |
| 577 if (container_) | 594 if (container_) |
| 578 container_->clearScriptObjects(); | 595 container_->clearScriptObjects(); |
| 579 | 596 |
| 597 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
| 598 // call returns, so let's not keep a reference to it around. |
| 599 g_plugin_container_map.Get().erase(container_); |
| 600 |
| 580 if (compositing_helper_.get()) | 601 if (compositing_helper_.get()) |
| 581 compositing_helper_->OnContainerDestroy(); | 602 compositing_helper_->OnContainerDestroy(); |
| 582 container_ = NULL; | 603 container_ = NULL; |
| 583 // Will be a no-op if the mouse is not currently locked. | 604 // Will be a no-op if the mouse is not currently locked. |
| 584 if (render_view_.get()) | 605 if (render_view_.get()) |
| 585 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); | 606 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); |
| 586 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 607 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 587 } | 608 } |
| 588 | 609 |
| 589 NPObject* BrowserPlugin::scriptableObject() { | 610 NPObject* BrowserPlugin::scriptableObject() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 SkIntToScalar(plugin_rect_.height())); | 658 SkIntToScalar(plugin_rect_.height())); |
| 638 canvas->clipRect(image_data_rect); | 659 canvas->clipRect(image_data_rect); |
| 639 // Paint black or white in case we have nothing in our backing store or we | 660 // Paint black or white in case we have nothing in our backing store or we |
| 640 // need to show a gutter. | 661 // need to show a gutter. |
| 641 SkPaint paint; | 662 SkPaint paint; |
| 642 paint.setStyle(SkPaint::kFill_Style); | 663 paint.setStyle(SkPaint::kFill_Style); |
| 643 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE); | 664 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE); |
| 644 canvas->drawRect(image_data_rect, paint); | 665 canvas->drawRect(image_data_rect, paint); |
| 645 } | 666 } |
| 646 | 667 |
| 668 // static. |
| 669 BrowserPlugin* BrowserPlugin::FromNode(blink::WebNode& node) { |
| 670 blink::WebPluginContainer* container = node.pluginContainer(); |
| 671 if (!container) |
| 672 return NULL; |
| 673 |
| 674 PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer(); |
| 675 PluginContainerMap::iterator it = browser_plugins->find(container); |
| 676 return it == browser_plugins->end() ? NULL : it->second; |
| 677 } |
| 678 |
| 647 // static | 679 // static |
| 648 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 680 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
| 649 const IPC::Message& message) { | 681 const IPC::Message& message) { |
| 650 switch (message.type()) { | 682 switch (message.type()) { |
| 651 case BrowserPluginMsg_AdvanceFocus::ID: | 683 case BrowserPluginMsg_AdvanceFocus::ID: |
| 652 case BrowserPluginMsg_Attach_ACK::ID: | |
| 653 case BrowserPluginMsg_BuffersSwapped::ID: | 684 case BrowserPluginMsg_BuffersSwapped::ID: |
| 654 case BrowserPluginMsg_CompositorFrameSwapped::ID: | 685 case BrowserPluginMsg_CompositorFrameSwapped::ID: |
| 655 case BrowserPluginMsg_CopyFromCompositingSurface::ID: | 686 case BrowserPluginMsg_CopyFromCompositingSurface::ID: |
| 656 case BrowserPluginMsg_GuestContentWindowReady::ID: | 687 case BrowserPluginMsg_GuestContentWindowReady::ID: |
| 657 case BrowserPluginMsg_GuestGone::ID: | 688 case BrowserPluginMsg_GuestGone::ID: |
| 658 case BrowserPluginMsg_SetCursor::ID: | 689 case BrowserPluginMsg_SetCursor::ID: |
| 659 case BrowserPluginMsg_SetMouseLock::ID: | 690 case BrowserPluginMsg_SetMouseLock::ID: |
| 660 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: | 691 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: |
| 661 case BrowserPluginMsg_UpdateRect::ID: | 692 case BrowserPluginMsg_UpdateRect::ID: |
| 662 return true; | 693 return true; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 void BrowserPlugin::updateFocus(bool focused) { | 766 void BrowserPlugin::updateFocus(bool focused) { |
| 736 plugin_focused_ = focused; | 767 plugin_focused_ = focused; |
| 737 UpdateGuestFocusState(); | 768 UpdateGuestFocusState(); |
| 738 } | 769 } |
| 739 | 770 |
| 740 void BrowserPlugin::updateVisibility(bool visible) { | 771 void BrowserPlugin::updateVisibility(bool visible) { |
| 741 if (visible_ == visible) | 772 if (visible_ == visible) |
| 742 return; | 773 return; |
| 743 | 774 |
| 744 visible_ = visible; | 775 visible_ = visible; |
| 745 if (!HasGuestInstanceID()) | 776 if (!attached()) |
| 746 return; | 777 return; |
| 747 | 778 |
| 748 if (compositing_helper_.get()) | 779 if (compositing_helper_.get()) |
| 749 compositing_helper_->UpdateVisibility(visible); | 780 compositing_helper_->UpdateVisibility(visible); |
| 750 | 781 |
| 751 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( | 782 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( |
| 752 render_view_routing_id_, | 783 render_view_routing_id_, |
| 753 guest_instance_id_, | 784 guest_instance_id_, |
| 754 visible)); | 785 visible)); |
| 755 } | 786 } |
| 756 | 787 |
| 757 bool BrowserPlugin::acceptsInputEvents() { | 788 bool BrowserPlugin::acceptsInputEvents() { |
| 758 return true; | 789 return true; |
| 759 } | 790 } |
| 760 | 791 |
| 761 bool BrowserPlugin::handleInputEvent(const blink::WebInputEvent& event, | 792 bool BrowserPlugin::handleInputEvent(const blink::WebInputEvent& event, |
| 762 blink::WebCursorInfo& cursor_info) { | 793 blink::WebCursorInfo& cursor_info) { |
| 763 if (guest_crashed_ || !HasGuestInstanceID()) | 794 if (guest_crashed_ || !attached()) |
| 764 return false; | 795 return false; |
| 765 | 796 |
| 766 if (event.type == blink::WebInputEvent::ContextMenu) | 797 if (event.type == blink::WebInputEvent::ContextMenu) |
| 767 return true; | 798 return true; |
| 768 | 799 |
| 769 const blink::WebInputEvent* modified_event = &event; | 800 const blink::WebInputEvent* modified_event = &event; |
| 770 scoped_ptr<blink::WebTouchEvent> touch_event; | 801 scoped_ptr<blink::WebTouchEvent> touch_event; |
| 771 if (blink::WebInputEvent::isTouchEventType(event.type)) { | 802 if (blink::WebInputEvent::isTouchEventType(event.type)) { |
| 772 const blink::WebTouchEvent* orig_touch_event = | 803 const blink::WebTouchEvent* orig_touch_event = |
| 773 static_cast<const blink::WebTouchEvent*>(&event); | 804 static_cast<const blink::WebTouchEvent*>(&event); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 modified_event)); | 857 modified_event)); |
| 827 GetWebKitCursorInfo(cursor_, &cursor_info); | 858 GetWebKitCursorInfo(cursor_, &cursor_info); |
| 828 return true; | 859 return true; |
| 829 } | 860 } |
| 830 | 861 |
| 831 bool BrowserPlugin::handleDragStatusUpdate(blink::WebDragStatus drag_status, | 862 bool BrowserPlugin::handleDragStatusUpdate(blink::WebDragStatus drag_status, |
| 832 const blink::WebDragData& drag_data, | 863 const blink::WebDragData& drag_data, |
| 833 blink::WebDragOperationsMask mask, | 864 blink::WebDragOperationsMask mask, |
| 834 const blink::WebPoint& position, | 865 const blink::WebPoint& position, |
| 835 const blink::WebPoint& screen) { | 866 const blink::WebPoint& screen) { |
| 836 if (guest_crashed_ || !HasGuestInstanceID()) | 867 if (guest_crashed_ || !attached()) |
| 837 return false; | 868 return false; |
| 838 browser_plugin_manager()->Send( | 869 browser_plugin_manager()->Send( |
| 839 new BrowserPluginHostMsg_DragStatusUpdate( | 870 new BrowserPluginHostMsg_DragStatusUpdate( |
| 840 render_view_routing_id_, | 871 render_view_routing_id_, |
| 841 guest_instance_id_, | 872 guest_instance_id_, |
| 842 drag_status, | 873 drag_status, |
| 843 DropDataBuilder::Build(drag_data), | 874 DropDataBuilder::Build(drag_data), |
| 844 mask, | 875 mask, |
| 845 position)); | 876 position)); |
| 846 return true; | 877 return true; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 edit_commands_.push_back(EditCommand(name.utf8(), value.utf8())); | 923 edit_commands_.push_back(EditCommand(name.utf8(), value.utf8())); |
| 893 // BrowserPlugin swallows edit commands. | 924 // BrowserPlugin swallows edit commands. |
| 894 return true; | 925 return true; |
| 895 } | 926 } |
| 896 | 927 |
| 897 bool BrowserPlugin::setComposition( | 928 bool BrowserPlugin::setComposition( |
| 898 const blink::WebString& text, | 929 const blink::WebString& text, |
| 899 const blink::WebVector<blink::WebCompositionUnderline>& underlines, | 930 const blink::WebVector<blink::WebCompositionUnderline>& underlines, |
| 900 int selectionStart, | 931 int selectionStart, |
| 901 int selectionEnd) { | 932 int selectionEnd) { |
| 902 if (!HasGuestInstanceID()) | 933 if (!attached()) |
| 903 return false; | 934 return false; |
| 904 std::vector<blink::WebCompositionUnderline> std_underlines; | 935 std::vector<blink::WebCompositionUnderline> std_underlines; |
| 905 for (size_t i = 0; i < underlines.size(); ++i) { | 936 for (size_t i = 0; i < underlines.size(); ++i) { |
| 906 std_underlines.push_back(underlines[i]); | 937 std_underlines.push_back(underlines[i]); |
| 907 } | 938 } |
| 908 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeSetComposition( | 939 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeSetComposition( |
| 909 render_view_routing_id_, | 940 render_view_routing_id_, |
| 910 guest_instance_id_, | 941 guest_instance_id_, |
| 911 text.utf8(), | 942 text.utf8(), |
| 912 std_underlines, | 943 std_underlines, |
| 913 selectionStart, | 944 selectionStart, |
| 914 selectionEnd)); | 945 selectionEnd)); |
| 915 // TODO(kochi): This assumes the IPC handling always succeeds. | 946 // TODO(kochi): This assumes the IPC handling always succeeds. |
| 916 return true; | 947 return true; |
| 917 } | 948 } |
| 918 | 949 |
| 919 bool BrowserPlugin::confirmComposition( | 950 bool BrowserPlugin::confirmComposition( |
| 920 const blink::WebString& text, | 951 const blink::WebString& text, |
| 921 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior) { | 952 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior) { |
| 922 if (!HasGuestInstanceID()) | 953 if (!attached()) |
| 923 return false; | 954 return false; |
| 924 bool keep_selection = (selectionBehavior == blink::WebWidget::KeepSelection); | 955 bool keep_selection = (selectionBehavior == blink::WebWidget::KeepSelection); |
| 925 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeConfirmComposition( | 956 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeConfirmComposition( |
| 926 render_view_routing_id_, | 957 render_view_routing_id_, |
| 927 guest_instance_id_, | 958 guest_instance_id_, |
| 928 text.utf8(), | 959 text.utf8(), |
| 929 keep_selection)); | 960 keep_selection)); |
| 930 // TODO(kochi): This assumes the IPC handling always succeeds. | 961 // TODO(kochi): This assumes the IPC handling always succeeds. |
| 931 return true; | 962 return true; |
| 932 } | 963 } |
| 933 | 964 |
| 934 void BrowserPlugin::extendSelectionAndDelete(int before, int after) { | 965 void BrowserPlugin::extendSelectionAndDelete(int before, int after) { |
| 935 if (!HasGuestInstanceID()) | 966 if (!attached()) |
| 936 return; | 967 return; |
| 937 browser_plugin_manager()->Send( | 968 browser_plugin_manager()->Send( |
| 938 new BrowserPluginHostMsg_ExtendSelectionAndDelete( | 969 new BrowserPluginHostMsg_ExtendSelectionAndDelete( |
| 939 render_view_routing_id_, | 970 render_view_routing_id_, |
| 940 guest_instance_id_, | 971 guest_instance_id_, |
| 941 before, | 972 before, |
| 942 after)); | 973 after)); |
| 943 } | 974 } |
| 944 | 975 |
| 945 void BrowserPlugin::OnLockMouseACK(bool succeeded) { | 976 void BrowserPlugin::OnLockMouseACK(bool succeeded) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 961 const blink::WebMouseEvent& event) { | 992 const blink::WebMouseEvent& event) { |
| 962 browser_plugin_manager()->Send( | 993 browser_plugin_manager()->Send( |
| 963 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 994 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 964 guest_instance_id_, | 995 guest_instance_id_, |
| 965 plugin_rect_, | 996 plugin_rect_, |
| 966 &event)); | 997 &event)); |
| 967 return true; | 998 return true; |
| 968 } | 999 } |
| 969 | 1000 |
| 970 } // namespace content | 1001 } // namespace content |
| OLD | NEW |