-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Adopt smart pointers in Webkit/NetworkProcess #47134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adopt smart pointers in Webkit/NetworkProcess #47134
Conversation
EWS run on previous version of this PR (hash f5843d0) |
Safer C++ Build #41445 (f5843d0)❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming. |
f5843d0
to
09aac3d
Compare
EWS run on previous version of this PR (hash 09aac3d) |
We typically place Bugzilla URL before radar. |
return; | ||
Ref scheduler = m_task->networkSession()->networkLoadScheduler(); | ||
Ref scheduler = CheckedPtr { task->networkSession() }->networkLoadScheduler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we typically want to add a helper function which returns a CheckedPtr so that we can rewrite this as:
Ref scheduler = task->checkedNetworkSession()->networkLoadScheduler();
@@ -89,9 +89,10 @@ void NetworkLoad::start() | |||
|
|||
void NetworkLoad::startWithScheduling() | |||
{ | |||
if (!m_task || !m_task->networkSession()) | |||
RefPtr task = m_task; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can inline the contents of NetworkDataTask::networkSession()
into the header file and avoid . i.e. move the following two functions in NetworkDataTask.cpp
to NetworkDataTask.h
. That'll make these functions to be "trivial" and static analyzer will no longer warn m_task being uncounted:
const NetworkSession* NetworkDataTask::networkSession() const
{
return m_session.get();
}
NetworkSession* NetworkDataTask::networkSession()
{
return m_session.get();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing that this results in a circular dependency. I think it may not be possible.
EDIT: Rupin was able to help fix the circular dependency but forward declaring one of the "circular" classes. Functions have been moved to the header.
09aac3d
to
ba6fe0f
Compare
EWS run on previous version of this PR (hash ba6fe0f) |
ba6fe0f
to
974c7a2
Compare
EWS run on previous version of this PR (hash 974c7a2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R=me.
@@ -537,7 +537,7 @@ ContentSecurityPolicy* NetworkLoadChecker::contentSecurityPolicy() | |||
if (!m_contentSecurityPolicy && m_cspResponseHeaders) { | |||
// FIXME: Pass the URL of the protected resource instead of its origin. | |||
m_contentSecurityPolicy = makeUnique<ContentSecurityPolicy>(URL { protectedOrigin()->toRawString() }, nullptr, m_networkResourceLoader.get()); | |||
m_contentSecurityPolicy->didReceiveHeaders(*m_cspResponseHeaders, String { m_referrer }, ContentSecurityPolicy::ReportParsingErrors::No); | |||
CheckedPtr { m_contentSecurityPolicy.get() }->didReceiveHeaders(*m_cspResponseHeaders, String { m_referrer }, ContentSecurityPolicy::ReportParsingErrors::No); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you also could add a helper function for this, e.g. checkedContentSecurityPolicy()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper is added, but it should be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I don't think that can be done here. checkedContentSecurityPolicy()
actually invokes contentSecurityPolicy()
so there's going to be some recursive errors there.
That being said - @pvollan & I talked it over and it's probably just better to remove checkedContentSecurityPolicy()
entirely because there's not much of a use case. contentSecurityPolicy()
is a private function and all of its usages in this file are already safe usages (e.g CheckedPtr foo = contentSecurityPolicy() ...
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, yeah, you could use it here too as it's also null-checked above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chatted with @pvollan in one of the slack threads.
The consensus is that constructing a CheckedPtr at the call-site is probably the better move because if we created a CheckedPtr foo at the top of the function, it might have to be re-assigned later.
974c7a2
to
654e108
Compare
EWS run on previous version of this PR (hash 654e108) |
654e108
to
9ccaade
Compare
EWS run on previous version of this PR (hash 9ccaade) |
Safer C++ Build #41732 (9ccaade)❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming. |
if (!m_documentURL.isEmpty()) | ||
m_contentSecurityPolicy->setDocumentURL(m_documentURL); | ||
} | ||
return m_contentSecurityPolicy.get(); | ||
} | ||
|
||
CheckedPtr<ContentSecurityPolicy> NetworkLoadChecker::checkedContentSecurityPolicy() | ||
{ | ||
return CheckedPtr { contentSecurityPolicy() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it sufficient with just return contentSecurityPolicy();
here?
9ccaade
to
2ff4526
Compare
EWS run on previous version of this PR (hash 2ff4526) |
@@ -537,7 +537,7 @@ ContentSecurityPolicy* NetworkLoadChecker::contentSecurityPolicy() | |||
if (!m_contentSecurityPolicy && m_cspResponseHeaders) { | |||
// FIXME: Pass the URL of the protected resource instead of its origin. | |||
m_contentSecurityPolicy = makeUnique<ContentSecurityPolicy>(URL { protectedOrigin()->toRawString() }, nullptr, m_networkResourceLoader.get()); | |||
m_contentSecurityPolicy->didReceiveHeaders(*m_cspResponseHeaders, String { m_referrer }, ContentSecurityPolicy::ReportParsingErrors::No); | |||
CheckedPtr { m_contentSecurityPolicy.get() }->didReceiveHeaders(*m_cspResponseHeaders, String { m_referrer }, ContentSecurityPolicy::ReportParsingErrors::No); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper is added, but it should be used here.
@@ -2271,19 +2271,21 @@ void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTas | |||
if (networkDataTask->state() == NetworkDataTask::State::Canceling || networkDataTask->state() == NetworkDataTask::State::Completed) | |||
return; | |||
|
|||
if (downloadManager().download(downloadID)) { | |||
CheckedRef downloadManagerCheckedRef = downloadManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckedRef downloadManagerCheckedRef = downloadManager(); | |
CheckedRef downloadManager = this->downloadManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Anne for this helpful suggestion!
I originally called it downloadManagerCheckedRef instead of downloadManager because the build couldn't distinguish between downloadManager vs downloadManager() (aka variable vs function). But if I'm explicitly doing this->
, the computer knows that it's a member function and thus shadowing is avoided. Smart thinking!
2ff4526
to
3709c29
Compare
EWS run on current version of this PR (hash 3709c29) |
https://bugs.webkit.org/show_bug.cgi?id=294928 rdar://154227081 Reviewed by Per Arne Vollan. Smart pointer adoption as per the static analyzer. * Source/WebKit/NetworkProcess/Downloads/DownloadManager.h: * Source/WebKit/NetworkProcess/NetworkDataTask.cpp: (WebKit::NetworkDataTask::sessionID const): Deleted. (WebKit::NetworkDataTask::networkSession const): Deleted. (WebKit::NetworkDataTask::networkSession): Deleted. (WebKit::NetworkDataTask::checkedNetworkSession): Deleted. * Source/WebKit/NetworkProcess/NetworkDataTask.h: (WebKit::NetworkDataTask::sessionID const): (WebKit::NetworkDataTask::networkSession const): (WebKit::NetworkDataTask::networkSession): (WebKit::NetworkDataTask::checkedNetworkSession): * Source/WebKit/NetworkProcess/NetworkLoad.cpp: (WebKit::NetworkLoad::startWithScheduling): (WebKit::NetworkLoad::shouldCaptureExtraNetworkLoadMetrics const): (WebKit::NetworkLoad::isAllowedToAskUserForCredentials const): (WebKit::NetworkLoad::willPerformHTTPRedirection): (WebKit::NetworkLoad::didReceiveChallenge): (WebKit::NetworkLoad::didReceiveInformationalResponse): (WebKit::NetworkLoad::notifyDidReceiveResponse): (WebKit::NetworkLoad::didReceiveData): (WebKit::NetworkLoad::didCompleteWithError): (WebKit::NetworkLoad::didSendData): (WebKit::NetworkLoad::wasBlocked): (WebKit::NetworkLoad::cannotShowURL): (WebKit::NetworkLoad::wasBlockedByRestrictions): (WebKit::NetworkLoad::wasBlockedByDisabledFTP): * Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp: (WebKit::NetworkLoadChecker::contentSecurityPolicy): * Source/WebKit/NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::addStorageSession): (WebKit::NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains): (WebKit::NetworkProcess::downloadRequest): (WebKit::NetworkProcess::resumeDownload): (WebKit::NetworkProcess::cancelDownload): (WebKit::NetworkProcess::publishDownloadProgress): (WebKit::NetworkProcess::findPendingDownloadLocation): (WebKit::NetworkProcess::dataTaskWithRequest): * Source/WebKit/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations: * Source/WebKit/SaferCPPExpectations/UncheckedLocalVarsCheckerExpectations: Canonical link: https://commits.webkit.org/296755@main
3709c29
to
9dfdee9
Compare
Committed 296755@main (9dfdee9): https://commits.webkit.org/296755@main Reviewed commits have been landed. Closing PR #47134 and removing active labels. |
9dfdee9
3709c29
🛠 playstation