| 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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 embedder_visible_(true), | 84 embedder_visible_(true), |
| 85 is_full_page_plugin_(false), | 85 is_full_page_plugin_(false), |
| 86 has_render_view_(has_render_view), | 86 has_render_view_(has_render_view), |
| 87 is_in_destruction_(false), | 87 is_in_destruction_(false), |
| 88 initialized_(false), | 88 initialized_(false), |
| 89 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 89 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 90 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 90 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 91 last_input_flags_(0), | 91 last_input_flags_(0), |
| 92 last_can_compose_inline_(true), | 92 last_can_compose_inline_(true), |
| 93 guest_proxy_routing_id_(MSG_ROUTING_NONE), | 93 guest_proxy_routing_id_(MSG_ROUTING_NONE), |
| 94 last_drag_status_(blink::WebDragStatusUnknown), |
| 95 seen_embedder_system_drag_ended_(false), |
| 96 seen_embedder_drag_source_ended_at_(false), |
| 94 delegate_(delegate), | 97 delegate_(delegate), |
| 95 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
| 96 DCHECK(web_contents); | 99 DCHECK(web_contents); |
| 97 DCHECK(delegate); | 100 DCHECK(delegate); |
| 98 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 101 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
| 99 web_contents->SetBrowserPluginGuest(this); | 102 web_contents->SetBrowserPluginGuest(this); |
| 100 delegate->RegisterDestructionCallback( | 103 delegate->RegisterDestructionCallback( |
| 101 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); | 104 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); |
| 102 delegate->SetGuestSizer(this); | 105 delegate->SetGuestSizer(this); |
| 103 } | 106 } |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); | 413 pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); |
| 411 return; | 414 return; |
| 412 } | 415 } |
| 413 owner_web_contents_->Send(msg); | 416 owner_web_contents_->Send(msg); |
| 414 } | 417 } |
| 415 | 418 |
| 416 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, | 419 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |
| 417 int screen_x, int screen_y, blink::WebDragOperation operation) { | 420 int screen_x, int screen_y, blink::WebDragOperation operation) { |
| 418 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, | 421 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
| 419 screen_x, screen_y, operation); | 422 screen_x, screen_y, operation); |
| 423 seen_embedder_drag_source_ended_at_ = true; |
| 424 EndSystemDragIfApplicable(); |
| 420 } | 425 } |
| 421 | 426 |
| 422 void BrowserPluginGuest::EndSystemDrag() { | 427 void BrowserPluginGuest::EndSystemDragIfApplicable() { |
| 423 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 428 // Ideally we'd want either WebDragStatusDrop or WebDragStatusLeave... |
| 424 GetWebContents()->GetRenderViewHost()); | 429 // Call guest RVH->DragSourceSystemDragEnded() correctly on the guest where |
| 425 guest_rvh->DragSourceSystemDragEnded(); | 430 // the drag was initiated. Calling DragSourceSystemDragEnded() correctly |
| 431 // means we call it in all cases and also make sure we only call it once. |
| 432 // This ensures that the input state of the guest stays correct, otherwise |
| 433 // it will go stale and won't accept any further input events. |
| 434 // |
| 435 // The strategy used here to call DragSourceSystemDragEnded() on the RVH |
| 436 // is when the following conditions are met: |
| 437 // a. Embedder has seen SystemDragEnded() |
| 438 // b. Embedder has seen DragSourceEndedAt() |
| 439 // c. The guest has seen some drag status update other than |
| 440 // WebDragStatusUnknown. Note that this step should ideally be done |
| 441 // differently: The guest has seen at least one of |
| 442 // {WebDragStatusOver, WebDragStatusDrop}. However, if a user drags |
| 443 // a source quickly outside of <webview> bounds, then the |
| 444 // BrowserPluginGuest never sees any of these drag status updates, |
| 445 // there we just check whether we've seen any drag status update or |
| 446 // not. |
| 447 if (last_drag_status_ != blink::WebDragStatusOver && |
| 448 seen_embedder_drag_source_ended_at_ && seen_embedder_system_drag_ended_) { |
| 449 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 450 GetWebContents()->GetRenderViewHost()); |
| 451 guest_rvh->DragSourceSystemDragEnded(); |
| 452 |
| 453 last_drag_status_ = blink::WebDragStatusUnknown; |
| 454 seen_embedder_system_drag_ended_ = false; |
| 455 seen_embedder_drag_source_ended_at_ = false; |
| 456 } |
| 457 } |
| 458 |
| 459 void BrowserPluginGuest::EmbedderSystemDragEnded() { |
| 460 seen_embedder_system_drag_ended_ = true; |
| 461 EndSystemDragIfApplicable(); |
| 426 } | 462 } |
| 427 | 463 |
| 428 void BrowserPluginGuest::SendQueuedMessages() { | 464 void BrowserPluginGuest::SendQueuedMessages() { |
| 429 if (!attached()) | 465 if (!attached()) |
| 430 return; | 466 return; |
| 431 | 467 |
| 432 while (!pending_messages_.empty()) { | 468 while (!pending_messages_.empty()) { |
| 433 linked_ptr<IPC::Message> message_ptr = pending_messages_.front(); | 469 linked_ptr<IPC::Message> message_ptr = pending_messages_.front(); |
| 434 pending_messages_.pop_front(); | 470 pending_messages_.pop_front(); |
| 435 SendMessageToEmbedder(message_ptr.release()); | 471 SendMessageToEmbedder(message_ptr.release()); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 break; | 678 break; |
| 643 case blink::WebDragStatusOver: | 679 case blink::WebDragStatusOver: |
| 644 host->DragTargetDragOver(location, location, mask, 0); | 680 host->DragTargetDragOver(location, location, mask, 0); |
| 645 break; | 681 break; |
| 646 case blink::WebDragStatusLeave: | 682 case blink::WebDragStatusLeave: |
| 647 owner_web_contents_->GetBrowserPluginEmbedder()->DragLeftGuest(this); | 683 owner_web_contents_->GetBrowserPluginEmbedder()->DragLeftGuest(this); |
| 648 host->DragTargetDragLeave(); | 684 host->DragTargetDragLeave(); |
| 649 break; | 685 break; |
| 650 case blink::WebDragStatusDrop: | 686 case blink::WebDragStatusDrop: |
| 651 host->DragTargetDrop(location, location, 0); | 687 host->DragTargetDrop(location, location, 0); |
| 652 EndSystemDrag(); | |
| 653 break; | 688 break; |
| 654 case blink::WebDragStatusUnknown: | 689 case blink::WebDragStatusUnknown: |
| 655 NOTREACHED(); | 690 NOTREACHED(); |
| 656 } | 691 } |
| 692 last_drag_status_ = drag_status; |
| 693 EndSystemDragIfApplicable(); |
| 657 } | 694 } |
| 658 | 695 |
| 659 void BrowserPluginGuest::OnExecuteEditCommand(int browser_plugin_instance_id, | 696 void BrowserPluginGuest::OnExecuteEditCommand(int browser_plugin_instance_id, |
| 660 const std::string& name) { | 697 const std::string& name) { |
| 661 RenderFrameHost* focused_frame = web_contents()->GetFocusedFrame(); | 698 RenderFrameHost* focused_frame = web_contents()->GetFocusedFrame(); |
| 662 if (!focused_frame) | 699 if (!focused_frame) |
| 663 return; | 700 return; |
| 664 | 701 |
| 665 focused_frame->Send(new InputMsg_ExecuteNoValueEditCommand( | 702 focused_frame->Send(new InputMsg_ExecuteNoValueEditCommand( |
| 666 focused_frame->GetRoutingID(), name)); | 703 focused_frame->GetRoutingID(), name)); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 900 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
| 864 const gfx::Range& range, | 901 const gfx::Range& range, |
| 865 const std::vector<gfx::Rect>& character_bounds) { | 902 const std::vector<gfx::Rect>& character_bounds) { |
| 866 static_cast<RenderWidgetHostViewBase*>( | 903 static_cast<RenderWidgetHostViewBase*>( |
| 867 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 904 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
| 868 range, character_bounds); | 905 range, character_bounds); |
| 869 } | 906 } |
| 870 #endif | 907 #endif |
| 871 | 908 |
| 872 } // namespace content | 909 } // namespace content |
| OLD | NEW |