diff --git a/shell/browser/api/electron_api_menu.cc b/shell/browser/api/electron_api_menu.cc index 9a87c9e19320..daef73495bf7 100644 --- a/shell/browser/api/electron_api_menu.cc +++ b/shell/browser/api/electron_api_menu.cc @@ -70,6 +70,8 @@ Menu::~Menu() { } } +namespace { + bool InvokeBoolMethod(const Menu* menu, const char* method, int command_id, @@ -84,6 +86,8 @@ bool InvokeBoolMethod(const Menu* menu, return gin::ConvertFromV8(isolate, val, &ret) ? ret : default_value; } +} // namespace + bool Menu::IsCommandIdChecked(int command_id) const { return InvokeBoolMethod(this, "_isCommandIdChecked", command_id); } diff --git a/shell/browser/api/electron_api_utility_process.cc b/shell/browser/api/electron_api_utility_process.cc index de128ddd52b8..a40d84ea948d 100644 --- a/shell/browser/api/electron_api_utility_process.cc +++ b/shell/browser/api/electron_api_utility_process.cc @@ -44,6 +44,8 @@ namespace electron { +namespace { + base::IDMap& GetAllUtilityProcessWrappers() { static base::NoDestructor< @@ -52,6 +54,8 @@ GetAllUtilityProcessWrappers() { return *s_all_utility_process_wrappers; } +} // namespace + namespace api { gin::WrapperInfo UtilityProcessWrapper::kWrapperInfo = { diff --git a/shell/browser/api/electron_api_web_frame_main.cc b/shell/browser/api/electron_api_web_frame_main.cc index ac9653a76239..a5cde1af50aa 100644 --- a/shell/browser/api/electron_api_web_frame_main.cc +++ b/shell/browser/api/electron_api_web_frame_main.cc @@ -100,6 +100,8 @@ using FrameTreeNodeIdMap = std::unordered_map; +namespace { + FrameTreeNodeIdMap& GetFrameTreeNodeIdMap() { static base::NoDestructor instance; return *instance; @@ -109,6 +111,8 @@ FrameTokenMap& GetFrameTokenMap() { return *instance; } +} // namespace + // static WebFrameMain* WebFrameMain::FromFrameTreeNodeId( content::FrameTreeNodeId frame_tree_node_id) { diff --git a/shell/browser/extensions/electron_extension_system.cc b/shell/browser/extensions/electron_extension_system.cc index 6ab4279b27dc..9d3ac16f3705 100644 --- a/shell/browser/extensions/electron_extension_system.cc +++ b/shell/browser/extensions/electron_extension_system.cc @@ -88,6 +88,8 @@ void ElectronExtensionSystem::InitForRegularProfile(bool extensions_enabled) { management_policy_ = std::make_unique(); } +namespace { + std::unique_ptr ParseManifest( const std::string_view manifest_contents) { JSONStringValueDeserializer deserializer(manifest_contents); @@ -101,6 +103,8 @@ std::unique_ptr ParseManifest( return std::make_unique(std::move(*manifest).TakeDict()); } +} // namespace + void ElectronExtensionSystem::LoadComponentExtensions() { std::string utf8_error; #if BUILDFLAG(ENABLE_PDF_VIEWER) diff --git a/shell/browser/printing/printing_utils.cc b/shell/browser/printing/printing_utils.cc index 5f1d4fb549b0..852a0c6dba68 100644 --- a/shell/browser/printing/printing_utils.cc +++ b/shell/browser/printing/printing_utils.cc @@ -79,6 +79,8 @@ bool IsDeviceNameValid(const std::u16string& device_name) { #endif } +namespace { + // Duplicated from chrome/browser/printing/print_view_manager_common.cc content::RenderFrameHost* GetFullPagePlugin(content::WebContents* contents) { content::RenderFrameHost* full_page_plugin = nullptr; @@ -98,6 +100,8 @@ content::RenderFrameHost* GetFullPagePlugin(content::WebContents* contents) { return full_page_plugin; } +} // namespace + // Pick the right RenderFrameHost based on the WebContents. // Modified from chrome/browser/printing/print_view_manager_common.cc content::RenderFrameHost* GetRenderFrameHostToUse( diff --git a/shell/common/gin_converters/blink_converter.cc b/shell/common/gin_converters/blink_converter.cc index 1e3c2716e21d..8828197606f3 100644 --- a/shell/common/gin_converters/blink_converter.cc +++ b/shell/common/gin_converters/blink_converter.cc @@ -200,6 +200,8 @@ struct Converter { } }; +namespace { + std::vector ModifiersToArray(int modifiers) { std::vector modifier_strings; @@ -210,6 +212,8 @@ std::vector ModifiersToArray(int modifiers) { return modifier_strings; } +} // namespace + blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate, v8::Local val) { blink::WebInputEvent::Type type = blink::WebInputEvent::Type::kUndefined; @@ -300,6 +304,8 @@ bool Converter::FromV8(v8::Isolate* isolate, return true; } +namespace { + int GetKeyLocationCode(const blink::WebInputEvent& key) { // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/events/keyboard_event.h;l=46;drc=1ff6437e65b183e673b7b4f25060b74dc2ba5c37 enum KeyLocationCode { @@ -318,6 +324,8 @@ int GetKeyLocationCode(const blink::WebInputEvent& key) { return kDomKeyLocationStandard; } +} // namespace + v8::Local Converter::ToV8( v8::Isolate* isolate, const blink::WebKeyboardEvent& in) { diff --git a/shell/common/platform_util.cc b/shell/common/platform_util.cc index 7d4b34baebf7..4c6326ca1e37 100644 --- a/shell/common/platform_util.cc +++ b/shell/common/platform_util.cc @@ -13,6 +13,8 @@ namespace platform_util { +namespace { + struct TrashItemResult { bool success; std::string error; @@ -24,6 +26,8 @@ TrashItemResult TrashItemOnBlockingThread(const base::FilePath& full_path) { return {success, error}; } +} // namespace + void TrashItem(const base::FilePath& full_path, base::OnceCallback callback) { // XXX: is continue_on_shutdown right? diff --git a/shell/common/skia_util.cc b/shell/common/skia_util.cc index b80b1c53f8ba..8b1d590873da 100644 --- a/shell/common/skia_util.cc +++ b/shell/common/skia_util.cc @@ -29,6 +29,8 @@ namespace electron::util { +namespace { + struct ScaleFactorPair { const char* name; float scale; @@ -55,6 +57,22 @@ float GetScaleFactorFromPath(const base::FilePath& path) { return 1.0f; } +bool AddImageSkiaRepFromPath(gfx::ImageSkia* image, + const base::FilePath& path, + double scale_factor) { + std::string file_contents; + { + electron::ScopedAllowBlockingForElectron allow_blocking; + if (!asar::ReadFileToString(path, &file_contents)) + return false; + } + + return AddImageSkiaRepFromBuffer(image, base::as_byte_span(file_contents), 0, + 0, scale_factor); +} + +} // namespace + bool AddImageSkiaRepFromPNG(gfx::ImageSkia* image, const base::span data, double scale_factor) { @@ -114,20 +132,6 @@ bool AddImageSkiaRepFromBuffer(gfx::ImageSkia* image, return true; } -bool AddImageSkiaRepFromPath(gfx::ImageSkia* image, - const base::FilePath& path, - double scale_factor) { - std::string file_contents; - { - electron::ScopedAllowBlockingForElectron allow_blocking; - if (!asar::ReadFileToString(path, &file_contents)) - return false; - } - - return AddImageSkiaRepFromBuffer(image, base::as_byte_span(file_contents), 0, - 0, scale_factor); -} - bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image, const base::FilePath& path) { bool succeed = false; diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 384eb4b33601..41f1db82799e 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -659,6 +659,8 @@ v8::MaybeLocal CreateProxyForAPI( } } +namespace { + void ExposeAPIInWorld(v8::Isolate* isolate, const int world_id, const std::string& key, @@ -819,6 +821,8 @@ bool IsCalledFromMainWorld(v8::Isolate* isolate) { return isolate->GetCurrentContext() == main_context; } +} // namespace + } // namespace api } // namespace electron