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 11 matching lines...) Expand all Loading... | |
51 : WebContentsObserver(web_contents), | 53 : WebContentsObserver(web_contents), |
52 embedder_web_contents_(NULL), | 54 embedder_web_contents_(NULL), |
53 instance_id_(instance_id), | 55 instance_id_(instance_id), |
54 damage_buffer_sequence_id_(0), | 56 damage_buffer_sequence_id_(0), |
55 damage_buffer_size_(0), | 57 damage_buffer_size_(0), |
56 damage_buffer_scale_factor_(1.0f), | 58 damage_buffer_scale_factor_(1.0f), |
57 guest_hang_timeout_( | 59 guest_hang_timeout_( |
58 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 60 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
59 focused_(params.focused), | 61 focused_(params.focused), |
60 visible_(params.visible), | 62 visible_(params.visible), |
63 dragging_(false), | |
64 drag_over_(false), | |
61 name_(params.name), | 65 name_(params.name), |
62 auto_size_enabled_(params.auto_size_params.enable), | 66 auto_size_enabled_(params.auto_size_params.enable), |
63 max_auto_size_(params.auto_size_params.max_size), | 67 max_auto_size_(params.auto_size_params.max_size), |
64 min_auto_size_(params.auto_size_params.min_size) { | 68 min_auto_size_(params.auto_size_params.min_size) { |
65 DCHECK(web_contents); | 69 DCHECK(web_contents); |
66 } | 70 } |
67 | 71 |
68 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 72 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
69 const IPC::Message& message) { | 73 const IPC::Message& message) { |
70 bool handled = true; | 74 bool handled = true; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 params.entry_count = | 318 params.entry_count = |
315 web_contents()->GetController().GetEntryCount(); | 319 web_contents()->GetController().GetEntryCount(); |
316 SendMessageToEmbedder( | 320 SendMessageToEmbedder( |
317 new BrowserPluginMsg_LoadCommit(embedder_routing_id(), | 321 new BrowserPluginMsg_LoadCommit(embedder_routing_id(), |
318 instance_id(), | 322 instance_id(), |
319 params)); | 323 params)); |
320 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 324 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
321 } | 325 } |
322 | 326 |
323 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 327 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
324 // Initiating a drag from inside a guest is currently not supported. So inject | 328 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
325 // some JS to disable it. http://crbug.com/161112 | 329 switches::kEnableBrowserPluginCompositing)) { |
326 const char script[] = "window.addEventListener('dragstart', function() { " | 330 // Initiating a drag from inside a guest is currently not supported without |
327 " window.event.preventDefault(); " | 331 // the kEnableBrowserPluginCompositing flag. So inject some JS to disable |
328 "});"; | 332 // it. http://crbug.com/161112 |
329 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 333 const char script[] = "window.addEventListener('dragstart', function() { " |
330 ASCIIToUTF16(script)); | 334 " window.event.preventDefault(); " |
335 "});"; | |
336 render_view_host->ExecuteJavascriptInWebFrame(string16(), | |
337 ASCIIToUTF16(script)); | |
338 } | |
331 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), | 339 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), |
332 instance_id())); | 340 instance_id())); |
333 } | 341 } |
334 | 342 |
335 void BrowserPluginGuest::RenderViewReady() { | 343 void BrowserPluginGuest::RenderViewReady() { |
336 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 344 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
337 // here (see http://crbug.com/158151). | 345 // here (see http://crbug.com/158151). |
338 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 346 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
339 UpdateVisibility(); | 347 UpdateVisibility(); |
340 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 348 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
(...skipping 21 matching lines...) Expand all Loading... | |
362 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 370 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
363 RecordAction(UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath")); | 371 RecordAction(UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath")); |
364 break; | 372 break; |
365 default: | 373 default: |
366 break; | 374 break; |
367 } | 375 } |
368 } | 376 } |
369 | 377 |
370 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 378 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
371 bool handled = true; | 379 bool handled = true; |
380 if (message.type() == DragHostMsg_StartDragging::ID) { | |
381 dragging_ = true; | |
Fady Samuel
2013/02/01 14:59:28
Use IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_StartD
mthiesse
2013/02/01 15:43:54
Done.
| |
382 // Don't mark as handled, so that it gets passed up the chain and eventually | |
383 // gets to WebContentsViewGuest::StartDragging, which starts the drag on the | |
384 // embedder. | |
385 return false; | |
386 } | |
372 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 387 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
373 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnCreateWindow) | 388 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnCreateWindow) |
389 IPC_MESSAGE_HANDLER(DragHostMsg_DragStopped, OnDragStopped) | |
374 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck) | 390 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck) |
375 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 391 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
376 OnHasTouchEventHandlers) | 392 OnHasTouchEventHandlers) |
377 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 393 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
378 #if defined(OS_MACOSX) | 394 #if defined(OS_MACOSX) |
379 // MacOSX creates and populates platform-specific select drop-down menus | 395 // MacOSX creates and populates platform-specific select drop-down menus |
380 // whereas other platforms merely create a popup window that the guest | 396 // whereas other platforms merely create a popup window that the guest |
381 // renderer process paints inside. | 397 // renderer process paints inside. |
382 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 398 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
383 #endif | 399 #endif |
384 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 400 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
385 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 401 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
386 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | |
387 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 402 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
388 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 403 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
389 IPC_MESSAGE_UNHANDLED(handled = false) | 404 IPC_MESSAGE_UNHANDLED(handled = false) |
390 IPC_END_MESSAGE_MAP() | 405 IPC_END_MESSAGE_MAP() |
391 return handled; | 406 return handled; |
392 } | 407 } |
393 | 408 |
394 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, | 409 void BrowserPluginGuest::OnDragStatusUpdate(int instance_id, |
395 WebKit::WebDragStatus drag_status, | 410 WebKit::WebDragStatus drag_status, |
396 const WebDropData& drop_data, | 411 const WebDropData& drop_data, |
397 WebKit::WebDragOperationsMask mask, | 412 WebKit::WebDragOperationsMask mask, |
398 const gfx::Point& location) { | 413 const gfx::Point& location) { |
399 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 414 RenderViewHost* host = web_contents()->GetRenderViewHost(); |
400 switch (drag_status) { | 415 switch (drag_status) { |
401 case WebKit::WebDragStatusEnter: | 416 case WebKit::WebDragStatusEnter: |
417 drag_over_ = true; | |
402 host->DragTargetDragEnter(drop_data, location, location, mask, 0); | 418 host->DragTargetDragEnter(drop_data, location, location, mask, 0); |
403 break; | 419 break; |
404 case WebKit::WebDragStatusOver: | 420 case WebKit::WebDragStatusOver: |
405 host->DragTargetDragOver(location, location, mask, 0); | 421 host->DragTargetDragOver(location, location, mask, 0); |
406 break; | 422 break; |
407 case WebKit::WebDragStatusLeave: | 423 case WebKit::WebDragStatusLeave: |
424 drag_over_ = false; | |
408 host->DragTargetDragLeave(); | 425 host->DragTargetDragLeave(); |
409 break; | 426 break; |
410 case WebKit::WebDragStatusDrop: | 427 case WebKit::WebDragStatusDrop: |
411 host->DragTargetDrop(location, location, 0); | 428 host->DragTargetDrop(location, location, 0); |
412 break; | 429 break; |
413 case WebKit::WebDragStatusUnknown: | 430 case WebKit::WebDragStatusUnknown: |
414 NOTREACHED(); | 431 NOTREACHED(); |
415 } | 432 } |
416 } | 433 } |
417 | 434 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 int* route_id, | 598 int* route_id, |
582 int* surface_id, | 599 int* surface_id, |
583 int64* cloned_session_storage_namespace_id) { | 600 int64* cloned_session_storage_namespace_id) { |
584 // TODO(fsamuel): We do not currently support window.open. | 601 // TODO(fsamuel): We do not currently support window.open. |
585 // See http://crbug.com/140316. | 602 // See http://crbug.com/140316. |
586 *route_id = MSG_ROUTING_NONE; | 603 *route_id = MSG_ROUTING_NONE; |
587 *surface_id = 0; | 604 *surface_id = 0; |
588 *cloned_session_storage_namespace_id = 0l; | 605 *cloned_session_storage_namespace_id = 0l; |
589 } | 606 } |
590 | 607 |
608 void BrowserPluginGuest::OnDragStopped() { | |
609 if (dragging_) { | |
610 web_contents()->GetRenderViewHost()->DragSourceSystemDragEnded(); | |
611 dragging_ = false; | |
612 } | |
613 } | |
614 | |
591 void BrowserPluginGuest::OnHandleInputEventAck( | 615 void BrowserPluginGuest::OnHandleInputEventAck( |
592 WebKit::WebInputEvent::Type event_type, | 616 WebKit::WebInputEvent::Type event_type, |
593 InputEventAckState ack_result) { | 617 InputEventAckState ack_result) { |
594 RenderViewHostImpl* guest_rvh = | 618 RenderViewHostImpl* guest_rvh = |
595 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); | 619 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); |
596 guest_rvh->StopHangMonitorTimeout(); | 620 guest_rvh->StopHangMonitorTimeout(); |
597 } | 621 } |
598 | 622 |
599 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { | 623 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { |
600 SendMessageToEmbedder( | 624 SendMessageToEmbedder( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 screen_pos); | 659 screen_pos); |
636 } | 660 } |
637 | 661 |
638 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 662 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
639 SendMessageToEmbedder( | 663 SendMessageToEmbedder( |
640 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), | 664 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(), |
641 instance_id(), | 665 instance_id(), |
642 reverse)); | 666 reverse)); |
643 } | 667 } |
644 | 668 |
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, | 669 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
658 bool is_top_level, | 670 bool is_top_level, |
659 const std::string& name) { | 671 const std::string& name) { |
660 if (!is_top_level) | 672 if (!is_top_level) |
661 return; | 673 return; |
662 | 674 |
663 name_ = name; | 675 name_ = name; |
664 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( | 676 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
665 embedder_routing_id(), | 677 embedder_routing_id(), |
666 instance_id_, | 678 instance_id_, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 relay_params.scroll_delta = params.scroll_delta; | 733 relay_params.scroll_delta = params.scroll_delta; |
722 relay_params.scroll_rect = params.scroll_rect; | 734 relay_params.scroll_rect = params.scroll_rect; |
723 relay_params.copy_rects = params.copy_rects; | 735 relay_params.copy_rects = params.copy_rects; |
724 | 736 |
725 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 737 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
726 instance_id(), | 738 instance_id(), |
727 relay_params)); | 739 relay_params)); |
728 } | 740 } |
729 | 741 |
730 } // namespace content | 742 } // namespace content |
OLD | NEW |