OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/app_view/app_view_guest.h" | 5 #include "chrome/browser/guest_view/app_view/app_view_guest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/guest_view/app_view/app_view_constants.h" | 10 #include "chrome/browser/guest_view/app_view/app_view_constants.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 const std::string& embedder_extension_id, | 144 const std::string& embedder_extension_id, |
145 int embedder_render_process_id, | 145 int embedder_render_process_id, |
146 const base::DictionaryValue& create_params, | 146 const base::DictionaryValue& create_params, |
147 const WebContentsCreatedCallback& callback) { | 147 const WebContentsCreatedCallback& callback) { |
148 std::string app_id; | 148 std::string app_id; |
149 if (!create_params.GetString(appview::kAppID, &app_id)) { | 149 if (!create_params.GetString(appview::kAppID, &app_id)) { |
150 callback.Run(NULL); | 150 callback.Run(NULL); |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
| 154 const base::DictionaryValue* params = NULL; |
| 155 if (!create_params.GetDictionary(appview::kParams, ¶ms)) { |
| 156 callback.Run(NULL); |
| 157 return; |
| 158 } |
| 159 |
154 ExtensionService* service = | 160 ExtensionService* service = |
155 ExtensionSystem::Get(browser_context())->extension_service(); | 161 ExtensionSystem::Get(browser_context())->extension_service(); |
156 const Extension* guest_extension = service->GetExtensionById(app_id, false); | 162 const Extension* guest_extension = service->GetExtensionById(app_id, false); |
157 const Extension* embedder_extension = | 163 const Extension* embedder_extension = |
158 service->GetExtensionById(embedder_extension_id, false); | 164 service->GetExtensionById(embedder_extension_id, false); |
159 | 165 |
160 if (!guest_extension || !guest_extension->is_platform_app() || | 166 if (!guest_extension || !guest_extension->is_platform_app() || |
161 !embedder_extension | !embedder_extension->is_platform_app()) { | 167 !embedder_extension | !embedder_extension->is_platform_app()) { |
162 callback.Run(NULL); | 168 callback.Run(NULL); |
163 return; | 169 return; |
164 } | 170 } |
165 | 171 |
166 pending_response_map.Get().insert( | 172 pending_response_map.Get().insert( |
167 std::make_pair(GetGuestInstanceID(), | 173 std::make_pair(GetGuestInstanceID(), |
168 make_linked_ptr(new ResponseInfo( | 174 make_linked_ptr(new ResponseInfo( |
169 guest_extension, | 175 guest_extension, |
170 weak_ptr_factory_.GetWeakPtr(), | 176 weak_ptr_factory_.GetWeakPtr(), |
171 callback)))); | 177 callback)))); |
172 | 178 |
173 LazyBackgroundTaskQueue* queue = | 179 LazyBackgroundTaskQueue* queue = |
174 ExtensionSystem::Get(browser_context())->lazy_background_task_queue(); | 180 ExtensionSystem::Get(browser_context())->lazy_background_task_queue(); |
175 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { | 181 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { |
176 queue->AddPendingTask(browser_context(), | 182 queue->AddPendingTask(browser_context(), |
177 guest_extension->id(), | 183 guest_extension->id(), |
178 base::Bind(&AppViewGuest::LaunchAppAndFireEvent, | 184 base::Bind( |
179 weak_ptr_factory_.GetWeakPtr(), | 185 &AppViewGuest::LaunchAppAndFireEvent, |
180 callback)); | 186 weak_ptr_factory_.GetWeakPtr(), |
| 187 base::Passed(make_scoped_ptr(params->DeepCopy())), |
| 188 callback)); |
181 return; | 189 return; |
182 } | 190 } |
183 | 191 |
184 ProcessManager* process_manager = | 192 ProcessManager* process_manager = |
185 ExtensionSystem::Get(browser_context())->process_manager(); | 193 ExtensionSystem::Get(browser_context())->process_manager(); |
186 ExtensionHost* host = | 194 ExtensionHost* host = |
187 process_manager->GetBackgroundHostForExtension(guest_extension->id()); | 195 process_manager->GetBackgroundHostForExtension(guest_extension->id()); |
188 DCHECK(host); | 196 DCHECK(host); |
189 LaunchAppAndFireEvent(callback, host); | 197 LaunchAppAndFireEvent(make_scoped_ptr(params->DeepCopy()), callback, host); |
190 } | 198 } |
191 | 199 |
192 void AppViewGuest::DidAttachToEmbedder() { | 200 void AppViewGuest::DidAttachToEmbedder() { |
193 // This is called after the guest process has been attached to a host | 201 // This is called after the guest process has been attached to a host |
194 // element. This means that the host element knows how to route input | 202 // element. This means that the host element knows how to route input |
195 // events to the guest, and the guest knows how to get frames to the | 203 // events to the guest, and the guest knows how to get frames to the |
196 // embedder. | 204 // embedder. |
197 guest_web_contents()->GetController().LoadURL( | 205 guest_web_contents()->GetController().LoadURL( |
198 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 206 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
199 } | 207 } |
(...skipping 21 matching lines...) Expand all Loading... |
221 | 229 |
222 WebContents::CreateParams params( | 230 WebContents::CreateParams params( |
223 browser_context(), | 231 browser_context(), |
224 content::SiteInstance::CreateForURL(browser_context(), | 232 content::SiteInstance::CreateForURL(browser_context(), |
225 guest_extension->url())); | 233 guest_extension->url())); |
226 params.guest_delegate = this; | 234 params.guest_delegate = this; |
227 callback.Run(WebContents::Create(params)); | 235 callback.Run(WebContents::Create(params)); |
228 } | 236 } |
229 | 237 |
230 void AppViewGuest::LaunchAppAndFireEvent( | 238 void AppViewGuest::LaunchAppAndFireEvent( |
| 239 scoped_ptr<base::DictionaryValue> params, |
231 const WebContentsCreatedCallback& callback, | 240 const WebContentsCreatedCallback& callback, |
232 ExtensionHost* extension_host) { | 241 ExtensionHost* extension_host) { |
233 ExtensionSystem* system = ExtensionSystem::Get(browser_context()); | 242 ExtensionSystem* system = ExtensionSystem::Get(browser_context()); |
234 bool has_event_listener = system->event_router()->ExtensionHasEventListener( | 243 bool has_event_listener = system->event_router()->ExtensionHasEventListener( |
235 extension_host->extension()->id(), | 244 extension_host->extension()->id(), |
236 app_runtime::OnEmbedRequested::kEventName); | 245 app_runtime::OnEmbedRequested::kEventName); |
237 if (!has_event_listener) { | 246 if (!has_event_listener) { |
238 callback.Run(NULL); | 247 callback.Run(NULL); |
239 return; | 248 return; |
240 } | 249 } |
241 | 250 |
242 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); | 251 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); |
243 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); | 252 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); |
244 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); | 253 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); |
| 254 embed_request->Set(appview::kParams, params.release()); |
245 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 255 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
246 browser_context(), embed_request.Pass(), extension_host->extension()); | 256 browser_context(), embed_request.Pass(), extension_host->extension()); |
247 } | 257 } |
248 | 258 |
249 } // namespace extensions | 259 } // namespace extensions |
OLD | NEW |