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 "content/browser/browser_plugin/browser_plugin_guest.h" | 7 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
8 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
11 #include "content/common/browser_plugin/browser_plugin_constants.h" | 11 #include "content/common/browser_plugin/browser_plugin_constants.h" |
12 #include "content/common/browser_plugin/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 13 #include "content/common/drag_messages.h" |
13 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
14 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
17 #include "content/public/common/result_codes.h" | 18 #include "content/public/common/result_codes.h" |
18 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
19 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
(...skipping 10 matching lines...) Expand all Loading... |
33 } | 34 } |
34 | 35 |
35 // static | 36 // static |
36 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( | 37 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( |
37 WebContentsImpl* web_contents) { | 38 WebContentsImpl* web_contents) { |
38 if (factory_) | 39 if (factory_) |
39 return factory_->CreateBrowserPluginEmbedder(web_contents); | 40 return factory_->CreateBrowserPluginEmbedder(web_contents); |
40 return new BrowserPluginEmbedder(web_contents); | 41 return new BrowserPluginEmbedder(web_contents); |
41 } | 42 } |
42 | 43 |
| 44 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) { |
| 45 guest_dragging_over_ = guest->AsWeakPtr(); |
| 46 } |
| 47 |
| 48 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) { |
| 49 // Avoid race conditions in switching between guests being hovered over by |
| 50 // only un-setting if the caller is marked as the guest being dragged over. |
| 51 if (guest_dragging_over_ == guest) { |
| 52 guest_dragging_over_.reset(); |
| 53 } |
| 54 } |
| 55 |
| 56 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { |
| 57 guest_started_drag_ = guest->AsWeakPtr(); |
| 58 } |
| 59 |
| 60 void BrowserPluginEmbedder::StopDrag(BrowserPluginGuest* guest) { |
| 61 if (guest_started_drag_ == guest) { |
| 62 guest_started_drag_.reset(); |
| 63 } |
| 64 } |
| 65 |
43 void BrowserPluginEmbedder::GetRenderViewHostAtPosition( | 66 void BrowserPluginEmbedder::GetRenderViewHostAtPosition( |
44 int x, int y, const WebContents::GetRenderViewHostCallback& callback) { | 67 int x, int y, const WebContents::GetRenderViewHostCallback& callback) { |
45 // Store the callback so we can call it later when we have the response. | 68 // Store the callback so we can call it later when we have the response. |
46 pending_get_render_view_callbacks_.insert( | 69 pending_get_render_view_callbacks_.insert( |
47 std::make_pair(next_get_render_view_request_id_, callback)); | 70 std::make_pair(next_get_render_view_request_id_, callback)); |
48 Send(new BrowserPluginMsg_PluginAtPositionRequest( | 71 Send(new BrowserPluginMsg_PluginAtPositionRequest( |
49 routing_id(), | 72 routing_id(), |
50 next_get_render_view_request_id_, | 73 next_get_render_view_request_id_, |
51 gfx::Point(x, y))); | 74 gfx::Point(x, y))); |
52 ++next_get_render_view_request_id_; | 75 ++next_get_render_view_request_id_; |
53 } | 76 } |
54 | 77 |
55 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { | 78 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { |
56 CleanUp(); | 79 CleanUp(); |
57 } | 80 } |
58 | 81 |
59 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 82 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
60 bool handled = true; | 83 bool handled = true; |
61 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 84 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
62 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, | 85 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, |
63 OnAllocateInstanceID) | 86 OnAllocateInstanceID) |
64 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) | 87 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) |
65 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest, OnCreateGuest) | 88 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest, OnCreateGuest) |
66 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse, | 89 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse, |
67 OnPluginAtPositionResponse) | 90 OnPluginAtPositionResponse) |
| 91 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, |
| 92 OnUpdateDragCursor(&handled)); |
68 IPC_MESSAGE_UNHANDLED(handled = false) | 93 IPC_MESSAGE_UNHANDLED(handled = false) |
69 IPC_END_MESSAGE_MAP() | 94 IPC_END_MESSAGE_MAP() |
70 return handled; | 95 return handled; |
71 } | 96 } |
72 | 97 |
| 98 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, |
| 99 int screen_x, int screen_y, WebKit::WebDragOperation operation) { |
| 100 gfx::Point guest_offset = |
| 101 guest_started_drag_->GetScreenCoordinates(gfx::Point()); |
| 102 |
| 103 if (guest_started_drag_) { |
| 104 guest_started_drag_->DragSourceEndedAt(client_x - guest_offset.x(), |
| 105 client_y - guest_offset.y(), screen_x, screen_y, operation); |
| 106 } |
| 107 } |
| 108 |
| 109 void BrowserPluginEmbedder::DragSourceMovedTo(int client_x, int client_y, |
| 110 int screen_x, int screen_y) { |
| 111 gfx::Point guest_offset = |
| 112 guest_started_drag_->GetScreenCoordinates(gfx::Point()); |
| 113 |
| 114 if (guest_started_drag_) { |
| 115 guest_started_drag_->DragSourceMovedTo(client_x - guest_offset.x(), |
| 116 client_y - guest_offset.y(), screen_x, screen_y); |
| 117 } |
| 118 } |
| 119 |
| 120 void BrowserPluginEmbedder::SystemDragEnded() { |
| 121 if (guest_started_drag_ && (guest_started_drag_ != guest_dragging_over_)) |
| 122 guest_started_drag_->EndSystemDrag(); |
| 123 guest_started_drag_.reset(); |
| 124 guest_dragging_over_.reset(); |
| 125 } |
| 126 |
| 127 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { |
| 128 *handled = (guest_dragging_over_ != NULL); |
| 129 } |
| 130 |
73 void BrowserPluginEmbedder::CleanUp() { | 131 void BrowserPluginEmbedder::CleanUp() { |
74 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away | 132 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away |
75 // or the associated RenderViewHost is destroyed or swapped out. Therefore we | 133 // or the associated RenderViewHost is destroyed or swapped out. Therefore we |
76 // don't need to care about the pending callbacks anymore. | 134 // don't need to care about the pending callbacks anymore. |
77 pending_get_render_view_callbacks_.clear(); | 135 pending_get_render_view_callbacks_.clear(); |
78 } | 136 } |
79 | 137 |
80 BrowserPluginGuestManager* | 138 BrowserPluginGuestManager* |
81 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { | 139 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { |
82 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>( | 140 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 if (guest) | 186 if (guest) |
129 render_view_host = guest->GetWebContents()->GetRenderViewHost(); | 187 render_view_host = guest->GetWebContents()->GetRenderViewHost(); |
130 else // No plugin, use embedder's RenderViewHost. | 188 else // No plugin, use embedder's RenderViewHost. |
131 render_view_host = web_contents()->GetRenderViewHost(); | 189 render_view_host = web_contents()->GetRenderViewHost(); |
132 | 190 |
133 callback_iter->second.Run(render_view_host, position.x(), position.y()); | 191 callback_iter->second.Run(render_view_host, position.x(), position.y()); |
134 pending_get_render_view_callbacks_.erase(callback_iter); | 192 pending_get_render_view_callbacks_.erase(callback_iter); |
135 } | 193 } |
136 | 194 |
137 } // namespace content | 195 } // namespace content |
OLD | NEW |