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