⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 282191 in webkit


Ignore:
Timestamp:
Sep 8, 2021, 9:37:45 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

Deploy CheckedRef on FocusController
​https://bugs.webkit.org/show_bug.cgi?id=230037

Reviewed by Wenson Hsieh.

Source/WebCore:

Make FocusController inherit from CanMakeCheckedPtr and deploy CheckedRef / CheckedPtr wherever appropriate.

  • dom/Element.cpp:

(WebCore::Element::focus):
(WebCore::Element::blur):

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::selectFrameElementInParentIfFullySelected):
(WebCore::FrameSelection::setFocusedElementIfNeeded):

  • editing/cocoa/AutofillElements.cpp:

(WebCore::AutofillElements::computeAutofillElements):

  • editing/cocoa/DictionaryLookup.mm:

(WebCore::DictionaryLookup::rangeAtHitTestResult):

  • history/BackForwardCache.cpp:

(WebCore::BackForwardCache::trySuspendPage):

  • history/CachedPage.cpp:

(WebCore::CachedPage::restore):

  • html/BaseDateAndTimeInputType.cpp:

(WebCore::BaseDateAndTimeInputType::handleFocusEvent):

  • html/HTMLFrameElementBase.cpp:

(WebCore::HTMLFrameElementBase::setFocus):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::focus):

  • page/EventHandler.cpp:

(WebCore::EventHandler::handlePasteGlobalSelection):
(WebCore::EventHandler::dispatchMouseEvent):
(WebCore::EventHandler::defaultArrowEventHandler):
(WebCore::EventHandler::defaultTabEventHandler):
(WebCore::EventHandler::focusDocumentView):

  • page/FocusController.h:
  • page/Frame.cpp:

(WebCore::Frame::willDetachPage):

  • page/Page.cpp:

(WebCore::Page::findString):
(WebCore::Page::replaceSelectionWithText):
(WebCore::Page::editableElementsInRect const):
(WebCore::Page::selection const):
(WebCore::Page::setActivityState):
(WebCore::Page::revealCurrentSelection):

  • page/ios/EventHandlerIOS.mm:

(WebCore::EventHandler::focusDocumentView):

  • page/mac/EventHandlerMac.mm:

(WebCore::EventHandler::focusDocumentView):

  • page/mac/ServicesOverlayController.mm:

(WebCore::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown const):
(WebCore::ServicesOverlayController::telephoneNumberRangesForFocusedFrame):
(WebCore::ServicesOverlayController::handleClick):

Source/WebKit:

  • WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:

(WKBundleFrameFocus):

  • WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:

(WKAccessibilityFocusedObject):

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::focusPluginElement):

  • WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm:

(WebKit::changeWordCase):

  • WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:

(WebKit::TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection):
(WebKit::TextCheckingControllerProxy::replaceRelativeToSelection):
(WebKit::TextCheckingControllerProxy::removeAnnotationRelativeToSelection):

  • WebProcess/WebPage/Cocoa/WebPageCocoa.mm:

(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
(WebKit::WebPage::insertDictatedTextAsync):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::showFindIndicatorInSelection):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::editorState const):
(WebKit::WebPage::changeFontAttributes):
(WebKit::WebPage::changeFont):
(WebKit::WebPage::updateEditorStateAfterLayoutIfEditabilityChanged):
(WebKit::WebPage::executeEditingCommand):
(WebKit::WebPage::setEditable):
(WebKit::WebPage::increaseListLevel):
(WebKit::WebPage::decreaseListLevel):
(WebKit::WebPage::changeListType):
(WebKit::WebPage::setBaseWritingDirection):
(WebKit::WebPage::isEditingCommandEnabled):
(WebKit::WebPage::contextMenuForKeyEvent):
(WebKit::WebPage::handleKeyEventByRelinquishingFocusToChrome):
(WebKit::WebPage::validateCommand):
(WebKit::WebPage::requestFontAttributesAtSelectionStart):
(WebKit::WebPage::centerSelectionInVisibleArea):
(WebKit::WebPage::insertNewlineInQuotedContent):
(WebKit::WebPage::viewWillStartLiveResize):
(WebKit::WebPage::viewWillEndLiveResize):
(WebKit::WebPage::setInitialFocus):
(WebKit::WebPage::getSelectionOrContentsAsString):
(WebKit::WebPage::advanceToNextMisspelling):
(WebKit::WebPage::hasRichlyEditableSelection const):
(WebKit::WebPage::changeSpellingToWord):
(WebKit::WebPage::uppercaseWord):
(WebKit::WebPage::lowercaseWord):
(WebKit::WebPage::capitalizeWord):
(WebKit::WebPage::clearSelection):
(WebKit::WebPage::restoreSelectionInFocusedEditableElement):
(WebKit::WebPage::handleAlternativeTextUIResult):
(WebKit::WebPage::setCompositionForTesting):
(WebKit::WebPage::hasCompositionForTesting):
(WebKit::WebPage::confirmCompositionForTesting):
(WebKit::WebPage::setTextAsync):
(WebKit::WebPage::insertTextAsync):
(WebKit::WebPage::hasMarkedText):
(WebKit::WebPage::getMarkedRangeAsync):
(WebKit::WebPage::getSelectedRangeAsync):
(WebKit::WebPage::characterIndexForPointAsync):
(WebKit::WebPage::firstRectForCharacterRangeAsync):
(WebKit::WebPage::setCompositionAsync):
(WebKit::WebPage::confirmCompositionAsync):
(WebKit::WebPage::didChangeSelectionOrOverflowScrollPosition):
(WebKit::WebPage::didEndUserTriggeredSelectionChanges):
(WebKit::WebPage::sendEditorStateUpdate):
(WebKit::WebPage::flushPendingEditorStateUpdate):
(WebKit::WebPage::insertAttachment):
(WebKit::WebPage::createAppHighlightInSelectedRange):
(WebKit::WebPage::restoreAppHighlightsAndScrollToIndex):

  • WebProcess/WebPage/ios/FindControllerIOS.mm:

(WebKit::FindController::didFindString):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::platformWillPerformEditingCommand):
(WebKit::WebPage::getSelectionContext):
(WebKit::WebPage::updateSelectionAppearance):
(WebKit::WebPage::generateSyntheticEditingCommand):
(WebKit::WebPage::completeSyntheticClick):
(WebKit::WebPage::didConcludeEditDrag):
(WebKit::WebPage::clearSelectionAfterTapIfNeeded):
(WebKit::WebPage::selectWithGesture):
(WebKit::WebPage::clearSelection):
(WebKit::WebPage::dispatchSyntheticMouseEventsForSelectionGesture):
(WebKit::WebPage::updateSelectionWithTouches):
(WebKit::WebPage::selectWithTwoTouches):
(WebKit::WebPage::extendSelection):
(WebKit::WebPage::platformDidSelectAll):
(WebKit::WebPage::selectWordBackward):
(WebKit::WebPage::moveSelectionByOffset):
(WebKit::WebPage::startAutoscrollAtPosition):
(WebKit::WebPage::requestEvasionRectsAboveSelection):
(WebKit::WebPage::getRectsForGranularityWithSelectionOffset):
(WebKit::WebPage::storeSelectionForAccessibility):
(WebKit::WebPage::getRectsAtSelectionOffsetWithText):
(WebKit::WebPage::selectPositionAtPoint):
(WebKit::WebPage::selectPositionAtBoundaryWithDirection):
(WebKit::WebPage::moveSelectionAtBoundaryWithDirection):
(WebKit::WebPage::setFocusedFrameBeforeSelectingTextAtLocation):
(WebKit::WebPage::setSelectionRange):
(WebKit::WebPage::updateSelectionWithExtentPointAndBoundary):
(WebKit::WebPage::updateSelectionWithExtentPoint):
(WebKit::WebPage::requestDictationContext):
(WebKit::WebPage::replaceSelectedText):
(WebKit::WebPage::replaceDictatedText):
(WebKit::WebPage::requestAutocorrectionData):
(WebKit::WebPage::applyAutocorrectionInternal):
(WebKit::WebPage::autocorrectionContext):
(WebKit::focusedElementPositionInformation):
(WebKit::nextAssistableElement):
(WebKit::WebPage::focusedElementInformation):
(WebKit::WebPage::hardwareKeyboardAvailabilityChanged):
(WebKit::WebPage::insertTextPlaceholder):
(WebKit::WebPage::updateSelectionWithDelta):
(WebKit::WebPage::requestDocumentEditingContext):
(WebKit::WebPage::focusTextInputContextAndPlaceCaret):
(WebKit::WebPage::animationDidFinishForElement):

Location:
trunk/Source
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r282190 r282191  
     12021-09-08  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deploy CheckedRef on FocusController
     4        https://bugs.webkit.org/show_bug.cgi?id=230037
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Make FocusController inherit from CanMakeCheckedPtr and deploy CheckedRef / CheckedPtr wherever appropriate.
     9 
     10        * dom/Element.cpp:
     11        (WebCore::Element::focus):
     12        (WebCore::Element::blur):
     13         * editing/FrameSelection.cpp:
     14        (WebCore::FrameSelection::selectFrameElementInParentIfFullySelected):
     15        (WebCore::FrameSelection::setFocusedElementIfNeeded):
     16        * editing/cocoa/AutofillElements.cpp:
     17        (WebCore::AutofillElements::computeAutofillElements):
     18        * editing/cocoa/DictionaryLookup.mm:
     19        (WebCore::DictionaryLookup::rangeAtHitTestResult):
     20        * history/BackForwardCache.cpp:
     21        (WebCore::BackForwardCache::trySuspendPage):
     22        * history/CachedPage.cpp:
     23        (WebCore::CachedPage::restore):
     24        * html/BaseDateAndTimeInputType.cpp:
     25        (WebCore::BaseDateAndTimeInputType::handleFocusEvent):
     26        * html/HTMLFrameElementBase.cpp:
     27        (WebCore::HTMLFrameElementBase::setFocus):
     28        * page/DOMWindow.cpp:
     29        (WebCore::DOMWindow::focus):
     30        * page/EventHandler.cpp:
     31        (WebCore::EventHandler::handlePasteGlobalSelection):
     32        (WebCore::EventHandler::dispatchMouseEvent):
     33        (WebCore::EventHandler::defaultArrowEventHandler):
     34        (WebCore::EventHandler::defaultTabEventHandler):
     35        (WebCore::EventHandler::focusDocumentView):
     36        * page/FocusController.h:
     37        * page/Frame.cpp:
     38        (WebCore::Frame::willDetachPage):
     39        * page/Page.cpp:
     40        (WebCore::Page::findString):
     41        (WebCore::Page::replaceSelectionWithText):
     42        (WebCore::Page::editableElementsInRect const):
     43        (WebCore::Page::selection const):
     44        (WebCore::Page::setActivityState):
     45        (WebCore::Page::revealCurrentSelection):
     46        * page/ios/EventHandlerIOS.mm:
     47        (WebCore::EventHandler::focusDocumentView):
     48        * page/mac/EventHandlerMac.mm:
     49        (WebCore::EventHandler::focusDocumentView):
     50        * page/mac/ServicesOverlayController.mm:
     51        (WebCore::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown const):
     52        (WebCore::ServicesOverlayController::telephoneNumberRangesForFocusedFrame):
     53        (WebCore::ServicesOverlayController::handleClick):
     54
    1552021-09-08  Fujii Hironori  <Hironori.Fujii@sony.com>
    256
  • trunk/Source/WebCore/dom/Element.cpp

    r281793 r282191  
    31123112        // If a focus event handler changes the focus to a different node it
    31133113        // does not make sense to continue and update appearence.
    3114         if (!page->focusController().setFocusedElement(newTarget.get(), *document->frame(), optionsWithVisibility))
     3114        if (!CheckedRef(page->focusController())->setFocusedElement(newTarget.get(), *document->frame(), optionsWithVisibility))
    31153115            return;
    31163116    }
    … …  
    31713171{
    31723172    if (treeScope().focusedElementInScope() == this) {
    3173         if (Frame* frame = document().frame())
    3174             frame->page()->focusController().setFocusedElement(nullptr, *frame);
     3173        if (RefPtr frame = document().frame())
     3174            CheckedRef(frame->page()->focusController())->setFocusedElement(nullptr, *frame);
    31753175        else
    31763176            document().setFocusedElement(nullptr);
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r281685 r282191  
    19771977    // Focus on the parent frame, and then select from before this element to after.
    19781978    VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement);
    1979     if (parent->selection().shouldChangeSelection(newSelection)) {
    1980         page->focusController().setFocusedFrame(parent.get());
     1979    if (parent->selection().shouldChangeSelection(newSelection) && page) {
     1980        CheckedRef(page->focusController())->setFocusedFrame(parent.get());
    19811981        // Previous focus can trigger DOM events, ensure the selection did not become orphan.
    19821982        if (newSelection.isOrphan())
    … …  
    22712271    bool caretBrowsing = m_document->settings().caretBrowsingEnabled();
    22722272    if (caretBrowsing) {
    2273         if (Element* anchor = enclosingAnchorElement(m_selection.base())) {
    2274             m_document->page()->focusController().setFocusedElement(anchor, *m_document->frame());
     2273        if (RefPtr anchor = enclosingAnchorElement(m_selection.base())) {
     2274            CheckedRef focusController { m_document->page()->focusController() };
     2275            focusController->setFocusedElement(anchor.get(), *m_document->frame());
    22752276            return;
    22762277        }
    … …  
    22842285            // work in the long term, but this is the safest fix at this time.
    22852286            if (target->isMouseFocusable() && !isFrameElement(target)) {
    2286                 m_document->page()->focusController().setFocusedElement(target, *m_document->frame());
     2287                CheckedRef(m_document->page()->focusController())->setFocusedElement(target, *m_document->frame());
    22872288                return;
    22882289            }
    … …  
    22932294
    22942295    if (caretBrowsing)
    2295         m_document->page()->focusController().setFocusedElement(nullptr, *m_document->frame());
     2296        CheckedRef(m_document->page()->focusController())->setFocusedElement(nullptr, *m_document->frame());
    22962297}
    22972298
  • trunk/Source/WebCore/editing/cocoa/AutofillElements.cpp

    r278253 r282191  
    8484    if (!start->document().page())
    8585        return std::nullopt;
    86     FocusController& focusController = start->document().page()->focusController();
     86    CheckedRef focusController = { start->document().page()->focusController() };
    8787    if (start->isPasswordField()) {
    8888        auto previousElement = previousAutofillableElement(start.ptr(), focusController);
  • trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm

    r278253 r282191  
    319319        position = firstPositionInOrBeforeNode(node);
    320320
    321     auto selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
     321    auto selection = CheckedRef(frame->page()->focusController())->focusedOrMainFrame().selection().selection();
    322322    NSRange selectionRange;
    323323    NSUInteger hitIndex;
  • trunk/Source/WebCore/history/BackForwardCache.cpp

    r277356 r282191  
    440440    // Focus the main frame, defocusing a focused subframe (if we have one). We do this here,
    441441    // before the page enters the back/forward cache, while we still can dispatch DOM blur/focus events.
    442     if (page.focusController().focusedFrame())
    443         page.focusController().setFocusedFrame(&page.mainFrame());
     442    if (CheckedRef focusController { page.focusController() }; focusController->focusedFrame())
     443        focusController->setFocusedFrame(&page.mainFrame());
    444444
    445445    // Fire the pagehide event in all frames.
  • trunk/Source/WebCore/history/CachedPage.cpp

    r275527 r282191  
    133133    // Restore the focus appearance for the focused element.
    134134    // FIXME: Right now we don't support pages w/ frames in the b/f cache.  This may need to be tweaked when we add support for that.
    135     Document* focusedDocument = page.focusController().focusedOrMainFrame().document();
    136     if (Element* element = focusedDocument->focusedElement()) {
     135    RefPtr focusedDocument = CheckedRef(page.focusController())->focusedOrMainFrame().document();
     136    if (RefPtr element = focusedDocument->focusedElement()) {
    137137#if PLATFORM(IOS_FAMILY)
    138138        // We don't want focused nodes changing scroll position when restoring from the cache
  • trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp

    r280419 r282191  
    445445        // not be focused as the element is losing focus entirely.
    446446        if (auto* page = element()->document().page())
    447             page->focusController().advanceFocus(direction, 0);
     447            CheckedRef(page->focusController())->advanceFocus(direction, 0);
     448
    448449    } else {
    449450        // If the element received focus in any other direction, transfer focus to the first focusable child.
  • trunk/Source/WebCore/html/HTMLFrameElementBase.cpp

    r276628 r282191  
    191191    HTMLFrameOwnerElement::setFocus(received, visibility);
    192192    if (Page* page = document().page()) {
     193        CheckedRef focusController { page->focusController() };
    193194        if (received)
    194             page->focusController().setFocusedFrame(contentFrame());
    195         else if (page->focusController().focusedFrame() == contentFrame()) // Focus may have already been given to another frame, don't take it away.
    196             page->focusController().setFocusedFrame(0);
     195            focusController->setFocusedFrame(contentFrame());
     196        else if (focusController->focusedFrame() == contentFrame()) // Focus may have already been given to another frame, don't take it away.
     197            focusController->setFocusedFrame(nullptr);
    197198    }
    198199}
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r281848 r282191  
    10001000
    10011001    // Clear the current frame's focused node if a new frame is about to be focused.
    1002     RefPtr focusedFrame = page->focusController().focusedFrame();
     1002    RefPtr focusedFrame = CheckedRef(page->focusController())->focusedFrame();
    10031003    if (focusedFrame && focusedFrame != frame)
    10041004        focusedFrame->document()->setFocusedElement(nullptr);
  • trunk/Source/WebCore/page/EventHandler.cpp

    r282165 r282191  
    22322232    if (!m_frame.page())
    22332233        return false;
    2234     Frame& focusFrame = m_frame.page()->focusController().focusedOrMainFrame();
     2234    Frame& focusFrame = CheckedRef(m_frame.page()->focusController())->focusedOrMainFrame();
    22352235    // Do not paste here if the focus was moved somewhere else.
    22362236    if (&m_frame == &focusFrame && m_frame.editor().client()->supportsGlobalSelection())
    … …  
    27492749    // If focus shift is blocked, we eat the event.
    27502750    auto* page = m_frame.page();
    2751     if (page && !page->focusController().setFocusedElement(element.get(), m_frame, { { }, { }, { }, FocusTrigger::Click, { } }))
     2751    if (page && !CheckedRef(page->focusController())->setFocusedElement(element.get(), m_frame, { { }, { }, { }, FocusTrigger::Click, { } }))
    27522752        return false;
    27532753
    … …  
    43264326        return;
    43274327
    4328     if (page->focusController().advanceFocus(focusDirection, &event))
     4328    if (CheckedRef(page->focusController())->advanceFocus(focusDirection, &event))
    43294329        event.setDefaultHandled();
    43304330}
    … …  
    43514351        return;
    43524352
    4353     if (page->focusController().advanceFocus(event.shiftKey() ? FocusDirection::Backward : FocusDirection::Forward, &event))
     4353    if (CheckedRef(page->focusController())->advanceFocus(event.shiftKey() ? FocusDirection::Backward : FocusDirection::Forward, &event))
    43544354        event.setDefaultHandled();
    43554355}
    … …  
    47284728{
    47294729    if (Page* page = m_frame.page())
    4730         page->focusController().setFocusedFrame(&m_frame);
     4730        CheckedRef(page->focusController())->setFocusedFrame(&m_frame);
    47314731}
    47324732#endif // !PLATFORM(COCOA)
  • trunk/Source/WebCore/page/FocusController.h

    r276016 r282191  
    3030#include "LayoutRect.h"
    3131#include "Timer.h"
     32#include <wtf/CheckedRef.h>
    3233#include <wtf/Forward.h>
    3334#include <wtf/RefPtr.h>
    … …  
    4849struct FocusCandidate;
    4950
    50 class FocusController {
     51class FocusController : public CanMakeCheckedPtr {
    5152    WTF_MAKE_FAST_ALLOCATED;
    5253public:
  • trunk/Source/WebCore/page/Frame.cpp

    r280504 r282191  
    778778    // FIXME: It's unclear as to why this is called more than once, but it is,
    779779    // so page() could be NULL.
    780     if (page() && page()->focusController().focusedFrame() == this)
    781         page()->focusController().setFocusedFrame(nullptr);
     780    if (page()) {
     781        CheckedRef focusController { page()->focusController() };
     782        if (focusController->focusedFrame() == this)
     783            focusController->setFocusedFrame(nullptr);
     784    }
     785
    782786
    783787    if (page() && page()->scrollingCoordinator() && m_view)
  • trunk/Source/WebCore/page/Page.cpp

    r282130 r282191  
    722722
    723723    CanWrap canWrap = options.contains(WrapAround) ? CanWrap::Yes : CanWrap::No;
    724     Frame* frame = &focusController().focusedOrMainFrame();
    725     Frame* startFrame = frame;
     724    CheckedRef focusController { *m_focusController };
     725    RefPtr frame = &focusController->focusedOrMainFrame();
     726    RefPtr startFrame = frame;
    726727    do {
    727728        if (frame->editor().findString(target, (options - WrapAround) | StartInSelection)) {
    728729            if (frame != startFrame)
    729730                startFrame->selection().clear();
    730             focusController().setFocusedFrame(frame);
     731            focusController->setFocusedFrame(frame.get());
    731732            return true;
    732733        }
    733         frame = incrementFrame(frame, !options.contains(Backwards), canWrap, didWrap);
     734        frame = incrementFrame(frame.get(), !options.contains(Backwards), canWrap, didWrap);
    734735    } while (frame && frame != startFrame);
    735736
    … …  
    740741            *didWrap = DidWrap::Yes;
    741742        bool found = startFrame->editor().findString(target, options | WrapAround | StartInSelection);
    742         focusController().setFocusedFrame(frame);
     743        focusController->setFocusedFrame(frame.get());
    743744        return found;
    744745    }
    … …  
    940941uint32_t Page::replaceSelectionWithText(const String& replacementText)
    941942{
    942     auto frame = makeRef(focusController().focusedOrMainFrame());
     943    Ref frame = CheckedRef(focusController())->focusedOrMainFrame();
    943944    auto selection = frame->selection().selection();
    944945    if (!selection.isContentEditable())
    … …  
    10211022    // focused element is inside the search rect it's the most likely target for future editing operations,
    10221023    // even if it's empty. So, we special case it here.
    1023     if (auto* focusedElement = focusController().focusedOrMainFrame().document()->focusedElement()) {
     1024    if (RefPtr focusedElement = CheckedRef(focusController())->focusedOrMainFrame().document()->focusedElement()) {
    10241025        if (searchRectInRootViewCoordinates.inclusivelyIntersects(focusedElement->boundingBoxInRootViewCoordinates())) {
    10251026            if (auto* editableElement = rootEditableElement(*focusedElement))
    … …  
    10321033const VisibleSelection& Page::selection() const
    10331034{
    1034     return focusController().focusedOrMainFrame().selection().selection();
     1035    return CheckedRef(focusController())->focusedOrMainFrame().selection().selection();
    10351036}
    10361037
    … …  
    23382339    m_activityState = activityState;
    23392340
    2340     m_focusController->setActivityState(activityState);
     2341    CheckedRef(*m_focusController)->setActivityState(activityState);
    23412342
    23422343    if (changed & ActivityState::IsVisible)
    … …  
    35393540void Page::revealCurrentSelection()
    35403541{
    3541     focusController().focusedOrMainFrame().selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterIfNeeded);
     3542    CheckedRef(focusController())->focusedOrMainFrame().selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterIfNeeded);
    35423543}
    35433544
  • trunk/Source/WebCore/page/ios/EventHandlerIOS.mm

    r281728 r282191  
    199199
    200200    RELEASE_ASSERT(page == m_frame.page());
    201     page->focusController().setFocusedFrame(&m_frame);
     201    CheckedRef(page->focusController())->setFocusedFrame(&m_frame);
    202202}
    203203
  • trunk/Source/WebCore/page/mac/EventHandlerMac.mm

    r280807 r282191  
    189189
    190190    RELEASE_ASSERT(page == m_frame.page());
    191     page->focusController().setFocusedFrame(&m_frame);
     191    CheckedRef(page->focusController())->setFocusedFrame(&m_frame);
    192192}
    193193
  • trunk/Source/WebCore/page/mac/ServicesOverlayController.mm

    r278530 r282191  
    283283
    284284    Seconds minimumTimeUntilHighlightShouldBeShown = 200_ms;
    285     if (m_page.focusController().focusedOrMainFrame().selection().selection().isContentEditable())
     285    if (CheckedRef(m_page.focusController())->focusedOrMainFrame().selection().selection().isContentEditable())
    286286        minimumTimeUntilHighlightShouldBeShown = 1_s;
    287287
    … …  
    474474Vector<SimpleRange> ServicesOverlayController::telephoneNumberRangesForFocusedFrame()
    475475{
    476     return m_page.focusController().focusedOrMainFrame().editor().detectedTelephoneNumberRanges();
     476    return CheckedRef(m_page.focusController())->focusedOrMainFrame().editor().detectedTelephoneNumberRanges();
    477477}
    478478
    … …  
    645645            selectedTelephoneNumbers.append(plainText(range));
    646646
    647         m_page.chrome().client().handleSelectionServiceClick(m_page.focusController().focusedOrMainFrame().selection(), selectedTelephoneNumbers, windowPoint);
     647        m_page.chrome().client().handleSelectionServiceClick(CheckedRef(m_page.focusController())->focusedOrMainFrame().selection(), selectedTelephoneNumbers, windowPoint);
    648648    } else if (highlight.type() == DataDetectorHighlight::Type::TelephoneNumber)
    649649        m_page.chrome().client().handleTelephoneNumberClick(plainText(highlight.range()), windowPoint);
  • trunk/Source/WebKit/ChangeLog

    r282190 r282191  
     12021-09-08  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deploy CheckedRef on FocusController
     4        https://bugs.webkit.org/show_bug.cgi?id=230037
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
     9        (WKBundleFrameFocus):
     10        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
     11        (WKAccessibilityFocusedObject):
     12        * WebProcess/Plugins/PluginView.cpp:
     13        (WebKit::PluginView::focusPluginElement):
     14        * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm:
     15        (WebKit::changeWordCase):
     16        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
     17        (WebKit::TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection):
     18        (WebKit::TextCheckingControllerProxy::replaceRelativeToSelection):
     19        (WebKit::TextCheckingControllerProxy::removeAnnotationRelativeToSelection):
     20        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
     21        (WebKit::WebPage::performDictionaryLookupAtLocation):
     22        (WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
     23        (WebKit::WebPage::insertDictatedTextAsync):
     24        * WebProcess/WebPage/FindController.cpp:
     25        (WebKit::FindController::showFindIndicatorInSelection):
     26        * WebProcess/WebPage/WebPage.cpp:
     27        (WebKit::WebPage::editorState const):
     28        (WebKit::WebPage::changeFontAttributes):
     29        (WebKit::WebPage::changeFont):
     30        (WebKit::WebPage::updateEditorStateAfterLayoutIfEditabilityChanged):
     31        (WebKit::WebPage::executeEditingCommand):
     32        (WebKit::WebPage::setEditable):
     33        (WebKit::WebPage::increaseListLevel):
     34        (WebKit::WebPage::decreaseListLevel):
     35        (WebKit::WebPage::changeListType):
     36        (WebKit::WebPage::setBaseWritingDirection):
     37        (WebKit::WebPage::isEditingCommandEnabled):
     38        (WebKit::WebPage::contextMenuForKeyEvent):
     39        (WebKit::WebPage::handleKeyEventByRelinquishingFocusToChrome):
     40        (WebKit::WebPage::validateCommand):
     41        (WebKit::WebPage::requestFontAttributesAtSelectionStart):
     42        (WebKit::WebPage::centerSelectionInVisibleArea):
     43        (WebKit::WebPage::insertNewlineInQuotedContent):
     44        (WebKit::WebPage::viewWillStartLiveResize):
     45        (WebKit::WebPage::viewWillEndLiveResize):
     46        (WebKit::WebPage::setInitialFocus):
     47        (WebKit::WebPage::getSelectionOrContentsAsString):
     48        (WebKit::WebPage::advanceToNextMisspelling):
     49        (WebKit::WebPage::hasRichlyEditableSelection const):
     50        (WebKit::WebPage::changeSpellingToWord):
     51        (WebKit::WebPage::uppercaseWord):
     52        (WebKit::WebPage::lowercaseWord):
     53        (WebKit::WebPage::capitalizeWord):
     54        (WebKit::WebPage::clearSelection):
     55        (WebKit::WebPage::restoreSelectionInFocusedEditableElement):
     56        (WebKit::WebPage::handleAlternativeTextUIResult):
     57        (WebKit::WebPage::setCompositionForTesting):
     58        (WebKit::WebPage::hasCompositionForTesting):
     59        (WebKit::WebPage::confirmCompositionForTesting):
     60        (WebKit::WebPage::setTextAsync):
     61        (WebKit::WebPage::insertTextAsync):
     62        (WebKit::WebPage::hasMarkedText):
     63        (WebKit::WebPage::getMarkedRangeAsync):
     64        (WebKit::WebPage::getSelectedRangeAsync):
     65        (WebKit::WebPage::characterIndexForPointAsync):
     66        (WebKit::WebPage::firstRectForCharacterRangeAsync):
     67        (WebKit::WebPage::setCompositionAsync):
     68        (WebKit::WebPage::confirmCompositionAsync):
     69        (WebKit::WebPage::didChangeSelectionOrOverflowScrollPosition):
     70        (WebKit::WebPage::didEndUserTriggeredSelectionChanges):
     71        (WebKit::WebPage::sendEditorStateUpdate):
     72        (WebKit::WebPage::flushPendingEditorStateUpdate):
     73        (WebKit::WebPage::insertAttachment):
     74        (WebKit::WebPage::createAppHighlightInSelectedRange):
     75        (WebKit::WebPage::restoreAppHighlightsAndScrollToIndex):
     76        * WebProcess/WebPage/ios/FindControllerIOS.mm:
     77        (WebKit::FindController::didFindString):
     78        * WebProcess/WebPage/ios/WebPageIOS.mm:
     79        (WebKit::WebPage::platformWillPerformEditingCommand):
     80        (WebKit::WebPage::getSelectionContext):
     81        (WebKit::WebPage::updateSelectionAppearance):
     82        (WebKit::WebPage::generateSyntheticEditingCommand):
     83        (WebKit::WebPage::completeSyntheticClick):
     84        (WebKit::WebPage::didConcludeEditDrag):
     85        (WebKit::WebPage::clearSelectionAfterTapIfNeeded):
     86        (WebKit::WebPage::selectWithGesture):
     87        (WebKit::WebPage::clearSelection):
     88        (WebKit::WebPage::dispatchSyntheticMouseEventsForSelectionGesture):
     89        (WebKit::WebPage::updateSelectionWithTouches):
     90        (WebKit::WebPage::selectWithTwoTouches):
     91        (WebKit::WebPage::extendSelection):
     92        (WebKit::WebPage::platformDidSelectAll):
     93        (WebKit::WebPage::selectWordBackward):
     94        (WebKit::WebPage::moveSelectionByOffset):
     95        (WebKit::WebPage::startAutoscrollAtPosition):
     96        (WebKit::WebPage::requestEvasionRectsAboveSelection):
     97        (WebKit::WebPage::getRectsForGranularityWithSelectionOffset):
     98        (WebKit::WebPage::storeSelectionForAccessibility):
     99        (WebKit::WebPage::getRectsAtSelectionOffsetWithText):
     100        (WebKit::WebPage::selectPositionAtPoint):
     101        (WebKit::WebPage::selectPositionAtBoundaryWithDirection):
     102        (WebKit::WebPage::moveSelectionAtBoundaryWithDirection):
     103        (WebKit::WebPage::setFocusedFrameBeforeSelectingTextAtLocation):
     104        (WebKit::WebPage::setSelectionRange):
     105        (WebKit::WebPage::updateSelectionWithExtentPointAndBoundary):
     106        (WebKit::WebPage::updateSelectionWithExtentPoint):
     107        (WebKit::WebPage::requestDictationContext):
     108        (WebKit::WebPage::replaceSelectedText):
     109        (WebKit::WebPage::replaceDictatedText):
     110        (WebKit::WebPage::requestAutocorrectionData):
     111        (WebKit::WebPage::applyAutocorrectionInternal):
     112        (WebKit::WebPage::autocorrectionContext):
     113        (WebKit::focusedElementPositionInformation):
     114        (WebKit::nextAssistableElement):
     115        (WebKit::WebPage::focusedElementInformation):
     116        (WebKit::WebPage::hardwareKeyboardAvailabilityChanged):
     117        (WebKit::WebPage::insertTextPlaceholder):
     118        (WebKit::WebPage::updateSelectionWithDelta):
     119        (WebKit::WebPage::requestDocumentEditingContext):
     120        (WebKit::WebPage::focusTextInputContextAndPlaceCaret):
     121        (WebKit::WebPage::animationDidFinishForElement):
     122
    11232021-09-08  Fujii Hironori  <Hironori.Fujii@sony.com>
    2124
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp

    r271013 r282191  
    282282void WKBundleFrameFocus(WKBundleFrameRef frameRef)
    283283{
    284     WebCore::Frame* coreFrame = WebKit::toImpl(frameRef)->coreFrame();
     284    RefPtr coreFrame = WebKit::toImpl(frameRef)->coreFrame();
    285285    if (!coreFrame)
    286286        return;
    287287
    288     coreFrame->page()->focusController().setFocusedFrame(coreFrame);
    289 }
     288    CheckedRef(coreFrame->page()->focusController())->setFocusedFrame(coreFrame.get());
     289}
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp

    r278253 r282191  
    279279        return 0;
    280280
    281     auto* focusedDocument = page->focusController().focusedOrMainFrame().document();
     281    RefPtr focusedDocument = CheckedRef(page->focusController())->focusedOrMainFrame().document();
    282282    if (!focusedDocument)
    283283        return 0;
  • trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp

    r280689 r282191  
    11021102   
    11031103    if (Page* page = frame()->page())
    1104         page->focusController().setFocusedElement(m_pluginElement.get(), *frame());
     1104        CheckedRef(page->focusController())->setFocusedElement(m_pluginElement.get(), *frame());
    11051105    else
    1106         frame()->document()->setFocusedElement(m_pluginElement.get());
     1106        RefPtr(frame()->document())->setFocusedElement(m_pluginElement.get());
    11071107}
    11081108
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm

    r244932 r282191  
    6666static void changeWordCase(WebPage* page, NSString *(*changeCase)(NSString *))
    6767{
    68     Frame& frame = page->corePage()->focusController().focusedOrMainFrame();
    69     if (!frame.editor().canEdit())
     68    Ref frame = CheckedRef(page->corePage()->focusController())->focusedOrMainFrame();
     69    if (!frame->editor().canEdit())
    7070        return;
    7171
    72     frame.editor().command("selectWord").execute();
     72    frame->editor().command("selectWord").execute();
    7373
    74     NSString *selectedString = frame.displayStringModifiedByEncoding(frame.editor().selectedText());
    75     page->replaceSelectionWithText(&frame, changeCase(selectedString));
     74    NSString *selectedString = frame->displayStringModifiedByEncoding(frame->editor().selectedText());
     75    page->replaceSelectionWithText(frame.ptr(), changeCase(selectedString));
    7676}
    7777
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm

    r278253 r282191  
    7474std::optional<TextCheckingControllerProxy::RangeAndOffset> TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection(int64_t offset, uint64_t length)
    7575{
    76     auto& frameSelection = m_page.corePage()->focusController().focusedOrMainFrame().selection();
    77     auto& selection = frameSelection.selection();
     76    auto& frameSelection = CheckedRef(m_page.corePage()->focusController()).focusedOrMainFrame().selection();
     77    auto selection = frameSelection.selection();
    7878
    79     auto root = frameSelection.rootEditableElementOrDocumentElement();
     79    RefPtr root = frameSelection.rootEditableElementOrDocumentElement();
    8080    if (!root)
    8181        return std::nullopt;
    … …  
    9797void TextCheckingControllerProxy::replaceRelativeToSelection(const WebCore::AttributedString& annotatedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength)
    9898{
    99     Frame& frame = m_page.corePage()->focusController().focusedOrMainFrame();
    100     FrameSelection& frameSelection = frame.selection();
    101     auto root = frameSelection.rootEditableElementOrDocumentElement();
     99    Ref frame = CheckedRef(m_page.corePage()->focusController())->focusedOrMainFrame();
     100    FrameSelection frameSelection = frame.selection();
     101    RefPtr root = frameSelection.rootEditableElementOrDocumentElement();
    102102    if (!root)
    103103        return;
    … …  
    156156    auto removeCoreSpellingMarkers = annotation == "NSSpellingState";
    157157    auto types = removeCoreSpellingMarkers ? relevantMarkerTypes() : WebCore::DocumentMarker::PlatformTextChecking;
    158     m_page.corePage()->focusController().focusedOrMainFrame().document()->markers().filterMarkers(rangeAndOffset->range, [&] (const DocumentMarker& marker) {
     158    RefPtr document = CheckedRef(m_page.corePage()->focusController()).focusedOrMainFrame().document();
     159    document->markers().filterMarkers(rangeAndOffset->range, [&] (const DocumentMarker& marker) {
    159160        if (!WTF::holds_alternative<WebCore::DocumentMarker::PlatformTextCheckingData>(marker.data()))
    160161            return false;
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm

    r281277 r282191  
    126126    auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)), hitType);
    127127
    128     auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
     128    RefPtr frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &CheckedRef(m_page->focusController())->focusedOrMainFrame();
    129129    if (!frame)
    130130        return;
    … …  
    150150void WebPage::performDictionaryLookupOfCurrentSelection()
    151151{
    152     auto& frame = m_page->focusController().focusedOrMainFrame();
    153     performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
     152    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     153    performDictionaryLookupForSelection(frame, frame->selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
    154154}
    155155   
    … …  
    226226void WebPage::insertDictatedTextAsync(const String& text, const EditingRange& replacementEditingRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, InsertTextOptions&& options)
    227227{
    228     auto& frame = m_page->focusController().focusedOrMainFrame();
    229     Ref<Frame> protector { frame };
     228    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    230229
    231230    if (replacementEditingRange.location != notFound) {
    232231        auto replacementRange = EditingRange::toRange(frame, replacementEditingRange);
    233232        if (replacementRange)
    234             frame.selection().setSelection(VisibleSelection { *replacementRange });
     233            frame->selection().setSelection(VisibleSelection { *replacementRange });
    235234    }
    236235
    … …  
    238237        send(Messages::WebPageProxy::RegisterInsertionUndoGrouping { });
    239238
    240     RefPtr<Element> focusedElement = frame.document() ? frame.document()->focusedElement() : nullptr;
     239    RefPtr<Element> focusedElement = frame->document() ? frame->document()->focusedElement() : nullptr;
    241240    if (focusedElement && options.shouldSimulateKeyboardInput)
    242241        focusedElement->dispatchEvent(Event::create(eventNames().keydownEvent, Event::CanBubble::Yes, Event::IsCancelable::Yes));
    243242
    244     ASSERT(!frame.editor().hasComposition());
    245     frame.editor().insertDictatedText(text, dictationAlternativeLocations, nullptr /* triggeringEvent */);
     243    ASSERT(!frame->editor().hasComposition());
     244    frame->editor().insertDictatedText(text, dictationAlternativeLocations, nullptr /* triggeringEvent */);
    246245
    247246    if (focusedElement && options.shouldSimulateKeyboardInput) {
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp

    r281782 r282191  
    436436void FindController::showFindIndicatorInSelection()
    437437{
    438     Frame& selectedFrame = m_webPage->corePage()->focusController().focusedOrMainFrame();
     438    Ref selectedFrame = CheckedRef(m_webPage->corePage()->focusController())->focusedOrMainFrame();
    439439    updateFindIndicator(selectedFrame, false);
    440440}
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r282130 r282191  
    12081208{
    12091209    // Ref the frame because this function may perform layout, which may cause frame destruction.
    1210     Ref<Frame> frame = m_page->focusController().focusedOrMainFrame();
     1210    Ref<Frame> frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    12111211
    12121212    EditorState result;
    … …  
    12661266void WebPage::changeFontAttributes(WebCore::FontAttributeChanges&& changes)
    12671267{
    1268     auto& frame = m_page->focusController().focusedOrMainFrame();
    1269     if (frame.selection().selection().isContentEditable())
    1270         frame.editor().applyStyleToSelection(changes.createEditingStyle(), changes.editAction(), Editor::ColorFilterMode::InvertColor);
     1268    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1269    if (frame->selection().selection().isContentEditable())
     1270        frame->editor().applyStyleToSelection(changes.createEditingStyle(), changes.editAction(), Editor::ColorFilterMode::InvertColor);
    12711271}
    12721272
    12731273void WebPage::changeFont(WebCore::FontChanges&& changes)
    12741274{
    1275     auto& frame = m_page->focusController().focusedOrMainFrame();
    1276     if (frame.selection().selection().isContentEditable())
    1277         frame.editor().applyStyleToSelection(changes.createEditingStyle(), EditAction::SetFont, Editor::ColorFilterMode::InvertColor);
     1275    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1276    if (frame->selection().selection().isContentEditable())
     1277        frame->editor().applyStyleToSelection(changes.createEditingStyle(), EditAction::SetFont, Editor::ColorFilterMode::InvertColor);
    12781278}
    12791279
    … …  
    13111311        return;
    13121312
    1313     Frame& frame = m_page->focusController().focusedOrMainFrame();
    1314     EditorStateIsContentEditable editorStateIsContentEditable = frame.selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
     1313    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1314    EditorStateIsContentEditable editorStateIsContentEditable = frame->selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
    13151315    if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable)
    13161316        scheduleFullEditorStateUpdate();
    … …  
    14261426    platformWillPerformEditingCommand();
    14271427
    1428     auto& frame = m_page->focusController().focusedOrMainFrame();
     1428    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    14291429
    14301430    if (PluginView* pluginView = focusedPluginViewForFrame(frame)) {
    … …  
    14331433    }
    14341434   
    1435     frame.editor().command(commandName).execute(argument);
     1435    frame->editor().command(commandName).execute(argument);
    14361436}
    14371437
    … …  
    14401440    m_page->setEditable(editable);
    14411441    m_page->setTabKeyCyclesThroughElements(!editable);
    1442     Frame& frame = m_page->focusController().focusedOrMainFrame();
     1442    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    14431443    if (editable) {
    1444         frame.editor().applyEditingStyleToBodyElement();
     1444        frame->editor().applyEditingStyleToBodyElement();
    14451445        // If the page is made editable and the selection is empty, set it to something.
    1446         if (frame.selection().isNone())
    1447             frame.selection().setSelectionFromNone();
     1446        if (frame->selection().isNone())
     1447            frame->selection().setSelectionFromNone();
    14481448    }
    14491449}
    … …  
    14511451void WebPage::increaseListLevel()
    14521452{
    1453     m_page->focusController().focusedOrMainFrame().editor().increaseSelectionListLevel();
     1453    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1454    frame->editor().increaseSelectionListLevel();
    14541455}
    14551456
    14561457void WebPage::decreaseListLevel()
    14571458{
    1458     m_page->focusController().focusedOrMainFrame().editor().decreaseSelectionListLevel();
     1459    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1460    frame->editor().decreaseSelectionListLevel();
    14591461}
    14601462
    14611463void WebPage::changeListType()
    14621464{
    1463     m_page->focusController().focusedOrMainFrame().editor().changeSelectionListType();
     1465    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1466    frame->editor().changeSelectionListType();
    14641467}
    14651468
    14661469void WebPage::setBaseWritingDirection(WritingDirection direction)
    14671470{
    1468     m_page->focusController().focusedOrMainFrame().editor().setBaseWritingDirection(direction);
     1471    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1472    frame->editor().setBaseWritingDirection(direction);
    14691473}
    14701474
    14711475bool WebPage::isEditingCommandEnabled(const String& commandName)
    14721476{
    1473     Frame& frame = m_page->focusController().focusedOrMainFrame();
     1477    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    14741478
    14751479    if (PluginView* pluginView = focusedPluginViewForFrame(frame))
    14761480        return pluginView->isEditingCommandEnabled(commandName);
    14771481   
    1478     Editor::Command command = frame.editor().command(commandName);
     1482    Editor::Command command = frame->editor().command(commandName);
    14791483    return command.isSupported() && command.isEnabled();
    14801484}
    … …  
    29082912#endif
    29092913
    2910     Frame& frame = m_page->focusController().focusedOrMainFrame();
    2911     bool handled = frame.eventHandler().sendContextMenuEventForKey();
     2914    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2915    bool handled = frame->eventHandler().sendContextMenuEventForKey();
    29122916#if ENABLE(CONTEXT_MENUS)
    29132917    if (handled)
    … …  
    30943098    // elements inside the view. We can only do this for shift-tab, not tab itself because
    30953099    // tabKeyCyclesThroughElements is used to make tab character insertion work in editable web views.
    3096     return m_page->focusController().relinquishFocusToChrome(FocusDirection::Backward);
     3100    return CheckedRef(m_page->focusController())->relinquishFocusToChrome(FocusDirection::Backward);
    30973101}
    30983102
    … …  
    31013105    bool isEnabled = false;
    31023106    int32_t state = 0;
    3103     Frame& frame = m_page->focusController().focusedOrMainFrame();
     3107    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    31043108    if (PluginView* pluginView = focusedPluginViewForFrame(frame))
    31053109        isEnabled = pluginView->isEditingCommandEnabled(commandName);
    31063110    else {
    3107         Editor::Command command = frame.editor().command(commandName);
     3111        Editor::Command command = frame->editor().command(commandName);
    31083112        state = (command.state() != TriState::False);
    31093113        isEnabled = command.isSupported() && command.isEnabled();
    … …  
    31613165void WebPage::requestFontAttributesAtSelectionStart(CompletionHandler<void(const WebCore::FontAttributes&)>&& completionHandler)
    31623166{
    3163     completionHandler(m_page->focusController().focusedOrMainFrame().editor().fontAttributesAtSelectionStart());
     3167    completionHandler(CheckedRef(m_page->focusController())->focusedOrMainFrame().editor().fontAttributesAtSelectionStart());
    31643168}
    31653169
    … …  
    33103314void WebPage::centerSelectionInVisibleArea()
    33113315{
    3312     Frame& frame = m_page->focusController().focusedOrMainFrame();
    3313     frame.selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterAlways);
     3316    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     3317    frame->selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterAlways);
    33143318    findController().showFindIndicatorInSelection();
    33153319}
    … …  
    33423346void WebPage::insertNewlineInQuotedContent()
    33433347{
    3344     Frame& frame = m_page->focusController().focusedOrMainFrame();
    3345     if (frame.selection().isNone())
    3346         return;
    3347     frame.editor().insertParagraphSeparatorInQuotedContent();
     3348    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     3349    if (frame->selection().isNone())
     3350        return;
     3351    frame->editor().insertParagraphSeparatorInQuotedContent();
    33483352}
    33493353
    … …  
    33933397
    33943398    // FIXME: This should propagate to all ScrollableAreas.
    3395     Frame& frame = m_page->focusController().focusedOrMainFrame();
    3396     if (FrameView* view = frame.view())
     3399    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     3400    if (RefPtr view = frame->view())
    33973401        view->willStartLiveResize();
    33983402}
    … …  
    34043408
    34053409    // FIXME: This should propagate to all ScrollableAreas.
    3406     Frame& frame = m_page->focusController().focusedOrMainFrame();
    3407     if (FrameView* view = frame.view())
     3410    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     3411    if (RefPtr view = frame->view())
    34083412        view->willEndLiveResize();
    34093413}
    … …  
    34163420    SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true };
    34173421
    3418     Frame& frame = m_page->focusController().focusedOrMainFrame();
    3419     frame.document()->setFocusedElement(0);
     3422    CheckedRef focusController { m_page->focusController() };
     3423    Ref frame = focusController->focusedOrMainFrame();
     3424    frame->document()->setFocusedElement(nullptr);
    34203425
    34213426    if (isKeyboardEventValid && event.type() == WebEvent::KeyDown) {
    34223427        PlatformKeyboardEvent platformEvent(platform(event));
    34233428        platformEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
    3424         m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, &KeyboardEvent::create(platformEvent, &frame.windowProxy()).get());
     3429        focusController->setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, &KeyboardEvent::create(platformEvent, &frame->windowProxy()).get());
    34253430        completionHandler();
    34263431        return;
    34273432    }
    34283433
    3429     m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, nullptr);
     3434    focusController->setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, nullptr);
    34303435    completionHandler();
    34313436}
    … …  
    38133818void WebPage::getSelectionOrContentsAsString(CompletionHandler<void(const String&)>&& callback)
    38143819{
    3815     WebFrame* focusedOrMainFrame = WebFrame::fromCoreFrame(m_page->focusController().focusedOrMainFrame());
     3820    WebFrame* focusedOrMainFrame = WebFrame::fromCoreFrame(CheckedRef(m_page->focusController())->focusedOrMainFrame());
    38163821    String resultString = focusedOrMainFrame->selectionAsString();
    38173822    if (resultString.isEmpty())
    … …  
    47654770void WebPage::advanceToNextMisspelling(bool startBeforeSelection)
    47664771{
    4767     Frame& frame = m_page->focusController().focusedOrMainFrame();
    4768     frame.editor().advanceToNextMisspelling(startBeforeSelection);
     4772    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4773    frame->editor().advanceToNextMisspelling(startBeforeSelection);
    47694774}
    47704775#endif
    … …  
    47724777bool WebPage::hasRichlyEditableSelection() const
    47734778{
    4774     auto& frame = m_page->focusController().focusedOrMainFrame();
     4779    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    47754780    if (m_page->dragCaretController().isContentRichlyEditable())
    47764781        return true;
    47774782
    4778     return frame.selection().selection().isContentRichlyEditable();
     4783    return frame->selection().selection().isContentRichlyEditable();
    47794784}
    47804785
    47814786void WebPage::changeSpellingToWord(const String& word)
    47824787{
    4783     replaceSelectionWithText(&m_page->focusController().focusedOrMainFrame(), word);
     4788    replaceSelectionWithText(&CheckedRef(m_page->focusController())->focusedOrMainFrame(), word);
    47844789}
    47854790
    … …  
    48034808void WebPage::uppercaseWord()
    48044809{
    4805     m_page->focusController().focusedOrMainFrame().editor().uppercaseWord();
     4810    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4811    frame->editor().uppercaseWord();
    48064812}
    48074813
    48084814void WebPage::lowercaseWord()
    48094815{
    4810     m_page->focusController().focusedOrMainFrame().editor().lowercaseWord();
     4816    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4817    frame->editor().lowercaseWord();
    48114818}
    48124819
    48134820void WebPage::capitalizeWord()
    48144821{
    4815     m_page->focusController().focusedOrMainFrame().editor().capitalizeWord();
     4822    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4823    frame->editor().capitalizeWord();
    48164824}
    48174825#endif
    … …  
    48514859void WebPage::clearSelection()
    48524860{
    4853     m_page->focusController().focusedOrMainFrame().selection().clear();
     4861    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4862    frame->selection().clear();
    48544863}
    48554864#endif
    … …  
    48574866void WebPage::restoreSelectionInFocusedEditableElement()
    48584867{
    4859     Frame& frame = m_page->focusController().focusedOrMainFrame();
    4860     if (!frame.selection().isNone())
    4861         return;
    4862 
    4863     if (auto document = frame.document()) {
    4864         if (auto element = document->focusedElement())
     4868    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4869    if (!frame->selection().isNone())
     4870        return;
     4871
     4872    if (RefPtr document = frame->document()) {
     4873        if (RefPtr element = document->focusedElement())
    48654874            element->updateFocusAppearance(SelectionRestorationMode::RestoreOrSelectAll, SelectionRevealMode::DoNotReveal);
    48664875    }
    … …  
    55775586void WebPage::handleAlternativeTextUIResult(const String& result)
    55785587{
    5579     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5580     frame.editor().handleAlternativeTextUIResult(result);
     5588    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5589    frame->editor().handleAlternativeTextUIResult(result);
    55815590}
    55825591#endif
    … …  
    56015610void WebPage::setCompositionForTesting(const String& compositionString, uint64_t from, uint64_t length, bool suppressUnderline, const Vector<CompositionHighlight>& highlights)
    56025611{
    5603     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5604     if (!frame.editor().canEdit())
     5612    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5613    if (!frame->editor().canEdit())
    56055614        return;
    56065615
    … …  
    56095618        underlines.append(CompositionUnderline(0, compositionString.length(), CompositionUnderlineColor::TextColor, Color(Color::black), false));
    56105619
    5611     frame.editor().setComposition(compositionString, underlines, highlights, from, from + length);
     5620    frame->editor().setComposition(compositionString, underlines, highlights, from, from + length);
    56125621}
    56135622
    56145623bool WebPage::hasCompositionForTesting()
    56155624{
    5616     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5617     return frame.editor().hasComposition();
     5625    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5626    return frame->editor().hasComposition();
    56185627}
    56195628
    56205629void WebPage::confirmCompositionForTesting(const String& compositionString)
    56215630{
    5622     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5623     if (!frame.editor().canEdit())
     5631    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5632    if (!frame->editor().canEdit())
    56245633        return;
    56255634
    56265635    if (compositionString.isNull())
    5627         frame.editor().confirmComposition();
    5628     frame.editor().confirmComposition(compositionString);
     5636        frame->editor().confirmComposition();
     5637    frame->editor().confirmComposition(compositionString);
    56295638}
    56305639
    … …  
    57425751void WebPage::setTextAsync(const String& text)
    57435752{
    5744     auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     5753    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    57455754    if (frame->selection().selection().isContentEditable()) {
    57465755        UserTypingGestureIndicator indicator(frame.get());
    … …  
    57655774    platformWillPerformEditingCommand();
    57665775
    5767     auto& frame = m_page->focusController().focusedOrMainFrame();
    5768 
    5769     Ref<Frame> protector(frame);
    5770 
    5771     UserGestureIndicator gestureIndicator { options.processingUserGesture ? ProcessingUserGesture : NotProcessingUserGesture, frame.document() };
     5776    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5777
     5778    UserGestureIndicator gestureIndicator { options.processingUserGesture ? ProcessingUserGesture : NotProcessingUserGesture, frame->document() };
    57725779
    57735780    bool replacesText = false;
    … …  
    57755782        if (auto replacementRange = EditingRange::toRange(frame, replacementEditingRange, options.editingRangeIsRelativeTo)) {
    57765783            SetForScope<bool> isSelectingTextWhileInsertingAsynchronously(m_isSelectingTextWhileInsertingAsynchronously, options.suppressSelectionUpdate);
    5777             frame.selection().setSelection(VisibleSelection(*replacementRange));
     5784            frame->selection().setSelection(VisibleSelection(*replacementRange));
    57785785            replacesText = replacementEditingRange.length;
    57795786        }
    … …  
    57835790        send(Messages::WebPageProxy::RegisterInsertionUndoGrouping());
    57845791
    5785     RefPtr<Element> focusedElement = frame.document() ? frame.document()->focusedElement() : nullptr;
     5792    RefPtr focusedElement = frame->document() ? frame->document()->focusedElement() : nullptr;
    57865793    if (focusedElement && options.shouldSimulateKeyboardInput)
    57875794        focusedElement->dispatchEvent(Event::create(eventNames().keydownEvent, Event::CanBubble::Yes, Event::IsCancelable::Yes));
    57885795
    5789     if (!frame.editor().hasComposition()) {
     5796    if (!frame->editor().hasComposition()) {
    57905797        // An insertText: might be handled by other responders in the chain if we don't handle it.
    57915798        // One example is space bar that results in scrolling down the page.
    5792         frame.editor().insertText(text, nullptr, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard);
     5799        frame->editor().insertText(text, nullptr, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard);
    57935800    } else
    5794         frame.editor().confirmComposition(text);
     5801        frame->editor().confirmComposition(text);
    57955802
    57965803    if (focusedElement && options.shouldSimulateKeyboardInput) {
    … …  
    58025809void WebPage::hasMarkedText(CompletionHandler<void(bool)>&& completionHandler)
    58035810{
    5804     completionHandler(m_page->focusController().focusedOrMainFrame().editor().hasComposition());
     5811    completionHandler(CheckedRef(m_page->focusController())->focusedOrMainFrame().editor().hasComposition());
    58055812}
    58065813
    58075814void WebPage::getMarkedRangeAsync(CompletionHandler<void(const EditingRange&)>&& completionHandler)
    58085815{
    5809     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5810     completionHandler(EditingRange::fromRange(frame, frame.editor().compositionRange()));
     5816    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5817    completionHandler(EditingRange::fromRange(frame, frame->editor().compositionRange()));
    58115818}
    58125819
    58135820void WebPage::getSelectedRangeAsync(CompletionHandler<void(const EditingRange&)>&& completionHandler)
    58145821{
    5815     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5816     completionHandler(EditingRange::fromRange(frame, frame.selection().selection().toNormalizedRange()));
     5822    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5823    completionHandler(EditingRange::fromRange(frame, frame->selection().selection().toNormalizedRange()));
    58175824}
    58185825
    … …  
    58215828    constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::DisallowUserAgentShadowContent,  HitTestRequest::Type::AllowChildFrameContent };
    58225829    auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(point, hitType);
    5823     auto& frame = result.innerNonSharedNode() ? *result.innerNodeFrame() : m_page->focusController().focusedOrMainFrame();
    5824     auto range = frame.rangeForPoint(result.roundedPointInInnerNodeFrame());
     5830    Ref frame = result.innerNonSharedNode() ? *result.innerNodeFrame() : CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5831    auto range = frame->rangeForPoint(result.roundedPointInInnerNodeFrame());
    58255832    auto editingRange = EditingRange::fromRange(frame, range);
    58265833    completionHandler(editingRange.location);
    … …  
    58295836void WebPage::firstRectForCharacterRangeAsync(const EditingRange& editingRange, CompletionHandler<void(const WebCore::IntRect&, const EditingRange&)>&& completionHandler)
    58305837{
    5831     auto& frame = m_page->focusController().focusedOrMainFrame();
     5838    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    58325839    auto range = EditingRange::toRange(frame, editingRange);
    58335840    if (!range)
    … …  
    58355842
    58365843    // FIXME: Pass an EditingRange that matches the range of the first rect, rather than the entire passed-in range?
    5837     auto rect = frame.view()->contentsToWindow(frame.editor().firstRectForRange(*range));
     5844    auto rect = RefPtr(frame->view())->contentsToWindow(frame->editor().firstRectForRange(*range));
    58385845    completionHandler(rect, editingRange);
    58395846}
    … …  
    58435850    platformWillPerformEditingCommand();
    58445851
    5845     auto& frame = m_page->focusController().focusedOrMainFrame();
    5846     if (frame.selection().selection().isContentEditable()) {
     5852    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5853    if (frame->selection().selection().isContentEditable()) {
    58475854        if (replacementEditingRange.location != notFound) {
    58485855            if (auto replacementRange = EditingRange::toRange(frame, replacementEditingRange))
    5849                 frame.selection().setSelection(VisibleSelection(*replacementRange));
     5856                frame->selection().setSelection(VisibleSelection(*replacementRange));
    58505857        }
    5851         frame.editor().setComposition(text, underlines, highlights, selection.location, selection.location + selection.length);
     5858        frame->editor().setComposition(text, underlines, highlights, selection.location, selection.location + selection.length);
    58525859    }
    58535860}
    … …  
    58575864    platformWillPerformEditingCommand();
    58585865
    5859     Frame& frame = m_page->focusController().focusedOrMainFrame();
    5860     frame.editor().confirmComposition();
     5866    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     5867    frame->editor().confirmComposition();
    58615868}
    58625869
    … …  
    59425949void WebPage::didChangeSelectionOrOverflowScrollPosition()
    59435950{
    5944     Frame& frame = m_page->focusController().focusedOrMainFrame();
     5951    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    59455952    // The act of getting Dictionary Popup info can make selection changes that we should not propagate to the UIProcess.
    59465953    // Specifically, if there is a caret selection, it will change to a range selection of the word around the caret. And
    59475954    // then it will change back.
    5948     if (frame.editor().isGettingDictionaryPopupInfo())
     5955    if (frame->editor().isGettingDictionaryPopupInfo())
    59495956        return;
    59505957
    … …  
    59605967    if (!hasPreviouslyFocusedDueToUserInteraction && m_hasEverFocusedElementDueToUserInteractionSincePageTransition) {
    59615968#if HAVE(TOUCH_BAR)
    5962         if (frame.document()->quirks().isTouchBarUpdateSupressedForHiddenContentEditable()) {
     5969        if (frame->document()->quirks().isTouchBarUpdateSupressedForHiddenContentEditable()) {
    59635970            m_isTouchBarUpdateSupressedForHiddenContentEditable = true;
    59645971            send(Messages::WebPageProxy::SetIsTouchBarUpdateSupressedForHiddenContentEditable(m_isTouchBarUpdateSupressedForHiddenContentEditable));
    59655972        }
    59665973
    5967         if (frame.document()->quirks().isNeverRichlyEditableForTouchBar()) {
     5974        if (frame->document()->quirks().isNeverRichlyEditableForTouchBar()) {
    59685975            m_isNeverRichlyEditableForTouchBar = true;
    59695976            send(Messages::WebPageProxy::SetIsNeverRichlyEditableForTouchBar(m_isNeverRichlyEditableForTouchBar));
    … …  
    59785985    // FIXME: Many changes that affect composition node do not go through didChangeSelection(). We need to do something when DOM manipulation affects the composition, because otherwise input method's idea about it will be different from Editor's.
    59795986    // FIXME: We can't cancel composition when selection changes to NoSelection, but we probably should.
    5980     if (frame.editor().hasComposition() && !frame.editor().ignoreSelectionChanges() && !frame.selection().isNone()) {
    5981         frame.editor().cancelComposition();
     5987    if (frame->editor().hasComposition() && !frame->editor().ignoreSelectionChanges() && !frame->selection().isNone()) {
     5988        frame->editor().cancelComposition();
    59825989        discardedComposition();
    59835990        return;
    … …  
    61096116void WebPage::didEndUserTriggeredSelectionChanges()
    61106117{
    6111     Frame& frame = m_page->focusController().focusedOrMainFrame();
    6112     if (!frame.editor().ignoreSelectionChanges())
     6118    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     6119    if (!frame->editor().ignoreSelectionChanges())
    61136120        sendEditorStateUpdate();
    61146121}
    … …  
    64986505void WebPage::sendEditorStateUpdate()
    64996506{
    6500     Frame& frame = m_page->focusController().focusedOrMainFrame();
    6501     if (frame.editor().ignoreSelectionChanges() || !frame.document() || !frame.document()->hasLivingRenderTree())
     6507    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     6508    if (frame->editor().ignoreSelectionChanges() || !frame->document() || !frame->document()->hasLivingRenderTree())
    65026509        return;
    65036510
    … …  
    65876594        return;
    65886595
    6589     Frame& frame = m_page->focusController().focusedOrMainFrame();
    6590     if (frame.editor().ignoreSelectionChanges())
     6596    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     6597    if (frame->editor().ignoreSelectionChanges())
    65916598        return;
    65926599
    … …  
    71667173void WebPage::insertAttachment(const String& identifier, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType, CompletionHandler<void()>&& callback)
    71677174{
    7168     auto& frame = m_page->focusController().focusedOrMainFrame();
    7169     frame.editor().insertAttachment(identifier, WTFMove(fileSize), fileName, contentType);
     7175    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     7176    frame->editor().insertAttachment(identifier, WTFMove(fileSize), fileName, contentType);
    71707177    callback();
    71717178}
    … …  
    76317638    SetForScope<WebCore::HighlightRequestOriginatedInApp> highlightRequestOriginScope { m_highlightRequestOriginatedInApp, requestOriginatedInApp };
    76327639
    7633     auto document = makeRefPtr(m_page->focusController().focusedOrMainFrame().document());
     7640    RefPtr document = CheckedRef(m_page->focusController())->focusedOrMainFrame().document();
    76347641
    76357642    auto frame = makeRefPtr(document->frame());
    … …  
    76497656void WebPage::restoreAppHighlightsAndScrollToIndex(const Vector<SharedMemory::IPCHandle>&& memoryHandles, const std::optional<unsigned> index)
    76507657{
    7651     auto document = makeRefPtr(m_page->focusController().focusedOrMainFrame().document());
     7658    RefPtr document = CheckedRef(m_page->focusController())->focusedOrMainFrame().document();
    76527659
    76537660    unsigned i = 0;
  • trunk/Source/WebKit/WebProcess/WebPage/ios/FindControllerIOS.mm

    r278560 r282191  
    158158    // Therefore, we need to force an update no matter what.
    159159
    160     Frame& frame = m_webPage->corePage()->focusController().focusedOrMainFrame();
    161     frame.selection().setUpdateAppearanceEnabled(true);
    162     frame.selection().updateAppearance();
    163     frame.selection().setUpdateAppearanceEnabled(false);
     160    Ref frame = CheckedRef(m_webPage->corePage()->focusController())->focusedOrMainFrame();
     161    frame->selection().setUpdateAppearanceEnabled(true);
     162    frame->selection().updateAppearance();
     163    frame->selection().setUpdateAppearanceEnabled(false);
    164164
    165165    // Scrolling the main frame is handled by the SmartMagnificationController class but we still
    … …  
    168168    // text, so we reveal the text at the center of the viewport.
    169169    // FIXME: Find a better way to estimate the obscured area (https://webkit.org/b/183889).
    170     frame.selection().revealSelection(SelectionRevealMode::RevealUpToMainFrame, ScrollAlignment::alignCenterAlways, WebCore::DoNotRevealExtent);
     170    frame->selection().revealSelection(SelectionRevealMode::RevealUpToMainFrame, ScrollAlignment::alignCenterAlways, WebCore::DoNotRevealExtent);
    171171}
    172172
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r281970 r282191  
    358358{
    359359#if ENABLE(CONTENT_CHANGE_OBSERVER)
    360     auto& frame = m_page->focusController().focusedOrMainFrame();
    361     if (auto* document = frame.document()) {
     360    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     361    if (RefPtr document = frame->document()) {
    362362        if (auto* holdingTank = document->domTimerHoldingTankIfExists())
    363363            holdingTank->removeAll();
    … …  
    573573void WebPage::getSelectionContext(CompletionHandler<void(const String&, const String&, const String&)>&& completionHandler)
    574574{
    575     Frame& frame = m_page->focusController().focusedOrMainFrame();
    576     if (!frame.selection().isRange())
     575    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     576    if (!frame->selection().isRange())
    577577        return completionHandler({ }, { }, { });
    578578    const int selectionExtendedContextLength = 350;
    579579
    580     auto& selection = frame.selection().selection();
     580    auto& selection = frame->selection().selection();
    581581    String selectedText = plainTextForContext(selection.firstRange());
    582582    String textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(selection.start(), selectionExtendedContextLength, SelectionDirection::Backward));
    … …  
    666666void WebPage::updateSelectionAppearance()
    667667{
    668     auto& frame = m_page->focusController().focusedOrMainFrame();
    669     auto& editor = frame.editor();
     668    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     669    auto& editor = frame->editor();
    670670    if (editor.ignoreSelectionChanges())
    671671        return;
    … …  
    674674        return;
    675675
    676     if (!editor.hasComposition() && frame.selection().selection().isNone())
     676    if (!editor.hasComposition() && frame->selection().selection().isNone())
    677677        return;
    678678
    … …  
    695695{
    696696    PlatformKeyboardEvent keyEvent;
    697     auto& frame = m_page->focusController().focusedOrMainFrame();
     697    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    698698   
    699699    OptionSet<PlatformEvent::Modifier> modifiers;
    … …  
    734734    PlatformKeyboardEvent::setCurrentModifierState(modifiers);
    735735   
    736     frame.eventHandler().keyEvent(keyEvent);
     736    frame->eventHandler().keyEvent(keyEvent);
    737737}
    738738
    … …  
    839839    Frame& mainframe = m_page->mainFrame();
    840840
    841     RefPtr<Frame> oldFocusedFrame = m_page->focusController().focusedFrame();
     841    RefPtr<Frame> oldFocusedFrame = CheckedRef(m_page->focusController())->focusedFrame();
    842842    RefPtr<Element> oldFocusedElement = oldFocusedFrame ? oldFocusedFrame->document()->focusedElement() : nullptr;
    843843
    … …  
    865865        return;
    866866
    867     RefPtr<Frame> newFocusedFrame = m_page->focusController().focusedFrame();
     867    RefPtr<Frame> newFocusedFrame = CheckedRef(m_page->focusController())->focusedFrame();
    868868    RefPtr<Element> newFocusedElement = newFocusedFrame ? newFocusedFrame->document()->focusedElement() : nullptr;
    869869
    … …  
    10021002    m_pendingImageElementsForDropSnapshot.clear();
    10031003
    1004     auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     1004    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    10051005    if (auto selectionRange = frame->selection().selection().toNormalizedRange()) {
    10061006        m_pendingImageElementsForDropSnapshot = visibleImageElementsInRangeWithNonLoadedImages(*selectionRange);
    … …  
    11741174void WebPage::clearSelectionAfterTapIfNeeded()
    11751175{
    1176     if (m_page->focusController().focusedOrMainFrame().selection().selection().isContentEditable())
     1176    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1177    if (frame->selection().selection().isContentEditable())
    11771178        return;
    11781179
    … …  
    13771378        setFocusedFrameBeforeSelectingTextAtLocation(point);
    13781379
    1379     auto& frame = m_page->focusController().focusedOrMainFrame();
     1380    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    13801381    VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
    13811382
    … …  
    13891390    switch (static_cast<GestureType>(gestureType)) {
    13901391    case GestureType::PhraseBoundary: {
    1391         if (!frame.editor().hasComposition())
     1392        if (!frame->editor().hasComposition())
    13921393            break;
    1393         auto markedRange = frame.editor().compositionRange();
     1394        auto markedRange = frame->editor().compositionRange();
    13941395        auto startPosition = VisiblePosition { makeDeprecatedLegacyPosition(markedRange->start) };
    13951396        position = std::clamp(position, startPosition, VisiblePosition { makeDeprecatedLegacyPosition(markedRange->end) });
    13961397        if (wkGestureState != GestureRecognizerState::Began)
    1397             flags = distanceBetweenPositions(startPosition, frame.selection().selection().start()) != distanceBetweenPositions(startPosition, position) ? PhraseBoundaryChanged : OptionSet<SelectionFlags> { };
     1398            flags = distanceBetweenPositions(startPosition, frame->selection().selection().start()) != distanceBetweenPositions(startPosition, position) ? PhraseBoundaryChanged : OptionSet<SelectionFlags> { };
    13981399        else
    13991400            flags = PhraseBoundaryChanged;
    … …  
    14991500    }
    15001501    if (range)
    1501         frame.selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1502        frame->selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    15021503
    15031504    completionHandler(point, gestureType, gestureState, flags);
    … …  
    16971698{
    16981699    m_startingGestureRange = std::nullopt;
    1699     m_page->focusController().focusedOrMainFrame().selection().clear();
     1700    CheckedRef(m_page->focusController())->focusedOrMainFrame().selection().clear();
    17001701}
    17011702
    17021703void WebPage::dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch touch, const IntPoint& point)
    17031704{
    1704     auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     1705    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    17051706    if (!frame->selection().selection().isContentEditable())
    17061707        return;
    … …  
    17331734void WebPage::updateSelectionWithTouches(const IntPoint& point, SelectionTouch selectionTouch, bool baseIsStart, CompletionHandler<void(const WebCore::IntPoint&, SelectionTouch, OptionSet<SelectionFlags>)>&& completionHandler)
    17341735{
    1735     Frame& frame = m_page->focusController().focusedOrMainFrame();
    1736     IntPoint pointInDocument = frame.view()->rootViewToContents(point);
    1737     VisiblePosition position = frame.visiblePositionForPoint(pointInDocument);
     1736    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1737    IntPoint pointInDocument = RefPtr(frame->view())->rootViewToContents(point);
     1738    VisiblePosition position = frame->visiblePositionForPoint(pointInDocument);
    17381739    if (position.isNull())
    17391740        return completionHandler(point, selectionTouch, { });
    … …  
    17511752
    17521753    case SelectionTouch::Ended:
    1753         if (frame.selection().selection().isContentEditable())
     1754        if (frame->selection().selection().isContentEditable())
    17541755            range = makeSimpleRange(closestWordBoundaryForPosition(position));
    17551756        else
    … …  
    17581759
    17591760    case SelectionTouch::EndedMovingForward:
    1760         range = rangeAtWordBoundaryForPosition(&frame, position, baseIsStart, SelectionDirection::Forward);
     1761        range = rangeAtWordBoundaryForPosition(frame.ptr(), position, baseIsStart, SelectionDirection::Forward);
    17611762        break;
    17621763
    17631764    case SelectionTouch::EndedMovingBackward:
    1764         range = rangeAtWordBoundaryForPosition(&frame, position, baseIsStart, SelectionDirection::Backward);
     1765        range = rangeAtWordBoundaryForPosition(frame.ptr(), position, baseIsStart, SelectionDirection::Backward);
    17651766        break;
    17661767
    … …  
    17711772
    17721773    if (range)
    1773         frame.selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1774        frame->selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    17741775
    17751776    completionHandler(point, selectionTouch, flags);
    … …  
    17781779void WebPage::selectWithTwoTouches(const WebCore::IntPoint& from, const WebCore::IntPoint& to, GestureType gestureType, GestureRecognizerState gestureState, CompletionHandler<void(const WebCore::IntPoint&, GestureType, GestureRecognizerState, OptionSet<SelectionFlags>)>&& completionHandler)
    17791780{
    1780     Frame& frame = m_page->focusController().focusedOrMainFrame();
    1781     auto fromPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(from));
    1782     auto toPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(to));
     1781    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1782    RefPtr view = frame->view();
     1783    auto fromPosition = frame->visiblePositionForPoint(view->rootViewToContents(from));
     1784    auto toPosition = frame->visiblePositionForPoint(view->rootViewToContents(to));
    17831785    if (auto range = makeSimpleRange(fromPosition, toPosition)) {
    17841786        if (!(fromPosition < toPosition))
    17851787            std::swap(range->start, range->end);
    1786         frame.selection().setSelectedRange(range, fromPosition.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1788        frame->selection().setSelectedRange(range, fromPosition.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    17871789    }
    17881790
    … …  
    17951797    auto callCompletionHandlerOnExit = makeScopeExit(WTFMove(completionHandler));
    17961798
    1797     Frame& frame = m_page->focusController().focusedOrMainFrame();
     1799    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    17981800    // For the moment we handle only TextGranularity::WordGranularity.
    1799     if (granularity != TextGranularity::WordGranularity || !frame.selection().isCaret())
    1800         return;
    1801 
    1802     VisiblePosition position = frame.selection().selection().start();
     1801    if (granularity != TextGranularity::WordGranularity || !frame->selection().isCaret())
     1802        return;
     1803
     1804    VisiblePosition position = frame->selection().selection().start();
    18031805    auto wordRange = wordRangeFromPosition(position);
    18041806    if (!wordRange)
    … …  
    18081810    bool shouldDispatchMouseEvents = shouldDispatchSyntheticMouseEventsWhenModifyingSelection();
    18091811    if (shouldDispatchMouseEvents) {
    1810         auto startLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->start)).absoluteCaretBounds()).center();
    1811         endLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->end)).absoluteCaretBounds()).center();
     1812        RefPtr view = frame->view();
     1813        auto startLocationForSyntheticMouseEvents = view->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->start)).absoluteCaretBounds()).center();
     1814        endLocationForSyntheticMouseEvents = view->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->end)).absoluteCaretBounds()).center();
    18121815        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startLocationForSyntheticMouseEvents);
    18131816        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endLocationForSyntheticMouseEvents);
    18141817    }
    18151818
    1816     frame.selection().setSelectedRange(wordRange, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1819    frame->selection().setSelectedRange(wordRange, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    18171820
    18181821    if (shouldDispatchMouseEvents)
    … …  
    18251828        return;
    18261829
    1827     auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
    1828     auto startCaretRect = frame->view()->contentsToRootView(VisiblePosition(frame->selection().selection().start()).absoluteCaretBounds());
    1829     auto endCaretRect = frame->view()->contentsToRootView(VisiblePosition(frame->selection().selection().end()).absoluteCaretBounds());
     1830    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1831    RefPtr view = frame->view();
     1832    auto startCaretRect = view->contentsToRootView(VisiblePosition(frame->selection().selection().start()).absoluteCaretBounds());
     1833    auto endCaretRect = view->contentsToRootView(VisiblePosition(frame->selection().selection().end()).absoluteCaretBounds());
    18301834    dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startCaretRect.center());
    18311835    dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endCaretRect.center());
    … …  
    18351839void WebPage::selectWordBackward()
    18361840{
    1837     Frame& frame = m_page->focusController().focusedOrMainFrame();
    1838     if (!frame.selection().isCaret())
    1839         return;
    1840 
    1841     auto position = frame.selection().selection().visibleStart();
     1841    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1842    if (!frame->selection().isCaret())
     1843        return;
     1844
     1845    auto position = frame->selection().selection().visibleStart();
    18421846    auto startPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward);
    18431847    if (startPosition.isNull() || startPosition == position)
    18441848        return;
    18451849
    1846     frame.selection().setSelectedRange(makeSimpleRange(startPosition, position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1850    frame->selection().setSelectedRange(makeSimpleRange(startPosition, position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    18471851}
    18481852
    18491853void WebPage::moveSelectionByOffset(int32_t offset, CompletionHandler<void()>&& completionHandler)
    18501854{
    1851     Frame& frame = m_page->focusController().focusedOrMainFrame();
     1855    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    18521856   
    1853     VisiblePosition startPosition = frame.selection().selection().end();
     1857    VisiblePosition startPosition = frame->selection().selection().end();
    18541858    if (startPosition.isNull())
    18551859        return;
    … …  
    18621866    }
    18631867    if (position.isNotNull() && startPosition != position)
    1864         frame.selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1868        frame->selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    18651869    completionHandler();
    18661870}
    … …  
    18731877    }
    18741878   
    1875     Frame& frame = m_page->focusController().focusedOrMainFrame();
    1876     auto& selection = frame.selection().selection();
     1879    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1880    auto& selection = frame->selection().selection();
    18771881    if (!selection.isRange())
    18781882        return;
    … …  
    18841888        return;
    18851889
    1886     m_page->mainFrame().eventHandler().startSelectionAutoscroll(renderer, positionInWindow);
     1890    Ref(m_page->mainFrame())->eventHandler().startSelectionAutoscroll(renderer, positionInWindow);
    18871891}
    18881892   
    … …  
    18941898void WebPage::requestEvasionRectsAboveSelection(CompletionHandler<void(const Vector<FloatRect>&)>&& reply)
    18951899{
    1896     auto& frame = m_page->focusController().focusedOrMainFrame();
    1897     auto frameView = makeRefPtr(frame.view());
     1900    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     1901    auto frameView = makeRefPtr(frame->view());
    18981902    if (!frameView) {
    18991903        reply({ });
    … …  
    19011905    }
    19021906
    1903     auto& selection = frame.selection().selection();
     1907    auto selection = frame->selection().selection();
    19041908    if (selection.isNone()) {
    19051909        reply({ });
    … …  
    19201924    float scaleFactor = pageScaleFactor();
    19211925    const double factorOfContentArea = 0.5;
    1922     auto unobscuredContentArea = m_page->mainFrame().view()->unobscuredContentRect().area();
     1926    auto unobscuredContentArea = RefPtr(m_page->mainFrame().view())->unobscuredContentRect().area();
    19231927    if (unobscuredContentArea.hasOverflowed()) {
    19241928        reply({ });
    … …  
    19321936        selectionBoundsInRootViewCoordinates = frameView->contentsToRootView(unionRect(RenderObject::absoluteTextRects(*selectedRange)));
    19331937    else
    1934         selectionBoundsInRootViewCoordinates = frameView->contentsToRootView(frame.selection().absoluteCaretBounds());
     1938        selectionBoundsInRootViewCoordinates = frameView->contentsToRootView(frame->selection().absoluteCaretBounds());
    19351939
    19361940    auto centerOfTargetBounds = selectionBoundsInRootViewCoordinates.center();
    … …  
    19391943    auto clickableNonEditableNode = [&] (const FloatPoint& locationInRootViewCoordinates) -> Node* {
    19401944        FloatPoint adjustedPoint;
    1941         auto* hitNode = m_page->mainFrame().nodeRespondingToClickEvents(locationInRootViewCoordinates, adjustedPoint);
     1945        auto* hitNode = Ref(m_page->mainFrame())->nodeRespondingToClickEvents(locationInRootViewCoordinates, adjustedPoint);
    19421946        if (!hitNode || is<HTMLBodyElement>(hitNode) || is<Document>(hitNode) || hitNode->hasEditableStyle())
    19431947            return nullptr;
    … …  
    19951999void WebPage::getRectsForGranularityWithSelectionOffset(WebCore::TextGranularity granularity, int32_t offset, CompletionHandler<void(const Vector<WebCore::SelectionGeometry>&)>&& completionHandler)
    19962000{
    1997     Frame& frame = m_page->focusController().focusedOrMainFrame();
    1998 
    1999     auto selection = m_storedSelectionForAccessibility.isNone() ? frame.selection().selection() : m_storedSelectionForAccessibility;
     2001    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2002
     2003    auto selection = m_storedSelectionForAccessibility.isNone() ? frame->selection().selection() : m_storedSelectionForAccessibility;
    20002004    auto position = visiblePositionForPositionWithOffset(selection.visibleStart(), offset);
    20012005    auto direction = offset < 0 ? SelectionDirection::Backward : SelectionDirection::Forward;
    … …  
    20072011
    20082012    auto selectionGeometries = RenderObject::collectSelectionGeometriesWithoutUnionInteriorLines(*range);
    2009     convertContentToRootView(*frame.view(), selectionGeometries);
     2013    RefPtr view = frame->view();
     2014    convertContentToRootView(*view, selectionGeometries);
    20102015    completionHandler(selectionGeometries);
    20112016}
    … …  
    20162021        m_storedSelectionForAccessibility = VisibleSelection();
    20172022    else {
    2018         Frame& frame = m_page->focusController().focusedOrMainFrame();
     2023        Frame& frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    20192024        m_storedSelectionForAccessibility = frame.selection().selection();
    20202025    }
    … …  
    20352040void WebPage::getRectsAtSelectionOffsetWithText(int32_t offset, const String& text, CompletionHandler<void(const Vector<WebCore::SelectionGeometry>&)>&& completionHandler)
    20362041{
    2037     Frame& frame = m_page->focusController().focusedOrMainFrame();
    2038     auto& selection = m_storedSelectionForAccessibility.isNone() ? frame.selection().selection() : m_storedSelectionForAccessibility;
     2042    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2043    auto& selection = m_storedSelectionForAccessibility.isNone() ? frame->selection().selection() : m_storedSelectionForAccessibility;
    20392044    auto startPosition = visiblePositionForPositionWithOffset(selection.visibleStart(), offset);
    20402045    auto range = makeSimpleRange(startPosition, visiblePositionForPositionWithOffset(startPosition, text.length()));
    … …  
    20532058
    20542059    auto selectionGeometries = RenderObject::collectSelectionGeometriesWithoutUnionInteriorLines(*range);
    2055     convertContentToRootView(*frame.view(), selectionGeometries);
     2060    RefPtr view = frame->view();
     2061    convertContentToRootView(*view, selectionGeometries);
    20562062    completionHandler(selectionGeometries);
    20572063}
    … …  
    20702076    setFocusedFrameBeforeSelectingTextAtLocation(point);
    20712077
    2072     auto& frame = m_page->focusController().focusedOrMainFrame();
     2078    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    20732079    VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
    20742080   
    20752081    if (position.isNotNull())
    2076         frame.selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2082        frame->selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    20772083    completionHandler();
    20782084}
    … …  
    20802086void WebPage::selectPositionAtBoundaryWithDirection(const WebCore::IntPoint& point, WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, bool isInteractingWithFocusedElement, CompletionHandler<void()>&& completionHandler)
    20812087{
    2082     auto& frame = m_page->focusController().focusedOrMainFrame();
     2088    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    20832089    VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
    20842090
    … …  
    20862092        position = positionOfNextBoundaryOfGranularity(position, granularity, direction);
    20872093        if (position.isNotNull())
    2088             frame.selection().setSelectedRange(makeSimpleRange(position), Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2094            frame->selection().setSelectedRange(makeSimpleRange(position), Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    20892095    }
    20902096    completionHandler();
    … …  
    20932099void WebPage::moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, CompletionHandler<void()>&& completionHandler)
    20942100{
    2095     Frame& frame = m_page->focusController().focusedOrMainFrame();
    2096    
    2097     if (!frame.selection().selection().isNone()) {
     2101    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2102
     2103    if (!frame->selection().selection().isNone()) {
    20982104        bool isForward = (direction == SelectionDirection::Forward || direction == SelectionDirection::Right);
    2099         VisiblePosition position = (isForward) ? frame.selection().selection().visibleEnd() : frame.selection().selection().visibleStart();
     2105        VisiblePosition position = (isForward) ? frame->selection().selection().visibleEnd() : frame->selection().selection().visibleStart();
    21002106        position = positionOfNextBoundaryOfGranularity(position, granularity, direction);
    21012107        if (position.isNotNull())
    2102             frame.selection().setSelectedRange(makeSimpleRange(position), isForward? Affinity::Upstream : Affinity::Downstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2108            frame->selection().setSelectedRange(makeSimpleRange(position), isForward? Affinity::Upstream : Affinity::Downstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    21032109    }
    21042110    completionHandler();
    … …  
    21492155{
    21502156    constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::AllowVisibleChildFrameContentOnly };
    2151     auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(point, hitType);
     2157    auto result = Ref(m_page->mainFrame())->eventHandler().hitTestResultAtPoint(point, hitType);
    21522158    auto* hitNode = result.innerNode();
    2153     if (hitNode && hitNode->renderer())
    2154         m_page->focusController().setFocusedFrame(result.innerNodeFrame());
     2159    if (hitNode && hitNode->renderer()) {
     2160        RefPtr frame = result.innerNodeFrame();
     2161        CheckedRef(m_page->focusController())->setFocusedFrame(frame.get());
     2162    }
    21552163}
    21562164
    … …  
    21592167    setFocusedFrameBeforeSelectingTextAtLocation(point);
    21602168
    2161     auto& frame = m_page->focusController().focusedOrMainFrame();
     2169    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    21622170    auto range = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
    21632171    if (range)
    2164         frame.selection().setSelectedRange(*range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2172        frame->selection().setSelectedRange(*range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    21652173    m_initialSelection = range;
    21662174}
    … …  
    21982206void WebPage::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint& point, WebCore::TextGranularity granularity, bool isInteractingWithFocusedElement, CompletionHandler<void(bool)>&& callback)
    21992207{
    2200     auto& frame = m_page->focusController().focusedOrMainFrame();
     2208    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    22012209    auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
    22022210    auto newRange = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
    … …  
    22162224
    22172225    if (auto range = makeSimpleRange(selectionStart, selectionEnd))
    2218         frame.selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2226        frame->selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    22192227
    22202228    callback(selectionStart == initialSelectionStartPosition);
    … …  
    22232231void WebPage::updateSelectionWithExtentPoint(const WebCore::IntPoint& point, bool isInteractingWithFocusedElement, RespectSelectionAnchor respectSelectionAnchor, CompletionHandler<void(bool)>&& callback)
    22242232{
    2225     auto& frame = m_page->focusController().focusedOrMainFrame();
     2233    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    22262234    auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
    22272235
    … …  
    22342242    if (respectSelectionAnchor == RespectSelectionAnchor::Yes) {
    22352243        if (m_selectionAnchor == Start) {
    2236             selectionStart = frame.selection().selection().visibleStart();
     2244            selectionStart = frame->selection().selection().visibleStart();
    22372245            selectionEnd = position;
    22382246            if (position <= selectionStart) {
    22392247                selectionStart = selectionStart.previous();
    2240                 selectionEnd = frame.selection().selection().visibleEnd();
     2248                selectionEnd = frame->selection().selection().visibleEnd();
    22412249                m_selectionAnchor = End;
    22422250            }
    22432251        } else {
    22442252            selectionStart = position;
    2245             selectionEnd = frame.selection().selection().visibleEnd();
     2253            selectionEnd = frame->selection().selection().visibleEnd();
    22462254            if (position >= selectionEnd) {
    2247                 selectionStart = frame.selection().selection().visibleStart();
     2255                selectionStart = frame->selection().selection().visibleStart();
    22482256                selectionEnd = selectionEnd.next();
    22492257                m_selectionAnchor = Start;
    … …  
    22512259        }
    22522260    } else {
    2253         auto currentStart = frame.selection().selection().visibleStart();
    2254         auto currentEnd = frame.selection().selection().visibleEnd();
     2261        auto currentStart = frame->selection().selection().visibleStart();
     2262        auto currentEnd = frame->selection().selection().visibleEnd();
    22552263        if (position <= currentStart) {
    22562264            selectionStart = position;
    … …  
    22632271   
    22642272    if (auto range = makeSimpleRange(selectionStart, selectionEnd))
    2265         frame.selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     2273        frame->selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
    22662274
    22672275    callback(m_selectionAnchor == Start);
    … …  
    22702278void WebPage::requestDictationContext(CompletionHandler<void(const String&, const String&, const String&)>&& completionHandler)
    22712279{
    2272     Frame& frame = m_page->focusController().focusedOrMainFrame();
    2273     VisiblePosition startPosition = frame.selection().selection().start();
    2274     VisiblePosition endPosition = frame.selection().selection().end();
     2280    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2281    VisiblePosition startPosition = frame->selection().selection().start();
     2282    VisiblePosition endPosition = frame->selection().selection().end();
    22752283    const unsigned dictationContextWordCount = 5;
    22762284
    2277     String selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange());
     2285    String selectedText = plainTextForContext(frame->selection().selection().toNormalizedRange());
    22782286
    22792287    String contextBefore;
    … …  
    23082316void WebPage::replaceSelectedText(const String& oldText, const String& newText)
    23092317{
    2310     Frame& frame = m_page->focusController().focusedOrMainFrame();
    2311     auto wordRange = frame.selection().isCaret()
    2312         ? wordRangeFromPosition(frame.selection().selection().start())
    2313         : frame.selection().selection().toNormalizedRange();
     2318    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2319    auto wordRange = frame->selection().isCaret() ? wordRangeFromPosition(frame->selection().selection().start()) : frame->selection().selection().toNormalizedRange();
    23142320    if (plainTextForContext(wordRange) != oldText)
    23152321        return;
    2316     frame.editor().setIgnoreSelectionChanges(true);
    2317     frame.selection().setSelectedRange(wordRange, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes);
    2318     frame.editor().insertText(newText, 0);
    2319     frame.editor().setIgnoreSelectionChanges(false);
     2322    frame->editor().setIgnoreSelectionChanges(true);
     2323    frame->selection().setSelectedRange(wordRange, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes);
     2324    frame->editor().insertText(newText, 0);
     2325    frame->editor().setIgnoreSelectionChanges(false);
    23202326}
    23212327
    23222328void WebPage::replaceDictatedText(const String& oldText, const String& newText)
    23232329{
    2324     Frame& frame = m_page->focusController().focusedOrMainFrame();
    2325     if (frame.selection().isNone())
     2330    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2331    if (frame->selection().isNone())
    23262332        return;
    23272333   
    2328     if (frame.selection().isRange()) {
    2329         frame.editor().deleteSelectionWithSmartDelete(false);
    2330         return;
    2331     }
    2332     VisiblePosition position = frame.selection().selection().start();
     2334    if (frame->selection().isRange()) {
     2335        frame->editor().deleteSelectionWithSmartDelete(false);
     2336        return;
     2337    }
     2338    VisiblePosition position = frame->selection().selection().start();
    23332339    for (size_t i = 0; i < oldText.length(); ++i)
    23342340        position = position.previous();
    23352341    if (position.isNull())
    2336         position = startOfDocument(frame.document());
    2337     auto range = makeSimpleRange(position, frame.selection().selection().start());
     2342        position = startOfDocument(frame->document());
     2343    auto range = makeSimpleRange(position, frame->selection().selection().start());
    23382344
    23392345    if (plainTextForContext(range) != oldText)
    … …  
    23412347
    23422348    // We don't want to notify the client that the selection has changed until we are done inserting the new text.
    2343     frame.editor().setIgnoreSelectionChanges(true);
    2344     frame.selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes);
    2345     frame.editor().insertText(newText, 0);
    2346     frame.editor().setIgnoreSelectionChanges(false);
     2349    frame->editor().setIgnoreSelectionChanges(true);
     2350    frame->selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes);
     2351    frame->editor().insertText(newText, 0);
     2352    frame->editor().setIgnoreSelectionChanges(false);
    23472353}
    23482354
    23492355void WebPage::requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&& reply)
    23502356{
    2351     auto& frame = m_page->focusController().focusedOrMainFrame();
    2352     if (!frame.selection().isCaret()) {
     2357    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2358    if (!frame->selection().isCaret()) {
    23532359        reply({ });
    23542360        return;
    23552361    }
    23562362
    2357     auto range = wordRangeFromPosition(frame.selection().selection().visibleStart());
     2363    auto range = wordRangeFromPosition(frame->selection().selection().visibleStart());
    23582364    if (!range) {
    23592365        reply({ });
    … …  
    23762382
    23772383    auto rootViewSelectionRects = selectionGeometries.map([&](const auto& selectionGeometry) -> FloatRect {
    2378         return frame.view()->contentsToRootView(selectionGeometry.rect());
     2384        return frame->view()->contentsToRootView(selectionGeometry.rect());
    23792385    });
    23802386
    23812387    bool multipleFonts = false;
    23822388    CTFontRef font = nil;
    2383     if (auto coreFont = frame.editor().fontForSelection(multipleFonts))
     2389    if (auto coreFont = frame->editor().fontForSelection(multipleFonts))
    23842390        font = coreFont->getCTFont();
    23852391
    … …  
    24172423bool WebPage::applyAutocorrectionInternal(const String& correction, const String& originalText)
    24182424{
    2419     auto& frame = m_page->focusController().focusedOrMainFrame();
    2420     if (!frame.selection().isCaretOrRange())
     2425    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2426    if (!frame->selection().isCaretOrRange())
    24212427        return false;
    24222428
    … …  
    24252431    auto originalTextWithFoldedQuoteMarks = foldQuoteMarks(originalText);
    24262432
    2427     if (frame.selection().isCaret()) {
    2428         auto position = frame.selection().selection().visibleStart();
     2433    if (frame->selection().isCaret()) {
     2434        auto position = frame->selection().selection().visibleStart();
    24292435        range = wordRangeFromPosition(position);
    24302436        textForRange = plainTextForContext(range);
    … …  
    24372443                position = position.previous();
    24382444            if (position.isNull())
    2439                 position = startOfDocument(frame.document());
    2440             range = makeSimpleRange(position, frame.selection().selection().start());
     2445                position = startOfDocument(frame->document());
     2446            range = makeSimpleRange(position, frame->selection().selection().start());
    24412447            textForRange = plainTextForContext(range);
    24422448            unsigned loopCount = 0;
    … …  
    24442450            while (textForRange.length() && textForRange.length() > originalText.length() && loopCount < maxPositionsAttempts) {
    24452451                position = position.next();
    2446                 if (position.isNotNull() && position >= frame.selection().selection().start())
     2452                if (position.isNotNull() && position >= frame->selection().selection().start())
    24472453                    range = std::nullopt;
    24482454                else
    2449                     range = makeSimpleRange(position, frame.selection().selection().start());
     2455                    range = makeSimpleRange(position, frame->selection().selection().start());
    24502456                textForRange = plainTextForContext(range);
    24512457                loopCount++;
    … …  
    24602466    } else {
    24612467        // Range selection.
    2462         range = frame.selection().selection().toNormalizedRange();
     2468        range = frame->selection().selection().toNormalizedRange();
    24632469        if (!range)
    24642470            return false;
    … …  
    24752481        affinity = VisiblePosition(makeDeprecatedLegacyPosition(range->start), Affinity::Upstream).affinity();
    24762482   
    2477     frame.selection().setSelectedRange(range, affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes);
     2483    frame->selection().setSelectedRange(range, affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes);
    24782484    if (correction.length())
    2479         frame.editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion);
     2485        frame->editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion);
    24802486    else if (originalText.length())
    2481         frame.editor().deleteWithDirection(SelectionDirection::Backward, TextGranularity::CharacterGranularity, false, true);
     2487        frame->editor().deleteWithDirection(SelectionDirection::Backward, TextGranularity::CharacterGranularity, false, true);
    24822488    return true;
    24832489}
    … …  
    24912497    EditingRange markedTextRange;
    24922498
    2493     auto& frame = m_page->focusController().focusedOrMainFrame();
    2494     VisiblePosition startPosition = frame.selection().selection().start();
    2495     VisiblePosition endPosition = frame.selection().selection().end();
     2499    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     2500    VisiblePosition startPosition = frame->selection().selection().start();
     2501    VisiblePosition endPosition = frame->selection().selection().end();
    24962502    const unsigned minContextWordCount = 3;
    24972503    const unsigned minContextLenght = 12;
    24982504    const unsigned maxContextLength = 30;
    24992505
    2500     if (frame.selection().isRange())
    2501         selectedText = plainTextForContext(frame.selection().selection().toNormalizedRange());
    2502 
    2503     if (auto compositionRange = frame.editor().compositionRange()) {
     2506    if (frame->selection().isRange())
     2507        selectedText = plainTextForContext(frame->selection().selection().toNormalizedRange());
     2508
     2509    if (auto compositionRange = frame->editor().compositionRange()) {
    25042510        auto markedTextBefore = plainTextForContext(makeSimpleRange(compositionRange->start, startPosition));
    25052511        auto markedTextAfter = plainTextForContext(makeSimpleRange(endPosition, compositionRange->end));
    … …  
    26372643static void focusedElementPositionInformation(WebPage& page, Element& focusedElement, const InteractionInformationRequest& request, InteractionInformationAtPosition& info)
    26382644{
    2639     const Frame& frame = page.corePage()->focusController().focusedOrMainFrame();
    2640     if (!frame.editor().hasComposition())
     2645    Ref frame = CheckedRef(page.corePage()->focusController())->focusedOrMainFrame();
     2646    if (!frame->editor().hasComposition())
    26412647        return;
    26422648
    26432649    const uint32_t kHitAreaWidth = 66;
    26442650    const uint32_t kHitAreaHeight = 66;
    2645     FrameView& view = *frame.view();
    2646     IntPoint adjustedPoint(view.rootViewToContents(request.point));
     2651    Ref view = *frame->view();
     2652    IntPoint adjustedPoint(view->rootViewToContents(request.point));
    26472653    IntPoint constrainedPoint = constrainPoint(adjustedPoint, frame, focusedElement);
    2648     VisiblePosition position = frame.visiblePositionForPoint(constrainedPoint);
    2649 
    2650     auto compositionRange = frame.editor().compositionRange();
     2654    VisiblePosition position = frame->visiblePositionForPoint(constrainedPoint);
     2655
     2656    auto compositionRange = frame->editor().compositionRange();
    26512657    if (!compositionRange)
    26522658        return;
    … …  
    26582664    else if (position > endPosition)
    26592665        position = endPosition;
    2660     IntRect caretRect = view.contentsToRootView(position.absoluteCaretBounds());
     2666    IntRect caretRect = view->contentsToRootView(position.absoluteCaretBounds());
    26612667    float deltaX = abs(caretRect.x() + (caretRect.width() / 2) - request.point.x());
    26622668    float deltaYFromTheTop = abs(caretRect.y() - request.point.y());
    … …  
    31463152}
    31473153
    3148 static inline Element* nextAssistableElement(Node* startNode, Page& page, bool isForward)
     3154static inline RefPtr<Element> nextAssistableElement(Node* startNode, Page& page, bool isForward)
    31493155{
    31503156    if (!is<Element>(startNode))
    31513157        return nullptr;
    31523158
    3153     Element* nextElement = downcast<Element>(startNode);
     3159    RefPtr nextElement = downcast<Element>(startNode);
     3160    CheckedRef focusController { page.focusController() };
    31543161    do {
    3155         nextElement = isForward
    3156             ? page.focusController().nextFocusableElement(*nextElement)
    3157             : page.focusController().previousFocusableElement(*nextElement);
     3162        nextElement = isForward ? focusController->nextFocusableElement(*nextElement) : focusController->previousFocusableElement(*nextElement);
    31583163    } while (nextElement && (!isAssistableElement(*nextElement) || isObscuredElement(*nextElement)));
    31593164
    … …  
    31633168void WebPage::focusNextFocusedElement(bool isForward, CompletionHandler<void()>&& completionHandler)
    31643169{
    3165     Element* nextElement = nextAssistableElement(m_focusedElement.get(), *m_page, isForward);
     3170    auto nextElement = nextAssistableElement(m_focusedElement.get(), *m_page, isForward);
    31663171    m_userIsInteracting = true;
    31673172    if (nextElement)
    … …  
    31733178std::optional<FocusedElementInformation> WebPage::focusedElementInformation()
    31743179{
    3175     RefPtr<Document> document = m_page->focusController().focusedOrMainFrame().document();
     3180    RefPtr<Document> document = CheckedRef(m_page->focusController())->focusedOrMainFrame().document();
    31763181    if (!document || !document->view())
    31773182        return std::nullopt;
    … …  
    32193224    information.allowsUserScaling = m_viewportConfiguration.allowsUserScaling();
    32203225    information.allowsUserScalingIgnoringAlwaysScalable = m_viewportConfiguration.allowsUserScalingIgnoringAlwaysScalable();
    3221     if (auto* nextElement = nextAssistableElement(focusedElement.get(), *m_page, true)) {
     3226    if (auto nextElement = nextAssistableElement(focusedElement.get(), *m_page, true)) {
    32223227        information.nextNodeRect = rootViewBounds(*nextElement);
    32233228        information.hasNextNode = true;
    32243229    }
    3225     if (auto* previousElement = nextAssistableElement(focusedElement.get(), *m_page, false)) {
     3230    if (auto previousElement = nextAssistableElement(focusedElement.get(), *m_page, false)) {
    32263231        information.previousNodeRect = rootViewBounds(*previousElement);
    32273232        information.hasPreviousNode = true;
    … …  
    42474252    m_keyboardIsAttached = keyboardIsAttached;
    42484253
    4249     if (auto* focusedFrame = m_page->focusController().focusedFrame())
     4254    if (RefPtr focusedFrame = CheckedRef(m_page->focusController())->focusedFrame())
    42504255        focusedFrame->eventHandler().capsLockStateMayHaveChanged();
    42514256}
    … …  
    42684273{
    42694274    // Inserting the placeholder may run JavaScript, which can do anything, including frame destruction.
    4270     Ref<Frame> frame = corePage()->focusController().focusedOrMainFrame();
     4275    Ref<Frame> frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    42714276    auto placeholder = frame->editor().insertTextPlaceholder(size);
    42724277    completionHandler(placeholder ? contextForElement(*placeholder) : std::nullopt);
    … …  
    42854290void WebPage::updateSelectionWithDelta(int64_t locationDelta, int64_t lengthDelta, CompletionHandler<void()>&& completionHandler)
    42864291{
    4287     auto frame = makeRef(corePage()->focusController().focusedOrMainFrame());
     4292    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
    42884293    auto root = makeRefPtr(frame->selection().rootEditableElementOrDocumentElement());
    42894294    auto selectionRange = frame->selection().selection().toNormalizedRange();
    … …  
    43674372    }
    43684373
    4369     m_page->focusController().focusedOrMainFrame().document()->updateLayoutIgnorePendingStylesheets();
    4370 
    4371     Ref<Frame> frame = m_page->focusController().focusedOrMainFrame();
     4374    Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     4375    makeRefPtr(frame->document())->updateLayoutIgnorePendingStylesheets();
     4376
    43724377    VisibleSelection selection = frame->selection().selection();
    43734378
    … …  
    45574562    UserGestureIndicator gestureIndicator { ProcessingUserGesture, &target->document() };
    45584563    SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true };
    4559     m_page->focusController().setFocusedElement(target.get(), targetFrame);
     4564    CheckedRef(m_page->focusController())->setFocusedElement(target.get(), targetFrame);
    45604565
    45614566    // Setting the focused element could tear down the element's renderer. Check that we still have one.
    … …  
    46174622void WebPage::animationDidFinishForElement(const WebCore::Element& animatedElement)
    46184623{
    4619     auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     4624    Ref frame = makeRef(CheckedRef(m_page->focusController())->focusedOrMainFrame());
    46204625    auto& selection = frame->selection().selection();
    46214626    if (selection.isNoneOrOrphaned())
Note: See TracChangeset for help on using the changeset viewer.