2 * Copyright (c) 2009, Google 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 are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef ApplicationCacheHost_h
32 #define ApplicationCacheHost_h
34 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
37 #include <wtf/Deque.h>
38 #include <wtf/OwnPtr.h>
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/RefPtr.h>
41 #include <wtf/Vector.h>
44 class DOMApplicationCache;
49 class ResourceRequest;
50 class ResourceResponse;
52 #if PLATFORM(CHROMIUM)
53 class ApplicationCacheHostInternal;
55 class ApplicationCache;
56 class ApplicationCacheGroup;
57 class ApplicationCacheResource;
58 class ApplicationCacheStorage;
61 class ApplicationCacheHost {
62 WTF_MAKE_NONCOPYABLE(ApplicationCacheHost); WTF_MAKE_FAST_ALLOCATED;
64 // The Status numeric values are specified in the HTML5 spec.
82 OBSOLETE_EVENT // Must remain the last value, this is used to size arrays.
87 CacheInfo(const KURL& manifest, double creationTime, double updateTime, long long size)
88 : m_manifest(manifest)
89 , m_creationTime(creationTime)
90 , m_updateTime(updateTime)
93 double m_creationTime;
99 ResourceInfo(const KURL& resource, bool isMaster, bool isManifest, bool isFallback, bool isForeign, bool isExplicit, long long size)
100 : m_resource(resource)
101 , m_isMaster(isMaster)
102 , m_isManifest(isManifest)
103 , m_isFallback(isFallback)
104 , m_isForeign(isForeign)
105 , m_isExplicit(isExplicit)
116 typedef Vector<ResourceInfo> ResourceInfoList;
119 ApplicationCacheHost(DocumentLoader*);
120 ~ApplicationCacheHost();
122 void selectCacheWithoutManifest();
123 void selectCacheWithManifest(const KURL& manifestURL);
125 void maybeLoadMainResource(ResourceRequest&, SubstituteData&);
126 void maybeLoadMainResourceForRedirect(ResourceRequest&, SubstituteData&);
127 bool maybeLoadFallbackForMainResponse(const ResourceRequest&, const ResourceResponse&);
128 bool maybeLoadFallbackForMainError(const ResourceRequest&, const ResourceError&);
129 void mainResourceDataReceived(const char* data, int length, long long encodedDataLength, bool allAtOnce);
130 void finishedLoadingMainResource();
131 void failedLoadingMainResource();
133 bool maybeLoadResource(ResourceLoader*, ResourceRequest&, const KURL& originalURL);
134 bool maybeLoadFallbackForRedirect(ResourceLoader*, ResourceRequest&, const ResourceResponse&);
135 bool maybeLoadFallbackForResponse(ResourceLoader*, const ResourceResponse&);
136 bool maybeLoadFallbackForError(ResourceLoader*, const ResourceError&);
138 bool maybeLoadSynchronously(ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data);
139 void maybeLoadFallbackSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data);
141 bool canCacheInPageCache() const;
143 Status status() const;
147 void setDOMApplicationCache(DOMApplicationCache*);
148 void notifyDOMApplicationCache(EventID, int progressTotal, int progressDone);
150 void stopLoadingInFrame(Frame*);
152 void stopDeferringEvents(); // Also raises the events that have been queued up.
154 #if ENABLE(INSPECTOR)
155 void fillResourceList(ResourceInfoList*);
156 CacheInfo applicationCacheInfo();
159 #if !PLATFORM(CHROMIUM)
160 bool shouldLoadResourceFromApplicationCache(const ResourceRequest&, ApplicationCacheResource*&);
161 bool getApplicationCacheFallbackResource(const ResourceRequest&, ApplicationCacheResource*&, ApplicationCache* = 0);
165 bool isApplicationCacheEnabled();
166 DocumentLoader* documentLoader() const { return m_documentLoader; }
168 struct DeferredEvent {
172 DeferredEvent(EventID id, int total, int done) : eventID(id), progressTotal(total), progressDone(done) { }
175 DOMApplicationCache* m_domApplicationCache;
176 DocumentLoader* m_documentLoader;
177 bool m_defersEvents; // Events are deferred until after document onload.
178 Vector<DeferredEvent> m_deferredEvents;
180 void dispatchDOMEvent(EventID, int progressTotal, int progressDone);
182 #if PLATFORM(CHROMIUM)
183 friend class ApplicationCacheHostInternal;
184 OwnPtr<ApplicationCacheHostInternal> m_internal;
186 friend class ApplicationCacheGroup;
187 friend class ApplicationCacheStorage;
189 bool scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader*, ApplicationCache* = 0);
190 void setCandidateApplicationCacheGroup(ApplicationCacheGroup* group);
191 ApplicationCacheGroup* candidateApplicationCacheGroup() const { return m_candidateApplicationCacheGroup; }
192 void setApplicationCache(PassRefPtr<ApplicationCache> applicationCache);
193 ApplicationCache* applicationCache() const { return m_applicationCache.get(); }
194 ApplicationCache* mainResourceApplicationCache() const { return m_mainResourceApplicationCache.get(); }
197 // The application cache that the document loader is associated with (if any).
198 RefPtr<ApplicationCache> m_applicationCache;
200 // Before an application cache has finished loading, this will be the candidate application
201 // group that the document loader is associated with.
202 ApplicationCacheGroup* m_candidateApplicationCacheGroup;
204 // This is the application cache the main resource was loaded from (if any).
205 RefPtr<ApplicationCache> m_mainResourceApplicationCache;
209 } // namespace WebCore
211 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS)
212 #endif // ApplicationCacheHost_h