diff options
author | benwells <benwells@chromium.org> | 2015-10-13 16:38:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-13 23:39:38 +0000 |
commit | cb4422c1ee7c1909afed5edbce2cbc3dcaaea80a (patch) | |
tree | 51d55586cef6cb5b71a86ac17f6b5cb7734d4a5a /chrome/browser | |
parent | 778ff470b7022b5e0244a471d5041586aaf2b5b6 (diff) | |
download | chromium_src-cb4422c1ee7c1909afed5edbce2cbc3dcaaea80a.zip chromium_src-cb4422c1ee7c1909afed5edbce2cbc3dcaaea80a.tar.gz chromium_src-cb4422c1ee7c1909afed5edbce2cbc3dcaaea80a.tar.bz2 |
Remove ability for users to launch ephemeral apps.
Test code can still do this.
BUG=517735
Review URL: https://codereview.chromium.org/1395043002
Cr-Commit-Position: refs/heads/master@{#353904}
Diffstat (limited to 'chrome/browser')
18 files changed, 13 insertions, 1369 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 805876c..95affd34 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1458,11 +1458,6 @@ const Experiment kExperiments[] = { kOsMac, SINGLE_VALUE_TYPE(switches::kHostedAppQuitNotification)}, #endif - {"enable-ephemeral-apps-in-webstore", - IDS_FLAGS_ENABLE_EPHEMERAL_APPS_IN_WEBSTORE_NAME, - IDS_FLAGS_ENABLE_EPHEMERAL_APPS_IN_WEBSTORE_DESCRIPTION, - kOsAll, - SINGLE_VALUE_TYPE(switches::kEnableEphemeralAppsInWebstore)}, #if defined(OS_ANDROID) {"disable-pull-to-refresh-effect", IDS_FLAGS_DISABLE_PULL_TO_REFRESH_EFFECT_NAME, diff --git a/chrome/browser/apps/ephemeral_app_launcher.cc b/chrome/browser/apps/ephemeral_app_launcher.cc deleted file mode 100644 index c9d4fa0..0000000 --- a/chrome/browser/apps/ephemeral_app_launcher.cc +++ /dev/null @@ -1,477 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/apps/ephemeral_app_launcher.h" - -#include "base/command_line.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_install_checker.h" -#include "chrome/browser/extensions/extension_install_prompt.h" -#include "chrome/browser/extensions/extension_util.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser_navigator.h" -#include "chrome/browser/ui/browser_navigator_params.h" -#include "chrome/browser/ui/extensions/app_launch_params.h" -#include "chrome/browser/ui/extensions/application_launch.h" -#include "chrome/browser/ui/extensions/extension_enable_flow.h" -#include "chrome/browser/ui/native_window_tracker.h" -#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" -#include "content/public/browser/web_contents.h" -#include "extensions/browser/extension_prefs.h" -#include "extensions/browser/extension_registry.h" -#include "extensions/browser/extension_system.h" -#include "extensions/browser/management_policy.h" -#include "extensions/common/constants.h" -#include "extensions/common/permissions/permissions_data.h" -#include "ui/app_list/app_list_switches.h" - -using content::WebContents; -using extensions::Extension; -using extensions::ExtensionInstallChecker; -using extensions::ExtensionPrefs; -using extensions::ExtensionRegistry; -using extensions::ExtensionSystem; -using extensions::ManagementPolicy; -using extensions::WebstoreInstaller; -namespace webstore_install = extensions::webstore_install; - -namespace { - -const char kInvalidManifestError[] = "Invalid manifest"; -const char kExtensionTypeError[] = "Not an app"; -const char kAppTypeError[] = "Ephemeral legacy packaged apps not supported"; -const char kUserCancelledError[] = "Launch cancelled by the user"; -const char kBlacklistedError[] = "App is blacklisted for malware"; -const char kRequirementsError[] = "App has missing requirements"; -const char kFeatureDisabledError[] = "Launching ephemeral apps is not enabled"; -const char kMissingAppError[] = "App is not installed"; -const char kAppDisabledError[] = "App is disabled"; - -Profile* ProfileForWebContents(content::WebContents* contents) { - if (!contents) - return NULL; - - return Profile::FromBrowserContext(contents->GetBrowserContext()); -} - -gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { - if (!contents) - return NULL; - - return contents->GetTopLevelNativeWindow(); -} - -// Check whether an extension can be launched. The extension does not need to -// be currently installed. -bool CheckCommonLaunchCriteria(Profile* profile, - const Extension* extension, - webstore_install::Result* reason, - std::string* error) { - // Only apps can be launched. - if (!extension->is_app()) { - *reason = webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE; - *error = kExtensionTypeError; - return false; - } - - // Do not launch apps blocked by management policies. - ManagementPolicy* management_policy = - ExtensionSystem::Get(profile)->management_policy(); - base::string16 policy_error; - if (!management_policy->UserMayLoad(extension, &policy_error)) { - *reason = webstore_install::BLOCKED_BY_POLICY; - *error = base::UTF16ToUTF8(policy_error); - return false; - } - - return true; -} - -} // namespace - -// static -bool EphemeralAppLauncher::IsFeatureEnabled() { - return base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableEphemeralAppsInWebstore); -} - -// static -scoped_refptr<EphemeralAppLauncher> EphemeralAppLauncher::CreateForLauncher( - const std::string& webstore_item_id, - Profile* profile, - gfx::NativeWindow parent_window, - const LaunchCallback& callback) { - scoped_refptr<EphemeralAppLauncher> installer = - new EphemeralAppLauncher(webstore_item_id, - profile, - parent_window, - callback); - installer->set_install_source(WebstoreInstaller::INSTALL_SOURCE_APP_LAUNCHER); - return installer; -} - -// static -scoped_refptr<EphemeralAppLauncher> EphemeralAppLauncher::CreateForWebContents( - const std::string& webstore_item_id, - content::WebContents* web_contents, - const LaunchCallback& callback) { - scoped_refptr<EphemeralAppLauncher> installer = - new EphemeralAppLauncher(webstore_item_id, web_contents, callback); - installer->set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER); - return installer; -} - -void EphemeralAppLauncher::Start() { - if (!IsFeatureEnabled()) { - InvokeCallback(webstore_install::LAUNCH_FEATURE_DISABLED, - kFeatureDisabledError); - return; - } - - // Check whether the app already exists in extension system before downloading - // from the webstore. - const Extension* extension = - ExtensionRegistry::Get(profile()) - ->GetExtensionById(id(), ExtensionRegistry::EVERYTHING); - if (extension) { - webstore_install::Result result = webstore_install::OTHER_ERROR; - std::string error; - if (!CanLaunchInstalledApp(extension, &result, &error)) { - InvokeCallback(result, error); - return; - } - - if (extensions::util::IsAppLaunchableWithoutEnabling(extension->id(), - profile())) { - LaunchApp(extension); - InvokeCallback(webstore_install::SUCCESS, std::string()); - return; - } - - EnableInstalledApp(extension); - return; - } - - // Install the app ephemerally and launch when complete. - BeginInstall(); -} - -EphemeralAppLauncher::EphemeralAppLauncher(const std::string& webstore_item_id, - Profile* profile, - gfx::NativeWindow parent_window, - const LaunchCallback& callback) - : WebstoreStandaloneInstaller(webstore_item_id, profile, Callback()), - launch_callback_(callback), - parent_window_(parent_window), - dummy_web_contents_( - WebContents::Create(WebContents::CreateParams(profile))) { - if (parent_window_) - parent_window_tracker_ = NativeWindowTracker::Create(parent_window); -} - -EphemeralAppLauncher::EphemeralAppLauncher(const std::string& webstore_item_id, - content::WebContents* web_contents, - const LaunchCallback& callback) - : WebstoreStandaloneInstaller(webstore_item_id, - ProfileForWebContents(web_contents), - Callback()), - content::WebContentsObserver(web_contents), - launch_callback_(callback), - parent_window_(NativeWindowForWebContents(web_contents)) { -} - -EphemeralAppLauncher::~EphemeralAppLauncher() {} - -scoped_ptr<extensions::ExtensionInstallChecker> -EphemeralAppLauncher::CreateInstallChecker() { - return make_scoped_ptr(new ExtensionInstallChecker(profile())); -} - -scoped_ptr<ExtensionInstallPrompt> EphemeralAppLauncher::CreateInstallUI() { - if (web_contents()) - return make_scoped_ptr(new ExtensionInstallPrompt(web_contents())); - - return make_scoped_ptr(new ExtensionInstallPrompt(profile(), parent_window_)); -} - -scoped_ptr<WebstoreInstaller::Approval> EphemeralAppLauncher::CreateApproval() - const { - scoped_ptr<WebstoreInstaller::Approval> approval = - WebstoreStandaloneInstaller::CreateApproval(); - approval->is_ephemeral = true; - return approval.Pass(); -} - -bool EphemeralAppLauncher::CanLaunchInstalledApp( - const extensions::Extension* extension, - webstore_install::Result* reason, - std::string* error) { - if (!CheckCommonLaunchCriteria(profile(), extension, reason, error)) - return false; - - // Do not launch blacklisted apps. - if (ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(extension->id())) { - *reason = webstore_install::BLACKLISTED; - *error = kBlacklistedError; - return false; - } - - // If the app has missing requirements, it cannot be launched. - if (!extensions::util::IsAppLaunchable(extension->id(), profile())) { - *reason = webstore_install::REQUIREMENT_VIOLATIONS; - *error = kRequirementsError; - return false; - } - - return true; -} - -void EphemeralAppLauncher::EnableInstalledApp(const Extension* extension) { - // Check whether an install is already in progress. - webstore_install::Result result = webstore_install::OTHER_ERROR; - std::string error; - if (!EnsureUniqueInstall(&result, &error)) { - InvokeCallback(result, error); - return; - } - - // Keep this object alive until the enable flow is complete. Either - // ExtensionEnableFlowFinished() or ExtensionEnableFlowAborted() will be - // called. - AddRef(); - - extension_enable_flow_.reset( - new ExtensionEnableFlow(profile(), extension->id(), this)); - if (web_contents()) - extension_enable_flow_->StartForWebContents(web_contents()); - else - extension_enable_flow_->StartForNativeWindow(parent_window_); -} - -void EphemeralAppLauncher::MaybeLaunchApp() { - webstore_install::Result result = webstore_install::OTHER_ERROR; - std::string error; - - ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); - const Extension* extension = - registry->GetExtensionById(id(), ExtensionRegistry::EVERYTHING); - if (extension) { - // Although the installation was successful, the app may not be - // launchable. - if (registry->enabled_extensions().Contains(extension->id())) { - result = webstore_install::SUCCESS; - LaunchApp(extension); - } else { - error = kAppDisabledError; - // Determine why the app cannot be launched. - CanLaunchInstalledApp(extension, &result, &error); - } - } else { - // The extension must be present in the registry if installed. - NOTREACHED(); - error = kMissingAppError; - } - - InvokeCallback(result, error); -} - -void EphemeralAppLauncher::LaunchApp(const Extension* extension) const { - DCHECK(extension && extension->is_app() && - ExtensionRegistry::Get(profile()) - ->GetExtensionById(extension->id(), ExtensionRegistry::ENABLED)); - - AppLaunchParams params(profile(), extension, NEW_FOREGROUND_TAB, - extensions::SOURCE_EPHEMERAL_APP); - params.desktop_type = - chrome::GetHostDesktopTypeForNativeWindow(parent_window_); - OpenApplication(params); -} - -bool EphemeralAppLauncher::LaunchHostedApp(const Extension* extension) const { - GURL launch_url = extensions::AppLaunchInfo::GetLaunchWebURL(extension); - if (!launch_url.is_valid()) - return false; - - chrome::ScopedTabbedBrowserDisplayer displayer( - profile(), chrome::GetHostDesktopTypeForNativeWindow(parent_window_)); - chrome::NavigateParams params( - displayer.browser(), launch_url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL); - params.disposition = NEW_FOREGROUND_TAB; - chrome::Navigate(¶ms); - return true; -} - -void EphemeralAppLauncher::InvokeCallback(webstore_install::Result result, - const std::string& error) { - if (!launch_callback_.is_null()) { - LaunchCallback callback = launch_callback_; - launch_callback_.Reset(); - callback.Run(result, error); - } -} - -void EphemeralAppLauncher::AbortLaunch(webstore_install::Result result, - const std::string& error) { - InvokeCallback(result, error); - WebstoreStandaloneInstaller::CompleteInstall(result, error); -} - -void EphemeralAppLauncher::CheckEphemeralInstallPermitted() { - scoped_refptr<const Extension> extension = GetLocalizedExtensionForDisplay(); - DCHECK(extension.get()); // Checked in OnManifestParsed(). - - install_checker_ = CreateInstallChecker(); - DCHECK(install_checker_.get()); - - install_checker_->set_extension(extension); - install_checker_->Start(ExtensionInstallChecker::CHECK_BLACKLIST | - ExtensionInstallChecker::CHECK_REQUIREMENTS, - true, - base::Bind(&EphemeralAppLauncher::OnInstallChecked, - base::Unretained(this))); -} - -void EphemeralAppLauncher::OnInstallChecked(int check_failures) { - if (!CheckRequestorAlive()) { - AbortLaunch(webstore_install::OTHER_ERROR, std::string()); - return; - } - - if (install_checker_->blacklist_state() == extensions::BLACKLISTED_MALWARE) { - AbortLaunch(webstore_install::BLACKLISTED, kBlacklistedError); - return; - } - - if (!install_checker_->requirement_errors().empty()) { - AbortLaunch(webstore_install::REQUIREMENT_VIOLATIONS, - install_checker_->requirement_errors().front()); - return; - } - - // Proceed with the normal install flow. - ProceedWithInstallPrompt(); -} - -void EphemeralAppLauncher::InitInstallData( - extensions::ActiveInstallData* install_data) const { - install_data->is_ephemeral = true; -} - -bool EphemeralAppLauncher::CheckRequestorAlive() const { - if (!parent_window_) { - // Assume the requestor is always alive if |parent_window_| is null. - return true; - } - - return (web_contents() != nullptr || - (parent_window_tracker_ && - !parent_window_tracker_->WasNativeWindowClosed())); -} - -const GURL& EphemeralAppLauncher::GetRequestorURL() const { - return GURL::EmptyGURL(); -} - -bool EphemeralAppLauncher::ShouldShowPostInstallUI() const { - return false; -} - -bool EphemeralAppLauncher::ShouldShowAppInstalledBubble() const { - return false; -} - -WebContents* EphemeralAppLauncher::GetWebContents() const { - return web_contents() ? web_contents() : dummy_web_contents_.get(); -} - -scoped_refptr<ExtensionInstallPrompt::Prompt> -EphemeralAppLauncher::CreateInstallPrompt() const { - const Extension* extension = localized_extension_for_display(); - DCHECK(extension); // Checked in OnManifestParsed(). - - // Skip the prompt by returning null if the app does not need to display - // permission warnings. - if (extension->permissions_data()->GetPermissionMessages().empty()) - return NULL; - - return make_scoped_refptr(new ExtensionInstallPrompt::Prompt( - ExtensionInstallPrompt::LAUNCH_PROMPT)); -} - -bool EphemeralAppLauncher::CheckInlineInstallPermitted( - const base::DictionaryValue& webstore_data, - std::string* error) const { - *error = ""; - return true; -} - -bool EphemeralAppLauncher::CheckRequestorPermitted( - const base::DictionaryValue& webstore_data, - std::string* error) const { - *error = ""; - return true; -} - -void EphemeralAppLauncher::OnManifestParsed() { - scoped_refptr<const Extension> extension = GetLocalizedExtensionForDisplay(); - if (!extension.get()) { - AbortLaunch(webstore_install::INVALID_MANIFEST, kInvalidManifestError); - return; - } - - webstore_install::Result result = webstore_install::OTHER_ERROR; - std::string error; - if (!CheckCommonLaunchCriteria(profile(), extension.get(), &result, &error)) { - AbortLaunch(result, error); - return; - } - - if (extension->is_legacy_packaged_app()) { - AbortLaunch(webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE, - kAppTypeError); - return; - } - - if (extension->is_hosted_app()) { - // Hosted apps do not need to be installed ephemerally. Just navigate to - // their launch url. - if (LaunchHostedApp(extension.get())) - AbortLaunch(webstore_install::SUCCESS, std::string()); - else - AbortLaunch(webstore_install::INVALID_MANIFEST, kInvalidManifestError); - return; - } - - CheckEphemeralInstallPermitted(); -} - -void EphemeralAppLauncher::CompleteInstall(webstore_install::Result result, - const std::string& error) { - if (result == webstore_install::SUCCESS) - MaybeLaunchApp(); - else if (!launch_callback_.is_null()) - InvokeCallback(result, error); - - WebstoreStandaloneInstaller::CompleteInstall(result, error); -} - -void EphemeralAppLauncher::WebContentsDestroyed() { - launch_callback_.Reset(); - AbortInstall(); -} - -void EphemeralAppLauncher::ExtensionEnableFlowFinished() { - MaybeLaunchApp(); - - // CompleteInstall will call Release. - WebstoreStandaloneInstaller::CompleteInstall(webstore_install::SUCCESS, - std::string()); -} - -void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) { - // CompleteInstall will call Release. - CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError); -} diff --git a/chrome/browser/apps/ephemeral_app_launcher.h b/chrome/browser/apps/ephemeral_app_launcher.h deleted file mode 100644 index 1ffab65..0000000 --- a/chrome/browser/apps/ephemeral_app_launcher.h +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ -#define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ - -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/callback.h" -#include "base/scoped_observer.h" -#include "chrome/browser/extensions/webstore_standalone_installer.h" -#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" -#include "content/public/browser/web_contents_observer.h" - -class ExtensionEnableFlow; -class NativeWindowTracker; -class Profile; - -namespace content { -class WebContents; -} - -namespace extensions { -class Extension; -class ExtensionInstallChecker; -class ExtensionRegistry; -} - -// EphemeralAppLauncher manages the launching of ephemeral apps. It handles -// display of a prompt, initiates install of the app (if necessary) and finally -// launches the app. -class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller, - public content::WebContentsObserver, - public ExtensionEnableFlowDelegate { - public: - typedef base::Callback<void(extensions::webstore_install::Result result, - const std::string& error)> LaunchCallback; - - // Returns true if launching ephemeral apps from the webstore is enabled. - static bool IsFeatureEnabled(); - - // Create for the app launcher. - static scoped_refptr<EphemeralAppLauncher> CreateForLauncher( - const std::string& webstore_item_id, - Profile* profile, - gfx::NativeWindow parent_window, - const LaunchCallback& callback); - - // Create for a web contents. - static scoped_refptr<EphemeralAppLauncher> CreateForWebContents( - const std::string& webstore_item_id, - content::WebContents* web_contents, - const LaunchCallback& callback); - - // Initiate app launch. - void Start(); - - protected: - EphemeralAppLauncher(const std::string& webstore_item_id, - Profile* profile, - gfx::NativeWindow parent_window, - const LaunchCallback& callback); - EphemeralAppLauncher(const std::string& webstore_item_id, - content::WebContents* web_contents, - const LaunchCallback& callback); - - ~EphemeralAppLauncher() override; - - // Creates an install checker. Allows tests to mock the install checker. - virtual scoped_ptr<extensions::ExtensionInstallChecker> - CreateInstallChecker(); - - // WebstoreStandaloneInstaller implementation overridden in tests. - scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override; - scoped_ptr<extensions::WebstoreInstaller::Approval> CreateApproval() - const override; - - private: - friend class base::RefCountedThreadSafe<EphemeralAppLauncher>; - friend class EphemeralAppLauncherTest; - - // Returns true if an app that is already installed in extension system can - // be launched. - bool CanLaunchInstalledApp(const extensions::Extension* extension, - extensions::webstore_install::Result* reason, - std::string* error); - - // Initiates the enable flow for an app before it can be launched. - void EnableInstalledApp(const extensions::Extension* extension); - - // After the ephemeral installation or enable flow are complete, attempts to - // launch the app and notify the client of the outcome. - void MaybeLaunchApp(); - - // Launches an app. At this point, it is assumed that the app is enabled and - // can be launched. - void LaunchApp(const extensions::Extension* extension) const; - - // Navigates to the launch URL of a hosted app in a new browser tab. - bool LaunchHostedApp(const extensions::Extension* extension) const; - - // Notifies the client of the launch outcome. - void InvokeCallback(extensions::webstore_install::Result result, - const std::string& error); - - // Aborts the ephemeral install and notifies the client of the outcome. - void AbortLaunch(extensions::webstore_install::Result result, - const std::string& error); - - // Determines whether the app can be installed ephemerally. - void CheckEphemeralInstallPermitted(); - - // Install checker callback. - void OnInstallChecked(int check_failures); - - // WebstoreStandaloneInstaller implementation. - void InitInstallData( - extensions::ActiveInstallData* install_data) const override; - bool CheckRequestorAlive() const override; - const GURL& GetRequestorURL() const override; - bool ShouldShowPostInstallUI() const override; - bool ShouldShowAppInstalledBubble() const override; - content::WebContents* GetWebContents() const override; - scoped_refptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt() - const override; - bool CheckInlineInstallPermitted(const base::DictionaryValue& webstore_data, - std::string* error) const override; - bool CheckRequestorPermitted(const base::DictionaryValue& webstore_data, - std::string* error) const override; - void OnManifestParsed() override; - void CompleteInstall(extensions::webstore_install::Result result, - const std::string& error) override; - - // content::WebContentsObserver implementation. - void WebContentsDestroyed() override; - - // ExtensionEnableFlowDelegate implementation. - void ExtensionEnableFlowFinished() override; - void ExtensionEnableFlowAborted(bool user_initiated) override; - - LaunchCallback launch_callback_; - - gfx::NativeWindow parent_window_; - scoped_ptr<NativeWindowTracker> parent_window_tracker_; - scoped_ptr<content::WebContents> dummy_web_contents_; - - scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; - - scoped_ptr<extensions::ExtensionInstallChecker> install_checker_; - - DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher); -}; - -#endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ diff --git a/chrome/browser/apps/ephemeral_app_launcher_browsertest.cc b/chrome/browser/apps/ephemeral_app_launcher_browsertest.cc deleted file mode 100644 index fbeb7f8..0000000 --- a/chrome/browser/apps/ephemeral_app_launcher_browsertest.cc +++ /dev/null @@ -1,563 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/thread_task_runner_handle.h" -#include "chrome/browser/apps/ephemeral_app_launcher.h" -#include "chrome/browser/apps/ephemeral_app_service.h" -#include "chrome/browser/extensions/extension_install_checker.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/install_tracker.h" -#include "chrome/browser/extensions/test_blacklist.h" -#include "chrome/browser/extensions/webstore_installer_test.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/common/chrome_switches.h" -#include "content/public/browser/web_contents.h" -#include "content/public/test/test_utils.h" -#include "extensions/browser/extension_prefs.h" -#include "extensions/browser/extension_registry.h" -#include "extensions/browser/extension_system.h" -#include "extensions/browser/extension_util.h" -#include "extensions/browser/management_policy.h" -#include "extensions/browser/process_manager.h" -#include "extensions/browser/test_extension_registry_observer.h" -#include "extensions/test/extension_test_message_listener.h" - -using extensions::Extension; -using extensions::ExtensionPrefs; -using extensions::ExtensionRegistry; -using extensions::ExtensionSystem; -using extensions::InstallTracker; -namespace webstore_install = extensions::webstore_install; - -namespace { - -const char kWebstoreDomain[] = "cws.com"; -const char kAppDomain[] = "app.com"; -const char kNonAppDomain[] = "nonapp.com"; -const char kTestDataPath[] = "extensions/platform_apps/ephemeral_launcher"; - -const char kExtensionId[] = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeid"; -const char kExtensionTestPath[] = "extension"; -const char kLegacyAppId[] = "lnbochkobjfnhbnbljgfgokadhmbahcn"; -const char kLegacyAppTestPath[] = "legacy_app"; -const char kNonExistentId[] = "baaaaaaaaaaaaaaaaaaaaaaaaaaaadid"; -const char kDefaultAppId[] = "kbiancnbopdghkfedjhfdoegjadfjeal"; -const char kDefaultAppCrxFilename[] = "app.crx"; -const char kDefaultAppTestPath[] = "app"; -const char kAppWithPermissionsId[] = "mbfcnecjknjpipkfkoangpfnhhlpamki"; -const char kAppWithPermissionsFilename[] = "app_with_permissions.crx"; -const char kHostedAppId[] = "haaaaaaaaaaaaaaaaaaaaaaaaaaappid"; -const char kHostedAppLaunchUrl[] = "http://foo.bar.com"; - -class ExtensionInstallCheckerMock : public extensions::ExtensionInstallChecker { - public: - ExtensionInstallCheckerMock(Profile* profile, - const std::string& requirements_error) - : extensions::ExtensionInstallChecker(profile), - requirements_error_(requirements_error) {} - - ~ExtensionInstallCheckerMock() override {} - - private: - void CheckRequirements() override { - // Simulate an asynchronous operation. - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, - base::Bind(&ExtensionInstallCheckerMock::RequirementsErrorCheckDone, - base::Unretained(this), current_sequence_number())); - } - - void RequirementsErrorCheckDone(int sequence_number) { - std::vector<std::string> errors; - errors.push_back(requirements_error_); - OnRequirementsCheckDone(sequence_number, errors); - } - - std::string requirements_error_; -}; - -class EphemeralAppLauncherForTest : public EphemeralAppLauncher { - public: - EphemeralAppLauncherForTest(const std::string& id, - Profile* profile, - const LaunchCallback& callback) - : EphemeralAppLauncher(id, profile, NULL, callback), - install_initiated_(false), - install_prompt_created_(false) {} - - EphemeralAppLauncherForTest(const std::string& id, Profile* profile) - : EphemeralAppLauncher(id, profile, NULL, LaunchCallback()), - install_initiated_(false), - install_prompt_created_(false) {} - - bool install_initiated() const { return install_initiated_; } - bool install_prompt_created() const { return install_prompt_created_; } - - void set_requirements_error(const std::string& error) { - requirements_check_error_ = error; - } - - private: - // Override necessary functions for testing. - - scoped_ptr<extensions::ExtensionInstallChecker> CreateInstallChecker() - override { - if (requirements_check_error_.empty()) { - return EphemeralAppLauncher::CreateInstallChecker(); - } else { - return scoped_ptr<extensions::ExtensionInstallChecker>( - new ExtensionInstallCheckerMock(profile(), - requirements_check_error_)); - } - } - - scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { - install_prompt_created_ = true; - return EphemeralAppLauncher::CreateInstallUI(); - } - - scoped_ptr<extensions::WebstoreInstaller::Approval> CreateApproval() - const override { - install_initiated_ = true; - return EphemeralAppLauncher::CreateApproval(); - } - - private: - ~EphemeralAppLauncherForTest() override {} - friend class base::RefCountedThreadSafe<EphemeralAppLauncherForTest>; - - mutable bool install_initiated_; - std::string requirements_check_error_; - bool install_prompt_created_; -}; - -class LaunchObserver { - public: - LaunchObserver() - : done_(false), - waiting_(false), - result_(webstore_install::OTHER_ERROR) {} - - webstore_install::Result result() const { return result_; } - const std::string& error() const { return error_; } - - void OnLaunchCallback(webstore_install::Result result, - const std::string& error) { - result_ = result; - error_ = error; - done_ = true; - if (waiting_) { - waiting_ = false; - base::MessageLoopForUI::current()->QuitWhenIdle(); - } - } - - void Wait() { - if (done_) - return; - - waiting_ = true; - content::RunMessageLoop(); - } - - private: - bool done_; - bool waiting_; - webstore_install::Result result_; - std::string error_; -}; - -class ManagementPolicyMock : public extensions::ManagementPolicy::Provider { - public: - ManagementPolicyMock() {} - - std::string GetDebugPolicyProviderName() const override { - return "ManagementPolicyMock"; - } - - bool UserMayLoad(const Extension* extension, - base::string16* error) const override { - return false; - } -}; - -} // namespace - -class EphemeralAppLauncherTest : public WebstoreInstallerTest { - public: - EphemeralAppLauncherTest() - : WebstoreInstallerTest(kWebstoreDomain, - kTestDataPath, - kDefaultAppCrxFilename, - kAppDomain, - kNonAppDomain) {} - - void SetUpCommandLine(base::CommandLine* command_line) override { - WebstoreInstallerTest::SetUpCommandLine(command_line); - - // Make event pages get suspended immediately. - extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); - extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); - - // Enable ephemeral apps flag. - command_line->AppendSwitch(switches::kEnableEphemeralAppsInWebstore); - } - - void SetUpOnMainThread() override { - WebstoreInstallerTest::SetUpOnMainThread(); - - // Disable ephemeral apps immediately after they stop running in tests. - EphemeralAppService::Get(profile())->set_disable_delay_for_test(0); - } - - base::FilePath GetTestPath(const char* test_name) { - return test_data_dir_.AppendASCII("platform_apps/ephemeral_launcher") - .AppendASCII(test_name); - } - - const Extension* GetInstalledExtension(const std::string& id) { - return ExtensionRegistry::Get(profile()) - ->GetExtensionById(id, ExtensionRegistry::EVERYTHING); - } - - void SetCrxFilename(const std::string& filename) { - GURL crx_url = GenerateTestServerUrl(kWebstoreDomain, filename); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kAppsGalleryUpdateURL, crx_url.spec()); - } - - void StartLauncherAndCheckResult(EphemeralAppLauncherForTest* launcher, - webstore_install::Result expected_result, - bool expect_install_initiated) { - ExtensionTestMessageListener launched_listener("launched", false); - LaunchObserver launch_observer; - - launcher->launch_callback_ = base::Bind(&LaunchObserver::OnLaunchCallback, - base::Unretained(&launch_observer)); - launcher->Start(); - launch_observer.Wait(); - - // Verify the launch result. - EXPECT_EQ(expected_result, launch_observer.result()); - EXPECT_EQ(expect_install_initiated, launcher->install_initiated()); - - // Verify that the app was actually launched if the launcher succeeded. - if (launch_observer.result() == webstore_install::SUCCESS) - EXPECT_TRUE(launched_listener.WaitUntilSatisfied()); - else - EXPECT_FALSE(launched_listener.was_satisfied()); - - // Check the reference count to ensure the launcher instance will not be - // leaked. - EXPECT_TRUE(launcher->HasOneRef()); - } - - void RunLaunchTest(const std::string& id, - webstore_install::Result expected_result, - bool expect_install_initiated) { - InstallTracker* tracker = InstallTracker::Get(profile()); - ASSERT_TRUE(tracker); - bool was_install_active = !!tracker->GetActiveInstall(id); - - scoped_refptr<EphemeralAppLauncherForTest> launcher( - new EphemeralAppLauncherForTest(id, profile())); - StartLauncherAndCheckResult( - launcher.get(), expected_result, expect_install_initiated); - - // Verify that the install was deregistered from the InstallTracker. - EXPECT_EQ(was_install_active, !!tracker->GetActiveInstall(id)); - } - - void ValidateAppInstalledEphemerally(const std::string& id) { - EXPECT_TRUE(GetInstalledExtension(id)); - EXPECT_TRUE(extensions::util::IsEphemeralApp(id, profile())); - } - - const Extension* InstallAndDisableApp( - const char* test_path, - Extension::DisableReason disable_reason) { - const Extension* app = InstallExtension(GetTestPath(test_path), 1); - EXPECT_TRUE(app); - if (!app) - return NULL; - - ExtensionService* service = - ExtensionSystem::Get(profile())->extension_service(); - service->DisableExtension(app->id(), disable_reason); - - EXPECT_TRUE( - ExtensionRegistry::Get(profile())->disabled_extensions().Contains( - app->id())); - return app; - } -}; - -class EphemeralAppLauncherTestDisabled : public EphemeralAppLauncherTest { - public: - void SetUpCommandLine(base::CommandLine* command_line) override { - // Skip EphemeralAppLauncherTest as it enables the feature. - WebstoreInstallerTest::SetUpCommandLine(command_line); - } -}; - -// Verifies that an ephemeral app will not be installed and launched if the -// feature is disabled. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTestDisabled, FeatureDisabled) { - RunLaunchTest( - kDefaultAppCrxFilename, webstore_install::LAUNCH_FEATURE_DISABLED, false); - EXPECT_FALSE(GetInstalledExtension(kDefaultAppId)); -} - -// Verifies that an app with no permission warnings will be installed -// ephemerally and launched without prompting the user. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, - LaunchAppWithNoPermissionWarnings) { - extensions::TestExtensionRegistryObserver observer( - ExtensionRegistry::Get(profile())); - - scoped_refptr<EphemeralAppLauncherForTest> launcher( - new EphemeralAppLauncherForTest(kDefaultAppId, profile())); - StartLauncherAndCheckResult(launcher.get(), webstore_install::SUCCESS, true); - ValidateAppInstalledEphemerally(kDefaultAppId); - - // Apps with no permission warnings should not result in a prompt. - EXPECT_FALSE(launcher->install_prompt_created()); - - // Ephemeral apps are unloaded after they stop running. - observer.WaitForExtensionUnloaded(); - - // After an app has been installed ephemerally, it can be launched again - // without installing from the web store. - RunLaunchTest(kDefaultAppId, webstore_install::SUCCESS, false); -} - -// Verifies that an app with permission warnings will be installed -// ephemerally and launched if accepted by the user. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, - LaunchAppWithPermissionsWarnings) { - SetCrxFilename(kAppWithPermissionsFilename); - AutoAcceptInstall(); - - scoped_refptr<EphemeralAppLauncherForTest> launcher( - new EphemeralAppLauncherForTest(kAppWithPermissionsId, profile())); - StartLauncherAndCheckResult(launcher.get(), webstore_install::SUCCESS, true); - ValidateAppInstalledEphemerally(kAppWithPermissionsId); - EXPECT_TRUE(launcher->install_prompt_created()); -} - -// Verifies that an app with permission warnings will not be installed -// ephemerally if cancelled by the user. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, - CancelInstallAppWithPermissionWarnings) { - SetCrxFilename(kAppWithPermissionsFilename); - AutoCancelInstall(); - - scoped_refptr<EphemeralAppLauncherForTest> launcher( - new EphemeralAppLauncherForTest(kAppWithPermissionsId, profile())); - StartLauncherAndCheckResult( - launcher.get(), webstore_install::USER_CANCELLED, false); - EXPECT_FALSE(GetInstalledExtension(kAppWithPermissionsId)); - EXPECT_TRUE(launcher->install_prompt_created()); -} - -// Verifies that an extension will not be installed ephemerally. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, InstallExtension) { - RunLaunchTest( - kExtensionId, webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE, false); - EXPECT_FALSE(GetInstalledExtension(kExtensionId)); -} - -// Verifies that an already installed extension will not be launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchExtension) { - const Extension* extension = - InstallExtension(GetTestPath(kExtensionTestPath), 1); - ASSERT_TRUE(extension); - RunLaunchTest(extension->id(), - webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE, - false); -} - -// Verifies that a legacy packaged app will not be installed ephemerally. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, InstallLegacyApp) { - RunLaunchTest( - kLegacyAppId, webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE, false); - EXPECT_FALSE(GetInstalledExtension(kLegacyAppId)); -} - -// Verifies that a legacy packaged app that is already installed can be -// launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchLegacyApp) { - const Extension* extension = - InstallExtension(GetTestPath(kLegacyAppTestPath), 1); - ASSERT_TRUE(extension); - RunLaunchTest(extension->id(), webstore_install::SUCCESS, false); -} - -// Verifies that a hosted app is not installed. Launch succeeds because we -// navigate to its launch url. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchHostedApp) { - LaunchObserver launch_observer; - - scoped_refptr<EphemeralAppLauncherForTest> launcher( - new EphemeralAppLauncherForTest( - kHostedAppId, - profile(), - base::Bind(&LaunchObserver::OnLaunchCallback, - base::Unretained(&launch_observer)))); - launcher->Start(); - launch_observer.Wait(); - - EXPECT_EQ(webstore_install::SUCCESS, launch_observer.result()); - EXPECT_FALSE(launcher->install_initiated()); - EXPECT_FALSE(GetInstalledExtension(kHostedAppId)); - - // Verify that a navigation to the launch url was attempted. - Browser* browser = - FindBrowserWithProfile(profile(), chrome::GetActiveDesktop()); - ASSERT_TRUE(browser); - content::WebContents* web_contents = - browser->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(web_contents); - EXPECT_EQ(GURL(kHostedAppLaunchUrl), web_contents->GetVisibleURL()); -} - -// Verifies that the EphemeralAppLauncher handles non-existent extension ids. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, NonExistentExtensionId) { - RunLaunchTest( - kNonExistentId, webstore_install::WEBSTORE_REQUEST_ERROR, false); - EXPECT_FALSE(GetInstalledExtension(kNonExistentId)); -} - -// Verifies that an app blocked by management policy is not installed -// ephemerally. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlockedByPolicy) { - // Register a provider that blocks the installation of all apps. - ManagementPolicyMock policy; - ExtensionSystem::Get(profile())->management_policy()->RegisterProvider( - &policy); - - RunLaunchTest(kDefaultAppId, webstore_install::BLOCKED_BY_POLICY, false); - EXPECT_FALSE(GetInstalledExtension(kDefaultAppId)); -} - -// The blacklist relies on safe-browsing database infrastructure. -#if defined(SAFE_BROWSING_DB_LOCAL) -// Verifies that an app blacklisted for malware is not installed ephemerally. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlacklistedForMalware) { - // Mock a BLACKLISTED_MALWARE return status. - extensions::TestBlacklist blacklist_tester( - extensions::Blacklist::Get(profile())); - blacklist_tester.SetBlacklistState( - kDefaultAppId, extensions::BLACKLISTED_MALWARE, false); - - RunLaunchTest(kDefaultAppId, webstore_install::BLACKLISTED, false); - EXPECT_FALSE(GetInstalledExtension(kDefaultAppId)); -} - -// Verifies that an app with unknown blacklist status is installed ephemerally -// and launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlacklistStateUnknown) { - // Mock a BLACKLISTED_MALWARE return status. - extensions::TestBlacklist blacklist_tester( - extensions::Blacklist::Get(profile())); - blacklist_tester.SetBlacklistState( - kDefaultAppId, extensions::BLACKLISTED_UNKNOWN, false); - - RunLaunchTest(kDefaultAppId, webstore_install::SUCCESS, true); - ValidateAppInstalledEphemerally(kDefaultAppId); -} -#endif - -// Verifies that an app with unsupported requirements is not installed -// ephemerally. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, UnsupportedRequirements) { - scoped_refptr<EphemeralAppLauncherForTest> launcher( - new EphemeralAppLauncherForTest(kDefaultAppId, profile())); - launcher->set_requirements_error("App has unsupported requirements"); - - StartLauncherAndCheckResult( - launcher.get(), webstore_install::REQUIREMENT_VIOLATIONS, false); - EXPECT_FALSE(GetInstalledExtension(kDefaultAppId)); -} - -// Verifies that an app disabled due to permissions increase can be enabled -// and launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, EnableAndLaunchApp) { - const Extension* app = InstallAndDisableApp( - kDefaultAppTestPath, Extension::DISABLE_PERMISSIONS_INCREASE); - ASSERT_TRUE(app); - - AutoAcceptInstall(); - RunLaunchTest(app->id(), webstore_install::SUCCESS, false); -} - -// Verifies that if the user cancels the enable flow, the app will not be -// enabled and launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, EnableCancelled) { - const Extension* app = InstallAndDisableApp( - kDefaultAppTestPath, Extension::DISABLE_PERMISSIONS_INCREASE); - ASSERT_TRUE(app); - - AutoCancelInstall(); - RunLaunchTest(app->id(), webstore_install::USER_CANCELLED, false); -} - -// Verifies that an installed app that had been blocked by policy cannot be -// launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchAppBlockedByPolicy) { - const Extension* app = InstallExtension(GetTestPath(kDefaultAppTestPath), 1); - ASSERT_TRUE(app); - - // Simulate blocking of the app after it has been installed. - ManagementPolicyMock policy; - ExtensionSystem::Get(profile())->management_policy()->RegisterProvider( - &policy); - ExtensionSystem::Get(profile())->extension_service()->CheckManagementPolicy(); - - RunLaunchTest(app->id(), webstore_install::BLOCKED_BY_POLICY, false); -} - -// Verifies that an installed blacklisted app cannot be launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchBlacklistedApp) { - const Extension* app = InstallExtension(GetTestPath(kDefaultAppTestPath), 1); - ASSERT_TRUE(app); - - ExtensionService* service = - ExtensionSystem::Get(profile())->extension_service(); - service->BlacklistExtensionForTest(app->id()); - ASSERT_TRUE( - ExtensionRegistry::Get(profile())->blacklisted_extensions().Contains( - app->id())); - - RunLaunchTest(app->id(), webstore_install::BLACKLISTED, false); -} - -// Verifies that an installed app with unsupported requirements cannot be -// launched. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, - LaunchAppWithUnsupportedRequirements) { - const Extension* app = InstallAndDisableApp( - kDefaultAppTestPath, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); - ASSERT_TRUE(app); - - RunLaunchTest(app->id(), webstore_install::REQUIREMENT_VIOLATIONS, false); -} - -// Verifies that a launch will fail if the app is currently being installed. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, InstallInProgress) { - extensions::ActiveInstallData install_data(kDefaultAppId); - InstallTracker::Get(profile())->AddActiveInstall(install_data); - - RunLaunchTest(kDefaultAppId, webstore_install::INSTALL_IN_PROGRESS, false); -} - -// Verifies that a launch will fail if a duplicate launch is in progress. -IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, DuplicateLaunchInProgress) { - extensions::ActiveInstallData install_data(kDefaultAppId); - install_data.is_ephemeral = true; - InstallTracker::Get(profile())->AddActiveInstall(install_data); - - RunLaunchTest(kDefaultAppId, webstore_install::LAUNCH_IN_PROGRESS, false); -} diff --git a/chrome/browser/extensions/active_install_data.cc b/chrome/browser/extensions/active_install_data.cc index f9c9a0c..ee6cdfe 100644 --- a/chrome/browser/extensions/active_install_data.cc +++ b/chrome/browser/extensions/active_install_data.cc @@ -11,11 +11,11 @@ namespace extensions { // ActiveInstallData: ActiveInstallData::ActiveInstallData() - : percent_downloaded(0), is_ephemeral(false) { + : percent_downloaded(0) { } ActiveInstallData::ActiveInstallData(const std::string& extension_id) - : extension_id(extension_id), percent_downloaded(0), is_ephemeral(false) { + : extension_id(extension_id), percent_downloaded(0) { } // ScopedActiveInstall: diff --git a/chrome/browser/extensions/active_install_data.h b/chrome/browser/extensions/active_install_data.h index 4aa5887..c7dd9ba 100644 --- a/chrome/browser/extensions/active_install_data.h +++ b/chrome/browser/extensions/active_install_data.h @@ -23,7 +23,6 @@ struct ActiveInstallData { std::string extension_id; int percent_downloaded; - bool is_ephemeral; }; // Registers and deregisters and an active extension install with the diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc index 11e64a9..f127643 100644 --- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc +++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc @@ -14,7 +14,6 @@ #include "base/thread_task_runner_handle.h" #include "base/values.h" #include "base/version.h" -#include "chrome/browser/apps/ephemeral_app_launcher.h" #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_install_ui_util.h" @@ -100,46 +99,6 @@ chrome::HostDesktopType GetHostDesktopTypeForWebContents( contents->GetTopLevelNativeWindow()); } -api::webstore_private::Result WebstoreInstallResultToApiResult( - webstore_install::Result result) { - switch (result) { - case webstore_install::SUCCESS: - return api::webstore_private::RESULT_SUCCESS; - case webstore_install::OTHER_ERROR: - return api::webstore_private::RESULT_UNKNOWN_ERROR; - case webstore_install::INVALID_ID: - return api::webstore_private::RESULT_INVALID_ID; - case webstore_install::NOT_PERMITTED: - case webstore_install::WEBSTORE_REQUEST_ERROR: - case webstore_install::INVALID_WEBSTORE_RESPONSE: - return api::webstore_private::RESULT_INSTALL_ERROR; - case webstore_install::INVALID_MANIFEST: - return api::webstore_private::RESULT_MANIFEST_ERROR; - case webstore_install::ICON_ERROR: - return api::webstore_private::RESULT_ICON_ERROR; - case webstore_install::ABORTED: - case webstore_install::USER_CANCELLED: - return api::webstore_private::RESULT_USER_CANCELLED; - case webstore_install::BLACKLISTED: - return api::webstore_private::RESULT_BLACKLISTED; - case webstore_install::MISSING_DEPENDENCIES: - case webstore_install::REQUIREMENT_VIOLATIONS: - return api::webstore_private::RESULT_MISSING_DEPENDENCIES; - case webstore_install::BLOCKED_BY_POLICY: - return api::webstore_private::RESULT_BLOCKED_BY_POLICY; - case webstore_install::LAUNCH_FEATURE_DISABLED: - return api::webstore_private::RESULT_FEATURE_DISABLED; - case webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE: - return api::webstore_private::RESULT_UNSUPPORTED_EXTENSION_TYPE; - case webstore_install::INSTALL_IN_PROGRESS: - return api::webstore_private::RESULT_INSTALL_IN_PROGRESS; - case webstore_install::LAUNCH_IN_PROGRESS: - return api::webstore_private::RESULT_LAUNCH_IN_PROGRESS; - } - NOTREACHED(); - return api::webstore_private::RESULT_NONE; -} - api::webstore_private::Result WebstoreInstallHelperResultToApiResult( WebstoreInstallHelper::Delegate::InstallHelperResultCode result) { switch (result) { @@ -174,6 +133,8 @@ const char kNoPreviousBeginInstallWithManifestError[] = const char kUserCancelledError[] = "User cancelled install"; const char kIncognitoError[] = "Apps cannot be installed in guest/incognito mode"; +const char kEphemeralAppLaunchingNotSupported[] = + "Ephemeral launching of apps is no longer supported."; WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr; @@ -746,60 +707,8 @@ WebstorePrivateLaunchEphemeralAppFunction:: ExtensionFunction::ResponseAction WebstorePrivateLaunchEphemeralAppFunction::Run() { - // Check whether the browser window still exists. - content::WebContents* web_contents = - chrome_details_.GetAssociatedWebContents(); - if (!web_contents) - return RespondNow(Error("aborted")); - - if (!user_gesture()) { - return RespondNow(BuildResponse( - api::webstore_private::RESULT_USER_GESTURE_REQUIRED, - "User gesture is required")); - } - - scoped_ptr<LaunchEphemeralApp::Params> params( - LaunchEphemeralApp::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE(params); - - AddRef(); // Balanced in OnLaunchComplete() - - scoped_refptr<EphemeralAppLauncher> launcher = - EphemeralAppLauncher::CreateForWebContents( - params->id, - web_contents, - base::Bind( - &WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete, - base::Unretained(this))); - launcher->Start(); - - return RespondLater(); -} - -void WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete( - webstore_install::Result result, const std::string& error) { - Respond(BuildResponse(WebstoreInstallResultToApiResult(result), error)); - Release(); // Matches AddRef() in Run() -} - -ExtensionFunction::ResponseValue -WebstorePrivateLaunchEphemeralAppFunction::BuildResponse( - api::webstore_private::Result result, const std::string& error) { - if (result != api::webstore_private::RESULT_SUCCESS) { - std::string error_message; - if (error.empty()) { - error_message = base::StringPrintf( - "[%s]", api::webstore_private::ToString(result).c_str()); - } else { - error_message = base::StringPrintf( - "[%s]: %s", - api::webstore_private::ToString(result).c_str(), - error.c_str()); - } - return ErrorWithArguments(LaunchEphemeralApp::Results::Create(result), - error_message); - } - return ArgumentList(LaunchEphemeralApp::Results::Create(result)); + // Just fail as this is no longer supported. + return RespondNow(Error(kEphemeralAppLaunchingNotSupported)); } WebstorePrivateGetEphemeralAppsEnabledFunction:: @@ -811,7 +720,7 @@ WebstorePrivateGetEphemeralAppsEnabledFunction:: ExtensionFunction::ResponseAction WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( - EphemeralAppLauncher::IsFeatureEnabled()))); + false))); } } // namespace extensions diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc index 6d63a6a..656b7d3 100644 --- a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc +++ b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc @@ -32,7 +32,6 @@ #include "gpu/config/gpu_feature_type.h" #include "gpu/config/gpu_info.h" #include "net/dns/mock_host_resolver.h" -#include "ui/app_list/app_list_switches.h" #include "ui/gl/gl_switches.h" using gpu::GpuFeatureType; @@ -398,45 +397,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) { RunTest(webgl_allowed); } -class EphemeralAppWebstorePrivateApiTest - : public ExtensionWebstorePrivateApiTest { - public: - void SetUpInProcessBrowserTestFixture() override { - ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture(); - - net::HostPortPair host_port = test_server()->host_port_pair(); - std::string test_gallery_url = base::StringPrintf( - "http://www.example.com:%d/files/extensions/platform_apps/" - "ephemeral_launcher", - host_port.port()); - base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kAppsGalleryURL, test_gallery_url); - } - - GURL GetTestServerURL(const std::string& path) override { - return DoGetTestServerURL( - std::string("files/extensions/platform_apps/ephemeral_launcher/") + - path); - } -}; - -// Run tests when the --enable-ephemeral-apps switch is not enabled. -IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, - EphemeralAppsFeatureDisabled) { - base::CommandLine::ForCurrentProcess()->AppendSwitch( - app_list::switches::kDisableExperimentalAppList); - ASSERT_TRUE(RunInstallTest("webstore_launch_disabled.html", "app.crx")); -} - -// Run tests when the --enable-ephemeral-apps switch is enabled. -IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, LaunchEphemeralApp) { - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kEnableEphemeralAppsInWebstore); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - app_list::switches::kEnableExperimentalAppList); - ASSERT_TRUE(RunInstallTest("webstore_launch_app.html", "app.crx")); -} - class BundleWebstorePrivateApiTest : public ExtensionWebstorePrivateApiTest { public: diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index bcfd265..898c814 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -157,7 +157,6 @@ CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> service_weak, minimum_version_ = base::Version(*approval->minimum_version); show_dialog_callback_ = approval->show_dialog_callback; - set_is_ephemeral(approval->is_ephemeral); } CrxInstaller::~CrxInstaller() { diff --git a/chrome/browser/extensions/install_observer.cc b/chrome/browser/extensions/install_observer.cc index 37c7565..1145951 100644 --- a/chrome/browser/extensions/install_observer.cc +++ b/chrome/browser/extensions/install_observer.cc @@ -16,7 +16,6 @@ InstallObserver::ExtensionInstallParams::ExtensionInstallParams( extension_name(extension_name), installing_icon(installing_icon), is_app(is_app), - is_platform_app(is_platform_app), - is_ephemeral(false) {} + is_platform_app(is_platform_app) {} } // namespace extensions diff --git a/chrome/browser/extensions/install_observer.h b/chrome/browser/extensions/install_observer.h index faecf14..0185dd3 100644 --- a/chrome/browser/extensions/install_observer.h +++ b/chrome/browser/extensions/install_observer.h @@ -28,7 +28,6 @@ class InstallObserver { gfx::ImageSkia installing_icon; bool is_app; bool is_platform_app; - bool is_ephemeral; }; // Called at the beginning of the complete installation process, i.e., this diff --git a/chrome/browser/extensions/install_tracker.cc b/chrome/browser/extensions/install_tracker.cc index 29758b2..67e0cbb 100644 --- a/chrome/browser/extensions/install_tracker.cc +++ b/chrome/browser/extensions/install_tracker.cc @@ -79,7 +79,6 @@ void InstallTracker::OnBeginExtensionInstall( active_installs_.find(params.extension_id); if (install_data == active_installs_.end()) { ActiveInstallData install_data(params.extension_id); - install_data.is_ephemeral = params.is_ephemeral; active_installs_.insert(std::make_pair(params.extension_id, install_data)); } diff --git a/chrome/browser/extensions/install_tracker_unittest.cc b/chrome/browser/extensions/install_tracker_unittest.cc index e02400f..84572cd 100644 --- a/chrome/browser/extensions/install_tracker_unittest.cc +++ b/chrome/browser/extensions/install_tracker_unittest.cc @@ -61,7 +61,6 @@ class InstallTrackerTest : public testing::Test { void VerifyInstallData(const ActiveInstallData& original, const ActiveInstallData& retrieved) { EXPECT_EQ(original.extension_id, retrieved.extension_id); - EXPECT_EQ(original.is_ephemeral, retrieved.is_ephemeral); EXPECT_EQ(original.percent_downloaded, retrieved.percent_downloaded); } @@ -75,7 +74,6 @@ TEST_F(InstallTrackerTest, AddAndRemoveActiveInstalls) { ActiveInstallData install_data1(kExtensionId1); install_data1.percent_downloaded = 76; ActiveInstallData install_data2(kExtensionId2); - install_data2.is_ephemeral = true; tracker_->AddActiveInstall(install_data1); tracker_->AddActiveInstall(install_data2); @@ -174,7 +172,6 @@ TEST_F(InstallTrackerTest, DownloadProgressUpdated) { TEST_F(InstallTrackerTest, ExtensionInstallFailure) { InstallObserver::ExtensionInstallParams install_params( kExtensionId1, std::string(), gfx::ImageSkia(), false, false); - install_params.is_ephemeral = true; tracker_->OnBeginExtensionInstall(install_params); const ActiveInstallData* retrieved_data = @@ -182,7 +179,6 @@ TEST_F(InstallTrackerTest, ExtensionInstallFailure) { ASSERT_TRUE(retrieved_data); EXPECT_EQ(0, retrieved_data->percent_downloaded); EXPECT_EQ(install_params.extension_id, retrieved_data->extension_id); - EXPECT_EQ(install_params.is_ephemeral, retrieved_data->is_ephemeral); retrieved_data = NULL; tracker_->OnInstallFailure(kExtensionId1); @@ -200,7 +196,6 @@ TEST_F(InstallTrackerTest, ExtensionInstalledEvent) { ASSERT_TRUE(retrieved_data); EXPECT_EQ(0, retrieved_data->percent_downloaded); EXPECT_EQ(install_params.extension_id, retrieved_data->extension_id); - EXPECT_EQ(install_params.is_ephemeral, retrieved_data->is_ephemeral); retrieved_data = NULL; // Simulate an extension install. diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc index d85cfad..f824dd6 100644 --- a/chrome/browser/extensions/webstore_installer.cc +++ b/chrome/browser/extensions/webstore_installer.cc @@ -241,8 +241,7 @@ WebstoreInstaller::Approval::Approval() skip_post_install_ui(false), skip_install_dialog(false), enable_launcher(false), - manifest_check_level(MANIFEST_CHECK_LEVEL_STRICT), - is_ephemeral(false) { + manifest_check_level(MANIFEST_CHECK_LEVEL_STRICT) { } scoped_ptr<WebstoreInstaller::Approval> @@ -358,7 +357,6 @@ void WebstoreInstaller::Start() { approval_->installing_icon, approval_->manifest->is_app(), approval_->manifest->is_platform_app()); - params.is_ephemeral = approval_->is_ephemeral; tracker->OnBeginExtensionInstall(params); tracker->OnBeginExtensionDownload(id_); diff --git a/chrome/browser/extensions/webstore_installer.h b/chrome/browser/extensions/webstore_installer.h index 21f71a7..e02cbc6 100644 --- a/chrome/browser/extensions/webstore_installer.h +++ b/chrome/browser/extensions/webstore_installer.h @@ -161,9 +161,6 @@ class WebstoreInstaller : public content::NotificationObserver, // Required minimum version. scoped_ptr<Version> minimum_version; - // Ephemeral apps are transiently installed. - bool is_ephemeral; - // The authuser index required to download the item being installed. May be // the empty string, in which case no authuser parameter is used. std::string authuser; diff --git a/chrome/browser/extensions/webstore_standalone_installer.cc b/chrome/browser/extensions/webstore_standalone_installer.cc index 5b3ad15..760cb00 100644 --- a/chrome/browser/extensions/webstore_standalone_installer.cc +++ b/chrome/browser/extensions/webstore_standalone_installer.cc @@ -35,7 +35,6 @@ const char kInvalidManifestError[] = "Invalid manifest"; const char kUserCancelledError[] = "User cancelled install"; const char kExtensionIsBlacklisted[] = "Extension is blacklisted"; const char kInstallInProgressError[] = "An install is already in progress"; -const char kLaunchInProgressError[] = "A launch is already in progress"; WebstoreStandaloneInstaller::WebstoreStandaloneInstaller( const std::string& webstore_item_id, @@ -111,13 +110,8 @@ bool WebstoreStandaloneInstaller::EnsureUniqueInstall( const ActiveInstallData* existing_install_data = tracker->GetActiveInstall(id_); if (existing_install_data) { - if (existing_install_data->is_ephemeral) { - *reason = webstore_install::LAUNCH_IN_PROGRESS; - *error = kLaunchInProgressError; - } else { - *reason = webstore_install::INSTALL_IN_PROGRESS; - *error = kInstallInProgressError; - } + *reason = webstore_install::INSTALL_IN_PROGRESS; + *error = kInstallInProgressError; return false; } @@ -215,8 +209,7 @@ void WebstoreStandaloneInstaller::InstallUIProceed() { // Don't install a blacklisted extension. install_result = webstore_install::BLACKLISTED; install_message = kExtensionIsBlacklisted; - } else if (util::IsEphemeralApp(installed_extension->id(), profile_) && - !approval->is_ephemeral) { + } else if (util::IsEphemeralApp(installed_extension->id(), profile_)) { // If the target extension has already been installed ephemerally and is // up to date, it can be promoted to a regular installed extension and // downloading from the Web Store is not necessary. diff --git a/chrome/browser/ui/app_list/extension_app_model_builder.cc b/chrome/browser/ui/app_list/extension_app_model_builder.cc index 32bc979..ec4c287 100644 --- a/chrome/browser/ui/app_list/extension_app_model_builder.cc +++ b/chrome/browser/ui/app_list/extension_app_model_builder.cc @@ -128,7 +128,7 @@ void ExtensionAppModelBuilder::OnExtensionPreferenceChanged() { void ExtensionAppModelBuilder::OnBeginExtensionInstall( const ExtensionInstallParams& params) { - if (!params.is_app || params.is_ephemeral) + if (!params.is_app) return; DVLOG(2) << service_ << ": OnBeginExtensionInstall: " diff --git a/chrome/browser/ui/app_list/search/webstore/webstore_result.cc b/chrome/browser/ui/app_list/search/webstore/webstore_result.cc index 80f9b35..d160709 100644 --- a/chrome/browser/ui/app_list/search/webstore/webstore_result.cc +++ b/chrome/browser/ui/app_list/search/webstore/webstore_result.cc @@ -9,7 +9,6 @@ #include "base/bind.h" #include "base/memory/ref_counted.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/apps/ephemeral_app_launcher.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/install_tracker.h" #include "chrome/browser/extensions/install_tracker_factory.h" |