Skip to content

Adopt smart pointers in WebFullScreenManagerProxy.cpp, WebInspectorClient.cpp, WebInspectorInternal.cpp #47411

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

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

Conversation

jelee53
Copy link
Contributor

@jelee53 jelee53 commented Jun 30, 2025

1698769

Adopt smart pointers in WebFullScreenManagerProxy.cpp, WebInspectorClient.cpp, WebInspectorInternal.cpp
https://bugs.webkit.org/show_bug.cgi?id=295243
rdar://154710862

Reviewed by NOBODY (OOPS!).

Apply https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines

* Source/WebKit/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations:
* Source/WebKit/SaferCPPExpectations/UncountedCallArgsCheckerExpectations:
* Source/WebKit/UIProcess/WebFullScreenManagerProxy.cpp:
(WebKit::WebFullScreenManagerProxy::isFullScreen):
* Source/WebKit/WebProcess/Inspector/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::~WebInspectorClient):
(WebKit::WebInspectorClient::openLocalFrontend):
(WebKit::WebInspectorClient::bringFrontendToFront):
(WebKit::WebInspectorClient::didResizeMainFrame):
(WebKit::WebInspectorClient::showPaintRect):
(WebKit::WebInspectorClient::elementSelectionChanged):
(WebKit::WebInspectorClient::timelineRecordingChanged):
(WebKit::WebInspectorClient::setDeveloperPreferenceOverride):
* Source/WebKit/WebProcess/Inspector/WebInspectorInternal.cpp:
(WebKit::WebInspector::~WebInspector):
(WebKit::WebInspector::openLocalInspectorFrontend):
(WebKit::WebInspector::closeFrontendConnection):
(WebKit::WebInspector::bringToFront):
(WebKit::WebInspector::showMainResourceForFrame):
(WebKit::WebInspector::elementSelectionChanged):
(WebKit::WebInspector::timelineRecordingChanged):
(WebKit::WebInspector::setDeveloperPreferenceOverride):
(WebKit::WebInspector::setEmulatedConditions):
(WebKit::WebInspector::canAttachWindow):
(WebKit::WebInspector::updateDockingAvailability):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::protectedInspector):
(WebKit::WebPage::protectedInspectorUI):
(WebKit::WebPage::protectedRemoteInspectorUI):
* Source/WebKit/WebProcess/WebPage/WebPage.h:

bb0b2a2

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

@jelee53 jelee53 self-assigned this Jun 30, 2025
@jelee53 jelee53 added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Jun 30, 2025
@jelee53 jelee53 requested review from pvollan and annevk July 1, 2025 00:10
@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #42166 (ee580ee)

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

@jelee53
Copy link
Contributor Author

jelee53 commented Jul 1, 2025

Didn't check all the failures in the analyzer results. They were spread out across the results and I didn't realize. Will address tomorrow.

Comment on lines 113 to 114
if (page && page->protectedInspector())
page->protectedInspector()->bringToFront();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (page && page->protectedInspector())
page->protectedInspector()->bringToFront();
if (!page)
return;
if (RefPtr inspector = page->inspector();
inspector->bringToFront();

Is what we did elsewhere for cases like this. You should definitely never need a protected member just for a boolean output.

@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-WebFullScreenManagerProxy-cpp-WebInspectorClient-cpp-WebInspectorInternal-cpp branch from ee580ee to 51d2c6a Compare July 1, 2025 09:22
@@ -103,22 +103,28 @@ void WebInspectorClient::frontendCountChanged(unsigned count)
Inspector::FrontendChannel* WebInspectorClient::openLocalFrontend(InspectorController* controller)
{
if (RefPtr page = m_page.get())
page->inspector()->openLocalInspectorFrontend();
page->protectedInspector()->openLocalInspectorFrontend();
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'm keeping around the protectedInspector() and other protected getters just in case others might need them. I can remove though if we think just one usage in the code doesn't require a helper.

Thoughts? @annevk @pvollan

Copy link
Contributor

Choose a reason for hiding this comment

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

Given it's on page() I think that's warranted, might be worth a quick grep to confirm, but seems likely it's needed elsewhere.

@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #42214 (51d2c6a)

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

@@ -189,13 +195,13 @@ void WebInspectorClient::showPaintRect(const FloatRect& rect)

if (!m_paintRectOverlay) {
m_paintRectOverlay = PageOverlay::create(*this, PageOverlay::OverlayType::Document);
page->corePage()->pageOverlayController().installPageOverlay(*m_paintRectOverlay, PageOverlay::FadeMode::DoNotFade);
page->corePage()->pageOverlayController().installPageOverlay(*(m_paintRectOverlay.copyRef()), PageOverlay::FadeMode::DoNotFade);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that you need m_paintRectOverlay again below I'd write this as:

RefPtr paintRectOverlay = m_paintRectOverlay;
if (!paintRectOverlay)
    paintRectOverlay = ...
    m_paintRectOverlay = paintRectOverlay.copyRef();

...
... paintRectOverlay->layer();

I think that ends up being clearer overall.

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 made some stylistic updates to this where paintRectOverlay is not assigned until after m_paintRectOverlay is created. Please let me know what you think!

Copy link
Contributor

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Modulo m_paintRectOverlay nits this looks good to me. (Which I see now are also being flagged by the analyzer as wrong. Oops.)

@@ -80,7 +80,7 @@ WebInspectorClient::~WebInspectorClient()
if (m_paintRectOverlay) {
RefPtr page = m_page.get();
if (page && page->corePage())
page->corePage()->pageOverlayController().uninstallPageOverlay(*m_paintRectOverlay, PageOverlay::FadeMode::Fade);
page->corePage()->pageOverlayController().uninstallPageOverlay(*(m_paintRectOverlay.copyRef()), PageOverlay::FadeMode::Fade);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should obtain a RefPtr to m_paintRectOverlay as part of the conditional above and deref that here.

@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-WebFullScreenManagerProxy-cpp-WebInspectorClient-cpp-WebInspectorInternal-cpp branch from 51d2c6a to 1698769 Compare July 1, 2025 18:23
…ient.cpp, WebInspectorInternal.cpp

https://bugs.webkit.org/show_bug.cgi?id=295243
rdar://154710862

Reviewed by NOBODY (OOPS!).

Apply https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines

* Source/WebKit/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations:
* Source/WebKit/SaferCPPExpectations/UncountedCallArgsCheckerExpectations:
* Source/WebKit/UIProcess/WebFullScreenManagerProxy.cpp:
(WebKit::WebFullScreenManagerProxy::isFullScreen):
* Source/WebKit/WebProcess/Inspector/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::~WebInspectorClient):
(WebKit::WebInspectorClient::openLocalFrontend):
(WebKit::WebInspectorClient::bringFrontendToFront):
(WebKit::WebInspectorClient::didResizeMainFrame):
(WebKit::WebInspectorClient::showPaintRect):
(WebKit::WebInspectorClient::elementSelectionChanged):
(WebKit::WebInspectorClient::timelineRecordingChanged):
(WebKit::WebInspectorClient::setDeveloperPreferenceOverride):
* Source/WebKit/WebProcess/Inspector/WebInspectorInternal.cpp:
(WebKit::WebInspector::~WebInspector):
(WebKit::WebInspector::openLocalInspectorFrontend):
(WebKit::WebInspector::closeFrontendConnection):
(WebKit::WebInspector::bringToFront):
(WebKit::WebInspector::showMainResourceForFrame):
(WebKit::WebInspector::elementSelectionChanged):
(WebKit::WebInspector::timelineRecordingChanged):
(WebKit::WebInspector::setDeveloperPreferenceOverride):
(WebKit::WebInspector::setEmulatedConditions):
(WebKit::WebInspector::canAttachWindow):
(WebKit::WebInspector::updateDockingAvailability):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::protectedInspector):
(WebKit::WebPage::protectedInspectorUI):
(WebKit::WebPage::protectedRemoteInspectorUI):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
@jelee53 jelee53 force-pushed the eng/Adopt-smart-pointers-in-WebFullScreenManagerProxy-cpp-WebInspectorClient-cpp-WebInspectorInternal-cpp branch from 1698769 to bb0b2a2 Compare July 1, 2025 18:39
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.

4 participants