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 "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" | |
| 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/common/browser_plugin/browser_plugin_constants.h" | 12 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 14 #include "content/common/browser_plugin/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 15 #include "content/common/drag_messages.h" | 14 #include "content/common/drag_messages.h" |
| 16 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
| 17 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_plugin_guest_manager_delegate.h" | |
| 18 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
| 19 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 } | 59 } |
| 60 | 60 |
| 61 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { | 61 void BrowserPluginEmbedder::StartDrag(BrowserPluginGuest* guest) { |
| 62 guest_started_drag_ = guest->AsWeakPtr(); | 62 guest_started_drag_ = guest->AsWeakPtr(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const { | 65 WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const { |
| 66 return static_cast<WebContentsImpl*>(web_contents()); | 66 return static_cast<WebContentsImpl*>(web_contents()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 BrowserPluginGuestManager* | 69 BrowserPluginGuestManagerDelegate* |
| 70 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const { | 70 BrowserPluginEmbedder::GetBrowserPluginGuestManager() const { |
| 71 return BrowserPluginGuestManager::FromBrowserContext( | 71 return GetWebContents()->GetBrowserContext()->GetGuestManagerDelegate(); |
| 72 GetWebContents()->GetBrowserContext()); | |
| 73 } | 72 } |
| 74 | 73 |
| 75 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( | 74 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( |
| 76 BrowserPluginGuest* guest) { | 75 WebContents* guest_web_contents) { |
| 77 static_cast<RenderViewHostImpl*>( | 76 static_cast<RenderViewHostImpl*>( |
| 78 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); | 77 guest_web_contents->GetRenderViewHost())->SendScreenRects(); |
| 79 // Not handled => Iterate over all guests. | 78 // Not handled => Iterate over all guests. |
| 80 return false; | 79 return false; |
| 81 } | 80 } |
| 82 | 81 |
| 83 void BrowserPluginEmbedder::DidSendScreenRects() { | 82 void BrowserPluginEmbedder::DidSendScreenRects() { |
| 84 BrowserPluginGuestManager::FromBrowserContext( | 83 GetBrowserPluginGuestManager()->ForEachGuest( |
| 85 GetWebContents()->GetBrowserContext())->ForEachGuest( | |
| 86 GetWebContents(), base::Bind( | 84 GetWebContents(), base::Bind( |
| 87 &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 85 &BrowserPluginEmbedder::DidSendScreenRectsCallback, |
| 88 base::Unretained(this))); | 86 base::Unretained(this))); |
| 89 } | 87 } |
| 90 | 88 |
| 91 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( | 89 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( |
| 92 const NativeWebKeyboardEvent& event, | 90 const NativeWebKeyboardEvent& event, |
| 93 BrowserPluginGuest* guest) { | 91 WebContents* guest_web_contents) { |
| 94 return guest->UnlockMouseIfNecessary(event); | 92 return static_cast<WebContentsImpl*>(guest_web_contents)-> |
| 93 GetBrowserPluginGuest()->UnlockMouseIfNecessary(event); | |
| 95 } | 94 } |
| 96 | 95 |
| 97 bool BrowserPluginEmbedder::HandleKeyboardEvent( | 96 bool BrowserPluginEmbedder::HandleKeyboardEvent( |
| 98 const NativeWebKeyboardEvent& event) { | 97 const NativeWebKeyboardEvent& event) { |
| 99 if ((event.type != blink::WebInputEvent::RawKeyDown) || | 98 if ((event.type != blink::WebInputEvent::RawKeyDown) || |
| 100 (event.windowsKeyCode != ui::VKEY_ESCAPE) || | 99 (event.windowsKeyCode != ui::VKEY_ESCAPE) || |
| 101 (event.modifiers & blink::WebInputEvent::InputModifiers)) { | 100 (event.modifiers & blink::WebInputEvent::InputModifiers)) { |
| 102 return false; | 101 return false; |
| 103 } | 102 } |
| 104 | 103 |
| 105 return GetBrowserPluginGuestManager()->ForEachGuest( | 104 return GetBrowserPluginGuestManager()->ForEachGuest( |
| 106 GetWebContents(), | 105 GetWebContents(), |
| 107 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, | 106 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, |
| 108 base::Unretained(this), | 107 base::Unretained(this), |
| 109 event)); | 108 event)); |
| 110 } | 109 } |
| 111 | 110 |
| 112 bool BrowserPluginEmbedder::SetZoomLevelCallback( | 111 bool BrowserPluginEmbedder::SetZoomLevelCallback( |
| 113 double level, BrowserPluginGuest* guest) { | 112 double level, WebContents* guest_web_contents) { |
| 114 double zoom_factor = content::ZoomLevelToZoomFactor(level); | 113 double zoom_factor = content::ZoomLevelToZoomFactor(level); |
| 115 guest->SetZoom(zoom_factor); | 114 static_cast<WebContentsImpl*>(guest_web_contents)->GetBrowserPluginGuest()-> |
| 115 SetZoom(zoom_factor); | |
| 116 // Not handled => Iterate over all guests. | 116 // Not handled => Iterate over all guests. |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void BrowserPluginEmbedder::SetZoomLevel(double level) { | 120 void BrowserPluginEmbedder::SetZoomLevel(double level) { |
| 121 GetBrowserPluginGuestManager()->ForEachGuest( | 121 GetBrowserPluginGuestManager()->ForEachGuest( |
| 122 GetWebContents(), base::Bind( | 122 GetWebContents(), base::Bind( |
| 123 &BrowserPluginEmbedder::SetZoomLevelCallback, | 123 &BrowserPluginEmbedder::SetZoomLevelCallback, |
| 124 base::Unretained(this), | 124 base::Unretained(this), |
| 125 level)); | 125 level)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { | 165 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { |
| 166 int instance_id = GetBrowserPluginGuestManager()->GetNextInstanceID(); | 166 int instance_id = GetBrowserPluginGuestManager()->GetNextInstanceID(); |
| 167 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | 167 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( |
| 168 routing_id(), request_id, instance_id)); | 168 routing_id(), request_id, instance_id)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void BrowserPluginEmbedder::GuestCallback( | 171 void BrowserPluginEmbedder::GuestCallback( |
| 172 int instance_id, | 172 int instance_id, |
| 173 const BrowserPluginHostMsg_Attach_Params& params, | 173 const BrowserPluginHostMsg_Attach_Params& params, |
| 174 const base::DictionaryValue* extra_params, | 174 const base::DictionaryValue* extra_params, |
| 175 BrowserPluginGuest* guest) { | 175 WebContents* guest_web_contents) { |
| 176 BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager(); | 176 BrowserPluginGuest* guest = guest_web_contents ? |
| 177 static_cast<WebContentsImpl*>(guest_web_contents)-> | |
| 178 GetBrowserPluginGuest() : NULL; | |
| 179 BrowserPluginGuestManagerDelegate* guest_manager = | |
|
lazyboy
2014/05/05 21:40:54
Declare this close to where you use it.
Fady Samuel
2014/05/07 17:32:59
Removed entirely.
| |
| 180 GetBrowserPluginGuestManager(); | |
| 177 if (guest) { | 181 if (guest) { |
| 178 // There is an implicit order expectation here: | 182 // There is an implicit order expectation here: |
| 179 // 1. The content embedder is made aware of the attachment. | 183 // 1. The content embedder is made aware of the attachment. |
| 180 // 2. BrowserPluginGuest::Attach is called. | 184 // 2. BrowserPluginGuest::Attach is called. |
| 181 // 3. The content embedder issues queued events if any that happened | 185 // 3. The content embedder issues queued events if any that happened |
| 182 // prior to attachment. | 186 // prior to attachment. |
| 183 GetContentClient()->browser()->GuestWebContentsAttached( | 187 GetContentClient()->browser()->GuestWebContentsAttached( |
| 184 guest->GetWebContents(), | 188 guest->GetWebContents(), |
| 185 GetWebContents(), | 189 GetWebContents(), |
| 186 *extra_params); | 190 *extra_params); |
| 187 guest->Attach(GetWebContents(), params, *extra_params); | 191 guest->Attach(GetWebContents(), params, *extra_params); |
| 188 return; | 192 return; |
| 189 } | 193 } |
| 190 | 194 |
| 191 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy()); | 195 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy()); |
| 192 StorageInfo storage_info; | 196 StorageInfo storage_info; |
| 193 storage_info.partition_id = params.storage_partition_id; | 197 storage_info.partition_id = params.storage_partition_id; |
| 194 storage_info.persist = params.persist_storage; | 198 storage_info.persist = params.persist_storage; |
| 195 guest = guest_manager->CreateGuest( | 199 guest_web_contents = guest_manager->CreateGuest( |
| 196 GetWebContents()->GetSiteInstance(), | 200 GetWebContents()->GetSiteInstance(), |
| 197 instance_id, storage_info, | 201 instance_id, storage_info, |
| 198 copy_extra_params.Pass()); | 202 copy_extra_params.Pass()); |
| 203 guest = guest_web_contents ? | |
| 204 static_cast<WebContentsImpl*>(guest_web_contents)-> | |
| 205 GetBrowserPluginGuest() : NULL; | |
| 199 if (guest) { | 206 if (guest) { |
| 200 GetContentClient()->browser()->GuestWebContentsAttached( | 207 GetContentClient()->browser()->GuestWebContentsAttached( |
| 201 guest->GetWebContents(), | 208 guest->GetWebContents(), |
| 202 GetWebContents(), | 209 GetWebContents(), |
| 203 *extra_params); | 210 *extra_params); |
| 204 guest->Initialize(params, GetWebContents()); | 211 guest->Initialize(params, GetWebContents()); |
| 205 } | 212 } |
| 206 } | 213 } |
| 207 | 214 |
| 208 void BrowserPluginEmbedder::OnAttach( | 215 void BrowserPluginEmbedder::OnAttach( |
| 209 int instance_id, | 216 int instance_id, |
| 210 const BrowserPluginHostMsg_Attach_Params& params, | 217 const BrowserPluginHostMsg_Attach_Params& params, |
| 211 const base::DictionaryValue& extra_params) { | 218 const base::DictionaryValue& extra_params) { |
| 212 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( | 219 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( |
| 213 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), | 220 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), |
| 214 base::Bind(&BrowserPluginEmbedder::GuestCallback, | 221 base::Bind(&BrowserPluginEmbedder::GuestCallback, |
| 215 base::Unretained(this), | 222 base::Unretained(this), |
| 216 instance_id, | 223 instance_id, |
| 217 params, | 224 params, |
| 218 &extra_params)); | 225 &extra_params)); |
| 219 } | 226 } |
| 220 | 227 |
| 221 } // namespace content | 228 } // namespace content |
| OLD | NEW |