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

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: Fixed ExtensionServiceTest.ExternalUninstall test failing 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..98a4fa6b0b583e8609a769cf8a45bb589fad16da 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 (switch_name == switches::kDisableExtensionsExcept) {
+ disable_flag_exempted_extensions_.insert(extension_id);
+ }
+ }
+ }
+}
+
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);
Devlin 2016/08/29 20:53:40 nitty nit: Can we put this directly above the bloc
catmullings 2016/08/29 22:28:01 Done.
// LoadAllExtensions() calls OnLoadedInstalledExtensions().
component_loader_->LoadAll();
extensions::InstalledLoader(this).LoadAllExtensions();
-
+ if (extensions_enabled_) {
+ 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()) &&
+ disable_flag_exempted_extensions_.count(extension->id()) == 0) {
return;
}

Powered by Google App Engine
This is Rietveld 408576698