alloy: Fix crashes when extensions are disabled (fixes issue #3430)

This commit is contained in:
Marshall Greenblatt
2023-01-05 13:55:00 -05:00
parent 05104b07e0
commit 7209750d46
5 changed files with 114 additions and 161 deletions

View File

@ -380,11 +380,14 @@ patches = [
'name': 'build',
},
{
# Changes necessary to support for chrome extensions. Add a new
# Changes necessary to support chrome extensions. Add a new
# ExtensionHost constructor that allows CEF to create the WebContents.
# https://bitbucket.org/chromiumembedded/cef/issues/1947
#
# Don't initialize PrerenderContents object in StreamsPrivateAPI.
#
# Return nullptr from ExtensionsClient::Get and ExtensionRegistry::Get
# when extensions are disabled.
'name': 'extensions_1947',
},
{

View File

@ -1,129 +1,46 @@
diff --git chrome/browser/plugins/plugin_info_host_impl.cc chrome/browser/plugins/plugin_info_host_impl.cc
index 7ceb1d7b854d9..5efcb8c09058c 100644
index 7ceb1d7b854d9..721026a5a4be1 100644
--- chrome/browser/plugins/plugin_info_host_impl.cc
+++ chrome/browser/plugins/plugin_info_host_impl.cc
@@ -16,6 +16,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
+#include "cef/libcef/features/runtime.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
@@ -50,6 +51,10 @@
#include "url/gurl.h"
#include "url/origin.h"
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/common/extensions/extensions_util.h"
+#endif
+
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "components/guest_view/browser/guest_view_base.h"
#include "extensions/browser/extension_registry.h"
@@ -135,6 +140,9 @@ bool IsPluginLoadingAccessibleResourceInWebView(
@@ -135,6 +135,10 @@ bool IsPluginLoadingAccessibleResourceInWebView(
extensions::ExtensionRegistry* extension_registry,
int process_id,
const GURL& resource) {
+ // May be nullptr if using CEF Alloy with extensions disabled.
+ if (!extension_registry)
+ return false;
+
extensions::WebViewRendererState* renderer_state =
extensions::WebViewRendererState::GetInstance();
std::string partition_id;
@@ -163,14 +171,18 @@ bool IsPluginLoadingAccessibleResourceInWebView(
PluginInfoHostImpl::Context::Context(int render_process_id, Profile* profile)
: render_process_id_(render_process_id),
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- extension_registry_(extensions::ExtensionRegistry::Get(profile)),
-#endif
host_content_settings_map_(
HostContentSettingsMapFactory::GetForProfile(profile)),
plugin_prefs_(PluginPrefs::GetForProfile(profile)) {
allow_outdated_plugins_.Init(prefs::kPluginsAllowOutdated,
profile->GetPrefs());
+
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+#if BUILDFLAG(ENABLE_CEF)
+ if (!cef::IsAlloyRuntimeEnabled() || extensions::ExtensionsEnabled())
+#endif
+ extension_registry_ = extensions::ExtensionRegistry::Get(profile);
+#endif
}
PluginInfoHostImpl::Context::~Context() {}
diff --git chrome/browser/plugins/plugin_utils.cc chrome/browser/plugins/plugin_utils.cc
index 8b3f569882aeb..ae0c4aa9a0514 100644
index 8b3f569882aeb..afc8007a6228b 100644
--- chrome/browser/plugins/plugin_utils.cc
+++ chrome/browser/plugins/plugin_utils.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/plugins/plugin_utils.h"
#include "base/values.h"
+#include "cef/libcef/features/runtime.h"
#include "chrome/browser/profiles/profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_types.h"
@@ -14,6 +15,10 @@
#include "url/gurl.h"
#include "url/origin.h"
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/common/extensions/extensions_util.h"
+#endif
+
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/common/pref_names.h"
@@ -69,6 +74,12 @@ base::flat_map<std::string, std::string>
PluginUtils::GetMimeTypeToExtensionIdMap(
@@ -70,6 +70,13 @@ PluginUtils::GetMimeTypeToExtensionIdMap(
content::BrowserContext* browser_context) {
base::flat_map<std::string, std::string> mime_type_to_extension_id_map;
+
+#if BUILDFLAG(ENABLE_CEF)
+ if (cef::IsAlloyRuntimeEnabled() && !extensions::ExtensionsEnabled())
+ return mime_type_to_extension_id_map;
+#endif
+
#if BUILDFLAG(ENABLE_EXTENSIONS)
+ // May be nullptr if using CEF Alloy with extensions disabled.
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser_context);
+ if (!registry) {
+ return mime_type_to_extension_id_map;
+ }
+
Profile* profile = Profile::FromBrowserContext(browser_context);
if (extensions::ChromeContentBrowserClientExtensionsPart::
diff --git chrome/common/google_url_loader_throttle.cc chrome/common/google_url_loader_throttle.cc
index a29a2739af3c8..0feb1a87cef64 100644
--- chrome/common/google_url_loader_throttle.cc
+++ chrome/common/google_url_loader_throttle.cc
@@ -7,6 +7,7 @@
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "build/build_config.h"
+#include "cef/libcef/features/runtime.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/net/safe_search_util.h"
#include "components/google/core/common/google_util.h"
@@ -19,6 +20,10 @@
#include "ui/base/device_form_factor.h"
#endif
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/common/extensions/extensions_util.h"
+#endif
+
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/extension_urls.h"
#endif
@@ -158,6 +163,11 @@ void GoogleURLLoaderThrottle::WillProcessResponse(
const GURL& response_url,
network::mojom::URLResponseHead* response_head,
bool* defer) {
+#if BUILDFLAG(ENABLE_CEF)
+ if (cef::IsAlloyRuntimeEnabled() && !extensions::ExtensionsEnabled())
+ return;
+#endif
+
// Built-in additional protection for the chrome web store origin by ensuring
// that the X-Frame-Options protection mechanism is set to either DENY or
// SAMEORIGIN.
AreExtensionsDisabledForProfile(profile)) {
@@ -80,9 +87,6 @@ PluginUtils::GetMimeTypeToExtensionIdMap(
MimeTypesHandler::GetMIMETypeAllowlist();
// Go through the allowed extensions and try to use them to intercept
// the URL request.
- extensions::ExtensionRegistry* registry =
- extensions::ExtensionRegistry::Get(browser_context);
- DCHECK(registry);
for (const std::string& extension_id : allowlist) {
const extensions::Extension* extension =
registry->enabled_extensions().GetByID(extension_id);
diff --git chrome/renderer/chrome_content_renderer_client.cc chrome/renderer/chrome_content_renderer_client.cc
index 3d08b706ec4a0..7f4a0398e51f9 100644
--- chrome/renderer/chrome_content_renderer_client.cc

View File

@ -160,6 +160,37 @@ index 07be432f365b9..d3800886a5b5c 100644
// A pointer to the current or speculative main frame in `host_contents_`. We
// can't access this frame through the `host_contents_` directly as it does
diff --git extensions/browser/extension_registry.cc extensions/browser/extension_registry.cc
index 10d751cceab73..128af05925e07 100644
--- extensions/browser/extension_registry.cc
+++ extensions/browser/extension_registry.cc
@@ -6,9 +6,14 @@
#include "base/observer_list.h"
#include "base/strings/string_util.h"
+#include "cef/libcef/features/runtime.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_registry_observer.h"
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/common/extensions/extensions_util.h"
+#endif
+
namespace extensions {
ExtensionRegistry::ExtensionRegistry(content::BrowserContext* browser_context)
@@ -17,6 +22,11 @@ ExtensionRegistry::~ExtensionRegistry() {}
// static
ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) {
+#if BUILDFLAG(ENABLE_CEF)
+ if (cef::IsAlloyRuntimeEnabled() && !extensions::ExtensionsEnabled()) {
+ return nullptr;
+ }
+#endif
return ExtensionRegistryFactory::GetForBrowserContext(context);
}
diff --git extensions/browser/extensions_browser_client.h extensions/browser/extensions_browser_client.h
index 028d6b1fec3a0..0829a24eb2879 100644
--- extensions/browser/extensions_browser_client.h
@ -218,3 +249,16 @@ index aeee5f5a516c4..ca2079ba1b447 100644
host->SetCloseHandler(
base::BindOnce(&ProcessManager::HandleCloseExtensionHost,
weak_ptr_factory_.GetWeakPtr()));
diff --git extensions/common/extensions_client.cc extensions/common/extensions_client.cc
index 53ad0736cfbdf..c252591fa646d 100644
--- extensions/common/extensions_client.cc
+++ extensions/common/extensions_client.cc
@@ -23,7 +23,7 @@ ExtensionsClient* g_client = nullptr;
} // namespace
ExtensionsClient* ExtensionsClient::Get() {
- DCHECK(g_client);
+ // May be nullptr if using CEF Alloy with extensions disabled.
return g_client;
}

View File

@ -1,5 +1,5 @@
diff --git chrome/browser/net/profile_network_context_service.cc chrome/browser/net/profile_network_context_service.cc
index 8221b46c59df3..56f9d584b3a50 100644
index 8221b46c59df3..eca1b2040dd4c 100644
--- chrome/browser/net/profile_network_context_service.cc
+++ chrome/browser/net/profile_network_context_service.cc
@@ -22,6 +22,7 @@
@ -10,7 +10,18 @@ index 8221b46c59df3..56f9d584b3a50 100644
#include "chrome/browser/browser_features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_content_browser_client.h"
@@ -796,7 +797,19 @@ void ProfileNetworkContextService::ConfigureNetworkContextParamsInternal(
@@ -304,7 +305,9 @@ ProfileNetworkContextService::ProfileNetworkContextService(Profile* profile)
base::Unretained(this)));
#if BUILDFLAG(ENABLE_EXTENSIONS)
- registry_observation_.Observe(extensions::ExtensionRegistry::Get(profile_));
+ if (auto extension_registry = extensions::ExtensionRegistry::Get(profile_)) {
+ registry_observation_.Observe(extension_registry);
+ }
#endif
}
@@ -796,7 +799,19 @@ void ProfileNetworkContextService::ConfigureNetworkContextParamsInternal(
// Configure on-disk storage for non-OTR profiles. OTR profiles just use
// default behavior (in memory storage, default sizes).
@ -31,7 +42,7 @@ index 8221b46c59df3..56f9d584b3a50 100644
PrefService* local_state = g_browser_process->local_state();
// Configure the HTTP cache path and size.
base::FilePath base_cache_path;
@@ -809,7 +822,9 @@ void ProfileNetworkContextService::ConfigureNetworkContextParamsInternal(
@@ -809,7 +824,9 @@ void ProfileNetworkContextService::ConfigureNetworkContextParamsInternal(
base_cache_path.Append(chrome::kCacheDirname);
network_context_params->http_cache_max_size =
local_state->GetInteger(prefs::kDiskCacheSize);

View File

@ -1,16 +1,8 @@
diff --git chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc
index 0b3085d90332f..7b84c740aafc7 100644
index 0b3085d90332f..4fe995a31d4e8 100644
--- chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc
+++ chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc
@@ -10,6 +10,7 @@
#include <vector>
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
@@ -19,16 +20,19 @@
@@ -19,10 +19,12 @@
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "base/task/thread_pool.h"
@ -23,14 +15,7 @@ index 0b3085d90332f..7b84c740aafc7 100644
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/browser/google/google_brand.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/common/channel_info.h"
+#include "chrome/common/chrome_switches.h"
#include "chromeos/ash/components/dbus/spaced/spaced_client.h"
#include "components/feedback/system_logs/system_logs_source.h"
#include "components/prefs/pref_service.h"
@@ -398,7 +402,11 @@ void ChromeInternalLogSource::Fetch(SysLogsSourceCallback callback) {
@@ -398,7 +400,11 @@ void ChromeInternalLogSource::Fetch(SysLogsSourceCallback callback) {
response->emplace(kOsVersionTag, os_version);
#endif
@ -43,20 +28,20 @@ index 0b3085d90332f..7b84c740aafc7 100644
PopulateExtensionInfoLogs(response.get());
PopulatePowerApiLogs(response.get());
#if BUILDFLAG(IS_WIN)
@@ -472,6 +480,12 @@ void ChromeInternalLogSource::PopulateExtensionInfoLogs(
@@ -472,8 +478,12 @@ void ChromeInternalLogSource::PopulateExtensionInfoLogs(
if (!profile)
return;
+ // CEF should avoid accessing ExtensionRegistry when extensions are disabled.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableExtensions)) {
+ return;
+ }
+
+ // May be nullptr if using CEF Alloy with extensions disabled.
extensions::ExtensionRegistry* extension_registry =
extensions::ExtensionRegistry::Get(profile);
+ if (!extension_registry)
+ return;
+
std::string extensions_list;
@@ -577,6 +591,8 @@ void ChromeInternalLogSource::PopulateOnboardingTime(
for (const scoped_refptr<const extensions::Extension>& extension :
extension_registry->enabled_extensions()) {
@@ -577,6 +587,8 @@ void ChromeInternalLogSource::PopulateOnboardingTime(
#if BUILDFLAG(IS_WIN)
void ChromeInternalLogSource::PopulateUsbKeyboardDetected(
SystemLogsResponse* response) {
@ -66,33 +51,26 @@ index 0b3085d90332f..7b84c740aafc7 100644
bool result =
base::win::IsKeyboardPresentOnSlate(ui::GetHiddenWindow(), &reason);
diff --git chrome/browser/memory_details.cc chrome/browser/memory_details.cc
index d071ef696f441..441514f66150c 100644
index d071ef696f441..aba280943251a 100644
--- chrome/browser/memory_details.cc
+++ chrome/browser/memory_details.cc
@@ -8,6 +8,7 @@
#include <set>
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/containers/adapters.h"
#include "base/containers/cxx20_erase.h"
#include "base/file_version_info.h"
@@ -18,6 +19,7 @@
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
#include "components/nacl/common/nacl_process_type.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
@@ -291,7 +293,9 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
// Determine if this is an extension process.
bool process_is_for_extensions = false;
const extensions::ExtensionSet* extension_set = nullptr;
- if (render_process_host) {
+ if (render_process_host &&
+ !base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableExtensions)) {
@@ -294,8 +294,11 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
if (render_process_host) {
content::BrowserContext* context =
render_process_host->GetBrowserContext();
+
+ // May be nullptr if using CEF Alloy with extensions disabled.
extensions::ExtensionRegistry* extension_registry =
extensions::ExtensionRegistry::Get(context);
+ if (extension_registry) {
extension_set = &extension_registry->enabled_extensions();
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(context);
@@ -311,6 +314,7 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
break;
}
}
+ }
}
#endif