Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. All rights reserved. |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 3 | * |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 7 | * |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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 |
| 13 | * distribution. |
| 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. |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 17 | * |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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. |
| 29 | */ |
| 30 | |
| 31 | #ifndef ApplicationCacheHost_h |
| 32 | #define ApplicationCacheHost_h |
| 33 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 34 | #include "weborigin/KURL.h" |
| 35 | #include "wtf/Deque.h" |
| 36 | #include "wtf/OwnPtr.h" |
| 37 | #include "wtf/PassRefPtr.h" |
| 38 | #include "wtf/RefPtr.h" |
| 39 | #include "wtf/Vector.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 40 | |
| 41 | namespace WebCore { |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 42 | class ApplicationCache; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 43 | class DocumentLoader; |
| 44 | class Frame; |
| 45 | class ResourceLoader; |
| 46 | class ResourceError; |
| 47 | class ResourceRequest; |
| 48 | class ResourceResponse; |
| 49 | class SubstituteData; |
| 50 | class ApplicationCacheHostInternal; |
| 51 | |
| 52 | class ApplicationCacheHost { |
| 53 | WTF_MAKE_NONCOPYABLE(ApplicationCacheHost); WTF_MAKE_FAST_ALLOCATED; |
| 54 | public: |
| 55 | // The Status numeric values are specified in the HTML5 spec. |
| 56 | enum Status { |
| 57 | UNCACHED = 0, |
| 58 | IDLE = 1, |
| 59 | CHECKING = 2, |
| 60 | DOWNLOADING = 3, |
| 61 | UPDATEREADY = 4, |
| 62 | OBSOLETE = 5 |
| 63 | }; |
| 64 | |
| 65 | enum EventID { |
| 66 | CHECKING_EVENT = 0, |
| 67 | ERROR_EVENT, |
| 68 | NOUPDATE_EVENT, |
| 69 | DOWNLOADING_EVENT, |
| 70 | PROGRESS_EVENT, |
| 71 | UPDATEREADY_EVENT, |
| 72 | CACHED_EVENT, |
| 73 | OBSOLETE_EVENT // Must remain the last value, this is used to size arrays. |
| 74 | }; |
| 75 | |
| 76 | struct CacheInfo { |
| 77 | CacheInfo(const KURL& manifest, double creationTime, double updateTime, long long size) |
| 78 | : m_manifest(manifest) |
| 79 | , m_creationTime(creationTime) |
| 80 | , m_updateTime(updateTime) |
| 81 | , m_size(size) { } |
| 82 | KURL m_manifest; |
| 83 | double m_creationTime; |
| 84 | double m_updateTime; |
| 85 | long long m_size; |
| 86 | }; |
| 87 | |
| 88 | struct ResourceInfo { |
| 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) |
| 96 | , m_size(size) { } |
| 97 | KURL m_resource; |
| 98 | bool m_isMaster; |
| 99 | bool m_isManifest; |
| 100 | bool m_isFallback; |
| 101 | bool m_isForeign; |
| 102 | bool m_isExplicit; |
| 103 | long long m_size; |
| 104 | }; |
| 105 | |
| 106 | typedef Vector<ResourceInfo> ResourceInfoList; |
| 107 | |
| 108 | ApplicationCacheHost(DocumentLoader*); |
| 109 | ~ApplicationCacheHost(); |
| 110 | |
| 111 | void selectCacheWithoutManifest(); |
| 112 | void selectCacheWithManifest(const KURL& manifestURL); |
| 113 | |
| 114 | void willStartLoadingMainResource(ResourceRequest&); |
| 115 | void didReceiveResponseForMainResource(const ResourceResponse&); |
| 116 | void mainResourceDataReceived(const char* data, int length); |
| 117 | void finishedLoadingMainResource(); |
| 118 | void failedLoadingMainResource(); |
| 119 | |
| 120 | void willStartLoadingResource(ResourceRequest&); |
| 121 | void willStartLoadingSynchronously(ResourceRequest&); |
| 122 | |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 123 | Status status() const; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 124 | bool update(); |
| 125 | bool swapCache(); |
| 126 | void abort(); |
| 127 | |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 128 | void setApplicationCache(ApplicationCache*); |
| 129 | void notifyApplicationCache(EventID, int progressTotal, int progressDone); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 130 | |
| 131 | void stopDeferringEvents(); // Also raises the events that have been queued up. |
| 132 | |
| 133 | void fillResourceList(ResourceInfoList*); |
| 134 | CacheInfo applicationCacheInfo(); |
| 135 | |
| 136 | private: |
| 137 | bool isApplicationCacheEnabled(); |
| 138 | DocumentLoader* documentLoader() const { return m_documentLoader; } |
| 139 | |
| 140 | struct DeferredEvent { |
| 141 | EventID eventID; |
| 142 | int progressTotal; |
| 143 | int progressDone; |
| 144 | DeferredEvent(EventID id, int total, int done) : eventID(id), progressTotal(total), progressDone(done) { } |
| 145 | }; |
| 146 | |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 147 | ApplicationCache* m_domApplicationCache; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 148 | DocumentLoader* m_documentLoader; |
| 149 | bool m_defersEvents; // Events are deferred until after document onload. |
| 150 | Vector<DeferredEvent> m_deferredEvents; |
| 151 | |
| 152 | void dispatchDOMEvent(EventID, int progressTotal, int progressDone); |
| 153 | |
| 154 | friend class ApplicationCacheHostInternal; |
| 155 | OwnPtr<ApplicationCacheHostInternal> m_internal; |
| 156 | }; |
| 157 | |
| 158 | } // namespace WebCore |
| 159 | |
| 160 | #endif // ApplicationCacheHost_h |