2008-12-18 Dimitri Glazkov <dglazkov@chromium.org>
authordarin@chromium.org <darin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Dec 2008 21:21:13 +0000 (21:21 +0000)
committerdarin@chromium.org <darin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Dec 2008 21:21:13 +0000 (21:21 +0000)
        Reviewed by Geoffrey Garen.

        https://bugs.webkit.org/show_bug.cgi?id=22859
        Abstract away the use of JSDOMWindow in CachedPage and introduce
        ScriptCachedPageData abstraction.

        * GNUmakefile.am: Added ScriptCachedPageData to project.
        * WebCore.pro: Added ScriptCachedPageData to project.
        * WebCore.vcproj/WebCore.vcproj: Added ScriptCachedPageData to project.
        * WebCore.xcodeproj/project.pbxproj: Added ScriptCachedPageData to
            project.
        * bindings/js/ScriptCachedPageData.cpp: Added.
        (WebCore::ScriptCachedPageData::ScriptCachedPageData):
        (WebCore::ScriptCachedPageData::~ScriptCachedPageData):
        (WebCore::ScriptCachedPageData::restore):
        (WebCore::ScriptCachedPageData::clear):
        * bindings/js/ScriptCachedPageData.h: Added.
        * history/CachedPage.cpp: Replaced JSDOMWindow and ProtectedPtr with
            ScriptCachedPageData.
        (WebCore::CachedPage::CachedPage):
        (WebCore::CachedPage::domWindow):
        (WebCore::CachedPage::restore):
        (WebCore::CachedPage::clear):
        * history/CachedPage.h: Replaced JSDOMWindow and ProtectedPtr with
            ScriptCachedPageData.

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

WebCore/ChangeLog
WebCore/GNUmakefile.am
WebCore/WebCore.pro
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bindings/js/ScriptCachedPageData.cpp [new file with mode: 0644]
WebCore/bindings/js/ScriptCachedPageData.h [new file with mode: 0644]
WebCore/history/CachedPage.cpp
WebCore/history/CachedPage.h

index 3fe99be5c5a57f469a0dabf2c4390f94a61bf146..fcf16fe734312691c0fc1716bbdc8bb678033f42 100644 (file)
@@ -1,3 +1,31 @@
+2008-12-18  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Geoffrey Garen.
+
+        https://bugs.webkit.org/show_bug.cgi?id=22859
+        Abstract away the use of JSDOMWindow in CachedPage and introduce
+        ScriptCachedPageData abstraction.
+
+        * GNUmakefile.am: Added ScriptCachedPageData to project.
+        * WebCore.pro: Added ScriptCachedPageData to project.
+        * WebCore.vcproj/WebCore.vcproj: Added ScriptCachedPageData to project.
+        * WebCore.xcodeproj/project.pbxproj: Added ScriptCachedPageData to
+            project.
+        * bindings/js/ScriptCachedPageData.cpp: Added.
+        (WebCore::ScriptCachedPageData::ScriptCachedPageData):
+        (WebCore::ScriptCachedPageData::~ScriptCachedPageData):
+        (WebCore::ScriptCachedPageData::restore):
+        (WebCore::ScriptCachedPageData::clear):
+        * bindings/js/ScriptCachedPageData.h: Added.
+        * history/CachedPage.cpp: Replaced JSDOMWindow and ProtectedPtr with
+            ScriptCachedPageData.
+        (WebCore::CachedPage::CachedPage):
+        (WebCore::CachedPage::domWindow):
+        (WebCore::CachedPage::restore):
+        (WebCore::CachedPage::clear):
+        * history/CachedPage.h: Replaced JSDOMWindow and ProtectedPtr with
+            ScriptCachedPageData.
+
 2008-12-18  Chris Marrin  <cmarrin@apple.com>
 
         Reviewed by Dave Hyatt.
index b1648be90c2229c96a7a9071576dd8e83def7d7b..c8316a8ab32327cab2e6ec8fc7bb086b0f34ef11 100644 (file)
@@ -348,6 +348,8 @@ webcore_sources += \
        WebCore/bindings/js/JSXSLTProcessorCustom.cpp \
        WebCore/bindings/js/ScheduledAction.cpp \
        WebCore/bindings/js/ScheduledAction.h \
+       WebCore/bindings/js/ScriptCachedPageData.cpp \
+       WebCore/bindings/js/ScriptCachedPageData.h \
        WebCore/bindings/js/ScriptCallFrame.cpp \
        WebCore/bindings/js/ScriptCallFrame.h \
        WebCore/bindings/js/ScriptCallStack.cpp \
index b959dc69d6e0ca6a6b35afecfff567045d405ec2..b4fcca29c26255af3b35118652c90582d198b36c 100644 (file)
@@ -466,6 +466,7 @@ SOURCES += \
     bindings/js/JSDOMBinding.cpp \
     bindings/js/JSEventListener.cpp \
     bindings/js/JSPluginElementFunctions.cpp \
+    bindings/js/ScriptCachedPageData.cpp \
     bindings/js/ScriptCallFrame.cpp \
     bindings/js/ScriptCallStack.cpp \
     bindings/js/ScriptController.cpp \
index 9ae78697d09f1a51e0fae93b7771b27684dd4eaa..d97b76a205720e0f5ab8549c1527c33083558fb8 100644 (file)
                                        RelativePath="..\bindings\js\ScheduledAction.h"\r
                                        >\r
                                </File>\r
+                               <File\r
+                                       RelativePath="..\bindings\js\ScriptCachedPageData.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath="..\bindings\js\ScriptCachedPageData.h"\r
+                                       >\r
+                               </File>\r
                                <File\r
                                        RelativePath="..\bindings\js\ScriptCallFrame.cpp"\r
                                        >\r
index f86a299e7a7534757254f0a9363027881e07aa9a..0fd769f87688a7dda80616e27a685fb2a131445a 100644 (file)
                416E75CC0EDF90C700360E1D /* ScriptCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 416E75CA0EDF90C700360E1D /* ScriptCallFrame.cpp */; };
                416F45F00ED7B311008215B6 /* ScriptString.h in Headers */ = {isa = PBXBuildFile; fileRef = 416F45EF0ED7B311008215B6 /* ScriptString.h */; };
                41C760B10EDE03D300C1655F /* ScriptState.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C760B00EDE03D300C1655F /* ScriptState.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               41F1D21F0EF35C2A00DA8753 /* ScriptCachedPageData.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F1D21D0EF35C2A00DA8753 /* ScriptCachedPageData.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               41F1D2200EF35C2A00DA8753 /* ScriptCachedPageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41F1D21E0EF35C2A00DA8753 /* ScriptCachedPageData.cpp */; };
                4415292E0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */; };
                4415292F0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4415292D0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp */; };
                441B05560CD779B6007C1F18 /* DOMCSSStyleSheetPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 4429AAEA0CB84DC7007647C5 /* DOMCSSStyleSheetPrivate.h */; };
                416E75CA0EDF90C700360E1D /* ScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptCallFrame.cpp; sourceTree = "<group>"; };
                416F45EF0ED7B311008215B6 /* ScriptString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptString.h; sourceTree = "<group>"; };
                41C760B00EDE03D300C1655F /* ScriptState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptState.h; sourceTree = "<group>"; };
+               41F1D21D0EF35C2A00DA8753 /* ScriptCachedPageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptCachedPageData.h; sourceTree = "<group>"; };
+               41F1D21E0EF35C2A00DA8753 /* ScriptCachedPageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptCachedPageData.cpp; sourceTree = "<group>"; };
                4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLPlugInImageElement.h; sourceTree = "<group>"; };
                4415292D0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLPlugInImageElement.cpp; sourceTree = "<group>"; };
                4429AAEA0CB84DC7007647C5 /* DOMCSSStyleSheetPrivate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMCSSStyleSheetPrivate.h; sourceTree = "<group>"; };
                                BCE99EC20DCA624100182683 /* JSXSLTProcessorConstructor.h */,
                                BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */,
                                BCA378BB0D15F64200B793D6 /* ScheduledAction.h */,
+                               41F1D21E0EF35C2A00DA8753 /* ScriptCachedPageData.cpp */,
+                               41F1D21D0EF35C2A00DA8753 /* ScriptCachedPageData.h */,
                                416E75CA0EDF90C700360E1D /* ScriptCallFrame.cpp */,
                                416E75C90EDF90C700360E1D /* ScriptCallFrame.h */,
                                416E75BD0EDF8FD700360E1D /* ScriptCallStack.cpp */,
                                1A569D250D7E2B82007C3983 /* runtime_root.h in Headers */,
                                93309E1E099E64920056E581 /* visible_units.h in Headers */,
                                08820BDF0EF5D381009099A8 /* WMLTableElement.h in Headers */,
+                               41F1D21F0EF35C2A00DA8753 /* ScriptCachedPageData.h in Headers */,
                                49E911C40EF86D47009D0CAF /* AffineTransform.h in Headers */,
                                49E911C50EF86D47009D0CAF /* IdentityTransformOperation.h in Headers */,
                                49E911C70EF86D47009D0CAF /* MatrixTransformOperation.h in Headers */,
                                1A569D240D7E2B82007C3983 /* runtime_root.cpp in Sources */,
                                93309E1D099E64920056E581 /* visible_units.cpp in Sources */,
                                08820BDE0EF5D381009099A8 /* WMLTableElement.cpp in Sources */,
+                               41F1D2200EF35C2A00DA8753 /* ScriptCachedPageData.cpp in Sources */,
                                49E911C30EF86D47009D0CAF /* AffineTransform.cpp in Sources */,
                                49E911C60EF86D47009D0CAF /* MatrixTransformOperation.cpp in Sources */,
                                49E911C80EF86D47009D0CAF /* RotateTransformOperation.cpp in Sources */,
diff --git a/WebCore/bindings/js/ScriptCachedPageData.cpp b/WebCore/bindings/js/ScriptCachedPageData.cpp
new file mode 100644 (file)
index 0000000..eeccf43
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2008, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ScriptCachedPageData.h"
+
+#include "Frame.h"
+#include "GCController.h"
+#include "Page.h"
+#include "PageGroup.h"
+#include <runtime/JSLock.h>
+#include "ScriptController.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+ScriptCachedPageData::ScriptCachedPageData(Page* page)
+{
+    JSLock lock(false);
+
+    ScriptController* scriptController = page->mainFrame()->script();
+    if (scriptController->haveWindowShell()) {
+        m_window = scriptController->windowShell()->window();
+    }
+}
+
+DOMWindow* ScriptCachedPageData::domWindow() const {
+    return m_window ? m_window->impl() : 0;
+}
+
+ScriptCachedPageData::~ScriptCachedPageData()
+{
+    clear();
+}
+
+void ScriptCachedPageData::restore(Page* page)
+{
+    Frame* mainFrame = page->mainFrame();
+
+    JSLock lock(false);
+
+    ScriptController* scriptController = mainFrame->script();
+    if (scriptController->haveWindowShell()) {
+        JSDOMWindowShell* windowShell = scriptController->windowShell();
+        if (m_window) {
+            windowShell->setWindow(m_window.get());
+        } else {
+            windowShell->setWindow(mainFrame->domWindow());
+            scriptController->attachDebugger(page->debugger());
+            windowShell->window()->setProfileGroup(page->group().identifier());
+        }
+    }
+}
+
+void ScriptCachedPageData::clear()
+{
+    JSLock lock(false);
+
+    if (!m_window) {
+        m_window = 0;
+        gcController().garbageCollectSoon();
+    }
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/ScriptCachedPageData.h b/WebCore/bindings/js/ScriptCachedPageData.h
new file mode 100644 (file)
index 0000000..91e47d0
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Google Inc. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScriptCachedPageData_h
+#define ScriptCachedPageData_h
+
+#include <runtime/Protect.h>
+
+namespace WebCore {
+    class JSDOMWindow;
+    class Page;
+    class DOMWindow;
+
+    class ScriptCachedPageData  {
+    public:
+        ScriptCachedPageData(Page*);
+        ~ScriptCachedPageData();
+
+        void restore(Page*);
+        void clear();
+        DOMWindow* domWindow() const;
+
+    private:
+        JSC::ProtectedPtr<JSDOMWindow> m_window;
+    };
+
+} // namespace WebCore
+
+#endif // ScriptCachedPageData_h
index 125df307a1ea2949f21c9071b3b95d1c25b824d9..2690f76776eef1ad110d944c9270acca94ea8265 100644 (file)
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameView.h"
-#include "GCController.h"
-#include "JSDOMWindow.h"
-#include "JSDOMWindowShell.h"
 #include "Logging.h"
 #include "Page.h"
 #include "PageGroup.h"
 #include "SystemTime.h"
-#include "ScriptController.h"
-#include <runtime/JSLock.h>
 #include <wtf/RefCountedLeakCounter.h>
 
 #if ENABLE(SVG)
@@ -70,6 +65,7 @@ CachedPage::CachedPage(Page* page)
     , m_view(page->mainFrame()->view())
     , m_mousePressNode(page->mainFrame()->eventHandler()->mousePressNode())
     , m_URL(page->mainFrame()->loader()->url())
+    , m_cachedPageScriptData(page)
 {
 #ifndef NDEBUG
     cachedPageCounter.increment();
@@ -80,13 +76,6 @@ CachedPage::CachedPage(Page* page)
     Frame* mainFrame = page->mainFrame();
     mainFrame->clearTimers();
 
-    JSLock lock(false);
-
-    ScriptController* proxy = mainFrame->script();
-    if (proxy->haveWindowShell()) {
-        m_window = proxy->windowShell()->window();
-    }
-
     m_document->setInPageCache(true);
 }
 
@@ -101,7 +90,7 @@ CachedPage::~CachedPage()
 
 DOMWindow* CachedPage::domWindow() const
 {
-    return m_window ? m_window->impl() : 0;
+    return m_cachedPageScriptData.domWindow();
 }
 
 void CachedPage::restore(Page* page)
@@ -110,19 +99,7 @@ void CachedPage::restore(Page* page)
 
     Frame* mainFrame = page->mainFrame();
 
-    JSLock lock(false);
-
-    ScriptController* proxy = mainFrame->script();
-    if (proxy->haveWindowShell()) {
-        JSDOMWindowShell* windowShell = proxy->windowShell();
-        if (m_window) {
-            windowShell->setWindow(m_window.get());
-        } else {
-            windowShell->setWindow(mainFrame->domWindow());
-            proxy->attachDebugger(page->debugger());
-            windowShell->window()->setProfileGroup(page->group().identifier());
-        }
-    }
+    m_cachedPageScriptData.restore(page);
 
 #if ENABLE(SVG)
     if (m_document && m_document->svgExtensions())
@@ -171,12 +148,9 @@ void CachedPage::clear()
     m_mousePressNode = 0;
     m_URL = KURL();
 
-    JSLock lock(false);
-    m_window = 0;
-
     m_cachedPagePlatformData.clear();
 
-    gcController().garbageCollectSoon();
+    m_cachedPageScriptData.clear();
 }
 
 void CachedPage::setDocumentLoader(PassRefPtr<DocumentLoader> loader)
index 8dc008b0a8c00b656f43eacb5efcd5a2f0d68003..7602e2058267911432514e25029c59e684db134b 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "KURL.h"
 #include <wtf/OwnPtr.h>
-#include <runtime/Protect.h>
+#include "ScriptCachedPageData.h"
 
 namespace WebCore {
     
@@ -74,7 +74,7 @@ private:
     RefPtr<FrameView> m_view;
     RefPtr<Node> m_mousePressNode;
     KURL m_URL;
-    JSC::ProtectedPtr<JSDOMWindow> m_window;
+    ScriptCachedPageData m_cachedPageScriptData;
     OwnPtr<CachedPagePlatformData> m_cachedPagePlatformData;
 };