2009-03-16 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Mar 2009 16:47:10 +0000 (16:47 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Mar 2009 16:47:10 +0000 (16:47 +0000)
        Reviewed by Timothy Hatcher.

        https://bugs.webkit.org/show_bug.cgi?id=24590
        Refactor InspectorDOMStorageResource to use ScriptFunctionCall.

        * bindings/js/ScriptFunctionCall.cpp:
        (WebCore::ScriptFunctionCall::appendArgument): Added method for bool argument.
        * bindings/js/ScriptFunctionCall.h: Ditto, also cleaned up.
        * bindings/js/ScriptObjectQuarantine.cpp:
        (WebCore::getQuarantinedScriptObject): Added Storage helper.
        * bindings/js/ScriptObjectQuarantine.h: Ditto.
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::populateScriptObjects): Changed to use bind method.
        (WebCore::InspectorController::resetScriptObjects): Changed to use unbind method.
        (WebCore::InspectorController::didUseDOMStorage): Changed to use isSameHostAndType and bind methods.
        * inspector/InspectorController.h: Removed add/remove methods for DOM storage.
        * inspector/InspectorDOMStorageResource.cpp:
        (WebCore::InspectorDOMStorageResource::InspectorDOMStorageResource):
        (WebCore::InspectorDOMStorageResource::isSameHostAndType): Added.
        (WebCore::InspectorDOMStorageResource::bind): Added.
        (WebCore::InspectorDOMStorageResource::unbind): Added.
        * inspector/InspectorDOMStorageResource.h:

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

WebCore/ChangeLog
WebCore/bindings/js/ScriptFunctionCall.cpp
WebCore/bindings/js/ScriptFunctionCall.h
WebCore/bindings/js/ScriptObjectQuarantine.cpp
WebCore/bindings/js/ScriptObjectQuarantine.h
WebCore/inspector/InspectorController.cpp
WebCore/inspector/InspectorController.h
WebCore/inspector/InspectorDOMStorageResource.cpp
WebCore/inspector/InspectorDOMStorageResource.h

index 5464e29..314e1e7 100644 (file)
@@ -1,3 +1,28 @@
+2009-03-16  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Timothy Hatcher.
+
+        https://bugs.webkit.org/show_bug.cgi?id=24590
+        Refactor InspectorDOMStorageResource to use ScriptFunctionCall.
+
+        * bindings/js/ScriptFunctionCall.cpp:
+        (WebCore::ScriptFunctionCall::appendArgument): Added method for bool argument.
+        * bindings/js/ScriptFunctionCall.h: Ditto, also cleaned up.
+        * bindings/js/ScriptObjectQuarantine.cpp:
+        (WebCore::getQuarantinedScriptObject): Added Storage helper.
+        * bindings/js/ScriptObjectQuarantine.h: Ditto.
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::populateScriptObjects): Changed to use bind method.
+        (WebCore::InspectorController::resetScriptObjects): Changed to use unbind method.
+        (WebCore::InspectorController::didUseDOMStorage): Changed to use isSameHostAndType and bind methods.
+        * inspector/InspectorController.h: Removed add/remove methods for DOM storage.
+        * inspector/InspectorDOMStorageResource.cpp:
+        (WebCore::InspectorDOMStorageResource::InspectorDOMStorageResource):
+        (WebCore::InspectorDOMStorageResource::isSameHostAndType): Added.
+        (WebCore::InspectorDOMStorageResource::bind): Added.
+        (WebCore::InspectorDOMStorageResource::unbind): Added.
+        * inspector/InspectorDOMStorageResource.h:
+
 2009-03-16   Mike Belshe  <mike@belse.com>
 
         Reviewed by Dimitri Glazkov.
index a1f6693..3223aa9 100644 (file)
@@ -62,6 +62,11 @@ void ScriptFunctionCall::appendArgument(const String& argument)
     m_arguments.append(jsString(m_exec, argument));
 }
 
+void ScriptFunctionCall::appendArgument(bool argument)
+{
+    m_arguments.append(jsBoolean(argument));
+}
+
 ScriptValue ScriptFunctionCall::call(bool& hadException)
 {
     JSObject* thisObject = m_thisObject.jsObject();
index 020f267..dd77e34 100644 (file)
@@ -45,9 +45,10 @@ namespace WebCore {
         ScriptFunctionCall(ScriptState* exec, const ScriptObject& thisObject, const char* name);
         virtual ~ScriptFunctionCall() {};
 
-        void appendArgument(const ScriptObject& parameter);
-        void appendArgument(const ScriptValue& parameter);
-        void appendArgument(const String& parameter);
+        void appendArgument(const ScriptObject&);
+        void appendArgument(const ScriptValue&);
+        void appendArgument(const String&);
+        void appendArgument(bool);
         ScriptValue call(bool& hadException);
         ScriptObject construct(bool& hadException);
 
index 4942109..8cb3d25 100644 (file)
@@ -35,6 +35,7 @@
 #include "Document.h"
 #include "Frame.h"
 #include "JSDatabase.h"
+#include "JSStorage.h"
 #include "JSDOMBinding.h"
 #include "JSInspectedObjectWrapper.h"
 #include "ScriptObject.h"
@@ -48,16 +49,29 @@ namespace WebCore {
 bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject)
 {
     ASSERT(database);
-    
+
     Frame* frame = database->document()->frame();
     if (!frame)
         return false;
-    
+
     ExecState* exec = toJSDOMWindow(frame)->globalExec();
-    
+
     JSLock lock(false);
     quarantinedObject = ScriptObject(asObject(JSInspectedObjectWrapper::wrap(exec, toJS(exec, database))));
-    
+
+    return true;
+}
+
+bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject)
+{
+    ASSERT(frame);
+    ASSERT(storage);
+
+    ExecState* exec = toJSDOMWindow(frame)->globalExec();
+
+    JSLock lock(false);
+    quarantinedObject = ScriptObject(asObject(JSInspectedObjectWrapper::wrap(exec, toJS(exec, storage))));
+
     return true;
 }
 
index 5cb224b..0669fa6 100644 (file)
 namespace WebCore {
 
     class Database;
+    class Frame;
     class ScriptObject;
+    class Storage;
 
     bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject);
+    bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject);
 
 }
 
index a0ecebc..e2d57fe 100644 (file)
@@ -1190,84 +1190,12 @@ void InspectorController::populateScriptObjects()
 #if ENABLE(DOM_STORAGE)
     DOMStorageResourcesSet::iterator domStorageEnd = m_domStorageResources.end();
     for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it)
-        addDOMStorageScriptResource(it->get());
+        (*it)->bind(toJS(m_scriptContext), ScriptObject(toJS(m_scriptObject)));
 #endif
 
     callSimpleFunction(m_scriptContext, m_scriptObject, "populateInterface");
 }
 
-#if ENABLE(DOM_STORAGE)
-JSObjectRef InspectorController::addDOMStorageScriptResource(InspectorDOMStorageResource* resource)
-{
-    ASSERT_ARG(resource, resource);
-
-    if (resource->scriptObject)
-        return resource->scriptObject;
-
-    ASSERT(m_scriptContext);
-    ASSERT(m_scriptObject);
-    if (!m_scriptContext || !m_scriptObject)
-        return 0;
-
-    JSValueRef exception = 0;
-
-    JSValueRef domStorageProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("DOMStorage").get(), &exception);
-    if (HANDLE_EXCEPTION(m_scriptContext, exception))
-        return 0;
-
-    JSObjectRef domStorageConstructor = JSValueToObject(m_scriptContext, domStorageProperty, &exception);
-    if (HANDLE_EXCEPTION(m_scriptContext, exception))
-        return 0;
-
-    ExecState* exec = toJSDOMWindow(resource->frame.get())->globalExec();
-
-    JSValueRef domStorage;
-
-    {
-        JSC::JSLock lock(false);
-        domStorage = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, resource->domStorage.get())));
-    }
-
-    JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->frame->document()->securityOrigin()->host()).get());
-    JSValueRef isLocalStorageValue = JSValueMakeBoolean(m_scriptContext, resource->isLocalStorage);
-
-    JSValueRef arguments[] = { domStorage, domainValue, isLocalStorageValue };
-    JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, domStorageConstructor, 3, arguments, &exception);
-    if (HANDLE_EXCEPTION(m_scriptContext, exception))
-        return 0;
-
-    ASSERT(result);
-
-    callFunction(m_scriptContext, m_scriptObject, "addDOMStorage", 1, &result, exception);
-
-    if (exception)
-        return 0;
-
-    resource->setScriptObject(m_scriptContext, result);
-
-    return result;
-}
-
-void InspectorController::removeDOMStorageScriptResource(InspectorDOMStorageResource* resource)
-{
-    ASSERT(m_scriptContext);
-    ASSERT(m_scriptObject);
-    if (!m_scriptContext || !m_scriptObject)
-        return;
-
-    ASSERT(resource);
-    ASSERT(resource->scriptObject);
-    if (!resource || !resource->scriptObject)
-        return;
-
-    JSObjectRef scriptObject = resource->scriptObject;
-    resource->setScriptObject(0, 0);
-
-    JSValueRef exception = 0;
-    callFunction(m_scriptContext, m_scriptObject, "removeDOMStorage", 1, &scriptObject, exception);
-}
-#endif
-
 void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message)
 {
     ASSERT_ARG(message, message);
@@ -1347,10 +1275,8 @@ void InspectorController::resetScriptObjects()
 #endif
 #if ENABLE(DOM_STORAGE)
     DOMStorageResourcesSet::iterator domStorageEnd = m_domStorageResources.end();
-    for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it) {
-        InspectorDOMStorageResource* resource = it->get();
-        resource->setScriptObject(0, 0);
-    }
+    for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it)
+        (*it)->unbind();
 #endif
 
     callSimpleFunction(m_scriptContext, m_scriptObject, "reset");
@@ -1678,17 +1604,16 @@ void InspectorController::didUseDOMStorage(StorageArea* storageArea, bool isLoca
         return;
 
     DOMStorageResourcesSet::iterator domStorageEnd = m_domStorageResources.end();
-    for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it) {
-        InspectorDOMStorageResource* resource = it->get();
-        if (equalIgnoringCase(resource->frame->document()->securityOrigin()->host(), frame->document()->securityOrigin()->host()) && resource->isLocalStorage == isLocalStorage)
+    for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it)
+        if ((*it)->isSameHostAndType(frame, isLocalStorage))
             return;
-    }
+
     RefPtr<Storage> domStorage = Storage::create(frame, storageArea);
     RefPtr<InspectorDOMStorageResource> resource = InspectorDOMStorageResource::create(domStorage.get(), isLocalStorage, frame);
 
     m_domStorageResources.add(resource);
     if (windowVisible())
-        addDOMStorageScriptResource(resource.get());
+        resource->bind(toJS(m_scriptContext), ScriptObject(toJS(m_scriptObject)));
 }
 #endif
 
index 7968597..ba9f142 100644 (file)
@@ -286,11 +286,6 @@ private:
     void pruneResources(ResourcesMap*, DocumentLoader* loaderToKeep = 0);
     void removeAllResources(ResourcesMap* map) { pruneResources(map); }
 
-#if ENABLE(DOM_STORAGE)
-    JSObjectRef addDOMStorageScriptResource(InspectorDOMStorageResource*);
-    void removeDOMStorageScriptResource(InspectorDOMStorageResource*);
-#endif
-
     JSValueRef callSimpleFunction(JSContextRef, JSObjectRef thisObject, const char* functionName) const;
     JSValueRef callFunction(JSContextRef, JSObjectRef thisObject, const char* functionName, size_t argumentCount, const JSValueRef arguments[], JSValueRef& exception) const;
 
index b51ec09..33d036e 100644 (file)
 
 #include "InspectorDOMStorageResource.h"
 
+#include "Document.h"
 #include "Frame.h"
+#include "ScriptFunctionCall.h"
+#include "ScriptObjectQuarantine.h"
+#include "ScriptValue.h"
 #include "Storage.h"
 
 using namespace JSC;
@@ -41,25 +45,49 @@ using namespace JSC;
 namespace WebCore {
 
 InspectorDOMStorageResource::InspectorDOMStorageResource(Storage* domStorage, bool isLocalStorage, Frame* frame)
-    : domStorage(domStorage)
-    , isLocalStorage(isLocalStorage)
-    , frame(frame)
-    , scriptContext(0)
-    , scriptObject(0)
+    : m_domStorage(domStorage)
+    , m_isLocalStorage(isLocalStorage)
+    , m_frame(frame)
 {
 }
 
-void InspectorDOMStorageResource::setScriptObject(JSContextRef context, JSObjectRef newScriptObject)
+bool InspectorDOMStorageResource::isSameHostAndType(Frame* frame, bool isLocalStorage) const
 {
-    if (scriptContext && scriptObject)
-        JSValueUnprotect(scriptContext, scriptObject);
+    return equalIgnoringCase(m_frame->document()->securityOrigin()->host(), frame->document()->securityOrigin()->host()) && m_isLocalStorage == isLocalStorage;
+}
+
+void InspectorDOMStorageResource::bind(ScriptState* scriptState, const ScriptObject& webInspector)
+{
+    if (!m_scriptObject.hasNoValue())
+        return;
+
+    ASSERT(scriptState);
+    ASSERT(!webInspector.hasNoValue());
+    if (!scriptState || webInspector.hasNoValue())
+        return;
+
+    ScriptFunctionCall resourceConstructor(scriptState, webInspector, "DOMStorage");
+    ScriptObject domStorage;
+    if (!getQuarantinedScriptObject(m_frame.get(), m_domStorage.get(), domStorage))
+        return;
 
-    scriptObject = newScriptObject;
-    scriptContext = context;
+    resourceConstructor.appendArgument(domStorage);
+    resourceConstructor.appendArgument(m_frame->document()->securityOrigin()->host());
+    resourceConstructor.appendArgument(m_isLocalStorage);
 
-    ASSERT((context && newScriptObject) || (!context && !newScriptObject));
-    if (context && newScriptObject)
-        JSValueProtect(context, newScriptObject);
+    bool hadException = false;
+    m_scriptObject = resourceConstructor.construct(hadException);
+    if (hadException)
+        return;
+
+    ScriptFunctionCall addDOMStorage(scriptState, webInspector, "addDOMStorage");
+    addDOMStorage.appendArgument(m_scriptObject);
+    addDOMStorage.call(hadException);
+}
+
+void InspectorDOMStorageResource::unbind()
+{
+    m_scriptObject = ScriptObject();
 }
 
 } // namespace WebCore
index c52e8aa..ad3e196 100644 (file)
 
 #if ENABLE(DOM_STORAGE)
 
+#include "ScriptObject.h"
+#include "ScriptState.h"
+
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
-#include <JavaScriptCore/JSContextRef.h>
-
 namespace WebCore {
 
     class Storage;
@@ -51,16 +52,21 @@ namespace WebCore {
             return adoptRef(new InspectorDOMStorageResource(domStorage, isLocalStorage, frame));
         }
 
-        void setScriptObject(JSContextRef, JSObjectRef);
+        void bind(ScriptState*, const ScriptObject& webInspector);
+        void unbind();
 
-        RefPtr<Storage> domStorage;
-        bool isLocalStorage;
-        RefPtr<Frame> frame;
-        JSContextRef scriptContext;
-        JSObjectRef scriptObject;
+        bool isSameHostAndType(Frame*, bool isLocalStorage) const;
 
     private:
+
         InspectorDOMStorageResource(Storage*, bool isLocalStorage, Frame*);
+
+        ScriptObject m_scriptObject;
+        RefPtr<Storage> m_domStorage;
+        bool m_isLocalStorage;
+        RefPtr<Frame> m_frame;
+
+    private:
     };
 
 } // namespace WebCore