[go: nahoru, domu]

[BRP] Manual rewrite to raw_ptr on Mac

- This is a follow-up of https://crrev.com/c/4568700
- Add RAW_PTR_EXCLUSION to fields excluded from the automatic rewrite
- `content::ContentMainParams::autorelease_pool` is a manual rewrite
  to `raw_ptr` because `absl::optional` is safe with `raw_ptr`.

Change-Id: I6dcf846ed442df594a9102bd016c87cfe4af948c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4570453
Reviewed-by: Keishi Hattori <keishi@chromium.org>
Owners-Override: Keishi Hattori <keishi@chromium.org>
Commit-Queue: Mikihito Matsuura <mikt@google.com>
Cr-Commit-Position: refs/heads/main@{#1151142}
diff --git a/base/native_library.h b/base/native_library.h
index 4c9f788..0f5ff4d 100644
--- a/base/native_library.h
+++ b/base/native_library.h
@@ -12,6 +12,7 @@
 
 #include "base/base_export.h"
 #include "base/files/file_path.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/strings/string_piece.h"
 #include "build/build_config.h"
 
@@ -40,7 +41,9 @@
   NativeLibraryObjCStatus objc_status;
   union {
     CFBundleRef bundle;
-    void* dylib;
+    //// This field is not a raw_ptr<> because it was filtered by the rewriter
+    // for: #union
+    RAW_PTR_EXCLUSION void* dylib;
   };
 };
 using NativeLibrary = NativeLibraryStruct*;
diff --git a/chrome/common/mac/app_mode_common.h b/chrome/common/mac/app_mode_common.h
index c2c5b46..d03c460 100644
--- a/chrome/common/mac/app_mode_common.h
+++ b/chrome/common/mac/app_mode_common.h
@@ -9,6 +9,7 @@
 #include <string>
 
 #include "base/files/file_path.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/strings/stringize_macros.h"
 
 #ifdef __OBJC__
@@ -186,7 +187,9 @@
 struct ChromeAppModeInfo {
   // Original |argc| and |argv| of the App Mode shortcut.
   int argc;
-  char** argv;
+  // This field is not a raw_ptr<> because this struct is part of separate
+  // binary and must be a POD.
+  RAW_PTR_EXCLUSION char** argv;
 
   // Path of the Chromium Framework, as UTF-8. This will be the input to
   // SetOverrideFrameworkBundlePath().
diff --git a/chrome/utility/safe_browsing/mac/hfs.cc b/chrome/utility/safe_browsing/mac/hfs.cc
index 8cbe319c4..99b044c 100644
--- a/chrome/utility/safe_browsing/mac/hfs.cc
+++ b/chrome/utility/safe_browsing/mac/hfs.cc
@@ -15,6 +15,7 @@
 
 #include "base/logging.h"
 #include "base/memory/raw_ptr.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/numerics/safe_math.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/utility/safe_browsing/mac/convert_big_endian.h"
@@ -167,8 +168,12 @@
     std::u16string path;   // Full path to the item.
     bool unexported;  // Whether this is HFS+ private data.
     union {
-      HFSPlusCatalogFile* file;
-      HFSPlusCatalogFolder* folder;
+      // This field is not a raw_ptr<> because it was filtered by the rewriter
+      // for: #union
+      RAW_PTR_EXCLUSION HFSPlusCatalogFile* file;
+      // This field is not a raw_ptr<> because it was filtered by the rewriter
+      // for: #union
+      RAW_PTR_EXCLUSION HFSPlusCatalogFolder* folder;
     };
   };
 
diff --git a/components/remote_cocoa/app_shim/alert.mm b/components/remote_cocoa/app_shim/alert.mm
index 701779f..20208ce 100644
--- a/components/remote_cocoa/app_shim/alert.mm
+++ b/components/remote_cocoa/app_shim/alert.mm
@@ -7,6 +7,7 @@
 #include "base/functional/bind.h"
 #include "base/i18n/rtl.h"
 #import "base/mac/foundation_util.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/strings/sys_string_conversions.h"
 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
 #include "ui/base/l10n/l10n_util_mac.h"
@@ -29,7 +30,8 @@
 @interface AlertBridgeHelper : NSObject <NSAlertDelegate> {
  @private
   base::scoped_nsobject<NSAlert> _alert;
-  remote_cocoa::AlertBridge* _alertBridge;  // Weak.
+  // This field is not a raw_ptr<> because it requires @property rewrite.
+  RAW_PTR_EXCLUSION remote_cocoa::AlertBridge* _alertBridge;  // Weak.
   base::scoped_nsobject<NSTextField> _textField;
 }
 @property(assign, nonatomic) remote_cocoa::AlertBridge* alertBridge;
diff --git a/components/remote_cocoa/app_shim/bridged_content_view.h b/components/remote_cocoa/app_shim/bridged_content_view.h
index 55e7037..44f779b 100644
--- a/components/remote_cocoa/app_shim/bridged_content_view.h
+++ b/components/remote_cocoa/app_shim/bridged_content_view.h
@@ -9,6 +9,7 @@
 
 #include <string>
 
+#include "base/memory/raw_ptr_exclusion.h"
 #include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
 #import "ui/base/cocoa/tool_tip_base_view.h"
 #import "ui/base/cocoa/tracking_area.h"
@@ -31,7 +32,8 @@
                                                  NSServicesMenuRequestor> {
  @private
   // Weak, reset by clearView.
-  remote_cocoa::NativeWidgetNSWindowBridge* _bridge;
+  // This field is not a raw_ptr<> because it requires @property rewrite.
+  RAW_PTR_EXCLUSION remote_cocoa::NativeWidgetNSWindowBridge* _bridge;
 
   // A tracking area installed to enable mouseMoved events.
   ui::ScopedCrTrackingArea _cursorTrackingArea;
diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
index e90c794..ac6d188 100644
--- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
+++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
@@ -8,6 +8,7 @@
 #include "base/debug/dump_without_crashing.h"
 #include "base/mac/foundation_util.h"
 #include "base/mac/mac_util.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/trace_event/trace_event.h"
 #import "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
 #include "components/remote_cocoa/app_shim/native_widget_ns_window_host_helper.h"
@@ -166,7 +167,8 @@
   base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> _commandHandler;
   id<WindowTouchBarDelegate> _touchBarDelegate;  // Weak.
   uint64_t _bridgedNativeWidgetId;
-  remote_cocoa::NativeWidgetNSWindowBridge* _bridge;
+  // This field is not a raw_ptr<> because it requires @property rewrite.
+  RAW_PTR_EXCLUSION remote_cocoa::NativeWidgetNSWindowBridge* _bridge;
   BOOL _willUpdateRestorableState;
   BOOL _isEnforcingNeverMadeVisible;
   BOOL _preventKeyWindow;
diff --git a/content/browser/renderer_host/popup_menu_helper_mac.h b/content/browser/renderer_host/popup_menu_helper_mac.h
index 5affb53..2f80a95d 100644
--- a/content/browser/renderer_host/popup_menu_helper_mac.h
+++ b/content/browser/renderer_host/popup_menu_helper_mac.h
@@ -9,6 +9,7 @@
 #include <vector>
 
 #include "base/memory/raw_ptr.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/memory/weak_ptr.h"
 #include "base/scoped_observation.h"
 #include "content/common/content_export.h"
@@ -83,7 +84,10 @@
       observation_{this};
   base::WeakPtr<RenderFrameHostImpl> render_frame_host_;
   mojo::Remote<blink::mojom::PopupMenuClient> popup_client_;
-  WebMenuRunner* menu_runner_ = nil;
+
+  // This field is not a raw_ptr<> because it is a pointer to Objective-C
+  // object.
+  RAW_PTR_EXCLUSION WebMenuRunner* menu_runner_ = nil;
   bool popup_was_hidden_ = false;
 
   // Controls whether messages can be pumped during the menu fade.
diff --git a/content/public/app/content_main.h b/content/public/app/content_main.h
index baf8a17..9be99b2 100644
--- a/content/public/app/content_main.h
+++ b/content/public/app/content_main.h
@@ -71,7 +71,7 @@
 
 #if BUILDFLAG(IS_MAC)
   // The outermost autorelease pool to pass to main entry points.
-  base::mac::ScopedNSAutoreleasePool* autorelease_pool = nullptr;
+  raw_ptr<base::mac::ScopedNSAutoreleasePool> autorelease_pool = nullptr;
 #endif
 
   // Returns a copy of this ContentMainParams without the move-only data
diff --git a/content/public/browser/native_event_processor_observer_mac.h b/content/public/browser/native_event_processor_observer_mac.h
index 5863c2e5..0ba8ce8 100644
--- a/content/public/browser/native_event_processor_observer_mac.h
+++ b/content/public/browser/native_event_processor_observer_mac.h
@@ -6,6 +6,7 @@
 #define CONTENT_PUBLIC_BROWSER_NATIVE_EVENT_PROCESSOR_OBSERVER_MAC_H_
 
 #include "base/memory/raw_ptr.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/observer_list.h"
 #include "content/common/content_export.h"
 
@@ -45,7 +46,9 @@
  private:
   raw_ptr<base::ObserverList<NativeEventProcessorObserver>::Unchecked>
       observer_list_;
-  NSEvent* event_;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter
+  // for: #union
+  RAW_PTR_EXCLUSION NSEvent* event_;
 };
 
 }  // namespace content
diff --git a/content/public/common/main_function_params.h b/content/public/common/main_function_params.h
index 66723f5..bc235aa 100644
--- a/content/public/common/main_function_params.h
+++ b/content/public/common/main_function_params.h
@@ -10,6 +10,7 @@
 #include "base/command_line.h"
 #include "base/functional/callback.h"
 #include "base/memory/raw_ptr.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "build/build_config.h"
 #include "content/common/content_export.h"
 
@@ -49,7 +50,10 @@
 #if BUILDFLAG(IS_WIN)
   raw_ptr<sandbox::SandboxInterfaceInfo> sandbox_info = nullptr;
 #elif BUILDFLAG(IS_MAC)
-  base::mac::ScopedNSAutoreleasePool* autorelease_pool = nullptr;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter
+  // for: #union
+  RAW_PTR_EXCLUSION base::mac::ScopedNSAutoreleasePool* autorelease_pool =
+      nullptr;
 #elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
   bool zygote_child = false;
 #endif
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h
index 53b106a1..59c6989 100644
--- a/printing/printing_context_mac.h
+++ b/printing/printing_context_mac.h
@@ -9,6 +9,7 @@
 #include <string>
 
 #include "base/mac/scoped_nsobject.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/strings/string_piece.h"
 #include "printing/mojom/print.mojom.h"
 #include "printing/print_job_constants.h"
@@ -110,7 +111,9 @@
 
   // The current page's context; only valid between NewPage and PageDone call
   // pairs.
-  CGContext* context_;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter
+  // for: #addr-of
+  RAW_PTR_EXCLUSION CGContext* context_;
 };
 
 }  // namespace printing
diff --git a/ui/accessibility/platform/ax_platform_node_cocoa.mm b/ui/accessibility/platform/ax_platform_node_cocoa.mm
index 51035a2..31179b5 100644
--- a/ui/accessibility/platform/ax_platform_node_cocoa.mm
+++ b/ui/accessibility/platform/ax_platform_node_cocoa.mm
@@ -9,6 +9,7 @@
 #include "base/logging.h"
 #include "base/mac/foundation_util.h"
 #include "base/mac/mac_util.h"
+#include "base/memory/raw_ptr_exclusion.h"
 #include "base/no_destructor.h"
 #include "base/strings/sys_string_conversions.h"
 #include "base/trace_event/trace_event.h"
@@ -232,7 +233,8 @@
 @end
 
 @implementation AXPlatformNodeCocoa {
-  ui::AXPlatformNodeBase* _node;  // Weak. Retains us.
+  // This field is not a raw_ptr<> because it requires @property rewrite.
+  RAW_PTR_EXCLUSION ui::AXPlatformNodeBase* _node;  // Weak. Retains us.
   std::unique_ptr<ui::AXAnnouncementSpec> _pendingAnnouncement;
 }
 
diff --git a/ui/gfx/native_widget_types.h b/ui/gfx/native_widget_types.h
index 73283ac..46a639b 100644
--- a/ui/gfx/native_widget_types.h
+++ b/ui/gfx/native_widget_types.h
@@ -7,6 +7,7 @@
 
 #include <stdint.h>
 
+#include "base/memory/raw_ptr_exclusion.h"
 #include "build/build_config.h"
 #include "build/chromeos_buildflags.h"
 #include "ui/gfx/gfx_export.h"
@@ -167,7 +168,9 @@
 #if defined(__has_feature) && __has_feature(objc_arc)
   __unsafe_unretained NSView* ns_view_ = nullptr;
 #else
-  NSView* ns_view_ = nullptr;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter
+  // for: #constexpr-ctor-field-initializer, #global-scope, #union
+  RAW_PTR_EXCLUSION NSView* ns_view_ = nullptr;
 #endif
 };
 class GFX_EXPORT NativeWindow {
@@ -197,7 +200,9 @@
 #if defined(__has_feature) && __has_feature(objc_arc)
   __unsafe_unretained NSWindow* ns_window_ = nullptr;
 #else
-  NSWindow* ns_window_ = nullptr;
+  // This field is not a raw_ptr<> because it was filtered by the rewriter
+  // for: #constexpr-ctor-field-initializer, #global-scope, #union
+  RAW_PTR_EXCLUSION NSWindow* ns_window_ = nullptr;
 #endif
 };
 constexpr NativeView kNullNativeView = NativeView(nullptr);