OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef DOMApplicationCache_h | 26 #ifndef DOMApplicationCache_h |
27 #define DOMApplicationCache_h | 27 #define DOMApplicationCache_h |
28 | 28 |
29 #if ENABLE(OFFLINE_WEB_APPLICATIONS) | 29 #if ENABLE(APPLICATION_CACHE) |
30 | 30 |
| 31 #include "ApplicationCacheCommon.h" |
| 32 #include "ApplicationCacheFrontend.h" |
31 #include "AtomicStringHash.h" | 33 #include "AtomicStringHash.h" |
32 #include "EventTarget.h" | 34 #include "EventTarget.h" |
33 #include "EventListener.h" | 35 #include "EventListener.h" |
34 #include <wtf/HashMap.h> | 36 #include <wtf/HashMap.h> |
35 #include <wtf/PassRefPtr.h> | 37 #include <wtf/PassRefPtr.h> |
36 #include <wtf/RefCounted.h> | 38 #include <wtf/RefCounted.h> |
37 #include <wtf/Vector.h> | 39 #include <wtf/Vector.h> |
38 | 40 |
39 namespace WebCore { | 41 namespace WebCore { |
40 | 42 |
41 class ApplicationCache; | |
42 class AtomicStringImpl; | 43 class AtomicStringImpl; |
43 class DOMStringList; | 44 class DOMStringList; |
44 class Frame; | 45 class Frame; |
45 class KURL; | 46 class KURL; |
46 class String; | 47 class String; |
47 | 48 |
48 class DOMApplicationCache : public RefCounted<DOMApplicationCache>, public Event
Target { | 49 class DOMApplicationCache : public RefCounted<DOMApplicationCache>, public Event
Target { |
49 public: | 50 public: |
| 51 // FIXME: integrate with workers |
50 static PassRefPtr<DOMApplicationCache> create(Frame* frame) { return adoptRe
f(new DOMApplicationCache(frame)); } | 52 static PassRefPtr<DOMApplicationCache> create(Frame* frame) { return adoptRe
f(new DOMApplicationCache(frame)); } |
51 void disconnectFrame(); | 53 void disconnectFrame(); |
52 | 54 |
53 enum Status { | 55 enum Status { |
54 UNCACHED = 0, | 56 UNCACHED = APPCACHE_UNCACHED, |
55 IDLE = 1, | 57 IDLE = APPCACHE_IDLE, |
56 CHECKING = 2, | 58 CHECKING = APPCACHE_CHECKING, |
57 DOWNLOADING = 3, | 59 DOWNLOADING = APPCACHE_DOWNLOADING, |
58 UPDATEREADY = 4, | 60 UPDATEREADY = APPCACHE_UPDATEREADY, |
59 OBSOLETE = 5 | 61 OBSOLETE = APPCACHE_OBSOLETE |
60 }; | 62 }; |
61 | 63 |
62 unsigned short status() const; | 64 unsigned short status() const; |
63 | |
64 void update(ExceptionCode&); | 65 void update(ExceptionCode&); |
65 void swapCache(ExceptionCode&); | 66 void swapCache(ExceptionCode&); |
66 | |
67 PassRefPtr<DOMStringList> items(); | |
68 bool hasItem(const KURL&, ExceptionCode&); | |
69 void add(const KURL&, ExceptionCode&); | |
70 void remove(const KURL&, ExceptionCode&); | |
71 | 67 |
72 virtual void addEventListener(const AtomicString& eventType, PassRefPtr<Even
tListener>, bool useCapture); | 68 // Event attributes |
73 virtual void removeEventListener(const AtomicString& eventType, EventListene
r*, bool useCapture); | 69 void setAttributeEventListener(ApplicationCacheEventType type, PassRefPtr<Ev
entListener> eventListener) { m_attributeEventListeners[type] = eventListener; } |
| 70 EventListener* getAttributeEventListener(ApplicationCacheEventType type) con
st { return m_attributeEventListeners[type].get(); } |
| 71 void clearAttributeEventListener(ApplicationCacheEventType type) { m_attribu
teEventListeners[type] = 0; } |
| 72 void callEventListener(ApplicationCacheEventType type) { callListener(toEven
tName(type), getAttributeEventListener(type)); } |
| 73 |
| 74 // EventTarget impl |
| 75 virtual void addEventListener(const AtomicString& eventName, PassRefPtr<Even
tListener>, bool useCapture); |
| 76 virtual void removeEventListener(const AtomicString& eventName, EventListene
r*, bool useCapture); |
74 virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); | 77 virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); |
75 | |
76 typedef Vector<RefPtr<EventListener> > ListenerVector; | 78 typedef Vector<RefPtr<EventListener> > ListenerVector; |
77 typedef HashMap<AtomicString, ListenerVector> EventListenersMap; | 79 typedef HashMap<AtomicString, ListenerVector> EventListenersMap; |
78 EventListenersMap& eventListeners() { return m_eventListeners; } | 80 EventListenersMap& eventListeners() { return m_eventListeners; } |
79 | 81 |
80 using RefCounted<DOMApplicationCache>::ref; | 82 using RefCounted<DOMApplicationCache>::ref; |
81 using RefCounted<DOMApplicationCache>::deref; | 83 using RefCounted<DOMApplicationCache>::deref; |
82 | 84 |
83 void setOnchecking(PassRefPtr<EventListener> eventListener) { m_onCheckingLi
stener = eventListener; } | |
84 EventListener* onchecking() const { return m_onCheckingListener.get(); } | |
85 | |
86 void setOnerror(PassRefPtr<EventListener> eventListener) { m_onErrorListener
= eventListener; } | |
87 EventListener* onerror() const { return m_onErrorListener.get(); } | |
88 | |
89 void setOnnoupdate(PassRefPtr<EventListener> eventListener) { m_onNoUpdateLi
stener = eventListener; } | |
90 EventListener* onnoupdate() const { return m_onNoUpdateListener.get(); } | |
91 | |
92 void setOndownloading(PassRefPtr<EventListener> eventListener) { m_onDownloa
dingListener = eventListener; } | |
93 EventListener* ondownloading() const { return m_onDownloadingListener.get();
} | |
94 | |
95 void setOnprogress(PassRefPtr<EventListener> eventListener) { m_onProgressLi
stener = eventListener; } | |
96 EventListener* onprogress() const { return m_onProgressListener.get(); } | |
97 | |
98 void setOnupdateready(PassRefPtr<EventListener> eventListener) { m_onUpdateR
eadyListener = eventListener; } | |
99 EventListener* onupdateready() const { return m_onUpdateReadyListener.get();
} | |
100 | |
101 void setOncached(PassRefPtr<EventListener> eventListener) { m_onCachedListen
er = eventListener; } | |
102 EventListener* oncached() const { return m_onCachedListener.get(); } | |
103 | |
104 void setOnobsolete(PassRefPtr<EventListener> eventListener) { m_onObsoleteLi
stener = eventListener; } | |
105 EventListener* onobsolete() const { return m_onObsoleteListener.get(); } | |
106 | |
107 virtual ScriptExecutionContext* scriptExecutionContext() const; | 85 virtual ScriptExecutionContext* scriptExecutionContext() const; |
108 DOMApplicationCache* toDOMApplicationCache() { return this; } | 86 DOMApplicationCache* toDOMApplicationCache() { return this; } |
109 | 87 |
110 void callCheckingListener(); | 88 // Explicitly named attribute event listener helpers |
111 void callErrorListener(); | 89 void setOnchecking(PassRefPtr<EventListener> listener) { setAttributeEventLi
stener(APPCACHE_CHECKING_EVENT, listener); } |
112 void callNoUpdateListener(); | 90 void setOnerror(PassRefPtr<EventListener> listener) { setAttributeEventListe
ner(APPCACHE_ERROR_EVENT, listener);} |
113 void callDownloadingListener(); | 91 void setOnnoupdate(PassRefPtr<EventListener> listener) { setAttributeEventLi
stener(APPCACHE_NOUPDATE_EVENT, listener); } |
114 void callProgressListener(); | 92 void setOndownloading(PassRefPtr<EventListener> listener) { setAttributeEven
tListener(APPCACHE_DOWNLOADING_EVENT, listener); } |
115 void callUpdateReadyListener(); | 93 void setOnprogress(PassRefPtr<EventListener> listener) { setAttributeEventLi
stener(APPCACHE_PROGRESS_EVENT, listener); } |
116 void callCachedListener(); | 94 void setOnupdateready(PassRefPtr<EventListener> listener) { setAttributeEven
tListener(APPCACHE_UPDATEREADY_EVENT, listener); } |
117 void callObsoleteListener(); | 95 void setOncached(PassRefPtr<EventListener> listener) { setAttributeEventList
ener(APPCACHE_CACHED_EVENT, listener); } |
118 | 96 void setOnobsolete(PassRefPtr<EventListener> listener) { setAttributeEventLi
stener(APPCACHE_OBSOLETE_EVENT, listener); } |
| 97 EventListener* onchecking() const { return getAttributeEventListener(APPCACH
E_CHECKING_EVENT); } |
| 98 EventListener* onerror() const { return getAttributeEventListener(APPCACHE_E
RROR_EVENT); } |
| 99 EventListener* onnoupdate() const { return getAttributeEventListener(APPCACH
E_NOUPDATE_EVENT); } |
| 100 EventListener* ondownloading() const { return getAttributeEventListener(APPC
ACHE_DOWNLOADING_EVENT); } |
| 101 EventListener* onprogress() const { return getAttributeEventListener(APPCACH
E_PROGRESS_EVENT); } |
| 102 EventListener* onupdateready() const { return getAttributeEventListener(APPC
ACHE_UPDATEREADY_EVENT); } |
| 103 EventListener* oncached() const { return getAttributeEventListener(APPCACHE_
CACHED_EVENT); } |
| 104 EventListener* onobsolete() const { return getAttributeEventListener(APPCACH
E_OBSOLETE_EVENT); } |
| 105 void callCheckingListener() { callEventListener(APPCACHE_CHECKING_EVENT); } |
| 106 void callErrorListener() { callEventListener(APPCACHE_ERROR_EVENT); } |
| 107 void callNoUpdateListener() { callEventListener(APPCACHE_NOUPDATE_EVENT); } |
| 108 void callDownloadingListener() { callEventListener(APPCACHE_DOWNLOADING_EVEN
T); } |
| 109 void callProgressListener() { callEventListener(APPCACHE_PROGRESS_EVENT); } |
| 110 void callUpdateReadyListener() { callEventListener(APPCACHE_UPDATEREADY_EVEN
T); } |
| 111 void callCachedListener() { callEventListener(APPCACHE_CACHED_EVENT); } |
| 112 void callObsoleteListener() { callEventListener(APPCACHE_OBSOLETE_EVENT); } |
| 113 |
| 114 static const AtomicString& toEventName(ApplicationCacheEventType eventType); |
| 115 static ApplicationCacheEventType toEventType(const AtomicString& eventName); |
| 116 |
119 private: | 117 private: |
120 DOMApplicationCache(Frame*); | 118 DOMApplicationCache(Frame*); |
| 119 |
121 void callListener(const AtomicString& eventType, EventListener*); | 120 void callListener(const AtomicString& eventType, EventListener*); |
122 | 121 |
123 virtual void refEventTarget() { ref(); } | 122 virtual void refEventTarget() { ref(); } |
124 virtual void derefEventTarget() { deref(); } | 123 virtual void derefEventTarget() { deref(); } |
125 | 124 |
126 ApplicationCache* associatedCache() const; | 125 ApplicationCacheFrontend* appcacheFrontend() const { return m_appcacheFronte
nd; } |
127 bool swapCache(); | 126 bool swapCache(); |
128 | 127 |
129 RefPtr<EventListener> m_onCheckingListener; | 128 RefPtr<EventListener> m_attributeEventListeners[NUMBER_OF_APPCACHE_EVENT_TYP
ES]; |
130 RefPtr<EventListener> m_onErrorListener; | |
131 RefPtr<EventListener> m_onNoUpdateListener; | |
132 RefPtr<EventListener> m_onDownloadingListener; | |
133 RefPtr<EventListener> m_onProgressListener; | |
134 RefPtr<EventListener> m_onUpdateReadyListener; | |
135 RefPtr<EventListener> m_onCachedListener; | |
136 RefPtr<EventListener> m_onObsoleteListener; | |
137 | |
138 EventListenersMap m_eventListeners; | 129 EventListenersMap m_eventListeners; |
139 | 130 |
140 Frame* m_frame; | 131 Frame* m_frame; |
| 132 ApplicationCacheFrontend* m_appcacheFrontend; |
| 133 |
141 }; | 134 }; |
142 | 135 |
143 } // namespace WebCore | 136 } // namespace WebCore |
144 | 137 |
145 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS) | 138 #endif // ENABLE(APPLICATION_CACHE) |
146 | 139 |
147 #endif // DOMApplicationCache_h | 140 #endif // DOMApplicationCache_h |
OLD | NEW |