[Extensions] Obliterating the inline install API.
Removing everything associated with inline installation as it is
deprecated per the announcement in https://blog.chromium.org/2018/06/improving-extension-transparency-for.html
Bug: 882045
Change-Id: Ia24cb4076a841d9b37febe68cad89db7ea1ce1c8
Reviewed-on: https://chromium-review.googlesource.com/c/1220299
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Chris Palmer <[email protected]>
Reviewed-by: Devlin <[email protected]>
Commit-Queue: Benjamin Ackerman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#596334}
diff --git a/chrome/browser/chrome_content_browser_manifest_overlay.json b/chrome/browser/chrome_content_browser_manifest_overlay.json
index 121b4d8..3734fee 100644
--- a/chrome/browser/chrome_content_browser_manifest_overlay.json
+++ b/chrome/browser/chrome_content_browser_manifest_overlay.json
@@ -97,7 +97,6 @@
"extensions.KeepAlive",
"extensions.mime_handler.BeforeUnloadControl",
"extensions.mime_handler.MimeHandlerService",
- "extensions.mojom.InlineInstall",
"media_router.mojom.MediaRouter",
"page_load_metrics.mojom.PageLoadMetrics",
"safe_browsing.mojom.PhishingDetectorClient",
diff --git a/chrome/browser/extensions/BUILD.gn b/chrome/browser/extensions/BUILD.gn
index 9b3afbef..12c729e3 100644
--- a/chrome/browser/extensions/BUILD.gn
+++ b/chrome/browser/extensions/BUILD.gn
@@ -562,8 +562,6 @@
"extension_message_bubble_controller.h",
"extension_migrator.cc",
"extension_migrator.h",
- "extension_reenabler.cc",
- "extension_reenabler.h",
"extension_service.cc",
"extension_service.h",
"extension_special_storage_policy.cc",
@@ -728,10 +726,6 @@
"webstore_data_fetcher.h",
"webstore_data_fetcher_delegate.cc",
"webstore_data_fetcher_delegate.h",
- "webstore_inline_installer.cc",
- "webstore_inline_installer.h",
- "webstore_inline_installer_factory.cc",
- "webstore_inline_installer_factory.h",
"webstore_install_helper.cc",
"webstore_install_helper.h",
"webstore_install_with_prompt.cc",
@@ -742,8 +736,6 @@
"webstore_reinstaller.h",
"webstore_standalone_installer.cc",
"webstore_standalone_installer.h",
- "webstore_startup_installer.cc",
- "webstore_startup_installer.h",
"window_controller.cc",
"window_controller.h",
"window_controller_list.cc",
@@ -792,7 +784,6 @@
"//chrome/browser/web_applications/components",
"//chrome/browser/web_applications/extensions",
"//chrome/common",
- "//chrome/common/extensions:mojo_bindings",
"//chrome/common/extensions/api:extensions_features",
"//chrome/common/safe_browsing:proto",
"//chrome/services/removable_storage_writer/public/mojom",
diff --git a/chrome/browser/extensions/api/inline_install_private/inline_install_private_api.cc b/chrome/browser/extensions/api/inline_install_private/inline_install_private_api.cc
index 66322d8..f49f337 100644
--- a/chrome/browser/extensions/api/inline_install_private/inline_install_private_api.cc
+++ b/chrome/browser/extensions/api/inline_install_private/inline_install_private_api.cc
@@ -30,10 +30,6 @@
friend class base::RefCountedThreadSafe<Installer>;
~Installer() override;
- // Needed so that we send the right referrer value in requests to the
- // webstore.
- const GURL& GetRequestorURL() const override { return requestor_url_; }
-
std::unique_ptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
const override;
@@ -58,7 +54,7 @@
const {
std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt(
new ExtensionInstallPrompt::Prompt(
- ExtensionInstallPrompt::INLINE_INSTALL_PROMPT));
+ ExtensionInstallPrompt::WEBSTORE_WIDGET_PROMPT));
prompt->SetWebstoreData(localized_user_count(),
show_user_count(),
average_rating(),
diff --git a/chrome/browser/extensions/api/webstore_widget_private/app_installer.cc b/chrome/browser/extensions/api/webstore_widget_private/app_installer.cc
index bc08c60..025bfdb 100644
--- a/chrome/browser/extensions/api/webstore_widget_private/app_installer.cc
+++ b/chrome/browser/extensions/api/webstore_widget_private/app_installer.cc
@@ -53,10 +53,6 @@
return web_contents_ != NULL;
}
-const GURL& AppInstaller::GetRequestorURL() const {
- return GURL::EmptyGURL();
-}
-
std::unique_ptr<ExtensionInstallPrompt::Prompt>
AppInstaller::CreateInstallPrompt() const {
if (silent_installation_)
@@ -64,7 +60,7 @@
std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt(
new ExtensionInstallPrompt::Prompt(
- ExtensionInstallPrompt::INLINE_INSTALL_PROMPT));
+ ExtensionInstallPrompt::WEBSTORE_WIDGET_PROMPT));
prompt->SetWebstoreData(localized_user_count(), show_user_count(),
average_rating(), rating_count());
@@ -83,40 +79,6 @@
return web_contents_;
}
-bool AppInstaller::CheckInlineInstallPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- DCHECK(error != NULL);
- DCHECK(error->empty());
-
- // We expect to be able to inline install the app.
- bool inline_install_not_supported = false;
- if (webstore_data.HasKey(kInlineInstallNotSupportedKey) &&
- !webstore_data.GetBoolean(kInlineInstallNotSupportedKey,
- &inline_install_not_supported)) {
- *error = extensions::webstore_install::kInvalidWebstoreResponseError;
- return false;
- }
-
- DCHECK(!inline_install_not_supported)
- << "App does not support inline installation";
-
- if (inline_install_not_supported) {
- *error = extensions::webstore_install::kInvalidWebstoreResponseError;
- return false;
- }
-
- return true;
-}
-
-bool AppInstaller::CheckRequestorPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- DCHECK(error != NULL);
- DCHECK(error->empty());
- return true;
-}
-
void AppInstaller::OnWebContentsDestroyed(content::WebContents* web_contents) {
callback_.Run(false, kWebContentsDestroyedError,
extensions::webstore_install::OTHER_ERROR);
diff --git a/chrome/browser/extensions/api/webstore_widget_private/app_installer.h b/chrome/browser/extensions/api/webstore_widget_private/app_installer.h
index b142bf7..7f379fe 100644
--- a/chrome/browser/extensions/api/webstore_widget_private/app_installer.h
+++ b/chrome/browser/extensions/api/webstore_widget_private/app_installer.h
@@ -37,16 +37,11 @@
// WebstoreStandaloneInstaller implementation.
bool CheckRequestorAlive() const override;
- const GURL& GetRequestorURL() const override;
bool ShouldShowPostInstallUI() const override;
bool ShouldShowAppInstalledBubble() const override;
content::WebContents* GetWebContents() const override;
std::unique_ptr<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;
private:
class WebContentsObserver;
diff --git a/chrome/browser/extensions/extension_install_prompt.cc b/chrome/browser/extensions/extension_install_prompt.cc
index 2f7ef04..8694f7c 100644
--- a/chrome/browser/extensions/extension_install_prompt.cc
+++ b/chrome/browser/extensions/extension_install_prompt.cc
@@ -53,9 +53,9 @@
namespace {
bool AllowWebstoreData(ExtensionInstallPrompt::PromptType type) {
- return type == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT ||
- type == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT ||
- type == ExtensionInstallPrompt::REPAIR_PROMPT;
+ return type == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT ||
+ type == ExtensionInstallPrompt::REPAIR_PROMPT ||
+ type == ExtensionInstallPrompt::WEBSTORE_WIDGET_PROMPT;
}
// Returns bitmap for the default icon with size equal to the default icon's
@@ -179,7 +179,7 @@
int id = -1;
switch (type_) {
case INSTALL_PROMPT:
- case INLINE_INSTALL_PROMPT:
+ case WEBSTORE_WIDGET_PROMPT:
id = IDS_EXTENSION_INSTALL_PROMPT_TITLE;
break;
case RE_ENABLE_PROMPT:
@@ -234,7 +234,7 @@
int id = -1;
switch (type_) {
case INSTALL_PROMPT:
- case INLINE_INSTALL_PROMPT:
+ case WEBSTORE_WIDGET_PROMPT:
if (extension_->is_app())
id = IDS_EXTENSION_INSTALL_PROMPT_ACCEPT_BUTTON_APP;
else if (extension_->is_theme())
@@ -295,7 +295,7 @@
int id = -1;
switch (type_) {
case INSTALL_PROMPT:
- case INLINE_INSTALL_PROMPT:
+ case WEBSTORE_WIDGET_PROMPT:
case RE_ENABLE_PROMPT:
case REMOTE_INSTALL_PROMPT:
case REPAIR_PROMPT:
@@ -323,7 +323,7 @@
int id = -1;
switch (type_) {
case INSTALL_PROMPT:
- case INLINE_INSTALL_PROMPT:
+ case WEBSTORE_WIDGET_PROMPT:
case EXTERNAL_INSTALL_PROMPT:
case REMOTE_INSTALL_PROMPT:
case DELEGATED_PERMISSIONS_PROMPT:
@@ -361,13 +361,6 @@
return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT;
}
-bool ExtensionInstallPrompt::Prompt::ShouldUseTabModalDialog() const {
- // For inline install, we want the install prompt to be tab modal so that the
- // dialog is always clearly associated with the page that made the inline
- // install request.
- return type_ == INLINE_INSTALL_PROMPT;
-}
-
void ExtensionInstallPrompt::Prompt::AppendRatingStars(
StarAppender appender, void* data) const {
CHECK(appender);
diff --git a/chrome/browser/extensions/extension_install_prompt.h b/chrome/browser/extensions/extension_install_prompt.h
index db454db0..ec13a56b 100644
--- a/chrome/browser/extensions/extension_install_prompt.h
+++ b/chrome/browser/extensions/extension_install_prompt.h
@@ -55,7 +55,7 @@
enum PromptType {
UNSET_PROMPT_TYPE = -1,
INSTALL_PROMPT = 0,
- INLINE_INSTALL_PROMPT = 1,
+ // INLINE_INSTALL_PROMPT_DEPRECATED = 1,
// BUNDLE_INSTALL_PROMPT_DEPRECATED = 2,
RE_ENABLE_PROMPT = 3,
PERMISSIONS_PROMPT = 4,
@@ -67,6 +67,7 @@
DELEGATED_PERMISSIONS_PROMPT = 10,
// DELEGATED_BUNDLE_PERMISSIONS_PROMPT_DEPRECATED = 11,
NUM_PROMPT_TYPES = 12,
+ WEBSTORE_WIDGET_PROMPT = 13,
};
// The last prompt type to display; only used for testing.
@@ -111,8 +112,6 @@
bool ShouldShowPermissions() const;
- bool ShouldUseTabModalDialog() const;
-
// Getters for webstore metadata. Only populated when the type is
// INLINE_INSTALL_PROMPT, EXTERNAL_INSTALL_PROMPT, or REPAIR_PROMPT.
diff --git a/chrome/browser/extensions/extension_reenabler.cc b/chrome/browser/extensions/extension_reenabler.cc
deleted file mode 100644
index 407166a..0000000
--- a/chrome/browser/extensions/extension_reenabler.cc
+++ /dev/null
@@ -1,193 +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 "chrome/browser/extensions/extension_reenabler.h"
-
-#include "base/logging.h"
-#include "base/memory/ptr_util.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/webstore_data_fetcher.h"
-#include "chrome/browser/extensions/webstore_inline_installer.h"
-#include "chrome/browser/net/system_network_context_manager.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/browser/storage_partition.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/common/extension.h"
-
-namespace extensions {
-
-ExtensionReenabler::~ExtensionReenabler() {
- if (!finished_)
- Finish(ABORTED);
-}
-
-// static
-std::unique_ptr<ExtensionReenabler> ExtensionReenabler::PromptForReenable(
- const scoped_refptr<const Extension>& extension,
- content::BrowserContext* browser_context,
- content::WebContents* web_contents,
- const GURL& referrer_url,
- const Callback& callback) {
-#if DCHECK_IS_ON()
- // We should only try to reenable an extension that is, in fact, disabled.
- DCHECK(ExtensionRegistry::Get(browser_context)->disabled_extensions().
- Contains(extension->id()));
- // Currently, this should only be used for extensions that are disabled due
- // to a permissions increase.
- int disable_reasons =
- ExtensionPrefs::Get(browser_context)->GetDisableReasons(extension->id());
- DCHECK_NE(0, disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE);
-#endif // DCHECK_IS_ON()
-
- return base::WrapUnique(new ExtensionReenabler(
- extension, browser_context, referrer_url, callback, web_contents,
- ExtensionInstallPrompt::GetDefaultShowDialogCallback()));
-}
-
-// static
-std::unique_ptr<ExtensionReenabler>
-ExtensionReenabler::PromptForReenableWithCallbackForTest(
- const scoped_refptr<const Extension>& extension,
- content::BrowserContext* browser_context,
- const Callback& callback,
- const ExtensionInstallPrompt::ShowDialogCallback& show_dialog_callback) {
- return base::WrapUnique(new ExtensionReenabler(extension, browser_context,
- GURL(), callback, nullptr,
- show_dialog_callback));
-}
-
-ExtensionReenabler::ExtensionReenabler(
- const scoped_refptr<const Extension>& extension,
- content::BrowserContext* browser_context,
- const GURL& referrer_url,
- const Callback& callback,
- content::WebContents* web_contents,
- const ExtensionInstallPrompt::ShowDialogCallback& show_dialog_callback)
- : extension_(extension),
- browser_context_(browser_context),
- referrer_url_(referrer_url),
- callback_(callback),
- show_dialog_callback_(show_dialog_callback),
- finished_(false),
- registry_observer_(this),
- weak_factory_(this) {
- DCHECK(extension_.get());
- registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
-
- install_prompt_.reset(new ExtensionInstallPrompt(web_contents));
-
- // If we have a non-empty referrer, then we have to validate that it's a valid
- // url for the extension.
- if (!referrer_url_.is_empty()) {
- webstore_data_fetcher_.reset(
- new WebstoreDataFetcher(this, referrer_url_, extension->id()));
- webstore_data_fetcher_->Start(
- content::BrowserContext::GetDefaultStoragePartition(browser_context_)
- ->GetURLLoaderFactoryForBrowserProcess()
- .get());
- } else {
- ExtensionInstallPrompt::PromptType type =
- ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
- browser_context, extension.get());
- install_prompt_->ShowDialog(
- base::Bind(&ExtensionReenabler::OnInstallPromptDone,
- weak_factory_.GetWeakPtr()),
- extension.get(), nullptr,
- std::make_unique<ExtensionInstallPrompt::Prompt>(type),
- show_dialog_callback_);
- }
-}
-
-void ExtensionReenabler::OnInstallPromptDone(
- ExtensionInstallPrompt::Result install_result) {
- ReenableResult result = ABORTED;
- switch (install_result) {
- case ExtensionInstallPrompt::Result::ACCEPTED: {
- // Stop observing - we don't want to see our own enablement.
- registry_observer_.RemoveAll();
-
- ExtensionService* extension_service =
- ExtensionSystem::Get(browser_context_)->extension_service();
- if (extension_service->browser_terminating()) {
- result = ABORTED;
- } else {
- extension_service->GrantPermissionsAndEnableExtension(extension_.get());
- // The re-enable could have failed if the extension is disallowed by
- // policy.
- bool enabled = ExtensionRegistry::Get(browser_context_)
- ->enabled_extensions()
- .GetByID(extension_->id()) != nullptr;
- result = enabled ? REENABLE_SUCCESS : NOT_ALLOWED;
- }
- break;
- }
- case ExtensionInstallPrompt::Result::USER_CANCELED:
- result = USER_CANCELED;
- break;
- case ExtensionInstallPrompt::Result::ABORTED:
- result = ABORTED;
- break;
- }
-
- Finish(result);
-}
-
-void ExtensionReenabler::OnExtensionLoaded(
- content::BrowserContext* browser_context,
- const Extension* extension) {
- // If the user chose to manually re-enable the extension then, for all
- // intents and purposes, this was a success.
- if (extension == extension_.get())
- Finish(REENABLE_SUCCESS);
-}
-
-void ExtensionReenabler::OnExtensionUninstalled(
- content::BrowserContext* browser_context,
- const Extension* extension,
- UninstallReason reason) {
- if (extension == extension_.get())
- Finish(USER_CANCELED);
-}
-
-void ExtensionReenabler::OnWebstoreRequestFailure() {
- Finish(ABORTED);
-}
-
-void ExtensionReenabler::OnWebstoreResponseParseSuccess(
- std::unique_ptr<base::DictionaryValue> webstore_data) {
- DCHECK(!referrer_url_.is_empty());
- std::string error;
- if (!WebstoreInlineInstaller::IsRequestorPermitted(*webstore_data,
- referrer_url_,
- &error)) {
- Finish(NOT_ALLOWED);
- } else {
- ExtensionInstallPrompt::PromptType type =
- ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
- browser_context_, extension_.get());
- install_prompt_->ShowDialog(
- base::Bind(&ExtensionReenabler::OnInstallPromptDone,
- weak_factory_.GetWeakPtr()),
- extension_.get(), nullptr,
- std::make_unique<ExtensionInstallPrompt::Prompt>(type),
- show_dialog_callback_);
- }
-}
-
-void ExtensionReenabler::OnWebstoreResponseParseFailure(
- const std::string& error) {
- Finish(ABORTED);
-}
-
-void ExtensionReenabler::Finish(ReenableResult result) {
- DCHECK(!finished_);
- finished_ = true;
- registry_observer_.RemoveAll();
- callback_.Run(result);
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/extension_reenabler.h b/chrome/browser/extensions/extension_reenabler.h
deleted file mode 100644
index 4c19f32..0000000
--- a/chrome/browser/extensions/extension_reenabler.h
+++ /dev/null
@@ -1,130 +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.
-
-#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_
-#define CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_
-
-#include <memory>
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-#include "base/scoped_observer.h"
-#include "chrome/browser/extensions/extension_install_prompt.h"
-#include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
-#include "extensions/browser/extension_registry_observer.h"
-
-namespace content {
-class BrowserContext;
-}
-
-namespace extensions {
-
-class Extension;
-class ExtensionRegistry;
-class WebstoreDataFetcher;
-
-// A class to handle reenabling an extension disabled due to a permissions
-// increase.
-// TODO(devlin): Once we get the UI figured out, we should also have this handle
-// other disable reasons.
-class ExtensionReenabler : public ExtensionRegistryObserver,
- public WebstoreDataFetcherDelegate {
- public:
- enum ReenableResult {
- REENABLE_SUCCESS, // The extension has been successfully re-enabled.
- USER_CANCELED, // The user chose to not re-enable the extension.
- NOT_ALLOWED, // The re-enable is not allowed.
- ABORTED, // The re-enable process was aborted due to, e.g.,
- // shutdown or a bad webstore response.
- };
-
- using Callback = base::Callback<void(ReenableResult)>;
-
- ~ExtensionReenabler() override;
-
- // Prompts the user to reenable the given |extension|, and calls |callback|
- // upon completion.
- // If |referrer_url| is non-empty, then this will also check to make sure
- // that the referrer_url is listed as a trusted url by the extension.
- static std::unique_ptr<ExtensionReenabler> PromptForReenable(
- const scoped_refptr<const Extension>& extension,
- content::BrowserContext* browser_context,
- content::WebContents* web_contents,
- const GURL& referrer_url,
- const Callback& callback);
-
- // Like PromptForReenable, but allows tests to inject the
- // ExtensionInstallPrompt.
- static std::unique_ptr<ExtensionReenabler>
- PromptForReenableWithCallbackForTest(
- const scoped_refptr<const Extension>& extension,
- content::BrowserContext* browser_context,
- const Callback& callback,
- const ExtensionInstallPrompt::ShowDialogCallback& show_callback);
-
- private:
- ExtensionReenabler(
- const scoped_refptr<const Extension>& extension,
- content::BrowserContext* browser_context,
- const GURL& referrer_url,
- const Callback& callback,
- content::WebContents* web_contents,
- const ExtensionInstallPrompt::ShowDialogCallback& show_callback);
-
- void OnInstallPromptDone(ExtensionInstallPrompt::Result result);
-
- // ExtensionRegistryObserver:
- void OnExtensionLoaded(content::BrowserContext* browser_context,
- const Extension* extension) override;
- void OnExtensionUninstalled(content::BrowserContext* browser_context,
- const Extension* extension,
- UninstallReason reason) override;
-
- // WebstoreDataFetcherDelegate:
- void OnWebstoreRequestFailure() override;
- void OnWebstoreResponseParseSuccess(
- std::unique_ptr<base::DictionaryValue> webstore_data) override;
- void OnWebstoreResponseParseFailure(const std::string& error) override;
-
- // Sets the |finished_| bit and runs |callback_| with the given |result|.
- void Finish(ReenableResult result);
-
- // The extension to be re-enabled.
- scoped_refptr<const Extension> extension_;
-
- // The associated browser context.
- content::BrowserContext* browser_context_;
-
- // The url of the referrer, if any. If this is non-empty, it means we have
- // to check that the url is trusted by the extension.
- GURL referrer_url_;
-
- // The callback to run upon completion.
- Callback callback_;
-
- // The callback to use to show the dialog.
- ExtensionInstallPrompt::ShowDialogCallback show_dialog_callback_;
-
- // The re-enable prompt.
- std::unique_ptr<ExtensionInstallPrompt> install_prompt_;
-
- // Indicates whether the re-enable process finished.
- bool finished_;
-
- // The data fetcher for retrieving webstore data.
- std::unique_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
-
- ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
- registry_observer_;
-
- base::WeakPtrFactory<ExtensionReenabler> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(ExtensionReenabler);
-};
-
-} // namespace extensions
-
-#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_REENABLER_H_
diff --git a/chrome/browser/extensions/extension_reenabler_unittest.cc b/chrome/browser/extensions/extension_reenabler_unittest.cc
deleted file mode 100644
index 2bc89df5..0000000
--- a/chrome/browser/extensions/extension_reenabler_unittest.cc
+++ /dev/null
@@ -1,269 +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 <utility>
-
-#include "base/macros.h"
-#include "base/run_loop.h"
-#include "chrome/browser/extensions/extension_install_prompt.h"
-#include "chrome/browser/extensions/extension_reenabler.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_service_test_base.h"
-#include "chrome/browser/extensions/extension_system_factory.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/test/base/testing_profile.h"
-#include "components/crx_file/id_util.h"
-#include "extensions/browser/extension_dialog_auto_confirm.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/management_policy.h"
-#include "extensions/browser/test_extensions_browser_client.h"
-#include "extensions/common/extension.h"
-#include "extensions/common/extension_builder.h"
-#include "extensions/common/value_builder.h"
-
-namespace extensions {
-
-namespace {
-
-// A simple provider that says all extensions must remain disabled.
-class TestManagementProvider : public ManagementPolicy::Provider {
- public:
- TestManagementProvider() {}
- ~TestManagementProvider() override {}
-
- private:
- // MananagementPolicy::Provider:
- std::string GetDebugPolicyProviderName() const override { return "test"; }
- bool MustRemainDisabled(const Extension* extension,
- disable_reason::DisableReason* reason,
- base::string16* error) const override {
- return true;
- }
-
- DISALLOW_COPY_AND_ASSIGN(TestManagementProvider);
-};
-
-// A helper class for all the various callbacks associated with reenabling an
-// extension. This class also helps store the results of the run.
-class CallbackHelper {
- public:
- CallbackHelper() {}
- ~CallbackHelper() {}
-
- // Get a callback to run on the completion of the reenable process and reset
- // |result_|.
- ExtensionReenabler::Callback GetCallback() {
- result_.reset();
- return base::Bind(&CallbackHelper::OnComplete,
- base::Unretained(this));
- }
-
- // Check if we have receved any result, and if it matches the expected one.
- bool has_result() const { return result_ != nullptr; }
- bool result_matches(ExtensionReenabler::ReenableResult expected) const {
- return result_.get() && *result_ == expected;
- }
-
- // Create a test ExtensionInstallPrompt that will not display any UI (which
- // causes unit tests to crash), but rather runs the given |quit_closure| (with
- // the prompt still active|.
- ExtensionInstallPrompt::ShowDialogCallback CreateShowCallback(
- base::OnceClosure quit_closure) {
- quit_closure_ = std::move(quit_closure);
- return base::Bind(&CallbackHelper::OnShow, base::Unretained(this));
- }
-
- private:
- // The callback to run once the reenable process finishes.
- void OnComplete(ExtensionReenabler::ReenableResult result) {
- result_.reset(new ExtensionReenabler::ReenableResult(result));
- }
-
- // The callback to run when a test ExtensionInstallPrompt is ready to show.
- void OnShow(ExtensionInstallPromptShowParams* show_params,
- const ExtensionInstallPrompt::DoneCallback& done_callback,
- std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) {
- DCHECK(quit_closure_);
- std::move(quit_closure_).Run();
- }
-
- // The closure to quit the currently-running loop; used with test
- // ExtensionInstallPrompts.
- base::OnceClosure quit_closure_;
-
- // The result of the reenable process, or null if the process hasn't finished.
- std::unique_ptr<ExtensionReenabler::ReenableResult> result_;
-
- DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
-};
-
-} // namespace
-
-class ExtensionReenablerUnitTest : public ExtensionServiceTestBase {
- public:
- ExtensionReenablerUnitTest() {}
- ~ExtensionReenablerUnitTest() override {}
-
- private:
- void SetUp() override;
- void TearDown() override;
-
- std::unique_ptr<TestExtensionsBrowserClient> test_browser_client_;
-
- DISALLOW_COPY_AND_ASSIGN(ExtensionReenablerUnitTest);
-};
-
-void ExtensionReenablerUnitTest::SetUp() {
- ExtensionServiceTestBase::SetUp();
- InitializeEmptyExtensionService();
- // We need a TestExtensionsBrowserClient because the real one tries to
- // implicitly convert any browser context to a (non-Testing)Profile.
- test_browser_client_.reset(new TestExtensionsBrowserClient(profile()));
- test_browser_client_->set_extension_system_factory(
- ExtensionSystemFactory::GetInstance());
- ExtensionsBrowserClient::Set(test_browser_client_.get());
-}
-
-void ExtensionReenablerUnitTest::TearDown() {
- profile_.reset();
- ExtensionsBrowserClient::Set(nullptr);
- test_browser_client_.reset();
- ExtensionServiceTestBase::TearDown();
-}
-
-// Test that the ExtensionReenabler reenables disabled extensions.
-TEST_F(ExtensionReenablerUnitTest, TestReenablingDisabledExtension) {
- // Create a simple extension and add it to the service.
- scoped_refptr<const Extension> extension =
- ExtensionBuilder()
- .SetManifest(DictionaryBuilder()
- .Set("name", "test ext")
- .Set("version", "1.0")
- .Set("manifest_version", 2)
- .Set("description", "a test ext")
- .Build())
- .SetID(crx_file::id_util::GenerateId("test ext"))
- .Build();
- service()->AddExtension(extension.get());
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
-
- CallbackHelper callback_helper;
-
- // Check that the ExtensionReenabler can re-enable disabled extensions.
- {
- // Disable the extension due to a permissions increase (the only type of
- // disablement we handle with the ExtensionReenabler so far).
- service()->DisableExtension(extension->id(),
- disable_reason::DISABLE_PERMISSIONS_INCREASE);
- // Sanity check that it's disabled.
- EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
-
- // Automatically confirm install prompts.
- ScopedTestDialogAutoConfirm auto_confirm(
- ScopedTestDialogAutoConfirm::ACCEPT);
-
- // Run the ExtensionReenabler.
- std::unique_ptr<ExtensionReenabler> extension_reenabler =
- ExtensionReenabler::PromptForReenable(extension, profile(),
- nullptr, // No web contents.
- GURL(), // No referrer.
- callback_helper.GetCallback());
- base::RunLoop().RunUntilIdle();
-
- // The extension should be enabled.
- EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
- EXPECT_TRUE(
- callback_helper.result_matches(ExtensionReenabler::REENABLE_SUCCESS));
- }
-
- // Check that we don't re-enable extensions that must remain disabled, and
- // that the re-enabler reports failure correctly.
- {
- ScopedTestDialogAutoConfirm auto_confirm(
- ScopedTestDialogAutoConfirm::ACCEPT);
-
- ManagementPolicy* management_policy =
- ExtensionSystem::Get(browser_context())->management_policy();
- ASSERT_TRUE(management_policy);
- TestManagementProvider test_provider;
- management_policy->RegisterProvider(&test_provider);
- service()->DisableExtension(extension->id(),
- disable_reason::DISABLE_PERMISSIONS_INCREASE);
-
- std::unique_ptr<ExtensionReenabler> extension_reenabler =
- ExtensionReenabler::PromptForReenable(extension, profile(),
- nullptr, // No web contents.
- GURL(), // No referrer.
- callback_helper.GetCallback());
- base::RunLoop().RunUntilIdle();
-
- // The extension should be enabled.
- EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
- EXPECT_TRUE(
- callback_helper.result_matches(ExtensionReenabler::NOT_ALLOWED));
-
- management_policy->UnregisterProvider(&test_provider);
- }
-
- // Check that canceling the re-enable prompt doesn't re-enable the extension.
- {
- // Disable it again, and try canceling the prompt.
- service()->DisableExtension(extension->id(),
- disable_reason::DISABLE_PERMISSIONS_INCREASE);
- ScopedTestDialogAutoConfirm auto_confirm(
- ScopedTestDialogAutoConfirm::CANCEL);
- std::unique_ptr<ExtensionReenabler> extension_reenabler =
- ExtensionReenabler::PromptForReenable(extension, profile(),
- nullptr, // No web contents.
- GURL(), // No referrer.
- callback_helper.GetCallback());
- base::RunLoop().RunUntilIdle();
-
- // The extension should remain disabled.
- EXPECT_TRUE(registry()->disabled_extensions().Contains(extension->id()));
- EXPECT_TRUE(
- callback_helper.result_matches(ExtensionReenabler::USER_CANCELED));
- }
-
- // Test that if the extension is re-enabled while the prompt is active, the
- // prompt exits and reports success.
- {
- base::RunLoop run_loop;
- std::unique_ptr<ExtensionReenabler> extension_reenabler =
- ExtensionReenabler::PromptForReenableWithCallbackForTest(
- extension, profile(), callback_helper.GetCallback(),
- callback_helper.CreateShowCallback(run_loop.QuitClosure()));
- run_loop.Run();
-
- // We shouldn't have any result yet (the user hasn't confirmed or canceled).
- EXPECT_FALSE(callback_helper.has_result());
-
- // Reenable the extension. This should count as a success for reenabling.
- service()->GrantPermissionsAndEnableExtension(extension.get());
- EXPECT_TRUE(
- callback_helper.result_matches(ExtensionReenabler::REENABLE_SUCCESS));
- }
-
- // Test that prematurely destroying the re-enable prompt doesn't crash and
- // reports an "aborted" result.
- {
- // Disable again, and create another prompt.
- service()->DisableExtension(extension->id(),
- disable_reason::DISABLE_PERMISSIONS_INCREASE);
- base::RunLoop run_loop;
- std::unique_ptr<ExtensionReenabler> extension_reenabler =
- ExtensionReenabler::PromptForReenableWithCallbackForTest(
- extension, profile(), callback_helper.GetCallback(),
- callback_helper.CreateShowCallback(run_loop.QuitClosure()));
- run_loop.Run();
- EXPECT_FALSE(callback_helper.has_result());
- // Destroy the reenabler to simulate the owning context being shut down
- // (e.g., the tab closing).
- extension_reenabler.reset();
- EXPECT_TRUE(
- callback_helper.result_matches(ExtensionReenabler::ABORTED));
- }
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/tab_helper.cc b/chrome/browser/extensions/tab_helper.cc
index acb3d78..68eb168f 100644
--- a/chrome/browser/extensions/tab_helper.cc
+++ b/chrome/browser/extensions/tab_helper.cc
@@ -20,8 +20,6 @@
#include "chrome/browser/extensions/install_observer.h"
#include "chrome/browser/extensions/install_tracker.h"
#include "chrome/browser/extensions/install_tracker_factory.h"
-#include "chrome/browser/extensions/webstore_inline_installer.h"
-#include "chrome/browser/extensions/webstore_inline_installer_factory.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
@@ -70,75 +68,6 @@
namespace extensions {
-// A helper class to watch the progress of inline installation and update the
-// renderer. Owned by the TabHelper.
-class TabHelper::InlineInstallObserver : public InstallObserver {
- public:
- InlineInstallObserver(TabHelper* tab_helper,
- content::BrowserContext* browser_context,
- const ExtensionId& extension_id,
- bool observe_download_progress,
- bool observe_install_stage)
- : tab_helper_(tab_helper),
- extension_id_(extension_id),
- observe_download_progress_(observe_download_progress),
- observe_install_stage_(observe_install_stage),
- install_observer_(this) {
- DCHECK(tab_helper);
- DCHECK(observe_download_progress || observe_install_stage);
- InstallTracker* install_tracker =
- InstallTrackerFactory::GetForBrowserContext(browser_context);
- if (install_tracker)
- install_observer_.Add(install_tracker);
- }
- ~InlineInstallObserver() override {}
-
- private:
- // InstallObserver:
- void OnBeginExtensionDownload(const ExtensionId& extension_id) override {
- SendInstallStageChangedMessage(extension_id,
- api::webstore::INSTALL_STAGE_DOWNLOADING);
- }
- void OnDownloadProgress(const ExtensionId& extension_id,
- int percent_downloaded) override {
- if (observe_download_progress_ && extension_id == extension_id_) {
- auto iter =
- tab_helper_->inline_install_progress_listeners_.find(extension_id);
- DCHECK(iter != tab_helper_->inline_install_progress_listeners_.end());
- iter->second->InlineInstallDownloadProgress(percent_downloaded);
- }
- }
- void OnBeginCrxInstall(const ExtensionId& extension_id) override {
- SendInstallStageChangedMessage(extension_id,
- api::webstore::INSTALL_STAGE_INSTALLING);
- }
- void OnShutdown() override { install_observer_.RemoveAll(); }
-
- void SendInstallStageChangedMessage(const ExtensionId& extension_id,
- api::webstore::InstallStage stage) {
- if (observe_install_stage_ && extension_id == extension_id_) {
- auto iter =
- tab_helper_->inline_install_progress_listeners_.find(extension_id);
- DCHECK(iter != tab_helper_->inline_install_progress_listeners_.end());
- iter->second->InlineInstallStageChanged(stage);
- }
- }
-
- // The owning TabHelper (guaranteed to be valid).
- TabHelper* const tab_helper_;
-
- // The id of the extension to observe.
- ExtensionId extension_id_;
-
- // Whether or not to observe download/install progress.
- const bool observe_download_progress_;
- const bool observe_install_stage_;
-
- ScopedObserver<InstallTracker, InstallObserver> install_observer_;
-
- DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver);
-};
-
TabHelper::~TabHelper() {
RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_));
}
@@ -152,9 +81,7 @@
script_executor_(
new ScriptExecutor(web_contents, &script_execution_observers_)),
extension_action_runner_(new ExtensionActionRunner(web_contents)),
- webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()),
registry_observer_(this),
- bindings_(web_contents, this),
image_loader_ptr_factory_(this),
weak_ptr_factory_(this) {
// The ActiveTabPermissionManager requires a session ID; ensure this
@@ -379,80 +306,6 @@
pending_web_app_action_ = NONE;
}
-void TabHelper::DoInlineInstall(
- const std::string& webstore_item_id,
- int listeners_mask,
- mojom::InlineInstallProgressListenerPtr install_progress_listener,
- DoInlineInstallCallback callback) {
- content::RenderFrameHost* host = web_contents()->GetMainFrame();
- if (bindings_.GetCurrentTargetFrame() != host) {
- NOTREACHED();
- return;
- }
-
- GURL requestor_url(host->GetLastCommittedURL());
- // Check that the listener is reasonable. We should never get anything other
- // than an install stage listener, a download listener, or both.
- // The requestor_url should also be valid, and the renderer should disallow
- // child frames from sending the IPC.
- if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER |
- api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 ||
- !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL) {
- NOTREACHED();
- return;
- }
-
- if (base::ContainsKey(install_callbacks_, webstore_item_id)) {
- std::move(callback).Run(false, webstore_install::kInstallInProgressError,
- webstore_install::INSTALL_IN_PROGRESS);
- return;
- }
-
- install_callbacks_[webstore_item_id] = std::move(callback);
- inline_install_progress_listeners_[webstore_item_id] =
- std::move(install_progress_listener);
- // Inform the Webstore API that an inline install is happening, in case the
- // page requested status updates.
- ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
- if (registry->disabled_extensions().Contains(webstore_item_id) &&
- (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) &
- disable_reason::DISABLE_PERMISSIONS_INCREASE) != 0) {
- // The extension was disabled due to permissions increase. Prompt for
- // re-enable.
- // TODO(devlin): We should also prompt for re-enable for other reasons,
- // like user-disabled.
- // For clarity, explicitly end any prior reenable process.
- extension_reenabler_.reset();
- extension_reenabler_ = ExtensionReenabler::PromptForReenable(
- registry->disabled_extensions().GetByID(webstore_item_id), profile_,
- web_contents(), requestor_url,
- base::Bind(&TabHelper::OnReenableComplete,
- weak_ptr_factory_.GetWeakPtr(), webstore_item_id));
- } else {
- // TODO(devlin): We should adddress the case of the extension already
- // being installed and enabled.
- bool observe_download_progress =
- (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0;
- bool observe_install_stage =
- (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0;
- if (observe_install_stage || observe_download_progress) {
- DCHECK_EQ(0u, install_observers_.count(webstore_item_id));
- install_observers_[webstore_item_id] =
- std::make_unique<InlineInstallObserver>(
- this, web_contents()->GetBrowserContext(), webstore_item_id,
- observe_download_progress, observe_install_stage);
- }
-
- WebstoreStandaloneInstaller::Callback callback =
- base::Bind(&TabHelper::OnInlineInstallComplete,
- weak_ptr_factory_.GetWeakPtr(), webstore_item_id);
- scoped_refptr<WebstoreInlineInstaller> installer(
- webstore_inline_installer_factory_->CreateInstaller(
- web_contents(), host, webstore_item_id, requestor_url, callback));
- installer->BeginInstall();
- }
-}
-
void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host,
const GURL& requestor_url,
int return_route_id,
@@ -514,11 +367,6 @@
}
}
-void TabHelper::SetWebstoreInlineInstallerFactoryForTests(
- WebstoreInlineInstallerFactory* factory) {
- webstore_inline_installer_factory_.reset(factory);
-}
-
void TabHelper::OnImageLoaded(const gfx::Image& image) {
if (!image.IsEmpty()) {
extension_app_icon_ = *image.ToSkBitmap();
@@ -530,47 +378,6 @@
return ExtensionTabUtil::GetWindowControllerOfTab(web_contents());
}
-void TabHelper::OnReenableComplete(const ExtensionId& extension_id,
- ExtensionReenabler::ReenableResult result) {
- // Map the re-enable results to webstore-install results.
- webstore_install::Result webstore_result = webstore_install::SUCCESS;
- std::string error;
- switch (result) {
- case ExtensionReenabler::REENABLE_SUCCESS:
- break; // already set
- case ExtensionReenabler::USER_CANCELED:
- webstore_result = webstore_install::USER_CANCELLED;
- error = "User canceled install.";
- break;
- case ExtensionReenabler::NOT_ALLOWED:
- webstore_result = webstore_install::NOT_PERMITTED;
- error = "Install not permitted.";
- break;
- case ExtensionReenabler::ABORTED:
- webstore_result = webstore_install::ABORTED;
- error = "Aborted due to tab closing.";
- break;
- }
-
- OnInlineInstallComplete(extension_id,
- result == ExtensionReenabler::REENABLE_SUCCESS, error,
- webstore_result);
- // Note: ExtensionReenabler contained the callback with the curried-in
- // |extension_id|; delete it last.
- extension_reenabler_.reset();
-}
-
-void TabHelper::OnInlineInstallComplete(const ExtensionId& extension_id,
- bool success,
- const std::string& error,
- webstore_install::Result result) {
- install_observers_.erase(extension_id);
- auto iter = install_callbacks_.find(extension_id);
- DCHECK(iter != install_callbacks_.end());
- std::move(iter->second).Run(success, success ? std::string() : error, result);
- install_callbacks_.erase(iter);
-}
-
WebContents* TabHelper::GetAssociatedWebContents() const {
return web_contents();
}
diff --git a/chrome/browser/extensions/tab_helper.h b/chrome/browser/extensions/tab_helper.h
index 8fa70a9..0db580c 100644
--- a/chrome/browser/extensions/tab_helper.h
+++ b/chrome/browser/extensions/tab_helper.h
@@ -15,9 +15,7 @@
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/active_tab_permission_granter.h"
-#include "chrome/browser/extensions/extension_reenabler.h"
#include "chrome/common/chrome_render_frame.mojom.h"
-#include "chrome/common/extensions/mojom/inline_install.mojom.h"
#include "chrome/common/extensions/webstore_install_result.h"
#include "chrome/common/web_application_info.h"
#include "content/public/browser/web_contents_binding_set.h"
@@ -43,14 +41,12 @@
class ExtensionActionRunner;
class BookmarkAppHelper;
class Extension;
-class WebstoreInlineInstallerFactory;
// Per-tab extension helper. Also handles non-extension apps.
class TabHelper : public content::WebContentsObserver,
public ExtensionFunctionDispatcher::Delegate,
public ExtensionRegistryObserver,
- public content::WebContentsUserData<TabHelper>,
- public mojom::InlineInstaller {
+ public content::WebContentsUserData<TabHelper> {
public:
~TabHelper() override;
@@ -101,14 +97,7 @@
return active_tab_permission_granter_.get();
}
- // Sets the factory used to create inline webstore item installers.
- // Used for testing. Takes ownership of the factory instance.
- void SetWebstoreInlineInstallerFactoryForTests(
- WebstoreInlineInstallerFactory* factory);
-
private:
- class InlineInstallObserver;
-
// Utility function to invoke member functions on all relevant
// ContentRulesRegistries.
template <class Func>
@@ -148,13 +137,6 @@
const Extension* extension,
UnloadedExtensionReason reason) override;
- // mojom::InlineInstall:
- void DoInlineInstall(
- const std::string& webstore_item_id,
- int listeners_mask,
- mojom::InlineInstallProgressListenerPtr install_progress_listener,
- DoInlineInstallCallback callback) override;
-
// Message handlers.
void OnDidGetWebApplicationInfo(
chrome::mojom::ChromeRenderFrameAssociatedPtr chrome_render_frame,
@@ -179,16 +161,6 @@
void OnImageLoaded(const gfx::Image& image);
- // WebstoreStandaloneInstaller::Callback.
- void OnInlineInstallComplete(const ExtensionId& extension_id,
- bool success,
- const std::string& error,
- webstore_install::Result result);
-
- // ExtensionReenabler::Callback.
- void OnReenableComplete(const ExtensionId& extension_id,
- ExtensionReenabler::ReenableResult result);
-
// Requests application info for the specified page. This is an asynchronous
// request. The delegate is notified by way of OnDidGetWebApplicationInfo when
// the data is available.
@@ -231,30 +203,9 @@
std::unique_ptr<BookmarkAppHelper> bookmark_app_helper_;
- // Creates WebstoreInlineInstaller instances for inline install triggers.
- std::unique_ptr<WebstoreInlineInstallerFactory>
- webstore_inline_installer_factory_;
-
- // The reenable prompt for disabled extensions, if any.
- std::unique_ptr<ExtensionReenabler> extension_reenabler_;
-
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
registry_observer_;
- // Map of InlineInstallObservers for inline installations that have progress
- // listeners.
- std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>>
- install_observers_;
-
- // Map of function callbacks that are invoked when the inline installation for
- // a particular extension (hence ExtensionId) completes.
- std::map<ExtensionId, DoInlineInstallCallback> install_callbacks_;
-
- content::WebContentsFrameBindingSet<mojom::InlineInstaller> bindings_;
-
- std::map<ExtensionId, mojom::InlineInstallProgressListenerPtr>
- inline_install_progress_listeners_;
-
// Vend weak pointers that can be invalidated to stop in-progress loads.
base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_;
diff --git a/chrome/browser/extensions/webstore_data_fetcher.cc b/chrome/browser/extensions/webstore_data_fetcher.cc
index 1b84b751..558b721 100644
--- a/chrome/browser/extensions/webstore_data_fetcher.cc
+++ b/chrome/browser/extensions/webstore_data_fetcher.cc
@@ -43,10 +43,6 @@
WebstoreDataFetcher::~WebstoreDataFetcher() {}
-void WebstoreDataFetcher::SetPostData(const std::string& data) {
- post_data_ = data;
-}
-
void WebstoreDataFetcher::Start(
network::mojom::URLLoaderFactory* url_loader_factory) {
GURL webstore_data_url(extension_urls::GetWebstoreItemJsonDataURL(id_));
@@ -86,14 +82,10 @@
resource_request->load_flags =
net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DISABLE_CACHE;
resource_request->referrer = referrer_url_;
- resource_request->method = post_data_.empty() ? "GET" : "POST";
+ resource_request->method = "GET";
simple_url_loader_ = network::SimpleURLLoader::Create(
std::move(resource_request), traffic_annotation);
- if (!post_data_.empty())
- simple_url_loader_->AttachStringForUpload(post_data_,
- "application/octet-stream");
-
if (max_auto_retries_ > 0) {
simple_url_loader_->SetRetryOptions(
max_auto_retries_,
diff --git a/chrome/browser/extensions/webstore_data_fetcher.h b/chrome/browser/extensions/webstore_data_fetcher.h
index af46509..1d1edae 100644
--- a/chrome/browser/extensions/webstore_data_fetcher.h
+++ b/chrome/browser/extensions/webstore_data_fetcher.h
@@ -36,10 +36,6 @@
const std::string webstore_item_id);
~WebstoreDataFetcher();
- // Makes this request use a POST instead of GET, and sends |data| in the
- // body of the request. If |data| is empty, this is a no-op.
- void SetPostData(const std::string& data);
-
void Start(network::mojom::URLLoaderFactory* url_loader_factory);
void set_max_auto_retries(int max_retries) {
diff --git a/chrome/browser/extensions/webstore_data_fetcher_delegate.cc b/chrome/browser/extensions/webstore_data_fetcher_delegate.cc
index 21cab5d..72233ec 100644
--- a/chrome/browser/extensions/webstore_data_fetcher_delegate.cc
+++ b/chrome/browser/extensions/webstore_data_fetcher_delegate.cc
@@ -11,8 +11,6 @@
const char WebstoreDataFetcherDelegate::kIdKey[] = "id";
const char WebstoreDataFetcherDelegate::kExternalInstallDefaultButtonKey[] =
"external_install_default_button";
-const char WebstoreDataFetcherDelegate::kInlineInstallNotSupportedKey[] =
- "inline_install_not_supported";
const char WebstoreDataFetcherDelegate::kLocalizedDescriptionKey[] =
"localized_description";
const char WebstoreDataFetcherDelegate::kLocalizedNameKey[] = "localized_name";
diff --git a/chrome/browser/extensions/webstore_data_fetcher_delegate.h b/chrome/browser/extensions/webstore_data_fetcher_delegate.h
index a541e59..bef9178 100644
--- a/chrome/browser/extensions/webstore_data_fetcher_delegate.h
+++ b/chrome/browser/extensions/webstore_data_fetcher_delegate.h
@@ -33,7 +33,6 @@
static const char kIconUrlKey[];
static const char kIdKey[];
static const char kExternalInstallDefaultButtonKey[];
- static const char kInlineInstallNotSupportedKey[];
static const char kLocalizedDescriptionKey[];
static const char kLocalizedNameKey[];
static const char kManifestKey[];
diff --git a/chrome/browser/extensions/webstore_inline_installer.cc b/chrome/browser/extensions/webstore_inline_installer.cc
deleted file mode 100644
index b10f636..0000000
--- a/chrome/browser/extensions/webstore_inline_installer.cc
+++ /dev/null
@@ -1,318 +0,0 @@
-// Copyright (c) 2012 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/extensions/webstore_inline_installer.h"
-
-#include <utility>
-
-#include "base/json/json_writer.h"
-#include "base/strings/stringprintf.h"
-#include "base/values.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/extensions/webstore_data_fetcher.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h"
-#include "chrome/browser/safe_browsing/safe_browsing_service.h"
-#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_service.h"
-#include "components/safe_browsing/proto/csd.pb.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/navigation_handle.h"
-#include "content/public/browser/web_contents.h"
-
-using content::WebContents;
-using safe_browsing::SafeBrowsingNavigationObserverManager;
-using safe_browsing::ReferrerChain;
-
-namespace {
-
-// The number of user gestures to trace back for CWS pings.
-const int kExtensionReferrerUserGestureLimit = 2;
-}
-
-namespace extensions {
-
-const char kInvalidWebstoreResponseError[] =
- "Invalid Chrome Web Store response.";
-const char kNoVerifiedSitesError[] =
- "Inline installs can only be initiated for Chrome Web Store items that "
- "have one or more verified sites.";
-const char kNotFromVerifiedSitesError[] =
- "Installs can only be initiated by one of the Chrome Web Store item's "
- "verified sites.";
-const char kInlineInstallSupportedError[] =
- "Inline installation is not supported for this item. The user will be "
- "redirected to the Chrome Web Store.";
-const char kInitiatedFromPopupError[] =
- "Inline installs can not be initiated from pop-up windows.";
-const char kInitiatedFromFullscreenError[] =
- "Inline installs can not be initiated from fullscreen.";
-
-WebstoreInlineInstaller::WebstoreInlineInstaller(
- content::WebContents* web_contents,
- content::RenderFrameHost* host,
- const std::string& webstore_item_id,
- const GURL& requestor_url,
- const Callback& callback)
- : WebstoreStandaloneInstaller(
- webstore_item_id,
- Profile::FromBrowserContext(web_contents->GetBrowserContext()),
- callback),
- content::WebContentsObserver(web_contents),
- host_(host),
- requestor_url_(requestor_url) {}
-
-WebstoreInlineInstaller::~WebstoreInlineInstaller() {}
-
-// static
-bool WebstoreInlineInstaller::IsRequestorPermitted(
- const base::DictionaryValue& webstore_data,
- const GURL& requestor_url,
- std::string* error) {
- // Ensure that there is at least one verified site present.
- const bool data_has_single_site = webstore_data.HasKey(kVerifiedSiteKey);
- const bool data_has_site_list = webstore_data.HasKey(kVerifiedSitesKey);
- if (!data_has_single_site && !data_has_site_list) {
- *error = kNoVerifiedSitesError;
- return false;
- }
- bool requestor_is_ok = false;
- // Handle the deprecated single-site case.
- if (!data_has_site_list) {
- std::string verified_site;
- if (!webstore_data.GetString(kVerifiedSiteKey, &verified_site)) {
- *error = kInvalidWebstoreResponseError;
- return false;
- }
- requestor_is_ok = IsRequestorURLInVerifiedSite(requestor_url,
- verified_site);
- } else {
- const base::ListValue* verified_sites = NULL;
- if (!webstore_data.GetList(kVerifiedSitesKey, &verified_sites)) {
- *error = kInvalidWebstoreResponseError;
- return false;
- }
- for (auto it = verified_sites->begin();
- it != verified_sites->end() && !requestor_is_ok; ++it) {
- std::string verified_site;
- if (!it->GetAsString(&verified_site)) {
- *error = kInvalidWebstoreResponseError;
- return false;
- }
- if (IsRequestorURLInVerifiedSite(requestor_url, verified_site)) {
- requestor_is_ok = true;
- }
- }
- }
- if (!requestor_is_ok) {
- *error = kNotFromVerifiedSitesError;
- return false;
- }
- *error = "";
- return true;
-}
-
-bool WebstoreInlineInstaller::SafeBrowsingNavigationEventsEnabled() const {
- return SafeBrowsingNavigationObserverManager::IsEnabledAndReady(profile());
-}
-
-std::string WebstoreInlineInstaller::GetPostData() {
- // web_contents() might return null during tab destruction. This object would
- // also be destroyed shortly thereafter but check to be on the safe side.
- if (!web_contents())
- return std::string();
-
- // Report extra data only when SafeBrowsing is enabled and SB navigation
- // observer is enabled for the current profile.
- if (!profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) ||
- !SafeBrowsingNavigationEventsEnabled()) {
- return std::string();
- }
-
- scoped_refptr<SafeBrowsingNavigationObserverManager>
- navigation_observer_manager = g_browser_process->safe_browsing_service()
- ->navigation_observer_manager();
-
- ReferrerChain referrer_chain;
- SafeBrowsingNavigationObserverManager::AttributionResult result =
- navigation_observer_manager->IdentifyReferrerChainByWebContents(
- web_contents(), kExtensionReferrerUserGestureLimit, &referrer_chain);
-
- // If the referrer chain is incomplete we'll append most recent navigations
- // to referrer chain for diagnose purpose. This only happens if user is not
- // in incognito mode and has opted into extended reporting to Scout reporting.
- int recent_navigations_to_collect =
- SafeBrowsingNavigationObserverManager::CountOfRecentNavigationsToAppend(
- *profile(), result);
- navigation_observer_manager->AppendRecentNavigations(
- recent_navigations_to_collect, &referrer_chain);
- safe_browsing::ExtensionWebStoreInstallRequest request;
- request.mutable_referrer_chain()->Swap(&referrer_chain);
- request.mutable_referrer_chain_options()->set_recent_navigations_to_collect(
- recent_navigations_to_collect);
-
- return request.SerializeAsString();
-}
-
-bool WebstoreInlineInstaller::CheckRequestorAlive() const {
- // The frame or tab may have gone away - cancel installation in that case.
- return host_ != nullptr && web_contents() != nullptr &&
- chrome::FindBrowserWithWebContents(web_contents()) != nullptr;
-}
-
-const GURL& WebstoreInlineInstaller::GetRequestorURL() const {
- return requestor_url_;
-}
-
-std::unique_ptr<ExtensionInstallPrompt::Prompt>
-WebstoreInlineInstaller::CreateInstallPrompt() const {
- std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt(
- new ExtensionInstallPrompt::Prompt(
- ExtensionInstallPrompt::INLINE_INSTALL_PROMPT));
-
- // crbug.com/260742: Don't display the user count if it's zero. The reason
- // it's zero is very often that the number isn't actually being counted
- // (intentionally), which means that it's unlikely to be correct.
- prompt->SetWebstoreData(localized_user_count(),
- show_user_count(),
- average_rating(),
- rating_count());
- return prompt;
-}
-
-bool WebstoreInlineInstaller::ShouldShowPostInstallUI() const {
- return true;
-}
-
-bool WebstoreInlineInstaller::ShouldShowAppInstalledBubble() const {
- return true;
-}
-
-WebContents* WebstoreInlineInstaller::GetWebContents() const {
- return web_contents();
-}
-
-bool WebstoreInlineInstaller::CheckInlineInstallPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
- DCHECK(browser);
- if (browser->is_type_popup()) {
- *error = kInitiatedFromPopupError;
- return false;
- }
- FullscreenController* controller =
- browser->exclusive_access_manager()->fullscreen_controller();
- if (controller->IsTabFullscreen()) {
- *error = kInitiatedFromFullscreenError;
- return false;
- }
- // The store may not support inline installs for this item, in which case
- // we open the store-provided redirect URL in a new tab and abort the
- // installation process.
- bool inline_install_not_supported = false;
- if (webstore_data.HasKey(kInlineInstallNotSupportedKey)
- && !webstore_data.GetBoolean(kInlineInstallNotSupportedKey,
- &inline_install_not_supported)) {
- *error = kInvalidWebstoreResponseError;
- return false;
- }
- if (inline_install_not_supported) {
- std::string redirect_url;
- if (!webstore_data.GetString(kRedirectUrlKey, &redirect_url)) {
- *error = kInvalidWebstoreResponseError;
- return false;
- }
- web_contents()->OpenURL(content::OpenURLParams(
- GURL(redirect_url),
- content::Referrer::SanitizeForRequest(
- GURL(redirect_url),
- content::Referrer(web_contents()->GetURL(),
- blink::kWebReferrerPolicyDefault)),
- WindowOpenDisposition::NEW_FOREGROUND_TAB,
- ui::PAGE_TRANSITION_AUTO_BOOKMARK, false));
- *error = kInlineInstallSupportedError;
- return false;
- }
- *error = "";
- return true;
-}
-
-bool WebstoreInlineInstaller::CheckRequestorPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- return IsRequestorPermitted(webstore_data, requestor_url_, error);
-}
-
-//
-// Private implementation.
-//
-
-void WebstoreInlineInstaller::DidFinishNavigation(
- content::NavigationHandle* navigation_handle) {
- if (navigation_handle->HasCommitted() &&
- !navigation_handle->IsSameDocument() &&
- (navigation_handle->GetRenderFrameHost() == host_ ||
- navigation_handle->IsInMainFrame())) {
- host_ = nullptr;
- }
-}
-
-void WebstoreInlineInstaller::WebContentsDestroyed() {
- AbortInstall();
-}
-
-// static
-bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite(
- const GURL& requestor_url,
- const std::string& verified_site) {
- // Turn the verified site into a URL that can be parsed by URLPattern.
- // |verified_site| must follow the format:
- //
- // [scheme://]host[:port][/path/specifier]
- //
- // If scheme is omitted, URLPattern will match against either an
- // HTTP or HTTPS requestor. If scheme is specified, it must be either HTTP
- // or HTTPS, and URLPattern will only match the scheme specified.
- GURL verified_site_url(verified_site);
- int valid_schemes = URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS;
- if (!verified_site_url.is_valid() || !verified_site_url.IsStandard())
- // If no scheme is specified, GURL will fail to parse the string correctly.
- // It will either determine that the URL is invalid, or parse a
- // host:port/path as scheme:host/path.
- verified_site_url = GURL("http://" + verified_site);
- else if (verified_site_url.SchemeIs("http"))
- valid_schemes = URLPattern::SCHEME_HTTP;
- else if (verified_site_url.SchemeIs("https"))
- valid_schemes = URLPattern::SCHEME_HTTPS;
- else
- return false;
-
- std::string port_spec =
- verified_site_url.has_port() ? ":" + verified_site_url.port() : "";
- std::string path_spec = verified_site_url.path() + "*";
- std::string verified_site_pattern_spec =
- base::StringPrintf(
- "%s://*.%s%s%s",
- verified_site_url.scheme().c_str(),
- verified_site_url.host().c_str(),
- port_spec.c_str(),
- path_spec.c_str());
-
- URLPattern verified_site_pattern(valid_schemes);
- URLPattern::ParseResult parse_result =
- verified_site_pattern.Parse(verified_site_pattern_spec);
- if (parse_result != URLPattern::ParseResult::kSuccess) {
- DLOG(WARNING) << "Failed to parse '" << verified_site_pattern_spec
- << "': " << URLPattern::GetParseResultString(parse_result);
- return false;
- }
- verified_site_pattern.SetScheme("*");
-
- return verified_site_pattern.MatchesURL(requestor_url);
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/webstore_inline_installer.h b/chrome/browser/extensions/webstore_inline_installer.h
deleted file mode 100644
index 5b99811..0000000
--- a/chrome/browser/extensions/webstore_inline_installer.h
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (c) 2012 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_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
-#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
-
-#include <memory>
-#include <string>
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "chrome/browser/extensions/webstore_standalone_installer.h"
-#include "content/public/browser/web_contents_observer.h"
-
-namespace content {
-class WebContents;
-}
-
-namespace extensions {
-
-// Manages inline installs requested by a page: downloads and parses metadata
-// from the webstore, shows the install UI, starts the download once the user
-// confirms, optionally transfers the user to the store if the "View details"
-// link is clicked in the UI, shows the "App installed" bubble and the
-// post-install UI after successful installation.
-//
-// Clients will be notified of success or failure via the |callback| argument
-// passed into the constructor.
-class WebstoreInlineInstaller : public WebstoreStandaloneInstaller,
- public content::WebContentsObserver {
- public:
- typedef WebstoreStandaloneInstaller::Callback Callback;
-
- WebstoreInlineInstaller(content::WebContents* web_contents,
- content::RenderFrameHost* host,
- const std::string& webstore_item_id,
- const GURL& requestor_url,
- const Callback& callback);
-
- // Returns true if given |requestor_url| is a verified site according to the
- // given |webstore_data|.
- static bool IsRequestorPermitted(const base::DictionaryValue& webstore_data,
- const GURL& requestor_url,
- std::string* error);
-
- protected:
- friend class base::RefCountedThreadSafe<WebstoreInlineInstaller>;
-
- ~WebstoreInlineInstaller() override;
-
- // Returns whether to use the new navigation event tracker.
- virtual bool SafeBrowsingNavigationEventsEnabled() const;
-
- // Implementations WebstoreStandaloneInstaller Template Method's hooks.
- std::string GetPostData() override;
- bool CheckRequestorAlive() const override;
- const GURL& GetRequestorURL() const override;
- bool ShouldShowPostInstallUI() const override;
- bool ShouldShowAppInstalledBubble() const override;
- content::WebContents* GetWebContents() const override;
- std::unique_ptr<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;
-
- private:
- // content::WebContentsObserver interface implementation.
- void DidFinishNavigation(
- content::NavigationHandle* navigation_handle) override;
- void WebContentsDestroyed() override;
-
- // Checks whether the install is initiated by a page in a verified site
- // (which is at least a domain, but can also have a port or a path).
- static bool IsRequestorURLInVerifiedSite(const GURL& requestor_url,
- const std::string& verified_site);
-
- // This corresponds to the frame that initiated the install request.
- content::RenderFrameHost* host_;
- GURL requestor_url_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreInlineInstaller);
-};
-
-} // namespace extensions
-
-#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_H_
diff --git a/chrome/browser/extensions/webstore_inline_installer_browsertest.cc b/chrome/browser/extensions/webstore_inline_installer_browsertest.cc
deleted file mode 100644
index e2a7da6c..0000000
--- a/chrome/browser/extensions/webstore_inline_installer_browsertest.cc
+++ /dev/null
@@ -1,584 +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/extensions/webstore_inline_installer.h"
-
-#include "base/json/json_reader.h"
-#include "base/macros.h"
-#include "base/memory/ptr_util.h"
-#include "base/run_loop.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/values.h"
-#include "build/build_config.h"
-#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
-#include "chrome/browser/extensions/extension_install_prompt.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/tab_helper.h"
-#include "chrome/browser/extensions/webstore_inline_installer_factory.h"
-#include "chrome/browser/extensions/webstore_installer_test.h"
-#include "chrome/browser/extensions/webstore_standalone_installer.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "components/content_settings/core/browser/host_content_settings_map.h"
-#include "components/prefs/pref_service.h"
-#include "components/safe_browsing/features.h"
-#include "components/safe_browsing/proto/csd.pb.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/test/browser_test_utils.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/extension_system.h"
-#include "extensions/common/permissions/permission_set.h"
-#include "net/dns/mock_host_resolver.h"
-#include "net/test/embedded_test_server/http_request.h"
-#include "url/gurl.h"
-
-using content::WebContents;
-
-namespace extensions {
-
-namespace {
-
-const char kWebstoreDomain[] = "cws.com";
-const char kAppDomain[] = "app.com";
-const char kNonAppDomain[] = "nonapp.com";
-const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje";
-const char kTestDataPath[] = "extensions/api_test/webstore_inline_install";
-const char kCrxFilename[] = "extension.crx";
-
-const char kRedirect1Domain[] = "redirect1.com";
-const char kRedirect2Domain[] = "redirect2.com";
-
-// A struct for letting us store the actual parameters that were passed to
-// the install callback.
-struct InstallResult {
- bool success = false;
- std::string error;
- webstore_install::Result result = webstore_install::RESULT_LAST;
-};
-
-} // namespace
-
-class WebstoreInlineInstallerTest : public WebstoreInstallerTest {
- public:
- WebstoreInlineInstallerTest()
- : WebstoreInstallerTest(
- kWebstoreDomain,
- kTestDataPath,
- kCrxFilename,
- kAppDomain,
- kNonAppDomain) {}
-};
-
-class ProgrammableInstallPrompt : public ExtensionInstallPrompt {
- public:
- explicit ProgrammableInstallPrompt(WebContents* contents)
- : ExtensionInstallPrompt(contents)
- {}
-
- ~ProgrammableInstallPrompt() override { g_done_callback = nullptr; }
-
- void ShowDialog(
- const ExtensionInstallPrompt::DoneCallback& done_callback,
- const Extension* extension,
- const SkBitmap* icon,
- std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt,
- std::unique_ptr<const extensions::PermissionSet> custom_permissions,
- const ShowDialogCallback& show_dialog_callback) override {
- done_callback_ = done_callback;
- g_done_callback = &done_callback_;
- }
-
- static bool Ready() { return g_done_callback != nullptr; }
-
- static void Accept() {
- g_done_callback->Run(ExtensionInstallPrompt::Result::ACCEPTED);
- }
-
- static void Reject() {
- g_done_callback->Run(ExtensionInstallPrompt::Result::USER_CANCELED);
- }
-
- private:
- static ExtensionInstallPrompt::DoneCallback* g_done_callback;
-
- ExtensionInstallPrompt::DoneCallback done_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(ProgrammableInstallPrompt);
-};
-
-ExtensionInstallPrompt::DoneCallback*
- ProgrammableInstallPrompt::g_done_callback = nullptr;
-
-// Fake inline installer which creates a programmable prompt in place of
-// the normal dialog UI.
-class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller {
- public:
- WebstoreInlineInstallerForTest(WebContents* contents,
- content::RenderFrameHost* host,
- const std::string& extension_id,
- const GURL& requestor_url,
- const Callback& callback,
- bool enable_safebrowsing_redirects)
- : WebstoreInlineInstaller(
- contents,
- host,
- kTestExtensionId,
- requestor_url,
- base::Bind(&WebstoreInlineInstallerForTest::InstallCallback,
- base::Unretained(this))),
- install_result_target_(nullptr),
- enable_safebrowsing_redirects_(enable_safebrowsing_redirects),
- programmable_prompt_(nullptr) {}
-
- std::unique_ptr<ExtensionInstallPrompt> CreateInstallUI() override {
- programmable_prompt_ = new ProgrammableInstallPrompt(web_contents());
- return base::WrapUnique(programmable_prompt_);
- }
-
- // Added here to make it public so that test cases can call it below.
- bool CheckRequestorAlive() const override {
- return WebstoreInlineInstaller::CheckRequestorAlive();
- }
-
- bool SafeBrowsingNavigationEventsEnabled() const override {
- return enable_safebrowsing_redirects_;
- }
-
- // Tests that care about the actual arguments to the install callback can use
- // this to receive a copy in |install_result_target|.
- void set_install_result_target(
- std::unique_ptr<InstallResult>* install_result_target) {
- install_result_target_ = install_result_target;
- }
-
- private:
- ~WebstoreInlineInstallerForTest() override {}
-
- friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>;
-
- void InstallCallback(bool success,
- const std::string& error,
- webstore_install::Result result) {
- if (install_result_target_) {
- install_result_target_->reset(new InstallResult);
- (*install_result_target_)->success = success;
- (*install_result_target_)->error = error;
- (*install_result_target_)->result = result;
- }
- }
-
- // This can be set by tests that want to get the actual install callback
- // arguments.
- std::unique_ptr<InstallResult>* install_result_target_;
-
- // This can be set by tests that want to use the new SafeBrowsing redirect
- // tracker.
- bool enable_safebrowsing_redirects_;
-
- ProgrammableInstallPrompt* programmable_prompt_;
-};
-
-class WebstoreInlineInstallerForTestFactory :
- public WebstoreInlineInstallerFactory {
- public:
- WebstoreInlineInstallerForTestFactory()
- : last_installer_(nullptr), enable_safebrowsing_redirects_(false) {}
- explicit WebstoreInlineInstallerForTestFactory(
- bool enable_safebrowsing_redirects)
- : last_installer_(nullptr),
- enable_safebrowsing_redirects_(enable_safebrowsing_redirects) {}
- ~WebstoreInlineInstallerForTestFactory() override {}
-
- WebstoreInlineInstallerForTest* last_installer() { return last_installer_; }
-
- WebstoreInlineInstaller* CreateInstaller(
- WebContents* contents,
- content::RenderFrameHost* host,
- const std::string& webstore_item_id,
- const GURL& requestor_url,
- const WebstoreStandaloneInstaller::Callback& callback) override {
- last_installer_ = new WebstoreInlineInstallerForTest(
- contents, host, webstore_item_id, requestor_url, callback,
- enable_safebrowsing_redirects_);
- return last_installer_;
- }
-
- private:
- // The last installer that was created.
- WebstoreInlineInstallerForTest* last_installer_;
-
- bool enable_safebrowsing_redirects_;
-};
-
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
- CloseTabBeforeInstallConfirmation) {
- GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
- ui_test_utils::NavigateToURL(browser(), install_url);
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
- tab_helper->SetWebstoreInlineInstallerFactoryForTests(
- new WebstoreInlineInstallerForTestFactory());
- RunTestAsync("runTest");
- while (!ProgrammableInstallPrompt::Ready())
- base::RunLoop().RunUntilIdle();
- web_contents->Close();
- ProgrammableInstallPrompt::Accept();
-}
-
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
- NavigateBeforeInstallConfirmation) {
- GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
- ui_test_utils::NavigateToURL(browser(), install_url);
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
- WebstoreInlineInstallerForTestFactory* factory =
- new WebstoreInlineInstallerForTestFactory();
- tab_helper->SetWebstoreInlineInstallerFactoryForTests(factory);
- RunTestAsync("runTest");
- while (!ProgrammableInstallPrompt::Ready())
- base::RunLoop().RunUntilIdle();
- GURL new_url = GenerateTestServerUrl(kNonAppDomain, "empty.html");
- web_contents->GetController().LoadURL(
- new_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
- EXPECT_TRUE(content::WaitForLoadStop(web_contents));
- ASSERT_NE(factory->last_installer(), nullptr);
- EXPECT_NE(factory->last_installer()->web_contents(), nullptr);
- EXPECT_FALSE(factory->last_installer()->CheckRequestorAlive());
-
- // Right now the way we handle navigations away from the frame that began the
- // inline install is to just declare the requestor to be dead, but not to
- // kill the prompt (that would be a better UX, but more complicated to
- // implement). If we ever do change things to kill the prompt in this case,
- // the following code can be removed (it verifies that clicking ok on the
- // dialog does not result in an install).
- std::unique_ptr<InstallResult> install_result;
- factory->last_installer()->set_install_result_target(&install_result);
- ASSERT_TRUE(ProgrammableInstallPrompt::Ready());
- ProgrammableInstallPrompt::Accept();
- ASSERT_NE(install_result.get(), nullptr);
- EXPECT_EQ(install_result->success, false);
- EXPECT_EQ(install_result->result, webstore_install::ABORTED);
-}
-
-// Flaky: https://crbug.com/537526.
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
- DISABLED_ShouldBlockInlineInstallFromPopupWindow) {
- GURL install_url =
- GenerateTestServerUrl(kAppDomain, "install_from_popup.html");
- // Disable popup blocking for the test url.
- HostContentSettingsMapFactory::GetForProfile(browser()->profile())
- ->SetContentSettingDefaultScope(install_url, GURL(),
- CONTENT_SETTINGS_TYPE_POPUPS,
- std::string(), CONTENT_SETTING_ALLOW);
- ui_test_utils::NavigateToURL(browser(), install_url);
- // The test page opens a popup which is a new |browser| window.
- Browser* popup_browser =
- chrome::FindLastActiveWithProfile(browser()->profile());
- WebContents* popup_contents =
- popup_browser->tab_strip_model()->GetActiveWebContents();
- EXPECT_EQ(base::ASCIIToUTF16("POPUP"), popup_contents->GetTitle());
- RunTest(popup_contents, "runTest");
-}
-
-// Allow inline install while in browser fullscreen mode. Browser fullscreen
-// is initiated by the user using F11 (windows), ctrl+cmd+F (mac) or the green
-// maximize window button on mac. This will be allowed since it cannot be
-// initiated by an API and because of the nuance with mac windows.
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
- AllowInlineInstallFromFullscreenForBrowser) {
- const GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
- ui_test_utils::NavigateToURL(browser(), install_url);
- AutoAcceptInstall();
-
- // Enter browser fullscreen mode.
- FullscreenController* controller =
- browser()->exclusive_access_manager()->fullscreen_controller();
- controller->ToggleBrowserFullscreenMode();
-
- RunTest("runTest");
-
- // Ensure extension is installed.
- ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
- EXPECT_TRUE(
- registry->GenerateInstalledExtensionsSet()->Contains(kTestExtensionId));
-}
-
-// Prevent inline install while in tab fullscreen mode. Tab fullscreen is
-// initiated using the browser API.
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
- BlockInlineInstallFromFullscreenForTab) {
- const GURL install_url =
- GenerateTestServerUrl(kAppDomain, "install_from_fullscreen.html");
- ui_test_utils::NavigateToURL(browser(), install_url);
- AutoAcceptInstall();
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- FullscreenController* controller =
- browser()->exclusive_access_manager()->fullscreen_controller();
-
- // Enter tab fullscreen mode.
- controller->EnterFullscreenModeForTab(web_contents, install_url);
-
- RunTest("runTest");
-
- // Ensure extension is not installed.
- ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
- EXPECT_FALSE(
- registry->GenerateInstalledExtensionsSet()->Contains(kTestExtensionId));
-}
-
-// Flaky on Linux ASan LSan (https://crbug.com/889804)
-#if defined(OS_LINUX) && defined(ADDRESS_SANITIZER)
-#define MAYBE_ReinstallDisabledExtension DISABLED_ReinstallDisabledExtension
-#else
-#define MAYBE_ReinstallDisabledExtension ReinstallDisabledExtension
-#endif
-// Ensure that inline-installing a disabled extension simply re-enables it.
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
- MAYBE_ReinstallDisabledExtension) {
- // Install an extension via inline install, and confirm it is successful.
- AutoAcceptInstall();
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
- RunTest("runTest");
- ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
- ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
-
- // Disable the extension.
- ExtensionService* extension_service =
- ExtensionSystem::Get(browser()->profile())->extension_service();
- extension_service->DisableExtension(kTestExtensionId,
- disable_reason::DISABLE_USER_ACTION);
- EXPECT_TRUE(registry->disabled_extensions().GetByID(kTestExtensionId));
-
- // Revisit the inline install site and reinstall the extension. It should
- // simply be re-enabled, rather than try to install again.
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
- RunTest("runTest");
- EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
- // Since it was disabled by user action, the prompt should have just been the
- // inline install prompt.
- EXPECT_EQ(ExtensionInstallPrompt::INLINE_INSTALL_PROMPT,
- ExtensionInstallPrompt::g_last_prompt_type_for_tests);
-
- // Disable the extension due to a permissions increase.
- extension_service->DisableExtension(
- kTestExtensionId, disable_reason::DISABLE_PERMISSIONS_INCREASE);
- EXPECT_TRUE(registry->disabled_extensions().GetByID(kTestExtensionId));
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
- RunTest("runTest");
- EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
- // The displayed prompt should be for the permissions increase, versus a
- // normal inline install prompt.
- EXPECT_EQ(ExtensionInstallPrompt::RE_ENABLE_PROMPT,
- ExtensionInstallPrompt::g_last_prompt_type_for_tests);
-
- ExtensionInstallPrompt::g_last_prompt_type_for_tests =
- ExtensionInstallPrompt::UNSET_PROMPT_TYPE;
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
- RunTest("runTest");
- // If the extension was already enabled, we should still display an inline
- // install prompt (until we come up with something better).
- EXPECT_EQ(ExtensionInstallPrompt::INLINE_INSTALL_PROMPT,
- ExtensionInstallPrompt::g_last_prompt_type_for_tests);
-}
-
-// Test calling chrome.webstore.install() twice without waiting for the first to
-// finish.
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, DoubleInlineInstallTest) {
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "double_install.html"));
- RunTest("runTest");
-}
-
-class WebstoreInlineInstallerRedirectTest
- : public WebstoreInlineInstallerTest,
- public ::testing::WithParamInterface<bool> {
- public:
- WebstoreInlineInstallerRedirectTest() : cws_request_received_(false) {}
- ~WebstoreInlineInstallerRedirectTest() override {}
-
- void SetUpOnMainThread() override {
- WebstoreInstallerTest::SetUpOnMainThread();
- host_resolver()->AddRule(kRedirect1Domain, "127.0.0.1");
- host_resolver()->AddRule(kRedirect2Domain, "127.0.0.1");
- }
-
- void ProcessServerRequest(
- const net::test_server::HttpRequest& request) override {
- cws_request_received_ = true;
- if (request.content.empty())
- return;
-
- cws_request_proto_ =
- std::make_unique<safe_browsing::ExtensionWebStoreInstallRequest>();
- if (!cws_request_proto_->ParseFromString(request.content))
- cws_request_proto_.reset();
- }
-
- bool cws_request_received_;
- std::unique_ptr<safe_browsing::ExtensionWebStoreInstallRequest>
- cws_request_proto_;
-};
-
-// Test that an install from a page arrived at via redirects includes the
-// redirect information in the webstore request.
-IN_PROC_BROWSER_TEST_P(WebstoreInlineInstallerRedirectTest,
- IncludesRedirectProtoData) {
- const bool using_safe_browsing_tracker = GetParam();
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
- WebstoreInlineInstallerForTestFactory* factory =
- new WebstoreInlineInstallerForTestFactory(using_safe_browsing_tracker);
- tab_helper->SetWebstoreInlineInstallerFactoryForTests(factory);
-
- net::HostPortPair host_port = embedded_test_server()->host_port_pair();
-
- std::string final_url =
- GenerateTestServerUrl(kAppDomain, "install.html").spec();
- std::string redirect_url =
- base::StringPrintf("http://%s:%d/server-redirect?%s", kRedirect2Domain,
- host_port.port(), final_url.c_str());
- std::string install_url =
- base::StringPrintf("http://%s:%d/server-redirect?%s", kRedirect1Domain,
- host_port.port(), redirect_url.c_str());
- AutoAcceptInstall();
- ui_test_utils::NavigateToURL(browser(), GURL(install_url));
-
- RunTestAsync("runTest");
- while (!ProgrammableInstallPrompt::Ready())
- base::RunLoop().RunUntilIdle();
- web_contents->Close();
-
- EXPECT_TRUE(cws_request_received_);
- if (!using_safe_browsing_tracker) {
- ASSERT_EQ(nullptr, cws_request_proto_);
- return;
- }
- ASSERT_NE(nullptr, cws_request_proto_);
- ASSERT_EQ(1, cws_request_proto_->referrer_chain_size());
-
- safe_browsing::ReferrerChainEntry referrer_entry =
- cws_request_proto_->referrer_chain(0);
-
- // Check that the expected domains are in the redirect list.
- const std::set<std::string> expected_redirect_domains = {
- kRedirect1Domain, kRedirect2Domain, kAppDomain};
-
- EXPECT_EQ(final_url, referrer_entry.url());
- EXPECT_EQ(safe_browsing::ReferrerChainEntry::CLIENT_REDIRECT,
- referrer_entry.type());
- EXPECT_EQ(3, referrer_entry.server_redirect_chain_size());
- EXPECT_EQ(install_url, referrer_entry.server_redirect_chain(0).url());
- EXPECT_EQ(redirect_url, referrer_entry.server_redirect_chain(1).url());
- EXPECT_EQ(final_url, referrer_entry.server_redirect_chain(2).url());
- EXPECT_TRUE(cws_request_proto_->referrer_chain_options()
- .has_recent_navigations_to_collect());
-}
-
-// Test that an install from a page arrived at via redirects does not include
-// redirect information when SafeBrowsing is disabled.
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerRedirectTest,
- NoRedirectDataWhenSafeBrowsingDisabled) {
- PrefService* pref_service = browser()->profile()->GetPrefs();
- EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled));
-
- // Disable SafeBrowsing.
- pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false);
-
- // Hand craft a url that will cause the test server to issue redirects.
- const std::vector<std::string> redirects = {kRedirect1Domain,
- kRedirect2Domain};
- net::HostPortPair host_port = embedded_test_server()->host_port_pair();
- std::string redirect_chain;
- for (const auto& redirect : redirects) {
- std::string redirect_url = base::StringPrintf(
- "http://%s:%d/server-redirect?", redirect.c_str(), host_port.port());
- redirect_chain += redirect_url;
- }
- const GURL install_url =
- GURL(redirect_chain +
- GenerateTestServerUrl(kAppDomain, "install.html").spec());
-
- AutoAcceptInstall();
- ui_test_utils::NavigateToURL(browser(), install_url);
- RunTest("runTest");
-
- EXPECT_TRUE(cws_request_received_);
- ASSERT_EQ(nullptr, cws_request_proto_);
-}
-
-INSTANTIATE_TEST_CASE_P(NetRedirectTracking,
- WebstoreInlineInstallerRedirectTest,
- testing::Values(false));
-INSTANTIATE_TEST_CASE_P(SafeBrowsingRedirectTracking,
- WebstoreInlineInstallerRedirectTest,
- testing::Values(true));
-
-class WebstoreInlineInstallerListenerTest : public WebstoreInlineInstallerTest {
- public:
- WebstoreInlineInstallerListenerTest() {}
- ~WebstoreInlineInstallerListenerTest() override {}
-
- protected:
- void RunTest(const std::string& file_name) {
- AutoAcceptInstall();
- ui_test_utils::NavigateToURL(browser(),
- GenerateTestServerUrl(kAppDomain, file_name));
- WebstoreInstallerTest::RunTest("runTest");
- }
-};
-
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest,
- InstallStageListenerTest) {
- RunTest("install_stage_listener.html");
-}
-
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest,
- DownloadProgressListenerTest) {
- RunTest("download_progress_listener.html");
-}
-
-// Flaky on Linux ASan LSan (https://crbug.com/889804)
-#if defined(OS_LINUX) && defined(ADDRESS_SANITIZER)
-#define MAYBE_BothListenersTest DISABLED_BothListenersTest
-#else
-#define MAYBE_BothListenersTest BothListenersTest
-#endif
-IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest,
- MAYBE_BothListenersTest) {
- RunTest("both_listeners.html");
- // The extension should be installed.
- ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
- EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
-
- // Rinse and repeat: uninstall the extension, open a new tab, and install it
- // again. Regression test for crbug.com/613949.
- extension_service()->UninstallExtension(
- kTestExtensionId, UNINSTALL_REASON_FOR_TESTING, nullptr);
- base::RunLoop().RunUntilIdle();
- EXPECT_FALSE(registry->enabled_extensions().GetByID(kTestExtensionId));
- int old_tab_index = browser()->tab_strip_model()->active_index();
- ui_test_utils::NavigateToURLWithDisposition(
- browser(), GenerateTestServerUrl(kAppDomain, "both_listeners.html"),
- WindowOpenDisposition::NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
- DCHECK_NE(old_tab_index, browser()->tab_strip_model()->active_index());
- browser()->tab_strip_model()->CloseWebContentsAt(old_tab_index,
- TabStripModel::CLOSE_NONE);
- WebstoreInstallerTest::RunTest("runTest");
- EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/webstore_inline_installer_factory.cc b/chrome/browser/extensions/webstore_inline_installer_factory.cc
deleted file mode 100644
index 39e0b83a..0000000
--- a/chrome/browser/extensions/webstore_inline_installer_factory.cc
+++ /dev/null
@@ -1,24 +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/extensions/webstore_inline_installer_factory.h"
-
-#include <memory>
-
-#include "chrome/browser/extensions/webstore_inline_installer.h"
-#include "content/public/browser/web_contents.h"
-
-namespace extensions {
-
-WebstoreInlineInstaller* WebstoreInlineInstallerFactory::CreateInstaller(
- content::WebContents* contents,
- content::RenderFrameHost* host,
- const std::string& webstore_item_id,
- const GURL& requestor_url,
- const WebstoreStandaloneInstaller::Callback& callback) {
- return new WebstoreInlineInstaller(contents, host, webstore_item_id,
- requestor_url, callback);
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/webstore_inline_installer_factory.h b/chrome/browser/extensions/webstore_inline_installer_factory.h
deleted file mode 100644
index 97dcc8f9..0000000
--- a/chrome/browser/extensions/webstore_inline_installer_factory.h
+++ /dev/null
@@ -1,39 +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_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_FACTORY_H_
-#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_FACTORY_H_
-
-#include <memory>
-#include <string>
-
-#include "chrome/browser/extensions/extension_install_prompt.h"
-#include "chrome/browser/extensions/webstore_standalone_installer.h"
-
-namespace content {
-class WebContents;
-}
-
-class GURL;
-
-namespace extensions {
-
-class WebstoreInlineInstaller;
-
-class WebstoreInlineInstallerFactory {
- public:
- virtual ~WebstoreInlineInstallerFactory() {}
-
- // Create a new WebstoreInlineInstallerInstance to be owned by the caller.
- virtual WebstoreInlineInstaller* CreateInstaller(
- content::WebContents* contents,
- content::RenderFrameHost* host,
- const std::string& webstore_item_id,
- const GURL& requestor_url,
- const WebstoreStandaloneInstaller::Callback& callback);
-};
-
-} // namespace extensions
-
-#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INLINE_INSTALLER_FACTORY_H_
diff --git a/chrome/browser/extensions/webstore_inline_installer_unittest.cc b/chrome/browser/extensions/webstore_inline_installer_unittest.cc
deleted file mode 100644
index 881528bc..0000000
--- a/chrome/browser/extensions/webstore_inline_installer_unittest.cc
+++ /dev/null
@@ -1,228 +0,0 @@
-// Copyright (c) 2012 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 <utility>
-#include <vector>
-
-#include "chrome/browser/extensions/webstore_inline_installer.h"
-#include "chrome/common/extensions/webstore_install_result.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
-#include "content/public/browser/web_contents.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-namespace extensions {
-
-namespace {
-
-// Wraps WebstoreInlineInstaller to provide access to domain verification
-// methods for testing.
-class TestWebstoreInlineInstaller : public WebstoreInlineInstaller {
- public:
- explicit TestWebstoreInlineInstaller(content::WebContents* contents,
- const std::string& requestor_url);
-
- bool TestCheckRequestorPermitted(const base::DictionaryValue& webstore_data) {
- std::string error;
- return CheckRequestorPermitted(webstore_data, &error);
- }
-
- protected:
- ~TestWebstoreInlineInstaller() override;
-};
-
-void TestInstallerCallback(bool success,
- const std::string& error,
- webstore_install::Result result) {}
-
-TestWebstoreInlineInstaller::TestWebstoreInlineInstaller(
- content::WebContents* contents,
- const std::string& requestor_url)
- : WebstoreInlineInstaller(contents,
- contents->GetMainFrame(),
- "",
- GURL(requestor_url),
- base::Bind(&TestInstallerCallback)) {
-}
-
-TestWebstoreInlineInstaller::~TestWebstoreInlineInstaller() {}
-
-// We inherit from ChromeRenderViewHostTestHarness only for
-// CreateTestWebContents, because we need a mock WebContents to support the
-// underlying WebstoreInlineInstaller in each test case.
-class WebstoreInlineInstallerTest : public ChromeRenderViewHostTestHarness {
- public:
- // testing::Test
- void SetUp() override;
- void TearDown() override;
-
- bool TestSingleVerifiedSite(const std::string& requestor_url,
- const std::string& verified_site);
-
- bool TestMultipleVerifiedSites(
- const std::string& requestor_url,
- const std::vector<std::string>& verified_sites);
-
- protected:
- std::unique_ptr<content::WebContents> web_contents_;
-};
-
-void WebstoreInlineInstallerTest::SetUp() {
- ChromeRenderViewHostTestHarness::SetUp();
- web_contents_ = CreateTestWebContents();
-}
-
-void WebstoreInlineInstallerTest::TearDown() {
- web_contents_.reset(NULL);
- ChromeRenderViewHostTestHarness::TearDown();
-}
-
-// Simulates a test against the verified site string from a Webstore item's
-// "verified_site" manifest entry.
-bool WebstoreInlineInstallerTest::TestSingleVerifiedSite(
- const std::string& requestor_url,
- const std::string& verified_site) {
- base::DictionaryValue webstore_data;
- webstore_data.SetString("verified_site", verified_site);
-
- scoped_refptr<TestWebstoreInlineInstaller> installer =
- new TestWebstoreInlineInstaller(web_contents_.get(), requestor_url);
- return installer->TestCheckRequestorPermitted(webstore_data);
-}
-
-// Simulates a test against a list of verified site strings from a Webstore
-// item's "verified_sites" manifest entry.
-bool WebstoreInlineInstallerTest::TestMultipleVerifiedSites(
- const std::string& requestor_url,
- const std::vector<std::string>& verified_sites) {
- auto sites = std::make_unique<base::ListValue>();
- for (auto it = verified_sites.begin(); it != verified_sites.end(); ++it) {
- sites->AppendString(*it);
- }
- base::DictionaryValue webstore_data;
- webstore_data.Set("verified_sites", std::move(sites));
-
- scoped_refptr<TestWebstoreInlineInstaller> installer =
- new TestWebstoreInlineInstaller(web_contents_.get(), requestor_url);
- return installer->TestCheckRequestorPermitted(webstore_data);
-}
-
-} // namespace
-
-TEST_F(WebstoreInlineInstallerTest, DomainVerification) {
- // Exact domain match.
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com", "example.com"));
-
- // The HTTPS scheme is allowed.
- EXPECT_TRUE(TestSingleVerifiedSite("https://example.com", "example.com"));
-
- // The file: scheme is not allowed.
- EXPECT_FALSE(TestSingleVerifiedSite("file:///example.com", "example.com"));
-
- // Trailing slash in URL.
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/", "example.com"));
-
- // Page on the domain.
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/page.html",
- "example.com"));
-
- // Page on a subdomain.
- EXPECT_TRUE(TestSingleVerifiedSite("http://sub.example.com/page.html",
- "example.com"));
-
- // Root domain when only a subdomain is verified.
- EXPECT_FALSE(TestSingleVerifiedSite("http://example.com/",
- "sub.example.com"));
-
- // Different subdomain when only a subdomain is verified.
- EXPECT_FALSE(TestSingleVerifiedSite("http://www.example.com/",
- "sub.example.com"));
-
- // Port matches.
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com:123/",
- "example.com:123"));
-
- // Port doesn't match.
- EXPECT_FALSE(TestSingleVerifiedSite("http://example.com:456/",
- "example.com:123"));
-
- // Port is missing in the requestor URL.
- EXPECT_FALSE(TestSingleVerifiedSite("http://example.com/",
- "example.com:123"));
-
- // Port is missing in the verified site (any port matches).
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com:123/", "example.com"));
-
- // Path matches.
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/path",
- "example.com/path"));
-
- // Path doesn't match.
- EXPECT_FALSE(TestSingleVerifiedSite("http://example.com/foo",
- "example.com/path"));
-
- // Path is missing.
- EXPECT_FALSE(TestSingleVerifiedSite("http://example.com",
- "example.com/path"));
-
- // Path matches (with trailing slash).
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/path/",
- "example.com/path"));
-
- // Path matches (is a file under the path).
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com/path/page.html",
- "example.com/path"));
-
- // Path and port match.
- EXPECT_TRUE(TestSingleVerifiedSite(
- "http://example.com:123/path/page.html", "example.com:123/path"));
-
- // Match specific valid schemes
- EXPECT_TRUE(TestSingleVerifiedSite("http://example.com",
- "http://example.com"));
- EXPECT_TRUE(TestSingleVerifiedSite("https://example.com",
- "https://example.com"));
-
- // Mismatch specific vaild schemes
- EXPECT_FALSE(TestSingleVerifiedSite("https://example.com",
- "http://example.com"));
- EXPECT_FALSE(TestSingleVerifiedSite("http://example.com",
- "https://example.com"));
-
- // Invalid scheme spec
- EXPECT_FALSE(TestSingleVerifiedSite("file://example.com",
- "file://example.com"));
-
- std::vector<std::string> verified_sites;
- verified_sites.push_back("foo.example.com");
- verified_sites.push_back("bar.example.com:123");
- verified_sites.push_back("example.com/unicorns");
-
- // Test valid examples against the site list.
-
- EXPECT_TRUE(TestMultipleVerifiedSites("http://foo.example.com",
- verified_sites));
-
- EXPECT_TRUE(TestMultipleVerifiedSites("http://bar.example.com:123",
- verified_sites));
-
- EXPECT_TRUE(TestMultipleVerifiedSites(
- "http://cooking.example.com/unicorns/bacon.html", verified_sites));
-
- // Test invalid examples against the site list.
-
- EXPECT_FALSE(TestMultipleVerifiedSites("http://example.com",
- verified_sites));
-
- EXPECT_FALSE(TestMultipleVerifiedSites("file://foo.example.com",
- verified_sites));
-
- EXPECT_FALSE(TestMultipleVerifiedSites("http://baz.example.com",
- verified_sites));
-
- EXPECT_FALSE(TestMultipleVerifiedSites("http://bar.example.com:456",
- verified_sites));
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/webstore_install_with_prompt.cc b/chrome/browser/extensions/webstore_install_with_prompt.cc
index aab742f..4e60cd55 100644
--- a/chrome/browser/extensions/webstore_install_with_prompt.cc
+++ b/chrome/browser/extensions/webstore_install_with_prompt.cc
@@ -50,10 +50,6 @@
return !parent_window_tracker_->WasNativeWindowClosed();
}
-const GURL& WebstoreInstallWithPrompt::GetRequestorURL() const {
- return dummy_requestor_url_;
-}
-
std::unique_ptr<ExtensionInstallPrompt::Prompt>
WebstoreInstallWithPrompt::CreateInstallPrompt() const {
return std::make_unique<ExtensionInstallPrompt::Prompt>(
@@ -79,20 +75,4 @@
return dummy_web_contents_.get();
}
-bool WebstoreInstallWithPrompt::CheckInlineInstallPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- // Assume the requestor is trusted.
- *error = std::string();
- return true;
-}
-
-bool WebstoreInstallWithPrompt::CheckRequestorPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- // Assume the requestor is trusted.
- *error = std::string();
- return true;
-}
-
} // namespace extensions
diff --git a/chrome/browser/extensions/webstore_install_with_prompt.h b/chrome/browser/extensions/webstore_install_with_prompt.h
index ce4976ad..483ad49 100644
--- a/chrome/browser/extensions/webstore_install_with_prompt.h
+++ b/chrome/browser/extensions/webstore_install_with_prompt.h
@@ -52,23 +52,16 @@
// extensions::WebstoreStandaloneInstaller overrides:
bool CheckRequestorAlive() const override;
- const GURL& GetRequestorURL() const override;
bool ShouldShowPostInstallUI() const override;
bool ShouldShowAppInstalledBubble() const override;
content::WebContents* GetWebContents() const override;
std::unique_ptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
const override;
std::unique_ptr<ExtensionInstallPrompt> CreateInstallUI() 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;
private:
bool show_post_install_ui_;
- GURL dummy_requestor_url_;
-
// A non-visible WebContents used to download data from the webstore.
std::unique_ptr<content::WebContents> dummy_web_contents_;
diff --git a/chrome/browser/extensions/webstore_installer.h b/chrome/browser/extensions/webstore_installer.h
index ce7e85f..2dc86e3a 100644
--- a/chrome/browser/extensions/webstore_installer.h
+++ b/chrome/browser/extensions/webstore_installer.h
@@ -58,6 +58,9 @@
enum InstallSource {
// Inline installs trigger slightly different behavior (install source
// is different, download referrers are the item's page in the gallery).
+ // TODO(ackermanb): Remove once server side metrics (omaha) tracking with
+ // this enum is figured out with any of the subclasses of
+ // WebstoreStandaloneInstaller.
INSTALL_SOURCE_INLINE,
INSTALL_SOURCE_APP_LAUNCHER,
INSTALL_SOURCE_OTHER
diff --git a/chrome/browser/extensions/webstore_installer_test.cc b/chrome/browser/extensions/webstore_installer_test.cc
index 7bdca8c9..8318d22 100644
--- a/chrome/browser/extensions/webstore_installer_test.cc
+++ b/chrome/browser/extensions/webstore_installer_test.cc
@@ -8,8 +8,6 @@
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/tab_helper.h"
-#include "chrome/browser/extensions/webstore_inline_installer.h"
-#include "chrome/browser/extensions/webstore_inline_installer_factory.h"
#include "chrome/browser/extensions/webstore_installer_test.h"
#include "chrome/browser/extensions/webstore_standalone_installer.h"
#include "chrome/browser/profiles/profile.h"
@@ -33,8 +31,6 @@
using content::WebContents;
using extensions::Extension;
using extensions::TabHelper;
-using extensions::WebstoreInlineInstaller;
-using extensions::WebstoreInlineInstallerFactory;
using extensions::WebstoreStandaloneInstaller;
using net::test_server::HttpRequest;
diff --git a/chrome/browser/extensions/webstore_installer_unittest.cc b/chrome/browser/extensions/webstore_installer_unittest.cc
index 3befa733..9adee7a 100644
--- a/chrome/browser/extensions/webstore_installer_unittest.cc
+++ b/chrome/browser/extensions/webstore_installer_unittest.cc
@@ -26,8 +26,8 @@
TEST(WebstoreInstallerTest, PlatformParams) {
std::string id = crx_file::id_util::GenerateId("some random string");
std::string source = "inline";
- GURL url = WebstoreInstaller::GetWebstoreInstallURL(id,
- WebstoreInstaller::INSTALL_SOURCE_INLINE);
+ GURL url = WebstoreInstaller::GetWebstoreInstallURL(
+ id, WebstoreInstaller::INSTALL_SOURCE_INLINE);
std::string query = url.query();
EXPECT_TRUE(
Contains(query, StringPrintf("os=%s", UpdateQueryParams::GetOS())));
diff --git a/chrome/browser/extensions/webstore_reinstaller.cc b/chrome/browser/extensions/webstore_reinstaller.cc
index 720b69e6..61fcf8eb 100644
--- a/chrome/browser/extensions/webstore_reinstaller.cc
+++ b/chrome/browser/extensions/webstore_reinstaller.cc
@@ -43,10 +43,6 @@
return web_contents() != NULL;
}
-const GURL& WebstoreReinstaller::GetRequestorURL() const {
- return GURL::EmptyGURL();
-}
-
std::unique_ptr<ExtensionInstallPrompt::Prompt>
WebstoreReinstaller::CreateInstallPrompt() const {
std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt(
@@ -71,18 +67,6 @@
return web_contents();
}
-bool WebstoreReinstaller::CheckInlineInstallPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- return true;
-}
-
-bool WebstoreReinstaller::CheckRequestorPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const {
- return true;
-}
-
void WebstoreReinstaller::WebContentsDestroyed() {
// Run the callback now, because AbortInstall() doesn't do it.
RunCallback(false, kTabClosed, webstore_install::ABORTED);
diff --git a/chrome/browser/extensions/webstore_reinstaller.h b/chrome/browser/extensions/webstore_reinstaller.h
index 19996fcf..24904a9b 100644
--- a/chrome/browser/extensions/webstore_reinstaller.h
+++ b/chrome/browser/extensions/webstore_reinstaller.h
@@ -30,16 +30,11 @@
// WebstoreStandaloneInstaller:
bool CheckRequestorAlive() const override;
- const GURL& GetRequestorURL() const override;
bool ShouldShowPostInstallUI() const override;
bool ShouldShowAppInstalledBubble() const override;
content::WebContents* GetWebContents() const override;
std::unique_ptr<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 OnInstallPromptDone(ExtensionInstallPrompt::Result result) override;
// content::WebContentsObserver:
diff --git a/chrome/browser/extensions/webstore_standalone_installer.cc b/chrome/browser/extensions/webstore_standalone_installer.cc
index a4499af..e8517e9 100644
--- a/chrome/browser/extensions/webstore_standalone_installer.cc
+++ b/chrome/browser/extensions/webstore_standalone_installer.cc
@@ -38,8 +38,7 @@
install_source_(WebstoreInstaller::INSTALL_SOURCE_INLINE),
show_user_count_(true),
average_rating_(0.0),
- rating_count_(0) {
-}
+ rating_count_(0) {}
void WebstoreStandaloneInstaller::BeginInstall() {
// Add a ref to keep this alive for WebstoreDataFetcher.
@@ -63,10 +62,7 @@
// Use the requesting page as the referrer both since that is more correct
// (it is the page that caused this request to happen) and so that we can
// track top sites that trigger inline install requests.
- webstore_data_fetcher_.reset(
- new WebstoreDataFetcher(this, GetRequestorURL(), id_));
-
- webstore_data_fetcher_->SetPostData(GetPostData());
+ webstore_data_fetcher_.reset(new WebstoreDataFetcher(this, GURL(), id_));
webstore_data_fetcher_->Start(
content::BrowserContext::GetDefaultStoragePartition(profile_)
@@ -155,10 +151,6 @@
return localized_extension_for_display_.get();
}
-std::string WebstoreStandaloneInstaller::GetPostData() {
- return std::string();
-}
-
void WebstoreStandaloneInstaller::OnManifestParsed() {
ProceedWithInstallPrompt();
}
@@ -243,16 +235,6 @@
std::string error;
- if (!CheckInlineInstallPermitted(*webstore_data, &error)) {
- CompleteInstall(webstore_install::NOT_PERMITTED, error);
- return;
- }
-
- if (!CheckRequestorPermitted(*webstore_data, &error)) {
- CompleteInstall(webstore_install::NOT_PERMITTED, error);
- return;
- }
-
// Manifest, number of users, average rating and rating count are required.
std::string manifest;
if (!webstore_data->GetString(kManifestKey, &manifest) ||
diff --git a/chrome/browser/extensions/webstore_standalone_installer.h b/chrome/browser/extensions/webstore_standalone_installer.h
index d2989a1..c52695c 100644
--- a/chrome/browser/extensions/webstore_standalone_installer.h
+++ b/chrome/browser/extensions/webstore_standalone_installer.h
@@ -20,8 +20,6 @@
#include "net/url_request/url_fetcher_delegate.h"
#include "third_party/skia/include/core/SkBitmap.h"
-class GURL;
-
namespace base {
class DictionaryValue;
}
@@ -87,20 +85,11 @@
// Template Method's hooks to be implemented by subclasses.
- // Gives subclasses an opportunity to provide extra post data in the form of
- // serialized proto to the webstore data request before sending. The default
- // implementation returns an empty string.
- virtual std::string GetPostData();
-
// Called at certain check points of the workflow to decide whether it makes
// sense to proceed with installation. A requestor can be a website that
// initiated an inline installation, or a command line option.
virtual bool CheckRequestorAlive() const = 0;
- // Requestor's URL, if any. Should be an empty GURL if URL is meaningless
- // (e.g. for a command line option).
- virtual const GURL& GetRequestorURL() const = 0;
-
// Should a new tab be opened after installation to show the newly installed
// extension's icon?
virtual bool ShouldShowPostInstallUI() const = 0;
@@ -120,20 +109,6 @@
virtual std::unique_ptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
const = 0;
- // Perform all necessary checks to make sure inline install is permitted,
- // e.g. in the extension's properties in the store. The implementation may
- // choose to ignore such properties.
- virtual bool CheckInlineInstallPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const = 0;
-
- // Perform all necessary checks to make sure that requestor is allowed to
- // initiate this install (e.g. that the requestor's URL matches the verified
- // author's site specified in the extension's properties in the store).
- virtual bool CheckRequestorPermitted(
- const base::DictionaryValue& webstore_data,
- std::string* error) const = 0;
-
// Will be called after the extension's manifest has been successfully parsed.
// Subclasses can perform asynchronous checks at this point and call
// ProceedWithInstallPrompt() to proceed with the install or otherwise call
diff --git a/chrome/browser/extensions/webstore_startup_installer.cc b/chrome/browser/extensions/webstore_startup_installer.cc
deleted file mode 100644
index 010821a..0000000
--- a/chrome/browser/extensions/webstore_startup_installer.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2012 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/extensions/webstore_startup_installer.h"
-
-#include <memory>
-
-namespace extensions {
-
-WebstoreStartupInstaller::WebstoreStartupInstaller(
- const std::string& webstore_item_id,
- Profile* profile,
- bool show_prompt,
- const Callback& callback)
- : WebstoreInstallWithPrompt(webstore_item_id, profile, callback),
- show_prompt_(show_prompt) {
- set_install_source(WebstoreInstaller::INSTALL_SOURCE_INLINE);
- set_show_post_install_ui(false);
-}
-
-WebstoreStartupInstaller::~WebstoreStartupInstaller() {}
-
-std::unique_ptr<ExtensionInstallPrompt::Prompt>
-WebstoreStartupInstaller::CreateInstallPrompt() const {
- if (show_prompt_) {
- return std::make_unique<ExtensionInstallPrompt::Prompt>(
- ExtensionInstallPrompt::INSTALL_PROMPT);
- }
- return NULL;
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/webstore_startup_installer.h b/chrome/browser/extensions/webstore_startup_installer.h
deleted file mode 100644
index 594582d6..0000000
--- a/chrome/browser/extensions/webstore_startup_installer.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2012 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_EXTENSIONS_WEBSTORE_STARTUP_INSTALLER_H_
-#define CHROME_BROWSER_EXTENSIONS_WEBSTORE_STARTUP_INSTALLER_H_
-
-#include "base/gtest_prod_util.h"
-#include "base/macros.h"
-#include "chrome/browser/extensions/webstore_install_with_prompt.h"
-
-namespace extensions {
-
-// Manages inline installs requested to be performed at startup, e.g. via a
-// command line option: downloads and parses metadata from the webstore,
-// optionally shows an install UI, starts the download once the user
-// confirms.
-//
-// Clients will be notified of success or failure via the |callback| argument
-// passed into the constructor.
-class WebstoreStartupInstaller : public WebstoreInstallWithPrompt {
- public:
- WebstoreStartupInstaller(const std::string& webstore_item_id,
- Profile* profile,
- bool show_prompt,
- const Callback& callback);
-
- protected:
- friend class base::RefCountedThreadSafe<WebstoreStartupInstaller>;
- FRIEND_TEST_ALL_PREFIXES(WebstoreStartupInstallerTest, DomainVerification);
-
- ~WebstoreStartupInstaller() override;
-
- // Implementations of WebstoreStandaloneInstaller Template Method's hooks.
- std::unique_ptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
- const override;
-
- private:
- bool show_prompt_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(WebstoreStartupInstaller);
-};
-
-} // namespace extensions
-
-#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_STARTUP_INSTALLER_H_
diff --git a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc
deleted file mode 100644
index 498ab5c..0000000
--- a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc
+++ /dev/null
@@ -1,247 +0,0 @@
-// Copyright (c) 2012 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 <utility>
-
-#include "base/command_line.h"
-#include "base/scoped_observer.h"
-#include "build/build_config.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/webstore_installer_test.h"
-#include "chrome/browser/infobars/infobar_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/test/base/in_process_browser_test.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/test/browser_test_utils.h"
-#include "extensions/browser/extension_host.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/extension_system.h"
-#include "extensions/browser/install/extension_install_ui.h"
-#include "extensions/common/extension_builder.h"
-#include "extensions/common/value_builder.h"
-#include "net/dns/mock_host_resolver.h"
-#include "url/gurl.h"
-
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
-#include "chrome/browser/supervised_user/supervised_user_constants.h"
-#endif
-
-#if defined(OS_CHROMEOS)
-#include "chromeos/chromeos_switches.h"
-#endif
-
-using content::WebContents;
-using extensions::DictionaryBuilder;
-using extensions::Extension;
-using extensions::ExtensionBuilder;
-using extensions::ListBuilder;
-
-const char kWebstoreDomain[] = "cws.com";
-const char kAppDomain[] = "app.com";
-const char kNonAppDomain[] = "nonapp.com";
-const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje";
-const char kTestDataPath[] = "extensions/api_test/webstore_inline_install";
-const char kCrxFilename[] = "extension.crx";
-
-class WebstoreStartupInstallerTest : public WebstoreInstallerTest {
- public:
- WebstoreStartupInstallerTest()
- : WebstoreInstallerTest(
- kWebstoreDomain,
- kTestDataPath,
- kCrxFilename,
- kAppDomain,
- kNonAppDomain) {}
-};
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) {
- AutoAcceptInstall();
-
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
-
- RunTest("runTest");
-
- extensions::ExtensionRegistry* registry =
- extensions::ExtensionRegistry::Get(browser()->profile());
- const extensions::Extension* extension =
- registry->enabled_extensions().GetByID(kTestExtensionId);
- EXPECT_TRUE(extension);
-}
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
- InstallNotAllowedFromNonVerifiedDomains) {
- AutoCancelInstall();
- ui_test_utils::NavigateToURL(
- browser(),
- GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
-
- RunTest("runTest1");
- RunTest("runTest2");
-}
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, FindLink) {
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "find_link.html"));
-
- RunTest("runTest");
-}
-
-// Flakes on all platforms: http://crbug.com/95713, http://crbug.com/229947
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
- DISABLED_ArgumentValidation) {
- AutoCancelInstall();
-
- // Each of these tests has to run separately, since one page/tab can
- // only have one in-progress install request. These tests don't all pass
- // callbacks to install, so they have no way to wait for the installation
- // to complete before starting the next test.
- bool is_finished = false;
- for (int i = 0; !is_finished; ++i) {
- ui_test_utils::NavigateToURL(
- browser(),
- GenerateTestServerUrl(kAppDomain, "argument_validation.html"));
- is_finished = !RunIndexedTest("runTest", i);
- }
-}
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) {
- AutoCancelInstall();
-
- ui_test_utils::NavigateToURL(
- browser(),
- GenerateTestServerUrl(kAppDomain, "multiple_install_calls.html"));
- RunTest("runTest");
-}
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) {
- AutoCancelInstall();
- ui_test_utils::NavigateToURL(
- browser(),
- GenerateTestServerUrl(kAppDomain, "install_not_supported.html"));
-
- ui_test_utils::WindowedTabAddedNotificationObserver observer(
- content::NotificationService::AllSources());
- RunTest("runTest");
- observer.Wait();
-
- // The inline install should fail, and a store-provided URL should be opened
- // in a new tab.
- WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- EXPECT_EQ(GURL("http://cws.com/show-me-the-money"), web_contents->GetURL());
-}
-
-// Regression test for http://crbug.com/144991.
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) {
- AutoAcceptInstall();
-
- const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html");
-
- // We're forced to construct a hosted app dynamically because we need the
- // app to run on a declared URL, but we don't know the port ahead of time.
- scoped_refptr<const Extension> hosted_app =
- ExtensionBuilder()
- .SetManifest(
- DictionaryBuilder()
- .Set("name", "hosted app")
- .Set("version", "1")
- .Set(
- "app",
- DictionaryBuilder()
- .Set("urls",
- ListBuilder().Append(kInstallUrl.spec()).Build())
- .Set("launch", DictionaryBuilder()
- .Set("web_url", kInstallUrl.spec())
- .Build())
- .Build())
- .Set("manifest_version", 2)
- .Build())
- .Build();
- ASSERT_TRUE(hosted_app.get());
-
- extensions::ExtensionService* extension_service =
- extensions::ExtensionSystem::Get(browser()->profile())
- ->extension_service();
- extensions::ExtensionRegistry* registry =
- extensions::ExtensionRegistry::Get(browser()->profile());
-
- extension_service->AddExtension(hosted_app.get());
- EXPECT_TRUE(registry->enabled_extensions().GetByID(hosted_app->id()));
-
- ui_test_utils::NavigateToURL(browser(), kInstallUrl);
-
- EXPECT_FALSE(registry->enabled_extensions().GetByID(kTestExtensionId));
- RunTest("runTest");
- EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
-}
-
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
-class WebstoreStartupInstallerSupervisedUsersTest
- : public WebstoreStartupInstallerTest {
- public:
- // InProcessBrowserTest overrides:
- void SetUpCommandLine(base::CommandLine* command_line) override {
- WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
- command_line->AppendSwitchASCII(switches::kSupervisedUserId,
- supervised_users::kChildAccountSUID);
-#if defined(OS_CHROMEOS)
- command_line->AppendSwitchASCII(
- chromeos::switches::kLoginUser,
- "[email protected]");
- command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash");
-#endif
- }
-};
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest,
- InstallProhibited) {
- AutoAcceptInstall();
-
- ui_test_utils::NavigateToURL(
- browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html"));
-
- RunTest("runTest");
-
- // No error infobar should show up.
- WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
- InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
- EXPECT_EQ(0u, infobar_service->infobar_count());
-}
-#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
-
-// The unpack failure test needs to use a different install .crx, which is
-// specified via a command-line flag, so it needs its own test subclass.
-class WebstoreStartupInstallUnpackFailureTest
- : public WebstoreStartupInstallerTest {
- public:
- void SetUpCommandLine(base::CommandLine* command_line) override {
- WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
-
- GURL crx_url = GenerateTestServerUrl(
- kWebstoreDomain, "malformed_extension.crx");
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryUpdateURL, crx_url.spec());
- }
-
- void SetUpInProcessBrowserTestFixture() override {
- WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture();
- extensions::ExtensionInstallUI::set_disable_ui_for_tests();
- }
-};
-
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest,
- WebstoreStartupInstallUnpackFailureTest) {
- AutoAcceptInstall();
-
- ui_test_utils::NavigateToURL(browser(),
- GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
-
- RunTest("runTest");
-}
diff --git a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc
index 1adb1ff..c3f7c23 100644
--- a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc
+++ b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc
@@ -168,20 +168,12 @@
const ExtensionInstallPrompt::DoneCallback& done_callback,
std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- bool use_tab_modal_dialog = prompt->ShouldUseTabModalDialog();
ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView(
show_params->profile(), show_params->GetParentWebContents(),
done_callback, std::move(prompt));
- if (use_tab_modal_dialog) {
- content::WebContents* parent_web_contents =
- show_params->GetParentWebContents();
- if (parent_web_contents)
- constrained_window::ShowWebModalDialogViews(dialog, parent_web_contents);
- } else {
- constrained_window::CreateBrowserModalDialogViews(
- dialog, show_params->GetParentWindow())
- ->Show();
- }
+ constrained_window::CreateBrowserModalDialogViews(
+ dialog, show_params->GetParentWindow())
+ ->Show();
}
// A custom scrollable view implementation for the dialog.
@@ -437,8 +429,7 @@
}
ui::ModalType ExtensionInstallDialogView::GetModalType() const {
- return prompt_->ShouldUseTabModalDialog() ? ui::MODAL_TYPE_CHILD
- : ui::MODAL_TYPE_WINDOW;
+ return ui::MODAL_TYPE_WINDOW;
}
void ExtensionInstallDialogView::LinkClicked(views::Link* source,
diff --git a/chrome/browser/ui/views/extensions/extension_install_dialog_view_browsertest.cc b/chrome/browser/ui/views/extensions/extension_install_dialog_view_browsertest.cc
index af5870f..ca6fd7b 100644
--- a/chrome/browser/ui/views/extensions/extension_install_dialog_view_browsertest.cc
+++ b/chrome/browser/ui/views/extensions/extension_install_dialog_view_browsertest.cc
@@ -294,7 +294,7 @@
private:
ExtensionInstallPrompt::PromptType type_ =
- ExtensionInstallPrompt::INLINE_INSTALL_PROMPT;
+ ExtensionInstallPrompt::INSTALL_PROMPT;
bool from_webstore_ = false;
PermissionMessages permissions_;
std::vector<base::FilePath> retained_files_;
@@ -330,12 +330,14 @@
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_FromWebstore) {
+ set_type(ExtensionInstallPrompt::WEBSTORE_WIDGET_PROMPT);
set_from_webstore();
ShowAndVerifyUi();
}
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_FromWebstoreWithPermission) {
+ set_type(ExtensionInstallPrompt::WEBSTORE_WIDGET_PROMPT);
set_from_webstore();
AddPermission("Example permission");
ShowAndVerifyUi();
@@ -421,7 +423,7 @@
"Testing with %d ratings, %f average rating. Expected text: '%s'.",
num_ratings, average_rating, expected_text.c_str()));
std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt =
- CreatePrompt(ExtensionInstallPrompt::INLINE_INSTALL_PROMPT);
+ CreatePrompt(ExtensionInstallPrompt::REPAIR_PROMPT);
prompt->SetWebstoreData("1,234", true, average_rating, num_ratings);
ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView(