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

@@ -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