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

Changeset 242676 in webkit


Ignore:
Timestamp:
Mar 9, 2019, 6:25:42 PM (7 years ago)
Author:
Chris Dumez
Message:

Simplify DOMWindowProperty code / handling
https://bugs.webkit.org/show_bug.cgi?id=195495

Reviewed by Ryosuke Niwa.

DOMWindowProperty code was unnecessarily complex because DOMWindowExtension inherited
from it and DOMWindowExtension needs a lot of information about the global object's
lifetime to communicate to the injected bbundle client. This subclassing is also
very confusing because a DOMWindowExtension is not a *property* on the Window object.

This patch updates DOMWindowExtension to stop subclassing DOMWindowProperty and
moves all the complexity from DOMWindowProperty to DOMWindowExtension.
DOMWindowProperty is now a very simple base class which merely has a WeakPtr to
the window and getters for the window and the frame.

  • Modules/indexeddb/DOMWindowIndexedDatabase.cpp:

(WebCore::DOMWindowIndexedDatabase::DOMWindowIndexedDatabase):
(WebCore::DOMWindowIndexedDatabase::indexedDB):

  • Modules/indexeddb/DOMWindowIndexedDatabase.h:

There is no reason for DOMWindowIndexedDatabase to move its IDBFactory to a
separate data member which in PageCache. Script do not run while in PageCache.
Also, frames are nulled out while in the PageCache so the indexedDB() getter
would return null anyway while in PageCache.

  • css/StyleMedia.idl:
  • loader/appcache/ApplicationCacheHost.cpp:

(WebCore::ApplicationCacheHost::setDOMApplicationCache):
Store a WeakPtr to the DOMApplicationCache for safety.

(WebCore::ApplicationCacheHost::dispatchDOMEvent):
Do not fire events on the DOMApplicationCache if it is frameless to maintain
previous behavior. Previously, the DOMApplicationCache would have been nulled
out when detached from its frame so we would not have fired events.

  • loader/appcache/ApplicationCacheHost.h:
  • loader/appcache/DOMApplicationCache.cpp:
  • loader/appcache/DOMApplicationCache.h:

Remove some unnecessary complexity. The ApplicationCacheHost is owned by the
DocumentLoader, which changes on navigation. There is therefore no reason to
null out the DOMApplicationCache on the ApplicationCacheHost when its gets
detached from its frame or enters PageCache.

  • page/BarProp.idl:
  • page/DOMSelection.idl:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::willDestroyCachedFrame):
(WebCore::DOMWindow::willDestroyDocumentInFrame):
(WebCore::DOMWindow::willDetachDocumentFromFrame):
(WebCore::DOMWindow::registerExtension):
(WebCore::DOMWindow::unregisterExtension):

(WebCore::DOMWindow::resetDOMWindowProperties): Removed.
Stop clearing some of the DOMWindow's properties when the document gets destroyed or when
the Window for the initial empty document gets reused on navigation. I think we used to
need this because DOMWindowProperty used to hold pointers to their frame. However, this
is no longer the case nowadays as DOMWindowProperty objects get their frame from their
Window.

(WebCore::DOMWindow::resetUnlessSuspendedForDocumentSuspension):
(WebCore::DOMWindow::suspendForPageCache):
(WebCore::DOMWindow::resumeFromPageCache):

  • page/DOMWindow.h:
  • page/DOMWindowExtension.cpp:

(WebCore::DOMWindowExtension::DOMWindowExtension):
(WebCore::DOMWindowExtension::~DOMWindowExtension):
(WebCore::DOMWindowExtension::frame const):
(WebCore::DOMWindowExtension::suspendForPageCache):
(WebCore::DOMWindowExtension::resumeFromPageCache):
(WebCore::DOMWindowExtension::willDestroyGlobalObjectInCachedFrame):
(WebCore::DOMWindowExtension::willDestroyGlobalObjectInFrame):
(WebCore::DOMWindowExtension::willDetachGlobalObjectFromFrame):

  • page/DOMWindowExtension.h:
  • page/DOMWindowProperty.cpp:

(WebCore::DOMWindowProperty::DOMWindowProperty):

  • page/DOMWindowProperty.h:

(WebCore::DOMWindowProperty::window const):

  • page/History.idl:
  • page/Location.idl:
  • page/Navigator.cpp:

(WebCore::Navigator::plugins):
(WebCore::Navigator::mimeTypes):

  • page/PerformanceNavigation.idl:
  • page/PerformanceTiming.idl:
  • page/Screen.idl:
  • page/VisualViewport.cpp:

(WebCore::VisualViewport::scriptExecutionContext const):

  • plugins/DOMMimeTypeArray.idl:
  • plugins/DOMPluginArray.idl:
Location:
trunk/Source
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r242675 r242676  
     12019-03-09  Chris Dumez  <cdumez@apple.com>
     2
     3        Simplify DOMWindowProperty code / handling
     4        https://bugs.webkit.org/show_bug.cgi?id=195495
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        DOMWindowProperty code was unnecessarily complex because DOMWindowExtension inherited
     9        from it and DOMWindowExtension needs a lot of information about the global object's
     10        lifetime to communicate to the injected bbundle client. This subclassing is also
     11        very confusing because a DOMWindowExtension is not a *property* on the Window object.
     12
     13        This patch updates DOMWindowExtension to stop subclassing DOMWindowProperty and
     14        moves all the complexity from DOMWindowProperty to DOMWindowExtension.
     15        DOMWindowProperty is now a very simple base class which merely has a WeakPtr to
     16        the window and getters for the window and the frame.
     17
     18        * Modules/indexeddb/DOMWindowIndexedDatabase.cpp:
     19        (WebCore::DOMWindowIndexedDatabase::DOMWindowIndexedDatabase):
     20        (WebCore::DOMWindowIndexedDatabase::indexedDB):
     21        * Modules/indexeddb/DOMWindowIndexedDatabase.h:
     22        There is no reason for DOMWindowIndexedDatabase to move its IDBFactory to a
     23        separate data member which in PageCache. Script do not run while in PageCache.
     24        Also, frames are nulled out while in the PageCache so the indexedDB() getter
     25        would return null anyway while in PageCache.
     26
     27        * css/StyleMedia.idl:
     28        * loader/appcache/ApplicationCacheHost.cpp:
     29        (WebCore::ApplicationCacheHost::setDOMApplicationCache):
     30        Store a WeakPtr to the DOMApplicationCache for safety.
     31
     32        (WebCore::ApplicationCacheHost::dispatchDOMEvent):
     33        Do not fire events on the DOMApplicationCache if it is frameless to maintain
     34        previous behavior. Previously, the DOMApplicationCache would have been nulled
     35        out when detached from its frame so we would not have fired events.
     36
     37        * loader/appcache/ApplicationCacheHost.h:
     38        * loader/appcache/DOMApplicationCache.cpp:
     39        * loader/appcache/DOMApplicationCache.h:
     40        Remove some unnecessary complexity. The ApplicationCacheHost is owned by the
     41        DocumentLoader, which changes on navigation. There is therefore no reason to
     42        null out the DOMApplicationCache on the ApplicationCacheHost when its gets
     43        detached from its frame or enters PageCache.
     44
     45        * page/BarProp.idl:
     46        * page/DOMSelection.idl:
     47        * page/DOMWindow.cpp:
     48        (WebCore::DOMWindow::willDestroyCachedFrame):
     49        (WebCore::DOMWindow::willDestroyDocumentInFrame):
     50        (WebCore::DOMWindow::willDetachDocumentFromFrame):
     51        (WebCore::DOMWindow::registerExtension):
     52        (WebCore::DOMWindow::unregisterExtension):
     53
     54        (WebCore::DOMWindow::resetDOMWindowProperties): Removed.
     55        Stop clearing some of the DOMWindow's properties when the document gets destroyed or when
     56        the Window for the initial empty document gets reused on navigation. I think we used to
     57        need this because DOMWindowProperty used to hold pointers to their frame. However, this
     58        is no longer the case nowadays as DOMWindowProperty objects get their frame from their
     59        Window.
     60
     61        (WebCore::DOMWindow::resetUnlessSuspendedForDocumentSuspension):
     62        (WebCore::DOMWindow::suspendForPageCache):
     63        (WebCore::DOMWindow::resumeFromPageCache):
     64        * page/DOMWindow.h:
     65        * page/DOMWindowExtension.cpp:
     66        (WebCore::DOMWindowExtension::DOMWindowExtension):
     67        (WebCore::DOMWindowExtension::~DOMWindowExtension):
     68        (WebCore::DOMWindowExtension::frame const):
     69        (WebCore::DOMWindowExtension::suspendForPageCache):
     70        (WebCore::DOMWindowExtension::resumeFromPageCache):
     71        (WebCore::DOMWindowExtension::willDestroyGlobalObjectInCachedFrame):
     72        (WebCore::DOMWindowExtension::willDestroyGlobalObjectInFrame):
     73        (WebCore::DOMWindowExtension::willDetachGlobalObjectFromFrame):
     74        * page/DOMWindowExtension.h:
     75        * page/DOMWindowProperty.cpp:
     76        (WebCore::DOMWindowProperty::DOMWindowProperty):
     77        * page/DOMWindowProperty.h:
     78        (WebCore::DOMWindowProperty::window const):
     79        * page/History.idl:
     80        * page/Location.idl:
     81        * page/Navigator.cpp:
     82        (WebCore::Navigator::plugins):
     83        (WebCore::Navigator::mimeTypes):
     84        * page/PerformanceNavigation.idl:
     85        * page/PerformanceTiming.idl:
     86        * page/Screen.idl:
     87        * page/VisualViewport.cpp:
     88        (WebCore::VisualViewport::scriptExecutionContext const):
     89        * plugins/DOMMimeTypeArray.idl:
     90        * plugins/DOMPluginArray.idl:
     91
    1922019-03-09  Zalan Bujtas  <zalan@apple.com>
    293
  • trunk/Source/WebCore/Modules/indexeddb/DOMWindowIndexedDatabase.cpp

    r237029 r242676  
    3939DOMWindowIndexedDatabase::DOMWindowIndexedDatabase(DOMWindow* window)
    4040    : DOMWindowProperty(window)
    41     , m_window(window)
    4241{
    4342}
     
    6160}
    6261
    63 void DOMWindowIndexedDatabase::suspendForPageCache()
    64 {
    65     m_suspendedIDBFactory = WTFMove(m_idbFactory);
    66     DOMWindowProperty::suspendForPageCache();
    67 }
    68 
    69 void DOMWindowIndexedDatabase::resumeFromPageCache()
    70 {
    71     DOMWindowProperty::resumeFromPageCache();
    72     m_idbFactory = WTFMove(m_suspendedIDBFactory);
    73 }
    74 
    75 void DOMWindowIndexedDatabase::willDestroyGlobalObjectInCachedFrame()
    76 {
    77     m_suspendedIDBFactory = nullptr;
    78     DOMWindowProperty::willDestroyGlobalObjectInCachedFrame();
    79 }
    80 
    81 void DOMWindowIndexedDatabase::willDestroyGlobalObjectInFrame()
    82 {
    83     m_idbFactory = nullptr;
    84     DOMWindowProperty::willDestroyGlobalObjectInFrame();
    85 }
    86 
    87 void DOMWindowIndexedDatabase::willDetachGlobalObjectFromFrame()
    88 {
    89     m_idbFactory = nullptr;
    90     DOMWindowProperty::willDetachGlobalObjectFromFrame();
    91 }
    92 
    9362IDBFactory* DOMWindowIndexedDatabase::indexedDB(DOMWindow& window)
    9463{
     
    9867IDBFactory* DOMWindowIndexedDatabase::indexedDB()
    9968{
    100     Document* document = m_window->document();
     69    auto* window = this->window();
     70    if (!window)
     71        return nullptr;
     72
     73    auto* document = window->document();
    10174    if (!document)
    10275        return nullptr;
    10376
    104     Page* page = document->page();
     77    auto* page = document->page();
    10578    if (!page)
    10679        return nullptr;
    10780
    108     if (!m_window->isCurrentlyDisplayedInFrame())
     81    if (!window->isCurrentlyDisplayedInFrame())
    10982        return nullptr;
    11083
  • trunk/Source/WebCore/Modules/indexeddb/DOMWindowIndexedDatabase.h

    r237029 r242676  
    4646    WEBCORE_EXPORT static IDBFactory* indexedDB(DOMWindow&);
    4747
    48     void suspendForPageCache() override;
    49     void resumeFromPageCache() override;
    50     void willDestroyGlobalObjectInCachedFrame() override;
    51     void willDestroyGlobalObjectInFrame() override;
    52     void willDetachGlobalObjectFromFrame() override;
    53 
    5448private:
    5549    IDBFactory* indexedDB();
    5650    static const char* supplementName();
    5751
    58     DOMWindow* m_window;
    5952    RefPtr<IDBFactory> m_idbFactory;
    60     RefPtr<IDBFactory> m_suspendedIDBFactory;
    6153};
    6254
  • trunk/Source/WebCore/css/StyleMedia.idl

    r199969 r242676  
    2828    NoInterfaceObject,
    2929    GenerateIsReachable=ImplFrame,
     30    ImplementationLacksVTable,
    3031] interface StyleMedia {
    3132    readonly attribute DOMString type;
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp

    r240437 r242676  
    297297{
    298298    ASSERT(!m_domApplicationCache || !domApplicationCache);
    299     m_domApplicationCache = domApplicationCache;
     299    m_domApplicationCache = makeWeakPtr(domApplicationCache);
    300300}
    301301
     
    380380void ApplicationCacheHost::dispatchDOMEvent(const AtomicString& eventType, int total, int done)
    381381{
    382     if (!m_domApplicationCache)
     382    if (!m_domApplicationCache || !m_domApplicationCache->frame())
    383383        return;
     384
    384385    m_domApplicationCache->dispatchEvent(createApplicationCacheEvent(eventType, total, done));
    385386}
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.h

    r238771 r242676  
    3535#include <wtf/URL.h>
    3636#include <wtf/Vector.h>
     37#include <wtf/WeakPtr.h>
    3738
    3839namespace WebCore {
     
    147148    bool maybeLoadFallbackForMainError(const ResourceRequest&, const ResourceError&);
    148149
    149     DOMApplicationCache* m_domApplicationCache { nullptr };
     150    WeakPtr<DOMApplicationCache> m_domApplicationCache;
    150151    DocumentLoader& m_documentLoader;
    151152
  • trunk/Source/WebCore/loader/appcache/DOMApplicationCache.cpp

    r237029 r242676  
    4040    if (auto* host = applicationCacheHost())
    4141        host->setDOMApplicationCache(this);
    42 }
    43 
    44 void DOMApplicationCache::suspendForPageCache()
    45 {
    46     if (auto* host = applicationCacheHost())
    47         host->setDOMApplicationCache(nullptr);
    48     DOMWindowProperty::suspendForPageCache();
    49 }
    50 
    51 void DOMApplicationCache::resumeFromPageCache()
    52 {
    53     DOMWindowProperty::resumeFromPageCache();
    54     if (auto* host = applicationCacheHost())
    55         host->setDOMApplicationCache(this);
    56 }
    57 
    58 void DOMApplicationCache::willDestroyGlobalObjectInFrame()
    59 {
    60     if (auto* host = applicationCacheHost())
    61         host->setDOMApplicationCache(nullptr);
    62     DOMWindowProperty::willDestroyGlobalObjectInFrame();
    6342}
    6443
  • trunk/Source/WebCore/loader/appcache/DOMApplicationCache.h

    r237029 r242676  
    2828#include "DOMWindowProperty.h"
    2929#include "EventTarget.h"
     30#include <wtf/WeakPtr.h>
    3031
    3132namespace WebCore {
     
    3435class Frame;
    3536
    36 class DOMApplicationCache final : public RefCounted<DOMApplicationCache>, public EventTargetWithInlineData, public DOMWindowProperty {
     37class DOMApplicationCache final : public RefCounted<DOMApplicationCache>, public EventTargetWithInlineData, public DOMWindowProperty, public CanMakeWeakPtr<DOMApplicationCache> {
    3738public:
    3839    static Ref<DOMApplicationCache> create(DOMWindow& window) { return adoptRef(*new DOMApplicationCache(window)); }
     
    5657    ScriptExecutionContext* scriptExecutionContext() const final;
    5758
    58     void suspendForPageCache() final;
    59     void resumeFromPageCache() final;
    60     void willDestroyGlobalObjectInFrame() final;
    61 
    6259    ApplicationCacheHost* applicationCacheHost() const;
    6360};
  • trunk/Source/WebCore/page/BarProp.idl

    r165676 r242676  
    2929[
    3030    GenerateIsReachable=ImplFrame,
     31    ImplementationLacksVTable,
    3132] interface BarProp {
    3233    readonly attribute boolean visible;
  • trunk/Source/WebCore/page/DOMSelection.idl

    r207571 r242676  
    3131[
    3232    GenerateIsReachable=ImplFrame,
     33    ImplementationLacksVTable,
    3334    InterfaceName=Selection,
    3435] interface DOMSelection {
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r242664 r242676  
    4646#include "DOMTokenList.h"
    4747#include "DOMURL.h"
    48 #include "DOMWindowExtension.h"
    4948#include "DeviceMotionController.h"
    5049#include "DeviceMotionData.h"
     
    452451void DOMWindow::willDestroyCachedFrame()
    453452{
    454     // It is necessary to copy m_properties to a separate vector because the DOMWindowProperties may
     453    // It is necessary to copy m_observers to a separate vector because the Observer may
    455454    // unregister themselves from the DOMWindow as a result of the call to willDestroyGlobalObjectInCachedFrame.
    456     for (auto* property : copyToVector(m_properties)) {
    457         if (m_properties.contains(property))
    458             property->willDestroyGlobalObjectInCachedFrame();
     455    for (auto* observer : copyToVector(m_observers)) {
     456        if (m_observers.contains(observer))
     457            observer->willDestroyGlobalObjectInCachedFrame();
    459458    }
    460459}
     
    462461void DOMWindow::willDestroyDocumentInFrame()
    463462{
    464     // It is necessary to copy m_properties to a separate vector because the DOMWindowProperties may
     463    // It is necessary to copy m_observers to a separate vector because the Observer may
    465464    // unregister themselves from the DOMWindow as a result of the call to willDestroyGlobalObjectInFrame.
    466     for (auto* property : copyToVector(m_properties)) {
    467         if (m_properties.contains(property))
    468             property->willDestroyGlobalObjectInFrame();
     465    for (auto* observer : copyToVector(m_observers)) {
     466        if (m_observers.contains(observer))
     467            observer->willDestroyGlobalObjectInFrame();
    469468    }
    470469}
     
    475474        return;
    476475
    477     // It is necessary to copy m_properties to a separate vector because the DOMWindowProperties may
     476    // It is necessary to copy m_observers to a separate vector because the Observer may
    478477    // unregister themselves from the DOMWindow as a result of the call to willDetachGlobalObjectFromFrame.
    479     for (auto& property : copyToVector(m_properties)) {
    480         if (m_properties.contains(property))
    481             property->willDetachGlobalObjectFromFrame();
     478    for (auto& observer : copyToVector(m_observers)) {
     479        if (m_observers.contains(observer))
     480            observer->willDetachGlobalObjectFromFrame();
    482481    }
    483482
     
    504503#endif
    505504
    506 void DOMWindow::registerProperty(DOMWindowProperty& property)
    507 {
    508     m_properties.add(&property);
    509 }
    510 
    511 void DOMWindow::unregisterProperty(DOMWindowProperty& property)
    512 {
    513     m_properties.remove(&property);
     505void DOMWindow::registerObserver(Observer& observer)
     506{
     507    m_observers.add(&observer);
     508}
     509
     510void DOMWindow::unregisterObserver(Observer& observer)
     511{
     512    m_observers.remove(&observer);
    514513}
    515514
     
    519518        return;
    520519    willDestroyDocumentInFrame();
    521     resetDOMWindowProperties();
    522520}
    523521
    524522void DOMWindow::suspendForPageCache()
    525523{
    526     for (auto* property : copyToVector(m_properties)) {
    527         if (m_properties.contains(property))
    528             property->suspendForPageCache();
     524    for (auto* observer : copyToVector(m_observers)) {
     525        if (m_observers.contains(observer))
     526            observer->suspendForPageCache();
    529527    }
    530528
     
    534532void DOMWindow::resumeFromPageCache()
    535533{
    536     for (auto* property : copyToVector(m_properties)) {
    537         if (m_properties.contains(property))
    538             property->resumeFromPageCache();
     534    for (auto* observer : copyToVector(m_observers)) {
     535        if (m_observers.contains(observer))
     536            observer->resumeFromPageCache();
    539537    }
    540538
    541539    m_suspendedForDocumentSuspension = false;
    542 }
    543 
    544 void DOMWindow::resetDOMWindowProperties()
    545 {
    546     m_properties.clear();
    547 
    548     m_applicationCache = nullptr;
    549     m_crypto = nullptr;
    550     m_history = nullptr;
    551     m_localStorage = nullptr;
    552     m_location = nullptr;
    553     m_locationbar = nullptr;
    554     m_media = nullptr;
    555     m_menubar = nullptr;
    556     m_navigator = nullptr;
    557     m_personalbar = nullptr;
    558     m_screen = nullptr;
    559     m_scrollbars = nullptr;
    560     m_selection = nullptr;
    561     m_sessionStorage = nullptr;
    562     m_statusbar = nullptr;
    563     m_toolbar = nullptr;
    564     m_performance = nullptr;
    565     m_visualViewport = nullptr;
    566540}
    567541
  • trunk/Source/WebCore/page/DOMWindow.h

    r242664 r242676  
    114114    void didSecureTransitionTo(Document&);
    115115
    116     void registerProperty(DOMWindowProperty&);
    117     void unregisterProperty(DOMWindowProperty&);
     116    class Observer {
     117    public:
     118        virtual ~Observer() { }
     119
     120        virtual void suspendForPageCache() { }
     121        virtual void resumeFromPageCache() { }
     122        virtual void willDestroyGlobalObjectInCachedFrame() { }
     123        virtual void willDestroyGlobalObjectInFrame() { }
     124        virtual void willDetachGlobalObjectFromFrame() { }
     125    };
     126
     127    void registerObserver(Observer&);
     128    void unregisterObserver(Observer&);
    118129
    119130    void resetUnlessSuspendedForDocumentSuspension();
     
    370381    bool isInsecureScriptAccess(DOMWindow& activeWindow, const String& urlString);
    371382
    372     void resetDOMWindowProperties();
    373 
    374383#if ENABLE(DEVICE_ORIENTATION)
    375384    void failedToRegisterDeviceMotionEventListener();
     
    387396    Optional<bool> m_canShowModalDialogOverride;
    388397
    389     HashSet<DOMWindowProperty*> m_properties;
     398    HashSet<Observer*> m_observers;
    390399
    391400    mutable RefPtr<Crypto> m_crypto;
  • trunk/Source/WebCore/page/DOMWindowExtension.cpp

    r241848 r242676  
    3737
    3838DOMWindowExtension::DOMWindowExtension(DOMWindow* window, DOMWrapperWorld& world)
    39     : DOMWindowProperty(window)
     39    : m_window(makeWeakPtr(window))
    4040    , m_world(world)
    4141    , m_wasDetached(false)
    4242{
    4343    ASSERT(this->frame());
     44    if (m_window)
     45        m_window->registerObserver(*this);
     46}
     47
     48DOMWindowExtension::~DOMWindowExtension()
     49{
     50    if (m_window)
     51        m_window->unregisterObserver(*this);
     52}
     53
     54Frame* DOMWindowExtension::frame() const
     55{
     56    return m_window ? m_window->frame() : nullptr;
    4457}
    4558
     
    5467
    5568    m_disconnectedFrame = WTFMove(frame);
    56 
    57     DOMWindowProperty::suspendForPageCache();
    5869}
    5970
    6071void DOMWindowExtension::resumeFromPageCache()
    6172{
     73    ASSERT(frame());
    6274    ASSERT(m_disconnectedFrame == frame());
    63    
    64     DOMWindowProperty::resumeFromPageCache();
     75    ASSERT(frame()->document()->domWindow() == m_window);
     76
    6577    m_disconnectedFrame = nullptr;
    6678
     
    7991    m_disconnectedFrame = nullptr;
    8092
    81     DOMWindowProperty::willDestroyGlobalObjectInCachedFrame();
     93    // DOMWindowExtension lifetime isn't tied directly to the DOMWindow itself so it is important that it unregister
     94    // itself from any DOMWindow it is associated with if that DOMWindow is going away.
     95    ASSERT(m_window);
     96    if (m_window)
     97        m_window->unregisterObserver(*this);
     98    m_window = nullptr;
    8299}
    83100
     
    96113    }
    97114
    98     DOMWindowProperty::willDestroyGlobalObjectInFrame();
     115    // DOMWindowExtension lifetime isn't tied directly to the DOMWindow itself so it is important that it unregister
     116    // itself from any DOMWindow it is associated with if that DOMWindow is going away.
     117    ASSERT(m_window);
     118    if (m_window)
     119        m_window->unregisterObserver(*this);
     120    m_window = nullptr;
    99121}
    100122
     
    113135
    114136    m_wasDetached = true;
    115     DOMWindowProperty::willDetachGlobalObjectFromFrame();
    116137}
    117138
  • trunk/Source/WebCore/page/DOMWindowExtension.h

    r237029 r242676  
    2626#pragma once
    2727
    28 #include "DOMWindowProperty.h"
     28#include "DOMWindow.h"
    2929#include <wtf/RefCounted.h>
    3030#include <wtf/RefPtr.h>
     31#include <wtf/WeakPtr.h>
    3132
    3233namespace WebCore {
    3334
    34 class DOMWindowExtension;
    3535class DOMWrapperWorld;
    3636class Frame;
    3737
    38 class DOMWindowExtension : public RefCounted<DOMWindowExtension>, public DOMWindowProperty {
     38class DOMWindowExtension final : public RefCounted<DOMWindowExtension>, public DOMWindow::Observer {
    3939public:
    4040    static Ref<DOMWindowExtension> create(DOMWindow* window, DOMWrapperWorld& world)
     
    4343    }
    4444
    45     void suspendForPageCache() override;
    46     void resumeFromPageCache() override;
    47     void willDestroyGlobalObjectInCachedFrame() override;
    48     void willDestroyGlobalObjectInFrame() override;
    49     void willDetachGlobalObjectFromFrame() override;
     45    WEBCORE_EXPORT ~DOMWindowExtension();
    5046
     47    void suspendForPageCache() final;
     48    void resumeFromPageCache() final;
     49    void willDestroyGlobalObjectInCachedFrame() final;
     50    void willDestroyGlobalObjectInFrame() final;
     51    void willDetachGlobalObjectFromFrame() final;
     52
     53    WEBCORE_EXPORT Frame* frame() const;
    5154    DOMWrapperWorld& world() const { return m_world; }
    5255
     
    5457    WEBCORE_EXPORT DOMWindowExtension(DOMWindow*, DOMWrapperWorld&);
    5558
     59    WeakPtr<DOMWindow> m_window;
    5660    Ref<DOMWrapperWorld> m_world;
    5761    RefPtr<Frame> m_disconnectedFrame;
  • trunk/Source/WebCore/page/DOMWindowProperty.cpp

    r237029 r242676  
    2929
    3030#include "DOMWindow.h"
    31 #include "Document.h"
    3231#include "Frame.h"
    3332
     
    3534
    3635DOMWindowProperty::DOMWindowProperty(DOMWindow* window)
    37     : m_window(window)
    38 {
    39     if (m_window)
    40         m_window->registerProperty(*this);
    41 }
    42 
    43 DOMWindowProperty::~DOMWindowProperty()
    44 {
    45     if (m_window)
    46         m_window->unregisterProperty(*this);
    47 
    48     m_window = nullptr;
    49 }
    50 
    51 void DOMWindowProperty::suspendForPageCache()
    52 {
    53     ASSERT(m_window);
    54 }
    55 
    56 void DOMWindowProperty::resumeFromPageCache()
    57 {
    58     // If this property is being reconnected to its Frame to enter the PageCache, it must have
    59     // been disconnected from its Frame in the first place and it should still have an associated DOMWindow.
    60     ASSERT(frame());
    61     ASSERT(frame()->document()->domWindow() == m_window);
    62 }
    63 
    64 void DOMWindowProperty::willDestroyGlobalObjectInCachedFrame()
    65 {
    66     // If the property has been disconnected from its Frame for the page cache, then it must have originally had a Frame
    67     // and therefore should still have an associated DOMWindow.
    68     ASSERT(m_window);
    69 
    70     // DOMWindowProperty lifetime isn't tied directly to the DOMWindow itself so it is important that it unregister
    71     // itself from any DOMWindow it is associated with if that DOMWindow is going away.
    72     if (m_window)
    73         m_window->unregisterProperty(*this);
    74     m_window = nullptr;
    75 }
    76 
    77 void DOMWindowProperty::willDestroyGlobalObjectInFrame()
    78 {
    79     ASSERT(m_window);
    80 
    81     // DOMWindowProperty lifetime isn't tied directly to the DOMWindow itself so it is important that it unregister
    82     // itself from any DOMWindow it is associated with if that DOMWindow is going away.
    83     if (m_window)
    84         m_window->unregisterProperty(*this);
    85     m_window = nullptr;
    86 }
    87 
    88 void DOMWindowProperty::willDetachGlobalObjectFromFrame()
     36    : m_window(makeWeakPtr(window))
    8937{
    9038}
  • trunk/Source/WebCore/page/DOMWindowProperty.h

    r237029 r242676  
    2626#pragma once
    2727
     28#include <wtf/WeakPtr.h>
     29
    2830namespace WebCore {
    2931
     
    3335class DOMWindowProperty {
    3436public:
    35     explicit DOMWindowProperty(DOMWindow*);
    36 
    37     virtual void suspendForPageCache();
    38     virtual void resumeFromPageCache();
    39     virtual void willDestroyGlobalObjectInCachedFrame();
    40     virtual void willDestroyGlobalObjectInFrame();
    41     virtual void willDetachGlobalObjectFromFrame();
    42 
    43     WEBCORE_EXPORT Frame* frame() const;
    44     DOMWindow* window() const { return m_window; }
     37    Frame* frame() const;
     38    DOMWindow* window() const { return m_window.get(); }
    4539
    4640protected:
    47     virtual ~DOMWindowProperty();
     41    explicit DOMWindowProperty(DOMWindow*);
     42    ~DOMWindowProperty() = default;
    4843
    49     DOMWindow* m_window;
     44private:
     45    WeakPtr<DOMWindow> m_window;
    5046};
    5147
  • trunk/Source/WebCore/page/History.idl

    r229392 r242676  
    2727    GenerateIsReachable=ImplFrame,
    2828    JSCustomMarkFunction,
     29    ImplementationLacksVTable,
    2930] interface History {
    3031    readonly attribute unsigned long length;
  • trunk/Source/WebCore/page/Location.idl

    r222429 r242676  
    4141    GenerateIsReachable=ImplFrame,
    4242    IsImmutablePrototypeExoticObject,
     43    ImplementationLacksVTable,
    4344    Unforgeable
    4445] interface Location {
  • trunk/Source/WebCore/page/Navigator.cpp

    r240641 r242676  
    168168    }
    169169    if (!m_plugins)
    170         m_plugins = DOMPluginArray::create(m_window);
     170        m_plugins = DOMPluginArray::create(window());
    171171    return *m_plugins;
    172172}
     
    179179    }
    180180    if (!m_mimeTypes)
    181         m_mimeTypes = DOMMimeTypeArray::create(m_window);
     181        m_mimeTypes = DOMMimeTypeArray::create(window());
    182182    return *m_mimeTypes;
    183183}
  • trunk/Source/WebCore/page/PerformanceNavigation.idl

    r219954 r242676  
    3030
    3131// See: http://www.w3.org/TR/navigation-timing/
    32 interface PerformanceNavigation {
     32[
     33    ImplementationLacksVTable,
     34] interface PerformanceNavigation {
    3335    const unsigned short TYPE_NAVIGATE = 0;
    3436    const unsigned short TYPE_RELOAD = 1;
  • trunk/Source/WebCore/page/PerformanceTiming.idl

    r219954 r242676  
    3030
    3131// See: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html
    32 interface PerformanceTiming {
     32[
     33    ImplementationLacksVTable,
     34] interface PerformanceTiming {
    3335    readonly attribute unsigned long long navigationStart;
    3436    readonly attribute unsigned long long unloadEventStart;
  • trunk/Source/WebCore/page/Screen.idl

    r209247 r242676  
    3030[
    3131    GenerateIsReachable=ImplFrame,
     32    ImplementationLacksVTable,
    3233] interface Screen {
    3334    readonly attribute unsigned long height;
  • trunk/Source/WebCore/page/VisualViewport.cpp

    r236917 r242676  
    5151ScriptExecutionContext* VisualViewport::scriptExecutionContext() const
    5252{
    53     if (!m_window)
     53    auto window = this->window();
     54    if (!window)
    5455        return nullptr;
    55     return static_cast<ContextDestructionObserver*>(m_window)->scriptExecutionContext();
     56    return static_cast<ContextDestructionObserver*>(window)->scriptExecutionContext();
    5657}
    5758
  • trunk/Source/WebCore/plugins/DOMMimeTypeArray.idl

    r210667 r242676  
    2222    GenerateIsReachable=ImplFrame,
    2323    LegacyUnenumerableNamedProperties,
     24    ImplementationLacksVTable,
    2425    InterfaceName=MimeTypeArray,
    2526] interface DOMMimeTypeArray {
  • trunk/Source/WebCore/plugins/DOMPluginArray.idl

    r210667 r242676  
    2222    GenerateIsReachable=ImplFrame,
    2323    LegacyUnenumerableNamedProperties,
     24    ImplementationLacksVTable,
    2425    InterfaceName=PluginArray,
    2526] interface DOMPluginArray {
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/DOM/DOMObjectCache.cpp

    r236917 r242676  
    2020#include "DOMObjectCache.h"
    2121
    22 #include <WebCore/DOMWindowProperty.h>
     22#include <WebCore/DOMWindow.h>
    2323#include <WebCore/Document.h>
    2424#include <WebCore/Frame.h>
     
    114114
    115115private:
    116     class DOMWindowObserver final: public WebCore::DOMWindowProperty {
     116    class DOMWindowObserver final : public WebCore::DOMWindow::Observer {
    117117        WTF_MAKE_FAST_ALLOCATED;
    118118    public:
    119119        DOMWindowObserver(WebCore::DOMWindow& window, DOMObjectCacheFrameObserver& frameObserver)
    120             : DOMWindowProperty(&window)
     120            : m_window(makeWeakPtr(window))
    121121            , m_frameObserver(frameObserver)
    122122        {
    123         }
    124 
    125         virtual ~DOMWindowObserver()
     123            window.registerObserver(*this);
     124        }
     125
     126        ~DOMWindowObserver()
    126127        {
    127         }
     128            if (m_window)
     129                m_window->unregisterObserver(*this);
     130        }
     131
     132        WebCore::DOMWindow* window() const { return m_window.get(); }
    128133
    129134    private:
    130135        void willDetachGlobalObjectFromFrame() override
    131136        {
    132             // Clear the DOMWindowProperty first, and then notify the Frame observer.
    133             DOMWindowProperty::willDetachGlobalObjectFromFrame();
    134137            m_frameObserver.willDetachGlobalObjectFromFrame();
    135138        }
    136139
     140        WeakPtr<WebCore::DOMWindow> m_window;
    137141        DOMObjectCacheFrameObserver& m_frameObserver;
    138142    };
Note: See TracChangeset for help on using the changeset viewer.