| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 19 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 19 #include "chrome/browser/extensions/api/file_handlers/directory_util.h" | 20 #include "chrome/browser/extensions/api/file_handlers/directory_util.h" |
| 20 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" | 21 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" |
| 21 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 22 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 42 | 43 |
| 43 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
| 44 #include "components/user_manager/user_manager.h" | 45 #include "components/user_manager/user_manager.h" |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 namespace app_runtime = extensions::api::app_runtime; | 48 namespace app_runtime = extensions::api::app_runtime; |
| 48 | 49 |
| 49 using content::BrowserThread; | 50 using content::BrowserThread; |
| 50 using extensions::AppRuntimeEventRouter; | 51 using extensions::AppRuntimeEventRouter; |
| 52 using extensions::api::app_runtime::PlayStoreStatus; |
| 51 using extensions::app_file_handler_util::CreateFileEntry; | 53 using extensions::app_file_handler_util::CreateFileEntry; |
| 52 using extensions::app_file_handler_util::FileHandlerCanHandleEntry; | 54 using extensions::app_file_handler_util::FileHandlerCanHandleEntry; |
| 53 using extensions::app_file_handler_util::FileHandlerForId; | 55 using extensions::app_file_handler_util::FileHandlerForId; |
| 54 using extensions::app_file_handler_util::FirstFileHandlerForEntry; | 56 using extensions::app_file_handler_util::FirstFileHandlerForEntry; |
| 55 using extensions::app_file_handler_util::HasFileSystemWritePermission; | 57 using extensions::app_file_handler_util::HasFileSystemWritePermission; |
| 56 using extensions::app_file_handler_util::PrepareFilesForWritableApp; | 58 using extensions::app_file_handler_util::PrepareFilesForWritableApp; |
| 57 using extensions::EventRouter; | 59 using extensions::EventRouter; |
| 58 using extensions::Extension; | 60 using extensions::Extension; |
| 59 using extensions::ExtensionHost; | 61 using extensions::ExtensionHost; |
| 60 using extensions::GrantedFileEntry; | 62 using extensions::GrantedFileEntry; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 198 } |
| 197 | 199 |
| 198 void LaunchWithNoLaunchData() { | 200 void LaunchWithNoLaunchData() { |
| 199 // 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. |
| 200 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 202 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 201 | 203 |
| 202 const Extension* app = GetExtension(); | 204 const Extension* app = GetExtension(); |
| 203 if (!app) | 205 if (!app) |
| 204 return; | 206 return; |
| 205 | 207 |
| 208 std::unique_ptr<app_runtime::LaunchData> launch_data = |
| 209 base::MakeUnique<app_runtime::LaunchData>(); |
| 210 launch_data->action_data = std::move(action_data_); |
| 211 |
| 206 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 212 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 207 profile_, app, launch_source_, std::move(action_data_)); | 213 profile_, app, launch_source_, std::move(launch_data)); |
| 208 } | 214 } |
| 209 | 215 |
| 210 void OnAreDirectoriesCollected( | 216 void OnAreDirectoriesCollected( |
| 211 bool has_file_system_write_permission, | 217 bool has_file_system_write_permission, |
| 212 std::unique_ptr<std::set<base::FilePath>> directory_paths) { | 218 std::unique_ptr<std::set<base::FilePath>> directory_paths) { |
| 213 if (has_file_system_write_permission) { | 219 if (has_file_system_write_permission) { |
| 214 std::set<base::FilePath>* const directory_paths_ptr = | 220 std::set<base::FilePath>* const directory_paths_ptr = |
| 215 directory_paths.get(); | 221 directory_paths.get(); |
| 216 PrepareFilesForWritableApp( | 222 PrepareFilesForWritableApp( |
| 217 entry_paths_, profile_, *directory_paths_ptr, | 223 entry_paths_, profile_, *directory_paths_ptr, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; | 351 extensions::app_file_handler_util::MimeTypeCollector mime_type_collector_; |
| 346 extensions::app_file_handler_util::IsDirectoryCollector | 352 extensions::app_file_handler_util::IsDirectoryCollector |
| 347 is_directory_collector_; | 353 is_directory_collector_; |
| 348 | 354 |
| 349 DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); | 355 DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); |
| 350 }; | 356 }; |
| 351 | 357 |
| 352 } // namespace | 358 } // namespace |
| 353 | 359 |
| 354 void LaunchPlatformAppWithCommandLine(Profile* profile, | 360 void LaunchPlatformAppWithCommandLine(Profile* profile, |
| 355 const Extension* app, | 361 const extensions::Extension* app, |
| 356 const base::CommandLine& command_line, | 362 const base::CommandLine& command_line, |
| 357 const base::FilePath& current_directory, | 363 const base::FilePath& current_directory, |
| 358 extensions::AppLaunchSource source) { | 364 extensions::AppLaunchSource source, |
| 365 PlayStoreStatus play_store_status) { |
| 359 // An app with "kiosk_only" should not be installed and launched | 366 // An app with "kiosk_only" should not be installed and launched |
| 360 // outside of ChromeOS kiosk mode in the first place. This is a defensive | 367 // outside of ChromeOS kiosk mode in the first place. This is a defensive |
| 361 // check in case this scenario does occur. | 368 // check in case this scenario does occur. |
| 362 if (extensions::KioskModeInfo::IsKioskOnly(app)) { | 369 if (extensions::KioskModeInfo::IsKioskOnly(app)) { |
| 363 bool in_kiosk_mode = false; | 370 bool in_kiosk_mode = false; |
| 364 #if defined(OS_CHROMEOS) | 371 #if defined(OS_CHROMEOS) |
| 365 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 372 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 366 in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); | 373 in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); |
| 367 #endif | 374 #endif |
| 368 if (!in_kiosk_mode) { | 375 if (!in_kiosk_mode) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 379 #else | 386 #else |
| 380 base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); | 387 base::CommandLine::StringType about_blank_url(url::kAboutBlankURL); |
| 381 #endif | 388 #endif |
| 382 base::CommandLine::StringVector args = command_line.GetArgs(); | 389 base::CommandLine::StringVector args = command_line.GetArgs(); |
| 383 // Browser tests will add about:blank to the command line. This should | 390 // Browser tests will add about:blank to the command line. This should |
| 384 // never be interpreted as a file to open, as doing so with an app that | 391 // never be interpreted as a file to open, as doing so with an app that |
| 385 // has write access will result in a file 'about' being created, which | 392 // has write access will result in a file 'about' being created, which |
| 386 // causes problems on the bots. | 393 // causes problems on the bots. |
| 387 if (args.empty() || (command_line.HasSwitch(switches::kTestType) && | 394 if (args.empty() || (command_line.HasSwitch(switches::kTestType) && |
| 388 args[0] == about_blank_url)) { | 395 args[0] == about_blank_url)) { |
| 389 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 396 std::unique_ptr<app_runtime::LaunchData> launch_data = |
| 390 profile, app, source, std::unique_ptr<app_runtime::ActionData>()); | 397 base::MakeUnique<app_runtime::LaunchData>(); |
| 398 if (play_store_status != PlayStoreStatus::PLAY_STORE_STATUS_UNKNOWN) |
| 399 launch_data->play_store_status = play_store_status; |
| 400 AppRuntimeEventRouter::DispatchOnLaunchedEvent(profile, app, source, |
| 401 std::move(launch_data)); |
| 391 return; | 402 return; |
| 392 } | 403 } |
| 393 | 404 |
| 394 base::FilePath file_path(command_line.GetArgs()[0]); | 405 base::FilePath file_path(command_line.GetArgs()[0]); |
| 395 scoped_refptr<PlatformAppPathLauncher> launcher = | 406 scoped_refptr<PlatformAppPathLauncher> launcher = |
| 396 new PlatformAppPathLauncher(profile, app, file_path); | 407 new PlatformAppPathLauncher(profile, app, file_path); |
| 397 launcher->LaunchWithRelativePath(current_directory); | 408 launcher->LaunchWithRelativePath(current_directory); |
| 398 } | 409 } |
| 399 | 410 |
| 400 void LaunchPlatformAppWithPath(Profile* profile, | 411 void LaunchPlatformAppWithPath(Profile* profile, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 extensions::ExtensionPrefs* extension_prefs = | 459 extensions::ExtensionPrefs* extension_prefs = |
| 449 extensions::ExtensionPrefs::Get(profile); | 460 extensions::ExtensionPrefs::Get(profile); |
| 450 bool had_windows = extension_prefs->IsActive(app->id()); | 461 bool had_windows = extension_prefs->IsActive(app->id()); |
| 451 extension_prefs->SetIsActive(app->id(), false); | 462 extension_prefs->SetIsActive(app->id(), false); |
| 452 bool listening_to_launch = event_router->ExtensionHasEventListener( | 463 bool listening_to_launch = event_router->ExtensionHasEventListener( |
| 453 app->id(), app_runtime::OnLaunched::kEventName); | 464 app->id(), app_runtime::OnLaunched::kEventName); |
| 454 | 465 |
| 455 if (listening_to_launch && had_windows) { | 466 if (listening_to_launch && had_windows) { |
| 456 AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 467 AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 457 profile, app, extensions::SOURCE_RESTART, | 468 profile, app, extensions::SOURCE_RESTART, |
| 458 std::unique_ptr<app_runtime::ActionData>()); | 469 std::unique_ptr<app_runtime::LaunchData>()); |
| 459 } | 470 } |
| 460 } | 471 } |
| 461 | 472 |
| 462 void LaunchPlatformAppWithUrl(Profile* profile, | 473 void LaunchPlatformAppWithUrl(Profile* profile, |
| 463 const Extension* app, | 474 const Extension* app, |
| 464 const std::string& handler_id, | 475 const std::string& handler_id, |
| 465 const GURL& url, | 476 const GURL& url, |
| 466 const GURL& referrer_url) { | 477 const GURL& referrer_url) { |
| 467 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( | 478 AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( |
| 468 profile, app, handler_id, url, referrer_url); | 479 profile, app, handler_id, url, referrer_url); |
| 469 } | 480 } |
| 470 | 481 |
| 471 } // namespace apps | 482 } // namespace apps |
| OLD | NEW |