• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
24  */
25 
26 #ifndef ApplicationCache_h
27 #define ApplicationCache_h
28 
29 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
30 
31 #include "PlatformString.h"
32 #include "StringHash.h"
33 #include <wtf/HashMap.h>
34 #include <wtf/HashSet.h>
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/RefCounted.h>
37 
38 namespace WebCore {
39 
40 class ApplicationCacheGroup;
41 class ApplicationCacheResource;
42 class DocumentLoader;
43 class KURL;
44 
45 struct ResourceRequest;
46 
47 typedef Vector<std::pair<KURL, KURL> > FallbackURLVector;
48 
49 class ApplicationCache : public RefCounted<ApplicationCache> {
50 public:
create()51     static PassRefPtr<ApplicationCache> create() { return adoptRef(new ApplicationCache); }
52     ~ApplicationCache();
53 
54     void addResource(PassRefPtr<ApplicationCacheResource> resource);
55     unsigned removeResource(const String& url);
56 
57     void setManifestResource(PassRefPtr<ApplicationCacheResource> manifest);
manifestResource()58     ApplicationCacheResource* manifestResource() const { return m_manifest; }
59 
60     void setGroup(ApplicationCacheGroup*);
group()61     ApplicationCacheGroup* group() const { return m_group; }
62 
63     bool isComplete() const;
64 
65     ApplicationCacheResource* resourceForRequest(const ResourceRequest&);
66     ApplicationCacheResource* resourceForURL(const String& url);
67 
68     void setOnlineWhitelist(const Vector<KURL>& onlineWhitelist);
onlineWhitelist()69     const Vector<KURL>& onlineWhitelist() const { return m_onlineWhitelist; }
70     bool isURLInOnlineWhitelist(const KURL&); // There is an entry in online whitelist that has the same origin as the resource's URL and that is a prefix match for the resource's URL.
71 
72     void setFallbackURLs(const FallbackURLVector&);
fallbackURLs()73     const FallbackURLVector& fallbackURLs() const { return m_fallbackURLs; }
74     bool urlMatchesFallbackNamespace(const KURL&, KURL* fallbackURL = 0);
75 
76 #ifndef NDEBUG
77     void dump();
78 #endif
79 
80     typedef HashMap<String, RefPtr<ApplicationCacheResource> > ResourceMap;
begin()81     ResourceMap::const_iterator begin() const { return m_resources.begin(); }
end()82     ResourceMap::const_iterator end() const { return m_resources.end(); }
83 
setStorageID(unsigned storageID)84     void setStorageID(unsigned storageID) { m_storageID = storageID; }
storageID()85     unsigned storageID() const { return m_storageID; }
86     void clearStorageID();
87 
88     static bool requestIsHTTPOrHTTPSGet(const ResourceRequest&);
89 
estimatedSizeInStorage()90     int64_t estimatedSizeInStorage() const { return m_estimatedSizeInStorage; }
91 
92 private:
93     ApplicationCache();
94 
95     ApplicationCacheGroup* m_group;
96     ResourceMap m_resources;
97     ApplicationCacheResource* m_manifest;
98 
99     Vector<KURL> m_onlineWhitelist;
100     FallbackURLVector m_fallbackURLs;
101 
102     // The total size of the resources belonging to this Application Cache instance.
103     // This is an estimation of the size this Application Cache occupies in the
104     // database file.
105     int64_t m_estimatedSizeInStorage;
106 
107     unsigned m_storageID;
108 };
109 
110 } // namespace WebCore
111 
112 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS)
113 
114 #endif // ApplicationCache_h
115