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/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
17 #include "content/browser/renderer_host/render_widget_host_impl.h" | 18 #include "content/browser/renderer_host/render_widget_host_impl.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/browser/web_contents/web_contents_view_guest.h" | 20 #include "content/browser/web_contents/web_contents_view_guest.h" |
20 #include "content/common/browser_plugin/browser_plugin_constants.h" | 21 #include "content/common/browser_plugin/browser_plugin_constants.h" |
21 #include "content/common/browser_plugin/browser_plugin_messages.h" | 22 #include "content/common/browser_plugin/browser_plugin_messages.h" |
22 #include "content/common/content_constants_internal.h" | 23 #include "content/common/content_constants_internal.h" |
23 #include "content/common/drag_messages.h" | 24 #include "content/common/drag_messages.h" |
24 #include "content/common/gpu/gpu_messages.h" | 25 #include "content/common/gpu/gpu_messages.h" |
25 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
26 #include "content/port/browser/render_view_host_delegate_view.h" | 27 #include "content/port/browser/render_view_host_delegate_view.h" |
27 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
28 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
29 #include "content/public/browser/geolocation_permission_context.h" | 30 #include "content/public/browser/geolocation_permission_context.h" |
30 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
34 #include "content/public/browser/resource_request_details.h" | 35 #include "content/public/browser/resource_request_details.h" |
35 #include "content/public/browser/user_metrics.h" | 36 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents_view.h" | 37 #include "content/public/browser/web_contents_view.h" |
38 #include "content/public/common/content_switches.h" | |
37 #include "content/public/common/media_stream_request.h" | 39 #include "content/public/common/media_stream_request.h" |
38 #include "content/public/common/result_codes.h" | 40 #include "content/public/common/result_codes.h" |
39 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
41 #include "ui/surface/transport_dib.h" | 43 #include "ui/surface/transport_dib.h" |
42 #include "webkit/glue/resource_type.h" | 44 #include "webkit/glue/resource_type.h" |
43 #include "webkit/glue/webdropdata.h" | 45 #include "webkit/glue/webdropdata.h" |
44 | 46 |
45 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
46 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 48 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 | 480 |
479 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 481 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
480 if (!attached()) { | 482 if (!attached()) { |
481 delete msg; | 483 delete msg; |
482 return; | 484 return; |
483 } | 485 } |
484 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); | 486 msg->set_routing_id(embedder_web_contents_->GetRoutingID()); |
485 embedder_web_contents_->Send(msg); | 487 embedder_web_contents_->Send(msg); |
486 } | 488 } |
487 | 489 |
490 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, | |
491 int screen_x, int screen_y, WebKit::WebDragOperation operation) { | |
492 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, | |
493 screen_x, screen_y, operation); | |
494 } | |
495 | |
496 void BrowserPluginGuest::DragSourceMovedTo(int client_x, int client_y, | |
497 int screen_x, int screen_y) { | |
498 web_contents()->GetRenderViewHost()->DragSourceMovedTo(client_x, client_y, | |
499 screen_x, screen_y); | |
500 } | |
501 | |
502 void BrowserPluginGuest::EndSystemDrag() { | |
503 web_contents()->GetRenderViewHost()->DragSourceSystemDragEnded(); | |
Fady Samuel
2013/04/09 20:49:12
This ought to fix the sticky selection problem:
v
mthiesse
2013/04/18 18:02:03
Done. Thanks.
| |
504 } | |
505 | |
488 void BrowserPluginGuest::LoadRedirect( | 506 void BrowserPluginGuest::LoadRedirect( |
489 const GURL& old_url, | 507 const GURL& old_url, |
490 const GURL& new_url, | 508 const GURL& new_url, |
491 bool is_top_level) { | 509 bool is_top_level) { |
492 SendMessageToEmbedder( | 510 SendMessageToEmbedder( |
493 new BrowserPluginMsg_LoadRedirect(instance_id(), | 511 new BrowserPluginMsg_LoadRedirect(instance_id(), |
494 old_url, | 512 old_url, |
495 new_url, | 513 new_url, |
496 is_top_level)); | 514 is_top_level)); |
497 } | 515 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 params.current_entry_index = | 568 params.current_entry_index = |
551 GetWebContents()->GetController().GetCurrentEntryIndex(); | 569 GetWebContents()->GetController().GetCurrentEntryIndex(); |
552 params.entry_count = | 570 params.entry_count = |
553 GetWebContents()->GetController().GetEntryCount(); | 571 GetWebContents()->GetController().GetEntryCount(); |
554 SendMessageToEmbedder( | 572 SendMessageToEmbedder( |
555 new BrowserPluginMsg_LoadCommit(instance_id(), params)); | 573 new BrowserPluginMsg_LoadCommit(instance_id(), params)); |
556 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 574 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
557 } | 575 } |
558 | 576 |
559 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 577 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
560 // Initiating a drag from inside a guest is currently not supported. So inject | 578 bool disable_dragdrop = true; |
561 // some JS to disable it. http://crbug.com/161112 | 579 #if (defined(OS_LINUX)) |
562 const char script[] = "window.addEventListener('dragstart', function() { " | 580 if (CommandLine::ForCurrentProcess()->HasSwitch( |
563 " window.event.preventDefault(); " | 581 switches::kEnableBrowserPluginDragDrop)) |
564 "});"; | 582 disable_dragdrop = false; |
565 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 583 #endif // (defined(OS_LINUX)) |
566 ASCIIToUTF16(script)); | 584 if (disable_dragdrop) { |
585 // Initiating a drag from inside a guest is currently not supported without | |
586 // the kEnableBrowserPluginGuestViews flag. So inject some JS to disable | |
Fady Samuel
2013/04/09 20:49:12
Stale comment.
mthiesse
2013/04/18 18:02:03
Done.
| |
587 // it. http://crbug.com/161112 | |
588 const char script[] = "window.addEventListener('dragstart', function() { " | |
589 " window.event.preventDefault(); " | |
590 "});"; | |
591 render_view_host->ExecuteJavascriptInWebFrame(string16(), | |
592 ASCIIToUTF16(script)); | |
593 } | |
567 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); | 594 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); |
568 } | 595 } |
569 | 596 |
570 void BrowserPluginGuest::RenderViewReady() { | 597 void BrowserPluginGuest::RenderViewReady() { |
571 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 598 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
572 // here (see http://crbug.com/158151). | 599 // here (see http://crbug.com/158151). |
573 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 600 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
574 UpdateVisibility(); | 601 UpdateVisibility(); |
575 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 602 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
576 if (auto_size_enabled_) | 603 if (auto_size_enabled_) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 681 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
655 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 682 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
656 #if defined(OS_MACOSX) | 683 #if defined(OS_MACOSX) |
657 // MacOSX creates and populates platform-specific select drop-down menus | 684 // MacOSX creates and populates platform-specific select drop-down menus |
658 // whereas other platforms merely create a popup window that the guest | 685 // whereas other platforms merely create a popup window that the guest |
659 // renderer process paints inside. | 686 // renderer process paints inside. |
660 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 687 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
661 #endif | 688 #endif |
662 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView) | 689 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView) |
663 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 690 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
691 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_StartDragging, | |
692 OnStartDragging(&handled)); | |
664 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 693 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
694 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_TargetDrop_ACK, | |
695 OnTargetDrop_ACK(&handled)); | |
665 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 696 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
666 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | |
667 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 697 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
668 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 698 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
669 IPC_MESSAGE_UNHANDLED(handled = false) | 699 IPC_MESSAGE_UNHANDLED(handled = false) |
670 IPC_END_MESSAGE_MAP() | 700 IPC_END_MESSAGE_MAP() |
671 return handled; | 701 return handled; |
672 } | 702 } |
673 | 703 |
674 void BrowserPluginGuest::Attach( | 704 void BrowserPluginGuest::Attach( |
675 WebContentsImpl* embedder_web_contents, | 705 WebContentsImpl* embedder_web_contents, |
676 BrowserPluginHostMsg_CreateGuest_Params params) { | 706 BrowserPluginHostMsg_CreateGuest_Params params) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 } | 751 } |
722 | 752 |
723 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, | 753 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, |
724 WebKit::WebDragStatus drag_status, | 754 WebKit::WebDragStatus drag_status, |
725 const WebDropData& drop_data, | 755 const WebDropData& drop_data, |
726 WebKit::WebDragOperationsMask mask, | 756 WebKit::WebDragOperationsMask mask, |
727 const gfx::Point& location) { | 757 const gfx::Point& location) { |
728 RenderViewHost* host = GetWebContents()->GetRenderViewHost(); | 758 RenderViewHost* host = GetWebContents()->GetRenderViewHost(); |
729 switch (drag_status) { | 759 switch (drag_status) { |
730 case WebKit::WebDragStatusEnter: | 760 case WebKit::WebDragStatusEnter: |
761 embedder_web_contents_->GetBrowserPluginEmbedder()->DragEnteredGuest( | |
762 this); | |
731 host->DragTargetDragEnter(drop_data, location, location, mask, 0); | 763 host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
732 break; | 764 break; |
733 case WebKit::WebDragStatusOver: | 765 case WebKit::WebDragStatusOver: |
734 host->DragTargetDragOver(location, location, mask, 0); | 766 host->DragTargetDragOver(location, location, mask, 0); |
735 break; | 767 break; |
736 case WebKit::WebDragStatusLeave: | 768 case WebKit::WebDragStatusLeave: |
769 embedder_web_contents_->GetBrowserPluginEmbedder()->DragLeftGuest(this); | |
737 host->DragTargetDragLeave(); | 770 host->DragTargetDragLeave(); |
738 break; | 771 break; |
739 case WebKit::WebDragStatusDrop: | 772 case WebKit::WebDragStatusDrop: |
740 host->DragTargetDrop(location, location, 0); | 773 host->DragTargetDrop(location, location, 0); |
774 host->DragSourceSystemDragEnded(); | |
Fady Samuel
2013/04/09 20:49:12
EndSystemDrag();
mthiesse
2013/04/18 18:02:03
Done.
| |
741 break; | 775 break; |
742 case WebKit::WebDragStatusUnknown: | 776 case WebKit::WebDragStatusUnknown: |
743 NOTREACHED(); | 777 NOTREACHED(); |
744 } | 778 } |
745 } | 779 } |
746 | 780 |
747 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { | 781 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { |
748 GetWebContents()->GetController().GoToOffset(relative_index); | 782 GetWebContents()->GetController().GoToOffset(relative_index); |
749 } | 783 } |
750 | 784 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 web_contents, disposition, initial_bounds, user_gesture); | 1078 web_contents, disposition, initial_bounds, user_gesture); |
1045 } | 1079 } |
1046 | 1080 |
1047 void BrowserPluginGuest::OnShowWidget(int route_id, | 1081 void BrowserPluginGuest::OnShowWidget(int route_id, |
1048 const gfx::Rect& initial_pos) { | 1082 const gfx::Rect& initial_pos) { |
1049 gfx::Rect screen_pos(initial_pos); | 1083 gfx::Rect screen_pos(initial_pos); |
1050 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); | 1084 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); |
1051 GetWebContents()->ShowCreatedWidget(route_id, screen_pos); | 1085 GetWebContents()->ShowCreatedWidget(route_id, screen_pos); |
1052 } | 1086 } |
1053 | 1087 |
1088 void BrowserPluginGuest::OnStartDragging(bool* handled) { | |
1089 embedder_web_contents_->GetBrowserPluginEmbedder()->StartDrag(this); | |
Fady Samuel
2013/04/09 20:49:12
Why not just move this to WebContentsViewGuest::St
mthiesse
2013/04/18 18:02:03
Done.
| |
1090 // Don't mark as handled, so that the message gets routed to | |
1091 // RenderViewHostImpl::OnStartDragging, which in turn calls | |
1092 // WebContentsViewGuest::StartDragging, which starts the drag on the embedder. | |
1093 *handled = false; | |
1094 } | |
1095 | |
1054 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 1096 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
1055 SendMessageToEmbedder( | 1097 SendMessageToEmbedder( |
1056 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | 1098 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); |
1057 } | 1099 } |
1058 | 1100 |
1059 void BrowserPluginGuest::OnUpdateDragCursor( | 1101 void BrowserPluginGuest::OnTargetDrop_ACK(bool* handled) { |
1060 WebKit::WebDragOperation operation) { | 1102 EndSystemDrag(); |
1061 RenderViewHostImpl* embedder_render_view_host = | 1103 // Don't mark as handled. |
Fady Samuel
2013/04/09 20:49:12
This comment on its own is not very useful. Please
mthiesse
2013/04/18 18:02:03
Ah, meant to clean this up, was part of my experim
| |
1062 static_cast<RenderViewHostImpl*>( | 1104 *handled = false; |
1063 embedder_web_contents_->GetRenderViewHost()); | |
1064 CHECK(embedder_render_view_host); | |
1065 RenderViewHostDelegateView* view = | |
1066 embedder_render_view_host->GetDelegate()->GetDelegateView(); | |
1067 if (view) | |
1068 view->UpdateDragCursor(operation); | |
1069 } | 1105 } |
1070 | 1106 |
1071 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | 1107 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
1072 bool is_top_level, | 1108 bool is_top_level, |
1073 const std::string& name) { | 1109 const std::string& name) { |
1074 if (!is_top_level) | 1110 if (!is_top_level) |
1075 return; | 1111 return; |
1076 | 1112 |
1077 name_ = name; | 1113 name_ = name; |
1078 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); | 1114 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; | 1266 LOG(INFO) << "Guest not found. Instance ID: " << instance_id; |
1231 return; | 1267 return; |
1232 } | 1268 } |
1233 if (!should_allow) | 1269 if (!should_allow) |
1234 guest->Destroy(); | 1270 guest->Destroy(); |
1235 // If we do not destroy the guest then we allow the new window. | 1271 // If we do not destroy the guest then we allow the new window. |
1236 new_window_request_map_.erase(new_window_request_iter); | 1272 new_window_request_map_.erase(new_window_request_iter); |
1237 } | 1273 } |
1238 | 1274 |
1239 } // namespace content | 1275 } // namespace content |
OLD | NEW |