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

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

Issue 258373002: Towards moving guest management to chrome: Introduce GuestViewManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android build Created 6 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 "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/browser_plugin/browser_plugin_guest_manager.h" 9 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
25 #include "net/base/escape.h" 25 #include "net/base/escape.h"
26 #include "ui/events/keycodes/keyboard_codes.h" 26 #include "ui/events/keycodes/keyboard_codes.h"
27 27
28 namespace content { 28 namespace content {
29 29
30 // static 30 // static
31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; 31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL;
32 32
33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) 33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents)
34 : WebContentsObserver(web_contents) { 34 : WebContentsObserver(web_contents),
35 weak_ptr_factory_(this) {
35 } 36 }
36 37
37 BrowserPluginEmbedder::~BrowserPluginEmbedder() { 38 BrowserPluginEmbedder::~BrowserPluginEmbedder() {
38 } 39 }
39 40
40 // static 41 // static
41 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( 42 BrowserPluginEmbedder* BrowserPluginEmbedder::Create(
42 WebContentsImpl* web_contents) { 43 WebContentsImpl* web_contents) {
43 if (factory_) 44 if (factory_)
44 return factory_->CreateBrowserPluginEmbedder(web_contents); 45 return factory_->CreateBrowserPluginEmbedder(web_contents);
45 return new BrowserPluginEmbedder(web_contents); 46 return new BrowserPluginEmbedder(web_contents);
46 } 47 }
47 48
48 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) { 49 void BrowserPluginEmbedder::DragEnteredGuest(BrowserPluginGuest* guest) {
49 guest_dragging_over_ = guest->AsWeakPtr(); 50 guest_dragging_over_ = guest->AsWeakPtr();
50 } 51 }
51 52
52 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) { 53 void BrowserPluginEmbedder::DragLeftGuest(BrowserPluginGuest* guest) {
53 // Avoid race conditions in switching between guests being hovered over by 54 // Avoid race conditions in switching between guests being hovered over by
54 // only un-setting if the caller is marked as the guest being dragged over. 55 // only un-setting if the caller is marked as the guest being dragged over.
55 if (guest_dragging_over_.get() == guest) { 56 if (guest_dragging_over_.get() == guest) {
56 guest_dragging_over_.reset(); 57 guest_dragging_over_.reset();
57 } 58 }
58 } 59 }
59 60
60 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { 61 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) {
61 guest_started_drag_ = guest->AsWeakPtr(); 62 guest_started_drag_ = guest->AsWeakPtr();
62 } 63 }
63 64
64 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() { 65 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const {
65 return static_cast<WebContentsImpl*>(web_contents()); 66 return static_cast<WebContentsImpl*>(web_contents());
66 } 67 }
67 68
69 BrowserPluginGuestManager*
70 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const {
71 return BrowserPluginGuestManager::FromBrowserContext(
72 GetWebContents()->GetBrowserContext());
73 }
74
68 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( 75 bool BrowserPluginEmbedder::DidSendScreenRectsCallback(
69 BrowserPluginGuest* guest) { 76 BrowserPluginGuest* guest) {
70 static_cast<RenderViewHostImpl*>( 77 static_cast<RenderViewHostImpl*>(
71 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); 78 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects();
72 // Not handled => Iterate over all guests. 79 // Not handled => Iterate over all guests.
73 return false; 80 return false;
74 } 81 }
75 82
76 void BrowserPluginEmbedder::DidSendScreenRects() { 83 void BrowserPluginEmbedder::DidSendScreenRects() {
77 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( 84 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind(
78 &BrowserPluginEmbedder::DidSendScreenRectsCallback, 85 &BrowserPluginEmbedder::DidSendScreenRectsCallback,
79 base::Unretained(this))); 86 base::Unretained(this)));
80 } 87 }
81 88
82 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( 89 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback(
83 const NativeWebKeyboardEvent& event, 90 const NativeWebKeyboardEvent& event,
84 BrowserPluginGuest* guest) { 91 BrowserPluginGuest* guest) {
85 return guest->UnlockMouseIfNecessary(event); 92 return guest->UnlockMouseIfNecessary(event);
86 } 93 }
87 94
88 bool BrowserPluginEmbedder::HandleKeyboardEvent( 95 bool BrowserPluginEmbedder::HandleKeyboardEvent(
89 const NativeWebKeyboardEvent& event) { 96 const NativeWebKeyboardEvent& event) {
90 if ((event.type != blink::WebInputEvent::RawKeyDown) || 97 if ((event.type != blink::WebInputEvent::RawKeyDown) ||
91 (event.windowsKeyCode != ui::VKEY_ESCAPE) || 98 (event.windowsKeyCode != ui::VKEY_ESCAPE) ||
92 (event.modifiers & blink::WebInputEvent::InputModifiers)) { 99 (event.modifiers & blink::WebInputEvent::InputModifiers)) {
93 return false; 100 return false;
94 } 101 }
95 102
96 return GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), 103 return GetBrowserPluginGuestManager()->ForEachGuest(
104 GetWebContents(),
97 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, 105 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback,
98 base::Unretained(this), 106 base::Unretained(this),
99 event)); 107 event));
100 } 108 }
101 109
102 bool BrowserPluginEmbedder::SetZoomLevelCallback( 110 bool BrowserPluginEmbedder::SetZoomLevelCallback(
103 double level, BrowserPluginGuest* guest) { 111 double level, BrowserPluginGuest* guest) {
104 double zoom_factor = content::ZoomLevelToZoomFactor(level); 112 double zoom_factor = content::ZoomLevelToZoomFactor(level);
105 guest->SetZoom(zoom_factor); 113 guest->SetZoom(zoom_factor);
106 // Not handled => Iterate over all guests. 114 // Not handled => Iterate over all guests.
107 return false; 115 return false;
108 } 116 }
109 117
110 void BrowserPluginEmbedder::SetZoomLevel(double level) { 118 void BrowserPluginEmbedder::SetZoomLevel(double level) {
111 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( 119 GetBrowserPluginGuestManager()->ForEachGuest(
112 &BrowserPluginEmbedder::SetZoomLevelCallback, 120 GetWebContents(), base::Bind(
113 base::Unretained(this), 121 &BrowserPluginEmbedder::SetZoomLevelCallback,
114 level)); 122 base::Unretained(this),
123 level));
115 } 124 }
116 125
117 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { 126 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) {
118 bool handled = true; 127 bool handled = true;
119 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) 128 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message)
120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, 129 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID,
121 OnAllocateInstanceID) 130 OnAllocateInstanceID)
122 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) 131 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach)
123 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, 132 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor,
124 OnUpdateDragCursor(&handled)); 133 OnUpdateDragCursor(&handled));
(...skipping 19 matching lines...) Expand all
144 if (guest_started_drag_.get()) 153 if (guest_started_drag_.get())
145 guest_started_drag_->EndSystemDrag(); 154 guest_started_drag_->EndSystemDrag();
146 guest_started_drag_.reset(); 155 guest_started_drag_.reset();
147 guest_dragging_over_.reset(); 156 guest_dragging_over_.reset();
148 } 157 }
149 158
150 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { 159 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) {
151 *handled = (guest_dragging_over_.get() != NULL); 160 *handled = (guest_dragging_over_.get() != NULL);
152 } 161 }
153 162
154 BrowserPluginGuestManager*
155 BrowserPluginEmbedder::GetBrowserPluginGuestManager() {
156 BrowserPluginGuestManager* guest_manager =
157 GetWebContents()->GetBrowserPluginGuestManager();
158 if (!guest_manager) {
159 guest_manager = BrowserPluginGuestManager::Create();
160 GetWebContents()->GetBrowserContext()->SetUserData(
161 browser_plugin::kBrowserPluginGuestManagerKeyName, guest_manager);
162 }
163 return guest_manager;
164 }
165
166 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { 163 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) {
167 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id(); 164 int instance_id = GetBrowserPluginGuestManager()->GetNextInstanceID();
168 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( 165 Send(new BrowserPluginMsg_AllocateInstanceID_ACK(
169 routing_id(), request_id, instance_id)); 166 routing_id(), request_id, instance_id));
170 } 167 }
171 168
172 void BrowserPluginEmbedder::OnAttach( 169 void BrowserPluginEmbedder::OnAttach(
173 int instance_id, 170 int instance_id,
174 const BrowserPluginHostMsg_Attach_Params& params, 171 const BrowserPluginHostMsg_Attach_Params& params,
175 const base::DictionaryValue& extra_params) { 172 const base::DictionaryValue& extra_params) {
176 if (!GetBrowserPluginGuestManager()->CanEmbedderAccessInstanceIDMaybeKill( 173 BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager();
174 if (!guest_manager->CanEmbedderAccessInstanceIDMaybeKill(
177 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id)) 175 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id))
178 return; 176 return;
179 177
180 BrowserPluginGuest* guest = 178 BrowserPluginGuest* guest =
181 GetBrowserPluginGuestManager()->GetGuestByInstanceID( 179 guest_manager->GetGuestByInstanceID(
182 instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); 180 instance_id, GetWebContents()->GetRenderProcessHost()->GetID());
183 181
184 if (guest) { 182 if (guest) {
185 // There is an implicit order expectation here: 183 // There is an implicit order expectation here:
186 // 1. The content embedder is made aware of the attachment. 184 // 1. The content embedder is made aware of the attachment.
187 // 2. BrowserPluginGuest::Attach is called. 185 // 2. BrowserPluginGuest::Attach is called.
188 // 3. The content embedder issues queued events if any that happened 186 // 3. The content embedder issues queued events if any that happened
189 // prior to attachment. 187 // prior to attachment.
190 GetContentClient()->browser()->GuestWebContentsAttached( 188 GetContentClient()->browser()->GuestWebContentsAttached(
191 guest->GetWebContents(), 189 guest->GetWebContents(),
192 GetWebContents(), 190 GetWebContents(),
193 extra_params); 191 extra_params);
194 guest->Attach(GetWebContents(), params, extra_params); 192 guest->Attach(GetWebContents(), params, extra_params);
195 return; 193 return;
196 } 194 }
197 195
198 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); 196 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy());
199 guest = GetBrowserPluginGuestManager()->CreateGuest( 197 guest = guest_manager->CreateGuest(
200 GetWebContents()->GetSiteInstance(), 198 GetWebContents()->GetSiteInstance(),
201 instance_id, params, 199 instance_id, params,
202 copy_extra_params.Pass()); 200 copy_extra_params.Pass());
203 if (guest) { 201 if (guest) {
204 GetContentClient()->browser()->GuestWebContentsAttached( 202 GetContentClient()->browser()->GuestWebContentsAttached(
205 guest->GetWebContents(), 203 guest->GetWebContents(),
206 GetWebContents(), 204 GetWebContents(),
207 extra_params); 205 extra_params);
208 guest->Initialize(params, GetWebContents()); 206 guest->Initialize(params, GetWebContents());
209 } 207 }
210 } 208 }
211 209
212 } // namespace content 210 } // 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