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

Side by Side Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 1196423003: Improve console log message for CORS failure (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 6 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) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 sourceOrigin = context().securityOrigin(); 194 sourceOrigin = context().securityOrigin();
195 195
196 if (sourceOrigin->canRequest(url)) 196 if (sourceOrigin->canRequest(url))
197 return true; 197 return true;
198 198
199 String errorDescription; 199 String errorDescription;
200 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) { 200 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) {
201 resource->setCORSFailed(); 201 resource->setCORSFailed();
202 if (!forPreload && (logErrorsDecision == ShouldLogAccessControlErrors)) { 202 if (!forPreload && (logErrorsDecision == ShouldLogAccessControlErrors)) {
203 String resourceType = Resource::resourceTypeToString(resource->type( ), resource->options().initiatorInfo); 203 String resourceType = Resource::resourceTypeToString(resource->type( ), resource->options().initiatorInfo);
204 context().addConsoleMessage(resourceType + " from origin '" + Securi tyOrigin::create(url)->toString() + "' has been blocked from loading by Cross-Or igin Resource Sharing policy: " + errorDescription); 204 context().addConsoleMessage("Access to " + resourceType + " from ori gin '" + SecurityOrigin::create(url)->toString() + "' has been blocked by Cross- Origin Resource Sharing policy: " + errorDescription);
205 } 205 }
206 return false; 206 return false;
207 } 207 }
208 return true; 208 return true;
209 } 209 }
210 210
211 bool ResourceFetcher::isControlledByServiceWorker() const 211 bool ResourceFetcher::isControlledByServiceWorker() const
212 { 212 {
213 return context().isControlledByServiceWorker(); 213 return context().isControlledByServiceWorker();
214 } 214 }
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 bool ResourceFetcher::defersLoading() const 932 bool ResourceFetcher::defersLoading() const
933 { 933 {
934 return context().defersLoading(); 934 return context().defersLoading();
935 } 935 }
936 936
937 bool ResourceFetcher::isLoadedBy(ResourceFetcher* possibleOwner) const 937 bool ResourceFetcher::isLoadedBy(ResourceFetcher* possibleOwner) const
938 { 938 {
939 return this == possibleOwner; 939 return this == possibleOwner;
940 } 940 }
941 941
942 bool ResourceFetcher::canAccessRedirect(Resource* resource, ResourceRequest& req uest, const ResourceResponse& redirectResponse, ResourceLoaderOptions& options) 942 bool ResourceFetcher::canAccessRedirect(Resource* resource, ResourceRequest& new Request, const ResourceResponse& redirectResponse, ResourceLoaderOptions& option s)
943 { 943 {
944 if (!context().canRequest(resource->type(), request, request.url(), options, resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestrictionForType)) 944 if (!context().canRequest(resource->type(), newRequest, newRequest.url(), op tions, resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestrictionFor Type))
945 return false; 945 return false;
946 if (options.corsEnabled == IsCORSEnabled) { 946 if (options.corsEnabled == IsCORSEnabled) {
947 SecurityOrigin* sourceOrigin = options.securityOrigin.get(); 947 SecurityOrigin* sourceOrigin = options.securityOrigin.get();
948 if (!sourceOrigin) 948 if (!sourceOrigin)
949 sourceOrigin = context().securityOrigin(); 949 sourceOrigin = context().securityOrigin();
950 950
951 String errorMessage; 951 String errorMessage;
952 StoredCredentials withCredentials = resource->lastResourceRequest().allo wStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; 952 StoredCredentials withCredentials = resource->lastResourceRequest().allo wStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials;
953 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, request, red irectResponse, withCredentials, options, errorMessage)) { 953 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newRequest, redirectResponse, withCredentials, options, errorMessage)) {
954 resource->setCORSFailed(); 954 resource->setCORSFailed();
955 context().addConsoleMessage(errorMessage); 955 context().addConsoleMessage(errorMessage);
956 return false; 956 return false;
957 } 957 }
958 } 958 }
959 if (resource->type() == Resource::Image && shouldDeferImageLoad(request.url( ))) 959 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u rl()))
960 return false; 960 return false;
961 return true; 961 return true;
962 } 962 }
963 963
964 #if PRELOAD_DEBUG 964 #if PRELOAD_DEBUG
965 void ResourceFetcher::printPreloadStats() 965 void ResourceFetcher::printPreloadStats()
966 { 966 {
967 if (!m_preloads) 967 if (!m_preloads)
968 return; 968 return;
969 969
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 1059
1060 DEFINE_TRACE(ResourceFetcher) 1060 DEFINE_TRACE(ResourceFetcher)
1061 { 1061 {
1062 visitor->trace(m_context); 1062 visitor->trace(m_context);
1063 visitor->trace(m_archiveResourceCollection); 1063 visitor->trace(m_archiveResourceCollection);
1064 visitor->trace(m_loaders); 1064 visitor->trace(m_loaders);
1065 visitor->trace(m_nonBlockingLoaders); 1065 visitor->trace(m_nonBlockingLoaders);
1066 } 1066 }
1067 1067
1068 } 1068 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698