| 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 11 matching lines...) Expand all Loading... |
| 30 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
| 31 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
| 32 #include "content/public/browser/geolocation_permission_context.h" | 33 #include "content/public/browser/geolocation_permission_context.h" |
| 33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 37 #include "content/public/browser/resource_request_details.h" | 38 #include "content/public/browser/resource_request_details.h" |
| 38 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
| 39 #include "content/public/browser/web_contents_view.h" | 40 #include "content/public/browser/web_contents_view.h" |
| 41 #include "content/public/common/content_switches.h" |
| 40 #include "content/public/common/media_stream_request.h" | 42 #include "content/public/common/media_stream_request.h" |
| 41 #include "content/public/common/result_codes.h" | 43 #include "content/public/common/result_codes.h" |
| 42 #include "net/base/net_errors.h" | 44 #include "net/base/net_errors.h" |
| 43 #include "net/url_request/url_request.h" | 45 #include "net/url_request/url_request.h" |
| 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 45 #include "ui/base/keycodes/keyboard_codes.h" | 47 #include "ui/base/keycodes/keyboard_codes.h" |
| 46 #include "ui/surface/transport_dib.h" | 48 #include "ui/surface/transport_dib.h" |
| 47 #include "webkit/glue/resource_type.h" | 49 #include "webkit/glue/resource_type.h" |
| 48 #include "webkit/glue/webdropdata.h" | 50 #include "webkit/glue/webdropdata.h" |
| 49 | 51 |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 602 |
| 601 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 603 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 602 if (!attached()) { | 604 if (!attached()) { |
| 603 delete msg; | 605 delete msg; |
| 604 return; | 606 return; |
| 605 } | 607 } |
| 606 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); | 608 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); |
| 607 embedder_web_contents_->Send(msg); | 609 embedder_web_contents_->Send(msg); |
| 608 } | 610 } |
| 609 | 611 |
| 612 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |
| 613 int screen_x, int screen_y, WebKit::WebDragOperation operation) { |
| 614 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
| 615 screen_x, screen_y, operation); |
| 616 } |
| 617 |
| 618 void BrowserPluginGuest::DragSourceMovedTo(int client_x, int client_y, |
| 619 int screen_x, int screen_y) { |
| 620 web_contents()->GetRenderViewHost()->DragSourceMovedTo(client_x, client_y, |
| 621 screen_x, screen_y); |
| 622 } |
| 623 |
| 624 void BrowserPluginGuest::EndSystemDrag() { |
| 625 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 626 GetWebContents()->GetRenderViewHost()); |
| 627 guest_rvh->DragSourceSystemDragEnded(); |
| 628 // Issue a MouseUp event to get out of a selection state. |
| 629 WebKit::WebMouseEvent mouse_event; |
| 630 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 631 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 632 guest_rvh->ForwardMouseEvent(mouse_event); |
| 633 } |
| 634 |
| 610 void BrowserPluginGuest::LoadRedirect( | 635 void BrowserPluginGuest::LoadRedirect( |
| 611 const GURL& old_url, | 636 const GURL& old_url, |
| 612 const GURL& new_url, | 637 const GURL& new_url, |
| 613 bool is_top_level) { | 638 bool is_top_level) { |
| 614 SendMessageToEmbedder( | 639 SendMessageToEmbedder( |
| 615 new BrowserPluginMsg_LoadRedirect(instance_id(), | 640 new BrowserPluginMsg_LoadRedirect(instance_id(), |
| 616 old_url, | 641 old_url, |
| 617 new_url, | 642 new_url, |
| 618 is_top_level)); | 643 is_top_level)); |
| 619 } | 644 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 params.current_entry_index = | 707 params.current_entry_index = |
| 683 GetWebContents()->GetController().GetCurrentEntryIndex(); | 708 GetWebContents()->GetController().GetCurrentEntryIndex(); |
| 684 params.entry_count = | 709 params.entry_count = |
| 685 GetWebContents()->GetController().GetEntryCount(); | 710 GetWebContents()->GetController().GetEntryCount(); |
| 686 SendMessageToEmbedder( | 711 SendMessageToEmbedder( |
| 687 new BrowserPluginMsg_LoadCommit(instance_id(), params)); | 712 new BrowserPluginMsg_LoadCommit(instance_id(), params)); |
| 688 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 713 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
| 689 } | 714 } |
| 690 | 715 |
| 691 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 716 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 692 // Initiating a drag from inside a guest is currently not supported. So inject | 717 bool disable_dragdrop = true; |
| 693 // some JS to disable it. http://crbug.com/161112 | 718 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 694 const char script[] = "window.addEventListener('dragstart', function() { " | 719 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 695 " window.event.preventDefault(); " | 720 switches::kEnableBrowserPluginDragDrop)) |
| 696 "});"; | 721 disable_dragdrop = false; |
| 697 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 722 #endif // defined(OS_LINUX) || defined(OS_MACOSX) |
| 698 ASCIIToUTF16(script)); | 723 if (disable_dragdrop) { |
| 724 // Initiating a drag from inside a guest is currently not supported without |
| 725 // the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some |
| 726 // JS to disable it. http://crbug.com/161112 |
| 727 const char script[] = "window.addEventListener('dragstart', function() { " |
| 728 " window.event.preventDefault(); " |
| 729 "});"; |
| 730 render_view_host->ExecuteJavascriptInWebFrame(string16(), |
| 731 ASCIIToUTF16(script)); |
| 732 } |
| 699 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); | 733 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); |
| 700 } | 734 } |
| 701 | 735 |
| 702 void BrowserPluginGuest::RenderViewReady() { | 736 void BrowserPluginGuest::RenderViewReady() { |
| 703 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 737 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 704 // here (see http://crbug.com/158151). | 738 // here (see http://crbug.com/158151). |
| 705 Send(new InputMsg_SetFocus(routing_id(), focused_)); | 739 Send(new InputMsg_SetFocus(routing_id(), focused_)); |
| 706 UpdateVisibility(); | 740 UpdateVisibility(); |
| 707 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 741 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
| 708 if (auto_size_enabled_) | 742 if (auto_size_enabled_) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 823 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
| 790 #if defined(OS_MACOSX) | 824 #if defined(OS_MACOSX) |
| 791 // MacOSX creates and populates platform-specific select drop-down menus | 825 // MacOSX creates and populates platform-specific select drop-down menus |
| 792 // whereas other platforms merely create a popup window that the guest | 826 // whereas other platforms merely create a popup window that the guest |
| 793 // renderer process paints inside. | 827 // renderer process paints inside. |
| 794 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 828 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
| 795 #endif | 829 #endif |
| 796 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 830 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 797 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 831 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
| 798 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 832 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
| 799 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | |
| 800 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 833 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 801 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 834 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 802 IPC_MESSAGE_UNHANDLED(handled = false) | 835 IPC_MESSAGE_UNHANDLED(handled = false) |
| 803 IPC_END_MESSAGE_MAP() | 836 IPC_END_MESSAGE_MAP() |
| 804 return handled; | 837 return handled; |
| 805 } | 838 } |
| 806 | 839 |
| 807 void BrowserPluginGuest::Attach( | 840 void BrowserPluginGuest::Attach( |
| 808 WebContentsImpl* embedder_web_contents, | 841 WebContentsImpl* embedder_web_contents, |
| 809 BrowserPluginHostMsg_Attach_Params params) { | 842 BrowserPluginHostMsg_Attach_Params params) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 } | 908 } |
| 876 | 909 |
| 877 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, | 910 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, |
| 878 WebKit::WebDragStatus drag_status, | 911 WebKit::WebDragStatus drag_status, |
| 879 const WebDropData& drop_data, | 912 const WebDropData& drop_data, |
| 880 WebKit::WebDragOperationsMask mask, | 913 WebKit::WebDragOperationsMask mask, |
| 881 const gfx::Point& location) { | 914 const gfx::Point& location) { |
| 882 RenderViewHost* host = GetWebContents()->GetRenderViewHost(); | 915 RenderViewHost* host = GetWebContents()->GetRenderViewHost(); |
| 883 switch (drag_status) { | 916 switch (drag_status) { |
| 884 case WebKit::WebDragStatusEnter: | 917 case WebKit::WebDragStatusEnter: |
| 918 embedder_web_contents_->GetBrowserPluginEmbedder()->DragEnteredGuest( |
| 919 this); |
| 885 host->DragTargetDragEnter(drop_data, location, location, mask, 0); | 920 host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
| 886 break; | 921 break; |
| 887 case WebKit::WebDragStatusOver: | 922 case WebKit::WebDragStatusOver: |
| 888 host->DragTargetDragOver(location, location, mask, 0); | 923 host->DragTargetDragOver(location, location, mask, 0); |
| 889 break; | 924 break; |
| 890 case WebKit::WebDragStatusLeave: | 925 case WebKit::WebDragStatusLeave: |
| 926 embedder_web_contents_->GetBrowserPluginEmbedder()->DragLeftGuest(this); |
| 891 host->DragTargetDragLeave(); | 927 host->DragTargetDragLeave(); |
| 892 break; | 928 break; |
| 893 case WebKit::WebDragStatusDrop: | 929 case WebKit::WebDragStatusDrop: |
| 894 host->DragTargetDrop(location, location, 0); | 930 host->DragTargetDrop(location, location, 0); |
| 931 EndSystemDrag(); |
| 895 break; | 932 break; |
| 896 case WebKit::WebDragStatusUnknown: | 933 case WebKit::WebDragStatusUnknown: |
| 897 NOTREACHED(); | 934 NOTREACHED(); |
| 898 } | 935 } |
| 899 } | 936 } |
| 900 | 937 |
| 901 void BrowserPluginGuest::OnExecuteEditCommand(int instance_id, | 938 void BrowserPluginGuest::OnExecuteEditCommand(int instance_id, |
| 902 const std::string& name) { | 939 const std::string& name) { |
| 903 Send(new InputMsg_ExecuteEditCommand(routing_id(), name, std::string())); | 940 Send(new InputMsg_ExecuteEditCommand(routing_id(), name, std::string())); |
| 904 } | 941 } |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 gfx::Rect screen_pos(initial_pos); | 1252 gfx::Rect screen_pos(initial_pos); |
| 1216 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); | 1253 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); |
| 1217 GetWebContents()->ShowCreatedWidget(route_id, screen_pos); | 1254 GetWebContents()->ShowCreatedWidget(route_id, screen_pos); |
| 1218 } | 1255 } |
| 1219 | 1256 |
| 1220 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 1257 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
| 1221 SendMessageToEmbedder( | 1258 SendMessageToEmbedder( |
| 1222 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | 1259 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); |
| 1223 } | 1260 } |
| 1224 | 1261 |
| 1225 void BrowserPluginGuest::OnUpdateDragCursor( | |
| 1226 WebKit::WebDragOperation operation) { | |
| 1227 RenderViewHostImpl* embedder_render_view_host = | |
| 1228 static_cast<RenderViewHostImpl*>( | |
| 1229 embedder_web_contents_->GetRenderViewHost()); | |
| 1230 CHECK(embedder_render_view_host); | |
| 1231 RenderViewHostDelegateView* view = | |
| 1232 embedder_render_view_host->GetDelegate()->GetDelegateView(); | |
| 1233 if (view) | |
| 1234 view->UpdateDragCursor(operation); | |
| 1235 } | |
| 1236 | |
| 1237 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | 1262 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| 1238 bool is_top_level, | 1263 bool is_top_level, |
| 1239 const std::string& name) { | 1264 const std::string& name) { |
| 1240 if (!is_top_level) | 1265 if (!is_top_level) |
| 1241 return; | 1266 return; |
| 1242 | 1267 |
| 1243 name_ = name; | 1268 name_ = name; |
| 1244 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); | 1269 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); |
| 1245 } | 1270 } |
| 1246 | 1271 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 base::Value::CreateStringValue(request_method)); | 1456 base::Value::CreateStringValue(request_method)); |
| 1432 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1457 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1433 | 1458 |
| 1434 SendMessageToEmbedder( | 1459 SendMessageToEmbedder( |
| 1435 new BrowserPluginMsg_RequestPermission(instance_id(), | 1460 new BrowserPluginMsg_RequestPermission(instance_id(), |
| 1436 BrowserPluginPermissionTypeDownload, permission_request_id, | 1461 BrowserPluginPermissionTypeDownload, permission_request_id, |
| 1437 request_info)); | 1462 request_info)); |
| 1438 } | 1463 } |
| 1439 | 1464 |
| 1440 } // namespace content | 1465 } // namespace content |
| OLD | NEW |