Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 requests are allowed only for those contexts when | |
|
Marijn Kruisselbrink
2016/05/12 17:30:37
The comment doesn't match the check. You're commen
horo
2016/05/16 06:24:19
Updated comment.
| |
| 209 // skipServiceWorker is not set. | |
| 210 SECURITY_CHECK(request.skipServiceWorker() || m_requestContext == We bURLRequest::RequestContextAudio || m_requestContext == WebURLRequest::RequestCo ntextVideo || m_requestContext == WebURLRequest::RequestContextObject || m_reque stContext == WebURLRequest::RequestContextFavicon || m_requestContext == WebURLR equest::RequestContextImage || m_requestContext == WebURLRequest::RequestContext Script); | |
| 211 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS ); | |
| 212 break; | |
| 213 } | |
| 214 if (m_resourceLoaderOptions.allowCredentials == AllowStoredCredentials) | |
| 215 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsMo deInclude); | |
| 216 else | |
| 217 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentialsMo deSameOrigin); | |
| 218 } | |
| 219 | |
| 189 // We assume that ServiceWorker is skipped for sync requests and unsupported | 220 // We assume that ServiceWorker is skipped for sync requests and unsupported |
| 190 // protocol requests by content/ code. | 221 // protocol requests by content/ code. |
| 191 if (m_async && !request.skipServiceWorker() && SchemeRegistry::shouldTreatUR LSchemeAsAllowingServiceWorkers(request.url().protocol()) && m_document->fetcher ()->isControlledByServiceWorker()) { | 222 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) { | 223 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORSWithForc edPreflight) { |
| 223 m_fallbackRequestForServiceWorker = ResourceRequest(request); | 224 m_fallbackRequestForServiceWorker = ResourceRequest(request); |
| 224 m_fallbackRequestForServiceWorker.setSkipServiceWorker(true); | 225 m_fallbackRequestForServiceWorker.setSkipServiceWorker(true); |
| 225 } | 226 } |
| 226 | |
| 227 loadRequest(newRequest, m_resourceLoaderOptions); | 227 loadRequest(newRequest, m_resourceLoaderOptions); |
| 228 // |this| may be dead here. | 228 // |this| may be dead here. |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 | 231 |
| 232 dispatchInitialRequest(request); | 232 dispatchInitialRequest(newRequest); |
| 233 // |this| may be dead here in async mode. | 233 // |this| may be dead here in async mode. |
| 234 } | 234 } |
| 235 | 235 |
| 236 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req uest) | 236 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req uest) |
| 237 { | 237 { |
| 238 if (!request.isExternalRequest() && (m_sameOriginRequest || m_options.crossO riginRequestPolicy == AllowCrossOriginRequests)) { | 238 if (!request.isExternalRequest() && (m_sameOriginRequest || m_options.crossO riginRequestPolicy == AllowCrossOriginRequests)) { |
| 239 loadRequest(request, m_resourceLoaderOptions); | 239 loadRequest(request, m_resourceLoaderOptions); |
| 240 // |this| may be dead here in async mode. | 240 // |this| may be dead here in async mode. |
| 241 return; | 241 return; |
| 242 } | 242 } |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin(); | 974 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin(); |
| 975 } | 975 } |
| 976 | 976 |
| 977 Document& DocumentThreadableLoader::document() const | 977 Document& DocumentThreadableLoader::document() const |
| 978 { | 978 { |
| 979 ASSERT(m_document); | 979 ASSERT(m_document); |
| 980 return *m_document; | 980 return *m_document; |
| 981 } | 981 } |
| 982 | 982 |
| 983 } // namespace blink | 983 } // namespace blink |
| OLD | NEW |