DOMWindow shouldn't have any INDEXED_DATABASE ifdefs
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Mar 2012 20:29:55 +0000 (20:29 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Mar 2012 20:29:55 +0000 (20:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80013

Reviewed by Kentaro Hara.

Before this patch, DOMWindow still knew about IDB because of the
database factory.  This patch moves the factory to
DOMWindowIndexedDatabase.

* Modules/indexeddb/DOMWindowIndexedDatabase.cpp:
(WebCore::DOMWindowIndexedDatabase::DOMWindowIndexedDatabase):
(WebCore::DOMWindowIndexedDatabase::from):
(WebCore):
(WebCore::DOMWindowIndexedDatabase::disconnectFrame):
(WebCore::DOMWindowIndexedDatabase::webkitIndexedDB):
* Modules/indexeddb/DOMWindowIndexedDatabase.h:
(DOMWindowIndexedDatabase):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::~DOMWindow):
(WebCore::DOMWindow::clear):
(WebCore):
* page/DOMWindow.h:
(DOMWindow):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109392 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/DOMWindowIndexedDatabase.cpp
Source/WebCore/Modules/indexeddb/DOMWindowIndexedDatabase.h
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h

index 396c417..a89c85a 100644 (file)
@@ -1,3 +1,29 @@
+2012-03-01  Adam Barth  <abarth@webkit.org>
+
+        DOMWindow shouldn't have any INDEXED_DATABASE ifdefs
+        https://bugs.webkit.org/show_bug.cgi?id=80013
+
+        Reviewed by Kentaro Hara.
+
+        Before this patch, DOMWindow still knew about IDB because of the
+        database factory.  This patch moves the factory to
+        DOMWindowIndexedDatabase.
+
+        * Modules/indexeddb/DOMWindowIndexedDatabase.cpp:
+        (WebCore::DOMWindowIndexedDatabase::DOMWindowIndexedDatabase):
+        (WebCore::DOMWindowIndexedDatabase::from):
+        (WebCore):
+        (WebCore::DOMWindowIndexedDatabase::disconnectFrame):
+        (WebCore::DOMWindowIndexedDatabase::webkitIndexedDB):
+        * Modules/indexeddb/DOMWindowIndexedDatabase.h:
+        (DOMWindowIndexedDatabase):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::~DOMWindow):
+        (WebCore::DOMWindow::clear):
+        (WebCore):
+        * page/DOMWindow.h:
+        (DOMWindow):
+
 2012-03-01  Anders Carlsson  <andersca@apple.com>
 
         Glitchy scrolling on pages where the scroll layer needs to be updated on the main thread
index 9b40c5a..ad6eedb 100644 (file)
@@ -37,7 +37,9 @@
 
 namespace WebCore {
 
-DOMWindowIndexedDatabase::DOMWindowIndexedDatabase()
+DOMWindowIndexedDatabase::DOMWindowIndexedDatabase(DOMWindow* window)
+    : DOMWindowProperty(window->frame())
+    , m_window(window)
 {
 }
 
@@ -45,9 +47,31 @@ DOMWindowIndexedDatabase::~DOMWindowIndexedDatabase()
 {
 }
 
+DOMWindowIndexedDatabase* DOMWindowIndexedDatabase::from(DOMWindow* window)
+{
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("DOMWindowIndexedDatabase"));
+    DOMWindowIndexedDatabase* supplement = static_cast<DOMWindowIndexedDatabase*>(Supplement<DOMWindow>::from(window, name));
+    if (!supplement) {
+        supplement = new DOMWindowIndexedDatabase(window);
+        provideTo(window, name, adoptPtr(supplement));
+    }
+    return supplement;
+}
+
+void DOMWindowIndexedDatabase::disconnectFrame()
+{
+    m_idbFactory = 0;
+    DOMWindowProperty::disconnectFrame();
+}
+
 IDBFactory* DOMWindowIndexedDatabase::webkitIndexedDB(DOMWindow* window)
 {
-    Document* document = window->document();
+    return from(window)->webkitIndexedDB();
+}
+
+IDBFactory* DOMWindowIndexedDatabase::webkitIndexedDB()
+{
+    Document* document = m_window->document();
     if (!document)
         return 0;
 
@@ -58,9 +82,9 @@ IDBFactory* DOMWindowIndexedDatabase::webkitIndexedDB(DOMWindow* window)
     if (!document->securityOrigin()->canAccessDatabase())
         return 0;
 
-    if (!window->idbFactory() && window->isCurrentlyDisplayedInFrame())
-        window->setIDBFactory(IDBFactory::create(page->group().idbFactory()));
-    return window->idbFactory();
+    if (!m_idbFactory && m_window->isCurrentlyDisplayedInFrame())
+        m_idbFactory = IDBFactory::create(page->group().idbFactory());
+    return m_idbFactory.get();
 }
 
 } // namespace WebCore
index 960c144..338d11b 100644 (file)
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "DOMWindowProperty.h"
+#include "Supplementable.h"
+
 namespace WebCore {
 
 class IDBFactory;
 class DOMWindow;
 
-class DOMWindowIndexedDatabase {
+class DOMWindowIndexedDatabase : public DOMWindowProperty, public Supplement<DOMWindow> {
 public:
+    virtual ~DOMWindowIndexedDatabase();
+    static DOMWindowIndexedDatabase* from(DOMWindow*);
+
     static IDBFactory* webkitIndexedDB(DOMWindow*);
 
+    virtual void disconnectFrame() OVERRIDE;
+
 private:
-    DOMWindowIndexedDatabase();
-    ~DOMWindowIndexedDatabase();
+    explicit DOMWindowIndexedDatabase(DOMWindow*);
+
+    IDBFactory* webkitIndexedDB();
+
+    DOMWindow* m_window;
+    RefPtr<IDBFactory> m_idbFactory;
 };
 
 } // namespace WebCore
index 8b24881..557f636 100644 (file)
@@ -420,9 +420,6 @@ DOMWindow::~DOMWindow()
 #if ENABLE(NOTIFICATIONS)
     ASSERT(!m_notifications);
 #endif
-#if ENABLE(INDEXED_DATABASE)
-    ASSERT(!m_idbFactory);
-#endif
 #if ENABLE(BLOB)
     ASSERT(!m_domURL);
 #endif
@@ -531,9 +528,6 @@ void DOMWindow::clear()
     // the rest of the DOMWindowProperties.
     resetNotifications();
 #endif
-#if ENABLE(INDEXED_DATABASE)
-    m_idbFactory = 0;
-#endif
 #if ENABLE(BLOB)
     m_domURL = 0;
 #endif
@@ -740,13 +734,6 @@ void DOMWindow::resetNotifications()
 }
 #endif
 
-#if ENABLE(INDEXED_DATABASE)
-void DOMWindow::setIDBFactory(PassRefPtr<IDBFactory> idbFactory)
-{
-    m_idbFactory = idbFactory;
-}
-#endif
-
 void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort* port, const String& targetOrigin, DOMWindow* source, ExceptionCode& ec)
 {
     MessagePortArray ports;
index 0b8b73f..816648f 100644 (file)
@@ -30,6 +30,7 @@
 #include "EventTarget.h"
 #include "FrameDestructionObserver.h"
 #include "KURL.h"
+#include "Supplementable.h"
 
 namespace WebCore {
 
@@ -80,7 +81,7 @@ namespace WebCore {
 
     enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
 
-    class DOMWindow : public RefCounted<DOMWindow>, public EventTarget, public FrameDestructionObserver {
+    class DOMWindow : public RefCounted<DOMWindow>, public EventTarget, public FrameDestructionObserver, public Supplementable<DOMWindow> {
     public:
         static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
         virtual ~DOMWindow();
@@ -393,11 +394,6 @@ namespace WebCore {
         // by the document that is currently active in m_frame.
         bool isCurrentlyDisplayedInFrame() const;
 
-#if ENABLE(INDEXED_DATABASE)
-        IDBFactory* idbFactory() { return m_idbFactory.get(); }
-        void setIDBFactory(PassRefPtr<IDBFactory>);
-#endif
-
     private:
         explicit DOMWindow(Frame*);
 
@@ -445,11 +441,6 @@ namespace WebCore {
 
         mutable RefPtr<Storage> m_sessionStorage;
         mutable RefPtr<Storage> m_localStorage;
-
-#if ENABLE(INDEXED_DATABASE)
-        mutable RefPtr<IDBFactory> m_idbFactory;
-#endif
-
         mutable RefPtr<DOMApplicationCache> m_applicationCache;
 
 #if ENABLE(NOTIFICATIONS)