Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/launcher.h" | 5 #include "apps/launcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // has outstanding tasks on a message queue it will be retained; once all | 92 // has outstanding tasks on a message queue it will be retained; once all |
| 93 // outstanding tasks are completed it will be deleted. | 93 // outstanding tasks are completed it will be deleted. |
| 94 class PlatformAppPathLauncher | 94 class PlatformAppPathLauncher |
| 95 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { | 95 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { |
| 96 public: | 96 public: |
| 97 PlatformAppPathLauncher(Profile* profile, | 97 PlatformAppPathLauncher(Profile* profile, |
| 98 const Extension* extension, | 98 const Extension* extension, |
| 99 const std::vector<base::FilePath>& entry_paths) | 99 const std::vector<base::FilePath>& entry_paths) |
| 100 : profile_(profile), | 100 : profile_(profile), |
| 101 extension_id(extension->id()), | 101 extension_id(extension->id()), |
| 102 action_data_(), | |
|
Daniel Erat
2016/08/10 22:19:24
nit: leave this out? (i'm guessing it has a defaul
| |
| 102 entry_paths_(entry_paths), | 103 entry_paths_(entry_paths), |
| 103 mime_type_collector_(profile), | 104 mime_type_collector_(profile), |
| 104 is_directory_collector_(profile) {} | 105 is_directory_collector_(profile) {} |
| 105 | 106 |
| 106 PlatformAppPathLauncher(Profile* profile, | 107 PlatformAppPathLauncher(Profile* profile, |
| 107 const Extension* extension, | 108 const Extension* extension, |
| 108 const base::FilePath& file_path) | 109 const base::FilePath& file_path) |
| 109 : profile_(profile), | 110 : profile_(profile), |
| 110 extension_id(extension->id()), | 111 extension_id(extension->id()), |
| 112 action_data_(), | |
|
Daniel Erat
2016/08/10 22:19:24
nit: ditto
| |
| 111 mime_type_collector_(profile), | 113 mime_type_collector_(profile), |
| 112 is_directory_collector_(profile) { | 114 is_directory_collector_(profile) { |
| 113 if (!file_path.empty()) | 115 if (!file_path.empty()) |
| 114 entry_paths_.push_back(file_path); | 116 entry_paths_.push_back(file_path); |
| 115 } | 117 } |
| 116 | 118 |
| 119 void set_action_data(extensions::ActionData action_data) { | |
| 120 action_data_ = action_data; | |
| 121 } | |
| 122 | |
| 123 void set_launch_source(extensions::AppLaunchSource launch_source) { | |
| 124 launch_source_ = launch_source; | |
| 125 } | |
| 126 | |
| 117 void Launch() { | 127 void Launch() { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 | 129 |
| 120 const Extension* extension = GetExtension(); | 130 const Extension* extension = GetExtension(); |
| 121 if (!extension) | 131 if (!extension) |
| 122 return; | 132 return; |
| 123 | 133 |
| 124 if (entry_paths_.empty()) { | 134 if (entry_paths_.empty()) { |
| 125 LaunchWithNoLaunchData(); | 135 LaunchWithNoLaunchData(); |
| 126 return; | 136 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 199 |
| 190 void LaunchWithNoLaunchData() { | 200 void LaunchWithNoLaunchData() { |
| 191 // This method is required as an entry point on the UI thread. | 201 // This method is required as an entry point on the UI thread. |
| 192 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 202 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 193 | 203 |
| 194 const Extension* extension = GetExtension(); | 204 const Extension* extension = GetExtension(); |
| 195 if (!extension) | 205 if (!extension) |
| 196 return; | 206 return; |
| 197 | 207 |
| 198 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 208 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 199 profile_, extension, extensions::SOURCE_FILE_HANDLER); | 209 profile_, extension, launch_source_, action_data_); |
| 200 } | 210 } |
| 201 | 211 |
| 202 void OnAreDirectoriesCollected( | 212 void OnAreDirectoriesCollected( |
| 203 bool has_file_system_write_permission, | 213 bool has_file_system_write_permission, |
| 204 std::unique_ptr<std::set<base::FilePath>> directory_paths) { | 214 std::unique_ptr<std::set<base::FilePath>> directory_paths) { |
| 205 if (has_file_system_write_permission) { | 215 if (has_file_system_write_permission) { |
| 206 std::set<base::FilePath>* const directory_paths_ptr = | 216 std::set<base::FilePath>* const directory_paths_ptr = |
| 207 directory_paths.get(); | 217 directory_paths.get(); |
| 208 PrepareFilesForWritableApp( | 218 PrepareFilesForWritableApp( |
| 209 entry_paths_, profile_, *directory_paths_ptr, | 219 entry_paths_, profile_, *directory_paths_ptr, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 } | 313 } |
| 304 | 314 |
| 305 std::vector<GrantedFileEntry> granted_entries; | 315 std::vector<GrantedFileEntry> granted_entries; |
| 306 for (size_t i = 0; i < entry_paths_.size(); ++i) { | 316 for (size_t i = 0; i < entry_paths_.size(); ++i) { |
| 307 granted_entries.push_back(CreateFileEntry( | 317 granted_entries.push_back(CreateFileEntry( |
| 308 profile_, extension, host->render_process_host()->GetID(), | 318 profile_, extension, host->render_process_host()->GetID(), |
| 309 entries_[i].path, entries_[i].is_directory)); | 319 entries_[i].path, entries_[i].is_directory)); |
| 310 } | 320 } |
| 311 | 321 |
| 312 AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( | 322 AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
| 313 profile_, extension, handler_id_, entries_, granted_entries); | 323 profile_, extension, launch_source_, handler_id_, entries_, |
| 324 granted_entries, action_data_); | |
| 314 } | 325 } |
| 315 | 326 |
| 316 const Extension* GetExtension() const { | 327 const Extension* GetExtension() const { |
| 317 return extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( | 328 return extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 318 extension_id, extensions::ExtensionRegistry::EVERYTHING); | 329 extension_id, extensions::ExtensionRegistry::EVERYTHING); |
| 319 } | 330 } |
| 320 | 331 |
| 321 // The profile the app should be run in. | 332 // The profile the app should be run in. |
| 322 Profile* profile_; | 333 Profile* profile_; |
| 323 // The id of the extension providing the app. A pointer to the extension is | 334 // The id of the extension providing the app. A pointer to the extension is |
| 324 // not kept as the extension may be unloaded and deleted during the course of | 335 // not kept as the extension may be unloaded and deleted during the course of |
| 325 // the launch. | 336 // the launch. |
| 326 const std::string extension_id; | 337 const std::string extension_id; |
| 338 extensions::AppLaunchSource launch_source_ = extensions::SOURCE_FILE_HANDLER; | |
| 339 base::Optional<extensions::ActionData> action_data_; | |
| 327 // A list of files and directories to be passed through to the app. | 340 // A list of files and directories to be passed through to the app. |
| 328 std::vector<base::FilePath> entry_paths_; | 341 std::vector<base::FilePath> entry_paths_; |
| 329 // A corresponding list with EntryInfo for every base::FilePath in | 342 // A corresponding list with EntryInfo for every base::FilePath in |
| 330 // entry_paths_. | 343 // entry_paths_. |
| 331 std::vector<extensions::EntryInfo> entries_; | 344 std::vector<extensions::EntryInfo> entries_; |
| 332 // The ID of the file handler used to launch the app. | 345 // The ID of the file handler used to launch the app. |
| 333 std::string handler_id_; | 346 std::string handler_id_; |
| 334 extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; | 347 extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; |
| 335 extensions::app_file_handler_util::IsDirectoryCollector | 348 extensions::app_file_handler_util::IsDirectoryCollector |
| 336 is_directory_collector_; | 349 is_directory_collector_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 #else | 381 #else |
| 369 base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); | 382 base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); |
| 370 #endif | 383 #endif |
| 371 base::CommandLine::StringVector args = command_line.GetArgs(); | 384 base::CommandLine::StringVector args = command_line.GetArgs(); |
| 372 // Browser tests will add about:blank to the command line. This should | 385 // Browser tests will add about:blank to the command line. This should |
| 373 // never be interpreted as a file to open, as doing so with an app that | 386 // never be interpreted as a file to open, as doing so with an app that |
| 374 // has write access will result in a file 'about' being created, which | 387 // has write access will result in a file 'about' being created, which |
| 375 // causes problems on the bots. | 388 // causes problems on the bots. |
| 376 if (args.empty() || (command_line.HasSwitch(switches::kTestType) && | 389 if (args.empty() || (command_line.HasSwitch(switches::kTestType) && |
| 377 args[0] == about_blank_url)) { | 390 args[0] == about_blank_url)) { |
| 378 AppRuntimeEventRouter::DispatchOnLaunchedEvent(profile, extension, source); | 391 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 392 profile, extension, source, base::Optional<extensions::ActionData>()); | |
| 379 return; | 393 return; |
| 380 } | 394 } |
| 381 | 395 |
| 382 base::FilePath file_path(command_line.GetArgs()[0]); | 396 base::FilePath file_path(command_line.GetArgs()[0]); |
| 383 scoped_refptr<PlatformAppPathLauncher> launcher = | 397 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 384 new PlatformAppPathLauncher(profile, extension, file_path); | 398 new PlatformAppPathLauncher(profile, extension, file_path); |
| 385 launcher->LaunchWithRelativePath(current_directory); | 399 launcher->LaunchWithRelativePath(current_directory); |
| 386 } | 400 } |
| 387 | 401 |
| 388 void LaunchPlatformAppWithPath(Profile* profile, | 402 void LaunchPlatformAppWithPath(Profile* profile, |
| 389 const Extension* extension, | 403 const Extension* extension, |
| 390 const base::FilePath& file_path) { | 404 const base::FilePath& file_path) { |
| 391 scoped_refptr<PlatformAppPathLauncher> launcher = | 405 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 392 new PlatformAppPathLauncher(profile, extension, file_path); | 406 new PlatformAppPathLauncher(profile, extension, file_path); |
| 393 launcher->Launch(); | 407 launcher->Launch(); |
| 394 } | 408 } |
| 395 | 409 |
| 410 void LaunchPlatformAppWithAction(Profile* profile, | |
| 411 const extensions::Extension* extension, | |
| 412 extensions::ActionData action_data, | |
| 413 const base::FilePath& file_path) { | |
| 414 scoped_refptr<PlatformAppPathLauncher> launcher = | |
| 415 new PlatformAppPathLauncher(profile, extension, file_path); | |
| 416 launcher->set_action_data(action_data); | |
| 417 launcher->set_launch_source(extensions::AppLaunchSource::SOURCE_UNTRACKED); | |
| 418 launcher->Launch(); | |
| 419 } | |
| 420 | |
| 396 void LaunchPlatformApp(Profile* profile, | 421 void LaunchPlatformApp(Profile* profile, |
| 397 const Extension* extension, | 422 const Extension* extension, |
| 398 extensions::AppLaunchSource source) { | 423 extensions::AppLaunchSource source) { |
| 399 LaunchPlatformAppWithCommandLine( | 424 LaunchPlatformAppWithCommandLine( |
| 400 profile, | 425 profile, |
| 401 extension, | 426 extension, |
| 402 base::CommandLine(base::CommandLine::NO_PROGRAM), | 427 base::CommandLine(base::CommandLine::NO_PROGRAM), |
| 403 base::FilePath(), | 428 base::FilePath(), |
| 404 source); | 429 source); |
| 405 } | 430 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 428 extensions::ExtensionPrefs* extension_prefs = | 453 extensions::ExtensionPrefs* extension_prefs = |
| 429 extensions::ExtensionPrefs::Get(profile); | 454 extensions::ExtensionPrefs::Get(profile); |
| 430 bool had_windows = extension_prefs->IsActive(extension->id()); | 455 bool had_windows = extension_prefs->IsActive(extension->id()); |
| 431 extension_prefs->SetIsActive(extension->id(), false); | 456 extension_prefs->SetIsActive(extension->id(), false); |
| 432 bool listening_to_launch = event_router-> | 457 bool listening_to_launch = event_router-> |
| 433 ExtensionHasEventListener(extension->id(), | 458 ExtensionHasEventListener(extension->id(), |
| 434 app_runtime::OnLaunched::kEventName); | 459 app_runtime::OnLaunched::kEventName); |
| 435 | 460 |
| 436 if (listening_to_launch && had_windows) { | 461 if (listening_to_launch && had_windows) { |
| 437 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 462 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 438 profile, extension, extensions::SOURCE_RESTART); | 463 profile, extension, extensions::SOURCE_RESTART, |
| 464 base::Optional<extensions::ActionData>()); | |
| 439 } | 465 } |
| 440 } | 466 } |
| 441 | 467 |
| 442 void LaunchPlatformAppWithUrl(Profile* profile, | 468 void LaunchPlatformAppWithUrl(Profile* profile, |
| 443 const Extension* extension, | 469 const Extension* extension, |
| 444 const std::string& handler_id, | 470 const std::string& handler_id, |
| 445 const GURL& url, | 471 const GURL& url, |
| 446 const GURL& referrer_url) { | 472 const GURL& referrer_url) { |
| 447 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( | 473 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( |
| 448 profile, extension, handler_id, url, referrer_url); | 474 profile, extension, handler_id, url, referrer_url); |
| 449 } | 475 } |
| 450 | 476 |
| 451 } // namespace apps | 477 } // namespace apps |
| OLD | NEW |