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

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 2398733003: Cache SubResourceIntegrity checks at Resource (Closed)
Patch Set: add include Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
7 rights reserved. 7 rights reserved.
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either 11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version. 12 version 2 of the License, or (at your option) any later version.
13 13
14 This library is distributed in the hope that it will be useful, 14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details. 17 Library General Public License for more details.
18 18
19 You should have received a copy of the GNU Library General Public License 19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to 20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. 22 Boston, MA 02110-1301, USA.
23 */ 23 */
24 24
25 #include "core/fetch/Resource.h" 25 #include "core/fetch/Resource.h"
26 26
27 #include "core/fetch/CachedMetadata.h" 27 #include "core/fetch/CachedMetadata.h"
28 #include "core/fetch/CrossOriginAccessControl.h" 28 #include "core/fetch/CrossOriginAccessControl.h"
29 #include "core/fetch/FetchInitiatorTypeNames.h" 29 #include "core/fetch/FetchInitiatorTypeNames.h"
30 #include "core/fetch/FetchRequest.h"
31 #include "core/fetch/IntegrityMetadata.h"
30 #include "core/fetch/MemoryCache.h" 32 #include "core/fetch/MemoryCache.h"
31 #include "core/fetch/ResourceClient.h" 33 #include "core/fetch/ResourceClient.h"
32 #include "core/fetch/ResourceClientWalker.h" 34 #include "core/fetch/ResourceClientWalker.h"
33 #include "core/fetch/ResourceLoader.h" 35 #include "core/fetch/ResourceLoader.h"
34 #include "core/inspector/InstanceCounters.h" 36 #include "core/inspector/InstanceCounters.h"
35 #include "platform/Histogram.h" 37 #include "platform/Histogram.h"
36 #include "platform/RuntimeEnabledFeatures.h" 38 #include "platform/RuntimeEnabledFeatures.h"
37 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
38 #include "platform/network/HTTPParsers.h" 40 #include "platform/network/HTTPParsers.h"
39 #include "platform/tracing/TraceEvent.h" 41 #include "platform/tracing/TraceEvent.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 m_preloadCount(0), 308 m_preloadCount(0),
307 m_preloadDiscoveryTime(0.0), 309 m_preloadDiscoveryTime(0.0),
308 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()), 310 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()),
309 m_preloadResult(PreloadNotReferenced), 311 m_preloadResult(PreloadNotReferenced),
310 m_type(type), 312 m_type(type),
311 m_status(NotStarted), 313 m_status(NotStarted),
312 m_needsSynchronousCacheHit(false), 314 m_needsSynchronousCacheHit(false),
313 m_linkPreload(false), 315 m_linkPreload(false),
314 m_isRevalidating(false), 316 m_isRevalidating(false),
315 m_isAlive(false), 317 m_isAlive(false),
318 m_integrityDisposition(ResourceIntegrityDisposition::NotChecked),
316 m_options(options), 319 m_options(options),
317 m_responseTimestamp(currentTime()), 320 m_responseTimestamp(currentTime()),
318 m_cancelTimer(this, &Resource::cancelTimerFired), 321 m_cancelTimer(this, &Resource::cancelTimerFired),
319 m_resourceRequest(request) { 322 m_resourceRequest(request) {
320 // m_type is a bitfield, so this tests careless updates of the enum. 323 // m_type is a bitfield, so this tests careless updates of the enum.
321 DCHECK_EQ(m_type, unsigned(type)); 324 DCHECK_EQ(m_type, unsigned(type));
322 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); 325 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter);
323 326
324 // Currently we support the metadata caching only for HTTP family. 327 // Currently we support the metadata caching only for HTTP family.
325 if (m_resourceRequest.url().protocolIsInHTTPFamily()) 328 if (m_resourceRequest.url().protocolIsInHTTPFamily())
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 securityOrigin, errorDescription, lastResourceRequest().requestContext()); 444 securityOrigin, errorDescription, lastResourceRequest().requestContext());
442 } 445 }
443 446
444 bool Resource::isEligibleForIntegrityCheck( 447 bool Resource::isEligibleForIntegrityCheck(
445 SecurityOrigin* securityOrigin) const { 448 SecurityOrigin* securityOrigin) const {
446 String ignoredErrorDescription; 449 String ignoredErrorDescription;
447 return securityOrigin->canRequest(resourceRequest().url()) || 450 return securityOrigin->canRequest(resourceRequest().url()) ||
448 passesAccessControlCheck(securityOrigin, ignoredErrorDescription); 451 passesAccessControlCheck(securityOrigin, ignoredErrorDescription);
449 } 452 }
450 453
454 void Resource::setIntegrityDisposition(
455 ResourceIntegrityDisposition disposition) {
456 DCHECK_NE(disposition, ResourceIntegrityDisposition::NotChecked);
457 DCHECK(m_type == Resource::Script);
458 m_integrityDisposition = disposition;
459 }
460
461 bool Resource::mustRefetchDueToIntegrityMetadata(
462 const FetchRequest& request) const {
463 if (request.integrityMetadata().isEmpty())
464 return false;
465
466 return !IntegrityMetadata::setsEqual(m_integrityMetadata,
467 request.integrityMetadata());
468 }
469
451 static double currentAge(const ResourceResponse& response, 470 static double currentAge(const ResourceResponse& response,
452 double responseTimestamp) { 471 double responseTimestamp) {
453 // RFC2616 13.2.3 472 // RFC2616 13.2.3
454 // No compensation for latency as that is not terribly important in practice 473 // No compensation for latency as that is not terribly important in practice
455 double dateValue = response.date(); 474 double dateValue = response.date();
456 double apparentAge = std::isfinite(dateValue) 475 double apparentAge = std::isfinite(dateValue)
457 ? std::max(0., responseTimestamp - dateValue) 476 ? std::max(0., responseTimestamp - dateValue)
458 : 0; 477 : 0;
459 double ageValue = response.age(); 478 double ageValue = response.age();
460 double correctedReceivedAge = 479 double correctedReceivedAge =
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 case Resource::TextTrack: 1091 case Resource::TextTrack:
1073 case Resource::Media: 1092 case Resource::Media:
1074 case Resource::Manifest: 1093 case Resource::Manifest:
1075 return false; 1094 return false;
1076 } 1095 }
1077 NOTREACHED(); 1096 NOTREACHED();
1078 return false; 1097 return false;
1079 } 1098 }
1080 1099
1081 } // namespace blink 1100 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698