From ec7942e8b5025cc748d837dd833642fa652cee6d Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 28 Apr 2020 23:16:10 -0700 Subject: [PATCH] fix: build when some buildflags are disabled (#23307) --- BUILD.gn | 28 +++++++++++++------ build/args/all.gn | 4 --- buildflags/buildflags.gni | 2 +- chromium_src/BUILD.gn | 21 ++++++++++---- filenames.gni | 4 +-- shell/app/electron_main_delegate_mac.mm | 3 ++ shell/browser/api/electron_api_web_contents.h | 2 +- shell/browser/electron_browser_client.cc | 5 +++- .../extensions/electron_extension_system.cc | 8 +++++- shell/browser/net/proxying_websocket.cc | 18 ++++-------- shell/browser/net/proxying_websocket.h | 20 +++++++++++-- shell/common/mac/main_application_bundle.mm | 7 +++-- shell/renderer/renderer_client_base.cc | 2 +- .../electron_content_utility_client.cc | 2 +- 14 files changed, 82 insertions(+), 44 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index e7f756b15d9a..e767f31273d0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3,6 +3,7 @@ import("//build/config/ui.gni") import("//build/config/win/manifest.gni") import("//components/spellcheck/spellcheck_build_features.gni") import("//content/public/app/mac_helpers.gni") +import("//extensions/buildflags/buildflags.gni") import("//pdf/features.gni") import("//ppapi/buildflags/buildflags.gni") import("//printing/buildflags/buildflags.gni") @@ -58,6 +59,17 @@ if (is_mas_build) { "It doesn't make sense to build a MAS build on a non-mac platform") } +if (enable_pdf_viewer) { + assert(enable_pdf, "PDF viewer support requires enable_pdf=true") + assert(enable_electron_extensions, + "PDF viewer support requires enable_electron_extensions=true") +} + +if (enable_electron_extensions) { + assert(enable_extensions, + "Chrome extension support requires enable_extensions=true") +} + config("branding") { defines = [ "ELECTRON_PRODUCT_NAME=\"$electron_product_name\"", @@ -330,7 +342,9 @@ source_set("electron_lib") { "//components/network_hints/common:mojo_bindings", "//components/network_hints/renderer", "//components/network_session_configurator/common", + "//components/pref_registry", "//components/prefs", + "//components/user_prefs", "//components/viz/host", "//components/viz/service", "//content/public/browser", @@ -622,15 +636,6 @@ source_set("electron_lib") { deps += [ "//components/printing/common:mojo_interfaces" ] } - deps += [ - "//components/pref_registry", - "//components/user_prefs", - "//extensions/browser", - "//extensions/browser:core_api_provider", - "//extensions/common", - "//extensions/common:core_api_provider", - "//extensions/renderer", - ] if (enable_electron_extensions) { sources += filenames.lib_sources_extensions deps += [ @@ -639,6 +644,11 @@ source_set("electron_lib") { "shell/common/extensions/api:extensions_features", "//chrome/browser/resources:component_extension_resources", "//components/zoom", + "//extensions/browser", + "//extensions/browser:core_api_provider", + "//extensions/common", + "//extensions/common:core_api_provider", + "//extensions/renderer", ] } diff --git a/build/args/all.gn b/build/args/all.gn index 61c3b8118f05..bf8078539d13 100644 --- a/build/args/all.gn +++ b/build/args/all.gn @@ -20,7 +20,3 @@ angle_enable_vulkan_validation_layers = false dawn_enable_vulkan_validation_layers = false is_cfi = false - -enable_osr = true - -enable_electron_extensions = true diff --git a/buildflags/buildflags.gni b/buildflags/buildflags.gni index a926a324d15f..ab79d37d091d 100644 --- a/buildflags/buildflags.gni +++ b/buildflags/buildflags.gni @@ -32,7 +32,7 @@ declare_args() { enable_pepper_flash = true # Enable Chrome extensions support. - enable_electron_extensions = false + enable_electron_extensions = true # Enable Spellchecker support enable_builtin_spellchecker = true diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index 2df8d3986ab6..13b65275acec 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -239,17 +239,22 @@ static_library("chrome") { sources += [ "//chrome/browser/extensions/chrome_url_request_util.cc", "//chrome/browser/extensions/chrome_url_request_util.h", - "//chrome/browser/pdf/pdf_extension_util.cc", - "//chrome/browser/pdf/pdf_extension_util.h", "//chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.cc", "//chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h", "//chrome/renderer/extensions/extension_hooks_delegate.cc", "//chrome/renderer/extensions/extension_hooks_delegate.h", "//chrome/renderer/extensions/tabs_hooks_delegate.cc", "//chrome/renderer/extensions/tabs_hooks_delegate.h", - "//chrome/renderer/pepper/chrome_pdf_print_client.cc", - "//chrome/renderer/pepper/chrome_pdf_print_client.h", ] + + if (enable_pdf_viewer) { + sources += [ + "//chrome/browser/pdf/pdf_extension_util.cc", + "//chrome/browser/pdf/pdf_extension_util.h", + "//chrome/renderer/pepper/chrome_pdf_print_client.cc", + "//chrome/renderer/pepper/chrome_pdf_print_client.h", + ] + } } } @@ -268,12 +273,14 @@ source_set("plugins") { "//chrome/browser/renderer_host/pepper/pepper_isolated_file_system_message_filter.h", ] deps += [ - "//components/pdf/browser", "//media:media_buildflags", "//ppapi/buildflags", "//ppapi/proxy:ipc", "//services/device/public/mojom", ] + if (enable_pdf_viewer) { + deps += [ "//components/pdf/browser" ] + } if (enable_pepper_flash) { sources += [ "//chrome/browser/renderer_host/pepper/pepper_flash_browser_host.cc", @@ -319,9 +326,11 @@ source_set("plugins") { "//chrome/renderer/pepper/pepper_flash_font_file_host.cc", "//chrome/renderer/pepper/pepper_flash_font_file_host.h", ] + if (enable_pdf_viewer) { + deps += [ "//components/pdf/renderer" ] + } } deps += [ - "//components/pdf/renderer", "//components/strings", "//media:media_buildflags", "//ppapi/host", diff --git a/filenames.gni b/filenames.gni index ca3db4b5cddf..afbb062b0521 100644 --- a/filenames.gni +++ b/filenames.gni @@ -488,8 +488,6 @@ filenames = { "shell/common/gin_converters/callback_converter.h", "shell/common/gin_converters/content_converter.cc", "shell/common/gin_converters/content_converter.h", - "shell/common/gin_converters/extension_converter.cc", - "shell/common/gin_converters/extension_converter.h", "shell/common/gin_converters/file_dialog_converter.cc", "shell/common/gin_converters/file_dialog_converter.h", "shell/common/gin_converters/file_path_converter.h", @@ -663,6 +661,8 @@ filenames = { "shell/common/extensions/electron_extensions_api_provider.h", "shell/common/extensions/electron_extensions_client.cc", "shell/common/extensions/electron_extensions_client.h", + "shell/common/gin_converters/extension_converter.cc", + "shell/common/gin_converters/extension_converter.h", "shell/renderer/extensions/electron_extensions_dispatcher_delegate.cc", "shell/renderer/extensions/electron_extensions_dispatcher_delegate.h", "shell/renderer/extensions/electron_extensions_renderer_client.cc", diff --git a/shell/app/electron_main_delegate_mac.mm b/shell/app/electron_main_delegate_mac.mm index 3805ad76a2d6..b3c3e5df9e0d 100644 --- a/shell/app/electron_main_delegate_mac.mm +++ b/shell/app/electron_main_delegate_mac.mm @@ -15,6 +15,7 @@ #include "base/strings/sys_string_conversions.h" #include "content/common/mac_helpers.h" #include "content/public/common/content_paths.h" +#include "ppapi/buildflags/buildflags.h" #include "shell/browser/mac/electron_application.h" #include "shell/common/application_info.h" #include "shell/common/mac/main_application_bundle.h" @@ -40,9 +41,11 @@ base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path, } else if (base::EndsWith(path.value(), content::kMacHelperSuffix_gpu, base::CompareCase::SENSITIVE)) { helper_name += content::kMacHelperSuffix_gpu; +#if BUILDFLAG(ENABLE_PLUGINS) } else if (base::EndsWith(path.value(), content::kMacHelperSuffix_plugin, base::CompareCase::SENSITIVE)) { helper_name += content::kMacHelperSuffix_plugin; +#endif } return frameworks_path.Append(name + " " + helper_name + ".app") diff --git a/shell/browser/api/electron_api_web_contents.h b/shell/browser/api/electron_api_web_contents.h index 980ff85b0630..ab9946c031bd 100644 --- a/shell/browser/api/electron_api_web_contents.h +++ b/shell/browser/api/electron_api_web_contents.h @@ -34,7 +34,7 @@ #if BUILDFLAG(ENABLE_PRINTING) #include "chrome/browser/printing/print_view_manager_basic.h" #include "components/printing/common/print_messages.h" -#include "printing/backend/print_backend.h" +#include "printing/backend/print_backend.h" // nogncheck #include "shell/browser/printing/print_preview_message_handler.h" #if defined(OS_WIN) diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index d48f04b5a1f4..ca0456b7f035 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -91,6 +91,7 @@ #include "shell/common/application_info.h" #include "shell/common/options_switches.h" #include "shell/common/platform_util.h" +#include "third_party/blink/public/common/loader/url_loader_throttle.h" #include "ui/base/resource/resource_bundle.h" #include "ui/native_theme/native_theme.h" #include "v8/include/v8.h" @@ -115,7 +116,7 @@ #endif #if BUILDFLAG(ENABLE_PEPPER_FLASH) -#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" +#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" // nogncheck #endif // BUILDFLAG(ENABLE_PEPPER_FLASH) #if BUILDFLAG(OVERRIDE_LOCATION_PROVIDER) @@ -140,6 +141,7 @@ #include "extensions/browser/extension_message_filter.h" #include "extensions/browser/extension_navigation_throttle.h" #include "extensions/browser/extension_registry.h" +#include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" #include "extensions/browser/info_map.h" @@ -453,6 +455,7 @@ void ElectronBrowserClient::RenderProcessWillLaunch( return; auto* browser_context = host->GetBrowserContext(); + ALLOW_UNUSED_LOCAL(browser_context); #if BUILDFLAG(ENABLE_PRINTING) host->AddFilter( diff --git a/shell/browser/extensions/electron_extension_system.cc b/shell/browser/extensions/electron_extension_system.cc index 93ffc1413ad4..e0fa17a5c080 100644 --- a/shell/browser/extensions/electron_extension_system.cc +++ b/shell/browser/extensions/electron_extension_system.cc @@ -14,7 +14,6 @@ #include "base/json/json_string_value_serializer.h" #include "base/path_service.h" #include "base/task/post_task.h" -#include "chrome/browser/pdf/pdf_extension_util.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_task_traits.h" @@ -22,6 +21,7 @@ #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" +#include "electron/buildflags/buildflags.h" #include "extensions/browser/api/app_runtime/app_runtime_api.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/info_map.h" @@ -36,6 +36,10 @@ #include "extensions/common/file_util.h" #include "shell/browser/extensions/electron_extension_loader.h" +#if BUILDFLAG(ENABLE_PDF_VIEWER) +#include "chrome/browser/pdf/pdf_extension_util.h" +#endif + using content::BrowserContext; using content::BrowserThread; @@ -106,6 +110,7 @@ std::unique_ptr ParseManifest( } void ElectronExtensionSystem::LoadComponentExtensions() { +#if BUILDFLAG(ENABLE_PDF_VIEWER) std::string utf8_error; std::string pdf_manifest_string = pdf_extension_util::GetManifest(); std::unique_ptr pdf_manifest = @@ -117,6 +122,7 @@ void ElectronExtensionSystem::LoadComponentExtensions() { root_directory, extensions::Manifest::COMPONENT, *pdf_manifest, extensions::Extension::REQUIRE_KEY, &utf8_error); extension_loader_->registrar()->AddExtension(pdf_extension); +#endif } ExtensionService* ElectronExtensionSystem::extension_service() { diff --git a/shell/browser/net/proxying_websocket.cc b/shell/browser/net/proxying_websocket.cc index 5a04fd16f0cf..e4f4e585630f 100644 --- a/shell/browser/net/proxying_websocket.cc +++ b/shell/browser/net/proxying_websocket.cc @@ -375,24 +375,19 @@ void ProxyingWebSocket::OnHeadersReceivedComplete(int error_code) { ContinueToCompleted(); } -void ProxyingWebSocket::OnAuthRequiredComplete( - extensions::ExtensionWebRequestEventRouter::AuthRequiredResponse rv) { +void ProxyingWebSocket::OnAuthRequiredComplete(AuthRequiredResponse rv) { CHECK(auth_required_callback_); ResumeIncomingMethodCallProcessing(); switch (rv) { - case extensions::ExtensionWebRequestEventRouter::AuthRequiredResponse:: - AUTH_REQUIRED_RESPONSE_NO_ACTION: - case extensions::ExtensionWebRequestEventRouter::AuthRequiredResponse:: - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: + case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_NO_ACTION: + case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: std::move(auth_required_callback_).Run(base::nullopt); break; - case extensions::ExtensionWebRequestEventRouter::AuthRequiredResponse:: - AUTH_REQUIRED_RESPONSE_SET_AUTH: + case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_SET_AUTH: std::move(auth_required_callback_).Run(auth_credentials_); break; - case extensions::ExtensionWebRequestEventRouter::AuthRequiredResponse:: - AUTH_REQUIRED_RESPONSE_IO_PENDING: + case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_IO_PENDING: NOTREACHED(); break; } @@ -410,8 +405,7 @@ void ProxyingWebSocket::OnHeadersReceivedCompleteForAuth( auto continuation = base::BindRepeating( &ProxyingWebSocket::OnAuthRequiredComplete, weak_factory_.GetWeakPtr()); - auto auth_rv = extensions::ExtensionWebRequestEventRouter:: - AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_IO_PENDING; + auto auth_rv = AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_IO_PENDING; PauseIncomingMethodCallProcessing(); OnAuthRequiredComplete(auth_rv); diff --git a/shell/browser/net/proxying_websocket.h b/shell/browser/net/proxying_websocket.h index 833d196dca08..3ed9ea8f87bc 100644 --- a/shell/browser/net/proxying_websocket.h +++ b/shell/browser/net/proxying_websocket.h @@ -12,7 +12,7 @@ #include "base/optional.h" #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" -#include "extensions/browser/api/web_request/web_request_api.h" +#include "content/public/browser/content_browser_client.h" #include "extensions/browser/api/web_request/web_request_info.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/receiver.h" @@ -37,6 +37,21 @@ class ProxyingWebSocket : public network::mojom::WebSocketHandshakeClient, public: using WebSocketFactory = content::ContentBrowserClient::WebSocketFactory; + // AuthRequiredResponse indicates how an OnAuthRequired call is handled. + enum class AuthRequiredResponse { + // No credenitals were provided. + AUTH_REQUIRED_RESPONSE_NO_ACTION, + // AuthCredentials is filled in with a username and password, which should + // be used in a response to the provided auth challenge. + AUTH_REQUIRED_RESPONSE_SET_AUTH, + // The request should be canceled. + AUTH_REQUIRED_RESPONSE_CANCEL_AUTH, + // The action will be decided asynchronously. |callback| will be invoked + // when the decision is made, and one of the other AuthRequiredResponse + // values will be passed in with the same semantics as described above. + AUTH_REQUIRED_RESPONSE_IO_PENDING, + }; + ProxyingWebSocket( WebRequestAPI* web_request_api, WebSocketFactory factory, @@ -100,8 +115,7 @@ class ProxyingWebSocket : public network::mojom::WebSocketHandshakeClient, void ContinueToStartRequest(int error_code); void OnHeadersReceivedComplete(int error_code); void ContinueToHeadersReceived(); - void OnAuthRequiredComplete( - extensions::ExtensionWebRequestEventRouter::AuthRequiredResponse rv); + void OnAuthRequiredComplete(AuthRequiredResponse rv); void OnHeadersReceivedCompleteForAuth(const net::AuthChallengeInfo& auth_info, int rv); void ContinueToCompleted(); diff --git a/shell/common/mac/main_application_bundle.mm b/shell/common/mac/main_application_bundle.mm index 698d62a05037..0e8058e8f90a 100644 --- a/shell/common/mac/main_application_bundle.mm +++ b/shell/common/mac/main_application_bundle.mm @@ -11,6 +11,7 @@ #include "base/path_service.h" #include "base/strings/string_util.h" #include "content/common/mac_helpers.h" +#include "ppapi/buildflags/buildflags.h" namespace electron { @@ -32,11 +33,13 @@ base::FilePath MainApplicationBundlePath() { // Up to Contents. if (!HasMainProcessKey() && (base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE) || +#if BUILDFLAG(ENABLE_PLUGINS) + base::EndsWith(path.value(), content::kMacHelperSuffix_plugin, + base::CompareCase::SENSITIVE) || +#endif base::EndsWith(path.value(), content::kMacHelperSuffix_renderer, base::CompareCase::SENSITIVE) || base::EndsWith(path.value(), content::kMacHelperSuffix_gpu, - base::CompareCase::SENSITIVE) || - base::EndsWith(path.value(), content::kMacHelperSuffix_plugin, base::CompareCase::SENSITIVE))) { // The running executable is the helper. Go up five steps: // Contents/Frameworks/Helper.app/Contents/MacOS/Helper diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index 1daf3dd511ac..18abdb5fc1c2 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -62,7 +62,7 @@ #if BUILDFLAG(ENABLE_PRINTING) #include "components/printing/renderer/print_render_frame_helper.h" -#include "printing/print_settings.h" +#include "printing/print_settings.h" // nogncheck #include "shell/renderer/printing/print_render_frame_helper_delegate.h" #endif // BUILDFLAG(ENABLE_PRINTING) diff --git a/shell/utility/electron_content_utility_client.cc b/shell/utility/electron_content_utility_client.cc index 20e3efac9a63..b5443e24cc34 100644 --- a/shell/utility/electron_content_utility_client.cc +++ b/shell/utility/electron_content_utility_client.cc @@ -18,7 +18,7 @@ #if BUILDFLAG(ENABLE_PRINTING) #include "components/services/print_compositor/print_compositor_impl.h" -#include "components/services/print_compositor/public/mojom/print_compositor.mojom.h" +#include "components/services/print_compositor/public/mojom/print_compositor.mojom.h" // nogncheck #if defined(OS_WIN) #include "chrome/services/printing/pdf_to_emf_converter_factory.h"