OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2009, Google 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 are |
| 6 * met: |
| 7 * |
| 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. |
| 17 * |
| 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 ApplicationCacheFrontend_h |
| 32 #define ApplicationCacheFrontend_h |
| 33 |
| 34 #if ENABLE(APPLICATION_CACHE) |
| 35 |
| 36 #include "ApplicationCacheCommon.h" |
| 37 #include "KURL.h" |
| 38 #include <wtf/Threading.h> |
| 39 |
| 40 namespace WebCore { |
| 41 |
| 42 class ApplicationCacheBridge; |
| 43 class ApplicationCacheBridgeClientImpl; |
| 44 class DOMApplicationCache; |
| 45 class Frame; |
| 46 class ResourceRequest; |
| 47 |
| 48 // Each frame and worker has an ApplicationCacheFrontend which serves as a |
| 49 // facade to the actual implmentation which may be running in another proces
s. |
| 50 // FIXME: integrate with the inspector |
| 51 // FIXME: integrate with workers |
| 52 class ApplicationCacheFrontend { |
| 53 public: |
| 54 ApplicationCacheFrontend(); |
| 55 |
| 56 // Deleted upon frame destruction. |
| 57 ~ApplicationCacheFrontend(); |
| 58 |
| 59 // Returns the appcache contextID for this instance, each frame is uniqu
ely |
| 60 // identified by this ID. |
| 61 const GlobalApplicationCacheContextID& contextID() const { return m_cont
extID; } |
| 62 |
| 63 // Returns the appcache contextType for this instance |
| 64 ApplicationCacheContextType contextType() const { return m_contextType;
} |
| 65 |
| 66 // Called during frame creation. Should only be called once. |
| 67 void initializeForFrame(Frame* frame); |
| 68 |
| 69 // Called during frame navigation when a new document is committed. |
| 70 void selectInitialCache(const KURL& documentURL, |
| 71 ApplicationCacheID cacheDocumentWasLoadedFrom); |
| 72 |
| 73 // Called after parsing of the HTML element is complete, and there was n
o |
| 74 // manifest attribute. |
| 75 void selectCacheWithoutManifest(const KURL& documentURL, |
| 76 ApplicationCacheID cacheDocumentWasLoade
dFrom); |
| 77 |
| 78 // Called after parsing of the HTML element is complete, and there was a |
| 79 // manifest attribute. Returns false if the the navigation should be res
tarted, |
| 80 // this occurs if a 'foriegn' resource was loaded from the cache. |
| 81 bool selectCacheWithManifest(const KURL& documentURL, |
| 82 ApplicationCacheID cacheDocumentWasLoadedFr
om, |
| 83 const KURL& manifestURLofCacheDocumentWasLo
adedFrom, |
| 84 const KURL& manifestURL); |
| 85 |
| 86 // Called by FrameLoader when preparing a resource request associated wi
th this context. |
| 87 void addExtraFieldsToRequest(ResourceRequest& request, bool mainResource
); |
| 88 |
| 89 // Called by FrameLoader when deciding whether the contents are eligible
for the page cache. |
| 90 bool canCacheCurrentDocumentInPageCache() const; |
| 91 |
| 92 // Support for the scriptable interface defined by DOMApplicatoinCache.i
dl |
| 93 ApplicationCacheStatus status() const; |
| 94 bool update(); |
| 95 bool swapCache(); |
| 96 void setDOMApplicationCache(DOMApplicationCache* client) |
| 97 { |
| 98 ASSERT(!m_DOMApplicationCache || !client); |
| 99 ASSERT(isInitialized()); |
| 100 m_DOMApplicationCache = client; |
| 101 } |
| 102 |
| 103 protected: |
| 104 // methods for use by the bridge client |
| 105 friend ApplicationCacheBridgeClientImpl; |
| 106 |
| 107 // Retrieve the frontend object for a contextID. It is a programming err
or |
| 108 // to retrieve the object on the wrong thread. |
| 109 static ApplicationCacheFrontend* fromContextID(const GlobalApplicationCa
cheContextID &contextID); |
| 110 |
| 111 // Used by the bridge to prevent sending notification related to a previ
ously selected cache |
| 112 int cacheSequenceNumber() { return m_cacheSequenceNumber; } |
| 113 |
| 114 // Called by the backend proxy to notify the frontend of happenings to t
he underlying |
| 115 // appcache associated with this context. |
| 116 void notifySelectComplete(ApplicationCacheStatus status); |
| 117 void notifyStatusChanged(ApplicationCacheStatus status); |
| 118 void notifyEventListener(ApplicationCacheEventType eventType); |
| 119 |
| 120 private: |
| 121 void initialize(ApplicationCacheContextType contextType, |
| 122 const GlobalApplicationCacheContextID& parentContextID); |
| 123 |
| 124 bool isInitialized() const { return m_contextID != GlobalApplicationCach
eContextID::none(); } |
| 125 int prepareForSelectCall(); |
| 126 |
| 127 static void addToMap(ApplicationCacheFrontend* frontend); |
| 128 static void removeFromMap(ApplicationCacheFrontend* frontend); |
| 129 |
| 130 // System wide unique id for the context. |
| 131 GlobalApplicationCacheContextID m_contextID; |
| 132 |
| 133 // The type of context. |
| 134 ApplicationCacheContextType m_contextType; |
| 135 |
| 136 // The DOM object thru which we surface events to script. |
| 137 DOMApplicationCache* m_DOMApplicationCache; |
| 138 |
| 139 bool m_canCacheInPageCache; |
| 140 bool m_isSelectInProgress; |
| 141 int m_cacheSequenceNumber; |
| 142 |
| 143 // We cache this value to avoid round trips to the backend when the |
| 144 // status method is called. |
| 145 mutable bool m_hasCachedStatus; |
| 146 mutable ApplicationCacheStatus m_cachedStatus; |
| 147 |
| 148 // Our bridge to the backend. |
| 149 ApplicationCacheBridge* m_bridge; |
| 150 }; |
| 151 |
| 152 } // namespace WebCore |
| 153 |
| 154 #endif // ENABLE(APPLICATION_CACHE) |
| 155 #endif // ApplicationCacheFrontend_h |
OLD | NEW |