| 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/command_line.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 16 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
| 17 #include "content/common/browser_plugin_messages.h" | 18 #include "content/common/browser_plugin_messages.h" |
| 18 #include "content/common/content_constants_internal.h" | 19 #include "content/common/content_constants_internal.h" |
| 19 #include "content/common/drag_messages.h" | 20 #include "content/common/drag_messages.h" |
| 20 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| 21 #include "content/port/browser/render_view_host_delegate_view.h" | 22 #include "content/port/browser/render_view_host_delegate_view.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 23 #include "content/public/browser/content_browser_client.h" |
| 23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/browser/resource_request_details.h" | 28 #include "content/public/browser/resource_request_details.h" |
| 28 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 29 #include "content/public/browser/web_contents_view.h" | 30 #include "content/public/browser/web_contents_view.h" |
| 31 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/common/result_codes.h" | 32 #include "content/public/common/result_codes.h" |
| 31 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 33 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 32 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 34 #include "ui/surface/transport_dib.h" | 36 #include "ui/surface/transport_dib.h" |
| 35 #include "webkit/glue/resource_type.h" | 37 #include "webkit/glue/resource_type.h" |
| 36 #include "webkit/glue/webdropdata.h" | 38 #include "webkit/glue/webdropdata.h" |
| 37 | 39 |
| 38 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
| 39 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 41 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 : WebContentsObserver(web_contents), | 53 : WebContentsObserver(web_contents), |
| 52 embedder_web_contents_(NULL), | 54 embedder_web_contents_(NULL), |
| 53 instance_id_(instance_id), | 55 instance_id_(instance_id), |
| 54 damage_buffer_sequence_id_(0), | 56 damage_buffer_sequence_id_(0), |
| 55 damage_buffer_size_(0), | 57 damage_buffer_size_(0), |
| 56 damage_buffer_scale_factor_(1.0f), | 58 damage_buffer_scale_factor_(1.0f), |
| 57 guest_hang_timeout_( | 59 guest_hang_timeout_( |
| 58 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 60 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 59 focused_(params.focused), | 61 focused_(params.focused), |
| 60 visible_(params.visible), | 62 visible_(params.visible), |
| 63 dragging_(false), |
| 64 drag_over_(false), |
| 61 name_(params.name), | 65 name_(params.name), |
| 62 auto_size_enabled_(params.auto_size_params.enable), | 66 auto_size_enabled_(params.auto_size_params.enable), |
| 63 max_auto_size_(params.auto_size_params.max_size), | 67 max_auto_size_(params.auto_size_params.max_size), |
| 64 min_auto_size_(params.auto_size_params.min_size) { | 68 min_auto_size_(params.auto_size_params.min_size) { |
| 65 DCHECK(web_contents); | 69 DCHECK(web_contents); |
| 66 } | 70 } |
| 67 | 71 |
| 68 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 72 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 69 const IPC::Message& message) { | 73 const IPC::Message& message) { |
| 70 bool handled = true; | 74 bool handled = true; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 params.entry_count = | 318 params.entry_count = |
| 315 web_contents()->GetController().GetEntryCount(); | 319 web_contents()->GetController().GetEntryCount(); |
| 316 SendMessageToEmbedder( | 320 SendMessageToEmbedder( |
| 317 new BrowserPluginMsg_LoadCommit(embedder_routing_id(), | 321 new BrowserPluginMsg_LoadCommit(embedder_routing_id(), |
| 318 instance_id(), | 322 instance_id(), |
| 319 params)); | 323 params)); |
| 320 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 324 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
| 321 } | 325 } |
| 322 | 326 |
| 323 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 327 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 324 // Initiating a drag from inside a guest is currently not supported. So inject | 328 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 325 // some JS to disable it. http://crbug.com/161112 | 329 switches::kEnableBrowserPluginCompositing)) { |
| 326 const char script[] = "window.addEventListener('dragstart', function() { " | 330 // Initiating a drag from inside a guest is currently not supported without |
| 327 " window.event.preventDefault(); " | 331 // the kEnableBrowserPluginCompositing flag. So inject some JS to disable |
| 328 "});"; | 332 // it. http://crbug.com/161112 |
| 329 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 333 const char script[] = "window.addEventListener('dragstart', function() { " |
| 330 ASCIIToUTF16(script)); | 334 " window.event.preventDefault(); " |
| 335 "});"; |
| 336 render_view_host->ExecuteJavascriptInWebFrame(string16(), |
| 337 ASCIIToUTF16(script)); |
| 338 } |
| 331 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), | 339 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), |
| 332 instance_id())); | 340 instance_id())); |
| 333 } | 341 } |
| 334 | 342 |
| 335 void BrowserPluginGuest::RenderViewReady() { | 343 void BrowserPluginGuest::RenderViewReady() { |
| 336 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 344 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 337 // here (see http://crbug.com/158151). | 345 // here (see http://crbug.com/158151). |
| 338 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 346 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
| 339 UpdateVisibility(); | 347 UpdateVisibility(); |
| 340 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 348 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 364 break; | 372 break; |
| 365 default: | 373 default: |
| 366 break; | 374 break; |
| 367 } | 375 } |
| 368 } | 376 } |
| 369 | 377 |
| 370 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 378 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
| 371 bool handled = true; | 379 bool handled = true; |
| 372 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 380 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 373 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnCreateWindow) | 381 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnCreateWindow) |
| 382 IPC_MESSAGE_HANDLER(DragHostMsg_DragStopped, OnDragStopped) |
| 374 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck) | 383 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck) |
| 375 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 384 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
| 376 OnHasTouchEventHandlers) | 385 OnHasTouchEventHandlers) |
| 377 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 386 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
| 378 #if defined(OS_MACOSX) | 387 #if defined(OS_MACOSX) |
| 379 // MacOSX creates and populates platform-specific select drop-down menus | 388 // MacOSX creates and populates platform-specific select drop-down menus |
| 380 // whereas other platforms merely create a popup window that the guest | 389 // whereas other platforms merely create a popup window that the guest |
| 381 // renderer process paints inside. | 390 // renderer process paints inside. |
| 382 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 391 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
| 383 #endif | 392 #endif |
| 384 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 393 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 394 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_StartDragging, |
| 395 OnStartDragging(&handled)); |
| 385 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 396 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
| 386 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | |
| 387 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 397 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 388 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 398 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 389 IPC_MESSAGE_UNHANDLED(handled = false) | 399 IPC_MESSAGE_UNHANDLED(handled = false) |
| 390 IPC_END_MESSAGE_MAP() | 400 IPC_END_MESSAGE_MAP() |
| 391 return handled; | 401 return handled; |
| 392 } | 402 } |
| 393 | 403 |
| 394 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, | 404 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, |
| 395 WebKit::WebDragStatus drag_status, | 405 WebKit::WebDragStatus drag_status, |
| 396 const WebDropData& drop_data, | 406 const WebDropData& drop_data, |
| 397 WebKit::WebDragOperationsMask mask, | 407 WebKit::WebDragOperationsMask mask, |
| 398 const gfx::Point& location) { | 408 const gfx::Point& location) { |
| 399 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 409 RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| 400 switch (drag_status) { | 410 switch (drag_status) { |
| 401 case WebKit::WebDragStatusEnter: | 411 case WebKit::WebDragStatusEnter: |
| 412 drag_over_ = true; |
| 402 host->DragTargetDragEnter(drop_data, location, location, mask, 0); | 413 host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
| 403 break; | 414 break; |
| 404 case WebKit::WebDragStatusOver: | 415 case WebKit::WebDragStatusOver: |
| 405 host->DragTargetDragOver(location, location, mask, 0); | 416 host->DragTargetDragOver(location, location, mask, 0); |
| 406 break; | 417 break; |
| 407 case WebKit::WebDragStatusLeave: | 418 case WebKit::WebDragStatusLeave: |
| 419 drag_over_ = false; |
| 408 host->DragTargetDragLeave(); | 420 host->DragTargetDragLeave(); |
| 409 break; | 421 break; |
| 410 case WebKit::WebDragStatusDrop: | 422 case WebKit::WebDragStatusDrop: |
| 411 host->DragTargetDrop(location, location, 0); | 423 host->DragTargetDrop(location, location, 0); |
| 412 break; | 424 break; |
| 413 case WebKit::WebDragStatusUnknown: | 425 case WebKit::WebDragStatusUnknown: |
| 414 NOTREACHED(); | 426 NOTREACHED(); |
| 415 } | 427 } |
| 416 } | 428 } |
| 417 | 429 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 int* route_id, | 593 int* route_id, |
| 582 int* surface_id, | 594 int* surface_id, |
| 583 int64* cloned_session_storage_namespace_id) { | 595 int64* cloned_session_storage_namespace_id) { |
| 584 // TODO(fsamuel): We do not currently support window.open. | 596 // TODO(fsamuel): We do not currently support window.open. |
| 585 // See http://crbug.com/140316. | 597 // See http://crbug.com/140316. |
| 586 *route_id = MSG_ROUTING_NONE; | 598 *route_id = MSG_ROUTING_NONE; |
| 587 *surface_id = 0; | 599 *surface_id = 0; |
| 588 *cloned_session_storage_namespace_id = 0l; | 600 *cloned_session_storage_namespace_id = 0l; |
| 589 } | 601 } |
| 590 | 602 |
| 603 void BrowserPluginGuest::OnDragStopped() { |
| 604 if (dragging_) { |
| 605 web_contents()->GetRenderViewHost()->DragSourceSystemDragEnded(); |
| 606 dragging_ = false; |
| 607 } |
| 608 } |
| 609 |
| 591 void BrowserPluginGuest::OnHandleInputEventAck( | 610 void BrowserPluginGuest::OnHandleInputEventAck( |
| 592 WebKit::WebInputEvent::Type event_type, | 611 WebKit::WebInputEvent::Type event_type, |
| 593 InputEventAckState ack_result) { | 612 InputEventAckState ack_result) { |
| 594 RenderViewHostImpl* guest_rvh = | 613 RenderViewHostImpl* guest_rvh = |
| 595 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); | 614 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); |
| 596 guest_rvh->StopHangMonitorTimeout(); | 615 guest_rvh->StopHangMonitorTimeout(); |
| 597 } | 616 } |
| 598 | 617 |
| 599 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { | 618 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { |
| 600 SendMessageToEmbedder( | 619 SendMessageToEmbedder( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 628 #endif | 647 #endif |
| 629 | 648 |
| 630 void BrowserPluginGuest::OnShowWidget(int route_id, | 649 void BrowserPluginGuest::OnShowWidget(int route_id, |
| 631 const gfx::Rect& initial_pos) { | 650 const gfx::Rect& initial_pos) { |
| 632 gfx::Rect screen_pos(initial_pos); | 651 gfx::Rect screen_pos(initial_pos); |
| 633 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); | 652 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); |
| 634 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, | 653 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, |
| 635 screen_pos); | 654 screen_pos); |
| 636 } | 655 } |
| 637 | 656 |
| 657 void BrowserPluginGuest::OnStartDragging(bool* handled) { |
| 658 dragging_ = true; |
| 659 // Don't mark as handled, so that it gets passed up the chain and eventually |
| 660 // gets to WebContentsViewGuest::StartDragging, which starts the drag on the |
| 661 // embedder. |
| 662 *handled = false; |
| 663 } |
| 664 |
| 638 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 665 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
| 639 SendMessageToEmbedder( | 666 SendMessageToEmbedder( |
| 640 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), | 667 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), |
| 641 instance_id(), | 668 instance_id(), |
| 642 reverse)); | 669 reverse)); |
| 643 } | 670 } |
| 644 | 671 |
| 645 void BrowserPluginGuest::OnUpdateDragCursor( | |
| 646 WebKit::WebDragOperation operation) { | |
| 647 RenderViewHostImpl* embedder_render_view_host = | |
| 648 static_cast<RenderViewHostImpl*>( | |
| 649 embedder_web_contents_->GetRenderViewHost()); | |
| 650 CHECK(embedder_render_view_host); | |
| 651 RenderViewHostDelegateView* view = | |
| 652 embedder_render_view_host->GetDelegate()->GetDelegateView(); | |
| 653 if (view) | |
| 654 view->UpdateDragCursor(operation); | |
| 655 } | |
| 656 | |
| 657 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | 672 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| 658 bool is_top_level, | 673 bool is_top_level, |
| 659 const std::string& name) { | 674 const std::string& name) { |
| 660 if (!is_top_level) | 675 if (!is_top_level) |
| 661 return; | 676 return; |
| 662 | 677 |
| 663 name_ = name; | 678 name_ = name; |
| 664 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 679 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 665 embedder_routing_id(), | 680 embedder_routing_id(), |
| 666 instance_id_, | 681 instance_id_, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 relay_params.scroll_delta = params.scroll_delta; | 736 relay_params.scroll_delta = params.scroll_delta; |
| 722 relay_params.scroll_rect = params.scroll_rect; | 737 relay_params.scroll_rect = params.scroll_rect; |
| 723 relay_params.copy_rects = params.copy_rects; | 738 relay_params.copy_rects = params.copy_rects; |
| 724 | 739 |
| 725 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 740 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 726 instance_id(), | 741 instance_id(), |
| 727 relay_params)); | 742 relay_params)); |
| 728 } | 743 } |
| 729 | 744 |
| 730 } // namespace content | 745 } // namespace content |
| OLD | NEW |