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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/ForeignFetchRespondWithObserver.cpp

Issue 1969403004: Expose and check origin of request in response for foreign fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@set-request-and-credentials-mode
Patch Set: update layouttests 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/serviceworkers/ForeignFetchRespondWithObserver.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ForeignFetchRespondWithObserver.cpp b/third_party/WebKit/Source/modules/serviceworkers/ForeignFetchRespondWithObserver.cpp
index a707f7165010cdc194065fac50be487dee8002c9..8cdedbdf4b7521c5ac8ca9f968a5095784103728 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/ForeignFetchRespondWithObserver.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/ForeignFetchRespondWithObserver.cpp
@@ -8,9 +8,9 @@
namespace blink {
-ForeignFetchRespondWithObserver* ForeignFetchRespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext)
+ForeignFetchRespondWithObserver* ForeignFetchRespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext, PassRefPtr<SecurityOrigin> requestOrigin)
{
- return new ForeignFetchRespondWithObserver(context, eventID, requestURL, requestMode, frameType, requestContext);
+ return new ForeignFetchRespondWithObserver(context, eventID, requestURL, requestMode, frameType, requestContext, requestOrigin);
}
void ForeignFetchRespondWithObserver::responseWasFulfilled(const ScriptValue& value)
@@ -23,13 +23,36 @@ void ForeignFetchRespondWithObserver::responseWasFulfilled(const ScriptValue& va
return;
}
- // TODO(mek): Handle foreign fetch specific response parameters.
Response* response = foreignFetchResponse.response();
+ const FetchResponseData* internalResponse = response->response();
+ const bool isOpaque = internalResponse->getType() == FetchResponseData::OpaqueType || internalResponse->getType() == FetchResponseData::OpaqueRedirectType;
+ if (internalResponse->getType() != FetchResponseData::DefaultType)
+ internalResponse = internalResponse->internalResponse();
+
+ if (!foreignFetchResponse.hasOrigin()) {
+ if (foreignFetchResponse.hasHeaders() && !foreignFetchResponse.headers().isEmpty()) {
+ responseWasRejected(WebServiceWorkerResponseErrorForeignFetchHeadersWithoutOrigin);
+ return;
+ }
+
+ // If response isn't already opaque, make it opaque.
+ if (!isOpaque) {
+ FetchResponseData* opaqueData = internalResponse->createOpaqueFilteredResponse();
+ response = Response::create(getExecutionContext(), opaqueData);
+ }
+ } else if (m_requestOrigin->toString() != foreignFetchResponse.origin()) {
Nate Chapin 2016/05/17 17:39:22 I don't know the spec well enough to know exactly
Marijn Kruisselbrink 2016/05/17 17:43:16 I actually had that check first (and then realized
+ responseWasRejected(WebServiceWorkerResponseErrorForeignFetchMismatchedOrigin);
+ return;
+ } else if (!isOpaque) {
+ // TODO(mek): Handle |headers| response attribute, and properly filter response.
+ }
+
RespondWithObserver::responseWasFulfilled(ScriptValue::from(value.getScriptState(), response));
}
-ForeignFetchRespondWithObserver::ForeignFetchRespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext)
+ForeignFetchRespondWithObserver::ForeignFetchRespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext, PassRefPtr<SecurityOrigin> requestOrigin)
: RespondWithObserver(context, eventID, requestURL, requestMode, frameType, requestContext)
+ , m_requestOrigin(requestOrigin)
{
}

Powered by Google App Engine
This is Rietveld 408576698