Skip to content

Commit 2394366

Browse files
kmonsenzakariaridouh
authored andcommitted
Fixing SaferCPP warnings in InjectedBundle.cpp
https://bugs.webkit.org/show_bug.cgi?id=290078 rdar://problem/147455928 Reviewed by Chris Dumez. * Source/WebKit/SaferCPPExpectations/UncountedCallArgsCheckerExpectations: * Source/WebKit/SaferCPPExpectations/UncountedLocalVarsCheckerExpectations: * Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp: (WebKit::InjectedBundle::postMessage): (WebKit::InjectedBundle::postSynchronousMessage): (WebKit::InjectedBundle::addOriginAccessAllowListEntry): (WebKit::InjectedBundle::removeOriginAccessAllowListEntry): (WebKit::InjectedBundle::resetOriginAccessAllowLists): (WebKit::InjectedBundle::numberOfPages): (WebKit::InjectedBundle::pageNumberForElementById): (WebKit::InjectedBundle::pageSizeAndMarginsInPixels): (WebKit::InjectedBundle::isPageBoxVisible): (WebKit::InjectedBundle::removeAllWebNotificationPermissions): (WebKit::InjectedBundle::webNotificationID): (WebKit::InjectedBundle::liveDocumentURLs): * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::protectedNotificationPermissionRequestManager): * Source/WebKit/WebProcess/WebPage/WebPage.h: Canonical link: https://commits.webkit.org/292544@main
1 parent 190edba commit 2394366

5 files changed

Lines changed: 27 additions & 23 deletions

File tree

Source/WebKit/SaferCPPExpectations/UncountedCallArgsCheckerExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm
168168
WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
169169
WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
170170
WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
171-
WebProcess/InjectedBundle/InjectedBundle.cpp
172171
WebProcess/InjectedBundle/InjectedBundleDOMWindowExtension.cpp
173172
WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp
174173
WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp

Source/WebKit/SaferCPPExpectations/UncountedLocalVarsCheckerExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
2727
WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.cpp
2828
WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
2929
WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
30-
WebProcess/InjectedBundle/InjectedBundle.cpp
3130
WebProcess/InjectedBundle/InjectedBundleDOMWindowExtension.cpp
3231
WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp
3332
WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.cpp

Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,36 +126,36 @@ void InjectedBundle::setServiceWorkerProxyCreationCallback(void (*callback)(uint
126126
void InjectedBundle::postMessage(const String& messageName, API::Object* messageBody)
127127
{
128128
auto& webProcess = WebProcess::singleton();
129-
webProcess.parentProcessConnection()->send(Messages::WebProcessPool::HandleMessage(messageName, UserData(webProcess.transformObjectsToHandles(messageBody))), 0);
129+
webProcess.protectedParentProcessConnection()->send(Messages::WebProcessPool::HandleMessage(messageName, UserData(webProcess.transformObjectsToHandles(messageBody))), 0);
130130
}
131131

132132
void InjectedBundle::postSynchronousMessage(const String& messageName, API::Object* messageBody, RefPtr<API::Object>& returnData)
133133
{
134134
auto& webProcess = WebProcess::singleton();
135-
auto sendResult = webProcess.parentProcessConnection()->sendSync(Messages::WebProcessPool::HandleSynchronousMessage(messageName, UserData(webProcess.transformObjectsToHandles(messageBody))), 0);
135+
auto sendResult = webProcess.protectedParentProcessConnection()->sendSync(Messages::WebProcessPool::HandleSynchronousMessage(messageName, UserData(webProcess.transformObjectsToHandles(messageBody))), 0);
136136
if (sendResult.succeeded()) {
137137
auto [returnUserData] = sendResult.takeReply();
138-
returnData = webProcess.transformHandlesToObjects(returnUserData.object());
138+
returnData = webProcess.transformHandlesToObjects(returnUserData.protectedObject().get());
139139
} else
140140
returnData = nullptr;
141141
}
142142

143143
void InjectedBundle::addOriginAccessAllowListEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
144144
{
145145
SecurityPolicy::addOriginAccessAllowlistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains);
146-
WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::AddOriginAccessAllowListEntry { sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains }, 0);
146+
WebProcess::singleton().ensureNetworkProcessConnection().protectedConnection()->send(Messages::NetworkConnectionToWebProcess::AddOriginAccessAllowListEntry { sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains }, 0);
147147
}
148148

149149
void InjectedBundle::removeOriginAccessAllowListEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
150150
{
151151
SecurityPolicy::removeOriginAccessAllowlistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains);
152-
WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RemoveOriginAccessAllowListEntry { sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains }, 0);
152+
WebProcess::singleton().ensureNetworkProcessConnection().protectedConnection()->send(Messages::NetworkConnectionToWebProcess::RemoveOriginAccessAllowListEntry { sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains }, 0);
153153
}
154154

155155
void InjectedBundle::resetOriginAccessAllowLists()
156156
{
157157
SecurityPolicy::resetOriginAccessAllowlists();
158-
WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::ResetOriginAccessAllowLists { }, 0);
158+
WebProcess::singleton().ensureNetworkProcessConnection().protectedConnection()->send(Messages::NetworkConnectionToWebProcess::ResetOriginAccessAllowLists { }, 0);
159159
}
160160

161161
void InjectedBundle::setAsynchronousSpellCheckingEnabled(bool enabled)
@@ -167,13 +167,13 @@ void InjectedBundle::setAsynchronousSpellCheckingEnabled(bool enabled)
167167

168168
int InjectedBundle::numberOfPages(WebFrame* frame, double pageWidthInPixels, double pageHeightInPixels)
169169
{
170-
auto* coreFrame = frame ? frame->coreLocalFrame() : nullptr;
170+
RefPtr coreFrame = frame ? frame->coreLocalFrame() : nullptr;
171171
if (!coreFrame)
172172
return -1;
173173
if (!pageWidthInPixels)
174-
pageWidthInPixels = coreFrame->view()->width();
174+
pageWidthInPixels = coreFrame->protectedView()->width();
175175
if (!pageHeightInPixels)
176-
pageHeightInPixels = coreFrame->view()->height();
176+
pageHeightInPixels = coreFrame->protectedView()->height();
177177

178178
return PrintContext::numberOfPages(*coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
179179
}
@@ -184,34 +184,34 @@ int InjectedBundle::pageNumberForElementById(WebFrame* frame, const String& id,
184184
if (!coreFrame)
185185
return -1;
186186

187-
RefPtr element = coreFrame->document()->getElementById(id);
187+
RefPtr element = coreFrame->protectedDocument()->getElementById(id);
188188
if (!element)
189189
return -1;
190190

191191
if (!pageWidthInPixels)
192-
pageWidthInPixels = coreFrame->view()->width();
192+
pageWidthInPixels = coreFrame->protectedView()->width();
193193
if (!pageHeightInPixels)
194-
pageHeightInPixels = coreFrame->view()->height();
194+
pageHeightInPixels = coreFrame->protectedView()->height();
195195

196196
return PrintContext::pageNumberForElement(element.get(), FloatSize(pageWidthInPixels, pageHeightInPixels));
197197
}
198198

199199
String InjectedBundle::pageSizeAndMarginsInPixels(WebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
200200
{
201-
auto* coreFrame = frame ? frame->coreLocalFrame() : nullptr;
201+
RefPtr coreFrame = frame ? frame->coreLocalFrame() : nullptr;
202202
if (!coreFrame)
203203
return String();
204204

205-
return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height, marginTop, marginRight, marginBottom, marginLeft);
205+
return PrintContext::pageSizeAndMarginsInPixels(coreFrame.get(), pageIndex, width, height, marginTop, marginRight, marginBottom, marginLeft);
206206
}
207207

208208
bool InjectedBundle::isPageBoxVisible(WebFrame* frame, int pageIndex)
209209
{
210-
auto* coreFrame = frame ? frame->coreLocalFrame() : nullptr;
210+
RefPtr coreFrame = frame ? frame->coreLocalFrame() : nullptr;
211211
if (!coreFrame)
212212
return false;
213213

214-
return PrintContext::isPageBoxVisible(coreFrame, pageIndex);
214+
return PrintContext::isPageBoxVisible(coreFrame.get(), pageIndex);
215215
}
216216

217217
bool InjectedBundle::isProcessingUserGesture()
@@ -276,7 +276,7 @@ void InjectedBundle::setUserStyleSheetLocation(const String& location)
276276
void InjectedBundle::removeAllWebNotificationPermissions(WebPage* page)
277277
{
278278
#if ENABLE(NOTIFICATIONS)
279-
page->notificationPermissionRequestManager()->removeAllPermissionsForTesting();
279+
page->protectedNotificationPermissionRequestManager()->removeAllPermissionsForTesting();
280280
#else
281281
UNUSED_PARAM(page);
282282
#endif
@@ -285,7 +285,7 @@ void InjectedBundle::removeAllWebNotificationPermissions(WebPage* page)
285285
std::optional<WTF::UUID> InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
286286
{
287287
#if ENABLE(NOTIFICATIONS)
288-
WebCore::Notification* notification = JSNotification::toWrapped(toJS(jsContext)->vm(), toJS(toJS(jsContext), jsNotification));
288+
RefPtr notification = JSNotification::toWrapped(toJS(jsContext)->vm(), toJS(toJS(jsContext), jsNotification));
289289
if (!notification)
290290
return std::nullopt;
291291
return notification->identifier();
@@ -314,11 +314,11 @@ InjectedBundle::DocumentIDToURLMap InjectedBundle::liveDocumentURLs(bool exclude
314314

315315
if (excludeDocumentsInPageGroupPages) {
316316
Page::forEachPage([&](Page& page) {
317-
for (auto* frame = &page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
318-
auto* localFrame = dynamicDowncast<LocalFrame>(frame);
317+
for (RefPtr frame = &page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
318+
RefPtr localFrame = dynamicDowncast<LocalFrame>(frame);
319319
if (!localFrame)
320320
continue;
321-
auto* document = localFrame->document();
321+
RefPtr document = localFrame->document();
322322
if (!document)
323323
continue;
324324
result.remove(document->identifier().object());

Source/WebKit/WebProcess/WebPage/WebPage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5472,6 +5472,11 @@ NotificationPermissionRequestManager* WebPage::notificationPermissionRequestMana
54725472
return m_notificationPermissionRequestManager.get();
54735473
}
54745474

5475+
RefPtr<NotificationPermissionRequestManager> WebPage::protectedNotificationPermissionRequestManager()
5476+
{
5477+
return notificationPermissionRequestManager();
5478+
}
5479+
54755480
#if ENABLE(DRAG_SUPPORT)
54765481

54775482
#if PLATFORM(GTK)

Source/WebKit/WebProcess/WebPage/WebPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
11341134
void swipeAnimationDidEnd();
11351135

11361136
NotificationPermissionRequestManager* notificationPermissionRequestManager();
1137+
RefPtr<NotificationPermissionRequestManager> protectedNotificationPermissionRequestManager();
11371138

11381139
void pageDidScroll();
11391140

0 commit comments

Comments
 (0)