| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/serviceworkers/ForeignFetchRespondWithObserver.h" | 5 #include "modules/serviceworkers/ForeignFetchRespondWithObserver.h" |
| 6 | 6 |
| 7 #include "core/fetch/CrossOriginAccessControl.h" |
| 7 #include "modules/serviceworkers/ForeignFetchResponse.h" | 8 #include "modules/serviceworkers/ForeignFetchResponse.h" |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 11 ForeignFetchRespondWithObserver* ForeignFetchRespondWithObserver::create(Executi
onContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchReq
uestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::Request
Context requestContext, PassRefPtr<SecurityOrigin> requestOrigin) | 12 ForeignFetchRespondWithObserver* ForeignFetchRespondWithObserver::create(Executi
onContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchReq
uestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::Request
Context requestContext, PassRefPtr<SecurityOrigin> requestOrigin) |
| 12 { | 13 { |
| 13 return new ForeignFetchRespondWithObserver(context, eventID, requestURL, req
uestMode, frameType, requestContext, requestOrigin); | 14 return new ForeignFetchRespondWithObserver(context, eventID, requestURL, req
uestMode, frameType, requestContext, requestOrigin); |
| 14 } | 15 } |
| 15 | 16 |
| 16 void ForeignFetchRespondWithObserver::responseWasFulfilled(const ScriptValue& va
lue) | 17 void ForeignFetchRespondWithObserver::responseWasFulfilled(const ScriptValue& va
lue) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 // If response isn't already opaque, make it opaque. | 39 // If response isn't already opaque, make it opaque. |
| 39 if (!isOpaque) { | 40 if (!isOpaque) { |
| 40 FetchResponseData* opaqueData = internalResponse->createOpaqueFilter
edResponse(); | 41 FetchResponseData* opaqueData = internalResponse->createOpaqueFilter
edResponse(); |
| 41 response = Response::create(getExecutionContext(), opaqueData); | 42 response = Response::create(getExecutionContext(), opaqueData); |
| 42 } | 43 } |
| 43 } else if (m_requestOrigin->toString() != foreignFetchResponse.origin()) { | 44 } else if (m_requestOrigin->toString() != foreignFetchResponse.origin()) { |
| 44 responseWasRejected(WebServiceWorkerResponseErrorForeignFetchMismatchedO
rigin); | 45 responseWasRejected(WebServiceWorkerResponseErrorForeignFetchMismatchedO
rigin); |
| 45 return; | 46 return; |
| 46 } else if (!isOpaque) { | 47 } else if (!isOpaque) { |
| 47 // TODO(mek): Handle |headers| response attribute, and properly filter r
esponse. | 48 HTTPHeaderSet headers; |
| 49 if (foreignFetchResponse.hasHeaders()) { |
| 50 for (const String& header : foreignFetchResponse.headers()) |
| 51 headers.add(header); |
| 52 if (response->response()->getType() == FetchResponseData::CORSType)
{ |
| 53 const HTTPHeaderSet& existingHeaders = response->response()->cor
sExposedHeaderNames(); |
| 54 HTTPHeaderSet headersToRemove; |
| 55 for (HTTPHeaderSet::iterator it = headers.begin(); it != headers
.end(); ++it) { |
| 56 if (!existingHeaders.contains(*it)) |
| 57 headersToRemove.add(*it); |
| 58 } |
| 59 headers.removeAll(headersToRemove); |
| 60 } |
| 61 } |
| 62 FetchResponseData* responseData = internalResponse->createCORSFilteredRe
sponse(headers); |
| 63 response = Response::create(getExecutionContext(), responseData); |
| 48 } | 64 } |
| 49 | 65 |
| 50 RespondWithObserver::responseWasFulfilled(ScriptValue::from(value.getScriptS
tate(), response)); | 66 RespondWithObserver::responseWasFulfilled(ScriptValue::from(value.getScriptS
tate(), response)); |
| 51 } | 67 } |
| 52 | 68 |
| 53 ForeignFetchRespondWithObserver::ForeignFetchRespondWithObserver(ExecutionContex
t* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode
requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext
requestContext, PassRefPtr<SecurityOrigin> requestOrigin) | 69 ForeignFetchRespondWithObserver::ForeignFetchRespondWithObserver(ExecutionContex
t* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode
requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext
requestContext, PassRefPtr<SecurityOrigin> requestOrigin) |
| 54 : RespondWithObserver(context, eventID, requestURL, requestMode, frameType,
requestContext) | 70 : RespondWithObserver(context, eventID, requestURL, requestMode, frameType,
requestContext) |
| 55 , m_requestOrigin(requestOrigin) | 71 , m_requestOrigin(requestOrigin) |
| 56 { | 72 { |
| 57 } | 73 } |
| 58 | 74 |
| 59 } // namespace blink | 75 } // namespace blink |
| OLD | NEW |