| 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 "chrome/browser/extensions/platform_app_launcher.h" | 5 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" | 14 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
| 15 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
| 16 #include "chrome/browser/extensions/extension_process_manager.h" | 16 #include "chrome/browser/extensions/extension_process_manager.h" |
| 17 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
| 18 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 18 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_messages.h" | 21 #include "chrome/common/extensions/extension_messages.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/child_process_security_policy.h" | 23 #include "content/public/browser/child_process_security_policy.h" |
| 24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_intents_dispatcher.h" |
| 25 #include "net/base/mime_util.h" | 27 #include "net/base/mime_util.h" |
| 26 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 27 #include "webkit/fileapi/file_system_types.h" | 29 #include "webkit/fileapi/file_system_types.h" |
| 28 #include "webkit/fileapi/isolated_context.h" | 30 #include "webkit/fileapi/isolated_context.h" |
| 29 #include "webkit/glue/web_intent_data.h" | 31 #include "webkit/glue/web_intent_data.h" |
| 30 #include "webkit/glue/web_intent_service_data.h" | 32 #include "webkit/glue/web_intent_service_data.h" |
| 31 | 33 |
| 32 using content::BrowserThread; | 34 using content::BrowserThread; |
| 33 | 35 |
| 34 namespace extensions { | 36 namespace extensions { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 }; | 228 }; |
| 227 | 229 |
| 228 // Class to handle launching of platform apps with WebIntent data. | 230 // Class to handle launching of platform apps with WebIntent data. |
| 229 // An instance of this class is created for each launch. The lifetime of these | 231 // An instance of this class is created for each launch. The lifetime of these |
| 230 // instances is managed by reference counted pointers. As long as an instance | 232 // instances is managed by reference counted pointers. As long as an instance |
| 231 // has outstanding tasks on a message queue it will be retained; once all | 233 // has outstanding tasks on a message queue it will be retained; once all |
| 232 // outstanding tasks are completed it will be deleted. | 234 // outstanding tasks are completed it will be deleted. |
| 233 class PlatformAppWebIntentLauncher | 235 class PlatformAppWebIntentLauncher |
| 234 : public base::RefCountedThreadSafe<PlatformAppWebIntentLauncher> { | 236 : public base::RefCountedThreadSafe<PlatformAppWebIntentLauncher> { |
| 235 public: | 237 public: |
| 236 PlatformAppWebIntentLauncher(Profile* profile, | 238 PlatformAppWebIntentLauncher( |
| 237 const Extension* extension, | 239 Profile* profile, |
| 238 const webkit_glue::WebIntentData& data) | 240 const Extension* extension, |
| 241 content::WebIntentsDispatcher* intents_dispatcher, |
| 242 content::WebContents* source) |
| 239 : profile_(profile), | 243 : profile_(profile), |
| 240 extension_(extension), | 244 extension_(extension), |
| 241 data_(data) {} | 245 intents_dispatcher_(intents_dispatcher), |
| 246 source_(source), |
| 247 data_(intents_dispatcher->GetIntent()) {} |
| 242 | 248 |
| 243 void Launch() { | 249 void Launch() { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 245 if (data_.data_type != webkit_glue::WebIntentData::BLOB && | 251 if (data_.data_type != webkit_glue::WebIntentData::BLOB && |
| 246 data_.data_type != webkit_glue::WebIntentData::FILESYSTEM) { | 252 data_.data_type != webkit_glue::WebIntentData::FILESYSTEM) { |
| 247 InternalLaunch(); | 253 InternalLaunch(); |
| 248 return; | 254 return; |
| 249 } | 255 } |
| 250 | 256 |
| 251 // Access needs to be granted to the file or filesystem for the process | 257 // Access needs to be granted to the file or filesystem for the process |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 policy->GrantReadFile(renderer_id, path); | 310 policy->GrantReadFile(renderer_id, path); |
| 305 policy->GrantReadFileSystem(renderer_id, data_.filesystem_id); | 311 policy->GrantReadFileSystem(renderer_id, data_.filesystem_id); |
| 306 } else { | 312 } else { |
| 307 NOTREACHED(); | 313 NOTREACHED(); |
| 308 } | 314 } |
| 309 InternalLaunch(); | 315 InternalLaunch(); |
| 310 } | 316 } |
| 311 | 317 |
| 312 void InternalLaunch() { | 318 void InternalLaunch() { |
| 313 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 319 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 314 profile_, extension_, data_); | 320 profile_, extension_, intents_dispatcher_, source_); |
| 315 } | 321 } |
| 316 | 322 |
| 317 // The profile the app should be run in. | 323 // The profile the app should be run in. |
| 318 Profile* profile_; | 324 Profile* profile_; |
| 319 // The extension providing the app. | 325 // The extension providing the app. |
| 320 const Extension* extension_; | 326 const Extension* extension_; |
| 321 // The WebIntent data to be passed through to the app. | 327 // The dispatcher so that platform apps can respond to this intent. |
| 328 content::WebIntentsDispatcher* intents_dispatcher_; |
| 329 // The source of this intent. |
| 330 content::WebContents* source_; |
| 331 // The WebIntent data from the dispatcher. |
| 322 const webkit_glue::WebIntentData data_; | 332 const webkit_glue::WebIntentData data_; |
| 323 | 333 |
| 324 DISALLOW_COPY_AND_ASSIGN(PlatformAppWebIntentLauncher); | 334 DISALLOW_COPY_AND_ASSIGN(PlatformAppWebIntentLauncher); |
| 325 }; | 335 }; |
| 326 | 336 |
| 327 } // namespace | 337 } // namespace |
| 328 | 338 |
| 329 void LaunchPlatformApp(Profile* profile, | 339 void LaunchPlatformApp(Profile* profile, |
| 330 const Extension* extension, | 340 const Extension* extension, |
| 331 const CommandLine* command_line, | 341 const CommandLine* command_line, |
| 332 const FilePath& current_directory) { | 342 const FilePath& current_directory) { |
| 333 // launcher will be freed when nothing has a reference to it. The message | 343 // launcher will be freed when nothing has a reference to it. The message |
| 334 // queue will retain a reference for any outstanding task, so when the | 344 // queue will retain a reference for any outstanding task, so when the |
| 335 // launcher has finished it will be freed. | 345 // launcher has finished it will be freed. |
| 336 scoped_refptr<PlatformAppCommandLineLauncher> launcher = | 346 scoped_refptr<PlatformAppCommandLineLauncher> launcher = |
| 337 new PlatformAppCommandLineLauncher(profile, extension, command_line, | 347 new PlatformAppCommandLineLauncher(profile, extension, command_line, |
| 338 current_directory); | 348 current_directory); |
| 339 launcher->Launch(); | 349 launcher->Launch(); |
| 340 } | 350 } |
| 341 | 351 |
| 342 void LaunchPlatformAppWithWebIntent( | 352 void LaunchPlatformAppWithWebIntent( |
| 343 Profile* profile, | 353 Profile* profile, |
| 344 const Extension* extension, | 354 const Extension* extension, |
| 345 const webkit_glue::WebIntentData& web_intent_data) { | 355 content::WebIntentsDispatcher* intents_dispatcher, |
| 356 content::WebContents* source) { |
| 346 scoped_refptr<PlatformAppWebIntentLauncher> launcher = | 357 scoped_refptr<PlatformAppWebIntentLauncher> launcher = |
| 347 new PlatformAppWebIntentLauncher(profile, extension, web_intent_data); | 358 new PlatformAppWebIntentLauncher( |
| 359 profile, extension, intents_dispatcher, source); |
| 348 launcher->Launch(); | 360 launcher->Launch(); |
| 349 } | 361 } |
| 350 | 362 |
| 351 } // namespace extensions | 363 } // namespace extensions |
| OLD | NEW |