fix: failing build with enable_electron_extensions=false (#40032)

* fix: ENABLE_EXTENSIONS -> ENABLE_ELECTRON_EXTENSIONS

* fix: extension guard fixes

* chore: fix linker errors
This commit is contained in:
Shelley Vohr 2023-10-04 10:40:01 +02:00 committed by GitHub
parent 713d8c4167
commit b0590b6ee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 39 deletions

View file

@ -342,6 +342,34 @@ static_library("chrome") {
"//components/pdf/renderer", "//components/pdf/renderer",
] ]
} }
} else {
# These are required by the webRequest module.
sources += [
"//extensions/browser/api/declarative_net_request/request_action.cc",
"//extensions/browser/api/declarative_net_request/request_action.h",
"//extensions/browser/api/web_request/form_data_parser.cc",
"//extensions/browser/api/web_request/form_data_parser.h",
"//extensions/browser/api/web_request/upload_data_presenter.cc",
"//extensions/browser/api/web_request/upload_data_presenter.h",
"//extensions/browser/api/web_request/web_request_api_constants.cc",
"//extensions/browser/api/web_request/web_request_api_constants.h",
"//extensions/browser/api/web_request/web_request_info.cc",
"//extensions/browser/api/web_request/web_request_info.h",
"//extensions/browser/api/web_request/web_request_resource_type.cc",
"//extensions/browser/api/web_request/web_request_resource_type.h",
"//extensions/browser/extension_api_frame_id_map.cc",
"//extensions/browser/extension_api_frame_id_map.h",
"//extensions/browser/extension_navigation_ui_data.cc",
"//extensions/browser/extension_navigation_ui_data.h",
"//extensions/browser/extensions_browser_client.cc",
"//extensions/browser/extensions_browser_client.h",
"//extensions/browser/guest_view/web_view/web_view_renderer_state.cc",
"//extensions/browser/guest_view/web_view/web_view_renderer_state.h",
]
public_deps += [
"//extensions/browser/api/declarative_net_request/flat:extension_ruleset",
]
} }
if (!is_mas_build) { if (!is_mas_build) {

View file

@ -57,7 +57,7 @@
#include "crypto/crypto_buildflags.h" #include "crypto/crypto_buildflags.h"
#include "electron/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "electron/shell/common/api/api.mojom.h" #include "electron/shell/common/api/api.mojom.h"
#include "extensions/browser/api/messaging/messaging_api_message_filter.h" #include "extensions/browser/extension_navigation_ui_data.h"
#include "mojo/public/cpp/bindings/binder_map.h" #include "mojo/public/cpp/bindings/binder_map.h"
#include "net/ssl/ssl_cert_request_info.h" #include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_private_key.h" #include "net/ssl/ssl_private_key.h"
@ -114,6 +114,7 @@
#include "shell/common/options_switches.h" #include "shell/common/options_switches.h"
#include "shell/common/platform_util.h" #include "shell/common/platform_util.h"
#include "shell/common/thread_restrictions.h" #include "shell/common/thread_restrictions.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h" #include "third_party/blink/public/common/loader/url_loader_throttle.h"
#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h" #include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
#include "third_party/blink/public/common/tokens/tokens.h" #include "third_party/blink/public/common/tokens/tokens.h"
@ -147,6 +148,7 @@
#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/file_url_loader.h" #include "content/public/browser/file_url_loader.h"
#include "content/public/browser/web_ui_url_loader_factory.h" #include "content/public/browser/web_ui_url_loader_factory.h"
#include "extensions/browser/api/messaging/messaging_api_message_filter.h"
#include "extensions/browser/api/mime_handler_private/mime_handler_private.h" #include "extensions/browser/api/mime_handler_private/mime_handler_private.h"
#include "extensions/browser/api/web_request/web_request_api.h" #include "extensions/browser/api/web_request/web_request_api.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
@ -154,7 +156,6 @@
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_message_filter.h" #include "extensions/browser/extension_message_filter.h"
#include "extensions/browser/extension_navigation_throttle.h" #include "extensions/browser/extension_navigation_throttle.h"
#include "extensions/browser/extension_navigation_ui_data.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_protocols.h" #include "extensions/browser/extension_protocols.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
@ -172,7 +173,6 @@
#include "shell/browser/extensions/electron_extension_message_filter.h" #include "shell/browser/extensions/electron_extension_message_filter.h"
#include "shell/browser/extensions/electron_extension_system.h" #include "shell/browser/extensions/electron_extension_system.h"
#include "shell/browser/extensions/electron_extension_web_contents_observer.h" #include "shell/browser/extensions/electron_extension_web_contents_observer.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#endif #endif
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
@ -1220,12 +1220,12 @@ void ElectronBrowserClient::
protocol_registry->RegisterURLLoaderFactories(factories, protocol_registry->RegisterURLLoaderFactories(factories,
false /* allow_file_access */); false /* allow_file_access */);
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
factories->emplace( factories->emplace(
extensions::kExtensionScheme, extensions::kExtensionScheme,
extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(
browser_context)); browser_context));
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
} }
bool ElectronBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( bool ElectronBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
@ -1413,9 +1413,10 @@ void ElectronBrowserClient::OverrideURLLoaderFactoryParams(
factory_params->disable_web_security = true; factory_params->disable_web_security = true;
} }
} }
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
extensions::URLLoaderFactoryManager::OverrideURLLoaderFactoryParams( extensions::URLLoaderFactoryManager::OverrideURLLoaderFactoryParams(
browser_context, origin, is_for_isolated_world, factory_params); browser_context, origin, is_for_isolated_world, factory_params);
#endif
} }
void ElectronBrowserClient:: void ElectronBrowserClient::
@ -1473,7 +1474,7 @@ void ElectronBrowserClient::
}, },
&render_frame_host)); &render_frame_host));
#endif #endif
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
associated_registry.AddInterface<extensions::mojom::LocalFrameHost>( associated_registry.AddInterface<extensions::mojom::LocalFrameHost>(
base::BindRepeating( base::BindRepeating(
[](content::RenderFrameHost* render_frame_host, [](content::RenderFrameHost* render_frame_host,

View file

@ -11,6 +11,7 @@
#include "base/containers/contains.h" #include "base/containers/contains.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "electron/buildflags/buildflags.h"
#include "services/device/public/cpp/hid/hid_switches.h" #include "services/device/public/cpp/hid/hid_switches.h"
#include "shell/browser/electron_permission_manager.h" #include "shell/browser/electron_permission_manager.h"
#include "shell/browser/hid/hid_chooser_context.h" #include "shell/browser/hid/hid_chooser_context.h"
@ -19,9 +20,9 @@
#include "shell/browser/web_contents_permission_helper.h" #include "shell/browser/web_contents_permission_helper.h"
#include "third_party/blink/public/common/permissions/permission_utils.h" #include "third_party/blink/public/common/permissions/permission_utils.h"
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
namespace { namespace {
@ -128,14 +129,14 @@ bool ElectronHidDelegate::IsFidoAllowedForOrigin(
bool ElectronHidDelegate::IsServiceWorkerAllowedForOrigin( bool ElectronHidDelegate::IsServiceWorkerAllowedForOrigin(
const url::Origin& origin) { const url::Origin& origin) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// WebHID is only available on extension service workers with feature flag // WebHID is only available on extension service workers with feature flag
// enabled for now. // enabled for now.
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
features::kEnableWebHidOnExtensionServiceWorker) && features::kEnableWebHidOnExtensionServiceWorker) &&
origin.scheme() == extensions::kExtensionScheme) origin.scheme() == extensions::kExtensionScheme)
return true; return true;
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
return false; return false;
} }

View file

@ -9,11 +9,11 @@
#include "base/containers/contains.h" #include "base/containers/contains.h"
#include "base/values.h" #include "base/values.h"
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "extensions/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h" #include "extensions/browser/extension_util.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
@ -36,7 +36,7 @@ base::flat_map<std::string, std::string>
PluginUtils::GetMimeTypeToExtensionIdMap( PluginUtils::GetMimeTypeToExtensionIdMap(
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
base::flat_map<std::string, std::string> mime_type_to_extension_id_map; base::flat_map<std::string, std::string> mime_type_to_extension_id_map;
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
std::vector<std::string> allowed_extension_ids = std::vector<std::string> allowed_extension_ids =
MimeTypesHandler::GetMIMETypeAllowlist(); MimeTypesHandler::GetMIMETypeAllowlist();
// Go through the white-listed extensions and try to use them to intercept // Go through the white-listed extensions and try to use them to intercept

View file

@ -13,7 +13,7 @@
#include "base/scoped_observation.h" #include "base/scoped_observation.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "services/device/public/mojom/usb_enumeration_options.mojom.h" #include "services/device/public/mojom/usb_enumeration_options.mojom.h"
#include "shell/browser/electron_permission_manager.h" #include "shell/browser/electron_permission_manager.h"
#include "shell/browser/usb/usb_chooser_context.h" #include "shell/browser/usb/usb_chooser_context.h"
@ -21,7 +21,7 @@
#include "shell/browser/usb/usb_chooser_controller.h" #include "shell/browser/usb/usb_chooser_controller.h"
#include "shell/browser/web_contents_permission_helper.h" #include "shell/browser/web_contents_permission_helper.h"
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "base/containers/fixed_flat_set.h" #include "base/containers/fixed_flat_set.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
@ -41,7 +41,7 @@ electron::UsbChooserContext* GetChooserContext(
browser_context); browser_context);
} }
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// These extensions can claim the smart card USB class and automatically gain // These extensions can claim the smart card USB class and automatically gain
// permissions for devices that have an interface with this class. // permissions for devices that have an interface with this class.
constexpr auto kSmartCardPrivilegedExtensionIds = constexpr auto kSmartCardPrivilegedExtensionIds =
@ -65,12 +65,12 @@ bool DeviceHasInterfaceWithClass(
} }
return false; return false;
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
bool IsDevicePermissionAutoGranted( bool IsDevicePermissionAutoGranted(
const url::Origin& origin, const url::Origin& origin,
const device::mojom::UsbDeviceInfo& device_info) { const device::mojom::UsbDeviceInfo& device_info) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// Note: The `DeviceHasInterfaceWithClass()` call is made after checking the // Note: The `DeviceHasInterfaceWithClass()` call is made after checking the
// origin, since that method call is expensive. // origin, since that method call is expensive.
if (origin.scheme() == extensions::kExtensionScheme && if (origin.scheme() == extensions::kExtensionScheme &&
@ -79,7 +79,7 @@ bool IsDevicePermissionAutoGranted(
device::mojom::kUsbSmartCardClass)) { device::mojom::kUsbSmartCardClass)) {
return true; return true;
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
return false; return false;
} }
@ -251,14 +251,14 @@ ElectronUsbDelegate::GetContextObserver(
bool ElectronUsbDelegate::IsServiceWorkerAllowedForOrigin( bool ElectronUsbDelegate::IsServiceWorkerAllowedForOrigin(
const url::Origin& origin) { const url::Origin& origin) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// WebUSB is only available on extension service workers for now. // WebUSB is only available on extension service workers for now.
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
features::kEnableWebUsbOnExtensionServiceWorker) && features::kEnableWebUsbOnExtensionServiceWorker) &&
origin.scheme() == extensions::kExtensionScheme) { origin.scheme() == extensions::kExtensionScheme) {
return true; return true;
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
return false; return false;
} }
@ -289,7 +289,7 @@ void ElectronUsbDelegate::DeleteControllerForFrame(
bool ElectronUsbDelegate::PageMayUseUsb(content::Page& page) { bool ElectronUsbDelegate::PageMayUseUsb(content::Page& page) {
content::RenderFrameHost& main_rfh = page.GetMainDocument(); content::RenderFrameHost& main_rfh = page.GetMainDocument();
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// WebViewGuests have no mechanism to show permission prompts and their // WebViewGuests have no mechanism to show permission prompts and their
// embedder can't grant USB access through its permissionrequest API. Also // embedder can't grant USB access through its permissionrequest API. Also
// since webviews use a separate StoragePartition, they must not gain access // since webviews use a separate StoragePartition, they must not gain access
@ -297,7 +297,7 @@ bool ElectronUsbDelegate::PageMayUseUsb(content::Page& page) {
if (extensions::WebViewGuest::FromRenderFrameHost(&main_rfh)) { if (extensions::WebViewGuest::FromRenderFrameHost(&main_rfh)) {
return false; return false;
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// USB permissions are scoped to a BrowserContext instead of a // USB permissions are scoped to a BrowserContext instead of a
// StoragePartition, so we need to be careful about usage across // StoragePartition, so we need to be careful about usage across

View file

@ -7,15 +7,15 @@
#include <utility> #include <utility>
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "extensions/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "third_party/blink/public/web/web_element.h" #include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "chrome/common/pdf_util.h" #include "chrome/common/pdf_util.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/renderer/guest_view/mime_handler_view/post_message_support.h" #include "extensions/renderer/guest_view/mime_handler_view/post_message_support.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
namespace electron { namespace electron {
@ -26,14 +26,14 @@ PrintRenderFrameHelperDelegate::~PrintRenderFrameHelperDelegate() = default;
// Return the PDF object element if |frame| is the out of process PDF extension. // Return the PDF object element if |frame| is the out of process PDF extension.
blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement( blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
blink::WebLocalFrame* frame) { blink::WebLocalFrame* frame) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
if (frame->Parent() && if (frame->Parent() &&
IsPdfInternalPluginAllowedOrigin(frame->Parent()->GetSecurityOrigin())) { IsPdfInternalPluginAllowedOrigin(frame->Parent()->GetSecurityOrigin())) {
auto plugin_element = frame->GetDocument().QuerySelector("embed"); auto plugin_element = frame->GetDocument().QuerySelector("embed");
DCHECK(!plugin_element.IsNull()); DCHECK(!plugin_element.IsNull());
return plugin_element; return plugin_element;
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
return blink::WebElement(); return blink::WebElement();
} }
@ -43,7 +43,7 @@ bool PrintRenderFrameHelperDelegate::IsPrintPreviewEnabled() {
bool PrintRenderFrameHelperDelegate::OverridePrint( bool PrintRenderFrameHelperDelegate::OverridePrint(
blink::WebLocalFrame* frame) { blink::WebLocalFrame* frame) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
auto* post_message_support = auto* post_message_support =
extensions::PostMessageSupport::FromWebLocalFrame(frame); extensions::PostMessageSupport::FromWebLocalFrame(frame);
if (post_message_support) { if (post_message_support) {
@ -56,7 +56,7 @@ bool PrintRenderFrameHelperDelegate::OverridePrint(
post_message_support->PostMessageFromValue(base::Value(std::move(message))); post_message_support->PostMessageFromValue(base::Value(std::move(message)));
return true; return true;
} }
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
return false; return false;
} }

View file

@ -235,14 +235,6 @@ void RendererClientBase::RenderThreadStarted() {
extensions::ExtensionsRendererClient::Set(extensions_renderer_client_.get()); extensions::ExtensionsRendererClient::Set(extensions_renderer_client_.get());
thread->AddObserver(extensions_renderer_client_->GetDispatcher()); thread->AddObserver(extensions_renderer_client_->GetDispatcher());
#endif
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
spellcheck_ = std::make_unique<SpellCheck>(this);
#endif
blink::WebCustomElement::AddEmbedderCustomElementName("webview");
blink::WebCustomElement::AddEmbedderCustomElementName("browserplugin");
WTF::String extension_scheme(extensions::kExtensionScheme); WTF::String extension_scheme(extensions::kExtensionScheme);
// Extension resources are HTTP-like and safe to expose to the fetch API. The // Extension resources are HTTP-like and safe to expose to the fetch API. The
@ -255,6 +247,14 @@ void RendererClientBase::RenderThreadStarted() {
extension_scheme); extension_scheme);
blink::SchemeRegistry::RegisterURLSchemeAsBypassingContentSecurityPolicy( blink::SchemeRegistry::RegisterURLSchemeAsBypassingContentSecurityPolicy(
extension_scheme); extension_scheme);
#endif
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
spellcheck_ = std::make_unique<SpellCheck>(this);
#endif
blink::WebCustomElement::AddEmbedderCustomElementName("webview");
blink::WebCustomElement::AddEmbedderCustomElementName("browserplugin");
std::vector<std::string> fetch_enabled_schemes = std::vector<std::string> fetch_enabled_schemes =
ParseSchemesCLISwitch(command_line, switches::kFetchSchemes); ParseSchemesCLISwitch(command_line, switches::kFetchSchemes);