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

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

Issue 2420603003: Make DocumentThreadableLoader's cross origin logic clearer in terms of layering (Closed)
Patch Set: Rebase Created 4 years, 1 month 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 bool isOnAccessControlResponseHeaderWhitelist(const String& name) { 46 bool isOnAccessControlResponseHeaderWhitelist(const String& name) {
47 DEFINE_THREAD_SAFE_STATIC_LOCAL( 47 DEFINE_THREAD_SAFE_STATIC_LOCAL(
48 HTTPHeaderSet, allowedCrossOriginResponseHeaders, 48 HTTPHeaderSet, allowedCrossOriginResponseHeaders,
49 (new HTTPHeaderSet({ 49 (new HTTPHeaderSet({
50 "cache-control", "content-language", "content-type", "expires", 50 "cache-control", "content-language", "content-type", "expires",
51 "last-modified", "pragma", 51 "last-modified", "pragma",
52 }))); 52 })));
53 return allowedCrossOriginResponseHeaders.contains(name); 53 return allowedCrossOriginResponseHeaders.contains(name);
54 } 54 }
55 55
56 void updateRequestForAccessControl(ResourceRequest& request,
57 const SecurityOrigin* securityOrigin,
58 StoredCredentials allowCredentials) {
59 request.removeCredentials();
60 request.setAllowStoredCredentials(allowCredentials == AllowStoredCredentials);
61
62 if (securityOrigin)
63 request.setHTTPOrigin(securityOrigin);
64 }
65
66 // Fetch API Spec: https://fetch.spec.whatwg.org/#cors-preflight-fetch-0 56 // Fetch API Spec: https://fetch.spec.whatwg.org/#cors-preflight-fetch-0
67 static AtomicString createAccessControlRequestHeadersHeader( 57 static AtomicString createAccessControlRequestHeadersHeader(
68 const HTTPHeaderMap& headers) { 58 const HTTPHeaderMap& headers) {
69 Vector<String> filteredHeaders; 59 Vector<String> filteredHeaders;
70 for (const auto& header : headers) { 60 for (const auto& header : headers) {
71 if (FetchUtils::isSimpleHeader(header.key, header.value)) { 61 if (FetchUtils::isSimpleHeader(header.key, header.value)) {
72 // Exclude simple headers. 62 // Exclude simple headers.
73 continue; 63 continue;
74 } 64 }
75 if (equalIgnoringCase(header.key, "referer")) { 65 if (equalIgnoringCase(header.key, "referer")) {
(...skipping 14 matching lines...) Expand all
90 headerBuffer.append(", "); 80 headerBuffer.append(", ");
91 headerBuffer.append(header); 81 headerBuffer.append(header);
92 } 82 }
93 83
94 return AtomicString(headerBuffer.toString()); 84 return AtomicString(headerBuffer.toString());
95 } 85 }
96 86
97 ResourceRequest createAccessControlPreflightRequest( 87 ResourceRequest createAccessControlPreflightRequest(
98 const ResourceRequest& request, 88 const ResourceRequest& request,
99 const SecurityOrigin* securityOrigin) { 89 const SecurityOrigin* securityOrigin) {
100 ResourceRequest preflightRequest(request.url()); 90 const KURL& requestURL = request.url();
101 updateRequestForAccessControl(preflightRequest, securityOrigin, 91
102 DoNotAllowStoredCredentials); 92 DCHECK(requestURL.user().isEmpty());
93 DCHECK(requestURL.pass().isEmpty());
94
95 ResourceRequest preflightRequest(requestURL);
96 preflightRequest.setAllowStoredCredentials(false);
103 preflightRequest.setHTTPMethod(HTTPNames::OPTIONS); 97 preflightRequest.setHTTPMethod(HTTPNames::OPTIONS);
104 preflightRequest.setHTTPHeaderField(HTTPNames::Access_Control_Request_Method, 98 preflightRequest.setHTTPHeaderField(HTTPNames::Access_Control_Request_Method,
105 AtomicString(request.httpMethod())); 99 AtomicString(request.httpMethod()));
106 preflightRequest.setPriority(request.priority()); 100 preflightRequest.setPriority(request.priority());
107 preflightRequest.setRequestContext(request.requestContext()); 101 preflightRequest.setRequestContext(request.requestContext());
108 preflightRequest.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); 102 preflightRequest.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All);
109 103
110 if (request.isExternalRequest()) { 104 if (request.isExternalRequest()) {
111 preflightRequest.setHTTPHeaderField( 105 preflightRequest.setHTTPHeaderField(
112 HTTPNames::Access_Control_Request_External, "true"); 106 HTTPNames::Access_Control_Request_External, "true");
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // 427 //
434 // This is equivalent to the step 2 in 428 // This is equivalent to the step 2 in
435 // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch 429 // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch
436 if (options.credentialsRequested == ClientDidNotRequestCredentials) 430 if (options.credentialsRequested == ClientDidNotRequestCredentials)
437 options.allowCredentials = DoNotAllowStoredCredentials; 431 options.allowCredentials = DoNotAllowStoredCredentials;
438 } 432 }
439 return true; 433 return true;
440 } 434 }
441 435
442 } // namespace blink 436 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CrossOriginAccessControl.h ('k') | third_party/WebKit/Source/core/fetch/FetchRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698