[Extensions] Fix a crash in ExtensionPrefValueMap
When extensions are disabled with --disable-extensions, ExtensionPrefs
would completely skip initializing the Extension-controlled preferences
(which encompasses the content settings overrides, preferences API, and
chrome settings overrides). This would result in no entry being added
to the ExtensionPrefValueMap for extensions if --disable-extensions was
used. This is generally desirable, since otherwise the settings may
still take effect, even though the extensions were not enabled.
However, some extensions are still loaded with --disable-extensions.
Obviously, this includes component extensions, but this also
(surprisingly) includes external extensions, such as those added by
the windows registry.
The result of this is that if an external extension used an API that
relied on the ExtensionPrefValueMap, such as the chrome settings
overrides, while --disable-extensions was used, there would be no
entry in the value map. Chrome would then crash.
Fix this by having ExtensionPrefs check if the extension will still be
loaded, even if extensions are disabled. If it will, always load the
corresponding extension-controlled preferences.
Add two tests to cover this case: one general unit test to ensure the
extension-controlled prefs are initialized for external extensions
(which will always be loaded), and one end-to-end test with adding an
external extension using the chrome settings overrides API.
Bug: 828295
Change-Id: I0b01f6ed2fd41874f8fa47378f111c0692cb1ea5
Reviewed-on: https://chromium-review.googlesource.com/1013305
Reviewed-by: Karan Bhatia <[email protected]>
Commit-Queue: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#552209}
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index e337f86..49e0117f 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -1200,9 +1200,9 @@
// 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() &&
- extension->location() != Manifest::COMPONENT &&
- !Manifest::IsExternalLocation(extension->location()) &&
+ if (!extensions_enabled_ &&
+ !Manifest::ShouldAlwaysLoadExtension(extension->location(),
+ extension->GetType()) &&
disable_flag_exempted_extensions_.count(extension->id()) == 0) {
return;
}