Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: webkit/appcache/appcache_request_handler.cc

Issue 7720022: Third-party appcache blocking. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Code review comments (not all). Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/appcache/appcache_request_handler.h" 5 #include "webkit/appcache/appcache_request_handler.h"
6 6
7 #include "net/url_request/url_request.h" 7 #include "net/url_request/url_request.h"
8 #include "net/url_request/url_request_job.h" 8 #include "net/url_request/url_request_job.h"
9 #include "webkit/appcache/appcache.h" 9 #include "webkit/appcache/appcache.h"
10 #include "webkit/appcache/appcache_policy.h"
10 #include "webkit/appcache/appcache_url_request_job.h" 11 #include "webkit/appcache/appcache_url_request_job.h"
11 12
12 namespace appcache { 13 namespace appcache {
13 14
14 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host, 15 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host,
15 ResourceType::Type resource_type) 16 ResourceType::Type resource_type)
16 : host_(host), resource_type_(resource_type), 17 : host_(host), resource_type_(resource_type),
17 is_waiting_for_cache_selection_(false), found_cache_id_(0), 18 is_waiting_for_cache_selection_(false), found_cache_id_(0),
18 found_network_namespace_(false), cache_entry_not_found_(false) { 19 found_network_namespace_(false), cache_entry_not_found_(false) {
19 DCHECK(host_); 20 DCHECK(host_);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // We may have to wait for our storage query to complete, but 210 // We may have to wait for our storage query to complete, but
210 // this query can also complete syncrhonously. 211 // this query can also complete syncrhonously.
211 job_ = new AppCacheURLRequestJob(request, storage()); 212 job_ = new AppCacheURLRequestJob(request, storage());
212 storage()->FindResponseForMainRequest( 213 storage()->FindResponseForMainRequest(
213 request->url(), preferred_manifest_url, this); 214 request->url(), preferred_manifest_url, this);
214 } 215 }
215 216
216 void AppCacheRequestHandler::OnMainResponseFound( 217 void AppCacheRequestHandler::OnMainResponseFound(
217 const GURL& url, const AppCacheEntry& entry, 218 const GURL& url, const AppCacheEntry& entry,
218 const GURL& fallback_url, const AppCacheEntry& fallback_entry, 219 const GURL& fallback_url, const AppCacheEntry& fallback_entry,
219 int64 cache_id, const GURL& manifest_url, 220 int64 cache_id, const GURL& manifest_url) {
220 bool was_blocked_by_policy) {
221 DCHECK(host_); 221 DCHECK(host_);
222 DCHECK(is_main_resource()); 222 DCHECK(is_main_resource());
223 DCHECK(!entry.IsForeign()); 223 DCHECK(!entry.IsForeign());
224 DCHECK(!fallback_entry.IsForeign()); 224 DCHECK(!fallback_entry.IsForeign());
225 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); 225 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id()));
226 226
227 AppCachePolicy* policy = host_->service()->appcache_policy();
228 bool was_blocked_by_policy = policy &&
229 !policy->CanLoadAppCache(manifest_url, host_->first_party_url());
230
227 if (ResourceType::IsFrame(resource_type_)) { 231 if (ResourceType::IsFrame(resource_type_)) {
228 if (was_blocked_by_policy) 232 if (was_blocked_by_policy)
229 host_->NotifyMainResourceBlocked(manifest_url); 233 host_->NotifyMainResourceBlocked(manifest_url);
230 234
231 if (cache_id != kNoCacheId) { 235 else if (cache_id != kNoCacheId) {
232 // AppCacheHost loads and holds a reference to the main resource cache 236 // AppCacheHost loads and holds a reference to the main resource cache
233 // for two reasons, firstly to preload the cache into the working set 237 // for two reasons, firstly to preload the cache into the working set
234 // in advance of subresource loads happening, secondly to prevent the 238 // in advance of subresource loads happening, secondly to prevent the
235 // AppCache from falling out of the working set on frame navigations. 239 // AppCache from falling out of the working set on frame navigations.
236 host_->LoadMainResourceCache(cache_id); 240 host_->LoadMainResourceCache(cache_id);
237 host_->set_preferred_manifest_url(manifest_url); 241 host_->set_preferred_manifest_url(manifest_url);
238 } 242 }
239 } else { 243 } else {
240 DCHECK(ResourceType::IsSharedWorker(resource_type_)); 244 DCHECK(ResourceType::IsSharedWorker(resource_type_));
241 if (was_blocked_by_policy) 245 if (was_blocked_by_policy)
242 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); 246 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url);
243 } 247 }
244 248
249 if (was_blocked_by_policy) {
250 DeliverNetworkResponse();
251 return;
252 }
253
245 // 6.11.1 Navigating across documents, steps 10 and 14. 254 // 6.11.1 Navigating across documents, steps 10 and 14.
246 255
247 found_entry_ = entry; 256 found_entry_ = entry;
248 found_fallback_url_ = fallback_url; 257 found_fallback_url_ = fallback_url;
249 found_fallback_entry_ = fallback_entry; 258 found_fallback_entry_ = fallback_entry;
250 found_cache_id_ = cache_id; 259 found_cache_id_ = cache_id;
251 found_manifest_url_ = manifest_url; 260 found_manifest_url_ = manifest_url;
252 found_network_namespace_ = false; // not applicable to main requests 261 found_network_namespace_ = false; // not applicable to main requests
253 262
254 if (found_entry_.has_response_id()) { 263 if (found_entry_.has_response_id()) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (!host_->associated_cache() || 353 if (!host_->associated_cache() ||
345 !host_->associated_cache()->is_complete()) { 354 !host_->associated_cache()->is_complete()) {
346 DeliverNetworkResponse(); 355 DeliverNetworkResponse();
347 return; 356 return;
348 } 357 }
349 358
350 ContinueMaybeLoadSubResource(); 359 ContinueMaybeLoadSubResource();
351 } 360 }
352 361
353 } // namespace appcache 362 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698