Skip to content

Commit f92ac66

Browse files
committed
Address safer CPP failures in PageClientImplMac.h
https://bugs.webkit.org/show_bug.cgi?id=290217 Reviewed by Geoffrey Garen. * Source/WebKit/SaferCPPExpectations/NoUnretainedMemberCheckerExpectations: * Source/WebKit/UIProcess/mac/PageClientImplMac.h: * Source/WebKit/UIProcess/mac/PageClientImplMac.mm: (WebKit::PageClientImpl::activeView const): (WebKit::PageClientImpl::activeWindow const): (WebKit::PageClientImpl::assistiveTechnologyMakeFirstResponder): (WebKit::PageClientImpl::makeFirstResponder): (WebKit::PageClientImpl::setCursor): (WebKit::PageClientImpl::screenToRootView): (WebKit::PageClientImpl::rootViewToScreen): (WebKit::PageClientImpl::createPopupMenuProxy): (WebKit::PageClientImpl::createContextMenuProxy): (WebKit::PageClientImpl::createColorPicker): (WebKit::PageClientImpl::createDataListSuggestionsDropdown): (WebKit::PageClientImpl::createDateTimePicker): (WebKit::PageClientImpl::createValidationBubble): (WebKit::PageClientImpl::didPerformDictionaryLookup): (WebKit::PageClientImpl::showCorrectionPanel): (WebKit::PageClientImpl::showDictationAlternativeUI): (WebKit::PageClientImpl::didFinishNavigation): (WebKit::PageClientImpl::didFailNavigation): (WebKit::PageClientImpl::boundsOfLayerInLayerBackedWindowCoordinates const): (WebKit::PageClientImpl::showPlatformContextMenu): (WebKit::PageClientImpl::refView): (WebKit::PageClientImpl::derefView): (WebKit::PageClientImpl::userInterfaceLayoutDirection): (WebKit::PageClientImpl::handleContextMenuWritingTools): Canonical link: https://commits.webkit.org/292568@main
1 parent 408eb97 commit f92ac66

5 files changed

Lines changed: 37 additions & 32 deletions

File tree

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
UIProcess/mac/PageClientImplMac.h

Source/WebKit/UIProcess/mac/PageClientImplMac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <WebCore/DOMPasteAccess.h>
3434
#include <wtf/CompletionHandler.h>
3535
#include <wtf/Forward.h>
36+
#include <wtf/WeakObjCPtr.h>
3637

3738
@class WKEditorUndoTarget;
3839
@class WKView;
@@ -327,7 +328,7 @@ class PageClientImpl final : public PageClientImplCocoa
327328
void didCleanupFullscreen() final { }
328329
#endif
329330

330-
NSView *m_view;
331+
WeakObjCPtr<NSView> m_view;
331332
WeakPtr<WebViewImpl> m_impl;
332333
#if USE(AUTOCORRECTION_PANEL)
333334
CorrectionPanel m_correctionPanel;

Source/WebKit/UIProcess/mac/PageClientImplMac.mm

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ - (BOOL)_hostsLayersInWindowServer;
155155

156156
NSView *PageClientImpl::activeView() const
157157
{
158-
return (m_impl && m_impl->thumbnailView()) ? (NSView *)m_impl->thumbnailView() : m_view;
158+
return (m_impl && m_impl->thumbnailView()) ? (NSView *)m_impl->thumbnailView() : m_view.getAutoreleased();
159159
}
160160

161161
NSWindow *PageClientImpl::activeWindow() const
@@ -164,7 +164,7 @@ - (BOOL)_hostsLayersInWindowServer;
164164
return [m_impl->thumbnailView() window];
165165
if (m_impl && m_impl->targetWindowForMovePreparation())
166166
return m_impl->targetWindowForMovePreparation();
167-
return m_view.window;
167+
return [m_view window];
168168
}
169169

170170
bool PageClientImpl::isViewWindowActive()
@@ -186,15 +186,15 @@ - (BOOL)_hostsLayersInWindowServer;
186186

187187
void PageClientImpl::assistiveTechnologyMakeFirstResponder()
188188
{
189-
[[m_view window] makeFirstResponder:m_view];
189+
[[m_view window] makeFirstResponder:m_view.get().get()];
190190
}
191191

192192
void PageClientImpl::makeFirstResponder()
193193
{
194194
if (m_shouldSuppressFirstResponderChanges)
195195
return;
196196

197-
[[m_view window] makeFirstResponder:m_view];
197+
[[m_view window] makeFirstResponder:m_view.get().get()];
198198
}
199199

200200
bool PageClientImpl::isViewVisible()
@@ -323,10 +323,11 @@ - (BOOL)_hostsLayersInWindowServer;
323323
if ([NSApp _cursorRectCursor])
324324
return;
325325

326-
if (!m_view)
326+
RetainPtr view = m_view.get();
327+
if (!view)
327328
return;
328329

329-
NSWindow *window = [m_view window];
330+
NSWindow *window = [view window];
330331
if (!window)
331332
return;
332333

@@ -338,7 +339,7 @@ - (BOOL)_hostsLayersInWindowServer;
338339
if ([NSCursor currentCursor] == platformCursor)
339340
return;
340341

341-
if (m_impl->imageAnalysisOverlayViewHasCursorAtPoint([m_view convertPoint:mouseLocationInScreen fromView:nil]))
342+
if (m_impl->imageAnalysisOverlayViewHasCursorAtPoint([view convertPoint:mouseLocationInScreen fromView:nil]))
342343
return;
343344

344345
[platformCursor set];
@@ -453,20 +454,20 @@ - (BOOL)_hostsLayersInWindowServer;
453454

454455
IntPoint PageClientImpl::screenToRootView(const IntPoint& point)
455456
{
456-
NSPoint windowCoord = [m_view.window convertPointFromScreen:point];
457+
NSPoint windowCoord = [[m_view window] convertPointFromScreen:point];
457458
return IntPoint([m_view convertPoint:windowCoord fromView:nil]);
458459
}
459460

460461
IntPoint PageClientImpl::rootViewToScreen(const IntPoint& point)
461462
{
462-
return IntPoint([m_view.window convertPointToScreen:[m_view convertPoint:point toView:nil]]);
463+
return IntPoint([[m_view window] convertPointToScreen:[m_view convertPoint:point toView:nil]]);
463464
}
464465

465466
IntRect PageClientImpl::rootViewToScreen(const IntRect& rect)
466467
{
467468
NSRect tempRect = rect;
468469
tempRect = [m_view convertRect:tempRect toView:nil];
469-
tempRect.origin = [m_view.window convertPointToScreen:tempRect.origin];
470+
tempRect.origin = [[m_view window] convertPointToScreen:tempRect.origin];
470471
return enclosingIntRect(tempRect);
471472
}
472473

@@ -508,14 +509,14 @@ - (BOOL)_hostsLayersInWindowServer;
508509

509510
RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy& page)
510511
{
511-
return WebPopupMenuProxyMac::create(m_view, page.popupMenuClient());
512+
return WebPopupMenuProxyMac::create(m_view.get().get(), page.popupMenuClient());
512513
}
513514

514515
#if ENABLE(CONTEXT_MENUS)
515516

516517
Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, FrameInfoData&& frameInfo, ContextMenuContextData&& context, const UserData& userData)
517518
{
518-
return WebContextMenuProxyMac::create(m_view, page, WTFMove(frameInfo), WTFMove(context), userData);
519+
return WebContextMenuProxyMac::create(m_view.get().get(), page, WTFMove(frameInfo), WTFMove(context), userData);
519520
}
520521

521522
void PageClientImpl::didShowContextMenu()
@@ -532,22 +533,22 @@ - (BOOL)_hostsLayersInWindowServer;
532533

533534
RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy& page, const WebCore::Color& initialColor, const WebCore::IntRect& rect, ColorControlSupportsAlpha supportsAlpha, Vector<WebCore::Color>&& suggestions)
534535
{
535-
return WebColorPickerMac::create(&page.colorPickerClient(), initialColor, rect, supportsAlpha, WTFMove(suggestions), m_view);
536+
return WebColorPickerMac::create(&page.colorPickerClient(), initialColor, rect, supportsAlpha, WTFMove(suggestions), m_view.get().get());
536537
}
537538

538539
RefPtr<WebDataListSuggestionsDropdown> PageClientImpl::createDataListSuggestionsDropdown(WebPageProxy& page)
539540
{
540-
return WebDataListSuggestionsDropdownMac::create(page, m_view);
541+
return WebDataListSuggestionsDropdownMac::create(page, m_view.get().get());
541542
}
542543

543544
RefPtr<WebDateTimePicker> PageClientImpl::createDateTimePicker(WebPageProxy& page)
544545
{
545-
return WebDateTimePickerMac::create(page, m_view);
546+
return WebDateTimePickerMac::create(page, m_view.get().get());
546547
}
547548

548549
Ref<ValidationBubble> PageClientImpl::createValidationBubble(const String& message, const ValidationBubble::Settings& settings)
549550
{
550-
return ValidationBubble::create(m_view, message, settings);
551+
return ValidationBubble::create(m_view.get().get(), message, settings);
551552
}
552553

553554
void PageClientImpl::showBrowsingWarning(const BrowsingWarning& warning, CompletionHandler<void(std::variant<WebKit::ContinueUnsafeLoad, URL>&&)>&& completionHandler)
@@ -693,7 +694,7 @@ - (BOOL)_hostsLayersInWindowServer;
693694
{
694695
m_impl->prepareForDictionaryLookup();
695696

696-
DictionaryLookup::showPopup(dictionaryPopupInfo, m_view, [this](TextIndicator& textIndicator) {
697+
DictionaryLookup::showPopup(dictionaryPopupInfo, m_view.get().get(), [this](TextIndicator& textIndicator) {
697698
m_impl->setTextIndicator(textIndicator, WebCore::TextIndicatorLifetime::Permanent);
698699
}, nullptr, [this]() {
699700
m_impl->clearTextIndicatorWithAnimation(WebCore::TextIndicatorDismissalAnimation::None);
@@ -705,7 +706,7 @@ - (BOOL)_hostsLayersInWindowServer;
705706
#if USE(AUTOCORRECTION_PANEL)
706707
if (!isViewVisible() || !isViewInWindow())
707708
return;
708-
m_correctionPanel.show(m_view, *m_impl, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
709+
m_correctionPanel.show(m_view.get().get(), *m_impl, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
709710
#endif
710711
}
711712

@@ -771,7 +772,7 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
771772
{
772773
if (!isViewVisible() || !isViewInWindow())
773774
return;
774-
m_alternativeTextUIController->showAlternatives(m_view, boundingBoxOfDictatedText, dictationContext, ^(NSString *acceptedAlternative) {
775+
m_alternativeTextUIController->showAlternatives(m_view.get().get(), boundingBoxOfDictatedText, dictationContext, ^(NSString *acceptedAlternative) {
775776
m_impl->handleAcceptedAlternativeText(acceptedAlternative);
776777
});
777778
}
@@ -921,15 +922,15 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
921922
if (RefPtr gestureController = m_impl->gestureController())
922923
gestureController->didFinishNavigation(navigation);
923924

924-
NSAccessibilityPostNotification(NSAccessibilityUnignoredAncestor(m_view), kAXLoadCompleteNotification);
925+
NSAccessibilityPostNotification(NSAccessibilityUnignoredAncestor(m_view.get().get()), kAXLoadCompleteNotification);
925926
}
926927

927928
void PageClientImpl::didFailNavigation(API::Navigation* navigation)
928929
{
929930
if (RefPtr gestureController = m_impl->gestureController())
930931
gestureController->didFailNavigation(navigation);
931932

932-
NSAccessibilityPostNotification(NSAccessibilityUnignoredAncestor(m_view), kAXLoadCompleteNotification);
933+
NSAccessibilityPostNotification(NSAccessibilityUnignoredAncestor(m_view.get().get()), kAXLoadCompleteNotification);
933934
}
934935

935936
void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type)
@@ -950,7 +951,7 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
950951

951952
CGRect PageClientImpl::boundsOfLayerInLayerBackedWindowCoordinates(CALayer *layer) const
952953
{
953-
CALayer *windowContentLayer = static_cast<NSView *>(m_view.window.contentView).layer;
954+
CALayer *windowContentLayer = static_cast<NSView *>([m_view window].contentView).layer;
954955
ASSERT(windowContentLayer);
955956

956957
return [windowContentLayer convertRect:layer.bounds fromLayer:layer];
@@ -974,7 +975,7 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
974975

975976
void PageClientImpl::showPlatformContextMenu(NSMenu *menu, IntPoint location)
976977
{
977-
[menu popUpMenuPositioningItem:nil atLocation:location inView:m_view];
978+
[menu popUpMenuPositioningItem:nil atLocation:location inView:m_view.get().get()];
978979
}
979980

980981
#if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -986,12 +987,14 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
986987

987988
void PageClientImpl::refView()
988989
{
989-
CFRetain((__bridge CFTypeRef)m_view);
990+
if (RetainPtr view = m_view.get())
991+
CFRetain((__bridge CFTypeRef)view.get());
990992
}
991993

992994
void PageClientImpl::derefView()
993995
{
994-
CFRelease((__bridge CFTypeRef)m_view);
996+
if (RetainPtr view = m_view.get())
997+
CFRelease((__bridge CFTypeRef)view.get());
995998
}
996999

9971000
void PageClientImpl::startWindowDrag()
@@ -1053,9 +1056,10 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
10531056

10541057
WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
10551058
{
1056-
if (!m_view)
1059+
RetainPtr view = m_view.get();
1060+
if (!view)
10571061
return WebCore::UserInterfaceLayoutDirection::LTR;
1058-
return (m_view.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionLeftToRight) ? WebCore::UserInterfaceLayoutDirection::LTR : WebCore::UserInterfaceLayoutDirection::RTL;
1062+
return ([view userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionLeftToRight) ? WebCore::UserInterfaceLayoutDirection::LTR : WebCore::UserInterfaceLayoutDirection::RTL;
10591063
}
10601064

10611065
bool PageClientImpl::effectiveAppearanceIsDark() const
@@ -1143,7 +1147,7 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
11431147
{
11441148
RetainPtr webView = this->webView();
11451149
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
1146-
[[PAL::getWTWritingToolsClass() sharedInstance] showTool:WebKit::convertToPlatformRequestedTool(tool) forSelectionRect:selectionRect ofView:m_view forDelegate:webView.get()];
1150+
[[PAL::getWTWritingToolsClass() sharedInstance] showTool:WebKit::convertToPlatformRequestedTool(tool) forSelectionRect:selectionRect ofView:m_view.get().get() forDelegate:webView.get()];
11471151
ALLOW_DEPRECATED_DECLARATIONS_END
11481152
}
11491153

Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#import "WebDataListSuggestionsDropdown.h"
3131
#import <wtf/RetainPtr.h>
32+
#import <wtf/WeakObjCPtr.h>
3233

3334
OBJC_CLASS WKDataListSuggestionsController;
3435

@@ -50,7 +51,7 @@ class WebDataListSuggestionsDropdownMac final : public WebDataListSuggestionsDro
5051

5152
void selectOption();
5253

53-
NSView *m_view;
54+
WeakObjCPtr<NSView> m_view;
5455
RetainPtr<WKDataListSuggestionsController> m_dropdownUI;
5556
};
5657

Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ - (String)currentSelectedString;
8888
return;
8989
}
9090

91-
m_dropdownUI = adoptNS([[WKDataListSuggestionsController alloc] initWithInformation:WTFMove(information) inView:m_view]);
91+
m_dropdownUI = adoptNS([[WKDataListSuggestionsController alloc] initWithInformation:WTFMove(information) inView:m_view.get().get()]);
9292
[m_dropdownUI showSuggestionsDropdown:*this];
9393
}
9494

0 commit comments

Comments
 (0)