| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 DCHECK(m_documentLoader); | 69 DCHECK(m_documentLoader); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ApplicationCacheHost::~ApplicationCacheHost() { | 72 ApplicationCacheHost::~ApplicationCacheHost() { |
| 73 // Verify that detachFromDocumentLoader() has been performed already. | 73 // Verify that detachFromDocumentLoader() has been performed already. |
| 74 DCHECK(!m_host); | 74 DCHECK(!m_host); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void ApplicationCacheHost::willStartLoadingMainResource( | 77 void ApplicationCacheHost::willStartLoadingMainResource( |
| 78 ResourceRequest& request) { | 78 ResourceRequest& request) { |
| 79 // We defer creating the outer host object to avoid spurious creation/destruct
ion | 79 // We defer creating the outer host object to avoid spurious |
| 80 // around creating empty documents. At this point, we're initiating a main res
ource | 80 // creation/destruction around creating empty documents. At this point, we're |
| 81 // load for the document, so its for real. | 81 // initiating a main resource load for the document, so its for real. |
| 82 | 82 |
| 83 if (!isApplicationCacheEnabled()) | 83 if (!isApplicationCacheEnabled()) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 DCHECK(m_documentLoader->frame()); | 86 DCHECK(m_documentLoader->frame()); |
| 87 LocalFrame& frame = *m_documentLoader->frame(); | 87 LocalFrame& frame = *m_documentLoader->frame(); |
| 88 m_host = frame.loader().client()->createApplicationCacheHost(this); | 88 m_host = frame.loader().client()->createApplicationCacheHost(this); |
| 89 if (!m_host) | 89 if (!m_host) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 WrappedResourceRequest wrapped(request); | 92 WrappedResourceRequest wrapped(request); |
| 93 | 93 |
| 94 const WebApplicationCacheHost* spawningHost = nullptr; | 94 const WebApplicationCacheHost* spawningHost = nullptr; |
| 95 Frame* spawningFrame = frame.tree().parent(); | 95 Frame* spawningFrame = frame.tree().parent(); |
| 96 if (!spawningFrame || !spawningFrame->isLocalFrame()) | 96 if (!spawningFrame || !spawningFrame->isLocalFrame()) |
| 97 spawningFrame = frame.loader().opener(); | 97 spawningFrame = frame.loader().opener(); |
| 98 if (!spawningFrame || !spawningFrame->isLocalFrame()) | 98 if (!spawningFrame || !spawningFrame->isLocalFrame()) |
| 99 spawningFrame = &frame; | 99 spawningFrame = &frame; |
| 100 if (DocumentLoader* spawningDocLoader = | 100 if (DocumentLoader* spawningDocLoader = |
| 101 toLocalFrame(spawningFrame)->loader().documentLoader()) | 101 toLocalFrame(spawningFrame)->loader().documentLoader()) |
| 102 spawningHost = spawningDocLoader->applicationCacheHost() | 102 spawningHost = spawningDocLoader->applicationCacheHost() |
| 103 ? spawningDocLoader->applicationCacheHost()->m_host.get() | 103 ? spawningDocLoader->applicationCacheHost()->m_host.get() |
| 104 : nullptr; | 104 : nullptr; |
| 105 | 105 |
| 106 m_host->willStartMainResourceRequest(wrapped, spawningHost); | 106 m_host->willStartMainResourceRequest(wrapped, spawningHost); |
| 107 | 107 |
| 108 // NOTE: The semantics of this method, and others in this interface, are subtl
y different | 108 // NOTE: The semantics of this method, and others in this interface, are |
| 109 // than the method names would suggest. For example, in this method never retu
rns an appcached | 109 // subtly different than the method names would suggest. For example, in this |
| 110 // response in the SubstituteData out argument, instead we return the appcache
d response thru | 110 // method never returns an appcached response in the SubstituteData out |
| 111 // the usual resource loading pipeline. | 111 // argument, instead we return the appcached response thru the usual resource |
| 112 // loading pipeline. |
| 112 } | 113 } |
| 113 | 114 |
| 114 void ApplicationCacheHost::selectCacheWithoutManifest() { | 115 void ApplicationCacheHost::selectCacheWithoutManifest() { |
| 115 if (m_host) | 116 if (m_host) |
| 116 m_host->selectCacheWithoutManifest(); | 117 m_host->selectCacheWithoutManifest(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void ApplicationCacheHost::selectCacheWithManifest(const KURL& manifestURL) { | 120 void ApplicationCacheHost::selectCacheWithManifest(const KURL& manifestURL) { |
| 120 DCHECK(m_documentLoader); | 121 DCHECK(m_documentLoader); |
| 121 | 122 |
| 122 LocalFrame* frame = m_documentLoader->frame(); | 123 LocalFrame* frame = m_documentLoader->frame(); |
| 123 Document* document = frame->document(); | 124 Document* document = frame->document(); |
| 124 if (document->isSecureContext()) { | 125 if (document->isSecureContext()) { |
| 125 UseCounter::count(document, | 126 UseCounter::count(document, |
| 126 UseCounter::ApplicationCacheManifestSelectSecureOrigin); | 127 UseCounter::ApplicationCacheManifestSelectSecureOrigin); |
| 127 UseCounter::countCrossOriginIframe( | 128 UseCounter::countCrossOriginIframe( |
| 128 *document, UseCounter::ApplicationCacheManifestSelectSecureOrigin); | 129 *document, UseCounter::ApplicationCacheManifestSelectSecureOrigin); |
| 129 } else { | 130 } else { |
| 130 Deprecation::countDeprecation( | 131 Deprecation::countDeprecation( |
| 131 document, UseCounter::ApplicationCacheManifestSelectInsecureOrigin); | 132 document, UseCounter::ApplicationCacheManifestSelectInsecureOrigin); |
| 132 Deprecation::countDeprecationCrossOriginIframe( | 133 Deprecation::countDeprecationCrossOriginIframe( |
| 133 *document, UseCounter::ApplicationCacheManifestSelectInsecureOrigin); | 134 *document, UseCounter::ApplicationCacheManifestSelectInsecureOrigin); |
| 134 HostsUsingFeatures::countAnyWorld( | 135 HostsUsingFeatures::countAnyWorld( |
| 135 *document, HostsUsingFeatures::Feature:: | 136 *document, HostsUsingFeatures::Feature:: |
| 136 ApplicationCacheManifestSelectInsecureHost); | 137 ApplicationCacheManifestSelectInsecureHost); |
| 137 } | 138 } |
| 138 if (m_host && !m_host->selectCacheWithManifest(manifestURL)) { | 139 if (m_host && !m_host->selectCacheWithManifest(manifestURL)) { |
| 139 // It's a foreign entry, restart the current navigation from the top | 140 // It's a foreign entry, restart the current navigation from the top of the |
| 140 // of the navigation algorithm. The navigation will not result in the | 141 // navigation algorithm. The navigation will not result in the same resource |
| 141 // same resource being loaded, because "foreign" entries are never picked | 142 // being loaded, because "foreign" entries are never picked during |
| 142 // during navigation. | 143 // navigation. see ApplicationCacheGroup::selectCache() |
| 143 // see ApplicationCacheGroup::selectCache() | |
| 144 frame->navigate(*document, document->url(), true, UserGestureStatus::None); | 144 frame->navigate(*document, document->url(), true, UserGestureStatus::None); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ApplicationCacheHost::didReceiveResponseForMainResource( | 148 void ApplicationCacheHost::didReceiveResponseForMainResource( |
| 149 const ResourceResponse& response) { | 149 const ResourceResponse& response) { |
| 150 if (m_host) { | 150 if (m_host) { |
| 151 WrappedResourceResponse wrapped(response); | 151 WrappedResourceResponse wrapped(response); |
| 152 m_host->didReceiveResponseForMainResource(wrapped); | 152 m_host->didReceiveResponseForMainResource(wrapped); |
| 153 } | 153 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 void ApplicationCacheHost::setApplicationCache( | 179 void ApplicationCacheHost::setApplicationCache( |
| 180 ApplicationCache* domApplicationCache) { | 180 ApplicationCache* domApplicationCache) { |
| 181 DCHECK(!m_domApplicationCache || !domApplicationCache); | 181 DCHECK(!m_domApplicationCache || !domApplicationCache); |
| 182 m_domApplicationCache = domApplicationCache; | 182 m_domApplicationCache = domApplicationCache; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void ApplicationCacheHost::detachFromDocumentLoader() { | 185 void ApplicationCacheHost::detachFromDocumentLoader() { |
| 186 // Detach from the owning DocumentLoader and let go of WebApplicationCacheHost
. | 186 // Detach from the owning DocumentLoader and let go of |
| 187 // WebApplicationCacheHost. |
| 187 setApplicationCache(nullptr); | 188 setApplicationCache(nullptr); |
| 188 m_host.reset(); | 189 m_host.reset(); |
| 189 m_documentLoader = nullptr; | 190 m_documentLoader = nullptr; |
| 190 } | 191 } |
| 191 | 192 |
| 192 void ApplicationCacheHost::notifyApplicationCache( | 193 void ApplicationCacheHost::notifyApplicationCache( |
| 193 EventID id, | 194 EventID id, |
| 194 int progressTotal, | 195 int progressTotal, |
| 195 int progressDone, | 196 int progressDone, |
| 196 WebApplicationCacheHost::ErrorReason errorReason, | 197 WebApplicationCacheHost::ErrorReason errorReason, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 298 |
| 298 bool ApplicationCacheHost::isApplicationCacheEnabled() { | 299 bool ApplicationCacheHost::isApplicationCacheEnabled() { |
| 299 DCHECK(m_documentLoader->frame()); | 300 DCHECK(m_documentLoader->frame()); |
| 300 return m_documentLoader->frame()->settings() && | 301 return m_documentLoader->frame()->settings() && |
| 301 m_documentLoader->frame() | 302 m_documentLoader->frame() |
| 302 ->settings() | 303 ->settings() |
| 303 ->offlineWebApplicationCacheEnabled(); | 304 ->offlineWebApplicationCacheEnabled(); |
| 304 } | 305 } |
| 305 | 306 |
| 306 void ApplicationCacheHost::didChangeCacheAssociation() { | 307 void ApplicationCacheHost::didChangeCacheAssociation() { |
| 307 // FIXME: Prod the inspector to update its notion of what cache the page is us
ing. | 308 // FIXME: Prod the inspector to update its notion of what cache the page is |
| 309 // using. |
| 308 } | 310 } |
| 309 | 311 |
| 310 void ApplicationCacheHost::notifyEventListener( | 312 void ApplicationCacheHost::notifyEventListener( |
| 311 WebApplicationCacheHost::EventID eventID) { | 313 WebApplicationCacheHost::EventID eventID) { |
| 312 notifyApplicationCache(static_cast<ApplicationCacheHost::EventID>(eventID), 0, | 314 notifyApplicationCache(static_cast<ApplicationCacheHost::EventID>(eventID), 0, |
| 313 0, WebApplicationCacheHost::UnknownError, String(), 0, | 315 0, WebApplicationCacheHost::UnknownError, String(), 0, |
| 314 String()); | 316 String()); |
| 315 } | 317 } |
| 316 | 318 |
| 317 void ApplicationCacheHost::notifyProgressEventListener(const WebURL&, | 319 void ApplicationCacheHost::notifyProgressEventListener(const WebURL&, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 330 notifyApplicationCache(kErrorEvent, 0, 0, reason, url.string(), status, | 332 notifyApplicationCache(kErrorEvent, 0, 0, reason, url.string(), status, |
| 331 message); | 333 message); |
| 332 } | 334 } |
| 333 | 335 |
| 334 DEFINE_TRACE(ApplicationCacheHost) { | 336 DEFINE_TRACE(ApplicationCacheHost) { |
| 335 visitor->trace(m_domApplicationCache); | 337 visitor->trace(m_domApplicationCache); |
| 336 visitor->trace(m_documentLoader); | 338 visitor->trace(m_documentLoader); |
| 337 } | 339 } |
| 338 | 340 |
| 339 } // namespace blink | 341 } // namespace blink |
| OLD | NEW |