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)) { |
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 int* route_id, | 592 int* route_id, |
582 int* surface_id, | 593 int* surface_id, |
583 int64* cloned_session_storage_namespace_id) { | 594 int64* cloned_session_storage_namespace_id) { |
584 // TODO(fsamuel): We do not currently support window.open. | 595 // TODO(fsamuel): We do not currently support window.open. |
585 // See http://crbug.com/140316. | 596 // See http://crbug.com/140316. |
586 *route_id = MSG_ROUTING_NONE; | 597 *route_id = MSG_ROUTING_NONE; |
587 *surface_id = 0; | 598 *surface_id = 0; |
588 *cloned_session_storage_namespace_id = 0l; | 599 *cloned_session_storage_namespace_id = 0l; |
589 } | 600 } |
590 | 601 |
| 602 void BrowserPluginGuest::OnDragStopped() { |
| 603 web_contents()->GetRenderViewHost()->DragSourceSystemDragEnded(); |
| 604 } |
| 605 |
591 void BrowserPluginGuest::OnHandleInputEventAck( | 606 void BrowserPluginGuest::OnHandleInputEventAck( |
592 WebKit::WebInputEvent::Type event_type, | 607 WebKit::WebInputEvent::Type event_type, |
593 InputEventAckState ack_result) { | 608 InputEventAckState ack_result) { |
594 RenderViewHostImpl* guest_rvh = | 609 RenderViewHostImpl* guest_rvh = |
595 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); | 610 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); |
596 guest_rvh->StopHangMonitorTimeout(); | 611 guest_rvh->StopHangMonitorTimeout(); |
597 } | 612 } |
598 | 613 |
599 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { | 614 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { |
600 SendMessageToEmbedder( | 615 SendMessageToEmbedder( |
(...skipping 27 matching lines...) Expand all Loading... |
628 #endif | 643 #endif |
629 | 644 |
630 void BrowserPluginGuest::OnShowWidget(int route_id, | 645 void BrowserPluginGuest::OnShowWidget(int route_id, |
631 const gfx::Rect& initial_pos) { | 646 const gfx::Rect& initial_pos) { |
632 gfx::Rect screen_pos(initial_pos); | 647 gfx::Rect screen_pos(initial_pos); |
633 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); | 648 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); |
634 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, | 649 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, |
635 screen_pos); | 650 screen_pos); |
636 } | 651 } |
637 | 652 |
| 653 void BrowserPluginGuest::OnStartDragging(bool* handled) { |
| 654 embedder_web_contents_->GetBrowserPluginEmbedder()->StartDrag(this); |
| 655 // Don't mark as handled, so that it gets passed up the chain and eventually |
| 656 // gets to WebContentsViewGuest::StartDragging, which starts the drag on the |
| 657 // embedder. |
| 658 *handled = false; |
| 659 } |
| 660 |
638 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 661 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
639 SendMessageToEmbedder( | 662 SendMessageToEmbedder( |
640 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), | 663 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), |
641 instance_id(), | 664 instance_id(), |
642 reverse)); | 665 reverse)); |
643 } | 666 } |
644 | 667 |
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, | 668 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
658 bool is_top_level, | 669 bool is_top_level, |
659 const std::string& name) { | 670 const std::string& name) { |
660 if (!is_top_level) | 671 if (!is_top_level) |
661 return; | 672 return; |
662 | 673 |
663 name_ = name; | 674 name_ = name; |
664 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 675 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
665 embedder_routing_id(), | 676 embedder_routing_id(), |
666 instance_id_, | 677 instance_id_, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 relay_params.scroll_delta = params.scroll_delta; | 732 relay_params.scroll_delta = params.scroll_delta; |
722 relay_params.scroll_rect = params.scroll_rect; | 733 relay_params.scroll_rect = params.scroll_rect; |
723 relay_params.copy_rects = params.copy_rects; | 734 relay_params.copy_rects = params.copy_rects; |
724 | 735 |
725 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 736 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
726 instance_id(), | 737 instance_id(), |
727 relay_params)); | 738 relay_params)); |
728 } | 739 } |
729 | 740 |
730 } // namespace content | 741 } // namespace content |
OLD | NEW |