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

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

Issue 2398733003: Cache SubResourceIntegrity checks at Resource (Closed)
Patch Set: 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"
30 #include "core/fetch/MemoryCache.h" 31 #include "core/fetch/MemoryCache.h"
31 #include "core/fetch/ResourceClient.h" 32 #include "core/fetch/ResourceClient.h"
32 #include "core/fetch/ResourceClientWalker.h" 33 #include "core/fetch/ResourceClientWalker.h"
33 #include "core/fetch/ResourceLoader.h" 34 #include "core/fetch/ResourceLoader.h"
34 #include "core/inspector/InstanceCounters.h" 35 #include "core/inspector/InstanceCounters.h"
35 #include "platform/Histogram.h" 36 #include "platform/Histogram.h"
36 #include "platform/RuntimeEnabledFeatures.h" 37 #include "platform/RuntimeEnabledFeatures.h"
37 #include "platform/SharedBuffer.h" 38 #include "platform/SharedBuffer.h"
38 #include "platform/network/HTTPParsers.h" 39 #include "platform/network/HTTPParsers.h"
39 #include "platform/tracing/TraceEvent.h" 40 #include "platform/tracing/TraceEvent.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 m_preloadCount(0), 307 m_preloadCount(0),
307 m_preloadDiscoveryTime(0.0), 308 m_preloadDiscoveryTime(0.0),
308 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()), 309 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()),
309 m_preloadResult(PreloadNotReferenced), 310 m_preloadResult(PreloadNotReferenced),
310 m_type(type), 311 m_type(type),
311 m_status(NotStarted), 312 m_status(NotStarted),
312 m_needsSynchronousCacheHit(false), 313 m_needsSynchronousCacheHit(false),
313 m_linkPreload(false), 314 m_linkPreload(false),
314 m_isRevalidating(false), 315 m_isRevalidating(false),
315 m_isAlive(false), 316 m_isAlive(false),
317 m_integrityDisposition(ResourceIntegrityDisposition::NotChecked),
316 m_options(options), 318 m_options(options),
317 m_responseTimestamp(currentTime()), 319 m_responseTimestamp(currentTime()),
318 m_cancelTimer(this, &Resource::cancelTimerFired), 320 m_cancelTimer(this, &Resource::cancelTimerFired),
319 m_resourceRequest(request) { 321 m_resourceRequest(request) {
320 // m_type is a bitfield, so this tests careless updates of the enum. 322 // m_type is a bitfield, so this tests careless updates of the enum.
321 DCHECK_EQ(m_type, unsigned(type)); 323 DCHECK_EQ(m_type, unsigned(type));
322 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); 324 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter);
323 325
324 // Currently we support the metadata caching only for HTTP family. 326 // Currently we support the metadata caching only for HTTP family.
325 if (m_resourceRequest.url().protocolIsInHTTPFamily()) 327 if (m_resourceRequest.url().protocolIsInHTTPFamily())
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 securityOrigin, errorDescription, lastResourceRequest().requestContext()); 443 securityOrigin, errorDescription, lastResourceRequest().requestContext());
442 } 444 }
443 445
444 bool Resource::isEligibleForIntegrityCheck( 446 bool Resource::isEligibleForIntegrityCheck(
445 SecurityOrigin* securityOrigin) const { 447 SecurityOrigin* securityOrigin) const {
446 String ignoredErrorDescription; 448 String ignoredErrorDescription;
447 return securityOrigin->canRequest(resourceRequest().url()) || 449 return securityOrigin->canRequest(resourceRequest().url()) ||
448 passesAccessControlCheck(securityOrigin, ignoredErrorDescription); 450 passesAccessControlCheck(securityOrigin, ignoredErrorDescription);
449 } 451 }
450 452
453 void Resource::setIntegrityDisposition(
454 ResourceIntegrityDisposition disposition) {
455 DCHECK_NE(disposition, ResourceIntegrityDisposition::NotChecked);
456 DCHECK(m_type == Resource::Script);
457 m_integrityDisposition = disposition;
458 }
459
460 bool Resource::mustRefetchDueToIntegrityMetadata(
461 const FetchRequest& request) const {
462 if (request.integrityMetadata().isEmpty())
463 return false;
464
465 return !IntegrityMetadata::setsEqual(m_integrityMetadata,
jww 2016/10/06 20:42:45 nit: Please #include IntegrityMetadata.h
kouhei (in TOK) 2016/10/07 01:49:16 Done.
466 request.integrityMetadata());
467 }
468
451 static double currentAge(const ResourceResponse& response, 469 static double currentAge(const ResourceResponse& response,
452 double responseTimestamp) { 470 double responseTimestamp) {
453 // RFC2616 13.2.3 471 // RFC2616 13.2.3
454 // No compensation for latency as that is not terribly important in practice 472 // No compensation for latency as that is not terribly important in practice
455 double dateValue = response.date(); 473 double dateValue = response.date();
456 double apparentAge = std::isfinite(dateValue) 474 double apparentAge = std::isfinite(dateValue)
457 ? std::max(0., responseTimestamp - dateValue) 475 ? std::max(0., responseTimestamp - dateValue)
458 : 0; 476 : 0;
459 double ageValue = response.age(); 477 double ageValue = response.age();
460 double correctedReceivedAge = 478 double correctedReceivedAge =
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 case Resource::TextTrack: 1090 case Resource::TextTrack:
1073 case Resource::Media: 1091 case Resource::Media:
1074 case Resource::Manifest: 1092 case Resource::Manifest:
1075 return false; 1093 return false;
1076 } 1094 }
1077 NOTREACHED(); 1095 NOTREACHED();
1078 return false; 1096 return false;
1079 } 1097 }
1080 1098
1081 } // namespace blink 1099 } // 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