Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: chrome/browser/extensions/extension_service.cc

Issue 2166513002: Create --disable-extensions-except switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed patch 10 code review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.cc
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 9f425f57445b17dc110c3530babf849ffaea4c11..bebcdcd7f07320a3293ee999021a0b5898613d34 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -15,6 +15,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_tokenizer.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -300,6 +301,7 @@ ExtensionService::ExtensionService(Profile* profile,
bool extensions_enabled,
extensions::OneShotEvent* ready)
: extensions::Blacklist::Observer(blacklist),
+ command_line_(command_line),
profile_(profile),
system_(extensions::ExtensionSystem::Get(profile)),
extension_prefs_(extension_prefs),
@@ -427,7 +429,9 @@ void ExtensionService::Init() {
// LoadAllExtensions() calls OnLoadedInstalledExtensions().
component_loader_->LoadAll();
extensions::InstalledLoader(this).LoadAllExtensions();
-
+ LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
+ if (extensions_enabled_)
+ LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
EnabledReloadableExtensions();
MaybeFinishShutdownDelayed();
SetReadyAndNotifyListeners();
@@ -596,6 +600,26 @@ bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
return true;
}
+void ExtensionService::LoadExtensionsFromCommandLineFlag(
+ const char* switch_name) {
+ if (command_line_->HasSwitch(switch_name)) {
+ base::CommandLine::StringType path_list =
+ command_line_->GetSwitchValueNative(switch_name);
+ base::StringTokenizerT<base::CommandLine::StringType,
+ base::CommandLine::StringType::const_iterator>
+ t(path_list, FILE_PATH_LITERAL(","));
+ while (t.GetNext()) {
+ std::string extension_id;
+ extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine(
+ base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
+ // Extension id is added to whitelist after its extension is loaded
+ // because code is executed asynchronously.
+ if (switch_name == switches::kDisableExtensionsExcept)
+ disable_flag_exempted_extensions_.insert(extension_id);
+ }
+ }
+}
+
void ExtensionService::ReloadExtensionImpl(
// "transient" because the process of reloading may cause the reference
// to become invalid. Instead, use |extension_id|, a copy.
@@ -1422,10 +1446,10 @@ void ExtensionService::AddExtension(const Extension* extension) {
// TODO(jstritar): We may be able to get rid of this branch by overriding the
// default extension state to DISABLED when the --disable-extensions flag
// is set (http://crbug.com/29067).
- if (!extensions_enabled() &&
- !extension->is_theme() &&
+ if (!extensions_enabled() && !extension->is_theme() &&
extension->location() != Manifest::COMPONENT &&
- !Manifest::IsExternalLocation(extension->location())) {
+ !Manifest::IsExternalLocation(extension->location()) &&
+ disable_flag_exempted_extensions_.count(extension->id()) == 0) {
return;
}
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_startup_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698