| 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" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 DISALLOW_COPY_AND_ASSIGN(PlatformAppCommandLineLauncher); | 225 DISALLOW_COPY_AND_ASSIGN(PlatformAppCommandLineLauncher); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 // Class to handle launching of platform apps with WebIntent data that is being | 228 // Class to handle launching of platform apps with WebIntent data that is being |
| 229 // passed in a a blob. | 229 // passed in a a blob. |
| 230 // An instance of this class is created for each launch. The lifetime of these | 230 // 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 | 231 // 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 | 232 // has outstanding tasks on a message queue it will be retained; once all |
| 233 // outstanding tasks are completed it will be deleted. | 233 // outstanding tasks are completed it will be deleted. |
| 234 class PlatformAppBlobIntentLauncher | 234 class PlatformAppGrantIntentLauncher |
| 235 : public base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher> { | 235 : public base::RefCountedThreadSafe<PlatformAppGrantIntentLauncher> { |
| 236 public: | 236 public: |
| 237 PlatformAppBlobIntentLauncher(Profile* profile, | 237 PlatformAppGrantIntentLauncher(Profile* profile, |
| 238 const Extension* extension, | 238 const Extension* extension, |
| 239 const webkit_glue::WebIntentData& data) | 239 const webkit_glue::WebIntentData& data) |
| 240 : profile_(profile), | 240 : profile_(profile), |
| 241 extension_(extension), | 241 extension_(extension), |
| 242 data_(data) {} | 242 data_(data) {} |
| 243 | 243 |
| 244 void Launch() { | 244 void Launch() { |
| 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 246 | 246 |
| 247 // Access needs to be granted to the file for the process associated with | 247 // 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 | 248 // 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 | 249 // 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 | 250 // the lazy background task queue is used to load the extension and then |
| 251 // call back to us. | 251 // call back to us. |
| 252 extensions::LazyBackgroundTaskQueue* queue = | 252 extensions::LazyBackgroundTaskQueue* queue = |
| 253 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | 253 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
| 254 if (queue->ShouldEnqueueTask(profile_, extension_)) { | 254 if (queue->ShouldEnqueueTask(profile_, extension_)) { |
| 255 queue->AddPendingTask(profile_, extension_->id(), base::Bind( | 255 queue->AddPendingTask(profile_, extension_->id(), base::Bind( |
| 256 &PlatformAppBlobIntentLauncher::GrantAccessToFileAndLaunch, | 256 &PlatformAppGrantIntentLauncher::GrantAccessToFileAndLaunch, |
| 257 this)); | 257 this)); |
| 258 return; | 258 return; |
| 259 } | 259 } |
| 260 | 260 |
| 261 ExtensionProcessManager* process_manager = | 261 ExtensionProcessManager* process_manager = |
| 262 ExtensionSystem::Get(profile_)->process_manager(); | 262 ExtensionSystem::Get(profile_)->process_manager(); |
| 263 extensions::ExtensionHost* host = | 263 extensions::ExtensionHost* host = |
| 264 process_manager->GetBackgroundHostForExtension(extension_->id()); | 264 process_manager->GetBackgroundHostForExtension(extension_->id()); |
| 265 DCHECK(host); | 265 DCHECK(host); |
| 266 GrantAccessToFileAndLaunch(host); | 266 GrantAccessToFileAndLaunch(host); |
| 267 } | 267 } |
| 268 | 268 |
| 269 private: | 269 private: |
| 270 friend class base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher>; | 270 friend class base::RefCountedThreadSafe<PlatformAppGrantIntentLauncher>; |
| 271 | 271 |
| 272 virtual ~PlatformAppBlobIntentLauncher() {} | 272 virtual ~PlatformAppGrantIntentLauncher() {} |
| 273 | 273 |
| 274 void GrantAccessToFileAndLaunch(extensions::ExtensionHost* host) { | 274 void GrantAccessToFileAndLaunch(extensions::ExtensionHost* host) { |
| 275 // If there was an error loading the app page, |host| will be NULL. | 275 // If there was an error loading the app page, |host| will be NULL. |
| 276 if (!host) { | 276 if (!host) { |
| 277 LOG(ERROR) << "Could not load app page for " << extension_->id(); | 277 LOG(ERROR) << "Could not load app page for " << extension_->id(); |
| 278 return; | 278 return; |
| 279 } | 279 } |
| 280 | 280 |
| 281 content::ChildProcessSecurityPolicy* policy = | 281 content::ChildProcessSecurityPolicy* policy = |
| 282 content::ChildProcessSecurityPolicy::GetInstance(); | 282 content::ChildProcessSecurityPolicy::GetInstance(); |
| 283 int renderer_id = host->render_process_host()->GetID(); | 283 int renderer_id = host->render_process_host()->GetID(); |
| 284 | 284 |
| 285 // Granting read file permission to allow reading file content. | 285 if (data_.data_type == webkit_glue::WebIntentData::BLOB) { |
| 286 // If the renderer already has permission to read these paths, it is not | 286 // Granting read file permission to allow reading file content. |
| 287 // regranted, as this would overwrite any other permissions which the | 287 // If the renderer already has permission to read these paths, it is not |
| 288 // renderer may already have. | 288 // regranted, as this would overwrite any other permissions which the |
| 289 if (!policy->CanReadFile(renderer_id, data_.blob_file)) | 289 // renderer may already have. |
| 290 policy->GrantReadFile(renderer_id, data_.blob_file); | 290 if (!policy->CanReadFile(renderer_id, data_.blob_file)) |
| 291 policy->GrantReadFile(renderer_id, data_.blob_file); |
| 292 } else if (data_.data_type == webkit_glue::WebIntentData::FILESYSTEM) { |
| 293 // Grant read filesystem and read directory permission to allow reading |
| 294 // any part of the specified filesystem. |
| 295 policy->GrantReadFileSystem(renderer_id, data_.filesystem_id); |
| 296 // TODO(thorogood): We may need to revisit this. |
| 297 // if (!policy->CanReadDirectory(renderer_id, data_.root_path)) |
| 298 // policy->GrantReadDirectory(renderer_id, data_.root_path); |
| 299 } else { |
| 300 NOTREACHED(); |
| 301 } |
| 291 | 302 |
| 292 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 303 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 293 profile_, extension_, data_); | 304 profile_, extension_, data_); |
| 294 } | 305 } |
| 295 | 306 |
| 296 // The profile the app should be run in. | 307 // The profile the app should be run in. |
| 297 Profile* profile_; | 308 Profile* profile_; |
| 298 // The extension providing the app. | 309 // The extension providing the app. |
| 299 const Extension* extension_; | 310 const Extension* extension_; |
| 300 // The WebIntent data to be passed through to the app. | 311 // The WebIntent data to be passed through to the app. |
| 301 const webkit_glue::WebIntentData data_; | 312 const webkit_glue::WebIntentData data_; |
| 302 | 313 |
| 303 DISALLOW_COPY_AND_ASSIGN(PlatformAppBlobIntentLauncher); | 314 DISALLOW_COPY_AND_ASSIGN(PlatformAppGrantIntentLauncher); |
| 304 }; | 315 }; |
| 305 | 316 |
| 306 } // namespace | 317 } // namespace |
| 307 | 318 |
| 308 void LaunchPlatformApp(Profile* profile, | 319 void LaunchPlatformApp(Profile* profile, |
| 309 const Extension* extension, | 320 const Extension* extension, |
| 310 const CommandLine* command_line, | 321 const CommandLine* command_line, |
| 311 const FilePath& current_directory) { | 322 const FilePath& current_directory) { |
| 312 // launcher will be freed when nothing has a reference to it. The message | 323 // launcher will be freed when nothing has a reference to it. The message |
| 313 // queue will retain a reference for any outstanding task, so when the | 324 // queue will retain a reference for any outstanding task, so when the |
| 314 // launcher has finished it will be freed. | 325 // launcher has finished it will be freed. |
| 315 scoped_refptr<PlatformAppCommandLineLauncher> launcher = | 326 scoped_refptr<PlatformAppCommandLineLauncher> launcher = |
| 316 new PlatformAppCommandLineLauncher(profile, extension, command_line, | 327 new PlatformAppCommandLineLauncher(profile, extension, command_line, |
| 317 current_directory); | 328 current_directory); |
| 318 launcher->Launch(); | 329 launcher->Launch(); |
| 319 } | 330 } |
| 320 | 331 |
| 321 void LaunchPlatformAppWithWebIntent( | 332 void LaunchPlatformAppWithWebIntent( |
| 322 Profile* profile, | 333 Profile* profile, |
| 323 const Extension* extension, | 334 const Extension* extension, |
| 324 const webkit_glue::WebIntentData& web_intent_data) { | 335 const webkit_glue::WebIntentData& web_intent_data) { |
| 325 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB) { | 336 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB || |
| 326 scoped_refptr<PlatformAppBlobIntentLauncher> launcher = | 337 web_intent_data.data_type == webkit_glue::WebIntentData::FILESYSTEM) { |
| 327 new PlatformAppBlobIntentLauncher(profile, extension, web_intent_data); | 338 scoped_refptr<PlatformAppGrantIntentLauncher> launcher = |
| 339 new PlatformAppGrantIntentLauncher(profile, extension, web_intent_data); |
| 328 launcher->Launch(); | 340 launcher->Launch(); |
| 329 return; | 341 return; |
| 330 } | 342 } |
| 331 | 343 |
| 332 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 344 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 333 profile, extension, web_intent_data); | 345 profile, extension, web_intent_data); |
| 334 } | 346 } |
| 335 | 347 |
| 336 } // namespace extensions | 348 } // namespace extensions |
| OLD | NEW |