diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 00:19:40 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 00:19:40 +0000 |
commit | 2abcade13437abb0a3b92cb0b7236b3dd5f1a236 (patch) | |
tree | 268c2baca793e8e865d4b24c69376cf212927133 | |
parent | 17e6cde51ff33a5dac5290e978c4e7acf08a473c (diff) | |
download | chromium_src-2abcade13437abb0a3b92cb0b7236b3dd5f1a236.zip chromium_src-2abcade13437abb0a3b92cb0b7236b3dd5f1a236.tar.gz chromium_src-2abcade13437abb0a3b92cb0b7236b3dd5f1a236.tar.bz2 |
Fix some loose ends around recently introduced AppCache INTERCEPT namespaces
- if an intercept entry cant be fetched, the appcache update should fail
- properly mark the intercept entry as FORIEGN when thats detected
BUG=101565
Review URL: http://codereview.chromium.org/8949001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116417 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/appcache/appcache.cc | 15 | ||||
-rw-r--r-- | webkit/appcache/appcache.h | 17 | ||||
-rw-r--r-- | webkit/appcache/appcache_entry.h | 1 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.cc | 12 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.h | 11 | ||||
-rw-r--r-- | webkit/appcache/appcache_host_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler.cc | 20 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler.h | 5 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler_unittest.cc | 4 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage.h | 7 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl.cc | 25 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl.h | 2 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl_unittest.cc | 17 | ||||
-rw-r--r-- | webkit/appcache/appcache_unittest.cc | 53 | ||||
-rw-r--r-- | webkit/appcache/appcache_update_job.cc | 7 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage.cc | 117 |
16 files changed, 200 insertions, 115 deletions
diff --git a/webkit/appcache/appcache.cc b/webkit/appcache/appcache.cc index 5a4e548..e5d197d 100644 --- a/webkit/appcache/appcache.cc +++ b/webkit/appcache/appcache.cc @@ -79,11 +79,12 @@ const AppCacheEntry* AppCache::GetEntryWithResponseId(int64 response_id) { return NULL; } -GURL AppCache::GetFallbackEntryUrl(const GURL& namespace_url) const { - size_t count = fallback_namespaces_.size(); +GURL AppCache::GetNamespaceEntryUrl(const NamespaceVector& namespaces, + const GURL& namespace_url) const { + size_t count = namespaces.size(); for (size_t i = 0; i < count; ++i) { - if (fallback_namespaces_[i].namespace_url == namespace_url) - return fallback_namespaces_[i].target_url; + if (namespaces[i].namespace_url == namespace_url) + return namespaces[i].target_url; } NOTREACHED(); return GURL(); @@ -219,8 +220,9 @@ void AppCache::ToDatabaseRecords( } bool AppCache::FindResponseForRequest(const GURL& url, - AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, - GURL* found_fallback_namespace, bool* found_network_namespace) { + AppCacheEntry* found_entry, GURL* found_intercept_namespace, + AppCacheEntry* found_fallback_entry, GURL* found_fallback_namespace, + bool* found_network_namespace) { // Ignore fragments when looking up URL in the cache. GURL url_no_ref; if (url.has_ref()) { @@ -249,6 +251,7 @@ bool AppCache::FindResponseForRequest(const GURL& url, entry = GetEntry(intercept_namespace->target_url); DCHECK(entry); *found_entry = *entry; + *found_intercept_namespace = intercept_namespace->namespace_url; return true; } diff --git a/webkit/appcache/appcache.h b/webkit/appcache/appcache.h index bc42b5f..daf9874 100644 --- a/webkit/appcache/appcache.h +++ b/webkit/appcache/appcache.h @@ -60,8 +60,13 @@ class APPCACHE_EXPORT AppCache : public base::RefCounted<AppCache> { const EntryMap& entries() const { return entries_; } - // Returns the URL of the resource used as the fallback for 'namespace_url'. - GURL GetFallbackEntryUrl(const GURL& namespace_url) const; + // Returns the URL of the resource used as entry for 'namespace_url'. + GURL GetFallbackEntryUrl(const GURL& namespace_url) const { + return GetNamespaceEntryUrl(fallback_namespaces_, namespace_url); + } + GURL GetInterceptEntryUrl(const GURL& namespace_url) const { + return GetNamespaceEntryUrl(intercept_namespaces_, namespace_url); + } AppCacheHosts& associated_hosts() { return associated_hosts_; } @@ -107,8 +112,9 @@ class APPCACHE_EXPORT AppCache : public base::RefCounted<AppCache> { std::vector<AppCacheDatabase::OnlineWhiteListRecord>* whitelists); bool FindResponseForRequest(const GURL& url, - AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, - GURL* found_fallback_namespace, bool* found_network_namespace); + AppCacheEntry* found_entry, GURL* found_intercept_namespace, + AppCacheEntry* found_fallback_entry, GURL* found_fallback_namespace, + bool* found_network_namespace); // Populates the 'infos' vector with an element per entry in the appcache. void ToResourceInfoVector(AppCacheResourceInfoVector* infos) const; @@ -139,6 +145,9 @@ class APPCACHE_EXPORT AppCache : public base::RefCounted<AppCache> { const Namespace* FindNamespace(const NamespaceVector& namespaces, const GURL& url); + GURL GetNamespaceEntryUrl(const NamespaceVector& namespaces, + const GURL& namespace_url) const; + // Use AppCacheHost::Associate*Cache() to manipulate host association. void AssociateHost(AppCacheHost* host) { associated_hosts_.insert(host); diff --git a/webkit/appcache/appcache_entry.h b/webkit/appcache/appcache_entry.h index 2b38a25..8f92533 100644 --- a/webkit/appcache/appcache_entry.h +++ b/webkit/appcache/appcache_entry.h @@ -16,6 +16,7 @@ class AppCacheEntry { public: // An entry can be of more than one type so use a bitmask. + // Note: These bit values are stored on disk. enum Type { MASTER = 1 << 0, MANIFEST = 1 << 1, diff --git a/webkit/appcache/appcache_host.cc b/webkit/appcache/appcache_host.cc index b9cae76..ff0cb3e 100644 --- a/webkit/appcache/appcache_host.cc +++ b/webkit/appcache/appcache_host.cc @@ -50,7 +50,8 @@ AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, pending_selected_cache_id_(kNoCacheId), frontend_(frontend), service_(service), pending_callback_param_(NULL), - main_resource_was_fallback_(false), main_resource_blocked_(false), + main_resource_was_namespace_entry_(false), + main_resource_blocked_(false), associated_cache_info_pending_(false) { } @@ -160,7 +161,7 @@ void AppCacheHost::MarkAsForeignEntry(const GURL& document_url, int64 cache_document_was_loaded_from) { // The document url is not the resource url in the fallback case. service_->storage()->MarkEntryAsForeign( - main_resource_was_fallback_ ? fallback_url_ : document_url, + main_resource_was_namespace_entry_ ? namespace_entry_url_ : document_url, cache_document_was_loaded_from); SelectCache(document_url, kNoCacheId, GURL()); } @@ -464,9 +465,10 @@ void AppCacheHost::LoadMainResourceCache(int64 cache_id) { service_->storage()->LoadCache(cache_id, this); } -void AppCacheHost::NotifyMainResourceFallback(const GURL& fallback_url) { - main_resource_was_fallback_ = true; - fallback_url_ = fallback_url; +void AppCacheHost::NotifyMainResourceIsNamespaceEntry( + const GURL& namespace_entry_url) { + main_resource_was_namespace_entry_ = true; + namespace_entry_url_ = namespace_entry_url; } void AppCacheHost::NotifyMainResourceBlocked(const GURL& manifest_url) { diff --git a/webkit/appcache/appcache_host.h b/webkit/appcache/appcache_host.h index 2ea022b..172d740 100644 --- a/webkit/appcache/appcache_host.h +++ b/webkit/appcache/appcache_host.h @@ -123,9 +123,9 @@ class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate, // Used to ensure that a loaded appcache survives a frame navigation. void LoadMainResourceCache(int64 cache_id); - // Used to notify the host that a fallback resource is being delivered as + // Used to notify the host that a namespace resource is being delivered as // the main resource of the page and to provide its url. - void NotifyMainResourceFallback(const GURL& fallback_url); + void NotifyMainResourceIsNamespaceEntry(const GURL& namespace_entry_url); // Used to notify the host that the main resource was blocked by a policy. To // work properly, this method needs to by invoked prior to cache selection. @@ -245,9 +245,10 @@ class APPCACHE_EXPORT AppCacheHost : public AppCacheStorage::Delegate, SwapCacheCallback pending_swap_cache_callback_; void* pending_callback_param_; - // True if a fallback resource was delivered as the main resource. - bool main_resource_was_fallback_; - GURL fallback_url_; + // True if an intercept or fallback namespace resource was + // delivered as the main resource. + bool main_resource_was_namespace_entry_; + GURL namespace_entry_url_; // True if requests for this host were blocked by a policy. bool main_resource_blocked_; diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc index 1b89d06..a5b98a2 100644 --- a/webkit/appcache/appcache_host_unittest.cc +++ b/webkit/appcache/appcache_host_unittest.cc @@ -254,7 +254,7 @@ TEST_F(AppCacheHostTest, ForeignFallbackEntry) { cache->AddEntry(kFallbackURL, AppCacheEntry(AppCacheEntry::FALLBACK)); AppCacheHost host(1, &mock_frontend_, &service_); - host.NotifyMainResourceFallback(kFallbackURL); + host.NotifyMainResourceIsNamespaceEntry(kFallbackURL); host.MarkAsForeignEntry(GURL("http://origin/missing_document"), kCacheId); // We should have received an OnCacheSelected msg for kNoCacheId. diff --git a/webkit/appcache/appcache_request_handler.cc b/webkit/appcache/appcache_request_handler.cc index dc55088..0f123a1 100644 --- a/webkit/appcache/appcache_request_handler.cc +++ b/webkit/appcache/appcache_request_handler.cc @@ -105,7 +105,7 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( job_ = new AppCacheURLRequestJob(request, storage()); DeliverAppCachedResponse( found_fallback_entry_, found_cache_id_, found_group_id_, - found_manifest_url_, true, found_fallback_url_); + found_manifest_url_, true, found_namespace_entry_url_); } else if (!found_network_namespace_) { // 6.9.6, step 6: Fail the resource load. job_ = new AppCacheURLRequestJob(request, storage()); @@ -157,7 +157,7 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( job_ = new AppCacheURLRequestJob(request, storage()); DeliverAppCachedResponse( found_fallback_entry_, found_cache_id_, found_group_id_, - found_manifest_url_, true, found_fallback_url_); + found_manifest_url_, true, found_namespace_entry_url_); return job_; } @@ -175,14 +175,13 @@ void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { void AppCacheRequestHandler::DeliverAppCachedResponse( const AppCacheEntry& entry, int64 cache_id, int64 group_id, - const GURL& manifest_url, bool is_fallback, const GURL& fallback_url) { + const GURL& manifest_url, bool is_fallback, + const GURL& namespace_entry_url) { DCHECK(host_ && job_ && job_->is_waiting()); DCHECK(entry.has_response_id()); - if (ResourceType::IsFrame(resource_type_) && is_fallback) { - DCHECK(!fallback_url.is_empty()); - host_->NotifyMainResourceFallback(fallback_url); - } + if (ResourceType::IsFrame(resource_type_) && !namespace_entry_url.is_empty()) + host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); job_->DeliverAppCachedResponse(manifest_url, group_id, cache_id, entry, is_fallback); @@ -219,7 +218,7 @@ void AppCacheRequestHandler::MaybeLoadMainResource(net::URLRequest* request) { void AppCacheRequestHandler::OnMainResponseFound( const GURL& url, const AppCacheEntry& entry, - const GURL& fallback_url, const AppCacheEntry& fallback_entry, + const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, int64 cache_id, int64 group_id, const GURL& manifest_url) { DCHECK(job_); DCHECK(host_); @@ -258,7 +257,7 @@ void AppCacheRequestHandler::OnMainResponseFound( // 6.11.1 Navigating across documents, steps 10 and 14. found_entry_ = entry; - found_fallback_url_ = fallback_url; + found_namespace_entry_url_ = namespace_entry_url; found_fallback_entry_ = fallback_entry; found_cache_id_ = cache_id; found_group_id_ = group_id; @@ -266,9 +265,10 @@ void AppCacheRequestHandler::OnMainResponseFound( found_network_namespace_ = false; // not applicable to main requests if (found_entry_.has_response_id()) { + DCHECK(!found_fallback_entry_.has_response_id()); DeliverAppCachedResponse( found_entry_, found_cache_id_, found_group_id_, found_manifest_url_, - false, GURL()); + false, found_namespace_entry_url_); } else { DeliverNetworkResponse(); } diff --git a/webkit/appcache/appcache_request_handler.h b/webkit/appcache/appcache_request_handler.h index b4a387d..6f45358 100644 --- a/webkit/appcache/appcache_request_handler.h +++ b/webkit/appcache/appcache_request_handler.h @@ -59,7 +59,8 @@ class APPCACHE_EXPORT AppCacheRequestHandler // deliver for the request we're handling. void DeliverAppCachedResponse(const AppCacheEntry& entry, int64 cache_id, int64 group_id, const GURL& manifest_url, - bool is_fallback, const GURL& fallback_url); + bool is_fallback, + const GURL& namespace_entry_url); void DeliverNetworkResponse(); void DeliverErrorResponse(); @@ -107,7 +108,7 @@ class APPCACHE_EXPORT AppCacheRequestHandler int64 found_cache_id_; AppCacheEntry found_entry_; AppCacheEntry found_fallback_entry_; - GURL found_fallback_url_; + GURL found_namespace_entry_url_; GURL found_manifest_url_; bool found_network_namespace_; diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc index c576133..5d61e86 100644 --- a/webkit/appcache/appcache_request_handler_unittest.cc +++ b/webkit/appcache/appcache_request_handler_unittest.cc @@ -361,8 +361,8 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_->GetExtraResponseInfo(&cache_id, &manifest_url); EXPECT_EQ(1, cache_id); EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); - EXPECT_TRUE(host_->main_resource_was_fallback_); - EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->fallback_url_); + EXPECT_TRUE(host_->main_resource_was_namespace_entry_); + EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->namespace_entry_url_); EXPECT_EQ(GURL("http://blah/manifest/"), host_->preferred_manifest_url()); diff --git a/webkit/appcache/appcache_storage.h b/webkit/appcache/appcache_storage.h index 4d30ce3..9f74a59 100644 --- a/webkit/appcache/appcache_storage.h +++ b/webkit/appcache/appcache_storage.h @@ -60,12 +60,15 @@ class APPCACHE_EXPORT AppCacheStorage { virtual void OnResponseInfoLoaded( AppCacheResponseInfo* response_info, int64 response_id) {} - // If no response is found, entry.response_id() will be kNoResponseId. + // If no response is found, entry.response_id() and + // fallback_entry.response_id() will be kNoResponseId. + // If the response is the entry for an intercept or fallback + // namespace, the url of the namespece entry is returned. // If a response is found, the cache id and manifest url of the // containing cache and group are also returned. virtual void OnMainResponseFound( const GURL& url, const AppCacheEntry& entry, - const GURL& fallback_url, const AppCacheEntry& fallback_entry, + const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, int64 cache_id, int64 group_id, const GURL& mainfest_url) {} }; diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc index 617bc27..4e3c3be 100644 --- a/webkit/appcache/appcache_storage_impl.cc +++ b/webkit/appcache/appcache_storage_impl.cc @@ -851,7 +851,7 @@ class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask { std::set<int64> cache_ids_in_use_; AppCacheEntry entry_; AppCacheEntry fallback_entry_; - GURL fallback_url_; + GURL namespace_entry_url_; int64 cache_id_; int64 group_id_; GURL manifest_url_; @@ -1004,13 +1004,12 @@ FindMainResponseTask::FindFirstValidNamespace( manifest_url_ = group_record.manifest_url; group_id_ = group_record.group_id; cache_id_ = (*iter)->cache_id; - if ((*iter)->type == FALLBACK_NAMESPACE) { - fallback_url_ = (*iter)->target_url; - fallback_entry_ = AppCacheEntry( - entry_record.flags, entry_record.response_id); - } else { + namespace_entry_url_ = (*iter)->target_url; + if ((*iter)->type == FALLBACK_NAMESPACE) + fallback_entry_ = AppCacheEntry(entry_record.flags, + entry_record.response_id); + else entry_ = AppCacheEntry(entry_record.flags, entry_record.response_id); - } return true; // We found one. } } @@ -1019,7 +1018,7 @@ FindMainResponseTask::FindFirstValidNamespace( void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { storage_->CallOnMainResponseFound( - &delegates_, url_, entry_, fallback_url_, fallback_entry_, + &delegates_, url_, entry_, namespace_entry_url_, fallback_entry_, cache_id_, group_id_, manifest_url_); } @@ -1453,12 +1452,12 @@ void AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse( void AppCacheStorageImpl::CallOnMainResponseFound( DelegateReferenceVector* delegates, const GURL& url, const AppCacheEntry& entry, - const GURL& fallback_url, const AppCacheEntry& fallback_entry, + const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, int64 cache_id, int64 group_id, const GURL& manifest_url) { FOR_EACH_DELEGATE( (*delegates), OnMainResponseFound(url, entry, - fallback_url, fallback_entry, + namespace_entry_url, fallback_entry, cache_id, group_id, manifest_url)); } @@ -1479,9 +1478,11 @@ void AppCacheStorageImpl::FindResponseForSubRequest( } GURL fallback_namespace_not_used; + GURL intercept_namespace_not_used; cache->FindResponseForRequest( - url, found_entry, found_fallback_entry, - &fallback_namespace_not_used, found_network_namespace); + url, found_entry, &intercept_namespace_not_used, + found_fallback_entry, &fallback_namespace_not_used, + found_network_namespace); } void AppCacheStorageImpl::MarkEntryAsForeign( diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h index db87bbf..b983f47 100644 --- a/webkit/appcache/appcache_storage_impl.h +++ b/webkit/appcache/appcache_storage_impl.h @@ -125,7 +125,7 @@ class AppCacheStorageImpl : public AppCacheStorage { void CallOnMainResponseFound( DelegateReferenceVector* delegates, const GURL& url, const AppCacheEntry& entry, - const GURL& fallback_url, const AppCacheEntry& fallback_entry, + const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, int64 cache_id, int64 group_id, const GURL& manifest_url); APPCACHE_EXPORT AppCacheDiskCache* disk_cache(); diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc index cdfe149..5521e61 100644 --- a/webkit/appcache/appcache_storage_impl_unittest.cc +++ b/webkit/appcache/appcache_storage_impl_unittest.cc @@ -95,13 +95,13 @@ class AppCacheStorageImplTest : public testing::Test { } void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, - const GURL& fallback_url, + const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, int64 cache_id, int64 group_id, const GURL& manifest_url) { found_url_ = url; found_entry_ = entry; - found_fallback_url_ = fallback_url; + found_namespace_entry_url_ = namespace_entry_url; found_fallback_entry_ = fallback_entry; found_cache_id_ = cache_id; found_group_id_ = group_id; @@ -121,7 +121,7 @@ class AppCacheStorageImplTest : public testing::Test { bool obsoleted_success_; GURL found_url_; AppCacheEntry found_entry_; - GURL found_fallback_url_; + GURL found_namespace_entry_url_; AppCacheEntry found_fallback_entry_; int64 found_cache_id_; int64 found_group_id_; @@ -807,7 +807,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); - EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); + EXPECT_TRUE(delegate()->found_namespace_entry_url_.is_empty()); EXPECT_EQ(0, delegate()->found_entry_.types()); EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); TestFinished(); @@ -926,7 +926,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(2, delegate()->found_group_id_); EXPECT_FALSE(delegate()->found_entry_.has_response_id()); EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); - EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); + EXPECT_EQ(kEntryUrl2, delegate()->found_namespace_entry_url_); EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); TestFinished(); } @@ -995,6 +995,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(2, delegate()->found_group_id_); EXPECT_EQ(2, delegate()->found_entry_.response_id()); EXPECT_TRUE(delegate()->found_entry_.IsIntercept()); + EXPECT_EQ(kEntryUrl2, delegate()->found_namespace_entry_url_); EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); TestFinished(); } @@ -1125,7 +1126,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(3 + kFallbackEntryIdOffset, delegate()->found_fallback_entry_.response_id()); EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); - EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); + EXPECT_EQ(kEntryUrl2, delegate()->found_namespace_entry_url_); // Conduct another test preferring kManifestUrl2 that hits the fallback. delegate_.reset(new MockStorageDelegate(this)); @@ -1146,7 +1147,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(2 + kFallbackEntryIdOffset, delegate()->found_fallback_entry_.response_id()); EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); - EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); + EXPECT_EQ(kEntryUrl2, delegate()->found_namespace_entry_url_); TestFinished(); } @@ -1213,7 +1214,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(0, delegate()->found_group_id_); EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); - EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); + EXPECT_TRUE(delegate()->found_namespace_entry_url_.is_empty()); EXPECT_EQ(0, delegate()->found_entry_.types()); EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); diff --git a/webkit/appcache/appcache_unittest.cc b/webkit/appcache/appcache_unittest.cc index 2b1bb83..2888984 100644 --- a/webkit/appcache/appcache_unittest.cc +++ b/webkit/appcache/appcache_unittest.cc @@ -191,15 +191,20 @@ TEST(AppCacheTest, FindResponseForRequest) { bool found = false; AppCacheEntry entry; AppCacheEntry fallback_entry; + GURL intercept_namespace; GURL fallback_namespace; bool network_namespace = false; found = cache->FindResponseForRequest(GURL("http://blah/miss"), - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_FALSE(found); found = cache->FindResponseForRequest(kForeignExplicitEntryUrl, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_EQ(kForeignExplicitResponseId, entry.response_id()); EXPECT_FALSE(fallback_entry.has_response_id()); @@ -208,7 +213,9 @@ TEST(AppCacheTest, FindResponseForRequest) { entry = AppCacheEntry(); // reset found = cache->FindResponseForRequest(kManifestUrl, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_EQ(kManifestResponseId, entry.response_id()); EXPECT_FALSE(fallback_entry.has_response_id()); @@ -217,7 +224,9 @@ TEST(AppCacheTest, FindResponseForRequest) { entry = AppCacheEntry(); // reset found = cache->FindResponseForRequest(kInOnlineNamespaceUrl, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_FALSE(fallback_entry.has_response_id()); @@ -226,7 +235,9 @@ TEST(AppCacheTest, FindResponseForRequest) { network_namespace = false; // reset found = cache->FindResponseForRequest(kExplicitInOnlineNamespaceUrl, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_EQ(kExplicitInOnlineNamespaceResponseId, entry.response_id()); EXPECT_FALSE(fallback_entry.has_response_id()); @@ -235,7 +246,9 @@ TEST(AppCacheTest, FindResponseForRequest) { entry = AppCacheEntry(); // reset found = cache->FindResponseForRequest(kFallbackTestUrl1, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_EQ(kFallbackResponseId1, fallback_entry.response_id()); @@ -246,7 +259,9 @@ TEST(AppCacheTest, FindResponseForRequest) { fallback_entry = AppCacheEntry(); // reset found = cache->FindResponseForRequest(kFallbackTestUrl2, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_EQ(kFallbackResponseId2, fallback_entry.response_id()); @@ -257,7 +272,9 @@ TEST(AppCacheTest, FindResponseForRequest) { fallback_entry = AppCacheEntry(); // reset found = cache->FindResponseForRequest(kOnlineNamespaceWithinOtherNamespaces, - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_FALSE(fallback_entry.has_response_id()); @@ -267,28 +284,42 @@ TEST(AppCacheTest, FindResponseForRequest) { found = cache->FindResponseForRequest( kOnlineNamespaceWithinOtherNamespaces.Resolve("online_resource"), - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_FALSE(fallback_entry.has_response_id()); EXPECT_TRUE(network_namespace); + fallback_namespace = GURL(); + found = cache->FindResponseForRequest( kInterceptNamespace.Resolve("intercept_me"), - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_EQ(kInterceptResponseId, entry.response_id()); + EXPECT_EQ(kInterceptNamespaceEntry, + cache->GetInterceptEntryUrl(intercept_namespace)); EXPECT_FALSE(fallback_entry.has_response_id()); + EXPECT_TRUE(fallback_namespace.is_empty()); EXPECT_FALSE(network_namespace); entry = AppCacheEntry(); // reset found = cache->FindResponseForRequest( kInterceptNamespaceWithinFallback.Resolve("intercept_me"), - &entry, &fallback_entry, &fallback_namespace, &network_namespace); + &entry, &intercept_namespace, + &fallback_entry, &fallback_namespace, + &network_namespace); EXPECT_TRUE(found); EXPECT_EQ(kInterceptResponseId, entry.response_id()); + EXPECT_EQ(kInterceptNamespaceEntry, + cache->GetInterceptEntryUrl(intercept_namespace)); EXPECT_FALSE(fallback_entry.has_response_id()); + EXPECT_TRUE(fallback_namespace.is_empty()); EXPECT_FALSE(network_namespace); } diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc index 7a68ca2..bd8ddc8 100644 --- a/webkit/appcache/appcache_update_job.cc +++ b/webkit/appcache/appcache_update_job.cc @@ -552,7 +552,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLFetcher* fetcher) { // TODO(michaeln): Check for <html manifest=xxx> // See http://code.google.com/p/chromium/issues/detail?id=97930 - // if (entry.IsMaster() && !entry.IsExplicit()) + // if (entry.IsMaster() && !(entry.IsExplicit() || fallback || intercept)) // if (!manifestAttribute) skip it // Foreign entries will be detected during cache selection. @@ -564,7 +564,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLFetcher* fetcher) { VLOG(1) << "Request status: " << request->status().status() << " error: " << request->status().error() << " response code: " << response_code; - if (entry.IsExplicit() || entry.IsFallback()) { + if (entry.IsExplicit() || entry.IsFallback() || entry.IsIntercept()) { if (response_code == 304 && fetcher->existing_entry().has_response_id()) { // Keep the existing response. entry.set_response_id(fetcher->existing_entry().response_id()); @@ -976,9 +976,8 @@ bool AppCacheUpdateJob::ShouldSkipUrlFetch(const AppCacheEntry& entry) { // If the resource URL being processed was flagged as neither an // "explicit entry" nor or a "fallback entry", then the user agent // may skip this URL. - if (entry.IsExplicit() || entry.IsFallback()) { + if (entry.IsExplicit() || entry.IsFallback() || entry.IsIntercept()) return false; - } // TODO(jennb): decide if entry should be skipped to expire it from cache return false; diff --git a/webkit/appcache/mock_appcache_storage.cc b/webkit/appcache/mock_appcache_storage.cc index 4353390..2fa1d04 100644 --- a/webkit/appcache/mock_appcache_storage.cc +++ b/webkit/appcache/mock_appcache_storage.cc @@ -121,9 +121,11 @@ void MockAppCacheStorage::FindResponseForSubRequest( } GURL fallback_namespace_not_used; + GURL intercept_namespace_not_used; cache->FindResponseForRequest( - url, found_entry, found_fallback_entry, - &fallback_namespace_not_used, found_network_namespace); + url, found_entry, &intercept_namespace_not_used, + found_fallback_entry, &fallback_namespace_not_used, + found_network_namespace); } void MockAppCacheStorage::MarkEntryAsForeign( @@ -232,7 +234,7 @@ void MockAppCacheStorage::ProcessStoreGroupAndNewestCache( namespace { struct FoundCandidate { - GURL url; + GURL namespace_entry_url; AppCacheEntry entry; int64 cache_id; int64 group_id; @@ -243,6 +245,53 @@ struct FoundCandidate { : cache_id(kNoCacheId), group_id(0), is_cache_in_use(false) {} }; +void MaybeTakeNewNamespaceEntry( + NamespaceType namespace_type, + const AppCacheEntry &entry, + const GURL& namespace_url, + bool cache_is_in_use, + FoundCandidate* best_candidate, + GURL* best_candidate_namespace, + AppCache* cache, + AppCacheGroup* group) { + DCHECK(entry.has_response_id()); + + bool take_new_entry = true; + + // Does the new candidate entry trump our current best candidate? + if (best_candidate->entry.has_response_id()) { + // Longer namespace prefix matches win. + size_t candidate_length = + namespace_url.spec().length(); + size_t best_length = + best_candidate_namespace->spec().length(); + + if (candidate_length > best_length) { + take_new_entry = true; + } else if (candidate_length == best_length && + cache_is_in_use && !best_candidate->is_cache_in_use) { + take_new_entry = true; + } else { + take_new_entry = false; + } + } + + if (take_new_entry) { + if (namespace_type == FALLBACK_NAMESPACE) { + best_candidate->namespace_entry_url = + cache->GetFallbackEntryUrl(namespace_url); + } else { + best_candidate->namespace_entry_url = + cache->GetInterceptEntryUrl(namespace_url); + } + best_candidate->entry = entry; + best_candidate->cache_id = cache->cache_id(); + best_candidate->group_id = group->group_id(); + best_candidate->manifest_url = group->manifest_url(); + best_candidate->is_cache_in_use = cache_is_in_use; + *best_candidate_namespace = namespace_url; + } +} } // namespace void MockAppCacheStorage::ProcessFindResponseForMainRequest( @@ -273,6 +322,7 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( // * take into account the cache associated with the document // currently residing in the frame being navigated FoundCandidate found_candidate; + GURL found_intercept_candidate_namespace; FoundCandidate found_fallback_candidate; GURL found_fallback_candidate_namespace; @@ -287,11 +337,12 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( AppCacheEntry found_entry; AppCacheEntry found_fallback_entry; + GURL found_intercept_namespace; GURL found_fallback_namespace; bool ignore_found_network_namespace = false; bool found = cache->FindResponseForRequest( - url, &found_entry, &found_fallback_entry, - &found_fallback_namespace, + url, &found_entry, &found_intercept_namespace, + &found_fallback_entry, &found_fallback_namespace, &ignore_found_network_namespace); // 6.11.1 Navigating across documents, Step 10. @@ -307,8 +358,9 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( // We have a bias for hits from caches that are in use. bool is_in_use = IsCacheStored(cache) && !cache->HasOneRef(); - if (found_entry.has_response_id()) { - found_candidate.url = url; + if (found_entry.has_response_id() && + found_intercept_namespace.is_empty()) { + found_candidate.namespace_entry_url = GURL(); found_candidate.entry = found_entry; found_candidate.cache_id = cache->cache_id(); found_candidate.group_id = group->group_id(); @@ -316,47 +368,28 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( found_candidate.is_cache_in_use = is_in_use; if (is_in_use) break; // We break out of the loop with this direct hit. + } else if (found_entry.has_response_id() && + !found_intercept_namespace.is_empty()) { + MaybeTakeNewNamespaceEntry( + INTERCEPT_NAMESPACE, + found_entry, found_intercept_namespace, is_in_use, + &found_candidate, &found_intercept_candidate_namespace, + cache, group); } else { DCHECK(found_fallback_entry.has_response_id()); - - bool take_new_candidate = true; - - // Does the newly found entry trump our current candidate? - if (found_fallback_candidate.entry.has_response_id()) { - // Longer namespace prefix matches win. - size_t found_length = - found_fallback_namespace.spec().length(); - size_t candidate_length = - found_fallback_candidate_namespace.spec().length(); - - if (found_length > candidate_length) { - take_new_candidate = true; - } else if (found_length == candidate_length && - is_in_use && !found_fallback_candidate.is_cache_in_use) { - take_new_candidate = true; - } else { - take_new_candidate = false; - } - } - - if (take_new_candidate) { - found_fallback_candidate.url = - cache->GetFallbackEntryUrl(found_fallback_namespace); - found_fallback_candidate.entry = found_fallback_entry; - found_fallback_candidate.cache_id = cache->cache_id(); - found_fallback_candidate.group_id = group->group_id(); - found_fallback_candidate.manifest_url = group->manifest_url(); - found_fallback_candidate.is_cache_in_use = is_in_use; - found_fallback_candidate_namespace = found_fallback_namespace; - } + MaybeTakeNewNamespaceEntry( + FALLBACK_NAMESPACE, + found_fallback_entry, found_fallback_namespace, is_in_use, + &found_fallback_candidate, &found_fallback_candidate_namespace, + cache, group); } } - // Found a direct hit. + // Found a direct hit or an intercept namespace hit. if (found_candidate.entry.has_response_id()) { delegate_ref->delegate->OnMainResponseFound( - url, found_candidate.entry, GURL(), AppCacheEntry(), - found_candidate.cache_id, found_candidate.group_id, + url, found_candidate.entry, found_candidate.namespace_entry_url, + AppCacheEntry(), found_candidate.cache_id, found_candidate.group_id, found_candidate.manifest_url); return; } @@ -365,7 +398,7 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( if (found_fallback_candidate.entry.has_response_id()) { delegate_ref->delegate->OnMainResponseFound( url, AppCacheEntry(), - found_fallback_candidate.url, + found_fallback_candidate.namespace_entry_url, found_fallback_candidate.entry, found_fallback_candidate.cache_id, found_fallback_candidate.group_id, |