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_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/result_codes.h" | 22 #include "content/public/common/result_codes.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
24 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
25 #include "ui/events/keycodes/keyboard_codes.h" | 25 #include "ui/events/keycodes/keyboard_codes.h" |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) | 29 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) |
30 : WebContentsObserver(web_contents), | 30 : WebContentsObserver(web_contents), |
| 31 guest_drag_ending_(false), |
31 weak_ptr_factory_(this) { | 32 weak_ptr_factory_(this) { |
32 } | 33 } |
33 | 34 |
34 BrowserPluginEmbedder::~BrowserPluginEmbedder() { | 35 BrowserPluginEmbedder::~BrowserPluginEmbedder() { |
35 } | 36 } |
36 | 37 |
37 // static | 38 // static |
38 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( | 39 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( |
39 WebContentsImpl* web_contents) { | 40 WebContentsImpl* web_contents) { |
40 return new BrowserPluginEmbedder(web_contents); | 41 return new BrowserPluginEmbedder(web_contents); |
41 } | 42 } |
42 | 43 |
43 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) { | 44 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) { |
44 guest_dragging_over_ = guest->AsWeakPtr(); | 45 guest_dragging_over_ = guest->AsWeakPtr(); |
45 } | 46 } |
46 | 47 |
47 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) { | 48 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) { |
48 // Avoid race conditions in switching between guests being hovered over by | 49 // Avoid race conditions in switching between guests being hovered over by |
49 // only un-setting if the caller is marked as the guest being dragged over. | 50 // only un-setting if the caller is marked as the guest being dragged over. |
50 if (guest_dragging_over_.get() == guest) { | 51 if (guest_dragging_over_.get() == guest) { |
51 guest_dragging_over_.reset(); | 52 guest_dragging_over_.reset(); |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { | 56 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { |
56 guest_started_drag_ = guest->AsWeakPtr(); | 57 guest_started_drag_ = guest->AsWeakPtr(); |
| 58 guest_drag_ending_ = false; |
57 } | 59 } |
58 | 60 |
59 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const { | 61 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const { |
60 return static_cast<WebContentsImpl*>(web_contents()); | 62 return static_cast<WebContentsImpl*>(web_contents()); |
61 } | 63 } |
62 | 64 |
63 BrowserPluginGuestManager* | 65 BrowserPluginGuestManager* |
64 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const { | 66 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const { |
65 return GetWebContents()->GetBrowserContext()->GetGuestManager(); | 67 return GetWebContents()->GetBrowserContext()->GetGuestManager(); |
66 } | 68 } |
67 | 69 |
| 70 void BrowserPluginEmbedder::ClearGuestDragStateIfApplicable() { |
| 71 // The order at which we observe SystemDragEnded() and DragSourceEndedAt() is |
| 72 // platform dependent. |
| 73 // In OSX, we see SystemDragEnded() first, where in aura, we see |
| 74 // DragSourceEndedAt() first. For this reason, we check if both methods were |
| 75 // called before resetting |guest_started_drag_|. |
| 76 if (guest_drag_ending_) { |
| 77 if (guest_started_drag_) |
| 78 guest_started_drag_.reset(); |
| 79 } else { |
| 80 guest_drag_ending_ = true; |
| 81 } |
| 82 } |
| 83 |
68 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( | 84 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( |
69 WebContents* guest_web_contents) { | 85 WebContents* guest_web_contents) { |
70 static_cast<RenderViewHostImpl*>( | 86 static_cast<RenderViewHostImpl*>( |
71 guest_web_contents->GetRenderViewHost())->SendScreenRects(); | 87 guest_web_contents->GetRenderViewHost())->SendScreenRects(); |
72 // Not handled => Iterate over all guests. | 88 // Not handled => Iterate over all guests. |
73 return false; | 89 return false; |
74 } | 90 } |
75 | 91 |
76 void BrowserPluginEmbedder::DidSendScreenRects() { | 92 void BrowserPluginEmbedder::DidSendScreenRects() { |
77 GetBrowserPluginGuestManager()->ForEachGuest( | 93 GetBrowserPluginGuestManager()->ForEachGuest( |
78 GetWebContents(), base::Bind( | 94 GetWebContents(), base::Bind( |
79 &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 95 &BrowserPluginEmbedder::DidSendScreenRectsCallback, |
80 base::Unretained(this))); | 96 base::Unretained(this))); |
81 } | 97 } |
82 | 98 |
83 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 99 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
84 bool handled = true; | 100 bool handled = true; |
85 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 101 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
86 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) | 102 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) |
87 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, | 103 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, |
88 OnUpdateDragCursor(&handled)); | 104 OnUpdateDragCursor(&handled)); |
89 IPC_MESSAGE_UNHANDLED(handled = false) | 105 IPC_MESSAGE_UNHANDLED(handled = false) |
90 IPC_END_MESSAGE_MAP() | 106 IPC_END_MESSAGE_MAP() |
91 return handled; | 107 return handled; |
92 } | 108 } |
93 | 109 |
94 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, | 110 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, |
95 int screen_x, int screen_y, blink::WebDragOperation operation) { | 111 int screen_x, int screen_y, blink::WebDragOperation operation) { |
96 if (guest_started_drag_.get()) { | 112 if (guest_started_drag_) { |
97 gfx::Point guest_offset = | 113 gfx::Point guest_offset = |
98 guest_started_drag_->GetScreenCoordinates(gfx::Point()); | 114 guest_started_drag_->GetScreenCoordinates(gfx::Point()); |
99 guest_started_drag_->DragSourceEndedAt(client_x - guest_offset.x(), | 115 guest_started_drag_->DragSourceEndedAt(client_x - guest_offset.x(), |
100 client_y - guest_offset.y(), screen_x, screen_y, operation); | 116 client_y - guest_offset.y(), screen_x, screen_y, operation); |
101 } | 117 } |
| 118 ClearGuestDragStateIfApplicable(); |
102 } | 119 } |
103 | 120 |
104 void BrowserPluginEmbedder::SystemDragEnded() { | 121 void BrowserPluginEmbedder::SystemDragEnded() { |
105 // When the embedder's drag/drop operation ends, we need to pass the message | 122 // When the embedder's drag/drop operation ends, we need to pass the message |
106 // to the guest that initiated the drag/drop operation. This will ensure that | 123 // to the guest that initiated the drag/drop operation. This will ensure that |
107 // the guest's RVH state is reset properly. | 124 // the guest's RVH state is reset properly. |
108 if (guest_started_drag_.get()) | 125 if (guest_started_drag_) |
109 guest_started_drag_->EndSystemDrag(); | 126 guest_started_drag_->EndSystemDrag(); |
110 guest_started_drag_.reset(); | |
111 guest_dragging_over_.reset(); | 127 guest_dragging_over_.reset(); |
| 128 ClearGuestDragStateIfApplicable(); |
112 } | 129 } |
113 | 130 |
114 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | 131 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { |
115 *handled = (guest_dragging_over_.get() != NULL); | 132 *handled = (guest_dragging_over_.get() != NULL); |
116 } | 133 } |
117 | 134 |
118 void BrowserPluginEmbedder::OnGuestCallback( | 135 void BrowserPluginEmbedder::OnGuestCallback( |
119 int instance_id, | 136 int instance_id, |
120 const BrowserPluginHostMsg_Attach_Params& params, | 137 const BrowserPluginHostMsg_Attach_Params& params, |
121 const base::DictionaryValue* extra_params, | 138 const base::DictionaryValue* extra_params, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 *mouse_unlocked |= static_cast<WebContentsImpl*>(guest) | 177 *mouse_unlocked |= static_cast<WebContentsImpl*>(guest) |
161 ->GetBrowserPluginGuest() | 178 ->GetBrowserPluginGuest() |
162 ->mouse_locked(); | 179 ->mouse_locked(); |
163 guest->GotResponseToLockMouseRequest(false); | 180 guest->GotResponseToLockMouseRequest(false); |
164 | 181 |
165 // Returns false to iterate over all guests. | 182 // Returns false to iterate over all guests. |
166 return false; | 183 return false; |
167 } | 184 } |
168 | 185 |
169 } // namespace content | 186 } // namespace content |
OLD | NEW |