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 #include "platform/weborigin/KURL.h"
35 #include "public/platform/WebApplicationCacheHostClient.h"
36 #include "wtf/Deque.h"
37 #include "wtf/OwnPtr.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefPtr.h"
40 #include "wtf/Vector.h"
43 class ApplicationCache;
48 class ResourceRequest;
49 class ResourceResponse;
52 class ApplicationCacheHost : public blink::WebApplicationCacheHostClient {
53 WTF_MAKE_NONCOPYABLE(ApplicationCacheHost);
55 // The Status numeric values are specified in the HTML5 spec.
73 OBSOLETE_EVENT // Must remain the last value, this is used to size arrays.
77 CacheInfo(const KURL& manifest, double creationTime, double updateTime, long long size)
78 : m_manifest(manifest)
79 , m_creationTime(creationTime)
80 , m_updateTime(updateTime)
83 double m_creationTime;
89 ResourceInfo(const KURL& resource, bool isMaster, bool isManifest, bool isFallback, bool isForeign, bool isExplicit, long long size)
90 : m_resource(resource)
91 , m_isMaster(isMaster)
92 , m_isManifest(isManifest)
93 , m_isFallback(isFallback)
94 , m_isForeign(isForeign)
95 , m_isExplicit(isExplicit)
106 typedef Vector<ResourceInfo> ResourceInfoList;
108 explicit ApplicationCacheHost(DocumentLoader*);
109 virtual ~ApplicationCacheHost();
111 void selectCacheWithoutManifest();
112 void selectCacheWithManifest(const KURL& manifestURL);
114 void willStartLoadingMainResource(ResourceRequest&);
115 void didReceiveResponseForMainResource(const ResourceResponse&);
116 void mainResourceDataReceived(const char* data, int length);
117 void finishedLoadingMainResource();
118 void failedLoadingMainResource();
120 void willStartLoadingResource(ResourceRequest&);
122 Status status() const;
127 void setApplicationCache(ApplicationCache*);
128 void notifyApplicationCache(EventID, int progressTotal, int progressDone, blink::WebApplicationCacheHost::ErrorReason, const String& errorURL, int errorStatus, const String& errorMessage);
130 void stopDeferringEvents(); // Also raises the events that have been queued up.
132 void fillResourceList(ResourceInfoList*);
133 CacheInfo applicationCacheInfo();
136 // WebApplicationCacheHostClient implementation
137 virtual void didChangeCacheAssociation() OVERRIDE FINAL;
138 virtual void notifyEventListener(blink::WebApplicationCacheHost::EventID) OVERRIDE FINAL;
139 virtual void notifyProgressEventListener(const blink::WebURL&, int progressTotal, int progressDone) OVERRIDE FINAL;
140 virtual void notifyErrorEventListener(blink::WebApplicationCacheHost::ErrorReason, const blink::WebURL&, int status, const blink::WebString& message) OVERRIDE FINAL;
142 bool isApplicationCacheEnabled();
143 DocumentLoader* documentLoader() const { return m_documentLoader; }
145 struct DeferredEvent {
149 blink::WebApplicationCacheHost::ErrorReason errorReason;
153 DeferredEvent(EventID id, int progressTotal, int progressDone, blink::WebApplicationCacheHost::ErrorReason errorReason, const String& errorURL, int errorStatus, const String& errorMessage)
155 , progressTotal(progressTotal)
156 , progressDone(progressDone)
157 , errorReason(errorReason)
159 , errorStatus(errorStatus)
160 , errorMessage(errorMessage)
165 ApplicationCache* m_domApplicationCache;
166 DocumentLoader* m_documentLoader;
167 bool m_defersEvents; // Events are deferred until after document onload.
168 Vector<DeferredEvent> m_deferredEvents;
170 void dispatchDOMEvent(EventID, int progressTotal, int progressDone, blink::WebApplicationCacheHost::ErrorReason, const String& errorURL, int errorStatus, const String& errorMessage);
172 OwnPtr<blink::WebApplicationCacheHost> m_host;
177 #endif // ApplicationCacheHost_h