Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: loader/appcache2/ApplicationCacheFrontend.cpp

Issue 113554: For local review prior to sending to webkit (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/WebCore/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « loader/appcache2/ApplicationCacheFrontend.h ('k') | loader/appcache2/DOMApplicationCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 #include "config.h"
32 #include "ApplicationCacheFrontend.h"
33
34 #if ENABLE(APPLICATION_CACHE)
35
36 #include "ApplicationCacheBridge.h"
37 #include "DOMApplicationCache.h"
38 #include "Frame.h"
39 #include "ResourceRequest.h"
40 #include <wtf/HashMap.h>
41 #include <wtf/StdLibExtras.h>
42 #include <wtf/Threading.h>
43
44 namespace WebCore {
45
46 // We keep a collection of all frontend instances for lookup by contextID.
47
48 typedef HashMap<int, ApplicationCacheFrontend*> FrontendsMap;
49
50 static FrontendsMap& frontends()
51 {
52 DEFINE_STATIC_LOCAL(FrontendsMap, staticFrontends, ());
53 return staticFrontends;
54 }
55
56
57 // static
58 void ApplicationCacheFrontend::addToMap(ApplicationCacheFrontend* frontend)
59 {
60 frontends().add(frontend->contextID().m_contextID, frontend);
61 }
62
63 // static
64 void ApplicationCacheFrontend::removeFromMap(ApplicationCacheFrontend* frontend)
65 {
66 frontends().remove(frontend->contextID().m_contextID);
67 }
68
69 // static
70 ApplicationCacheFrontend* ApplicationCacheFrontend::fromContextID(const GlobalAp plicationCacheContextID &contextID)
71 {
72 ApplicationCacheFrontend* frontend = frontends().get(contextID.m_contextID);
73 return frontend;
74 }
75
76 ApplicationCacheFrontend::ApplicationCacheFrontend()
77 : m_contextType(MainFrameContext)
78 , m_DOMApplicationCache(0)
79 , m_canCacheInPageCache(false)
80 , m_isSelectInProgress(false)
81 , m_cacheSequenceNumber(0)
82 , m_hasCachedStatus(false)
83 , m_cachedStatus(APPCACHE_UNCACHED)
84 , m_bridge(ApplicationCacheBridge::instance())
85 {
86 ASSERT(m_bridge);
87 }
88
89 ApplicationCacheFrontend::~ApplicationCacheFrontend()
90 {
91 if (isInitialized()) {
92 m_bridge->uninitializeContextAsync(contextID());
93 removeFromMap(this);
94 }
95 }
96
97 void ApplicationCacheFrontend::initializeForFrame(Frame* frame)
98 {
99 ASSERT(frame);
100 ApplicationCacheContextType contextType = MainFrameContext;
101 GlobalApplicationCacheContextID parentContextID = GlobalApplicationCacheCont extID::none();
102 if (Frame* parentFrame = frame->parentFrame()) {
103 contextType = SubFrameContext;
104 parentContextID = parentFrame->loader()->appcacheFrontend()->contextID() ;
105 }
106 initialize(contextType, parentContextID);
107 }
108
109 void ApplicationCacheFrontend::initialize(ApplicationCacheContextType contextTyp e,
110 const GlobalApplicationCacheContextID& parentContextID)
111 {
112 ASSERT(!isInitialized());
113 DEFINE_STATIC_LOCAL(int, nextID, (1));
114 // FIXME: set the processID data member of GlobalApplicationCacheContextID
115 m_contextID = GlobalApplicationCacheContextID(nextID++, 0);
116 m_contextType = contextType;
117 addToMap(this);
118 m_bridge->initializeContextAsync(contextID(), contextType, parentContextID);
119 }
120
121 int ApplicationCacheFrontend::prepareForSelectCall()
122 {
123 m_isSelectInProgress = true;
124 m_hasCachedStatus = false;
125 return ++m_cacheSequenceNumber;
126 }
127
128 void ApplicationCacheFrontend::selectInitialCache(const KURL& documentURL,
129 ApplicationCacheID cacheDocumentWasLoadedFrom)
130 {
131 if (!isInitialized())
132 return;
133 m_canCacheInPageCache = cacheDocumentWasLoadedFrom == NoApplicationCacheID;
134 m_bridge->selectInitialCacheAsync(contextID(),
135 prepareForSelectCall(),
136 documentURL,
137 cacheDocumentWasLoadedFrom);
138 }
139
140 void ApplicationCacheFrontend::selectCacheWithoutManifest(
141 const KURL& documentURL,
142 ApplicationCacheID cacheDocumentWasLoadedFrom )
143 {
144 if (!isInitialized())
145 return;
146 m_canCacheInPageCache = cacheDocumentWasLoadedFrom == NoApplicationCacheID;
147 m_bridge->selectCacheWithoutManifestAsync(contextID(),
148 prepareForSelectCall(),
149 documentURL,
150 cacheDocumentWasLoadedFrom);
151 }
152
153 bool ApplicationCacheFrontend::selectCacheWithManifest(
154 const KURL& documentURL,
155 ApplicationCacheID cacheDocumentWasLoadedFrom ,
156 const KURL& manifestURLofCacheDocumentWasLoad edFrom,
157 const KURL& manifestURL)
158 {
159 if (!isInitialized())
160 return true;
161
162 m_canCacheInPageCache = false;
163 m_bridge->selectCacheWithManifestAsync(contextID(),
164 prepareForSelectCall(),
165 documentURL,
166 cacheDocumentWasLoadedFrom,
167 manifestURLofCacheDocumentWasLoadedFr om,
168 manifestURL);
169
170 // Check for a foreign entriy and restart the current navigation if detected ,
171 // the foreign entry will not be picked up on reload.
172 if ((cacheDocumentWasLoadedFrom != NoApplicationCacheID)
173 && (manifestURL != manifestURLofCacheDocumentWasLoadedFrom))
174 return false;
175
176 return true;
177 }
178
179 void ApplicationCacheFrontend::addExtraFieldsToRequest(ResourceRequest& request, bool mainResource)
180 {
181 ASSERT(isInitialized());
182 request.setApplicationCacheContextID(contextID());
183 }
184
185 bool ApplicationCacheFrontend::canCacheCurrentDocumentInPageCache() const
186 {
187 return m_canCacheInPageCache;
188 }
189
190 ApplicationCacheStatus ApplicationCacheFrontend::status() const
191 {
192 ASSERT(isInitialized());
193 if (!m_hasCachedStatus) {
194 ASSERT(m_isSelectInProgress);
195 m_cachedStatus = m_bridge->status(contextID());
196 m_hasCachedStatus = true;
197 }
198 return m_cachedStatus;
199 }
200
201 bool ApplicationCacheFrontend::update()
202 {
203 ASSERT(isInitialized());
204 return m_bridge->startUpdate(contextID());
205 }
206
207 bool ApplicationCacheFrontend::swapCache()
208 {
209 ASSERT(isInitialized());
210 return m_bridge->swapCache(contextID());
211 }
212
213 void ApplicationCacheFrontend::notifySelectComplete(ApplicationCacheStatus statu s)
214 {
215 ASSERT(m_isSelectInProgress);
216 m_isSelectInProgress = false;
217 if (!m_hasCachedStatus) {
218 m_cachedStatus = status;
219 m_hasCachedStatus = true;
220 }
221 }
222
223 void ApplicationCacheFrontend::notifyStatusChanged(ApplicationCacheStatus status )
224 {
225 ASSERT(m_hasCachedStatus);
226 m_cachedStatus = status;
227 }
228
229 void ApplicationCacheFrontend::notifyEventListener(ApplicationCacheEventType eve ntType)
230 {
231 if (!m_isSelectInProgress && m_DOMApplicationCache)
232 m_DOMApplicationCache->callEventListener(eventType);
233 }
234
235 } // namespace WebCore
236
237 #endif // ENABLE(APPLICATION_CACHE)
OLDNEW
« no previous file with comments | « loader/appcache2/ApplicationCacheFrontend.h ('k') | loader/appcache2/DOMApplicationCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698