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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 params.entry_count = | 316 params.entry_count = |
315 web_contents()->GetController().GetEntryCount(); | 317 web_contents()->GetController().GetEntryCount(); |
316 SendMessageToEmbedder( | 318 SendMessageToEmbedder( |
317 new BrowserPluginMsg_LoadCommit(embedder_routing_id(), | 319 new BrowserPluginMsg_LoadCommit(embedder_routing_id(), |
318 instance_id(), | 320 instance_id(), |
319 params)); | 321 params)); |
320 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 322 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
321 } | 323 } |
322 | 324 |
323 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 325 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
324 // Initiating a drag from inside a guest is currently not supported. So inject | 326 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
325 // some JS to disable it. http://crbug.com/161112 | 327 switches::kEnableBrowserPluginCompositing)) { |
Fady Samuel
2013/02/07 15:37:18
kEnableBrowserPluginGuestViews. This doesn't need
mthiesse
2013/02/07 15:54:05
Done.
| |
326 const char script[] = "window.addEventListener('dragstart', function() { " | 328 // Initiating a drag from inside a guest is currently not supported without |
327 " window.event.preventDefault(); " | 329 // the kEnableBrowserPluginCompositing flag. So inject some JS to disable |
328 "});"; | 330 // it. http://crbug.com/161112 |
329 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 331 const char script[] = "window.addEventListener('dragstart', function() { " |
330 ASCIIToUTF16(script)); | 332 " window.event.preventDefault(); " |
333 "});"; | |
334 render_view_host->ExecuteJavascriptInWebFrame(string16(), | |
335 ASCIIToUTF16(script)); | |
336 } | |
331 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), | 337 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), |
332 instance_id())); | 338 instance_id())); |
333 } | 339 } |
334 | 340 |
335 void BrowserPluginGuest::RenderViewReady() { | 341 void BrowserPluginGuest::RenderViewReady() { |
336 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 342 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
337 // here (see http://crbug.com/158151). | 343 // here (see http://crbug.com/158151). |
338 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 344 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
339 UpdateVisibility(); | 345 UpdateVisibility(); |
340 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 346 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
(...skipping 23 matching lines...) Expand all Loading... | |
364 break; | 370 break; |
365 default: | 371 default: |
366 break; | 372 break; |
367 } | 373 } |
368 } | 374 } |
369 | 375 |
370 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 376 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
371 bool handled = true; | 377 bool handled = true; |
372 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 378 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
373 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnCreateWindow) | 379 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnCreateWindow) |
380 IPC_MESSAGE_HANDLER(DragHostMsg_DragStopped, OnDragStopped) | |
374 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck) | 381 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck) |
375 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 382 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
376 OnHasTouchEventHandlers) | 383 OnHasTouchEventHandlers) |
377 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 384 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
378 #if defined(OS_MACOSX) | 385 #if defined(OS_MACOSX) |
379 // MacOSX creates and populates platform-specific select drop-down menus | 386 // MacOSX creates and populates platform-specific select drop-down menus |
380 // whereas other platforms merely create a popup window that the guest | 387 // whereas other platforms merely create a popup window that the guest |
381 // renderer process paints inside. | 388 // renderer process paints inside. |
382 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 389 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
383 #endif | 390 #endif |
384 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 391 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
392 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_StartDragging, | |
393 OnStartDragging(&handled)); | |
385 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 394 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
386 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | |
387 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 395 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
388 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 396 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
389 IPC_MESSAGE_UNHANDLED(handled = false) | 397 IPC_MESSAGE_UNHANDLED(handled = false) |
390 IPC_END_MESSAGE_MAP() | 398 IPC_END_MESSAGE_MAP() |
391 return handled; | 399 return handled; |
392 } | 400 } |
393 | 401 |
394 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, | 402 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, |
395 WebKit::WebDragStatus drag_status, | 403 WebKit::WebDragStatus drag_status, |
396 const WebDropData& drop_data, | 404 const WebDropData& drop_data, |
397 WebKit::WebDragOperationsMask mask, | 405 WebKit::WebDragOperationsMask mask, |
398 const gfx::Point& location) { | 406 const gfx::Point& location) { |
399 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 407 RenderViewHost* host = web_contents()->GetRenderViewHost(); |
400 switch (drag_status) { | 408 switch (drag_status) { |
401 case WebKit::WebDragStatusEnter: | 409 case WebKit::WebDragStatusEnter: |
410 embedder_web_contents_->GetBrowserPluginEmbedder()->DragEnteredGuest( | |
411 this); | |
402 host->DragTargetDragEnter(drop_data, location, location, mask, 0); | 412 host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
403 break; | 413 break; |
404 case WebKit::WebDragStatusOver: | 414 case WebKit::WebDragStatusOver: |
405 host->DragTargetDragOver(location, location, mask, 0); | 415 host->DragTargetDragOver(location, location, mask, 0); |
406 break; | 416 break; |
407 case WebKit::WebDragStatusLeave: | 417 case WebKit::WebDragStatusLeave: |
418 embedder_web_contents_->GetBrowserPluginEmbedder()->DragLeftGuest(this); | |
408 host->DragTargetDragLeave(); | 419 host->DragTargetDragLeave(); |
409 break; | 420 break; |
410 case WebKit::WebDragStatusDrop: | 421 case WebKit::WebDragStatusDrop: |
411 host->DragTargetDrop(location, location, 0); | 422 host->DragTargetDrop(location, location, 0); |
412 break; | 423 break; |
413 case WebKit::WebDragStatusUnknown: | 424 case WebKit::WebDragStatusUnknown: |
414 NOTREACHED(); | 425 NOTREACHED(); |
415 } | 426 } |
416 } | 427 } |
417 | 428 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 int* route_id, | 597 int* route_id, |
587 int* surface_id, | 598 int* surface_id, |
588 int64* cloned_session_storage_namespace_id) { | 599 int64* cloned_session_storage_namespace_id) { |
589 // TODO(fsamuel): We do not currently support window.open. | 600 // TODO(fsamuel): We do not currently support window.open. |
590 // See http://crbug.com/140316. | 601 // See http://crbug.com/140316. |
591 *route_id = MSG_ROUTING_NONE; | 602 *route_id = MSG_ROUTING_NONE; |
592 *surface_id = 0; | 603 *surface_id = 0; |
593 *cloned_session_storage_namespace_id = 0l; | 604 *cloned_session_storage_namespace_id = 0l; |
594 } | 605 } |
595 | 606 |
607 void BrowserPluginGuest::OnDragStopped() { | |
608 web_contents()->GetRenderViewHost()->DragSourceSystemDragEnded(); | |
609 } | |
610 | |
596 void BrowserPluginGuest::OnHandleInputEventAck( | 611 void BrowserPluginGuest::OnHandleInputEventAck( |
597 WebKit::WebInputEvent::Type event_type, | 612 WebKit::WebInputEvent::Type event_type, |
598 InputEventAckState ack_result) { | 613 InputEventAckState ack_result) { |
599 RenderViewHostImpl* guest_rvh = | 614 RenderViewHostImpl* guest_rvh = |
600 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); | 615 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); |
601 guest_rvh->StopHangMonitorTimeout(); | 616 guest_rvh->StopHangMonitorTimeout(); |
602 } | 617 } |
603 | 618 |
604 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { | 619 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { |
605 SendMessageToEmbedder( | 620 SendMessageToEmbedder( |
(...skipping 27 matching lines...) Expand all Loading... | |
633 #endif | 648 #endif |
634 | 649 |
635 void BrowserPluginGuest::OnShowWidget(int route_id, | 650 void BrowserPluginGuest::OnShowWidget(int route_id, |
636 const gfx::Rect& initial_pos) { | 651 const gfx::Rect& initial_pos) { |
637 gfx::Rect screen_pos(initial_pos); | 652 gfx::Rect screen_pos(initial_pos); |
638 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); | 653 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); |
639 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, | 654 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, |
640 screen_pos); | 655 screen_pos); |
641 } | 656 } |
642 | 657 |
658 void BrowserPluginGuest::OnStartDragging(bool* handled) { | |
659 embedder_web_contents_->GetBrowserPluginEmbedder()->StartDrag(this); | |
660 // Don't mark as handled, so that it gets passed up the chain and eventually | |
661 // gets to WebContentsViewGuest::StartDragging, which starts the drag on the | |
662 // embedder. | |
663 *handled = false; | |
664 } | |
665 | |
643 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 666 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
644 SendMessageToEmbedder( | 667 SendMessageToEmbedder( |
645 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), | 668 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), |
646 instance_id(), | 669 instance_id(), |
647 reverse)); | 670 reverse)); |
648 } | 671 } |
649 | 672 |
650 void BrowserPluginGuest::OnUpdateDragCursor( | |
651 WebKit::WebDragOperation operation) { | |
652 RenderViewHostImpl* embedder_render_view_host = | |
653 static_cast<RenderViewHostImpl*>( | |
654 embedder_web_contents_->GetRenderViewHost()); | |
655 CHECK(embedder_render_view_host); | |
656 RenderViewHostDelegateView* view = | |
657 embedder_render_view_host->GetDelegate()->GetDelegateView(); | |
658 if (view) | |
659 view->UpdateDragCursor(operation); | |
660 } | |
661 | |
662 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | 673 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
663 bool is_top_level, | 674 bool is_top_level, |
664 const std::string& name) { | 675 const std::string& name) { |
665 if (!is_top_level) | 676 if (!is_top_level) |
666 return; | 677 return; |
667 | 678 |
668 name_ = name; | 679 name_ = name; |
669 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 680 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
670 embedder_routing_id(), | 681 embedder_routing_id(), |
671 instance_id_, | 682 instance_id_, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 relay_params.scroll_delta = params.scroll_delta; | 737 relay_params.scroll_delta = params.scroll_delta; |
727 relay_params.scroll_rect = params.scroll_rect; | 738 relay_params.scroll_rect = params.scroll_rect; |
728 relay_params.copy_rects = params.copy_rects; | 739 relay_params.copy_rects = params.copy_rects; |
729 | 740 |
730 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 741 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
731 instance_id(), | 742 instance_id(), |
732 relay_params)); | 743 relay_params)); |
733 } | 744 } |
734 | 745 |
735 } // namespace content | 746 } // namespace content |
OLD | NEW |