Skip to content

Adopt smart pointers in RemoteWebInspectorUI.cpp #47322

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jelee53
Copy link
Contributor

@jelee53 jelee53 commented Jun 27, 2025

723cfc8

Adopt smart pointers in RemoteWebInspectorUI.cpp
https://bugs.webkit.org/show_bug.cgi?id=295068
rdar://problem/154521813

Reviewed by NOBODY (OOPS!).

Smart pointer adoption as per the static analyzer.

* Source/WebCore/page/Page.cpp:
(WebCore::Page::checkedDiagnosticLoggingClient const):
* Source/WebCore/page/Page.h:
* Source/WebKit/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations:
* Source/WebKit/SaferCPPExpectations/UncountedCallArgsCheckerExpectations:
* Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp:
(WebKit::RemoteWebInspectorUI::RemoteWebInspectorUI):
(WebKit::RemoteWebInspectorUI::initialize):
(WebKit::RemoteWebInspectorUI::sendMessageToBackend):
(WebKit::RemoteWebInspectorUI::windowObjectCleared):
(WebKit::RemoteWebInspectorUI::frontendLoaded):
(WebKit::RemoteWebInspectorUI::changeSheetRect):
(WebKit::RemoteWebInspectorUI::setForcedAppearance):
(WebKit::RemoteWebInspectorUI::startWindowDrag):
(WebKit::RemoteWebInspectorUI::bringToFront):
(WebKit::RemoteWebInspectorUI::closeWindow):
(WebKit::RemoteWebInspectorUI::reopen):
(WebKit::RemoteWebInspectorUI::resetState):
(WebKit::RemoteWebInspectorUI::openURLExternally):
(WebKit::RemoteWebInspectorUI::revealFileExternally):
(WebKit::RemoteWebInspectorUI::save):
(WebKit::RemoteWebInspectorUI::load):
(WebKit::RemoteWebInspectorUI::pickColorFromScreen):
(WebKit::RemoteWebInspectorUI::showCertificate):
(WebKit::RemoteWebInspectorUI::setInspectorPageDeveloperExtrasEnabled):
(WebKit::RemoteWebInspectorUI::logDiagnosticEvent):
(WebKit::RemoteWebInspectorUI::protectedWebPage):
* Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h:

723cfc8

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@jelee53 jelee53 self-assigned this Jun 27, 2025
@jelee53 jelee53 added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Jun 27, 2025
@jelee53 jelee53 requested review from pvollan, annevk and rniwa June 27, 2025 22:05
@@ -1591,6 +1591,11 @@ DiagnosticLoggingClient& Page::diagnosticLoggingClient() const
return *m_diagnosticLoggingClient;
}

CheckedRef<DiagnosticLoggingClient> Page::protectedDiagnosticLoggingClient() const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can call this member function 'checkedDiagnosticLoggingClient()'

@@ -72,7 +72,7 @@ void RemoteWebInspectorUI::initialize(DebuggableInfoData&& debuggableInfo, const
m_debuggableInfo = WTFMove(debuggableInfo);
m_backendCommandsURL = backendCommandsURL;

m_page->protectedCorePage()->inspectorController().setInspectorFrontendClient(this);
WeakRef { m_page }->protectedCorePage()->inspectorController().setInspectorFrontendClient(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can create a helper method: Ref<WebPage> RemoteWebInspectorUI::protectedWebPage()?

@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-RemoteWebInspectorUI-cpp branch from 0e47b0a to 6bc4dc3 Compare June 27, 2025 23:04

m_frontendHost = InspectorFrontendHost::create(this, m_page->protectedCorePage().get());
m_frontendHost->addSelfToGlobalObjectInWorld(mainThreadNormalWorldSingleton());
frontendHost = InspectorFrontendHost::create(this, protectedWebPage()->protectedCorePage().get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still assign this to m_frontendHost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh that's so careless of me! Fixing.

@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #41906 (0e47b0a)

❌ Found 1 failing file with 4 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-RemoteWebInspectorUI-cpp branch from 6bc4dc3 to b4952c5 Compare June 27, 2025 23:48
@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-RemoteWebInspectorUI-cpp branch from b4952c5 to 5c7ff4c Compare June 28, 2025 00:54
@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-RemoteWebInspectorUI-cpp branch from 5c7ff4c to 5ba16b5 Compare June 28, 2025 01:06
@@ -90,16 +90,16 @@ void RemoteWebInspectorUI::sendMessageToFrontend(const String& message)

void RemoteWebInspectorUI::sendMessageToBackend(const String& message)
{
WebProcess::singleton().parentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::SendMessageToBackend(message), m_page->identifier());
WebProcess::singleton().protectedParentProcessConnection()->send(Messages::RemoteWebInspectorUIProxy::SendMessageToBackend(message), m_page->identifier());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit silly. parentProcessConnection is a singleton just like WebProcess::singleton(). Maybe we can wrap in a helper function by the name of parentProcessConnectionSingleton().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. There's a lot of usages of protectedParentProcessConnection() outside of this file. Should I file a bugzilla ticket to replace all of those?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline. We will be leaving this as-is.

@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #41918 (b4952c5)

❌ Found 1 failing file with 4 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@pvollan pvollan added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 30, 2025
@webkit-commit-queue
Copy link
Collaborator

Commit message contains (OOPS!), blocking PR #47322. Details: Build #17705

@webkit-commit-queue webkit-commit-queue added merging-blocked Applied to prevent a change from being merged and removed unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing labels Jun 30, 2025
@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-RemoteWebInspectorUI-cpp branch from 5ba16b5 to 47adbd8 Compare June 30, 2025 22:25
@@ -35,8 +35,9 @@

namespace WebKit {

class DiagnosticLoggingClient final : public API::DiagnosticLoggingClient {
class DiagnosticLoggingClient final : public API::DiagnosticLoggingClient, public CanMakeCheckedPtr<DiagnosticLoggingClient> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change? Where is this used in this PR? I looked at the PR twice but couldn't see any code using a CheckedPtr to a WebKit::DiagnosticLoggingClient, only to the WebCore one.

Copy link
Contributor Author

@jelee53 jelee53 Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed DiagnosticLoggingClient to become a CheckedPtr in order to make this helper function:

Source/WebCore/page/Page.h:
WEBCORE_EXPORT CheckedRef<DiagnosticLoggingClient> checkedDiagnosticLoggingClient() const;`

which I eventually used in

Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp:
void RemoteWebInspectorUI::logDiagnosticEvent(const String& eventName,  const DiagnosticLoggingClient::ValueDictionary& dictionary)
{ 
.. 
protectedWebPage()->protectedCorePage()->checkedDiagnosticLoggingClient()->logDiagnosticMessageWithValueDictionary(eventName, "Remote Web Inspector Frontend Diagnostics"_s, dictionary, ShouldSample::No);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we will need checkedDiagnosticLoggingClient() to fix other unsafe cpp errors as well, such as with WebResourceLoader.cpp and WebInspectorUI.cpp:

Screenshot 2025-07-01 at 12 14 03 AM Screenshot 2025-07-01 at 12 14 43 AM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris is pointing out that we have both Source/WebCore/page/DiagnosticLoggingClient.h and Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.h. And that you're not using the latter in this patch. And the former already has CanMakeCheckedPtr.

Copy link
Contributor Author

@jelee53 jelee53 Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh, I didn't even realize that there were two separate DiagnosticLoggingClient headers... Now that I'm reading Chris's comment closer - he's talking about a Webcore vs a Webkit one.

Anyways, even I was using the wrong file, I should have double-checked if the parent class was ref'd or check'd.

You two are right. I don't need this change at all since I'm using the Webcore one not the Webkit. I'll back this out.


WeakRef<WebPage> m_page;
const WeakRef<WebPage> m_page;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Don't need it as we discussed. I forgot about this and will back it out.

@cdumez
Copy link
Contributor

cdumez commented Jul 1, 2025

Adopt smart pointers in RemoteWebInspectorUI.cpp
https://bugs.webkit.org/show_bug.cgi?id=295068
Include a Radar link (OOPS!).

You need to drop this OOPS line.

https://bugs.webkit.org/show_bug.cgi?id=295068
rdar://problem/154521813

Reviewed by NOBODY (OOPS!).

Smart pointer adoption as per the static analyzer.

* Source/WebCore/page/Page.cpp:
(WebCore::Page::checkedDiagnosticLoggingClient const):
* Source/WebCore/page/Page.h:
* Source/WebKit/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations:
* Source/WebKit/SaferCPPExpectations/UncountedCallArgsCheckerExpectations:
* Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp:
(WebKit::RemoteWebInspectorUI::RemoteWebInspectorUI):
(WebKit::RemoteWebInspectorUI::initialize):
(WebKit::RemoteWebInspectorUI::sendMessageToBackend):
(WebKit::RemoteWebInspectorUI::windowObjectCleared):
(WebKit::RemoteWebInspectorUI::frontendLoaded):
(WebKit::RemoteWebInspectorUI::changeSheetRect):
(WebKit::RemoteWebInspectorUI::setForcedAppearance):
(WebKit::RemoteWebInspectorUI::startWindowDrag):
(WebKit::RemoteWebInspectorUI::bringToFront):
(WebKit::RemoteWebInspectorUI::closeWindow):
(WebKit::RemoteWebInspectorUI::reopen):
(WebKit::RemoteWebInspectorUI::resetState):
(WebKit::RemoteWebInspectorUI::openURLExternally):
(WebKit::RemoteWebInspectorUI::revealFileExternally):
(WebKit::RemoteWebInspectorUI::save):
(WebKit::RemoteWebInspectorUI::load):
(WebKit::RemoteWebInspectorUI::pickColorFromScreen):
(WebKit::RemoteWebInspectorUI::showCertificate):
(WebKit::RemoteWebInspectorUI::setInspectorPageDeveloperExtrasEnabled):
(WebKit::RemoteWebInspectorUI::logDiagnosticEvent):
(WebKit::RemoteWebInspectorUI::protectedWebPage):
* Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h:
@jelee53 jelee53 removed the merging-blocked Applied to prevent a change from being merged label Jul 1, 2025
@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-RemoteWebInspectorUI-cpp branch from 47adbd8 to 723cfc8 Compare July 1, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants