| 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/app_api.h" | 14 #include "chrome/browser/extensions/api/app/app_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 using extensions::Extension; | 35 using extensions::Extension; |
| 34 using extensions::ExtensionSystem; | 36 using extensions::ExtensionSystem; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // Class to handle launching of platform apps with WebIntent data that is being | 230 // Class to handle launching of platform apps with WebIntent data that is being |
| 229 // passed in a a blob. | 231 // passed in a a blob. |
| 230 // An instance of this class is created for each launch. The lifetime of these | 232 // An instance of this class is created for each launch. The lifetime of these |
| 231 // instances is managed by reference counted pointers. As long as an instance | 233 // instances is managed by reference counted pointers. As long as an instance |
| 232 // has outstanding tasks on a message queue it will be retained; once all | 234 // has outstanding tasks on a message queue it will be retained; once all |
| 233 // outstanding tasks are completed it will be deleted. | 235 // outstanding tasks are completed it will be deleted. |
| 234 class PlatformAppBlobIntentLauncher | 236 class PlatformAppBlobIntentLauncher |
| 235 : public base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher> { | 237 : public base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher> { |
| 236 public: | 238 public: |
| 237 PlatformAppBlobIntentLauncher(Profile* profile, | 239 PlatformAppBlobIntentLauncher(Profile* profile, |
| 238 const Extension* extension, | 240 const Extension* extension, |
| 239 const webkit_glue::WebIntentData& data) | 241 content::WebIntentsDispatcher* intents_dispatcher, |
| 242 content::WebContents* source) |
| 240 : profile_(profile), | 243 : profile_(profile), |
| 241 extension_(extension), | 244 extension_(extension), |
| 242 data_(data) {} | 245 intents_dispatcher_(intents_dispatcher), |
| 246 source_(source) {} |
| 243 | 247 |
| 244 void Launch() { | 248 void Launch() { |
| 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 246 | 250 |
| 247 // Access needs to be granted to the file for the process associated with | 251 // Access needs to be granted to the file for the process associated with |
| 248 // the extension. To do this the ExtensionHost is needed. This might not be | 252 // the extension. To do this the ExtensionHost is needed. This might not be |
| 249 // available, or it might be in the process of being unloaded, in which case | 253 // available, or it might be in the process of being unloaded, in which case |
| 250 // the lazy background task queue is used to load the extension and then | 254 // the lazy background task queue is used to load the extension and then |
| 251 // call back to us. | 255 // call back to us. |
| 252 extensions::LazyBackgroundTaskQueue* queue = | 256 extensions::LazyBackgroundTaskQueue* queue = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 279 } | 283 } |
| 280 | 284 |
| 281 content::ChildProcessSecurityPolicy* policy = | 285 content::ChildProcessSecurityPolicy* policy = |
| 282 content::ChildProcessSecurityPolicy::GetInstance(); | 286 content::ChildProcessSecurityPolicy::GetInstance(); |
| 283 int renderer_id = host->render_process_host()->GetID(); | 287 int renderer_id = host->render_process_host()->GetID(); |
| 284 | 288 |
| 285 // Granting read file permission to allow reading file content. | 289 // Granting read file permission to allow reading file content. |
| 286 // If the renderer already has permission to read these paths, it is not | 290 // If the renderer already has permission to read these paths, it is not |
| 287 // regranted, as this would overwrite any other permissions which the | 291 // regranted, as this would overwrite any other permissions which the |
| 288 // renderer may already have. | 292 // renderer may already have. |
| 289 if (!policy->CanReadFile(renderer_id, data_.blob_file)) | 293 webkit_glue::WebIntentData data = intents_dispatcher_->GetIntent(); |
| 290 policy->GrantReadFile(renderer_id, data_.blob_file); | 294 if (!policy->CanReadFile(renderer_id, data.blob_file)) |
| 295 policy->GrantReadFile(renderer_id, data.blob_file); |
| 291 | 296 |
| 292 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 297 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 293 profile_, extension_, data_); | 298 profile_, extension_, intents_dispatcher_, source_); |
| 294 } | 299 } |
| 295 | 300 |
| 296 // The profile the app should be run in. | 301 // The profile the app should be run in. |
| 297 Profile* profile_; | 302 Profile* profile_; |
| 298 // The extension providing the app. | 303 // The extension providing the app. |
| 299 const Extension* extension_; | 304 const Extension* extension_; |
| 300 // The WebIntent data to be passed through to the app. | 305 // The dispatcher so that platform apps can respond to this intent. |
| 301 const webkit_glue::WebIntentData data_; | 306 content::WebIntentsDispatcher* intents_dispatcher_; |
| 307 // The source of this intent. |
| 308 content::WebContents* source_; |
| 302 | 309 |
| 303 DISALLOW_COPY_AND_ASSIGN(PlatformAppBlobIntentLauncher); | 310 DISALLOW_COPY_AND_ASSIGN(PlatformAppBlobIntentLauncher); |
| 304 }; | 311 }; |
| 305 | 312 |
| 306 } // namespace | 313 } // namespace |
| 307 | 314 |
| 308 namespace extensions { | 315 namespace extensions { |
| 309 | 316 |
| 310 void LaunchPlatformApp(Profile* profile, | 317 void LaunchPlatformApp(Profile* profile, |
| 311 const Extension* extension, | 318 const Extension* extension, |
| 312 const CommandLine* command_line, | 319 const CommandLine* command_line, |
| 313 const FilePath& current_directory) { | 320 const FilePath& current_directory) { |
| 314 // launcher will be freed when nothing has a reference to it. The message | 321 // launcher will be freed when nothing has a reference to it. The message |
| 315 // queue will retain a reference for any outstanding task, so when the | 322 // queue will retain a reference for any outstanding task, so when the |
| 316 // launcher has finished it will be freed. | 323 // launcher has finished it will be freed. |
| 317 scoped_refptr<PlatformAppCommandLineLauncher> launcher = | 324 scoped_refptr<PlatformAppCommandLineLauncher> launcher = |
| 318 new PlatformAppCommandLineLauncher(profile, extension, command_line, | 325 new PlatformAppCommandLineLauncher(profile, extension, command_line, |
| 319 current_directory); | 326 current_directory); |
| 320 launcher->Launch(); | 327 launcher->Launch(); |
| 321 } | 328 } |
| 322 | 329 |
| 323 void LaunchPlatformAppWithWebIntent( | 330 void LaunchPlatformAppWithWebIntent( |
| 324 Profile* profile, | 331 Profile* profile, |
| 325 const Extension* extension, | 332 const Extension* extension, |
| 326 const webkit_glue::WebIntentData& web_intent_data) { | 333 content::WebIntentsDispatcher* intents_dispatcher, |
| 334 content::WebContents* source) { |
| 335 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); |
| 327 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB) { | 336 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB) { |
| 328 scoped_refptr<PlatformAppBlobIntentLauncher> launcher = | 337 scoped_refptr<PlatformAppBlobIntentLauncher> launcher = |
| 329 new PlatformAppBlobIntentLauncher(profile, extension, web_intent_data); | 338 new PlatformAppBlobIntentLauncher(profile, extension, |
| 339 intents_dispatcher, source); |
| 330 launcher->Launch(); | 340 launcher->Launch(); |
| 331 return; | 341 return; |
| 332 } | 342 } |
| 333 | 343 |
| 334 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 344 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 335 profile, extension, web_intent_data); | 345 profile, extension, intents_dispatcher, source); |
| 336 } | 346 } |
| 337 | 347 |
| 338 } // namespace extensions | 348 } // namespace extensions |
| OLD | NEW |