diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-13 06:11:15 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-13 06:11:15 +0000 |
commit | b993171fb1aa82255dbe9cbf51192e69cedb122d (patch) | |
tree | d615841977cd666c34d3d5e31e093d7aaed7a62f /webkit | |
parent | 3818dd0a6c6cba069e6eb93f3983240b4195c06f (diff) | |
download | chromium_src-b993171fb1aa82255dbe9cbf51192e69cedb122d.zip chromium_src-b993171fb1aa82255dbe9cbf51192e69cedb122d.tar.gz chromium_src-b993171fb1aa82255dbe9cbf51192e69cedb122d.tar.bz2 |
Require a specific content-type for appcache intercepts.
BUG=372634
TESTS=unittests and manual
Review URL: https://codereview.chromium.org/276093003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/browser/appcache/appcache_update_job.cc | 36 | ||||
-rw-r--r-- | webkit/browser/appcache/appcache_update_job.h | 2 | ||||
-rw-r--r-- | webkit/browser/appcache/manifest_parser.cc | 13 | ||||
-rw-r--r-- | webkit/browser/appcache/manifest_parser.h | 16 |
4 files changed, 60 insertions, 7 deletions
diff --git a/webkit/browser/appcache/appcache_update_job.cc b/webkit/browser/appcache/appcache_update_job.cc index 0cd087e..6589e3a 100644 --- a/webkit/browser/appcache/appcache_update_job.cc +++ b/webkit/browser/appcache/appcache_update_job.cc @@ -85,6 +85,17 @@ class HostNotifier { } } + void SendLogMessage(const std::string& message) { + for (NotifyHostMap::iterator it = hosts_to_notify.begin(); + it != hosts_to_notify.end(); ++it) { + AppCacheFrontend* frontend = it->first; + for (HostIds::iterator id = it->second.begin(); + id != it->second.end(); ++id) { + frontend->OnLogMessage(*id, LOG_WARNING, message); + } + } + } + private: NotifyHostMap hosts_to_notify; }; @@ -339,6 +350,7 @@ AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, master_entries_completed_(0), url_fetches_completed_(0), manifest_fetcher_(NULL), + manifest_has_valid_mime_type_(false), stored_state_(UNSTORED), storage_(service->storage()) { service_->AddObserver(this); @@ -489,6 +501,10 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted( if (request->status().is_success()) { response_code = request->GetResponseCode(); is_valid_response_code = (response_code / 100 == 2); + + std::string mime_type; + request->GetMimeType(&mime_type); + manifest_has_valid_mime_type_ = (mime_type == "text/cache-manifest"); } if (is_valid_response_code) { @@ -561,7 +577,11 @@ void AppCacheUpdateJob::ContinueHandleManifestFetchCompleted(bool changed) { Manifest manifest; if (!ParseManifest(manifest_url_, manifest_data_.data(), - manifest_data_.length(), manifest)) { + manifest_data_.length(), + manifest_has_valid_mime_type_ ? + PARSE_MANIFEST_ALLOWING_INTERCEPTS : + PARSE_MANIFEST_PER_STANDARD, + manifest)) { const char* kFormatString = "Failed to parse manifest %s"; const std::string message = base::StringPrintf(kFormatString, manifest_url_.spec().c_str()); @@ -591,6 +611,14 @@ void AppCacheUpdateJob::ContinueHandleManifestFetchCompleted(bool changed) { } } + if (manifest.did_ignore_intercept_namespaces) { + // Must be done after associating all pending master hosts. + std::string message( + "Ignoring the INTERCEPT section of the application cache manifest " + "because the content type is not text/cache-manifest"); + LogConsoleMessageToAll(message); + } + group_->SetUpdateStatus(AppCacheGroup::DOWNLOADING); NotifyAllAssociatedHosts(DOWNLOADING_EVENT); FetchUrls(); @@ -958,6 +986,12 @@ void AppCacheUpdateJob::NotifyAllError(const ErrorDetails& details) { host_notifier.SendErrorNotifications(details); } +void AppCacheUpdateJob::LogConsoleMessageToAll(const std::string& message) { + HostNotifier host_notifier; + AddAllAssociatedHostsToNotifier(&host_notifier); + host_notifier.SendLogMessage(message); +} + void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier( HostNotifier* host_notifier) { // Collect hosts so we only send one notification per frontend. diff --git a/webkit/browser/appcache/appcache_update_job.h b/webkit/browser/appcache/appcache_update_job.h index 86740b7f..2287729 100644 --- a/webkit/browser/appcache/appcache_update_job.h +++ b/webkit/browser/appcache/appcache_update_job.h @@ -209,6 +209,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheUpdateJob void NotifyAllProgress(const GURL& url); void NotifyAllFinalProgress(); void NotifyAllError(const ErrorDetails& detals); + void LogConsoleMessageToAll(const std::string& message); void AddAllAssociatedHostsToNotifier(HostNotifier* notifier); // Checks if manifest is byte for byte identical with the manifest @@ -319,6 +320,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheUpdateJob scoped_refptr<net::IOBuffer> read_manifest_buffer_; std::string loaded_manifest_data_; scoped_ptr<AppCacheResponseReader> manifest_response_reader_; + bool manifest_has_valid_mime_type_; // New master entries added to the cache by this job, used to cleanup // in error conditions. diff --git a/webkit/browser/appcache/manifest_parser.cc b/webkit/browser/appcache/manifest_parser.cc index 5735fe4..43ecd55 100644 --- a/webkit/browser/appcache/manifest_parser.cc +++ b/webkit/browser/appcache/manifest_parser.cc @@ -70,12 +70,15 @@ enum InterceptVerb { UNKNOWN_VERB, }; -Manifest::Manifest() : online_whitelist_all(false) {} +Manifest::Manifest() + : online_whitelist_all(false), + did_ignore_intercept_namespaces(false) { +} Manifest::~Manifest() {} bool ParseManifest(const GURL& manifest_url, const char* data, int length, - Manifest& manifest) { + ParseMode parse_mode, Manifest& manifest) { // This is an implementation of the parsing algorithm specified in // the HTML5 offline web application docs: // http://www.w3.org/TR/html5/offline.html @@ -92,6 +95,7 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, DCHECK(manifest.fallback_namespaces.empty()); DCHECK(manifest.online_whitelist_namespaces.empty()); DCHECK(!manifest.online_whitelist_all); + DCHECK(!manifest.did_ignore_intercept_namespaces); Mode mode = EXPLICIT; @@ -218,6 +222,11 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, Namespace(NETWORK_NAMESPACE, url, GURL(), is_pattern)); } } else if (mode == INTERCEPT) { + if (parse_mode != PARSE_MANIFEST_ALLOWING_INTERCEPTS) { + manifest.did_ignore_intercept_namespaces = true; + continue; + } + // Lines of the form, // <urlnamespace> <intercept_type> <targeturl> const wchar_t* line_p = line.c_str(); diff --git a/webkit/browser/appcache/manifest_parser.h b/webkit/browser/appcache/manifest_parser.h index 44661ef..c8d5f00 100644 --- a/webkit/browser/appcache/manifest_parser.h +++ b/webkit/browser/appcache/manifest_parser.h @@ -52,12 +52,20 @@ struct WEBKIT_STORAGE_BROWSER_EXPORT Manifest { NamespaceVector fallback_namespaces; NamespaceVector online_whitelist_namespaces; bool online_whitelist_all; + bool did_ignore_intercept_namespaces; }; -WEBKIT_STORAGE_BROWSER_EXPORT bool ParseManifest(const GURL& manifest_url, - const char* data, - int length, - Manifest& manifest); +enum ParseMode { + PARSE_MANIFEST_PER_STANDARD, + PARSE_MANIFEST_ALLOWING_INTERCEPTS +}; + +WEBKIT_STORAGE_BROWSER_EXPORT bool ParseManifest( + const GURL& manifest_url, + const char* data, + int length, + ParseMode parse_mode, + Manifest& manifest); } // namespace appcache |