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 seen_system_drag_ended_(false), | |
32 seen_drag_source_ended_at_(false), | |
Fady Samuel
2014/08/21 23:36:31
Can we do this with one flag?
lazyboy
2014/08/22 00:03:27
Done.
| |
31 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
32 } | 34 } |
33 | 35 |
34 BrowserPluginEmbedder::~BrowserPluginEmbedder() { | 36 BrowserPluginEmbedder::~BrowserPluginEmbedder() { |
35 } | 37 } |
36 | 38 |
37 // static | 39 // static |
38 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( | 40 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( |
39 WebContentsImpl* web_contents) { | 41 WebContentsImpl* web_contents) { |
40 return new BrowserPluginEmbedder(web_contents); | 42 return new BrowserPluginEmbedder(web_contents); |
41 } | 43 } |
42 | 44 |
43 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) { | 45 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) { |
44 guest_dragging_over_ = guest->AsWeakPtr(); | 46 guest_dragging_over_ = guest->AsWeakPtr(); |
45 } | 47 } |
46 | 48 |
47 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) { | 49 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) { |
48 // Avoid race conditions in switching between guests being hovered over by | 50 // 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. | 51 // only un-setting if the caller is marked as the guest being dragged over. |
50 if (guest_dragging_over_.get() == guest) { | 52 if (guest_dragging_over_.get() == guest) { |
51 guest_dragging_over_.reset(); | 53 guest_dragging_over_.reset(); |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { | 57 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { |
56 guest_started_drag_ = guest->AsWeakPtr(); | 58 guest_started_drag_ = guest->AsWeakPtr(); |
59 seen_system_drag_ended_ = false; | |
60 seen_drag_source_ended_at_ = false; | |
57 } | 61 } |
58 | 62 |
59 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const { | 63 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const { |
60 return static_cast<WebContentsImpl*>(web_contents()); | 64 return static_cast<WebContentsImpl*>(web_contents()); |
61 } | 65 } |
62 | 66 |
63 BrowserPluginGuestManager* | 67 BrowserPluginGuestManager* |
64 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const { | 68 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const { |
65 return GetWebContents()->GetBrowserContext()->GetGuestManager(); | 69 return GetWebContents()->GetBrowserContext()->GetGuestManager(); |
66 } | 70 } |
67 | 71 |
72 void BrowserPluginEmbedder::ClearGuestDragStateIfApplicable() { | |
73 // The order at which we observe SystemDragEnded() and DragSourceEndedAt() is | |
74 // platform dependent. | |
75 // In OSX, we see SystemDragEnded() first, where in aura, we see | |
76 // DragSourceEndedAt() first. For this reason, we check if both methods were | |
77 // called before resetting |guest_started_drag_|. | |
78 if (guest_started_drag_ && seen_drag_source_ended_at_ && | |
79 seen_system_drag_ended_) { | |
80 guest_started_drag_.reset(); | |
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 seen_drag_source_ended_at_ = true; |
113 if (guest_started_drag_) { | |
97 gfx::Point guest_offset = | 114 gfx::Point guest_offset = |
98 guest_started_drag_->GetScreenCoordinates(gfx::Point()); | 115 guest_started_drag_->GetScreenCoordinates(gfx::Point()); |
99 guest_started_drag_->DragSourceEndedAt(client_x - guest_offset.x(), | 116 guest_started_drag_->DragSourceEndedAt(client_x - guest_offset.x(), |
100 client_y - guest_offset.y(), screen_x, screen_y, operation); | 117 client_y - guest_offset.y(), screen_x, screen_y, operation); |
101 } | 118 } |
119 ClearGuestDragStateIfApplicable(); | |
102 } | 120 } |
103 | 121 |
104 void BrowserPluginEmbedder::SystemDragEnded() { | 122 void BrowserPluginEmbedder::SystemDragEnded() { |
105 // When the embedder's drag/drop operation ends, we need to pass the message | 123 // 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 | 124 // to the guest that initiated the drag/drop operation. This will ensure that |
107 // the guest's RVH state is reset properly. | 125 // the guest's RVH state is reset properly. |
108 if (guest_started_drag_.get()) | 126 seen_system_drag_ended_ = true; |
127 if (guest_started_drag_) | |
109 guest_started_drag_->EndSystemDrag(); | 128 guest_started_drag_->EndSystemDrag(); |
110 guest_started_drag_.reset(); | |
111 guest_dragging_over_.reset(); | 129 guest_dragging_over_.reset(); |
130 ClearGuestDragStateIfApplicable(); | |
112 } | 131 } |
113 | 132 |
114 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | 133 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { |
115 *handled = (guest_dragging_over_.get() != NULL); | 134 *handled = (guest_dragging_over_.get() != NULL); |
116 } | 135 } |
117 | 136 |
118 void BrowserPluginEmbedder::OnGuestCallback( | 137 void BrowserPluginEmbedder::OnGuestCallback( |
119 int instance_id, | 138 int instance_id, |
120 const BrowserPluginHostMsg_Attach_Params& params, | 139 const BrowserPluginHostMsg_Attach_Params& params, |
121 const base::DictionaryValue* extra_params, | 140 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) | 179 *mouse_unlocked |= static_cast<WebContentsImpl*>(guest) |
161 ->GetBrowserPluginGuest() | 180 ->GetBrowserPluginGuest() |
162 ->mouse_locked(); | 181 ->mouse_locked(); |
163 guest->GotResponseToLockMouseRequest(false); | 182 guest->GotResponseToLockMouseRequest(false); |
164 | 183 |
165 // Returns false to iterate over all guests. | 184 // Returns false to iterate over all guests. |
166 return false; | 185 return false; |
167 } | 186 } |
168 | 187 |
169 } // namespace content | 188 } // namespace content |
OLD | NEW |