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/heap/Handle.h"
35 #include "platform/weborigin/KURL.h"
36 #include "public/platform/WebApplicationCacheHostClient.h"
37 #include "wtf/OwnPtr.h"
38 #include "wtf/Vector.h"
41 class ApplicationCache;
43 class ResourceRequest;
44 class ResourceResponse;
46 class ApplicationCacheHost final : public NoBaseWillBeGarbageCollectedFinalized<ApplicationCacheHost>, public WebApplicationCacheHostClient {
47 WTF_MAKE_NONCOPYABLE(ApplicationCacheHost);
49 static PassOwnPtrWillBeRawPtr<ApplicationCacheHost> create(DocumentLoader* loader)
51 return adoptPtrWillBeNoop(new ApplicationCacheHost(loader));
53 virtual ~ApplicationCacheHost();
57 // The Status numeric values are specified in the HTML5 spec.
75 OBSOLETE_EVENT // Must remain the last value, this is used to size arrays.
79 CacheInfo(const KURL& manifest, double creationTime, double updateTime, long long size)
80 : m_manifest(manifest)
81 , m_creationTime(creationTime)
82 , m_updateTime(updateTime)
85 double m_creationTime;
91 ResourceInfo(const KURL& resource, bool isMaster, bool isManifest, bool isFallback, bool isForeign, bool isExplicit, long long size)
92 : m_resource(resource)
93 , m_isMaster(isMaster)
94 , m_isManifest(isManifest)
95 , m_isFallback(isFallback)
96 , m_isForeign(isForeign)
97 , m_isExplicit(isExplicit)
108 typedef Vector<ResourceInfo> ResourceInfoList;
110 void selectCacheWithoutManifest();
111 void selectCacheWithManifest(const KURL& manifestURL);
113 void willStartLoadingMainResource(ResourceRequest&);
114 void didReceiveResponseForMainResource(const ResourceResponse&);
115 void mainResourceDataReceived(const char* data, unsigned length);
116 void finishedLoadingMainResource();
117 void failedLoadingMainResource();
119 void willStartLoadingResource(ResourceRequest&);
121 Status status() const;
126 void setApplicationCache(ApplicationCache*);
127 void notifyApplicationCache(EventID, int progressTotal, int progressDone, WebApplicationCacheHost::ErrorReason, const String& errorURL, int errorStatus, const String& errorMessage);
129 void stopDeferringEvents(); // Also raises the events that have been queued up.
131 void fillResourceList(ResourceInfoList*);
132 CacheInfo applicationCacheInfo();
134 void trace(Visitor*);
137 explicit ApplicationCacheHost(DocumentLoader*);
139 // WebApplicationCacheHostClient implementation
140 virtual void didChangeCacheAssociation() override final;
141 virtual void notifyEventListener(WebApplicationCacheHost::EventID) override final;
142 virtual void notifyProgressEventListener(const WebURL&, int progressTotal, int progressDone) override final;
143 virtual void notifyErrorEventListener(WebApplicationCacheHost::ErrorReason, const WebURL&, int status, const WebString& message) override final;
145 bool isApplicationCacheEnabled();
146 DocumentLoader* documentLoader() const { return m_documentLoader; }
148 struct DeferredEvent {
152 WebApplicationCacheHost::ErrorReason errorReason;
156 DeferredEvent(EventID id, int progressTotal, int progressDone, WebApplicationCacheHost::ErrorReason errorReason, const String& errorURL, int errorStatus, const String& errorMessage)
158 , progressTotal(progressTotal)
159 , progressDone(progressDone)
160 , errorReason(errorReason)
162 , errorStatus(errorStatus)
163 , errorMessage(errorMessage)
168 RawPtrWillBeWeakMember<ApplicationCache> m_domApplicationCache;
169 DocumentLoader* m_documentLoader;
170 bool m_defersEvents; // Events are deferred until after document onload.
171 Vector<DeferredEvent> m_deferredEvents;
173 void dispatchDOMEvent(EventID, int progressTotal, int progressDone, WebApplicationCacheHost::ErrorReason, const String& errorURL, int errorStatus, const String& errorMessage);
175 OwnPtr<WebApplicationCacheHost> m_host;
180 #endif // ApplicationCacheHost_h