Chromium Code Reviews| 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) { | |
|
Fady Samuel
2013/04/09 20:49:12
Hmm, is client_x, client_y in the right coordinate
mthiesse
2013/04/18 18:02:03
Good catch, doesn't seem to change much (if anythi
| |
| 100 if (guest_started_drag_) | |
|
Fady Samuel
2013/04/09 20:49:12
Put in block:
if (guest_started_drag_) {
guest_
mthiesse
2013/04/18 18:02:03
Done.
| |
| 101 guest_started_drag_->DragSourceEndedAt(client_x, client_y, | |
| 102 screen_x, screen_y, operation); | |
| 103 } | |
| 104 | |
| 105 void BrowserPluginEmbedder::DragSourceMovedTo(int client_x, int client_y, | |
|
Fady Samuel
2013/04/09 20:49:12
ditto
mthiesse
2013/04/18 18:02:03
Done.
| |
| 106 int screen_x, int screen_y) { | |
| 107 if (guest_started_drag_) | |
| 108 guest_started_drag_->DragSourceMovedTo(client_x, client_y, | |
|
Fady Samuel
2013/04/09 20:49:12
{
...
}
mthiesse
2013/04/18 18:02:03
Done.
| |
| 109 screen_x, screen_y); | |
| 110 } | |
| 111 | |
| 112 void BrowserPluginEmbedder::SystemDragEnded() { | |
| 113 if (guest_started_drag_ && (guest_started_drag_ != guest_dragging_over_)) | |
| 114 guest_started_drag_->EndSystemDrag(); | |
| 115 guest_started_drag_.reset(); | |
| 116 guest_dragging_over_.reset(); | |
| 117 } | |
| 118 | |
| 119 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | |
| 120 *handled = (guest_dragging_over_ != NULL); | |
| 121 } | |
| 122 | |
| 73 void BrowserPluginEmbedder::CleanUp() { | 123 void BrowserPluginEmbedder::CleanUp() { |
| 74 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away | 124 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away |
| 75 // or the associated RenderViewHost is destroyed or swapped out. Therefore we | 125 // or the associated RenderViewHost is destroyed or swapped out. Therefore we |
| 76 // don't need to care about the pending callbacks anymore. | 126 // don't need to care about the pending callbacks anymore. |
| 77 pending_get_render_view_callbacks_.clear(); | 127 pending_get_render_view_callbacks_.clear(); |
| 78 } | 128 } |
| 79 | 129 |
| 80 BrowserPluginGuestManager* | 130 BrowserPluginGuestManager* |
| 81 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { | 131 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { |
| 82 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>( | 132 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 if (guest) | 178 if (guest) |
| 129 render_view_host = guest->GetWebContents()->GetRenderViewHost(); | 179 render_view_host = guest->GetWebContents()->GetRenderViewHost(); |
| 130 else // No plugin, use embedder's RenderViewHost. | 180 else // No plugin, use embedder's RenderViewHost. |
| 131 render_view_host = web_contents()->GetRenderViewHost(); | 181 render_view_host = web_contents()->GetRenderViewHost(); |
| 132 | 182 |
| 133 callback_iter->second.Run(render_view_host, position.x(), position.y()); | 183 callback_iter->second.Run(render_view_host, position.x(), position.y()); |
| 134 pending_get_render_view_callbacks_.erase(callback_iter); | 184 pending_get_render_view_callbacks_.erase(callback_iter); |
| 135 } | 185 } |
| 136 | 186 |
| 137 } // namespace content | 187 } // namespace content |
| OLD | NEW |