diff options
Diffstat (limited to 'chromium/content/child/appcache/web_application_cache_host_impl.cc')
-rw-r--r-- | chromium/content/child/appcache/web_application_cache_host_impl.cc | 127 |
1 files changed, 61 insertions, 66 deletions
diff --git a/chromium/content/child/appcache/web_application_cache_host_impl.cc b/chromium/content/child/appcache/web_application_cache_host_impl.cc index 2088bc6ace8..427262ed0b9 100644 --- a/chromium/content/child/appcache/web_application_cache_host_impl.cc +++ b/chromium/content/child/appcache/web_application_cache_host_impl.cc @@ -8,16 +8,14 @@ #include "base/id_map.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" +#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/platform/WebURLRequest.h" #include "third_party/WebKit/public/platform/WebURLResponse.h" -#include "third_party/WebKit/public/web/WebDataSource.h" -#include "third_party/WebKit/public/web/WebFrame.h" using blink::WebApplicationCacheHost; using blink::WebApplicationCacheHostClient; -using blink::WebDataSource; -using blink::WebFrame; +using blink::WebString; using blink::WebURLRequest; using blink::WebURL; using blink::WebURLResponse; @@ -57,29 +55,18 @@ WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromId(int id) { return all_hosts()->Lookup(id); } -WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromFrame( - const WebFrame* frame) { - if (!frame) - return NULL; - WebDataSource* data_source = frame->dataSource(); - if (!data_source) - return NULL; - return static_cast<WebApplicationCacheHostImpl*> - (data_source->applicationCacheHost()); -} - WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( WebApplicationCacheHostClient* client, AppCacheBackend* backend) : client_(client), backend_(backend), host_id_(all_hosts()->Add(this)), - status_(appcache::UNCACHED), + status_(appcache::APPCACHE_STATUS_UNCACHED), is_scheme_supported_(false), is_get_method_(false), is_new_master_entry_(MAYBE), was_select_cache_called_(false) { - DCHECK(client && backend && (host_id_ != appcache::kNoHostId)); + DCHECK(client && backend && (host_id_ != appcache::kAppCacheNoHostId)); backend_->RegisterHost(host_id_); } @@ -95,37 +82,40 @@ void WebApplicationCacheHostImpl::OnCacheSelected( client_->didChangeCacheAssociation(); } -void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { +void WebApplicationCacheHostImpl::OnStatusChanged( + appcache::AppCacheStatus status) { // TODO(michaeln): delete me, not used } -void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { - DCHECK(event_id != appcache::PROGRESS_EVENT); // See OnProgressEventRaised. - DCHECK(event_id != appcache::ERROR_EVENT); // See OnErrorEventRaised. +void WebApplicationCacheHostImpl::OnEventRaised( + appcache::AppCacheEventID event_id) { + DCHECK(event_id != + appcache::APPCACHE_PROGRESS_EVENT); // See OnProgressEventRaised. + DCHECK(event_id != appcache::APPCACHE_ERROR_EVENT); // See OnErrorEventRaised. // Emit logging output prior to calling out to script as we can get // deleted within the script event handler. const char* kFormatString = "Application Cache %s event"; std::string message = base::StringPrintf(kFormatString, kEventNames[event_id]); - OnLogMessage(appcache::LOG_INFO, message); + OnLogMessage(appcache::APPCACHE_LOG_INFO, message); switch (event_id) { - case appcache::CHECKING_EVENT: - status_ = appcache::CHECKING; + case appcache::APPCACHE_CHECKING_EVENT: + status_ = appcache::APPCACHE_STATUS_CHECKING; break; - case appcache::DOWNLOADING_EVENT: - status_ = appcache::DOWNLOADING; + case appcache::APPCACHE_DOWNLOADING_EVENT: + status_ = appcache::APPCACHE_STATUS_DOWNLOADING; break; - case appcache::UPDATE_READY_EVENT: - status_ = appcache::UPDATE_READY; + case appcache::APPCACHE_UPDATE_READY_EVENT: + status_ = appcache::APPCACHE_STATUS_UPDATE_READY; break; - case appcache::CACHED_EVENT: - case appcache::NO_UPDATE_EVENT: - status_ = appcache::IDLE; + case appcache::APPCACHE_CACHED_EVENT: + case appcache::APPCACHE_NO_UPDATE_EVENT: + status_ = appcache::APPCACHE_STATUS_IDLE; break; - case appcache::OBSOLETE_EVENT: - status_ = appcache::OBSOLETE; + case appcache::APPCACHE_OBSOLETE_EVENT: + status_ = appcache::APPCACHE_STATUS_OBSOLETE; break; default: NOTREACHED(); @@ -142,26 +132,37 @@ void WebApplicationCacheHostImpl::OnProgressEventRaised( const char* kFormatString = "Application Cache Progress event (%d of %d) %s"; std::string message = base::StringPrintf(kFormatString, num_complete, num_total, url.spec().c_str()); - OnLogMessage(appcache::LOG_INFO, message); - status_ = appcache::DOWNLOADING; + OnLogMessage(appcache::APPCACHE_LOG_INFO, message); + status_ = appcache::APPCACHE_STATUS_DOWNLOADING; client_->notifyProgressEventListener(url, num_total, num_complete); } void WebApplicationCacheHostImpl::OnErrorEventRaised( - const std::string& message) { + const appcache::AppCacheErrorDetails& details) { // Emit logging output prior to calling out to script as we can get // deleted within the script event handler. const char* kFormatString = "Application Cache Error event: %s"; - std::string full_message = base::StringPrintf(kFormatString, - message.c_str()); - OnLogMessage(appcache::LOG_ERROR, full_message); - - status_ = cache_info_.is_complete ? appcache::IDLE : appcache::UNCACHED; - client_->notifyEventListener(static_cast<EventID>(appcache::ERROR_EVENT)); + std::string full_message = + base::StringPrintf(kFormatString, details.message.c_str()); + OnLogMessage(appcache::APPCACHE_LOG_ERROR, full_message); + + status_ = cache_info_.is_complete ? appcache::APPCACHE_STATUS_IDLE : + appcache::APPCACHE_STATUS_UNCACHED; + if (details.is_cross_origin) { + // Don't leak detailed information to script for cross-origin resources. + DCHECK_EQ(appcache::APPCACHE_RESOURCE_ERROR, details.reason); + client_->notifyErrorEventListener( + static_cast<ErrorReason>(details.reason), details.url, 0, WebString()); + } else { + client_->notifyErrorEventListener(static_cast<ErrorReason>(details.reason), + details.url, + details.status, + WebString::fromUTF8(details.message)); + } } void WebApplicationCacheHostImpl::willStartMainResourceRequest( - WebURLRequest& request, const WebFrame* frame) { + WebURLRequest& request, const WebApplicationCacheHost* spawning_host) { request.setAppCacheHostID(host_id_); original_main_resource_url_ = ClearUrlRef(request.url()); @@ -170,18 +171,11 @@ void WebApplicationCacheHostImpl::willStartMainResourceRequest( is_get_method_ = (method == appcache::kHttpGETMethod); DCHECK(method == StringToUpperASCII(method)); - if (frame) { - const WebFrame* spawning_frame = frame->parent(); - if (!spawning_frame) - spawning_frame = frame->opener(); - if (!spawning_frame) - spawning_frame = frame; - - WebApplicationCacheHostImpl* spawning_host = FromFrame(spawning_frame); - if (spawning_host && (spawning_host != this) && - (spawning_host->status_ != appcache::UNCACHED)) { - backend_->SetSpawningHostId(host_id_, spawning_host->host_id()); - } + const WebApplicationCacheHostImpl* spawning_host_impl = + static_cast<const WebApplicationCacheHostImpl*>(spawning_host); + if (spawning_host_impl && (spawning_host_impl != this) && + (spawning_host_impl->status_ != appcache::APPCACHE_STATUS_UNCACHED)) { + backend_->SetSpawningHostId(host_id_, spawning_host_impl->host_id()); } } @@ -195,8 +189,8 @@ void WebApplicationCacheHostImpl::selectCacheWithoutManifest() { return; was_select_cache_called_ = true; - status_ = (document_response_.appCacheID() == appcache::kNoCacheId) ? - appcache::UNCACHED : appcache::CHECKING; + status_ = (document_response_.appCacheID() == appcache::kAppCacheNoCacheId) ? + appcache::APPCACHE_STATUS_UNCACHED : appcache::APPCACHE_STATUS_CHECKING; is_new_master_entry_ = NO; backend_->SelectCache(host_id_, document_url_, document_response_.appCacheID(), @@ -213,18 +207,18 @@ bool WebApplicationCacheHostImpl::selectCacheWithManifest( // 6.9.6 The application cache selection algorithm // Check for new 'master' entries. - if (document_response_.appCacheID() == appcache::kNoCacheId) { + if (document_response_.appCacheID() == appcache::kAppCacheNoCacheId) { if (is_scheme_supported_ && is_get_method_ && (manifest_gurl.GetOrigin() == document_url_.GetOrigin())) { - status_ = appcache::CHECKING; + status_ = appcache::APPCACHE_STATUS_CHECKING; is_new_master_entry_ = YES; } else { - status_ = appcache::UNCACHED; + status_ = appcache::APPCACHE_STATUS_UNCACHED; is_new_master_entry_ = NO; manifest_gurl = GURL(); } backend_->SelectCache( - host_id_, document_url_, appcache::kNoCacheId, manifest_gurl); + host_id_, document_url_, appcache::kAppCacheNoCacheId, manifest_gurl); return true; } @@ -236,11 +230,11 @@ bool WebApplicationCacheHostImpl::selectCacheWithManifest( if (document_manifest_gurl != manifest_gurl) { backend_->MarkAsForeignEntry(host_id_, document_url_, document_response_.appCacheID()); - status_ = appcache::UNCACHED; + status_ = appcache::APPCACHE_STATUS_UNCACHED; return false; // the navigation will be restarted } - status_ = appcache::CHECKING; + status_ = appcache::APPCACHE_STATUS_CHECKING; // Its a 'master' entry thats already in the cache. backend_->SelectCache(host_id_, document_url_, @@ -258,7 +252,7 @@ void WebApplicationCacheHostImpl::didReceiveResponseForMainResource( original_main_resource_url_ = GURL(); is_scheme_supported_ = appcache::IsSchemeSupported(document_url_); - if ((document_response_.appCacheID() != appcache::kNoCacheId) || + if ((document_response_.appCacheID() != appcache::kAppCacheNoCacheId) || !is_scheme_supported_ || !is_get_method_) is_new_master_entry_ = NO; } @@ -283,8 +277,9 @@ WebApplicationCacheHost::Status WebApplicationCacheHostImpl::status() { bool WebApplicationCacheHostImpl::startUpdate() { if (!backend_->StartUpdate(host_id_)) return false; - if (status_ == appcache::IDLE || status_ == appcache::UPDATE_READY) - status_ = appcache::CHECKING; + if (status_ == appcache::APPCACHE_STATUS_IDLE || + status_ == appcache::APPCACHE_STATUS_UPDATE_READY) + status_ = appcache::APPCACHE_STATUS_CHECKING; else status_ = backend_->GetStatus(host_id_); return true; |