2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "JSDOMApplicationCache.h"
29 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
31 #include "AtomicString.h"
32 #include "DOMApplicationCache.h"
33 #include "DOMWindow.h"
36 #include "FrameLoader.h"
37 #include "JSDOMWindowCustom.h"
39 #include "JSEventListener.h"
45 void JSDOMApplicationCache::mark()
49 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->onchecking()))
52 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->onerror()))
55 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->onnoupdate()))
58 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->ondownloading()))
61 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->onprogress()))
64 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->onupdateready()))
67 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->oncached()))
70 if (JSEventListener* listener = static_cast<JSEventListener*>(m_impl->onobsolete()))
73 typedef DOMApplicationCache::EventListenersMap EventListenersMap;
74 typedef DOMApplicationCache::ListenerVector ListenerVector;
75 EventListenersMap& eventListeners = m_impl->eventListeners();
76 for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) {
77 for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) {
78 JSEventListener* listener = static_cast<JSEventListener*>(vecIter->get());
84 #if ENABLE(APPLICATION_CAHE_DYNAMIC_ENTRIES)
86 JSValuePtr JSDOMApplicationCache::hasItem(ExecState* exec, const ArgList& args)
88 Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
91 const KURL& url = frame->loader()->completeURL(args.at(exec, 0).toString(exec));
94 bool result = impl()->hasItem(url, ec);
95 setDOMException(exec, ec);
96 return jsBoolean(result);
99 JSValuePtr JSDOMApplicationCache::add(ExecState* exec, const ArgList& args)
101 Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
103 return jsUndefined();
104 const KURL& url = frame->loader()->completeURL(args.at(exec, 0).toString(exec));
106 ExceptionCode ec = 0;
107 impl()->add(url, ec);
108 setDOMException(exec, ec);
109 return jsUndefined();
112 JSValuePtr JSDOMApplicationCache::remove(ExecState* exec, const ArgList& args)
114 Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
116 return jsUndefined();
117 const KURL& url = frame->loader()->completeURL(args.at(exec, 0).toString(exec));
119 ExceptionCode ec = 0;
120 impl()->remove(url, ec);
121 setDOMException(exec, ec);
122 return jsUndefined();
127 JSValuePtr JSDOMApplicationCache::addEventListener(ExecState* exec, const ArgList& args)
129 JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
131 return jsUndefined();
132 RefPtr<JSEventListener> listener = globalObject->findOrCreateJSEventListener(exec, args.at(exec, 1));
134 return jsUndefined();
135 impl()->addEventListener(args.at(exec, 0).toString(exec), listener.release(), args.at(exec, 2).toBoolean(exec));
136 return jsUndefined();
139 JSValuePtr JSDOMApplicationCache::removeEventListener(ExecState* exec, const ArgList& args)
141 JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
143 return jsUndefined();
144 JSEventListener* listener = globalObject->findJSEventListener(exec, args.at(exec, 1));
146 return jsUndefined();
147 impl()->removeEventListener(args.at(exec, 0).toString(exec), listener, args.at(exec, 2).toBoolean(exec));
148 return jsUndefined();
151 } // namespace WebCore
153 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS)