summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbinjin <binjin@chromium.org>2014-09-12 15:56:52 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-12 22:59:52 +0000
commit311ecdf7e9ba01b0a8ccbd1488e312e13cf398c5 (patch)
treef837785a4dd050b1924c5cc49342f25897eb30a1
parent5928c2f978a43488a2f45fe7da1d91dfdba1d593 (diff)
downloadchromium_src-311ecdf7e9ba01b0a8ccbd1488e312e13cf398c5.zip
chromium_src-311ecdf7e9ba01b0a8ccbd1488e312e13cf398c5.tar.gz
chromium_src-311ecdf7e9ba01b0a8ccbd1488e312e13cf398c5.tar.bz2
Deprecate direct use of legacy extension management preference
Use ExtensionManagement instead. BUG=177351 Review URL: https://codereview.chromium.org/555323002 Cr-Commit-Position: refs/heads/master@{#294688}
-rw-r--r--chrome/browser/download/download_crx_util.cc16
-rw-r--r--chrome/browser/extensions/extension_management.cc18
-rw-r--r--chrome/browser/extensions/extension_management.h4
-rw-r--r--chrome/browser/ui/webui/extensions/extension_settings_handler.cc14
-rw-r--r--chrome/browser/ui/webui/extensions/extension_settings_handler.h11
-rw-r--r--extensions/browser/extension_prefs.cc21
-rw-r--r--extensions/browser/extension_prefs.h4
7 files changed, 41 insertions, 47 deletions
diff --git a/chrome/browser/download/download_crx_util.cc b/chrome/browser/download/download_crx_util.cc
index 441c82b..28ba4ab 100644
--- a/chrome/browser/download/download_crx_util.cc
+++ b/chrome/browser/download/download_crx_util.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
+#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/webstore_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
@@ -16,7 +17,6 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/notification_service.h"
-#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/user_script.h"
@@ -131,21 +131,11 @@ bool IsExtensionDownload(const DownloadItem& download_item) {
}
bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) {
- extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile);
- CHECK(prefs);
-
- extensions::URLPatternSet url_patterns = prefs->GetAllowedInstallSites();
-
- if (!url_patterns.MatchesURL(item.GetURL()))
- return false;
-
- // The referrer URL must also be whitelisted, unless the URL has the file
- // scheme (there's no referrer for those URLs).
// TODO(aa): RefererURL is cleared in some cases, for example when going
// between secure and non-secure URLs. It would be better if DownloadItem
// tracked the initiating page explicitly.
- return url_patterns.MatchesURL(item.GetReferrerUrl()) ||
- item.GetURL().SchemeIsFile();
+ return extensions::ExtensionManagementFactory::GetForBrowserContext(profile)
+ ->IsOffstoreInstallAllowed(item.GetURL(), item.GetReferrerUrl());
}
} // namespace download_crx_util
diff --git a/chrome/browser/extensions/extension_management.cc b/chrome/browser/extensions/extension_management.cc
index 15caf92..186e4b4 100644
--- a/chrome/browser/extensions/extension_management.cc
+++ b/chrome/browser/extensions/extension_management.cc
@@ -17,6 +17,7 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/url_pattern.h"
+#include "url/gurl.h"
namespace extensions {
@@ -94,6 +95,23 @@ bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const {
return ReadById(id).installation_mode != INSTALLATION_BLOCKED;
}
+bool ExtensionManagement::IsOffstoreInstallAllowed(const GURL& url,
+ const GURL& referrer_url) {
+ // No allowed install sites specified, disallow by default.
+ if (!global_settings_.has_restricted_install_sources)
+ return false;
+
+ const extensions::URLPatternSet& url_patterns =
+ global_settings_.install_sources;
+
+ if (!url_patterns.MatchesURL(url))
+ return false;
+
+ // The referrer URL must also be whitelisted, unless the URL has the file
+ // scheme (there's no referrer for those URLs).
+ return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url);
+}
+
const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById(
const ExtensionId& id) const {
DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id;
diff --git a/chrome/browser/extensions/extension_management.h b/chrome/browser/extensions/extension_management.h
index 4aab9dd..1bfe39b 100644
--- a/chrome/browser/extensions/extension_management.h
+++ b/chrome/browser/extensions/extension_management.h
@@ -22,6 +22,7 @@
#include "extensions/common/manifest.h"
#include "extensions/common/url_pattern_set.h"
+class GURL;
class PrefService;
namespace content {
@@ -117,6 +118,9 @@ class ExtensionManagement : public KeyedService {
// Returns if an extension with id |id| is allowed to install or not.
bool IsInstallationAllowed(const ExtensionId& id) const;
+ // Returns true if an extension download should be allowed to proceed.
+ bool IsOffstoreInstallAllowed(const GURL& url, const GURL& referrer_url);
+
// Helper function to read |settings_by_id_| with |id| as key. Returns a
// constant reference to default settings if |id| does not exist.
const IndividualSettings& ReadById(const ExtensionId& id) const;
diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
index 34e61c4..20e6b3f 100644
--- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
+++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc
@@ -173,6 +173,7 @@ ExtensionSettingsHandler::ExtensionSettingsHandler()
error_console_observer_(this),
extension_prefs_observer_(this),
extension_registry_observer_(this),
+ extension_management_observer_(this),
should_do_verification_check_(false) {
}
@@ -192,6 +193,7 @@ ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
error_console_observer_(this),
extension_prefs_observer_(this),
extension_registry_observer_(this),
+ extension_management_observer_(this),
should_do_verification_check_(false) {
}
@@ -751,6 +753,10 @@ void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged(
MaybeUpdateAfterNotification();
}
+void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() {
+ MaybeUpdateAfterNotification();
+}
+
void ExtensionSettingsHandler::ExtensionUninstallAccepted() {
DCHECK(!extension_id_prompting_.empty());
@@ -1265,12 +1271,8 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() {
error_console_observer_.Add(ErrorConsole::Get(profile));
- base::Closure callback = base::Bind(
- &ExtensionSettingsHandler::MaybeUpdateAfterNotification,
- AsWeakPtr());
-
- pref_registrar_.Init(profile->GetPrefs());
- pref_registrar_.Add(pref_names::kInstallDenyList, callback);
+ extension_management_observer_.Add(
+ ExtensionManagementFactory::GetForBrowserContext(profile));
}
std::vector<ExtensionPage>
diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.h b/chrome/browser/ui/webui/extensions/extension_settings_handler.h
index 7cca3a3..1218e08 100644
--- a/chrome/browser/ui/webui/extensions/extension_settings_handler.h
+++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.h
@@ -10,11 +10,11 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
-#include "base/prefs/pref_change_registrar.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_install_ui.h"
+#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/extensions/requirements_checker.h"
#include "content/public/browser/navigation_controller.h"
@@ -71,6 +71,7 @@ class ExtensionSettingsHandler
public content::WebContentsObserver,
public ErrorConsole::Observer,
public ExtensionInstallPrompt::Delegate,
+ public ExtensionManagement::Observer,
public ExtensionPrefsObserver,
public ExtensionRegistryObserver,
public ExtensionUninstallDialog::Delegate,
@@ -134,6 +135,9 @@ class ExtensionSettingsHandler
virtual void OnExtensionDisableReasonsChanged(const std::string& extension_id,
int disable_reasons) OVERRIDE;
+ // ExtensionManagement::Observer implementation.
+ virtual void OnExtensionManagementSettingsChanged() OVERRIDE;
+
// ExtensionUninstallDialog::Delegate implementation, used for receiving
// notification about uninstall confirmation dialog selections.
virtual void ExtensionUninstallAccepted() OVERRIDE;
@@ -276,8 +280,6 @@ class ExtensionSettingsHandler
content::NotificationRegistrar registrar_;
- PrefChangeRegistrar pref_registrar_;
-
// This will not be empty when a requirements check is in progress. Doing
// another Check() before the previous one is complete will cause the first
// one to abort.
@@ -300,6 +302,9 @@ class ExtensionSettingsHandler
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
+ ScopedObserver<ExtensionManagement, ExtensionManagement::Observer>
+ extension_management_observer_;
+
// Whether we found any DISABLE_NOT_VERIFIED extensions and want to kick off
// a verification check to try and rescue them.
bool should_do_verification_check_;
diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
index 3cf4829..e0cd673 100644
--- a/extensions/browser/extension_prefs.cc
+++ b/extensions/browser/extension_prefs.cc
@@ -1813,27 +1813,6 @@ bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) {
return has_incognito_pref_value;
}
-URLPatternSet ExtensionPrefs::GetAllowedInstallSites() {
- URLPatternSet result;
- const base::ListValue* list =
- prefs_->GetList(pref_names::kAllowedInstallSites);
- CHECK(list);
-
- for (size_t i = 0; i < list->GetSize(); ++i) {
- std::string entry_string;
- URLPattern entry(URLPattern::SCHEME_ALL);
- if (!list->GetString(i, &entry_string) ||
- entry.Parse(entry_string) != URLPattern::PARSE_SUCCESS) {
- LOG(ERROR) << "Invalid value for preference: "
- << pref_names::kAllowedInstallSites << "." << i;
- continue;
- }
- result.AddPattern(entry);
- }
-
- return result;
-}
-
const base::DictionaryValue* ExtensionPrefs::GetGeometryCache(
const std::string& extension_id) const {
const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
diff --git a/extensions/browser/extension_prefs.h b/extensions/browser/extension_prefs.h
index 4b95e55..a322e8a 100644
--- a/extensions/browser/extension_prefs.h
+++ b/extensions/browser/extension_prefs.h
@@ -529,10 +529,6 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
// The underlying AppSorting.
AppSorting* app_sorting() const { return app_sorting_.get(); }
- // Describes the URLs that are able to install extensions. See
- // pref_names::kAllowedInstallSites for more information.
- URLPatternSet GetAllowedInstallSites();
-
// Schedules garbage collection of an extension's on-disk data on the next
// start of this ExtensionService. Applies only to extensions with isolated
// storage.