From c8559ea448ad93123865a6fa8af6fe2767e43396 Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Mon, 10 Jul 2023 18:52:08 -0400 Subject: [PATCH] WIP: 4658680: Convert /content/browser to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4658680 --- BUILD.gn | 12 ++++++++++- filenames.gni | 7 ------- shell/browser/browser_mac.mm | 21 ++++++++++++------- shell/browser/native_window.h | 2 +- shell/browser/native_window_mac.h | 2 +- shell/browser/ui/drag_util.h | 2 +- .../ui/inspectable_web_contents_view.h | 2 +- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 8375c68e28..89ca90f700 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -748,10 +748,17 @@ if (is_mac) { source_set("electron_lib_arc") { include_dirs = [ "." ] sources = [ + "shell/browser/browser_mac.mm", "shell/browser/mac/dict_util.h", "shell/browser/mac/dict_util.mm", + "shell/browser/mac/electron_application.h", + "shell/browser/mac/electron_application.mm", "shell/browser/mac/electron_application_delegate.h", "shell/browser/mac/electron_application_delegate.mm", + "shell/browser/native_window_mac.h", + "shell/browser/native_window_mac.mm", + "shell/browser/ui/cocoa/electron_ns_window_delegate.h", + "shell/browser/ui/cocoa/electron_ns_window_delegate.mm", ] deps = [ @@ -761,7 +768,10 @@ if (is_mac) { "//v8", ] - configs += [ "//build/config/compiler:enable_arc" ] + configs += [ + "//build/config/compiler:enable_arc", + "//electron/build/config:mas_build", + ] } } diff --git a/filenames.gni b/filenames.gni index 1fdf7cd3b2..f02208418b 100644 --- a/filenames.gni +++ b/filenames.gni @@ -127,10 +127,7 @@ filenames = { "shell/browser/api/electron_api_system_preferences_mac.mm", "shell/browser/api/electron_api_web_contents_mac.mm", "shell/browser/auto_updater_mac.mm", - "shell/browser/browser_mac.mm", "shell/browser/electron_browser_main_parts_mac.mm", - "shell/browser/mac/electron_application.h", - "shell/browser/mac/electron_application.mm", "shell/browser/mac/in_app_purchase_observer.h", "shell/browser/mac/in_app_purchase_observer.mm", "shell/browser/mac/in_app_purchase_product.h", @@ -139,8 +136,6 @@ filenames = { "shell/browser/mac/in_app_purchase.mm", "shell/browser/native_browser_view_mac.h", "shell/browser/native_browser_view_mac.mm", - "shell/browser/native_window_mac.h", - "shell/browser/native_window_mac.mm", "shell/browser/notifications/mac/cocoa_notification.h", "shell/browser/notifications/mac/cocoa_notification.mm", "shell/browser/notifications/mac/notification_center_delegate.h", @@ -161,8 +156,6 @@ filenames = { "shell/browser/ui/cocoa/electron_menu_controller.mm", "shell/browser/ui/cocoa/electron_native_widget_mac.h", "shell/browser/ui/cocoa/electron_native_widget_mac.mm", - "shell/browser/ui/cocoa/electron_ns_window_delegate.h", - "shell/browser/ui/cocoa/electron_ns_window_delegate.mm", "shell/browser/ui/cocoa/electron_ns_panel.h", "shell/browser/ui/cocoa/electron_ns_panel.mm", "shell/browser/ui/cocoa/electron_ns_window.h", diff --git a/shell/browser/browser_mac.mm b/shell/browser/browser_mac.mm index 125ab9807a..cfae6c3a9c 100644 --- a/shell/browser/browser_mac.mm +++ b/shell/browser/browser_mac.mm @@ -59,7 +59,9 @@ NSString* GetAppPathForProtocol(const GURL& url) { // likely kLSApplicationNotFoundErr return nullptr; } - NSString* app_path = [base::mac::CFToNSCast(openingApp.get()) path]; + NSURL* app_url = + const_cast(reinterpret_cast(openingApp.get())); + NSString* app_path = [app_url path]; return app_path; } @@ -178,7 +180,7 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, return false; NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; - CFStringRef protocol_cf = base::mac::NSToCFCast(protocol_ns); + CFStringRef protocol_cf = reinterpret_cast((protocol_ns); // TODO(codebytere): Use -[NSWorkspace URLForApplicationToOpenURL:] instead #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" @@ -200,7 +202,7 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, // No other app was found set it to none instead of setting it back to itself. if ([identifier isEqualToString:(__bridge NSString*)other]) { - other = base::mac::NSToCFCast(@"None"); + other = reinterpret_cast(@"None"); } OSStatus return_code = LSSetDefaultHandlerForURLScheme(protocol_cf, other); @@ -217,8 +219,9 @@ bool Browser::SetAsDefaultProtocolClient(const std::string& protocol, return false; NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; - OSStatus return_code = LSSetDefaultHandlerForURLScheme( - base::mac::NSToCFCast(protocol_ns), base::mac::NSToCFCast(identifier)); + CFStringRef protocol_cf = reinterpret_cast(protocol_ns); + CFStringRef identifier_cf = reinterpret_cast(identifier); + OSStatus return_code = LSSetDefaultHandlerForURLScheme(protocol_cf, identifier_cf)); return return_code == noErr; } @@ -232,20 +235,22 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol, return false; NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()]; + CFStringRef protocol_cf = reinterpret_cast(protocol_ns); // TODO(codebytere): Use -[NSWorkspace URLForApplicationToOpenURL:] instead #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" base::ScopedCFTypeRef bundleId( - LSCopyDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns))); + LSCopyDefaultHandlerForURLScheme(protocol_cf)); #pragma clang diagnostic pop if (!bundleId) return false; // Ensure the comparison is case-insensitive // as LS does not persist the case of the bundle id. - NSComparisonResult result = - [base::mac::CFToNSCast(bundleId) caseInsensitiveCompare:identifier]; + NSString* bundle_id_ns = + const_cast(reinterpret_cast(bundleId)); + NSComparisonResult result = [bundle_id_ns caseInsensitiveCompare:identifier]; return result == NSOrderedSame; } diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index f0bb45d545..ef3792300c 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -17,11 +17,11 @@ #include "base/supports_user_data.h" #include "content/public/browser/desktop_media_id.h" #include "content/public/browser/web_contents_user_data.h" +#include "electron/shell/common/api/api.mojom.h" #include "extensions/browser/app_window/size_constraints.h" #include "shell/browser/draggable_region_provider.h" #include "shell/browser/native_window_observer.h" #include "shell/browser/ui/inspectable_web_contents_view.h" -#include "shell/common/api/api.mojom.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/views/widget/widget_delegate.h" diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index c255f950e4..f0e3ab5ae3 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -12,8 +12,8 @@ #include #include "base/mac/scoped_nsobject.h" +#include "electron/shell/common/api/api.mojom.h" #include "shell/browser/native_window.h" -#include "shell/common/api/api.mojom.h" #include "ui/display/display_observer.h" #include "ui/native_theme/native_theme_observer.h" #include "ui/views/controls/native/native_view_host.h" diff --git a/shell/browser/ui/drag_util.h b/shell/browser/ui/drag_util.h index b3e18a505c..33a815609b 100644 --- a/shell/browser/ui/drag_util.h +++ b/shell/browser/ui/drag_util.h @@ -8,7 +8,7 @@ #include #include -#include "shell/common/api/api.mojom.h" +#include "electron/shell/common/api/api.mojom.h" #include "third_party/skia/include/core/SkRegion.h" #include "ui/gfx/image/image.h" diff --git a/shell/browser/ui/inspectable_web_contents_view.h b/shell/browser/ui/inspectable_web_contents_view.h index fb10cbf5d4..46cbda3312 100644 --- a/shell/browser/ui/inspectable_web_contents_view.h +++ b/shell/browser/ui/inspectable_web_contents_view.h @@ -9,7 +9,7 @@ #include #include "base/memory/raw_ptr.h" -#include "shell/common/api/api.mojom.h" +#include "electron/shell/common/api/api.mojom.h" #include "ui/gfx/native_widget_types.h" class DevToolsContentsResizingStrategy;