Skip to content

Commit dbbcfa7

Browse files
committed
Address more NoUnretainedMemberChecker warnings in WebCore/
https://bugs.webkit.org/show_bug.cgi?id=290277 Reviewed by Geoffrey Garen. * Source/WebCore/SaferCPPExpectations/NoUnretainedMemberCheckerExpectations: * Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm: (WebCore::drawMemHistory): * Source/WebCore/page/mac/TextIndicatorWindow.h: * Source/WebCore/platform/ValidationBubble.h: * Source/WebCore/platform/graphics/FontPlatformData.h: (WebCore::ScopedTextMatrix::ScopedTextMatrix): (WebCore::ScopedTextMatrix::~ScopedTextMatrix): * Source/WebCore/platform/graphics/cg/CGContextStateSaver.h: (WebCore::CGContextStateSaver::CGContextStateSaver): (WebCore::CGContextStateSaver::~CGContextStateSaver): (WebCore::CGContextStateSaver::save): (WebCore::CGContextStateSaver::restore): * Source/WebCore/platform/graphics/coretext/ComplexTextControllerCoreText.mm: (WebCore::provideStringAndAttributes): * Source/WebCore/platform/ios/ValidationBubbleIOS.mm: (WebCore::ValidationBubble::setAnchorRect): * Source/WebCore/platform/mac/ValidationBubbleMac.mm: (WebCore::ValidationBubble::showRelativeTo): * Source/WebCore/platform/network/ResourceHandleInternal.h: * Source/WebCore/platform/network/mac/ResourceHandleMac.mm: (WebCore::ResourceHandle::cancel): (WebCore::ResourceHandle::didReceiveAuthenticationChallenge): (WebCore::ResourceHandle::receivedCredential): (WebCore::ResourceHandle::receivedRequestToContinueWithoutCredential): (WebCore::ResourceHandle::receivedRequestToPerformDefaultHandling): (WebCore::ResourceHandle::receivedChallengeRejection): Canonical link: https://commits.webkit.org/292560@main
1 parent bf2a64f commit dbbcfa7

12 files changed

Lines changed: 42 additions & 37 deletions

Source/WebCore/SaferCPPExpectations/ForwardDeclCheckerExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ platform/mac/DataDetectorHighlight.mm
154154
platform/mediarecorder/MediaRecorderPrivateEncoder.h
155155
platform/mediastream/libwebrtc/LibWebRTCDav1dDecoder.cpp
156156
platform/mediastream/mac/CoreAudioSharedUnit.h
157-
platform/network/ResourceHandleInternal.h
158157
platform/network/cocoa/CredentialCocoa.h
159158
platform/network/cocoa/ProtectionSpaceCocoa.h
160159
platform/network/mac/FormDataStreamMac.mm

Source/WebCore/SaferCPPExpectations/NoUnretainedMemberCheckerExpectations

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ PAL/pal/spi/mac/NSGraphicsSPI.h
33
accessibility/mac/AccessibilityObjectMac.mm
44
accessibility/mac/WebAccessibilityObjectWrapperBase.mm
55
page/EventHandler.h
6-
page/cocoa/ResourceUsageOverlayCocoa.mm
7-
page/mac/TextIndicatorWindow.h
8-
platform/ValidationBubble.h
9-
platform/graphics/FontPlatformData.h
10-
platform/graphics/cg/CGContextStateSaver.h
116
platform/graphics/cg/CGSubimageCacheWithTimer.cpp
12-
platform/graphics/coretext/ComplexTextControllerCoreText.mm
137
platform/graphics/mac/LegacyDisplayRefreshMonitorMac.h
14-
platform/network/ResourceHandleInternal.h
15-
platform/network/cf/FormDataStreamCFNet.cpp
8+
platform/network/cf/FormDataStreamCFNet.cpp

Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static void drawMemHistory(CGContextRef context, float x1, float y1, float y2, H
373373
CGContextSetLineWidth(context, 1);
374374

375375
struct ColorAndSize {
376-
CGColorRef color;
376+
RetainPtr<CGColorRef> color;
377377
size_t size;
378378
};
379379

@@ -396,7 +396,7 @@ static void drawMemHistory(CGContextRef context, float x1, float y1, float y2, H
396396
CGContextBeginPath(context);
397397
CGContextMoveToPoint(context, x1 + i, currentY2);
398398
CGContextAddLineToPoint(context, x1 + i, nextY2);
399-
CGContextSetStrokeColorWithColor(context, colorAndSize.color);
399+
CGContextSetStrokeColorWithColor(context, colorAndSize.color.get());
400400
CGContextStrokePath(context);
401401
currentY2 = nextY2;
402402
}

Source/WebCore/page/mac/TextIndicatorWindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#import <wtf/RetainPtr.h>
3333
#import <wtf/RunLoop.h>
3434
#import <wtf/TZoneMalloc.h>
35+
#import <wtf/WeakObjCPtr.h>
3536

3637
OBJC_CLASS NSView;
3738
OBJC_CLASS WebTextIndicatorLayer;
@@ -58,7 +59,7 @@ class TextIndicatorWindow final : public CanMakeCheckedPtr<TextIndicatorWindow>
5859

5960
void startFadeOut();
6061

61-
NSView *m_targetView;
62+
WeakObjCPtr<NSView> m_targetView;
6263
RefPtr<TextIndicator> m_textIndicator;
6364
RetainPtr<NSWindow> m_textIndicatorWindow;
6465
RetainPtr<NSView> m_textIndicatorView;

Source/WebCore/platform/ValidationBubble.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ class ValidationBubble : public RefCounted<ValidationBubble> {
9696
WEBCORE_EXPORT ValidationBubble(PlatformView*, const String& message, const Settings&);
9797
#endif
9898

99+
#if PLATFORM(COCOA)
100+
WeakObjCPtr<PlatformView> m_view;
101+
#else
99102
PlatformView* m_view;
103+
#endif
100104
String m_message;
101105
double m_fontSize { 0 };
102106
#if PLATFORM(MAC)

Source/WebCore/platform/graphics/FontPlatformData.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,12 @@ class ScopedTextMatrix {
510510
: m_context(context)
511511
, m_textMatrix(CGContextGetTextMatrix(context))
512512
{
513-
CGContextSetTextMatrix(m_context, newMatrix);
513+
CGContextSetTextMatrix(m_context.get(), newMatrix);
514514
}
515515

516516
~ScopedTextMatrix()
517517
{
518-
CGContextSetTextMatrix(m_context, m_textMatrix);
518+
CGContextSetTextMatrix(m_context.get(), m_textMatrix);
519519
}
520520

521521
CGAffineTransform savedMatrix() const
@@ -524,7 +524,7 @@ class ScopedTextMatrix {
524524
}
525525

526526
private:
527-
CGContextRef m_context;
527+
RetainPtr<CGContextRef> m_context;
528528
CGAffineTransform m_textMatrix;
529529
};
530530

Source/WebCore/platform/graphics/cg/CGContextStateSaver.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ class CGContextStateSaver {
3636
, m_saveAndRestore(saveAndRestore)
3737
{
3838
if (m_saveAndRestore)
39-
CGContextSaveGState(m_context);
39+
CGContextSaveGState(m_context.get());
4040
}
4141

4242
~CGContextStateSaver()
4343
{
4444
if (m_saveAndRestore)
45-
CGContextRestoreGState(m_context);
45+
CGContextRestoreGState(m_context.get());
4646
}
4747

4848
void save()
4949
{
5050
ASSERT(!m_saveAndRestore);
51-
CGContextSaveGState(m_context);
51+
CGContextSaveGState(m_context.get());
5252
m_saveAndRestore = true;
5353
}
5454

5555
void restore()
5656
{
5757
ASSERT(m_saveAndRestore);
58-
CGContextRestoreGState(m_context);
58+
CGContextRestoreGState(m_context.get());
5959
m_saveAndRestore = false;
6060
}
6161

@@ -65,7 +65,7 @@ class CGContextStateSaver {
6565
}
6666

6767
private:
68-
CGContextRef m_context;
68+
RetainPtr<CGContextRef> m_context;
6969
bool m_saveAndRestore;
7070
};
7171

Source/WebCore/platform/graphics/coretext/ComplexTextControllerCoreText.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137

138138
struct ProviderInfo {
139139
std::span<const UChar> cp;
140-
CFDictionaryRef attributes;
140+
RetainPtr<CFDictionaryRef> attributes;
141141
};
142142

143143
static const UniChar* provideStringAndAttributes(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void* refCon)
@@ -147,7 +147,7 @@
147147
return 0;
148148

149149
*charCount = info->cp.size() - stringIndex;
150-
*attributes = info->attributes;
150+
*attributes = info->attributes.get();
151151
return reinterpret_cast<const UniChar*>(info->cp.subspan(stringIndex).data());
152152
}
153153

Source/WebCore/platform/ios/ValidationBubbleIOS.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,18 @@ - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(
218218

219219
void ValidationBubble::setAnchorRect(const IntRect& anchorRect, UIViewController *presentingViewController)
220220
{
221+
RetainPtr view = m_view.get();
221222
if (!presentingViewController)
222-
presentingViewController = fallbackViewController(m_view);
223+
presentingViewController = fallbackViewController(view.get());
223224

224225
if (!presentingViewController)
225226
return;
226227

227228
UIPopoverPresentationController *presentationController = [m_popoverController popoverPresentationController];
228229
m_popoverDelegate = adoptNS([[WebValidationBubbleDelegate alloc] init]);
229230
presentationController.delegate = m_popoverDelegate.get();
230-
presentationController.passthroughViews = @[ presentingViewController.view, m_view ];
231-
presentationController.sourceView = m_view;
231+
presentationController.passthroughViews = @[ presentingViewController.view, view.get() ];
232+
presentationController.sourceView = view.get();
232233
presentationController.sourceRect = CGRectMake(anchorRect.x(), anchorRect.y(), anchorRect.width(), anchorRect.height());
233234
m_presentingViewController = presentingViewController;
234235
}

Source/WebCore/platform/mac/ValidationBubbleMac.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ - (void)mouseDown:(NSEvent *)event
8787
void ValidationBubble::showRelativeTo(const IntRect& anchorRect)
8888
{
8989
// Passing an unparented view to [m_popover showRelativeToRect:ofView:preferredEdge:] crashes.
90-
if (![m_view window])
90+
RetainPtr view = m_view.get();
91+
if (![view window])
9192
return;
9293

9394
NSRect rect = NSMakeRect(anchorRect.x(), anchorRect.y(), anchorRect.width(), anchorRect.height());
94-
[m_popover showRelativeToRect:rect ofView:m_view preferredEdge:NSMinYEdge];
95+
[m_popover showRelativeToRect:rect ofView:view.get() preferredEdge:NSMinYEdge];
9596
}
9697

9798
} // namespace WebCore

0 commit comments

Comments
 (0)