| 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/message_loop.h" | 10 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 13 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 14 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
| 14 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" | 15 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
| 15 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 16 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 16 #include "content/browser/browser_thread_impl.h" | 17 #include "content/browser/browser_thread_impl.h" |
| 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/geolocation_permission_context.h" | 32 #include "content/public/browser/geolocation_permission_context.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
| 34 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 36 #include "content/public/browser/resource_request_details.h" | 37 #include "content/public/browser/resource_request_details.h" |
| 37 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 38 #include "content/public/browser/web_contents_view.h" | 39 #include "content/public/browser/web_contents_view.h" |
| 40 #include "content/public/common/content_switches.h" |
| 39 #include "content/public/common/media_stream_request.h" | 41 #include "content/public/common/media_stream_request.h" |
| 40 #include "content/public/common/result_codes.h" | 42 #include "content/public/common/result_codes.h" |
| 41 #include "net/base/net_errors.h" | 43 #include "net/base/net_errors.h" |
| 42 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
| 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 44 #include "ui/surface/transport_dib.h" | 46 #include "ui/surface/transport_dib.h" |
| 45 #include "webkit/glue/resource_type.h" | 47 #include "webkit/glue/resource_type.h" |
| 46 #include "webkit/glue/webdropdata.h" | 48 #include "webkit/glue/webdropdata.h" |
| 47 | 49 |
| 48 #if defined(OS_MACOSX) | 50 #if defined(OS_MACOSX) |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 519 |
| 518 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 520 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 519 if (!attached()) { | 521 if (!attached()) { |
| 520 delete msg; | 522 delete msg; |
| 521 return; | 523 return; |
| 522 } | 524 } |
| 523 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); | 525 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); |
| 524 embedder_web_contents_->Send(msg); | 526 embedder_web_contents_->Send(msg); |
| 525 } | 527 } |
| 526 | 528 |
| 529 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |
| 530 int screen_x, int screen_y, WebKit::WebDragOperation operation) { |
| 531 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
| 532 screen_x, screen_y, operation); |
| 533 } |
| 534 |
| 535 void BrowserPluginGuest::DragSourceMovedTo(int client_x, int client_y, |
| 536 int screen_x, int screen_y) { |
| 537 web_contents()->GetRenderViewHost()->DragSourceMovedTo(client_x, client_y, |
| 538 screen_x, screen_y); |
| 539 } |
| 540 |
| 541 void BrowserPluginGuest::EndSystemDrag() { |
| 542 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 543 GetWebContents()->GetRenderViewHost()); |
| 544 guest_rvh->DragSourceSystemDragEnded(); |
| 545 // Issue a MouseUp event to get out of a selection state. |
| 546 WebKit::WebMouseEvent mouse_event; |
| 547 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 548 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 549 guest_rvh->ForwardMouseEvent(mouse_event); |
| 550 } |
| 551 |
| 527 void BrowserPluginGuest::LoadRedirect( | 552 void BrowserPluginGuest::LoadRedirect( |
| 528 const GURL& old_url, | 553 const GURL& old_url, |
| 529 const GURL& new_url, | 554 const GURL& new_url, |
| 530 bool is_top_level) { | 555 bool is_top_level) { |
| 531 SendMessageToEmbedder( | 556 SendMessageToEmbedder( |
| 532 new BrowserPluginMsg_LoadRedirect(instance_id(), | 557 new BrowserPluginMsg_LoadRedirect(instance_id(), |
| 533 old_url, | 558 old_url, |
| 534 new_url, | 559 new_url, |
| 535 is_top_level)); | 560 is_top_level)); |
| 536 } | 561 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 params.current_entry_index = | 624 params.current_entry_index = |
| 600 GetWebContents()->GetController().GetCurrentEntryIndex(); | 625 GetWebContents()->GetController().GetCurrentEntryIndex(); |
| 601 params.entry_count = | 626 params.entry_count = |
| 602 GetWebContents()->GetController().GetEntryCount(); | 627 GetWebContents()->GetController().GetEntryCount(); |
| 603 SendMessageToEmbedder( | 628 SendMessageToEmbedder( |
| 604 new BrowserPluginMsg_LoadCommit(instance_id(), params)); | 629 new BrowserPluginMsg_LoadCommit(instance_id(), params)); |
| 605 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 630 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
| 606 } | 631 } |
| 607 | 632 |
| 608 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 633 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 609 // Initiating a drag from inside a guest is currently not supported. So inject | 634 bool disable_dragdrop = true; |
| 610 // some JS to disable it. http://crbug.com/161112 | 635 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 611 const char script[] = "window.addEventListener('dragstart', function() { " | 636 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 612 " window.event.preventDefault(); " | 637 switches::kEnableBrowserPluginDragDrop)) |
| 613 "});"; | 638 disable_dragdrop = false; |
| 614 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 639 #endif // defined(OS_LINUX) || defined(OS_MACOSX) |
| 615 ASCIIToUTF16(script)); | 640 if (disable_dragdrop) { |
| 641 // Initiating a drag from inside a guest is currently not supported without |
| 642 // the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some |
| 643 // JS to disable it. http://crbug.com/161112 |
| 644 const char script[] = "window.addEventListener('dragstart', function() { " |
| 645 " window.event.preventDefault(); " |
| 646 "});"; |
| 647 render_view_host->ExecuteJavascriptInWebFrame(string16(), |
| 648 ASCIIToUTF16(script)); |
| 649 } |
| 616 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); | 650 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); |
| 617 } | 651 } |
| 618 | 652 |
| 619 void BrowserPluginGuest::RenderViewReady() { | 653 void BrowserPluginGuest::RenderViewReady() { |
| 620 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 654 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 621 // here (see http://crbug.com/158151). | 655 // here (see http://crbug.com/158151). |
| 622 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 656 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
| 623 UpdateVisibility(); | 657 UpdateVisibility(); |
| 624 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 658 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
| 625 if (auto_size_enabled_) | 659 if (auto_size_enabled_) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 739 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
| 706 #if defined(OS_MACOSX) | 740 #if defined(OS_MACOSX) |
| 707 // MacOSX creates and populates platform-specific select drop-down menus | 741 // MacOSX creates and populates platform-specific select drop-down menus |
| 708 // whereas other platforms merely create a popup window that the guest | 742 // whereas other platforms merely create a popup window that the guest |
| 709 // renderer process paints inside. | 743 // renderer process paints inside. |
| 710 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 744 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
| 711 #endif | 745 #endif |
| 712 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 746 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 713 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 747 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
| 714 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 748 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
| 715 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | |
| 716 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 749 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 717 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 750 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 718 IPC_MESSAGE_UNHANDLED(handled = false) | 751 IPC_MESSAGE_UNHANDLED(handled = false) |
| 719 IPC_END_MESSAGE_MAP() | 752 IPC_END_MESSAGE_MAP() |
| 720 return handled; | 753 return handled; |
| 721 } | 754 } |
| 722 | 755 |
| 723 void BrowserPluginGuest::Attach( | 756 void BrowserPluginGuest::Attach( |
| 724 WebContentsImpl* embedder_web_contents, | 757 WebContentsImpl* embedder_web_contents, |
| 725 BrowserPluginHostMsg_CreateGuest_Params params) { | 758 BrowserPluginHostMsg_CreateGuest_Params params) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 812 } |
| 780 | 813 |
| 781 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, | 814 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, |
| 782 WebKit::WebDragStatus drag_status, | 815 WebKit::WebDragStatus drag_status, |
| 783 const WebDropData& drop_data, | 816 const WebDropData& drop_data, |
| 784 WebKit::WebDragOperationsMask mask, | 817 WebKit::WebDragOperationsMask mask, |
| 785 const gfx::Point& location) { | 818 const gfx::Point& location) { |
| 786 RenderViewHost* host = GetWebContents()->GetRenderViewHost(); | 819 RenderViewHost* host = GetWebContents()->GetRenderViewHost(); |
| 787 switch (drag_status) { | 820 switch (drag_status) { |
| 788 case WebKit::WebDragStatusEnter: | 821 case WebKit::WebDragStatusEnter: |
| 822 embedder_web_contents_->GetBrowserPluginEmbedder()->DragEnteredGuest( |
| 823 this); |
| 789 host->DragTargetDragEnter(drop_data, location, location, mask, 0); | 824 host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
| 790 break; | 825 break; |
| 791 case WebKit::WebDragStatusOver: | 826 case WebKit::WebDragStatusOver: |
| 792 host->DragTargetDragOver(location, location, mask, 0); | 827 host->DragTargetDragOver(location, location, mask, 0); |
| 793 break; | 828 break; |
| 794 case WebKit::WebDragStatusLeave: | 829 case WebKit::WebDragStatusLeave: |
| 830 embedder_web_contents_->GetBrowserPluginEmbedder()->DragLeftGuest(this); |
| 795 host->DragTargetDragLeave(); | 831 host->DragTargetDragLeave(); |
| 796 break; | 832 break; |
| 797 case WebKit::WebDragStatusDrop: | 833 case WebKit::WebDragStatusDrop: |
| 798 host->DragTargetDrop(location, location, 0); | 834 host->DragTargetDrop(location, location, 0); |
| 835 EndSystemDrag(); |
| 799 break; | 836 break; |
| 800 case WebKit::WebDragStatusUnknown: | 837 case WebKit::WebDragStatusUnknown: |
| 801 NOTREACHED(); | 838 NOTREACHED(); |
| 802 } | 839 } |
| 803 } | 840 } |
| 804 | 841 |
| 805 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { | 842 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { |
| 806 GetWebContents()->GetController().GoToOffset(relative_index); | 843 GetWebContents()->GetController().GoToOffset(relative_index); |
| 807 } | 844 } |
| 808 | 845 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 gfx::Rect screen_pos(initial_pos); | 1141 gfx::Rect screen_pos(initial_pos); |
| 1105 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); | 1142 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); |
| 1106 GetWebContents()->ShowCreatedWidget(route_id, screen_pos); | 1143 GetWebContents()->ShowCreatedWidget(route_id, screen_pos); |
| 1107 } | 1144 } |
| 1108 | 1145 |
| 1109 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 1146 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
| 1110 SendMessageToEmbedder( | 1147 SendMessageToEmbedder( |
| 1111 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | 1148 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); |
| 1112 } | 1149 } |
| 1113 | 1150 |
| 1114 void BrowserPluginGuest::OnUpdateDragCursor( | |
| 1115 WebKit::WebDragOperation operation) { | |
| 1116 RenderViewHostImpl* embedder_render_view_host = | |
| 1117 static_cast<RenderViewHostImpl*>( | |
| 1118 embedder_web_contents_->GetRenderViewHost()); | |
| 1119 CHECK(embedder_render_view_host); | |
| 1120 RenderViewHostDelegateView* view = | |
| 1121 embedder_render_view_host->GetDelegate()->GetDelegateView(); | |
| 1122 if (view) | |
| 1123 view->UpdateDragCursor(operation); | |
| 1124 } | |
| 1125 | |
| 1126 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | 1151 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| 1127 bool is_top_level, | 1152 bool is_top_level, |
| 1128 const std::string& name) { | 1153 const std::string& name) { |
| 1129 if (!is_top_level) | 1154 if (!is_top_level) |
| 1130 return; | 1155 return; |
| 1131 | 1156 |
| 1132 name_ = name; | 1157 name_ = name; |
| 1133 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); | 1158 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); |
| 1134 } | 1159 } |
| 1135 | 1160 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 base::Value::CreateStringValue(request_method)); | 1345 base::Value::CreateStringValue(request_method)); |
| 1321 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1346 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1322 | 1347 |
| 1323 SendMessageToEmbedder( | 1348 SendMessageToEmbedder( |
| 1324 new BrowserPluginMsg_RequestPermission(instance_id(), | 1349 new BrowserPluginMsg_RequestPermission(instance_id(), |
| 1325 BrowserPluginPermissionTypeDownload, permission_request_id, | 1350 BrowserPluginPermissionTypeDownload, permission_request_id, |
| 1326 request_info)); | 1351 request_info)); |
| 1327 } | 1352 } |
| 1328 | 1353 |
| 1329 } // namespace content | 1354 } // namespace content |
| OLD | NEW |