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