2008-04-17 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Apr 2008 21:30:36 +0000 (21:30 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Apr 2008 21:30:36 +0000 (21:30 +0000)
        Reviewed by Sam.

        Add JS bindings for the DOMApplicationCache object.

        * bindings/js/JSDOMApplicationCacheCustom.cpp:
        (WebCore::JSDOMApplicationCache::add):
        (WebCore::JSDOMApplicationCache::remove):
        (WebCore::JSDOMApplicationCache::addEventListener):
        (WebCore::JSDOMApplicationCache::removeEventListener):
        (WebCore::JSDOMApplicationCache::dispatchEvent):
        (WebCore::JSDOMApplicationCache::setOnchecking):
        (WebCore::JSDOMApplicationCache::onchecking):
        (WebCore::JSDOMApplicationCache::setOnerror):
        (WebCore::JSDOMApplicationCache::onerror):
        (WebCore::JSDOMApplicationCache::setOnnoupdate):
        (WebCore::JSDOMApplicationCache::onnoupdate):
        (WebCore::JSDOMApplicationCache::setOndownloading):
        (WebCore::JSDOMApplicationCache::ondownloading):
        (WebCore::JSDOMApplicationCache::setOnprogress):
        (WebCore::JSDOMApplicationCache::onprogress):
        (WebCore::JSDOMApplicationCache::setOnupdateready):
        (WebCore::JSDOMApplicationCache::onupdateready):
        (WebCore::JSDOMApplicationCache::setOncached):
        (WebCore::JSDOMApplicationCache::oncached):
        (WebCore::JSDOMApplicationCache::mark):
        * bindings/js/JSDOMWindowCustom.cpp:
        (WebCore::JSDOMWindow::mark):
        * bindings/js/JSEventTargetBase.cpp:
        (WebCore::toJS):
        * loader/appcache/DOMApplicationCache.idl:
        * page/DOMWindow.idl:

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

WebCore/ChangeLog
WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp
WebCore/bindings/js/JSDOMWindowCustom.cpp
WebCore/bindings/js/JSEventTargetBase.cpp
WebCore/loader/appcache/DOMApplicationCache.idl
WebCore/page/DOMWindow.idl

index e3aba23..32b093d 100644 (file)
@@ -1,3 +1,37 @@
+2008-04-17  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam.
+
+        Add JS bindings for the DOMApplicationCache object.
+        
+        * bindings/js/JSDOMApplicationCacheCustom.cpp:
+        (WebCore::JSDOMApplicationCache::add):
+        (WebCore::JSDOMApplicationCache::remove):
+        (WebCore::JSDOMApplicationCache::addEventListener):
+        (WebCore::JSDOMApplicationCache::removeEventListener):
+        (WebCore::JSDOMApplicationCache::dispatchEvent):
+        (WebCore::JSDOMApplicationCache::setOnchecking):
+        (WebCore::JSDOMApplicationCache::onchecking):
+        (WebCore::JSDOMApplicationCache::setOnerror):
+        (WebCore::JSDOMApplicationCache::onerror):
+        (WebCore::JSDOMApplicationCache::setOnnoupdate):
+        (WebCore::JSDOMApplicationCache::onnoupdate):
+        (WebCore::JSDOMApplicationCache::setOndownloading):
+        (WebCore::JSDOMApplicationCache::ondownloading):
+        (WebCore::JSDOMApplicationCache::setOnprogress):
+        (WebCore::JSDOMApplicationCache::onprogress):
+        (WebCore::JSDOMApplicationCache::setOnupdateready):
+        (WebCore::JSDOMApplicationCache::onupdateready):
+        (WebCore::JSDOMApplicationCache::setOncached):
+        (WebCore::JSDOMApplicationCache::oncached):
+        (WebCore::JSDOMApplicationCache::mark):
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::JSDOMWindow::mark):
+        * bindings/js/JSEventTargetBase.cpp:
+        (WebCore::toJS):
+        * loader/appcache/DOMApplicationCache.idl:
+        * page/DOMWindow.idl:
+
 2008-04-17 Eric Carlson  <eric.carlson@apple.com> 
 
         Reviewed by Adele. 
index 8924186..00e057b 100644 (file)
  */
 
 #include "config.h"
+#include "JSDOMApplicationCache.h"
 
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
 
+#include "AtomicString.h"
+#include "DOMApplicationCache.h"
+#include "DOMWindow.h"
+#include "Event.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "JSDOMWindow.h"
+#include "JSEvent.h"
+#include "kjs_events.h"
+
+using namespace KJS;
+
 namespace WebCore {
     
+JSValue* JSDOMApplicationCache::add(ExecState* exec, const List& args)
+{
+    Frame* frame = toJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
+    if (!frame)
+        return jsUndefined();
+    const KURL& url = frame->loader()->completeURL(args[0]->toString(exec));
+    
+    ExceptionCode ec = 0;
+    impl()->add(url, ec);
+    setDOMException(exec, ec);
+    return jsUndefined();
+}
+    
+JSValue* JSDOMApplicationCache::remove(ExecState* exec, const List& args)
+{
+    Frame* frame = toJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
+    if (!frame)
+        return jsUndefined();
+    const KURL& url = frame->loader()->completeURL(args[0]->toString(exec));
+    
+    ExceptionCode ec = 0;
+    impl()->remove(url, ec);
+    setDOMException(exec, ec);
+    return jsUndefined();
+}
+    
+JSValue* JSDOMApplicationCache::addEventListener(ExecState* exec, const List& args)
+{
+    Frame* frame = impl()->frame();
+    if (!frame)
+        return jsUndefined();
+    JSUnprotectedEventListener* listener = toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(args[1], true);
+    if (!listener)
+        return jsUndefined();
+    impl()->addEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec));
+    return jsUndefined();
+}
+
+JSValue* JSDOMApplicationCache::removeEventListener(ExecState* exec, const List& args)
+{
+    Frame* frame = impl()->frame();
+    if (!frame)
+        return jsUndefined();
+    JSUnprotectedEventListener* listener = toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(args[1], true);
+    if (!listener)
+        return jsUndefined();
+    impl()->removeEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec));
+    return jsUndefined();
+    
+}
+    
+JSValue* JSDOMApplicationCache::dispatchEvent(KJS::ExecState* exec, const List& args)
+{
+    ExceptionCode ec = 0;
+    
+    bool result = impl()->dispatchEvent(toEvent(args[0]), ec);
+    setDOMException(exec, ec);
+    return jsBoolean(result);    
+}
+
+void JSDOMApplicationCache::setOnchecking(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnCheckingListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
+
+JSValue* JSDOMApplicationCache::onchecking(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onCheckingListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
+}
+
+void JSDOMApplicationCache::setOnerror(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnErrorListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
+
+JSValue* JSDOMApplicationCache::onerror(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onErrorListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
+}
+
+void JSDOMApplicationCache::setOnnoupdate(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnNoUpdateListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
 
+JSValue* JSDOMApplicationCache::onnoupdate(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onNoUpdateListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
 }
 
+void JSDOMApplicationCache::setOndownloading(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnDownloadingListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
+
+JSValue* JSDOMApplicationCache::ondownloading(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onDownloadingListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
+}
+
+void JSDOMApplicationCache::setOnprogress(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnProgressListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
+
+JSValue* JSDOMApplicationCache::onprogress(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onProgressListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
+}
+
+void JSDOMApplicationCache::setOnupdateready(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnUpdateReadyListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
+
+JSValue* JSDOMApplicationCache::onupdateready(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onUpdateReadyListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
+}
+
+void JSDOMApplicationCache::setOncached(ExecState*, JSValue* value)
+{
+    if (Frame* frame = impl()->frame())
+        impl()->setOnCachedListener(toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+}
+
+JSValue* JSDOMApplicationCache::oncached(ExecState*) const
+{
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onCachedListener()))
+        if (JSObject* listenerObj = listener->listenerObj())
+            return listenerObj;
+    return jsNull();
+}
+
+void JSDOMApplicationCache::mark()
+{
+    DOMObject::mark();
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onCheckingListener()))
+        listener->mark();
+        
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onErrorListener()))
+        listener->mark();
+
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onNoUpdateListener()))
+        listener->mark();
+
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onDownloadingListener()))
+        listener->mark();
+
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onProgressListener()))
+        listener->mark();
+
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onUpdateReadyListener()))
+        listener->mark();
+
+    if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onCachedListener()))
+        listener->mark();
+    
+    typedef DOMApplicationCache::EventListenersMap EventListenersMap;
+    typedef DOMApplicationCache::ListenerVector ListenerVector;
+    EventListenersMap& eventListeners = m_impl->eventListeners();
+    for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) {
+        for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) {
+            JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get());
+            listener->mark();
+        }
+    }
+}
+
+} // namespace WebCore
+
 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS)
index 30fa1df..0a445fc 100644 (file)
@@ -65,6 +65,9 @@ void JSDOMWindow::mark()
     markDOMObjectWrapper(impl()->optionalSessionStorage());
     markDOMObjectWrapper(impl()->optionalLocalStorage());
 #endif
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+    markDOMObjectWrapper(impl()->optionalApplicationCache());
+#endif
 }
 
 bool JSDOMWindow::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
index e4b81d6..74e4d33 100644 (file)
@@ -266,6 +266,12 @@ JSValue* toJS(ExecState* exec, EventTarget* target)
         // XMLHttpRequest is always created via JS, so we don't need to use cacheDOMObject() here.
         return ScriptInterpreter::getDOMObject(xhr);
 
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+    if (DOMApplicationCache* cache = target->toDOMApplicationCache())
+        // DOMApplicationCache is always created via JS, so we don't need to use cacheDOMObject() here.
+        return ScriptInterpreter::getDOMObject(cache);
+#endif
+    
     // There are two kinds of EventTargets: EventTargetNode and XMLHttpRequest.
     // If SVG support is enabled, there is also SVGElementInstance.
     ASSERT_NOT_REACHED();
index 0bf604a..c8b0a19 100644 (file)
  */
  
 module offline {
+    interface [Conditional=OFFLINE_WEB_APPLICATIONS,
+               CustomMarkFunction] DOMApplicationCache {
+    
+        // update status
+        const unsigned short UNCACHED = 0;
+        const unsigned short IDLE = 1;
+        const unsigned short CHECKING = 2;
+        const unsigned short DOWNLOADING = 3;
+        const unsigned short UPDATEREADY = 4;
+        readonly attribute unsigned short status;
 
-interface [Conditional=OFFLINE_WEB_APPLICATIONS] DOMApplicationCache {
+        void update()
+            raises(DOMException);
+        void swapCache()
+            raises(DOMException);
+    
+        // dynamic entries
+        readonly attribute unsigned long length;
+        DOMString item(in [IsIndex] unsigned long index)
+            raises(DOMException);
+        [Custom] void add(in DOMString uri)
+            raises(DOMException);
+        [Custom] void remove(in DOMString uri)
+            raises(DOMException);
+    
+        // events
+        attribute [Custom] EventListener onchecking;
+        attribute [Custom] EventListener onerror;
+        attribute [Custom] EventListener onnoupdate;
+        attribute [Custom] EventListener ondownloading;
+        attribute [Custom] EventListener onprogress;
+        attribute [Custom] EventListener onupdateready;
+        attribute [Custom] EventListener oncached;
+    
+        // EventTarget interface
+        [Custom] void addEventListener(in DOMString type, 
+                                       in EventListener listener, 
+                                       in boolean useCapture);
+        [Custom] void removeEventListener(in DOMString type, 
+                                          in EventListener listener, 
+                                          in boolean useCapture);
+        [Custom] boolean dispatchEvent(in Event evt)
+            raises(EventException);
 };
 
 }
index c8d372b..34779a4 100644 (file)
@@ -132,6 +132,9 @@ module window {
                                        in [Optional] boolean authorOnly);
         attribute [Replaceable] double devicePixelRatio;
 
+#if defined(ENABLE_OFFLINE_WEB_APPLICATIONS)
+        readonly attribute DOMApplicationCache applicationCache;
+#endif    
 #if defined(ENABLE_DATABASE)
         Database openDatabase(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize)
             raises(DOMException);