OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ApplicationCacheHost::ApplicationCacheHost(DocumentLoader* documentLoader) | 63 ApplicationCacheHost::ApplicationCacheHost(DocumentLoader* documentLoader) |
64 : m_domApplicationCache(nullptr) | 64 : m_domApplicationCache(nullptr) |
65 , m_documentLoader(documentLoader) | 65 , m_documentLoader(documentLoader) |
66 , m_defersEvents(true) | 66 , m_defersEvents(true) |
67 { | 67 { |
68 ASSERT(m_documentLoader); | 68 ASSERT(m_documentLoader); |
69 } | 69 } |
70 | 70 |
71 ApplicationCacheHost::~ApplicationCacheHost() | 71 ApplicationCacheHost::~ApplicationCacheHost() |
72 { | 72 { |
| 73 // Verify that detachFromDocumentLoader() has been performed already. |
| 74 ASSERT(!m_host); |
73 } | 75 } |
74 | 76 |
75 void ApplicationCacheHost::willStartLoadingMainResource(ResourceRequest& request
) | 77 void ApplicationCacheHost::willStartLoadingMainResource(ResourceRequest& request
) |
76 { | 78 { |
77 // We defer creating the outer host object to avoid spurious creation/destru
ction | 79 // We defer creating the outer host object to avoid spurious creation/destru
ction |
78 // around creating empty documents. At this point, we're initiating a main r
esource | 80 // around creating empty documents. At this point, we're initiating a main r
esource |
79 // load for the document, so its for real. | 81 // load for the document, so its for real. |
80 | 82 |
81 if (!isApplicationCacheEnabled()) | 83 if (!isApplicationCacheEnabled()) |
82 return; | 84 return; |
83 | 85 |
84 ASSERT(m_documentLoader->frame()); | 86 ASSERT(m_documentLoader->frame()); |
85 LocalFrame& frame = *m_documentLoader->frame(); | 87 LocalFrame& frame = *m_documentLoader->frame(); |
86 m_host = frame.loader().client()->createApplicationCacheHost(this); | 88 m_host = frame.loader().client()->createApplicationCacheHost(this); |
87 if (m_host) { | 89 if (!m_host) |
88 WrappedResourceRequest wrapped(request); | 90 return; |
89 | 91 |
90 const WebApplicationCacheHost* spawningHost = 0; | 92 WrappedResourceRequest wrapped(request); |
91 Frame* spawningFrame = frame.tree().parent(); | |
92 if (!spawningFrame || !spawningFrame->isLocalFrame()) | |
93 spawningFrame = frame.loader().opener(); | |
94 if (!spawningFrame || !spawningFrame->isLocalFrame()) | |
95 spawningFrame = &frame; | |
96 if (DocumentLoader* spawningDocLoader = toLocalFrame(spawningFrame)->loa
der().documentLoader()) | |
97 spawningHost = spawningDocLoader->applicationCacheHost() ? spawningD
ocLoader->applicationCacheHost()->m_host.get() : 0; | |
98 | 93 |
99 m_host->willStartMainResourceRequest(wrapped, spawningHost); | 94 const WebApplicationCacheHost* spawningHost = nullptr; |
100 } | 95 Frame* spawningFrame = frame.tree().parent(); |
| 96 if (!spawningFrame || !spawningFrame->isLocalFrame()) |
| 97 spawningFrame = frame.loader().opener(); |
| 98 if (!spawningFrame || !spawningFrame->isLocalFrame()) |
| 99 spawningFrame = &frame; |
| 100 if (DocumentLoader* spawningDocLoader = toLocalFrame(spawningFrame)->loader(
).documentLoader()) |
| 101 spawningHost = spawningDocLoader->applicationCacheHost() ? spawningDocLo
ader->applicationCacheHost()->m_host.get() : nullptr; |
| 102 |
| 103 m_host->willStartMainResourceRequest(wrapped, spawningHost); |
101 | 104 |
102 // NOTE: The semantics of this method, and others in this interface, are sub
tly different | 105 // NOTE: The semantics of this method, and others in this interface, are sub
tly different |
103 // than the method names would suggest. For example, in this method never re
turns an appcached | 106 // than the method names would suggest. For example, in this method never re
turns an appcached |
104 // response in the SubstituteData out argument, instead we return the appcac
hed response thru | 107 // response in the SubstituteData out argument, instead we return the appcac
hed response thru |
105 // the usual resource loading pipeline. | 108 // the usual resource loading pipeline. |
106 } | 109 } |
107 | 110 |
108 void ApplicationCacheHost::selectCacheWithoutManifest() | 111 void ApplicationCacheHost::selectCacheWithoutManifest() |
109 { | 112 { |
110 if (m_host) | 113 if (m_host) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 m_host->willStartSubResourceRequest(wrapped); | 160 m_host->willStartSubResourceRequest(wrapped); |
158 } | 161 } |
159 } | 162 } |
160 | 163 |
161 void ApplicationCacheHost::setApplicationCache(ApplicationCache* domApplicationC
ache) | 164 void ApplicationCacheHost::setApplicationCache(ApplicationCache* domApplicationC
ache) |
162 { | 165 { |
163 ASSERT(!m_domApplicationCache || !domApplicationCache); | 166 ASSERT(!m_domApplicationCache || !domApplicationCache); |
164 m_domApplicationCache = domApplicationCache; | 167 m_domApplicationCache = domApplicationCache; |
165 } | 168 } |
166 | 169 |
167 void ApplicationCacheHost::dispose() | 170 void ApplicationCacheHost::detachFromDocumentLoader() |
168 { | 171 { |
169 // FIXME: Oilpan: remove the dispose step when the owning DocumentLoader | 172 // Detach from the owning DocumentLoader and let go of WebApplicationCacheHo
st. |
170 // becomes a garbage collected object. Until that time, have the | 173 setApplicationCache(nullptr); |
171 // DocumentLoader dispose and disable this ApplicationCacheHost when | |
172 // it is finalized. Releasing the WebApplicationCacheHost is needed | |
173 // to prevent further embedder notifications, which risk accessing an | |
174 // invalid DocumentLoader. | |
175 setApplicationCache(0); | |
176 m_host.clear(); | 174 m_host.clear(); |
177 m_documentLoader = nullptr; | 175 m_documentLoader = nullptr; |
178 } | 176 } |
179 | 177 |
180 void ApplicationCacheHost::notifyApplicationCache(EventID id, int progressTotal,
int progressDone, WebApplicationCacheHost::ErrorReason errorReason, const Strin
g& errorURL, int errorStatus, const String& errorMessage) | 178 void ApplicationCacheHost::notifyApplicationCache(EventID id, int progressTotal,
int progressDone, WebApplicationCacheHost::ErrorReason errorReason, const Strin
g& errorURL, int errorStatus, const String& errorMessage) |
181 { | 179 { |
182 if (id != PROGRESS_EVENT) | 180 if (id != PROGRESS_EVENT) |
183 InspectorInstrumentation::updateApplicationCacheStatus(m_documentLoader-
>frame()); | 181 InspectorInstrumentation::updateApplicationCacheStatus(m_documentLoader-
>frame()); |
184 | 182 |
185 if (m_defersEvents) { | 183 if (m_defersEvents) { |
(...skipping 23 matching lines...) Expand all Loading... |
209 m_host->getResourceList(&webResources); | 207 m_host->getResourceList(&webResources); |
210 for (size_t i = 0; i < webResources.size(); ++i) { | 208 for (size_t i = 0; i < webResources.size(); ++i) { |
211 resources->append(ResourceInfo( | 209 resources->append(ResourceInfo( |
212 webResources[i].url, webResources[i].isMaster, webResources[i].isMan
ifest, webResources[i].isFallback, | 210 webResources[i].url, webResources[i].isMaster, webResources[i].isMan
ifest, webResources[i].isFallback, |
213 webResources[i].isForeign, webResources[i].isExplicit, webResources[
i].size)); | 211 webResources[i].isForeign, webResources[i].isExplicit, webResources[
i].size)); |
214 } | 212 } |
215 } | 213 } |
216 | 214 |
217 void ApplicationCacheHost::stopDeferringEvents() | 215 void ApplicationCacheHost::stopDeferringEvents() |
218 { | 216 { |
219 RefPtr<DocumentLoader> protect(documentLoader()); | 217 RefPtrWillBeRawPtr<DocumentLoader> protect(documentLoader()); |
220 for (unsigned i = 0; i < m_deferredEvents.size(); ++i) { | 218 for (unsigned i = 0; i < m_deferredEvents.size(); ++i) { |
221 const DeferredEvent& deferred = m_deferredEvents[i]; | 219 const DeferredEvent& deferred = m_deferredEvents[i]; |
222 dispatchDOMEvent(deferred.eventID, deferred.progressTotal, deferred.prog
ressDone, deferred.errorReason, deferred.errorURL, deferred.errorStatus, deferre
d.errorMessage); | 220 dispatchDOMEvent(deferred.eventID, deferred.progressTotal, deferred.prog
ressDone, deferred.errorReason, deferred.errorURL, deferred.errorStatus, deferre
d.errorMessage); |
223 } | 221 } |
224 m_deferredEvents.clear(); | 222 m_deferredEvents.clear(); |
225 m_defersEvents = false; | 223 m_defersEvents = false; |
226 } | 224 } |
227 | 225 |
228 void ApplicationCacheHost::dispatchDOMEvent(EventID id, int progressTotal, int p
rogressDone, WebApplicationCacheHost::ErrorReason errorReason, const String& err
orURL, int errorStatus, const String& errorMessage) | 226 void ApplicationCacheHost::dispatchDOMEvent(EventID id, int progressTotal, int p
rogressDone, WebApplicationCacheHost::ErrorReason errorReason, const String& err
orURL, int errorStatus, const String& errorMessage) |
229 { | 227 { |
230 if (m_domApplicationCache) { | 228 if (!m_domApplicationCache) |
231 const AtomicString& eventType = ApplicationCache::toEventType(id); | 229 return; |
232 RefPtrWillBeRawPtr<Event> event = nullptr; | 230 |
233 if (id == PROGRESS_EVENT) | 231 const AtomicString& eventType = ApplicationCache::toEventType(id); |
234 event = ProgressEvent::create(eventType, true, progressDone, progres
sTotal); | 232 RefPtrWillBeRawPtr<Event> event = nullptr; |
235 else if (id == ERROR_EVENT) | 233 if (id == PROGRESS_EVENT) |
236 event = ApplicationCacheErrorEvent::create(errorReason, errorURL, er
rorStatus, errorMessage); | 234 event = ProgressEvent::create(eventType, true, progressDone, progressTot
al); |
237 else | 235 else if (id == ERROR_EVENT) |
238 event = Event::create(eventType); | 236 event = ApplicationCacheErrorEvent::create(errorReason, errorURL, errorS
tatus, errorMessage); |
239 m_domApplicationCache->dispatchEvent(event, ASSERT_NO_EXCEPTION); | 237 else |
240 } | 238 event = Event::create(eventType); |
| 239 m_domApplicationCache->dispatchEvent(event, ASSERT_NO_EXCEPTION); |
241 } | 240 } |
242 | 241 |
243 ApplicationCacheHost::Status ApplicationCacheHost::status() const | 242 ApplicationCacheHost::Status ApplicationCacheHost::status() const |
244 { | 243 { |
245 return m_host ? static_cast<Status>(m_host->status()) : UNCACHED; | 244 return m_host ? static_cast<Status>(m_host->status()) : UNCACHED; |
246 } | 245 } |
247 | 246 |
248 bool ApplicationCacheHost::update() | 247 bool ApplicationCacheHost::update() |
249 { | 248 { |
250 return m_host ? m_host->startUpdate() : false; | 249 return m_host ? m_host->startUpdate() : false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 285 } |
287 | 286 |
288 void ApplicationCacheHost::notifyErrorEventListener(WebApplicationCacheHost::Err
orReason reason, const WebURL& url, int status, const WebString& message) | 287 void ApplicationCacheHost::notifyErrorEventListener(WebApplicationCacheHost::Err
orReason reason, const WebURL& url, int status, const WebString& message) |
289 { | 288 { |
290 notifyApplicationCache(ERROR_EVENT, 0, 0, reason, url.string(), status, mess
age); | 289 notifyApplicationCache(ERROR_EVENT, 0, 0, reason, url.string(), status, mess
age); |
291 } | 290 } |
292 | 291 |
293 DEFINE_TRACE(ApplicationCacheHost) | 292 DEFINE_TRACE(ApplicationCacheHost) |
294 { | 293 { |
295 visitor->trace(m_domApplicationCache); | 294 visitor->trace(m_domApplicationCache); |
| 295 visitor->trace(m_documentLoader); |
296 } | 296 } |
297 | 297 |
298 } // namespace blink | 298 } // namespace blink |
OLD | NEW |