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 #include "config.h" | |
32 #include "ApplicationCacheHost.h" | |
33 | |
34 #if ENABLE(OFFLINE_WEB_APPLICATIONS) | |
35 | |
36 #include "DocumentLoader.h" | |
37 #include "DOMApplicationCache.h" | |
38 #include "Frame.h" | |
39 #include "Settings.h" | |
40 #include "WebApplicationCacheHost.h" | |
41 #include "WebApplicationCacheHostClient.h" | |
42 #include "WebKit.h" | |
43 #include "WebKitClient.h" | |
44 #include "WebURL.h" | |
45 #include "WebURLError.h" | |
46 #include "WebURLResponse.h" | |
47 #include "WrappedResourceRequest.h" | |
48 #include "WrappedResourceResponse.h" | |
49 | |
50 using namespace WebKit; | |
51 | |
52 namespace WebCore { | |
53 | |
54 // ApplicationCacheHostInternal ----------------------------------------------- | |
55 | |
56 class ApplicationCacheHostInternal : public WebApplicationCacheHostClient { | |
57 public: | |
58 ApplicationCacheHostInternal(ApplicationCacheHost* host) | |
59 : m_innerHost(host) | |
60 { | |
61 m_outerHost.set(WebKit::webKitClient()->createApplicationCacheHost(this)); | |
62 } | |
63 | |
64 virtual void notifyEventListener(WebApplicationCacheHost::EventID eventID) | |
65 { | |
66 m_innerHost->notifyDOMApplicationCache( | |
67 static_cast<ApplicationCacheHost::EventID>(eventID)); | |
68 } | |
69 | |
70 ApplicationCacheHost* m_innerHost; | |
71 OwnPtr<WebApplicationCacheHost> m_outerHost; | |
72 }; | |
73 | |
74 // ApplicationCacheHost ------------------------------------------------------- | |
75 // We provide a custom implementation of this class that calls out to the | |
76 // embedding application instead of using WebCore's built in appcache system. | |
77 // This file replaces webcore/appcache/ApplicationCacheHost.cpp in our build. | |
78 | |
79 ApplicationCacheHost::ApplicationCacheHost(DocumentLoader* documentLoader) | |
80 : m_domApplicationCache(0) | |
81 , m_documentLoader(documentLoader) | |
82 { | |
83 ASSERT(m_documentLoader); | |
84 } | |
85 | |
86 ApplicationCacheHost::~ApplicationCacheHost() | |
87 { | |
88 } | |
89 | |
90 void ApplicationCacheHost::maybeLoadMainResource(ResourceRequest& request, SubstituteData&) | |
91 { | |
92 // We defer creating the outer host object to avoid spurious creation/destruction | |
93 // around creating empty documents. At this point, we're initiating a main resource | |
94 // load for the document, so its for real. | |
95 | |
96 if (!isApplicationCacheEnabled()) | |
97 return; | |
98 | |
99 m_internal.set(new ApplicationCacheHostInternal(this)); | |
100 if (m_internal->m_outerHost) { | |
101 WrappedResourceRequest wrapped(request); | |
102 m_internal->m_outerHost->willStartMainResourceRequest(wrapped); | |
103 } else | |
104 m_internal.clear(); | |
105 | |
106 // NOTE: The semantics of this method, and others in this interface, are subtly different | |
107 // than the method names would suggest. For example, in this method never returns an appcached | |
108 // response in the SubstituteData out argument, instead we return the appcached response thru | |
109 // the usual resource loading pipeline. | |
110 } | |
111 | |
112 void ApplicationCacheHost::selectCacheWithoutManifest() | |
113 { | |
114 if (m_internal) | |
115 m_internal->m_outerHost->selectCacheWithoutManifest(); | |
116 } | |
117 | |
118 void ApplicationCacheHost::selectCacheWithManifest(const KURL& manifestURL) | |
119 { | |
120 if (m_internal) { | |
121 if (!m_internal->m_outerHost->selectCacheWithManifest(manifestURL)) { | |
122 // It's a foreign entry, restart the current navigation from the top | |
123 // of the navigation algorithm. The navigation will not result in the | |
124 // same resource being loaded, because "foreign" entries are never picked | |
125 // during navigation. | |
126 // see WebCore::ApplicationCacheGroup::selectCache() | |
127 const KURL& docURL = m_documentLoader->frame()->document()->url(); | |
128 String referrer = m_documentLoader->frameLoader()->referrer(); | |
129 m_documentLoader->frame()->redirectScheduler()->scheduleLocationChange(docURL, referrer); | |
130 } | |
131 } | |
132 } | |
133 | |
134 bool ApplicationCacheHost::maybeLoadFallbackForMainResponse(const ResourceRequest&, const ResourceResponse& response) | |
135 { | |
136 if (m_internal) { | |
137 WrappedResourceResponse wrapped(response); | |
138 m_internal->m_outerHost->didReceiveResponseForMainResource(wrapped); | |
139 } | |
140 return false; | |
141 } | |
142 | |
143 bool ApplicationCacheHost::maybeLoadFallbackForMainError(const ResourceRequest&, const ResourceError& error) | |
144 { | |
145 // N/A to the chromium port | |
146 return false; | |
147 } | |
148 | |
149 void ApplicationCacheHost::mainResourceDataReceived(const char* data, int length, long long, bool) | |
150 { | |
151 if (m_internal) | |
152 m_internal->m_outerHost->didReceiveDataForMainResource(data, length); | |
153 } | |
154 | |
155 void ApplicationCacheHost::failedLoadingMainResource() | |
156 { | |
157 if (m_internal) | |
158 m_internal->m_outerHost->didFinishLoadingMainResource(false); | |
159 } | |
160 | |
161 void ApplicationCacheHost::finishedLoadingMainResource() | |
162 { | |
163 if (m_internal) | |
164 m_internal->m_outerHost->didFinishLoadingMainResource(true); | |
165 } | |
166 | |
167 bool ApplicationCacheHost::maybeLoadResource(ResourceLoader*, ResourceRequest& request, const KURL&) | |
168 { | |
169 // FIXME: look into the purpose of the unused KURL& originalURL parameter | |
170 if (m_internal) { | |
171 WrappedResourceRequest wrapped(request); | |
172 m_internal->m_outerHost->willStartSubResourceRequest(wrapped); | |
173 } | |
174 return false; | |
175 } | |
176 | |
177 bool ApplicationCacheHost::maybeLoadFallbackForRedirect(ResourceLoader*, ResourceRequest&, const ResourceResponse&) | |
178 { | |
179 // N/A to the chromium port | |
180 return false; | |
181 } | |
182 | |
183 bool ApplicationCacheHost::maybeLoadFallbackForResponse(ResourceLoader*, const ResourceResponse&) | |
184 { | |
185 // N/A to the chromium port | |
186 return false; | |
187 } | |
188 | |
189 bool ApplicationCacheHost::maybeLoadFallbackForError(ResourceLoader*, const ResourceError&) | |
190 { | |
191 // N/A to the chromium port | |
192 return false; | |
193 } | |
194 | |
195 bool ApplicationCacheHost::maybeLoadSynchronously(ResourceRequest& request, ResourceError&, ResourceResponse&, Vector<char>&) | |
196 { | |
197 if (m_internal) { | |
198 WrappedResourceRequest wrapped(request); | |
199 m_internal->m_outerHost->willStartSubResourceRequest(wrapped); | |
200 } | |
201 return false; | |
202 } | |
203 | |
204 void ApplicationCacheHost::maybeLoadFallbackSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>&) | |
205 { | |
206 // N/A to the chromium port | |
207 } | |
208 | |
209 bool ApplicationCacheHost::canCacheInPageCache() const | |
210 { | |
211 // N/A to the chromium port which doesn't use the page cache. | |
212 return false; | |
213 } | |
214 | |
215 void ApplicationCacheHost::setDOMApplicationCache(DOMApplicationCache* domApplicationCache) | |
216 { | |
217 ASSERT(!m_domApplicationCache || !domApplicationCache); | |
218 m_domApplicationCache = domApplicationCache; | |
219 } | |
220 | |
221 void ApplicationCacheHost::notifyDOMApplicationCache(EventID id) | |
222 { | |
223 if (m_domApplicationCache) { | |
224 ExceptionCode ec = 0; | |
225 m_domApplicationCache->dispatchEvent( | |
226 Event::create(DOMApplicationCache::toEventType(id), false, false), | |
227 ec); | |
228 ASSERT(!ec); | |
229 } | |
230 } | |
231 | |
232 ApplicationCacheHost::Status ApplicationCacheHost::status() const | |
233 { | |
234 return m_internal ? static_cast<Status>(m_internal->m_outerHost->status()) : UNCACHED; | |
235 } | |
236 | |
237 bool ApplicationCacheHost::update() | |
238 { | |
239 return m_internal ? m_internal->m_outerHost->startUpdate() : false; | |
240 } | |
241 | |
242 bool ApplicationCacheHost::swapCache() | |
243 { | |
244 return m_internal ? m_internal->m_outerHost->swapCache() : false; | |
245 } | |
246 | |
247 bool ApplicationCacheHost::isApplicationCacheEnabled() | |
248 { | |
249 ASSERT(m_documentLoader->frame()); | |
250 return m_documentLoader->frame()->settings() | |
251 && m_documentLoader->frame()->settings()->offlineWebApplicationCacheEnabled(); | |
252 } | |
253 | |
254 } // namespace WebCore | |
255 | |
256 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS) | |
OLD | NEW |