Commit 311ecdf7 authored by binjin's avatar binjin Committed by Commit bot

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}
parent 5928c2f9
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_install_prompt.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/extensions/webstore_installer.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
...@@ -16,7 +17,6 @@ ...@@ -16,7 +17,6 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/download_item.h" #include "content/public/browser/download_item.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/user_script.h" #include "extensions/common/user_script.h"
...@@ -131,21 +131,11 @@ bool IsExtensionDownload(const DownloadItem& download_item) { ...@@ -131,21 +131,11 @@ bool IsExtensionDownload(const DownloadItem& download_item) {
} }
bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& 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 // TODO(aa): RefererURL is cleared in some cases, for example when going
// between secure and non-secure URLs. It would be better if DownloadItem // between secure and non-secure URLs. It would be better if DownloadItem
// tracked the initiating page explicitly. // tracked the initiating page explicitly.
return url_patterns.MatchesURL(item.GetReferrerUrl()) || return extensions::ExtensionManagementFactory::GetForBrowserContext(profile)
item.GetURL().SchemeIsFile(); ->IsOffstoreInstallAllowed(item.GetURL(), item.GetReferrerUrl());
} }
} // namespace download_crx_util } // namespace download_crx_util
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/pref_names.h" #include "extensions/browser/pref_names.h"
#include "extensions/common/url_pattern.h" #include "extensions/common/url_pattern.h"
#include "url/gurl.h"
namespace extensions { namespace extensions {
...@@ -94,6 +95,23 @@ bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { ...@@ -94,6 +95,23 @@ bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const {
return ReadById(id).installation_mode != INSTALLATION_BLOCKED; 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 ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById(
const ExtensionId& id) const { const ExtensionId& id) const {
DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "extensions/common/manifest.h" #include "extensions/common/manifest.h"
#include "extensions/common/url_pattern_set.h" #include "extensions/common/url_pattern_set.h"
class GURL;
class PrefService; class PrefService;
namespace content { namespace content {
...@@ -117,6 +118,9 @@ class ExtensionManagement : public KeyedService { ...@@ -117,6 +118,9 @@ class ExtensionManagement : public KeyedService {
// Returns if an extension with id |id| is allowed to install or not. // Returns if an extension with id |id| is allowed to install or not.
bool IsInstallationAllowed(const ExtensionId& id) const; 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 // Helper function to read |settings_by_id_| with |id| as key. Returns a
// constant reference to default settings if |id| does not exist. // constant reference to default settings if |id| does not exist.
const IndividualSettings& ReadById(const ExtensionId& id) const; const IndividualSettings& ReadById(const ExtensionId& id) const;
......
...@@ -173,6 +173,7 @@ ExtensionSettingsHandler::ExtensionSettingsHandler() ...@@ -173,6 +173,7 @@ ExtensionSettingsHandler::ExtensionSettingsHandler()
error_console_observer_(this), error_console_observer_(this),
extension_prefs_observer_(this), extension_prefs_observer_(this),
extension_registry_observer_(this), extension_registry_observer_(this),
extension_management_observer_(this),
should_do_verification_check_(false) { should_do_verification_check_(false) {
} }
...@@ -192,6 +193,7 @@ ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, ...@@ -192,6 +193,7 @@ ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
error_console_observer_(this), error_console_observer_(this),
extension_prefs_observer_(this), extension_prefs_observer_(this),
extension_registry_observer_(this), extension_registry_observer_(this),
extension_management_observer_(this),
should_do_verification_check_(false) { should_do_verification_check_(false) {
} }
...@@ -751,6 +753,10 @@ void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( ...@@ -751,6 +753,10 @@ void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged(
MaybeUpdateAfterNotification(); MaybeUpdateAfterNotification();
} }
void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() {
MaybeUpdateAfterNotification();
}
void ExtensionSettingsHandler::ExtensionUninstallAccepted() { void ExtensionSettingsHandler::ExtensionUninstallAccepted() {
DCHECK(!extension_id_prompting_.empty()); DCHECK(!extension_id_prompting_.empty());
...@@ -1265,12 +1271,8 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() { ...@@ -1265,12 +1271,8 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() {
error_console_observer_.Add(ErrorConsole::Get(profile)); error_console_observer_.Add(ErrorConsole::Get(profile));
base::Closure callback = base::Bind( extension_management_observer_.Add(
&ExtensionSettingsHandler::MaybeUpdateAfterNotification, ExtensionManagementFactory::GetForBrowserContext(profile));
AsWeakPtr());
pref_registrar_.Init(profile->GetPrefs());
pref_registrar_.Add(pref_names::kInstallDenyList, callback);
} }
std::vector<ExtensionPage> std::vector<ExtensionPage>
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include <vector> #include <vector>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_change_registrar.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/extensions/error_console/error_console.h" #include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_install_ui.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/extension_uninstall_dialog.h"
#include "chrome/browser/extensions/requirements_checker.h" #include "chrome/browser/extensions/requirements_checker.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
...@@ -71,6 +71,7 @@ class ExtensionSettingsHandler ...@@ -71,6 +71,7 @@ class ExtensionSettingsHandler
public content::WebContentsObserver, public content::WebContentsObserver,
public ErrorConsole::Observer, public ErrorConsole::Observer,
public ExtensionInstallPrompt::Delegate, public ExtensionInstallPrompt::Delegate,
public ExtensionManagement::Observer,
public ExtensionPrefsObserver, public ExtensionPrefsObserver,
public ExtensionRegistryObserver, public ExtensionRegistryObserver,
public ExtensionUninstallDialog::Delegate, public ExtensionUninstallDialog::Delegate,
...@@ -134,6 +135,9 @@ class ExtensionSettingsHandler ...@@ -134,6 +135,9 @@ class ExtensionSettingsHandler
virtual void OnExtensionDisableReasonsChanged(const std::string& extension_id, virtual void OnExtensionDisableReasonsChanged(const std::string& extension_id,
int disable_reasons) OVERRIDE; int disable_reasons) OVERRIDE;
// ExtensionManagement::Observer implementation.
virtual void OnExtensionManagementSettingsChanged() OVERRIDE;
// ExtensionUninstallDialog::Delegate implementation, used for receiving // ExtensionUninstallDialog::Delegate implementation, used for receiving
// notification about uninstall confirmation dialog selections. // notification about uninstall confirmation dialog selections.
virtual void ExtensionUninstallAccepted() OVERRIDE; virtual void ExtensionUninstallAccepted() OVERRIDE;
...@@ -276,8 +280,6 @@ class ExtensionSettingsHandler ...@@ -276,8 +280,6 @@ class ExtensionSettingsHandler
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
PrefChangeRegistrar pref_registrar_;
// This will not be empty when a requirements check is in progress. Doing // 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 // another Check() before the previous one is complete will cause the first
// one to abort. // one to abort.
...@@ -300,6 +302,9 @@ class ExtensionSettingsHandler ...@@ -300,6 +302,9 @@ class ExtensionSettingsHandler
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_; extension_registry_observer_;
ScopedObserver<ExtensionManagement, ExtensionManagement::Observer>
extension_management_observer_;
// Whether we found any DISABLE_NOT_VERIFIED extensions and want to kick off // Whether we found any DISABLE_NOT_VERIFIED extensions and want to kick off
// a verification check to try and rescue them. // a verification check to try and rescue them.
bool should_do_verification_check_; bool should_do_verification_check_;
......
...@@ -1813,27 +1813,6 @@ bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { ...@@ -1813,27 +1813,6 @@ bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) {
return has_incognito_pref_value; 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 base::DictionaryValue* ExtensionPrefs::GetGeometryCache(
const std::string& extension_id) const { const std::string& extension_id) const {
const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id); const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
......
...@@ -529,10 +529,6 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService { ...@@ -529,10 +529,6 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
// The underlying AppSorting. // The underlying AppSorting.
AppSorting* app_sorting() const { return app_sorting_.get(); } 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 // Schedules garbage collection of an extension's on-disk data on the next
// start of this ExtensionService. Applies only to extensions with isolated // start of this ExtensionService. Applies only to extensions with isolated
// storage. // storage.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment