Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder.cc

Issue 12086095: Fixed drag and drop into and out of Browser Plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Splitting up patch Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_PluginAtPositionResponse, 88 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse,
66 OnPluginAtPositionResponse) 89 OnPluginAtPositionResponse)
90 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor,
91 OnUpdateDragCursor(&handled));
67 IPC_MESSAGE_UNHANDLED(handled = false) 92 IPC_MESSAGE_UNHANDLED(handled = false)
68 IPC_END_MESSAGE_MAP() 93 IPC_END_MESSAGE_MAP()
69 return handled; 94 return handled;
70 } 95 }
71 96
97 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y,
98 int screen_x, int screen_y, WebKit::WebDragOperation operation) {
99 if (guest_started_drag_) {
100 gfx::Point guest_offset =
101 guest_started_drag_->GetScreenCoordinates(gfx::Point());
102 guest_started_drag_->DragSourceEndedAt(client_x - guest_offset.x(),
103 client_y - guest_offset.y(), screen_x, screen_y, operation);
104 }
105 }
106
107 void BrowserPluginEmbedder::DragSourceMovedTo(int client_x, int client_y,
108 int screen_x, int screen_y) {
109 if (guest_started_drag_) {
110 gfx::Point guest_offset =
111 guest_started_drag_->GetScreenCoordinates(gfx::Point());
112 guest_started_drag_->DragSourceMovedTo(client_x - guest_offset.x(),
113 client_y - guest_offset.y(), screen_x, screen_y);
114 }
115 }
116
117 void BrowserPluginEmbedder::SystemDragEnded() {
118 if (guest_started_drag_ && (guest_started_drag_ != guest_dragging_over_))
119 guest_started_drag_->EndSystemDrag();
120 guest_started_drag_.reset();
121 guest_dragging_over_.reset();
122 }
123
124 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) {
125 *handled = (guest_dragging_over_ != NULL);
126 }
127
72 void BrowserPluginEmbedder::CleanUp() { 128 void BrowserPluginEmbedder::CleanUp() {
73 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away 129 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away
74 // or the associated RenderViewHost is destroyed or swapped out. Therefore we 130 // or the associated RenderViewHost is destroyed or swapped out. Therefore we
75 // don't need to care about the pending callbacks anymore. 131 // don't need to care about the pending callbacks anymore.
76 pending_get_render_view_callbacks_.clear(); 132 pending_get_render_view_callbacks_.clear();
77 } 133 }
78 134
79 BrowserPluginGuestManager* 135 BrowserPluginGuestManager*
80 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { 136 BrowserPluginEmbedder::GetBrowserPluginGuestManager() {
81 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>( 137 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (guest) 186 if (guest)
131 render_view_host = guest->GetWebContents()->GetRenderViewHost(); 187 render_view_host = guest->GetWebContents()->GetRenderViewHost();
132 else // No plugin, use embedder's RenderViewHost. 188 else // No plugin, use embedder's RenderViewHost.
133 render_view_host = web_contents()->GetRenderViewHost(); 189 render_view_host = web_contents()->GetRenderViewHost();
134 190
135 callback_iter->second.Run(render_view_host, position.x(), position.y()); 191 callback_iter->second.Run(render_view_host, position.x(), position.y());
136 pending_get_render_view_callbacks_.erase(callback_iter); 192 pending_get_render_view_callbacks_.erase(callback_iter);
137 } 193 }
138 194
139 } // namespace content 195 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_embedder.h ('k') | content/browser/browser_plugin/browser_plugin_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698