Skip to content

Commit bf2a64f

Browse files
committed
Address more Safer CPP failures in UIProcess/Cocoa
https://bugs.webkit.org/show_bug.cgi?id=290272 Reviewed by Geoffrey Garen. * Source/WebKit/SaferCPPExpectations/NoUnretainedMemberCheckerExpectations: * Source/WebKit/UIProcess/Cocoa/AutomationClient.h: * Source/WebKit/UIProcess/Cocoa/AutomationClient.mm: (WebKit::AutomationClient::remoteAutomationAllowed const): (WebKit::AutomationClient::requestAutomationSession): (WebKit::AutomationClient::requestedDebuggablesToWakeUp): (WebKit::AutomationClient::browserName const): (WebKit::AutomationClient::browserVersion const): * Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.h: * Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.mm: (WebKit::DiagnosticLoggingClient::logDiagnosticMessage): (WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithResult): (WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithValue): (WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithEnhancedPrivacy): (WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary): (WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithDomain): * Source/WebKit/UIProcess/Cocoa/FullscreenClient.h: * Source/WebKit/UIProcess/Cocoa/FullscreenClient.mm: (WebKit::FullscreenClient::willEnterFullscreen): (WebKit::FullscreenClient::didEnterFullscreen): (WebKit::FullscreenClient::willExitFullscreen): (WebKit::FullscreenClient::didExitFullscreen): (WebKit::FullscreenClient::requestPresentingViewController): Canonical link: https://commits.webkit.org/292559@main
1 parent fa52877 commit bf2a64f

11 files changed

Lines changed: 46 additions & 45 deletions
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm
2-
UIProcess/Cocoa/AutomationClient.h
3-
UIProcess/Cocoa/DiagnosticLoggingClient.h
4-
UIProcess/Cocoa/FullscreenClient.h
52
UIProcess/DisplayLink.h
63
UIProcess/WebAuthentication/Cocoa/WebAuthenticationPanelClient.h
74
UIProcess/mac/PageClientImplMac.h
85
UIProcess/mac/WebPopupMenuProxyMac.h
96
UIProcess/mac/WebViewImpl.h
107
WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
11-
WebProcess/InjectedBundle/InjectedBundle.h
8+
WebProcess/InjectedBundle/InjectedBundle.h

Source/WebKit/UIProcess/Cocoa/AutomationClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class AutomationClient final : public API::AutomationClient, Inspector::RemoteIn
5656
String browserName() const final;
5757
String browserVersion() const final;
5858

59-
WKProcessPool *m_processPool;
59+
WeakObjCPtr<WKProcessPool> m_processPool;
6060
WeakObjCPtr<id <_WKAutomationDelegate>> m_delegate;
6161

6262
struct {

Source/WebKit/UIProcess/Cocoa/AutomationClient.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
bool AutomationClient::remoteAutomationAllowed() const
7474
{
7575
if (m_delegateMethods.allowsRemoteAutomation)
76-
return [m_delegate.get() _processPoolAllowsRemoteAutomation:m_processPool];
76+
return [m_delegate.get() _processPoolAllowsRemoteAutomation:m_processPool.get().get()];
7777

7878
return false;
7979
}
@@ -94,7 +94,7 @@
9494
NSString *requestedSessionIdentifier = sessionIdentifier;
9595
RunLoop::protectedMain()->dispatch([this, requestedSessionIdentifier = retainPtr(requestedSessionIdentifier), configuration = WTFMove(configuration)] {
9696
if (m_delegateMethods.requestAutomationSession)
97-
[m_delegate.get() _processPool:m_processPool didRequestAutomationSessionWithIdentifier:requestedSessionIdentifier.get() configuration:configuration.get()];
97+
[m_delegate.get() _processPool:m_processPool.get().get() didRequestAutomationSessionWithIdentifier:requestedSessionIdentifier.get() configuration:configuration.get()];
9898
});
9999
}
100100

@@ -104,14 +104,14 @@
104104
{
105105
RunLoop::protectedMain()->dispatch([this] {
106106
if (m_delegateMethods.requestedDebuggablesToWakeUp)
107-
[m_delegate.get() _processPoolDidRequestInspectorDebuggablesToWakeUp:m_processPool];
107+
[m_delegate.get() _processPoolDidRequestInspectorDebuggablesToWakeUp:m_processPool.get().get()];
108108
});
109109
}
110110

111111
String AutomationClient::browserName() const
112112
{
113113
if (m_delegateMethods.browserNameForAutomation)
114-
return [m_delegate _processPoolBrowserNameForAutomation:m_processPool];
114+
return [m_delegate _processPoolBrowserNameForAutomation:m_processPool.get().get()];
115115

116116
// Fall back to using the unlocalized app name (i.e., 'Safari').
117117
NSBundle *appBundle = [NSBundle mainBundle];
@@ -123,7 +123,7 @@
123123
String AutomationClient::browserVersion() const
124124
{
125125
if (m_delegateMethods.browserVersionForAutomation)
126-
return [m_delegate _processPoolBrowserVersionForAutomation:m_processPool];
126+
return [m_delegate _processPoolBrowserVersionForAutomation:m_processPool.get().get()];
127127

128128
// Fall back to using the app short version (i.e., '11.1.1').
129129
NSBundle *appBundle = [NSBundle mainBundle];

Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DiagnosticLoggingClient final : public API::DiagnosticLoggingClient {
5454

5555
bool isWebKitDiagnosticLoggingClient() const final { return true; }
5656

57-
WKWebView *m_webView;
57+
WeakObjCPtr<WKWebView> m_webView;
5858
WeakObjCPtr<id <_WKDiagnosticLoggingDelegate>> m_delegate;
5959

6060
struct {

Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
void DiagnosticLoggingClient::logDiagnosticMessage(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description)
6262
{
6363
if (m_delegateMethods.webviewLogDiagnosticMessage)
64-
[m_delegate.get() _webView:m_webView logDiagnosticMessage:message description:description];
64+
[m_delegate.get() _webView:m_webView.get().get() logDiagnosticMessage:message description:description];
6565
}
6666

6767
static _WKDiagnosticLoggingResultType toWKDiagnosticLoggingResultType(WebCore::DiagnosticLoggingResultType result)
@@ -87,31 +87,31 @@ static _WKDiagnosticLoggingDomain toWKDiagnosticLoggingDomain(WebCore::Diagnosti
8787
void DiagnosticLoggingClient::logDiagnosticMessageWithResult(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, WebCore::DiagnosticLoggingResultType result)
8888
{
8989
if (m_delegateMethods.webviewLogDiagnosticMessageWithResult)
90-
[m_delegate.get() _webView:m_webView logDiagnosticMessageWithResult:message description:description result:toWKDiagnosticLoggingResultType(result)];
90+
[m_delegate.get() _webView:m_webView.get().get() logDiagnosticMessageWithResult:message description:description result:toWKDiagnosticLoggingResultType(result)];
9191
}
9292

9393
void DiagnosticLoggingClient::logDiagnosticMessageWithValue(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, const WTF::String& value)
9494
{
9595
if (m_delegateMethods.webviewLogDiagnosticMessageWithValue)
96-
[m_delegate.get() _webView:m_webView logDiagnosticMessageWithValue:message description:description value:value];
96+
[m_delegate.get() _webView:m_webView.get().get() logDiagnosticMessageWithValue:message description:description value:value];
9797
}
9898

9999
void DiagnosticLoggingClient::logDiagnosticMessageWithEnhancedPrivacy(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description)
100100
{
101101
if (m_delegateMethods.webviewLogDiagnosticMessageWithEnhancedPrivacy)
102-
[m_delegate.get() _webView:m_webView logDiagnosticMessageWithEnhancedPrivacy:message description:description];
102+
[m_delegate.get() _webView:m_webView.get().get() logDiagnosticMessageWithEnhancedPrivacy:message description:description];
103103
}
104104

105105
void DiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary(WebPageProxy*, const String& message, const String& description, Ref<API::Dictionary>&& valueDictionary)
106106
{
107107
if (m_delegateMethods.webviewLogDiagnosticMessageWithValueDictionary)
108-
[m_delegate.get() _webView:m_webView logDiagnosticMessage:message description:description valueDictionary:static_cast<NSDictionary*>(valueDictionary->wrapper())];
108+
[m_delegate.get() _webView:m_webView.get().get() logDiagnosticMessage:message description:description valueDictionary:static_cast<NSDictionary*>(valueDictionary->wrapper())];
109109
}
110110

111111
void DiagnosticLoggingClient::logDiagnosticMessageWithDomain(WebPageProxy*, const String& message, WebCore::DiagnosticLoggingDomain domain)
112112
{
113113
if (m_delegateMethods.webviewLogDiagnosticMessageWithDomain)
114-
[m_delegate.get() _webView:m_webView logDiagnosticMessageWithDomain:message domain:toWKDiagnosticLoggingDomain(domain)];
114+
[m_delegate.get() _webView:m_webView.get().get() logDiagnosticMessageWithDomain:message domain:toWKDiagnosticLoggingDomain(domain)];
115115
}
116116

117117
} // namespace WebKit

Source/WebKit/UIProcess/Cocoa/FindClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class FindClient final : public API::FindClient {
5555

5656
bool isWebKitFindClient() const final { return true; }
5757

58-
WKWebView *m_webView;
58+
WeakObjCPtr<WKWebView> m_webView;
5959
WeakObjCPtr<id <_WKFindDelegate>> m_delegate;
6060

6161
struct {

Source/WebKit/UIProcess/Cocoa/FindClient.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@
5757
void FindClient::didCountStringMatches(WebPageProxy*, const String& string, uint32_t matchCount)
5858
{
5959
if (m_delegateMethods.webviewDidCountStringMatches)
60-
[m_delegate.get() _webView:m_webView didCountMatches:matchCount forString:string];
60+
[m_delegate.get() _webView:m_webView.get().get() didCountMatches:matchCount forString:string];
6161
}
6262

6363
void FindClient::didFindString(WebPageProxy*, const String& string, const Vector<WebCore::IntRect>&, uint32_t matchCount, int32_t matchIndex, bool)
6464
{
6565
if (m_delegateMethods.webviewDidFindString)
66-
[m_delegate.get() _webView:m_webView didFindMatches:matchCount forString:string withMatchIndex:matchIndex];
66+
[m_delegate.get() _webView:m_webView.get().get() didFindMatches:matchCount forString:string withMatchIndex:matchIndex];
6767
}
6868

6969
void FindClient::didFailToFindString(WebPageProxy*, const String& string)
7070
{
7171
if (m_delegateMethods.webviewDidFailToFindString)
72-
[m_delegate.get() _webView:m_webView didFailToFindString:string];
72+
[m_delegate.get() _webView:m_webView.get().get() didFailToFindString:string];
7373
}
7474

7575
void FindClient::didAddLayerForFindOverlay(WebKit::WebPageProxy*, PlatformLayer* layer)
7676
{
7777
if (m_delegateMethods.webviewDidAddLayerForFindOverlay)
78-
[m_delegate _webView:m_webView didAddLayerForFindOverlay:layer];
78+
[m_delegate _webView:m_webView.get().get() didAddLayerForFindOverlay:layer];
7979
}
8080

8181
void FindClient::didRemoveLayerForFindOverlay(WebKit::WebPageProxy*)
8282
{
8383
if (m_delegateMethods.webviewDidRemoveLayerForFindOverlay)
84-
[m_delegate _webViewDidRemoveLayerForFindOverlay:m_webView];
84+
[m_delegate _webViewDidRemoveLayerForFindOverlay:m_webView.get().get()];
8585
}
8686

8787
} // namespace WebKit

Source/WebKit/UIProcess/Cocoa/FullscreenClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class FullscreenClient final : public API::FullscreenClient {
5858
#endif
5959

6060
private:
61-
WKWebView *m_webView;
61+
WeakObjCPtr<WKWebView> m_webView;
6262
WeakObjCPtr<id <_WKFullscreenDelegate> > m_delegate;
6363

6464
struct {

Source/WebKit/UIProcess/Cocoa/FullscreenClient.mm

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,61 +67,65 @@
6767

6868
void FullscreenClient::willEnterFullscreen(WebPageProxy*)
6969
{
70-
[m_webView willChangeValueForKey:@"fullscreenState"];
71-
[m_webView didChangeValueForKey:@"fullscreenState"];
70+
RetainPtr webView = m_webView.get();
71+
[webView willChangeValueForKey:@"fullscreenState"];
72+
[webView didChangeValueForKey:@"fullscreenState"];
7273
#if PLATFORM(MAC)
7374
if (m_delegateMethods.webViewWillEnterFullscreen)
74-
[m_delegate.get() _webViewWillEnterFullscreen:m_webView];
75+
[m_delegate.get() _webViewWillEnterFullscreen:webView.get()];
7576
#else
7677
if (m_delegateMethods.webViewWillEnterElementFullscreen)
77-
[m_delegate.get() _webViewWillEnterElementFullscreen:m_webView];
78+
[m_delegate.get() _webViewWillEnterElementFullscreen:webView.get()];
7879
#endif
7980
}
8081

8182
void FullscreenClient::didEnterFullscreen(WebPageProxy*)
8283
{
83-
[m_webView willChangeValueForKey:@"fullscreenState"];
84-
[m_webView didChangeValueForKey:@"fullscreenState"];
84+
RetainPtr webView = m_webView.get();
85+
[webView willChangeValueForKey:@"fullscreenState"];
86+
[webView didChangeValueForKey:@"fullscreenState"];
8587
#if PLATFORM(MAC)
8688
if (m_delegateMethods.webViewDidEnterFullscreen)
87-
[m_delegate.get() _webViewDidEnterFullscreen:m_webView];
89+
[m_delegate.get() _webViewDidEnterFullscreen:webView.get()];
8890
#else
8991
if (m_delegateMethods.webViewDidEnterElementFullscreen)
90-
[m_delegate.get() _webViewDidEnterElementFullscreen:m_webView];
92+
[m_delegate.get() _webViewDidEnterElementFullscreen:webView.get()];
9193
#endif
9294

9395
#if ENABLE(QUICKLOOK_FULLSCREEN)
94-
if (auto fullScreenController = [m_webView fullScreenWindowController]) {
96+
if (auto fullScreenController = [webView fullScreenWindowController]) {
9597
CGSize imageDimensions = fullScreenController.imageDimensions;
9698
if (fullScreenController.isUsingQuickLook && m_delegateMethods.webViewDidFullscreenImageWithQuickLook)
97-
[m_delegate.get() _webView:m_webView didFullscreenImageWithQuickLook:imageDimensions];
99+
[m_delegate.get() _webView:webView.get() didFullscreenImageWithQuickLook:imageDimensions];
98100
}
99101
#endif // ENABLE(QUICKLOOK_FULLSCREEN)
100102
}
101103

102104
void FullscreenClient::willExitFullscreen(WebPageProxy*)
103105
{
104-
[m_webView willChangeValueForKey:@"fullscreenState"];
105-
[m_webView didChangeValueForKey:@"fullscreenState"];
106+
RetainPtr webView = m_webView.get();
107+
[webView willChangeValueForKey:@"fullscreenState"];
108+
[webView didChangeValueForKey:@"fullscreenState"];
106109
#if PLATFORM(MAC)
107110
if (m_delegateMethods.webViewWillExitFullscreen)
108-
[m_delegate.get() _webViewWillExitFullscreen:m_webView];
111+
[m_delegate.get() _webViewWillExitFullscreen:webView.get()];
109112
#else
110113
if (m_delegateMethods.webViewWillExitElementFullscreen)
111-
[m_delegate.get() _webViewWillExitElementFullscreen:m_webView];
114+
[m_delegate.get() _webViewWillExitElementFullscreen:webView.get()];
112115
#endif
113116
}
114117

115118
void FullscreenClient::didExitFullscreen(WebPageProxy*)
116119
{
117-
[m_webView willChangeValueForKey:@"fullscreenState"];
118-
[m_webView didChangeValueForKey:@"fullscreenState"];
120+
RetainPtr webView = m_webView.get();
121+
[webView willChangeValueForKey:@"fullscreenState"];
122+
[webView didChangeValueForKey:@"fullscreenState"];
119123
#if PLATFORM(MAC)
120124
if (m_delegateMethods.webViewDidExitFullscreen)
121-
[m_delegate.get() _webViewDidExitFullscreen:m_webView];
125+
[m_delegate.get() _webViewDidExitFullscreen:webView.get()];
122126
#else
123127
if (m_delegateMethods.webViewDidExitElementFullscreen)
124-
[m_delegate.get() _webViewDidExitElementFullscreen:m_webView];
128+
[m_delegate.get() _webViewDidExitElementFullscreen:webView.get()];
125129
#endif
126130
}
127131

@@ -131,7 +135,7 @@
131135
if (!m_delegateMethods.webViewRequestPresentingViewController)
132136
return completionHandler(nil, nil);
133137

134-
[m_delegate _webView:m_webView requestPresentingViewControllerWithCompletionHandler:makeBlockPtr(WTFMove(completionHandler)).get()];
138+
[m_delegate _webView:m_webView.get().get() requestPresentingViewControllerWithCompletionHandler:makeBlockPtr(WTFMove(completionHandler)).get()];
135139
}
136140
#endif
137141

Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class IconLoadingDelegate : public CanMakeCheckedPtr<IconLoadingDelegate> {
6363
CheckedRef<IconLoadingDelegate> m_iconLoadingDelegate;
6464
};
6565

66-
WKWebView *m_webView;
66+
WeakObjCPtr<WKWebView> m_webView;
6767
WeakObjCPtr<id <_WKIconLoadingDelegate> > m_delegate;
6868

6969
struct {

0 commit comments

Comments
 (0)