| 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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Store the callback so we can call it later when we have the response. | 74 // Store the callback so we can call it later when we have the response. |
| 75 pending_get_render_view_callbacks_.insert( | 75 pending_get_render_view_callbacks_.insert( |
| 76 std::make_pair(next_get_render_view_request_id_, callback)); | 76 std::make_pair(next_get_render_view_request_id_, callback)); |
| 77 Send(new BrowserPluginMsg_PluginAtPositionRequest( | 77 Send(new BrowserPluginMsg_PluginAtPositionRequest( |
| 78 routing_id(), | 78 routing_id(), |
| 79 next_get_render_view_request_id_, | 79 next_get_render_view_request_id_, |
| 80 gfx::Point(x, y))); | 80 gfx::Point(x, y))); |
| 81 ++next_get_render_view_request_id_; | 81 ++next_get_render_view_request_id_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() { |
| 85 return static_cast<WebContentsImpl*>(web_contents()); |
| 86 } |
| 87 |
| 84 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( | 88 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( |
| 85 BrowserPluginGuest* guest) { | 89 BrowserPluginGuest* guest) { |
| 86 static_cast<RenderViewHostImpl*>( | 90 static_cast<RenderViewHostImpl*>( |
| 87 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); | 91 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); |
| 88 // Not handled => Iterate over all guests. | 92 // Not handled => Iterate over all guests. |
| 89 return false; | 93 return false; |
| 90 } | 94 } |
| 91 | 95 |
| 92 void BrowserPluginEmbedder::DidSendScreenRects() { | 96 void BrowserPluginEmbedder::DidSendScreenRects() { |
| 93 WebContentsImpl* embedder = | 97 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( |
| 94 static_cast<WebContentsImpl*>(web_contents()); | |
| 95 GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind( | |
| 96 &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 98 &BrowserPluginEmbedder::DidSendScreenRectsCallback, |
| 97 base::Unretained(this))); | 99 base::Unretained(this))); |
| 98 } | 100 } |
| 99 | 101 |
| 100 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( | 102 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( |
| 101 const NativeWebKeyboardEvent& event, | 103 const NativeWebKeyboardEvent& event, |
| 102 BrowserPluginGuest* guest) { | 104 BrowserPluginGuest* guest) { |
| 103 return guest->UnlockMouseIfNecessary(event); | 105 return guest->UnlockMouseIfNecessary(event); |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool BrowserPluginEmbedder::HandleKeyboardEvent( | 108 bool BrowserPluginEmbedder::HandleKeyboardEvent( |
| 107 const NativeWebKeyboardEvent& event) { | 109 const NativeWebKeyboardEvent& event) { |
| 108 if ((event.type != blink::WebInputEvent::RawKeyDown) || | 110 if ((event.type != blink::WebInputEvent::RawKeyDown) || |
| 109 (event.windowsKeyCode != ui::VKEY_ESCAPE) || | 111 (event.windowsKeyCode != ui::VKEY_ESCAPE) || |
| 110 (event.modifiers & blink::WebInputEvent::InputModifiers)) { | 112 (event.modifiers & blink::WebInputEvent::InputModifiers)) { |
| 111 return false; | 113 return false; |
| 112 } | 114 } |
| 113 | 115 |
| 114 WebContentsImpl* embedder = | 116 return GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), |
| 115 static_cast<WebContentsImpl*>(web_contents()); | 117 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, |
| 116 return GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind( | 118 base::Unretained(this), |
| 117 &BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, | 119 event)); |
| 118 base::Unretained(this), | |
| 119 event)); | |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool BrowserPluginEmbedder::SetZoomLevelCallback( | 122 bool BrowserPluginEmbedder::SetZoomLevelCallback( |
| 123 double level, BrowserPluginGuest* guest) { | 123 double level, BrowserPluginGuest* guest) { |
| 124 guest->GetWebContents()->SetZoomLevel(level); | 124 guest->GetWebContents()->SetZoomLevel(level); |
| 125 // Not handled => Iterate over all guests. | 125 // Not handled => Iterate over all guests. |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void BrowserPluginEmbedder::SetZoomLevel(double level) { | 129 void BrowserPluginEmbedder::SetZoomLevel(double level) { |
| 130 WebContentsImpl* embedder = | 130 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( |
| 131 static_cast<WebContentsImpl*>(web_contents()); | |
| 132 GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind( | |
| 133 &BrowserPluginEmbedder::SetZoomLevelCallback, | 131 &BrowserPluginEmbedder::SetZoomLevelCallback, |
| 134 base::Unretained(this), | 132 base::Unretained(this), |
| 135 level)); | 133 level)); |
| 136 } | 134 } |
| 137 | 135 |
| 138 void BrowserPluginEmbedder::RenderProcessGone(base::TerminationStatus status) { | 136 void BrowserPluginEmbedder::RenderProcessGone(base::TerminationStatus status) { |
| 139 CleanUp(); | 137 CleanUp(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 140 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 186 |
| 189 void BrowserPluginEmbedder::CleanUp() { | 187 void BrowserPluginEmbedder::CleanUp() { |
| 190 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away | 188 // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away |
| 191 // or the associated RenderViewHost is destroyed or swapped out. Therefore we | 189 // or the associated RenderViewHost is destroyed or swapped out. Therefore we |
| 192 // don't need to care about the pending callbacks anymore. | 190 // don't need to care about the pending callbacks anymore. |
| 193 pending_get_render_view_callbacks_.clear(); | 191 pending_get_render_view_callbacks_.clear(); |
| 194 } | 192 } |
| 195 | 193 |
| 196 BrowserPluginGuestManager* | 194 BrowserPluginGuestManager* |
| 197 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { | 195 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { |
| 198 BrowserPluginGuestManager* guest_manager = static_cast<WebContentsImpl*>( | 196 BrowserPluginGuestManager* guest_manager = |
| 199 web_contents())->GetBrowserPluginGuestManager(); | 197 GetWebContents()->GetBrowserPluginGuestManager(); |
| 200 if (!guest_manager) { | 198 if (!guest_manager) { |
| 201 guest_manager = BrowserPluginGuestManager::Create(); | 199 guest_manager = BrowserPluginGuestManager::Create(); |
| 202 web_contents()->GetBrowserContext()->SetUserData( | 200 GetWebContents()->GetBrowserContext()->SetUserData( |
| 203 browser_plugin::kBrowserPluginGuestManagerKeyName, guest_manager); | 201 browser_plugin::kBrowserPluginGuestManagerKeyName, guest_manager); |
| 204 } | 202 } |
| 205 return guest_manager; | 203 return guest_manager; |
| 206 } | 204 } |
| 207 | 205 |
| 208 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { | 206 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { |
| 209 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id(); | 207 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id(); |
| 210 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | 208 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( |
| 211 routing_id(), request_id, instance_id)); | 209 routing_id(), request_id, instance_id)); |
| 212 } | 210 } |
| 213 | 211 |
| 214 void BrowserPluginEmbedder::OnAttach( | 212 void BrowserPluginEmbedder::OnAttach( |
| 215 int instance_id, | 213 int instance_id, |
| 216 const BrowserPluginHostMsg_Attach_Params& params, | 214 const BrowserPluginHostMsg_Attach_Params& params, |
| 217 const base::DictionaryValue& extra_params) { | 215 const base::DictionaryValue& extra_params) { |
| 218 if (!GetBrowserPluginGuestManager()->CanEmbedderAccessInstanceIDMaybeKill( | 216 if (!GetBrowserPluginGuestManager()->CanEmbedderAccessInstanceIDMaybeKill( |
| 219 web_contents()->GetRenderProcessHost()->GetID(), instance_id)) | 217 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id)) |
| 220 return; | 218 return; |
| 221 | 219 |
| 222 BrowserPluginGuest* guest = | 220 BrowserPluginGuest* guest = |
| 223 GetBrowserPluginGuestManager()->GetGuestByInstanceID( | 221 GetBrowserPluginGuestManager()->GetGuestByInstanceID( |
| 224 instance_id, web_contents()->GetRenderProcessHost()->GetID()); | 222 instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); |
| 225 | 223 |
| 226 if (guest) { | 224 if (guest) { |
| 227 // There is an implicit order expectation here: | 225 // There is an implicit order expectation here: |
| 228 // 1. The content embedder is made aware of the attachment. | 226 // 1. The content embedder is made aware of the attachment. |
| 229 // 2. BrowserPluginGuest::Attach is called. | 227 // 2. BrowserPluginGuest::Attach is called. |
| 230 // 3. The content embedder issues queued events if any that happened | 228 // 3. The content embedder issues queued events if any that happened |
| 231 // prior to attachment. | 229 // prior to attachment. |
| 232 GetContentClient()->browser()->GuestWebContentsAttached( | 230 GetContentClient()->browser()->GuestWebContentsAttached( |
| 233 guest->GetWebContents(), | 231 guest->GetWebContents(), |
| 234 web_contents(), | 232 GetWebContents(), |
| 235 extra_params); | 233 extra_params); |
| 236 guest->Attach( | 234 guest->Attach(GetWebContents(), params, extra_params); |
| 237 static_cast<WebContentsImpl*>(web_contents()), params, extra_params); | |
| 238 return; | 235 return; |
| 239 } | 236 } |
| 240 | 237 |
| 241 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); | 238 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); |
| 242 guest = GetBrowserPluginGuestManager()->CreateGuest( | 239 guest = GetBrowserPluginGuestManager()->CreateGuest( |
| 243 web_contents()->GetSiteInstance(), | 240 GetWebContents()->GetSiteInstance(), |
| 244 instance_id, params, | 241 instance_id, params, |
| 245 copy_extra_params.Pass()); | 242 copy_extra_params.Pass()); |
| 246 if (guest) { | 243 if (guest) { |
| 247 GetContentClient()->browser()->GuestWebContentsAttached( | 244 GetContentClient()->browser()->GuestWebContentsAttached( |
| 248 guest->GetWebContents(), | 245 guest->GetWebContents(), |
| 249 web_contents(), | 246 GetWebContents(), |
| 250 extra_params); | 247 extra_params); |
| 251 guest->Initialize(params, static_cast<WebContentsImpl*>(web_contents())); | 248 guest->Initialize(params, GetWebContents()); |
| 252 } | 249 } |
| 253 } | 250 } |
| 254 | 251 |
| 255 void BrowserPluginEmbedder::OnPluginAtPositionResponse( | 252 void BrowserPluginEmbedder::OnPluginAtPositionResponse( |
| 256 int instance_id, int request_id, const gfx::Point& position) { | 253 int instance_id, int request_id, const gfx::Point& position) { |
| 257 const std::map<int, WebContents::GetRenderViewHostCallback>::iterator | 254 const std::map<int, WebContents::GetRenderViewHostCallback>::iterator |
| 258 callback_iter = pending_get_render_view_callbacks_.find(request_id); | 255 callback_iter = pending_get_render_view_callbacks_.find(request_id); |
| 259 if (callback_iter == pending_get_render_view_callbacks_.end()) | 256 if (callback_iter == pending_get_render_view_callbacks_.end()) |
| 260 return; | 257 return; |
| 261 | 258 |
| 262 RenderViewHost* render_view_host; | 259 RenderViewHost* render_view_host; |
| 263 BrowserPluginGuest* guest = NULL; | 260 BrowserPluginGuest* guest = NULL; |
| 264 if (instance_id != browser_plugin::kInstanceIDNone) { | 261 if (instance_id != browser_plugin::kInstanceIDNone) { |
| 265 guest = GetBrowserPluginGuestManager()->GetGuestByInstanceID( | 262 guest = GetBrowserPluginGuestManager()->GetGuestByInstanceID( |
| 266 instance_id, web_contents()->GetRenderProcessHost()->GetID()); | 263 instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); |
| 267 } | 264 } |
| 268 | 265 |
| 269 if (guest) | 266 if (guest) |
| 270 render_view_host = guest->GetWebContents()->GetRenderViewHost(); | 267 render_view_host = guest->GetWebContents()->GetRenderViewHost(); |
| 271 else // No plugin, use embedder's RenderViewHost. | 268 else // No plugin, use embedder's RenderViewHost. |
| 272 render_view_host = web_contents()->GetRenderViewHost(); | 269 render_view_host = GetWebContents()->GetRenderViewHost(); |
| 273 | 270 |
| 274 callback_iter->second.Run(render_view_host, position.x(), position.y()); | 271 callback_iter->second.Run(render_view_host, position.x(), position.y()); |
| 275 pending_get_render_view_callbacks_.erase(callback_iter); | 272 pending_get_render_view_callbacks_.erase(callback_iter); |
| 276 } | 273 } |
| 277 | 274 |
| 278 } // namespace content | 275 } // namespace content |
| OLD | NEW |