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::OnGuestCallback( | 171 void BrowserPluginEmbedder::OnGuestCallback( |
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; |
177 if (guest) { | 179 if (guest) { |
178 // There is an implicit order expectation here: | 180 // There is an implicit order expectation here: |
179 // 1. The content embedder is made aware of the attachment. | 181 // 1. The content embedder is made aware of the attachment. |
180 // 2. BrowserPluginGuest::Attach is called. | 182 // 2. BrowserPluginGuest::Attach is called. |
181 // 3. The content embedder issues queued events if any that happened | 183 // 3. The content embedder issues queued events if any that happened |
182 // prior to attachment. | 184 // prior to attachment. |
183 GetContentClient()->browser()->GuestWebContentsAttached( | 185 GetContentClient()->browser()->GuestWebContentsAttached( |
184 guest->GetWebContents(), | 186 guest->GetWebContents(), |
185 GetWebContents(), | 187 GetWebContents(), |
186 *extra_params); | 188 *extra_params); |
187 guest->Attach(GetWebContents(), params, *extra_params); | 189 guest->Attach(GetWebContents(), params, *extra_params); |
188 return; | 190 return; |
189 } | 191 } |
190 | 192 |
191 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy()); | 193 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy()); |
192 guest = guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(), | 194 guest_web_contents = GetBrowserPluginGuestManager()->CreateGuest( |
193 instance_id, | 195 GetWebContents()->GetSiteInstance(), |
194 params.storage_partition_id, | 196 instance_id, |
195 params.persist_storage, | 197 params.storage_partition_id, |
196 copy_extra_params.Pass()); | 198 params.persist_storage, |
| 199 copy_extra_params.Pass()); |
| 200 guest = guest_web_contents ? |
| 201 static_cast<WebContentsImpl*>(guest_web_contents)-> |
| 202 GetBrowserPluginGuest() : NULL; |
197 if (guest) { | 203 if (guest) { |
198 GetContentClient()->browser()->GuestWebContentsAttached( | 204 GetContentClient()->browser()->GuestWebContentsAttached( |
199 guest->GetWebContents(), | 205 guest->GetWebContents(), |
200 GetWebContents(), | 206 GetWebContents(), |
201 *extra_params); | 207 *extra_params); |
202 guest->Initialize(params, GetWebContents()); | 208 guest->Initialize(params, GetWebContents()); |
203 } | 209 } |
204 } | 210 } |
205 | 211 |
206 void BrowserPluginEmbedder::OnAttach( | 212 void BrowserPluginEmbedder::OnAttach( |
207 int instance_id, | 213 int instance_id, |
208 const BrowserPluginHostMsg_Attach_Params& params, | 214 const BrowserPluginHostMsg_Attach_Params& params, |
209 const base::DictionaryValue& extra_params) { | 215 const base::DictionaryValue& extra_params) { |
210 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( | 216 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( |
211 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), | 217 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), |
212 base::Bind(&BrowserPluginEmbedder::OnGuestCallback, | 218 base::Bind(&BrowserPluginEmbedder::OnGuestCallback, |
213 base::Unretained(this), | 219 base::Unretained(this), |
214 instance_id, | 220 instance_id, |
215 params, | 221 params, |
216 &extra_params)); | 222 &extra_params)); |
217 } | 223 } |
218 | 224 |
219 } // namespace content | 225 } // namespace content |
OLD | NEW |