| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmark_app_helper.h" | 5 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 6 | 6 |
| 7 #include <cctype> | 7 #include <cctype> |
| 8 | 8 |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/crx_installer.h" | 12 #include "chrome/browser/extensions/crx_installer.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/favicon_downloader.h" | 14 #include "chrome/browser/extensions/favicon_downloader.h" |
| 15 #include "chrome/browser/extensions/launch_util.h" | 15 #include "chrome/browser/extensions/launch_util.h" |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/app_list/app_list_service.h" | 18 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 19 #include "chrome/browser/ui/app_list/app_list_util.h" | 19 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/host_desktop.h" | 22 #include "chrome/browser/ui/host_desktop.h" |
| 23 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 25 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 30 #include "extensions/browser/image_loader.h" | 31 #include "extensions/browser/image_loader.h" |
| 31 #include "extensions/browser/notification_types.h" | 32 #include "extensions/browser/notification_types.h" |
| 32 #include "extensions/browser/pref_names.h" | 33 #include "extensions/browser/pref_names.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 return; | 413 return; |
| 413 } | 414 } |
| 414 | 415 |
| 415 Browser* browser = chrome::FindBrowserWithWebContents(contents_); | 416 Browser* browser = chrome::FindBrowserWithWebContents(contents_); |
| 416 if (!browser) { | 417 if (!browser) { |
| 417 // The browser can be null in tests. | 418 // The browser can be null in tests. |
| 418 callback_.Run(extension, web_app_info_); | 419 callback_.Run(extension, web_app_info_); |
| 419 return; | 420 return; |
| 420 } | 421 } |
| 421 | 422 |
| 422 // Pin the app to the shelf on Ash. | 423 // Pin the app to the relevant launcher depending on the OS. |
| 424 Profile* current_profile = profile_->GetOriginalProfile(); |
| 423 chrome::HostDesktopType desktop = browser->host_desktop_type(); | 425 chrome::HostDesktopType desktop = browser->host_desktop_type(); |
| 426 if (desktop != chrome::HOST_DESKTOP_TYPE_ASH) { |
| 427 web_app::ShortcutLocations creation_locations; |
| 428 #if defined(OS_LINUX) |
| 429 creation_locations.on_desktop = true; |
| 430 #else |
| 431 creation_locations.on_desktop = false; |
| 432 #endif |
| 433 creation_locations.applications_menu_location = |
| 434 web_app::APP_MENU_LOCATION_HIDDEN; |
| 435 creation_locations.in_quick_launch_bar = true; |
| 436 web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER, |
| 437 creation_locations, current_profile, extension); |
| 424 #if defined(USE_ASH) | 438 #if defined(USE_ASH) |
| 425 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | 439 } else { |
| 426 ChromeLauncherController::instance()->PinAppWithID(extension->id()); | 440 ChromeLauncherController::instance()->PinAppWithID(extension->id()); |
| 427 #endif | 441 #endif |
| 442 } |
| 428 | 443 |
| 429 // Show the newly installed app in the app launcher, in finder (on Mac) or | 444 // Show the newly installed app in the app launcher, in finder (on Mac) or |
| 430 // chrome://apps. | 445 // chrome://apps. |
| 431 Profile* current_profile = profile_->GetOriginalProfile(); | |
| 432 if (IsAppLauncherEnabled()) { | 446 if (IsAppLauncherEnabled()) { |
| 433 AppListService::Get(desktop) | 447 AppListService::Get(desktop) |
| 434 ->ShowForAppInstall(current_profile, extension->id(), false); | 448 ->ShowForAppInstall(current_profile, extension->id(), false); |
| 435 #if defined(OS_MACOSX) | 449 #if defined(OS_MACOSX) |
| 436 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 450 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 437 switches::kEnableHostedAppShimCreation)) { | 451 switches::kEnableHostedAppShimCreation)) { |
| 438 web_app::RevealAppShimInFinderForApp(profile_, extension); | 452 web_app::RevealAppShimInFinderForApp(profile_, extension); |
| 439 #endif | 453 #endif |
| 440 } else { | 454 } else { |
| 441 chrome::NavigateParams params(current_profile, | 455 chrome::NavigateParams params(current_profile, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); | 537 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); |
| 524 } | 538 } |
| 525 | 539 |
| 526 bool IsValidBookmarkAppUrl(const GURL& url) { | 540 bool IsValidBookmarkAppUrl(const GURL& url) { |
| 527 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); | 541 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); |
| 528 origin_only_pattern.SetMatchAllURLs(true); | 542 origin_only_pattern.SetMatchAllURLs(true); |
| 529 return url.is_valid() && origin_only_pattern.MatchesURL(url); | 543 return url.is_valid() && origin_only_pattern.MatchesURL(url); |
| 530 } | 544 } |
| 531 | 545 |
| 532 } // namespace extensions | 546 } // namespace extensions |
| OLD | NEW |