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

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: Adjusted path to test extensions s.t. fixes trybot failings 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 53de0608842942797e7a0e7de7f927b1a66a54b5..0caa43d228c6df87eef252a364f18bc5e2123746 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),
@@ -416,6 +418,25 @@ const Extension* ExtensionService::GetExtensionById(
return registry_->GetExtensionById(id, include_mask);
}
+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*/);
+ if (std::strcmp(switch_name, switches::kDisableExtensionsExcept) == 0) {
Devlin 2016/08/10 19:22:31 Any reason to not compare directly?
catmullings 2016/08/29 20:42:27 Done.
+ AddExtensionToExemptedFromDisableFlag(extension_id);
Devlin 2016/08/10 19:22:31 We should probably add it to the whitelist before
+ }
+ }
+ }
+}
+
void ExtensionService::Init() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TRACE_EVENT0("browser,startup", "ExtensionService::Init");
@@ -424,10 +445,13 @@ void ExtensionService::Init() {
DCHECK(!is_ready()); // Can't redo init.
DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
+ LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
// LoadAllExtensions() calls OnLoadedInstalledExtensions().
component_loader_->LoadAll();
- extensions::InstalledLoader(this).LoadAllExtensions();
-
+ if (extensions_enabled_) {
+ extensions::InstalledLoader(this).LoadAllExtensions();
+ LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
+ }
EnabledReloadableExtensions();
MaybeFinishShutdownDelayed();
SetReadyAndNotifyListeners();
@@ -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()) &&
+ !IsExtensionExemptedFromDisableFlag(extension->id())) {
return;
}

Powered by Google App Engine
This is Rietveld 408576698