Skip to content

Commit

Permalink
Adopt more smart pointers under WebCore/page/
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269480

Reviewed by Ryosuke Niwa and Brent Fulgham.

Adopt more smart pointers under WebCore/page/, as recommended by the static analyzer.

* Source/WTF/wtf/RunLoop.h:
* Source/WebCore/dom/ElementInlines.h:
(WebCore::Node::protectedParentElement const):
* Source/WebCore/dom/Node.h:
* Source/WebCore/inspector/agents/page/PageDOMDebuggerAgent.cpp:
(WebCore::PageDOMDebuggerAgent::willInsertDOMNode):
* Source/WebCore/page/ContextMenuController.cpp:
(WebCore::prepareContextForQRCode):
* Source/WebCore/page/DragController.cpp:
(WebCore::DragController::tryDocumentDrag):
(WebCore::DragController::prepareForDragStart const):
* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::draggedElement):
(WebCore::EventHandler::protectedDraggedElement):
(WebCore::EventHandler::handleMousePressEvent):
(WebCore::EventHandler::scrollRecursively):
(WebCore::EventHandler::logicalScrollRecursively):
(WebCore::EventHandler::subframeForHitTestResult):
(WebCore::EventHandler::handleMouseDoubleClickEvent):
(WebCore::EventHandler::handleMouseMoveEvent):
(WebCore::EventHandler::handleMouseForceEvent):
(WebCore::EventHandler::canDropCurrentlyDraggedImageAsFile const):
(WebCore::EventHandler::dispatchDragEnterOrDragOverEvent):
(WebCore::EventHandler::updateDragAndDrop):
(WebCore::EventHandler::cancelDragAndDrop):
(WebCore::EventHandler::performDragAndDrop):
(WebCore::EventHandler::handleWheelEventInternal):
(WebCore::EventHandler::handleAccessKey):
(WebCore::EventHandler::internalKeyEvent):
(WebCore::EventHandler::didStartDrag):
(WebCore::EventHandler::updateDragStateAfterEditDragIfNeeded):
(WebCore::EventHandler::shouldDispatchEventsToDragSourceElement):
(WebCore::EventHandler::dispatchEventToDragSourceElement):
(WebCore::EventHandler::dispatchDragStartEventOnSourceElement):
(WebCore::EventHandler::handleDrag):
(WebCore::hitTestResultInFrame):
(WebCore::EventHandler::handleTouchEvent):
(WebCore::EventHandler::draggedElement const): Deleted.
* Source/WebCore/page/EventHandler.h:
* Source/WebCore/page/FocusController.cpp:
(WebCore::FocusController::nextFocusableElementOrScopeOwner):
(WebCore::shouldClearSelectionWhenChangingFocusedElement):
* Source/WebCore/page/FrameTree.cpp:
(WebCore::FrameTree::appendChild):
(WebCore::FrameTree::protectedThisFrame const):
(WebCore::FrameTree::scopedChild const):
(WebCore::FrameTree::scopedChildByUniqueName const):
(WebCore::FrameTree::scopedChildBySpecifiedName const):
(WebCore::FrameTree::scopedChildCount const):
(WebCore::FrameTree::find const):
(WebCore::FrameTree::isDescendantOf const):
(WebCore::FrameTree::traverseNext const):
(WebCore::FrameTree::traverseNextSkippingChildren const):
(WebCore::FrameTree::nextAncestorSibling const):
(WebCore::FrameTree::nextRenderedSibling const):
(WebCore::FrameTree::traverseNextRendered const):
(WebCore::FrameTree::deepFirstChild const):
(WebCore::FrameTree::deepLastChild const):
(WebCore::FrameTree::top const):
(WebCore::FrameTree::protectedTop const):
(WebCore::FrameTree::depth const):
(showFrameTree):
* Source/WebCore/page/FrameTree.h:
* Source/WebCore/page/ImageOverlayController.cpp:
(WebCore::ImageOverlayController::selectionQuadsDidChange):
(WebCore::ImageOverlayController::installPageOverlayIfNeeded):
(WebCore::ImageOverlayController::uninstallPageOverlay):
(WebCore::ImageOverlayController::protectedPage const):
* Source/WebCore/page/ImageOverlayController.h:
* Source/WebCore/page/LocalDOMWindow.cpp:
(WebCore::LocalDOMWindow::dispatchAllPendingUnloadEvents):
(WebCore::LocalDOMWindow::canShowModalDialog):
(WebCore::LocalDOMWindow::crypto const):
(WebCore::LocalDOMWindow::processPostMessage):
(WebCore::LocalDOMWindow::focus):
(WebCore::LocalDOMWindow::scrollY const):
(WebCore::LocalDOMWindow::getComputedStyle const):
(WebCore::LocalDOMWindow::getMatchedCSSRules const):
(WebCore::LocalDOMWindow::scrollBy const):
(WebCore::LocalDOMWindow::isSameSecurityOriginAsMainFrame const):
(WebCore::LocalDOMWindow::isAllowedToUseDeviceOrientation const):
(WebCore::LocalDOMWindow::hasPermissionToReceiveDeviceMotionOrOrientationEvents const):
(WebCore::LocalDOMWindow::dispatchLoadEvent):
(WebCore::LocalDOMWindow::removeAllEventListeners):
(WebCore::LocalDOMWindow::setLocation):
(WebCore::LocalDOMWindow::crossDomainAccessErrorMessage):
(WebCore::LocalDOMWindow::isInsecureScriptAccess):
(WebCore::LocalDOMWindow::createWindow):
(WebCore::LocalDOMWindow::open):
(WebCore::LocalDOMWindow::showModalDialog):
(WebCore::LocalDOMWindow::cookieStore):
* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::LocalFrameView::textFragmentIndicatorTimerFired):
(WebCore::LocalFrameView::mapFromLayoutToCSSUnits const):
(WebCore::LocalFrameView::mapFromCSSToLayoutUnits const):
* Source/WebCore/page/Page.cpp:
(WebCore::Page::takeAnyMediaCanStartListener):
(WebCore::Page::setCanStartMedia):
* Source/WebCore/page/PageSerializer.cpp:
(WebCore::PageSerializer::serializeFrame):
* Source/WebCore/page/PerformanceObserver.cpp:
(WebCore::PerformanceObserver::protectedPerformance const):
(WebCore::PerformanceObserver::observe):
(WebCore::PerformanceObserver::disconnect):
* Source/WebCore/page/PerformanceObserver.h:
* Source/WebCore/page/PrintContext.cpp:
(WebCore::PrintContext::spoolPage):
* Source/WebCore/page/ResizeObserver.cpp:
(WebCore::ResizeObserver::isReachableFromOpaqueRoots const):
* Source/WebCore/page/SpatialNavigation.cpp:
(WebCore::scrollInDirection):
* Source/WebCore/page/TextIndicator.h:
(WebCore::TextIndicator::protectedContentImage const):
* Source/WebCore/page/cocoa/WebTextIndicatorLayer.mm:
(createBounceAnimation):
(createContentCrossfadeAnimation):
* Source/WebCore/page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::passSubframeEventToSubframe):
* Source/WebCore/page/mac/ImageOverlayControllerMac.mm:
(WebCore::ImageOverlayController::updateDataDetectorHighlights):
(WebCore::ImageOverlayController::handleDataDetectorAction):
* Source/WebCore/page/scrolling/ScrollingTreeScrollingNodeDelegate.h:
(WebCore::ScrollingTreeScrollingNodeDelegate::protectedScrollingNode const):
* Source/WebCore/page/scrolling/ThreadedScrollingTreeScrollingNodeDelegate.cpp:
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::updateSnapScrollState):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::updateUserScrollInProgressForEvent):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::createTimer):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::startAnimationCallback):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::stopAnimationCallback):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::immediateScrollBy):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::pageScaleFactor const):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::willStartAnimatedScroll):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::didStopAnimatedScroll):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::willStartWheelEventScroll):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::didStopWheelEventScroll):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::willStartScrollSnapAnimation):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::didStopScrollSnapAnimation):
(WebCore::ThreadedScrollingTreeScrollingNodeDelegate::scrollExtents const):

Canonical link: https://commits.webkit.org/274827@main
  • Loading branch information
cdumez committed Feb 16, 2024
1 parent a1ffadc commit b2127af
Show file tree
Hide file tree
Showing 30 changed files with 266 additions and 207 deletions.
1 change: 1 addition & 0 deletions Source/WTF/wtf/RunLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class WTF_CAPABILITY("is current") RunLoop final : public RefCountedSerialFuncti
#endif

WTF_EXPORT_PRIVATE static RunLoop& current();
static Ref<RunLoop> protectedCurrent() { return current(); }
WTF_EXPORT_PRIVATE static RunLoop& main();
#if USE(WEB_THREAD)
WTF_EXPORT_PRIVATE static RunLoop& web();
Expand Down
11 changes: 7 additions & 4 deletions Source/WebCore/dom/DataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void DataTransfer::setEffectAllowed(const String&)
{
}

void DataTransfer::setDragImage(Element&, int, int)
void DataTransfer::setDragImage(Ref<Element>&&, int, int)
{
}

Expand Down Expand Up @@ -533,13 +533,13 @@ Ref<DataTransfer> DataTransfer::createForUpdatingDropTarget(const Document& docu
return dataTransfer;
}

void DataTransfer::setDragImage(Element& element, int x, int y)
void DataTransfer::setDragImage(Ref<Element>&& element, int x, int y)
{
if (!forDrag() || !canWriteData())
return;

CachedResourceHandle<CachedImage> image;
if (auto* imageElement = dynamicDowncast<HTMLImageElement>(element); imageElement && !imageElement->isConnected())
if (auto* imageElement = dynamicDowncast<HTMLImageElement>(element.get()); imageElement && !imageElement->isConnected())
image = imageElement->cachedImage();

m_dragLocation = IntPoint(x, y);
Expand All @@ -553,7 +553,10 @@ void DataTransfer::setDragImage(Element& element, int x, int y)
m_dragImageLoader->startLoading(m_dragImage);
}

m_dragImageElement = image ? nullptr : &element;
if (image)
m_dragImageElement = nullptr;
else
m_dragImageElement = WTFMove(element);

updateDragImage();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/DataTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DataTransfer : public RefCounted<DataTransfer>, public CanMakeWeakPtr<Data
void setData(Document&, const String& type, const String& data);
void setDataFromItemList(Document&, const String& type, const String& data);

void setDragImage(Element&, int x, int y);
void setDragImage(Ref<Element>&&, int x, int y);

void makeInvalidForSecurity() { m_storeMode = StoreMode::Invalid; }

Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/dom/ElementInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ inline Element* Node::parentElement() const
return dynamicDowncast<Element>(parentNode());
}

inline RefPtr<Element> Node::protectedParentElement() const
{
return parentElement();
}

inline const Element* Element::rootElement() const
{
if (isConnected())
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/dom/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class Node : public EventTarget {
ContainerNode* parentNode() const;
inline RefPtr<ContainerNode> protectedParentNode() const; // Defined in ContainerNode.h.
static ptrdiff_t parentNodeMemoryOffset() { return OBJECT_OFFSETOF(Node, m_parentNode); }
inline Element* parentElement() const;
inline Element* parentElement() const; // Defined in ElementInlines.h.
inline RefPtr<Element> protectedParentElement() const; // Defined in ElementInlines.h.
Node* previousSibling() const { return m_previous; }
RefPtr<Node> protectedPreviousSibling() const { return m_previous; }
static ptrdiff_t previousSiblingMemoryOffset() { return OBJECT_OFFSETOF(Node, m_previous); }
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/inspector/agents/page/PageDOMDebuggerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ void PageDOMDebuggerAgent::willInsertDOMNode(Node& parent)

std::optional<size_t> closestDistance;
RefPtr<JSC::Breakpoint> closestBreakpoint;
Node* closestBreakpointOwner = nullptr;
RefPtr<Node> closestBreakpointOwner;

for (auto [breakpointOwner, breakpoint] : m_domSubtreeModifiedBreakpoints) {
auto distance = calculateDistance(parent, *breakpointOwner);
auto distance = calculateDistance(parent, Ref { *breakpointOwner });
if (!distance)
continue;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/ContextMenuController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void prepareContextForQRCode(ContextMenuContext& context)

RefPtr<Element> element;
RefPtr nodeElement = dynamicDowncast<Element>(*node);
for (auto& lineage : lineageOfType<Element>(nodeElement ? *nodeElement : *node->parentElement())) {
for (auto& lineage : lineageOfType<Element>(nodeElement ? *nodeElement : *node->protectedParentElement())) {
if (is<HTMLTableElement>(lineage) || is<HTMLCanvasElement>(lineage) || is<HTMLImageElement>(lineage) || is<SVGSVGElement>(lineage)) {
element = &lineage;
break;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/DragController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ DragHandlingMethod DragController::tryDocumentDrag(LocalFrame& frame, const Drag
if (!m_documentUnderMouse)
return DragHandlingMethod::None;

if (m_dragInitiator && !m_documentUnderMouse->protectedSecurityOrigin()->canReceiveDragData(m_dragInitiator->securityOrigin()))
if (m_dragInitiator && !m_documentUnderMouse->protectedSecurityOrigin()->canReceiveDragData(m_dragInitiator->protectedSecurityOrigin()))
return DragHandlingMethod::None;

bool isHandlingDrag = false;
Expand Down Expand Up @@ -960,7 +960,7 @@ void DragController::prepareForDragStart(LocalFrame& source, OptionSet<DragSourc
}

auto linkURL = hitTestResult->absoluteLinkURL();
if (actionMask.contains(DragSourceAction::Link) && !linkURL.isEmpty() && source.document()->securityOrigin().canDisplay(linkURL, OriginAccessPatternsForWebProcess::singleton()))
if (actionMask.contains(DragSourceAction::Link) && !linkURL.isEmpty() && source.document()->protectedSecurityOrigin()->canDisplay(linkURL, OriginAccessPatternsForWebProcess::singleton()))
editor->copyURL(linkURL, hitTestResult->textContent().simplifyWhiteSpace(deprecatedIsSpaceOrNewline), pasteboard);
#else
// FIXME: Make this work on Windows by implementing Editor::writeSelectionToPasteboard and Editor::writeImageToPasteboard.
Expand Down
Loading

0 comments on commit b2127af

Please sign in to comment.