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

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentThreadableLoader.cpp

Issue 1976513002: Set the request mode and the credentials mode even if the request will not go to ServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment Created 4 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/ThreadableLoaderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation 3 * Copyright (C) 2013, Intel Corporation
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // recorded here. 179 // recorded here.
180 // - ThreadableLoader w/ non-GET request is only created from javascript 180 // - ThreadableLoader w/ non-GET request is only created from javascript
181 // initiated fetch. 181 // initiated fetch.
182 // - Some non-script initiated fetches such as WorkerScriptLoader also use 182 // - Some non-script initiated fetches such as WorkerScriptLoader also use
183 // ThreadableLoader, but they are guaranteed to use GET method. 183 // ThreadableLoader, but they are guaranteed to use GET method.
184 if (request.httpMethod() != HTTPNames::GET) { 184 if (request.httpMethod() != HTTPNames::GET) {
185 if (Page* page = m_document->page()) 185 if (Page* page = m_document->page())
186 page->chromeClient().didObserveNonGetFetchFromScript(); 186 page->chromeClient().didObserveNonGetFetchFromScript();
187 } 187 }
188 188
189 ResourceRequest newRequest(request);
190 if (m_requestContext != WebURLRequest::RequestContextFetch) {
191 // When the request context is not "fetch",
192 // |crossOriginRequestPolicy| represents the fetch request mode,
193 // and |credentialsRequested| represents the fetch credentials mode.
194 // So we set those flags here so that we can see the correct request
195 // mode and credentials mode in the service worker's fetch event
196 // handler.
197 switch (m_options.crossOriginRequestPolicy) {
198 case DenyCrossOriginRequests:
199 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeSameOr igin);
200 break;
201 case UseAccessControl:
202 if (m_options.preflightPolicy == ForcePreflight)
203 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCO RSWithForcedPreflight);
204 else
205 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCO RS);
206 break;
207 case AllowCrossOriginRequests:
208 // No-CORS is allowed for all these contexts, and plugin contexts
kinuko 2016/05/16 09:59:16 nit: "No-CORS requests are allowed for..." for con
horo 2016/05/16 10:14:34 Done.
209 // with private permission when we set skipServiceWorker flag in
210 // PepperURLLoaderHost.
211 SECURITY_CHECK(m_requestContext == WebURLRequest::RequestContextAudi o || m_requestContext == WebURLRequest::RequestContextVideo || m_requestContext == WebURLRequest::RequestContextObject || m_requestContext == WebURLRequest::Req uestContextFavicon || m_requestContext == WebURLRequest::RequestContextImage || m_requestContext == WebURLRequest::RequestContextScript || (request.skipServiceW orker() && m_requestContext == WebURLRequest::RequestContextPlugin));
kinuko 2016/05/16 09:59:16 nit: the line's going too long / too hard to read,
horo 2016/05/16 10:14:34 Introduced IsNoCORSAllowedContext().
212 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS );
213 break;
214 }
215 if (m_resourceLoaderOptions.allowCredentials == AllowStoredCredentials)
216 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsMo deInclude);
217 else
218 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsMo deSameOrigin);
219 }
220
189 // We assume that ServiceWorker is skipped for sync requests and unsupported 221 // We assume that ServiceWorker is skipped for sync requests and unsupported
190 // protocol requests by content/ code. 222 // protocol requests by content/ code.
191 if (m_async && !request.skipServiceWorker() && SchemeRegistry::shouldTreatUR LSchemeAsAllowingServiceWorkers(request.url().protocol()) && m_document->fetcher ()->isControlledByServiceWorker()) { 223 if (m_async && !request.skipServiceWorker() && SchemeRegistry::shouldTreatUR LSchemeAsAllowingServiceWorkers(request.url().protocol()) && m_document->fetcher ()->isControlledByServiceWorker()) {
192 ResourceRequest newRequest(request);
193 const WebURLRequest::RequestContext requestContext(request.requestContex t());
194 if (requestContext != WebURLRequest::RequestContextFetch) {
195 // When the request context is not "fetch",
196 // |crossOriginRequestPolicy| represents the fetch request mode,
197 // and |credentialsRequested| represents the fetch credentials mode.
198 // So we set those flags here so that we can see the correct request
199 // mode and credentials mode in the service worker's fetch event
200 // handler.
201 switch (m_options.crossOriginRequestPolicy) {
202 case DenyCrossOriginRequests:
203 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeSa meOrigin);
204 break;
205 case UseAccessControl:
206 if (m_options.preflightPolicy == ForcePreflight)
207 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestMo deCORSWithForcedPreflight);
208 else
209 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestMo deCORS);
210 break;
211 case AllowCrossOriginRequests:
212 // No-CORS requests are allowed only for those contexts.
213 SECURITY_CHECK(requestContext == WebURLRequest::RequestContextAu dio || requestContext == WebURLRequest::RequestContextVideo || requestContext == WebURLRequest::RequestContextObject || requestContext == WebURLRequest::Request ContextFavicon || requestContext == WebURLRequest::RequestContextImage || reques tContext == WebURLRequest::RequestContextScript);
214 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeNo CORS);
215 break;
216 }
217 if (m_resourceLoaderOptions.allowCredentials == AllowStoredCredentia ls)
218 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentia lsModeInclude);
219 else
220 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentia lsModeSameOrigin);
221 }
222 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORSWithForc edPreflight) { 224 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORSWithForc edPreflight) {
223 m_fallbackRequestForServiceWorker = ResourceRequest(request); 225 m_fallbackRequestForServiceWorker = ResourceRequest(request);
224 m_fallbackRequestForServiceWorker.setSkipServiceWorker(true); 226 m_fallbackRequestForServiceWorker.setSkipServiceWorker(true);
225 } 227 }
226
227 loadRequest(newRequest, m_resourceLoaderOptions); 228 loadRequest(newRequest, m_resourceLoaderOptions);
228 // |this| may be dead here. 229 // |this| may be dead here.
229 return; 230 return;
230 } 231 }
231 232
232 dispatchInitialRequest(request); 233 dispatchInitialRequest(newRequest);
233 // |this| may be dead here in async mode. 234 // |this| may be dead here in async mode.
234 } 235 }
235 236
236 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req uest) 237 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req uest)
237 { 238 {
238 if (!request.isExternalRequest() && (m_sameOriginRequest || m_options.crossO riginRequestPolicy == AllowCrossOriginRequests)) { 239 if (!request.isExternalRequest() && (m_sameOriginRequest || m_options.crossO riginRequestPolicy == AllowCrossOriginRequests)) {
239 loadRequest(request, m_resourceLoaderOptions); 240 loadRequest(request, m_resourceLoaderOptions);
240 // |this| may be dead here in async mode. 241 // |this| may be dead here in async mode.
241 return; 242 return;
242 } 243 }
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin(); 975 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin();
975 } 976 }
976 977
977 Document& DocumentThreadableLoader::document() const 978 Document& DocumentThreadableLoader::document() const
978 { 979 {
979 ASSERT(m_document); 980 ASSERT(m_document);
980 return *m_document; 981 return *m_document;
981 } 982 }
982 983
983 } // namespace blink 984 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/loader/ThreadableLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698