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

Changeset 236965 in webkit


Ignore:
Timestamp:
Oct 9, 2018, 10:15:21 AM (8 years ago)
Author:
Chris Dumez
Message:

Have DOMWindow get its frame from its document
https://bugs.webkit.org/show_bug.cgi?id=190389

Reviewed by Geoff Garen.

Have DOMWindow get its frame from its document instead of having its own m_frame which can potentially
be out-of-sync.

  • dom/Document.cpp:

(WebCore::Document::frameDestroyed):
(WebCore::Document::willDetachPage):
(WebCore::Document::attachToCachedFrame):

  • dom/Document.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::allowPopUp):
(WebCore::ContextDestructionObserver):
(WebCore::DOMWindow::didSecureTransitionTo):
(WebCore::DOMWindow::frameDestroyed):
(WebCore::DOMWindow::willDetachDocumentFromFrame):
(WebCore::DOMWindow::reconnectDOMWindowProperties):
(WebCore::DOMWindow::isCurrentlyDisplayedInFrame const):
(WebCore::DOMWindow::collectMatchingElementsInFlatTree):
(WebCore::DOMWindow::matchingElementInFlatTree):
(WebCore::DOMWindow::orientation const):
(WebCore::DOMWindow::console const):
(WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
(WebCore::DOMWindow::webkitNamespace):
(WebCore::DOMWindow::postMessage):
(WebCore::DOMWindow::postMessageTimerFired):
(WebCore::DOMWindow::frameElement const):
(WebCore::DOMWindow::focus):
(WebCore::DOMWindow::blur):
(WebCore::DOMWindow::close):
(WebCore::DOMWindow::print):
(WebCore::DOMWindow::stop):
(WebCore::DOMWindow::alert):
(WebCore::DOMWindow::confirm):
(WebCore::DOMWindow::prompt):
(WebCore::DOMWindow::find const):
(WebCore::DOMWindow::outerHeight const):
(WebCore::DOMWindow::outerWidth const):
(WebCore::DOMWindow::innerHeight const):
(WebCore::DOMWindow::innerWidth const):
(WebCore::DOMWindow::screenX const):
(WebCore::DOMWindow::screenY const):
(WebCore::DOMWindow::scrollX const):
(WebCore::DOMWindow::scrollY const):
(WebCore::DOMWindow::closed const):
(WebCore::DOMWindow::length const):
(WebCore::DOMWindow::name const):
(WebCore::DOMWindow::setName):
(WebCore::DOMWindow::setStatus):
(WebCore::DOMWindow::setDefaultStatus):
(WebCore::DOMWindow::self const):
(WebCore::DOMWindow::opener const):
(WebCore::DOMWindow::disownOpener):
(WebCore::DOMWindow::parent const):
(WebCore::DOMWindow::top const):
(WebCore::DOMWindow::getMatchedCSSRules const):
(WebCore::DOMWindow::devicePixelRatio const):
(WebCore::DOMWindow::scrollBy const):
(WebCore::DOMWindow::scrollTo const):
(WebCore::DOMWindow::allowedToChangeWindowGeometry const):
(WebCore::DOMWindow::moveBy const):
(WebCore::DOMWindow::moveTo const):
(WebCore::DOMWindow::resizeBy const):
(WebCore::DOMWindow::resizeTo const):
(WebCore::DOMWindow::clearTimeout):
(WebCore::DOMWindow::isSameSecurityOriginAsMainFrame const):
(WebCore::DOMWindow::finishedLoading):
(WebCore::DOMWindow::setLocation):
(WebCore::DOMWindow::open):
(WebCore::DOMWindow::showModalDialog):
(WebCore::DOMWindow::frame const):
(WebCore::FrameDestructionObserver): Deleted.
(WebCore::DOMWindow::willDetachPage): Deleted.
(WebCore::DOMWindow::detachFromFrame): Deleted.
(WebCore::DOMWindow::attachToFrame): Deleted.

  • page/DOMWindow.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r236964 r236965  
     12018-10-09  Chris Dumez  <cdumez@apple.com>
     2
     3        Have DOMWindow get its frame from its document
     4        https://bugs.webkit.org/show_bug.cgi?id=190389
     5
     6        Reviewed by Geoff Garen.
     7
     8        Have DOMWindow get its frame from its document instead of having its own m_frame which can potentially
     9        be out-of-sync.
     10
     11        * dom/Document.cpp:
     12        (WebCore::Document::frameDestroyed):
     13        (WebCore::Document::willDetachPage):
     14        (WebCore::Document::attachToCachedFrame):
     15        * dom/Document.h:
     16        * page/DOMWindow.cpp:
     17        (WebCore::DOMWindow::allowPopUp):
     18        (WebCore::ContextDestructionObserver):
     19        (WebCore::DOMWindow::didSecureTransitionTo):
     20        (WebCore::DOMWindow::frameDestroyed):
     21        (WebCore::DOMWindow::willDetachDocumentFromFrame):
     22        (WebCore::DOMWindow::reconnectDOMWindowProperties):
     23        (WebCore::DOMWindow::isCurrentlyDisplayedInFrame const):
     24        (WebCore::DOMWindow::collectMatchingElementsInFlatTree):
     25        (WebCore::DOMWindow::matchingElementInFlatTree):
     26        (WebCore::DOMWindow::orientation const):
     27        (WebCore::DOMWindow::console const):
     28        (WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
     29        (WebCore::DOMWindow::webkitNamespace):
     30        (WebCore::DOMWindow::postMessage):
     31        (WebCore::DOMWindow::postMessageTimerFired):
     32        (WebCore::DOMWindow::frameElement const):
     33        (WebCore::DOMWindow::focus):
     34        (WebCore::DOMWindow::blur):
     35        (WebCore::DOMWindow::close):
     36        (WebCore::DOMWindow::print):
     37        (WebCore::DOMWindow::stop):
     38        (WebCore::DOMWindow::alert):
     39        (WebCore::DOMWindow::confirm):
     40        (WebCore::DOMWindow::prompt):
     41        (WebCore::DOMWindow::find const):
     42        (WebCore::DOMWindow::outerHeight const):
     43        (WebCore::DOMWindow::outerWidth const):
     44        (WebCore::DOMWindow::innerHeight const):
     45        (WebCore::DOMWindow::innerWidth const):
     46        (WebCore::DOMWindow::screenX const):
     47        (WebCore::DOMWindow::screenY const):
     48        (WebCore::DOMWindow::scrollX const):
     49        (WebCore::DOMWindow::scrollY const):
     50        (WebCore::DOMWindow::closed const):
     51        (WebCore::DOMWindow::length const):
     52        (WebCore::DOMWindow::name const):
     53        (WebCore::DOMWindow::setName):
     54        (WebCore::DOMWindow::setStatus):
     55        (WebCore::DOMWindow::setDefaultStatus):
     56        (WebCore::DOMWindow::self const):
     57        (WebCore::DOMWindow::opener const):
     58        (WebCore::DOMWindow::disownOpener):
     59        (WebCore::DOMWindow::parent const):
     60        (WebCore::DOMWindow::top const):
     61        (WebCore::DOMWindow::getMatchedCSSRules const):
     62        (WebCore::DOMWindow::devicePixelRatio const):
     63        (WebCore::DOMWindow::scrollBy const):
     64        (WebCore::DOMWindow::scrollTo const):
     65        (WebCore::DOMWindow::allowedToChangeWindowGeometry const):
     66        (WebCore::DOMWindow::moveBy const):
     67        (WebCore::DOMWindow::moveTo const):
     68        (WebCore::DOMWindow::resizeBy const):
     69        (WebCore::DOMWindow::resizeTo const):
     70        (WebCore::DOMWindow::clearTimeout):
     71        (WebCore::DOMWindow::isSameSecurityOriginAsMainFrame const):
     72        (WebCore::DOMWindow::finishedLoading):
     73        (WebCore::DOMWindow::setLocation):
     74        (WebCore::DOMWindow::open):
     75        (WebCore::DOMWindow::showModalDialog):
     76        (WebCore::DOMWindow::frame const):
     77        (WebCore::FrameDestructionObserver): Deleted.
     78        (WebCore::DOMWindow::willDetachPage): Deleted.
     79        (WebCore::DOMWindow::detachFromFrame): Deleted.
     80        (WebCore::DOMWindow::attachToFrame): Deleted.
     81        * page/DOMWindow.h:
     82
    1832018-10-09  Jer Noble  <jer.noble@apple.com>
    284
  • trunk/Source/WebCore/dom/Document.cpp

    r236954 r236965  
    23332333    // detachFromFrame() must be called before destroying the Frame.
    23342334    RELEASE_ASSERT(!m_frame);
     2335
     2336    if (auto* window = domWindow())
     2337        window->frameDestroyed();
     2338
    23352339    FrameDestructionObserver::frameDestroyed();
     2340}
     2341
     2342void Document::willDetachPage()
     2343{
     2344    FrameDestructionObserver::willDetachPage();
     2345
     2346    if (domWindow() && frame())
     2347        InspectorInstrumentation::frameWindowDiscarded(*frame(), domWindow());
    23362348}
    23372349
     
    23422354    ASSERT(m_pageCacheState == Document::InPageCache);
    23432355    observeFrame(&cachedFrame.view()->frame());
    2344     if (auto* window = domWindow())
    2345         window->attachToFrame(cachedFrame.view()->frame());
    23462356}
    23472357
  • trunk/Source/WebCore/dom/Document.h

    r236954 r236965  
    15261526
    15271527    void updateTitleElement(Element& changingTitleElement);
     1528    void willDetachPage() final;
    15281529    void frameDestroyed() final;
    15291530
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r236917 r236965  
    376376bool DOMWindow::allowPopUp()
    377377{
    378     return m_frame && allowPopUp(*m_frame);
     378    auto* frame = this->frame();
     379    return frame && allowPopUp(*frame);
    379380}
    380381
     
    406407    : AbstractDOMWindow(GlobalWindowIdentifier { Process::identifier(), generateObjectIdentifier<WindowIdentifierType>() })
    407408    , ContextDestructionObserver(&document)
    408     , FrameDestructionObserver(document.frame())
    409409{
    410410    ASSERT(frame());
     
    415415{
    416416    observeContext(&document);
    417     observeFrame(document.frame());
    418417}
    419418
     
    477476
    478477    willDestroyDocumentInFrame();
    479     FrameDestructionObserver::frameDestroyed();
    480478    resetDOMWindowProperties();
    481479    JSDOMWindowBase::fireFrameClearedWatchpointsForWindow(this);
    482 }
    483 
    484 void DOMWindow::willDetachPage()
    485 {
    486     if (m_frame)
    487         InspectorInstrumentation::frameWindowDiscarded(*m_frame, this);
    488480}
    489481
     
    516508    if (m_performance)
    517509        m_performance->clearResourceTimings();
    518 
    519     detachFromFrame();
    520510}
    521511
     
    582572    // unregister themselves from the DOMWindow as a result of the call to reconnectFromPageCache.
    583573    for (auto& property : copyToVector(m_properties))
    584         property->reconnectFrameFromDocumentSuspension(m_frame);
     574        property->reconnectFrameFromDocumentSuspension(frame());
    585575}
    586576
     
    611601bool DOMWindow::isCurrentlyDisplayedInFrame() const
    612602{
    613     return m_frame && m_frame->document()->domWindow() == this;
     603    auto* frame = this->frame();
     604    return frame && frame->document()->domWindow() == this;
    614605}
    615606
     
    635626ExceptionOr<Ref<NodeList>> DOMWindow::collectMatchingElementsInFlatTree(Node& scope, const String& selectors)
    636627{
    637     auto queryOrException = selectorQueryInFrame(m_frame, selectors);
     628    auto queryOrException = selectorQueryInFrame(frame(), selectors);
    638629    if (queryOrException.hasException())
    639630        return queryOrException.releaseException();
     
    655646ExceptionOr<RefPtr<Element>> DOMWindow::matchingElementInFlatTree(Node& scope, const String& selectors)
    656647{
    657     auto queryOrException = selectorQueryInFrame(m_frame, selectors);
     648    auto queryOrException = selectorQueryInFrame(frame(), selectors);
    658649    if (queryOrException.hasException())
    659650        return queryOrException.releaseException();
     
    676667int DOMWindow::orientation() const
    677668{
    678     if (!m_frame)
     669    auto* frame = this->frame();
     670    if (!frame)
    679671        return 0;
    680672
    681     return m_frame->orientation();
     673    return frame->orientation();
    682674}
    683675
     
    770762    if (!isCurrentlyDisplayedInFrame())
    771763        return nullptr;
    772     return m_frame->page() ? &m_frame->page()->console() : nullptr;
     764    auto* frame = this->frame();
     765    return frame->page() ? &frame->page()->console() : nullptr;
    773766}
    774767
     
    833826bool DOMWindow::shouldHaveWebKitNamespaceForWorld(DOMWrapperWorld& world)
    834827{
    835     if (!m_frame)
     828    auto* frame = this->frame();
     829    if (!frame)
    836830        return false;
    837831
    838     auto* page = m_frame->page();
     832    auto* page = frame->page();
    839833    if (!page)
    840834        return false;
     
    855849    if (!isCurrentlyDisplayedInFrame())
    856850        return nullptr;
    857     auto* page = m_frame->page();
     851    auto* page = frame()->page();
    858852    if (!page)
    859853        return nullptr;
     
    972966    timer->startOneShot(0_s);
    973967
    974     InspectorInstrumentation::didPostMessage(*m_frame, *timer, state);
     968    InspectorInstrumentation::didPostMessage(*frame(), *timer, state);
    975969
    976970    return { };
     
    982976        return;
    983977
     978    auto* frame = this->frame();
    984979    if (auto* intendedTargetOrigin = timer.targetOrigin()) {
    985980        // Check target origin now since the target document may have changed since the timer was scheduled.
     
    993988            }
    994989
    995             InspectorInstrumentation::didFailPostMessage(*m_frame, timer);
     990            InspectorInstrumentation::didFailPostMessage(*frame, timer);
    996991            return;
    997992        }
    998993    }
    999994
    1000     InspectorInstrumentation::willDispatchPostMessage(*m_frame, timer);
     995    InspectorInstrumentation::willDispatchPostMessage(*frame, timer);
    1001996
    1002997    dispatchEvent(timer.event(*document()));
    1003998
    1004     InspectorInstrumentation::didDispatchPostMessage(*m_frame, timer);
     999    InspectorInstrumentation::didDispatchPostMessage(*frame, timer);
    10051000}
    10061001
     
    10161011Element* DOMWindow::frameElement() const
    10171012{
    1018     if (!m_frame)
    1019         return nullptr;
    1020 
    1021     return m_frame->ownerElement();
     1013    auto* frame = this->frame();
     1014    if (!frame)
     1015        return nullptr;
     1016
     1017    return frame->ownerElement();
    10221018}
    10231019
     
    10301026void DOMWindow::focus(bool allowFocus)
    10311027{
    1032     if (!m_frame)
    1033         return;
    1034 
    1035     Page* page = m_frame->page();
     1028    if (!frame())
     1029        return;
     1030
     1031    Page* page = frame()->page();
    10361032    if (!page)
    10371033        return;
    10381034
    1039     allowFocus = allowFocus || WindowFocusAllowedIndicator::windowFocusAllowed() || !m_frame->settings().windowFocusRestricted();
     1035    allowFocus = allowFocus || WindowFocusAllowedIndicator::windowFocusAllowed() || !frame()->settings().windowFocusRestricted();
    10401036
    10411037    // If we're a top level window, bring the window to the front.
    1042     if (m_frame->isMainFrame() && allowFocus)
     1038    if (frame()->isMainFrame() && allowFocus)
    10431039        page->chrome().focus();
    10441040
    1045     if (!m_frame)
     1041    if (!frame())
    10461042        return;
    10471043
    10481044    // Clear the current frame's focused node if a new frame is about to be focused.
    10491045    Frame* focusedFrame = page->focusController().focusedFrame();
    1050     if (focusedFrame && focusedFrame != m_frame)
     1046    if (focusedFrame && focusedFrame != frame())
    10511047        focusedFrame->document()->setFocusedElement(nullptr);
    10521048
    1053     // setFocusedElement may clear m_frame, so recheck before using it.
    1054     if (m_frame)
    1055         m_frame->eventHandler().focusDocumentView();
     1049    // setFocusedElement may clear frame(), so recheck before using it.
     1050    if (auto* frame = this->frame())
     1051        frame->eventHandler().focusDocumentView();
    10561052}
    10571053
    10581054void DOMWindow::blur()
    10591055{
    1060     if (!m_frame)
    1061         return;
    1062 
    1063     Page* page = m_frame->page();
     1056    auto* frame = this->frame();
     1057    if (!frame)
     1058        return;
     1059
     1060    Page* page = frame->page();
    10641061    if (!page)
    10651062        return;
    10661063
    1067     if (m_frame->settings().windowFocusRestricted())
    1068         return;
    1069 
    1070     if (!m_frame->isMainFrame())
     1064    if (frame->settings().windowFocusRestricted())
     1065        return;
     1066
     1067    if (!frame->isMainFrame())
    10711068        return;
    10721069
     
    10761073void DOMWindow::close(Document& document)
    10771074{
    1078     if (!document.canNavigate(m_frame))
     1075    if (!document.canNavigate(frame()))
    10791076        return;
    10801077    close();
     
    10831080void DOMWindow::close()
    10841081{
    1085     if (!m_frame)
    1086         return;
    1087 
    1088     Page* page = m_frame->page();
     1082    auto* frame = this->frame();
     1083    if (!frame)
     1084        return;
     1085
     1086    Page* page = frame->page();
    10891087    if (!page)
    10901088        return;
    10911089
    1092     if (!m_frame->isMainFrame())
     1090    if (!frame->isMainFrame())
    10931091        return;
    10941092
     
    10981096    }
    10991097
    1100     if (!m_frame->loader().shouldClose())
     1098    if (!frame->loader().shouldClose())
    11011099        return;
    11021100
     
    11071105void DOMWindow::print()
    11081106{
    1109     if (!m_frame)
    1110         return;
    1111 
    1112     auto* page = m_frame->page();
     1107    auto* frame = this->frame();
     1108    if (!frame)
     1109        return;
     1110
     1111    auto* page = frame->page();
    11131112    if (!page)
    11141113        return;
     
    11191118    }
    11201119
    1121     if (m_frame->loader().activeDocumentLoader()->isLoading()) {
     1120    if (frame->loader().activeDocumentLoader()->isLoading()) {
    11221121        m_shouldPrintWhenFinishedLoading = true;
    11231122        return;
    11241123    }
    11251124    m_shouldPrintWhenFinishedLoading = false;
    1126     page->chrome().print(*m_frame);
     1125    page->chrome().print(*frame);
    11271126}
    11281127
    11291128void DOMWindow::stop()
    11301129{
    1131     if (!m_frame)
     1130    auto* frame = this->frame();
     1131    if (!frame)
    11321132        return;
    11331133
    11341134    // We must check whether the load is complete asynchronously, because we might still be parsing
    11351135    // the document until the callstack unwinds.
    1136     m_frame->loader().stopForUserCancel(true);
     1136    frame->loader().stopForUserCancel(true);
    11371137}
    11381138
    11391139void DOMWindow::alert(const String& message)
    11401140{
    1141     if (!m_frame)
     1141    auto* frame = this->frame();
     1142    if (!frame)
    11421143        return;
    11431144
     
    11471148    }
    11481149
    1149     auto* page = m_frame->page();
     1150    auto* page = frame->page();
    11501151    if (!page)
    11511152        return;
     
    11561157    }
    11571158
    1158     m_frame->document()->updateStyleIfNeeded();
     1159    frame->document()->updateStyleIfNeeded();
    11591160#if ENABLE(POINTER_LOCK)
    11601161    page->pointerLockController().requestPointerUnlock();
    11611162#endif
    11621163
    1163     page->chrome().runJavaScriptAlert(*m_frame, message);
     1164    page->chrome().runJavaScriptAlert(*frame, message);
    11641165}
    11651166
    11661167bool DOMWindow::confirm(const String& message)
    11671168{
    1168     if (!m_frame)
     1169    auto* frame = this->frame();
     1170    if (!frame)
    11691171        return false;
    11701172   
     
    11741176    }
    11751177
    1176     auto* page = m_frame->page();
     1178    auto* page = frame->page();
    11771179    if (!page)
    11781180        return false;
     
    11831185    }
    11841186
    1185     m_frame->document()->updateStyleIfNeeded();
     1187    frame->document()->updateStyleIfNeeded();
    11861188#if ENABLE(POINTER_LOCK)
    11871189    page->pointerLockController().requestPointerUnlock();
    11881190#endif
    11891191
    1190     return page->chrome().runJavaScriptConfirm(*m_frame, message);
     1192    return page->chrome().runJavaScriptConfirm(*frame, message);
    11911193}
    11921194
    11931195String DOMWindow::prompt(const String& message, const String& defaultValue)
    11941196{
    1195     if (!m_frame)
     1197    auto* frame = this->frame();
     1198    if (!frame)
    11961199        return String();
    11971200
     
    12011204    }
    12021205
    1203     auto* page = m_frame->page();
     1206    auto* page = frame->page();
    12041207    if (!page)
    12051208        return String();
     
    12101213    }
    12111214
    1212     m_frame->document()->updateStyleIfNeeded();
     1215    frame->document()->updateStyleIfNeeded();
    12131216#if ENABLE(POINTER_LOCK)
    12141217    page->pointerLockController().requestPointerUnlock();
     
    12161219
    12171220    String returnValue;
    1218     if (page->chrome().runJavaScriptPrompt(*m_frame, message, defaultValue, returnValue))
     1221    if (page->chrome().runJavaScriptPrompt(*frame, message, defaultValue, returnValue))
    12191222        return returnValue;
    12201223
     
    12351238    if (wrap)
    12361239        options.add(WrapAround);
    1237     return m_frame->editor().findString(string, options);
     1240    return frame()->editor().findString(string, options);
    12381241}
    12391242
     
    12481251    return 0;
    12491252#else
    1250     if (!m_frame)
     1253    auto* frame = this->frame();
     1254    if (!frame)
    12511255        return 0;
    12521256
    1253     Page* page = m_frame->page();
     1257    Page* page = frame->page();
    12541258    if (!page)
    12551259        return 0;
     
    12641268    return 0;
    12651269#else
    1266     if (!m_frame)
     1270    auto* frame = this->frame();
     1271    if (!frame)
    12671272        return 0;
    12681273
    1269     Page* page = m_frame->page();
     1274    Page* page = frame->page();
    12701275    if (!page)
    12711276        return 0;
     
    12771282int DOMWindow::innerHeight() const
    12781283{
    1279     if (!m_frame)
     1284    auto* frame = this->frame();
     1285    if (!frame)
    12801286        return 0;
    12811287
     
    12841290        frameElement->document().updateLayoutIfDimensionsOutOfDate(*frameElement, HeightDimensionsCheck);
    12851291
    1286     FrameView* view = m_frame->view();
     1292    FrameView* view = frame->view();
    12871293    if (!view)
    12881294        return 0;
     
    12931299int DOMWindow::innerWidth() const
    12941300{
    1295     if (!m_frame)
     1301    auto* frame = this->frame();
     1302    if (!frame)
    12961303        return 0;
    12971304
     
    13001307        frameElement->document().updateLayoutIfDimensionsOutOfDate(*frameElement, WidthDimensionsCheck);
    13011308
    1302     FrameView* view = m_frame->view();
     1309    FrameView* view = frame->view();
    13031310    if (!view)
    13041311        return 0;
     
    13091316int DOMWindow::screenX() const
    13101317{
    1311     if (!m_frame)
     1318    auto* frame = this->frame();
     1319    if (!frame)
    13121320        return 0;
    13131321
    1314     Page* page = m_frame->page();
     1322    Page* page = frame->page();
    13151323    if (!page)
    13161324        return 0;
     
    13211329int DOMWindow::screenY() const
    13221330{
    1323     if (!m_frame)
     1331    auto* frame = this->frame();
     1332    if (!frame)
    13241333        return 0;
    13251334
    1326     Page* page = m_frame->page();
     1335    Page* page = frame->page();
    13271336    if (!page)
    13281337        return 0;
     
    13331342int DOMWindow::scrollX() const
    13341343{
    1335     if (!m_frame)
     1344    auto* frame = this->frame();
     1345    if (!frame)
    13361346        return 0;
    13371347
    1338     FrameView* view = m_frame->view();
     1348    FrameView* view = frame->view();
    13391349    if (!view)
    13401350        return 0;
     
    13441354        return 0;
    13451355
    1346     m_frame->document()->updateLayoutIgnorePendingStylesheets();
     1356    frame->document()->updateLayoutIgnorePendingStylesheets();
    13471357
    13481358    return view->mapFromLayoutToCSSUnits(view->contentsScrollPosition().x());
     
    13511361int DOMWindow::scrollY() const
    13521362{
    1353     if (!m_frame)
     1363    auto* frame = this->frame();
     1364    if (!frame)
    13541365        return 0;
    13551366
    1356     FrameView* view = m_frame->view();
     1367    FrameView* view = frame->view();
    13571368    if (!view)
    13581369        return 0;
     
    13621373        return 0;
    13631374
    1364     m_frame->document()->updateLayoutIgnorePendingStylesheets();
     1375    frame->document()->updateLayoutIgnorePendingStylesheets();
    13651376
    13661377    return view->mapFromLayoutToCSSUnits(view->contentsScrollPosition().y());
     
    13691380bool DOMWindow::closed() const
    13701381{
    1371     return !m_frame;
     1382    return !frame();
    13721383}
    13731384
     
    13771388        return 0;
    13781389
    1379     return m_frame->tree().scopedChildCount();
     1390    return frame()->tree().scopedChildCount();
    13801391}
    13811392
    13821393String DOMWindow::name() const
    13831394{
    1384     if (!m_frame)
     1395    auto* frame = this->frame();
     1396    if (!frame)
    13851397        return String();
    13861398
    1387     return m_frame->tree().name();
     1399    return frame->tree().name();
    13881400}
    13891401
    13901402void DOMWindow::setName(const String& string)
    13911403{
    1392     if (!m_frame)
    1393         return;
    1394 
    1395     m_frame->tree().setName(string);
     1404    auto* frame = this->frame();
     1405    if (!frame)
     1406        return;
     1407
     1408    frame->tree().setName(string);
    13961409}
    13971410
     
    14001413    m_status = string;
    14011414
    1402     if (!m_frame)
    1403         return;
    1404 
    1405     Page* page = m_frame->page();
     1415    auto* frame = this->frame();
     1416    if (!frame)
     1417        return;
     1418
     1419    Page* page = frame->page();
    14061420    if (!page)
    14071421        return;
    14081422
    1409     ASSERT(m_frame->document()); // Client calls shouldn't be made when the frame is in inconsistent state.
    1410     page->chrome().setStatusbarText(*m_frame, m_status);
    1411 }
    1412 
    1413 void DOMWindow::detachFromFrame()
    1414 {
    1415     observeFrame(nullptr);
    1416 }
    1417 
    1418 void DOMWindow::attachToFrame(Frame& frame)
    1419 {
    1420     observeFrame(&frame);
    1421 }
    1422    
     1423    ASSERT(frame->document()); // Client calls shouldn't be made when the frame is in inconsistent state.
     1424    page->chrome().setStatusbarText(*frame, m_status);
     1425}
     1426
    14231427void DOMWindow::setDefaultStatus(const String& string)
    14241428{
    14251429    m_defaultStatus = string;
    14261430
    1427     if (!m_frame)
    1428         return;
    1429 
    1430     Page* page = m_frame->page();
     1431    auto* frame = this->frame();
     1432    if (!frame)
     1433        return;
     1434
     1435    Page* page = frame->page();
    14311436    if (!page)
    14321437        return;
    14331438
    1434     ASSERT(m_frame->document()); // Client calls shouldn't be made when the frame is in inconsistent state.
    1435     page->chrome().setStatusbarText(*m_frame, m_defaultStatus);
     1439    ASSERT(frame->document()); // Client calls shouldn't be made when the frame is in inconsistent state.
     1440    page->chrome().setStatusbarText(*frame, m_defaultStatus);
    14361441}
    14371442
    14381443WindowProxy* DOMWindow::self() const
    14391444{
    1440     if (!m_frame)
    1441         return nullptr;
    1442 
    1443     return &m_frame->windowProxy();
     1445    auto* frame = this->frame();
     1446    if (!frame)
     1447        return nullptr;
     1448
     1449    return &frame->windowProxy();
    14441450}
    14451451
    14461452WindowProxy* DOMWindow::opener() const
    14471453{
    1448     if (!m_frame)
    1449         return nullptr;
    1450 
    1451     auto* openerFrame = m_frame->loader().opener();
     1454    auto* frame = this->frame();
     1455    if (!frame)
     1456        return nullptr;
     1457
     1458    auto* openerFrame = frame->loader().opener();
    14521459    if (!openerFrame)
    14531460        return nullptr;
     
    14581465void DOMWindow::disownOpener()
    14591466{
    1460     if (m_frame)
    1461         m_frame->loader().setOpener(nullptr);
     1467    if (auto* frame = this->frame())
     1468        frame->loader().setOpener(nullptr);
    14621469}
    14631470
    14641471WindowProxy* DOMWindow::parent() const
    14651472{
    1466     if (!m_frame)
    1467         return nullptr;
    1468 
    1469     auto* parentFrame = m_frame->tree().parent();
     1473    auto* frame = this->frame();
     1474    if (!frame)
     1475        return nullptr;
     1476
     1477    auto* parentFrame = frame->tree().parent();
    14701478    if (parentFrame)
    14711479        return &parentFrame->windowProxy();
    14721480
    1473     return &m_frame->windowProxy();
     1481    return &frame->windowProxy();
    14741482}
    14751483
    14761484WindowProxy* DOMWindow::top() const
    14771485{
    1478     if (!m_frame)
    1479         return nullptr;
    1480 
    1481     if (!m_frame->page())
    1482         return nullptr;
    1483 
    1484     return &m_frame->tree().top().windowProxy();
     1486    auto* frame = this->frame();
     1487    if (!frame)
     1488        return nullptr;
     1489
     1490    if (!frame->page())
     1491        return nullptr;
     1492
     1493    return &frame->tree().top().windowProxy();
    14851494}
    14861495
     
    15201529        return nullptr;
    15211530
    1522     m_frame->document()->styleScope().flushPendingUpdate();
     1531    auto* frame = this->frame();
     1532    frame->document()->styleScope().flushPendingUpdate();
    15231533
    15241534    unsigned rulesToInclude = StyleResolver::AuthorCSSRules;
     
    15281538    PseudoId pseudoId = CSSSelector::pseudoId(pseudoType);
    15291539
    1530     auto matchedRules = m_frame->document()->styleScope().resolver().pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
     1540    auto matchedRules = frame->document()->styleScope().resolver().pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
    15311541    if (matchedRules.isEmpty())
    15321542        return nullptr;
    15331543
    1534     bool allowCrossOrigin = m_frame->settings().crossOriginCheckInGetMatchedCSSRulesDisabled();
     1544    bool allowCrossOrigin = frame->settings().crossOriginCheckInGetMatchedCSSRulesDisabled();
    15351545
    15361546    RefPtr<StaticCSSRuleList> ruleList = StaticCSSRuleList::create();
     
    15791589double DOMWindow::devicePixelRatio() const
    15801590{
    1581     if (!m_frame)
     1591    auto* frame = this->frame();
     1592    if (!frame)
    15821593        return 0.0;
    15831594
    1584     Page* page = m_frame->page();
     1595    Page* page = frame->page();
    15851596    if (!page)
    15861597        return 0.0;
     
    16011612    document()->updateLayoutIgnorePendingStylesheets();
    16021613
    1603     FrameView* view = m_frame->view();
     1614    FrameView* view = frame()->view();
    16041615    if (!view)
    16051616        return;
     
    16211632        return;
    16221633
    1623     RefPtr<FrameView> view = m_frame->view();
     1634    RefPtr<FrameView> view = frame()->view();
    16241635    if (!view)
    16251636        return;
     
    16401651bool DOMWindow::allowedToChangeWindowGeometry() const
    16411652{
    1642     if (!m_frame)
     1653    auto* frame = this->frame();
     1654    if (!frame)
    16431655        return false;
    1644     if (!m_frame->page())
     1656    if (!frame->page())
    16451657        return false;
    1646     if (!m_frame->isMainFrame())
     1658    if (!frame->isMainFrame())
    16471659        return false;
    16481660    // Prevent web content from tricking the user into initiating a drag.
    1649     if (m_frame->eventHandler().mousePressed())
     1661    if (frame->eventHandler().mousePressed())
    16501662        return false;
    16511663    return true;
     
    16571669        return;
    16581670
    1659     Page* page = m_frame->page();
     1671    auto* page = frame()->page();
    16601672    FloatRect fr = page->chrome().windowRect();
    16611673    FloatRect update = fr;
     
    16691681        return;
    16701682
    1671     Page* page = m_frame->page();
     1683    auto* page = frame()->page();
    16721684    FloatRect fr = page->chrome().windowRect();
    16731685    FloatRect sr = screenAvailableRect(page->mainFrame().view());
     
    16831695        return;
    16841696
    1685     Page* page = m_frame->page();
     1697    auto* page = frame()->page();
    16861698    FloatRect fr = page->chrome().windowRect();
    16871699    FloatSize dest = fr.size() + FloatSize(x, y);
     
    16951707        return;
    16961708
    1697     Page* page = m_frame->page();
     1709    auto* page = frame()->page();
    16981710    FloatRect fr = page->chrome().windowRect();
    16991711    FloatSize dest = FloatSize(width, height);
     
    17221734{
    17231735#if PLATFORM(IOS)
    1724     if (m_frame) {
    1725         Document* document = m_frame->document();
     1736    if (auto* frame = this->frame()) {
     1737        Document* document = frame->document();
    17261738        if (timeoutId > 0 && document) {
    17271739            DOMTimer* timer = document->findTimeout(timeoutId);
     
    17301742
    17311743                if (!WebThreadCountOfObservedContentModifiers()) {
    1732                     if (Page* page = m_frame->page())
    1733                         page->chrome().client().observedContentChange(*m_frame);
     1744                    if (Page* page = frame->page())
     1745                        page->chrome().client().observedContentChange(*frame);
    17341746                }
    17351747            }
     
    18341846bool DOMWindow::isSameSecurityOriginAsMainFrame() const
    18351847{
    1836     if (!m_frame || !m_frame->page() || !document())
     1848    auto* frame = this->frame();
     1849    if (!frame || !frame->page() || !document())
    18371850        return false;
    18381851
    1839     if (m_frame->isMainFrame())
     1852    if (frame->isMainFrame())
    18401853        return true;
    18411854
    1842     Document* mainFrameDocument = m_frame->mainFrame().document();
     1855    Document* mainFrameDocument = frame->mainFrame().document();
    18431856
    18441857    if (mainFrameDocument && document()->securityOrigin().canAccess(mainFrameDocument->securityOrigin()))
     
    21332146    if (m_shouldPrintWhenFinishedLoading) {
    21342147        m_shouldPrintWhenFinishedLoading = false;
    2135         if (m_frame->loader().activeDocumentLoader()->mainDocumentError().isNull())
     2148        if (frame()->loader().activeDocumentLoader()->mainDocumentError().isNull())
    21362149            print();
    21372150    }
     
    21472160        return;
    21482161
    2149     if (!activeDocument->canNavigate(m_frame))
     2162    auto* frame = this->frame();
     2163    if (!activeDocument->canNavigate(frame))
    21502164        return;
    21512165
     
    21642178    LockHistory lockHistory = (locking != LockHistoryBasedOnGestureState || !UserGestureIndicator::processingUserGesture()) ? LockHistory::Yes : LockHistory::No;
    21652179    LockBackForwardList lockBackForwardList = (locking != LockHistoryBasedOnGestureState) ? LockBackForwardList::Yes : LockBackForwardList::No;
    2166     m_frame->navigationScheduler().scheduleLocationChange(*activeDocument, activeDocument->securityOrigin(),
     2180    frame->navigationScheduler().scheduleLocationChange(*activeDocument, activeDocument->securityOrigin(),
    21672181        // FIXME: What if activeDocument()->frame() is 0?
    21682182        completedURL, activeDocument->frame()->loader().outgoingReferrer(),
     
    23382352#endif
    23392353
     2354    auto* frame = this->frame();
    23402355    if (!firstWindow.allowPopUp()) {
    23412356        // Because FrameTree::findFrameForNavigation() returns true for empty strings, we must check for empty frame names.
    23422357        // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker.
    2343         if (frameName.isEmpty() || !m_frame->loader().findFrameForNavigation(frameName, activeDocument))
     2358        if (frameName.isEmpty() || !frame->loader().findFrameForNavigation(frameName, activeDocument))
    23442359            return RefPtr<WindowProxy> { nullptr };
    23452360    }
     
    23492364    Frame* targetFrame = nullptr;
    23502365    if (equalIgnoringASCIICase(frameName, "_top"))
    2351         targetFrame = &m_frame->tree().top();
     2366        targetFrame = &frame->tree().top();
    23522367    else if (equalIgnoringASCIICase(frameName, "_parent")) {
    2353         if (Frame* parent = m_frame->tree().parent())
     2368        if (Frame* parent = frame->tree().parent())
    23542369            targetFrame = parent;
    23552370        else
    2356             targetFrame = m_frame;
     2371            targetFrame = frame;
    23572372    }
    23582373    if (targetFrame) {
     
    23762391    }
    23772392
    2378     auto newFrameOrException = createWindow(urlString, frameName, parseWindowFeatures(windowFeaturesString), activeWindow, *firstFrame, *m_frame);
     2393    auto newFrameOrException = createWindow(urlString, frameName, parseWindowFeatures(windowFeaturesString), activeWindow, *firstFrame, *frame);
    23792394    if (newFrameOrException.hasException())
    23802395        return newFrameOrException.releaseException();
     
    23942409        return;
    23952410
    2396     auto* page = m_frame->page();
     2411    auto* frame = this->frame();
     2412    auto* page = frame->page();
    23972413    if (!page)
    23982414        return;
     
    24032419    }
    24042420
    2405     if (!canShowModalDialog(*m_frame) || !firstWindow.allowPopUp())
    2406         return;
    2407 
    2408     auto dialogFrameOrException = createWindow(urlString, emptyAtom(), parseDialogFeatures(dialogFeaturesString, screenAvailableRect(m_frame->view())), activeWindow, *firstFrame, *m_frame, prepareDialogFunction);
     2421    if (!canShowModalDialog(*frame) || !firstWindow.allowPopUp())
     2422        return;
     2423
     2424    auto dialogFrameOrException = createWindow(urlString, emptyAtom(), parseDialogFeatures(dialogFeaturesString, screenAvailableRect(frame->view())), activeWindow, *firstFrame, *frame, prepareDialogFunction);
    24092425    if (dialogFrameOrException.hasException())
    24102426        return;
     
    24272443}
    24282444
     2445Frame* DOMWindow::frame() const
     2446{
     2447    auto* document = this->document();
     2448    return document ? document->frame() : nullptr;
     2449}
     2450
    24292451} // namespace WebCore
  • trunk/Source/WebCore/page/DOMWindow.h

    r236917 r236965  
    8989enum class IncludeTargetOrigin { No, Yes };
    9090
    91 // FIXME: DOMWindow shouldn't subclass FrameDestructionObserver and instead should get to Frame via its Document.
    9291// FIXME: Rename DOMWindow to LocalWindow and AbstractDOMWindow to DOMWindow.
    9392class DOMWindow final
     
    9594    , public CanMakeWeakPtr<DOMWindow>
    9695    , public ContextDestructionObserver
    97     , public FrameDestructionObserver
    9896    , public Base64Utilities
    9997    , public Supplementable<DOMWindow> {
     
    117115    void suspendForDocumentSuspension();
    118116    void resumeFromDocumentSuspension();
     117
     118    WEBCORE_EXPORT Frame* frame() const final;
    119119
    120120    RefPtr<MediaQueryList> matchMedia(const String&);
     
    202202    WindowProxy* top() const;
    203203
    204     Frame* frame() const final { return FrameDestructionObserver::frame(); }
    205 
    206204    String origin() const;
    207205
     
    334332    void willDestroyCachedFrame();
    335333
    336     void attachToFrame(Frame&);
    337     void detachFromFrame();
    338 
    339334    void enableSuddenTermination();
    340335    void disableSuddenTermination();
    341336
     337    void frameDestroyed();
     338
    342339private:
    343340    explicit DOMWindow(Document&);
     
    350347    Page* page();
    351348    bool allowedToChangeWindowGeometry() const;
    352 
    353     void frameDestroyed() final;
    354     void willDetachPage() final;
    355349
    356350    static ExceptionOr<RefPtr<Frame>> createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures&, DOMWindow& activeWindow, Frame& firstFrame, Frame& openerFrame, const WTF::Function<void(DOMWindow&)>& prepareDialogFunction = nullptr);
Note: See TracChangeset for help on using the changeset viewer.