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

Side by Side Diff: Source/modules/serviceworkers/RespondWithObserver.cpp

Issue 621003002: [ServiceWorker] Treat opaque response as a network error for frame loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/RespondWithObserver.h" 6 #include "modules/serviceworkers/RespondWithObserver.h"
7 7
8 #include "bindings/core/v8/ScriptFunction.h" 8 #include "bindings/core/v8/ScriptFunction.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptValue.h" 10 #include "bindings/core/v8/ScriptValue.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 else 56 else
57 m_observer->responseWasFulfilled(value); 57 m_observer->responseWasFulfilled(value);
58 m_observer = nullptr; 58 m_observer = nullptr;
59 return value; 59 return value;
60 } 60 }
61 61
62 Member<RespondWithObserver> m_observer; 62 Member<RespondWithObserver> m_observer;
63 ResolveType m_resolveType; 63 ResolveType m_resolveType;
64 }; 64 };
65 65
66 RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, WebURLRequest::FetchRequestMode requestMode) 66 RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType f rameType)
67 { 67 {
68 return new RespondWithObserver(context, eventID, requestMode); 68 return new RespondWithObserver(context, eventID, requestMode, frameType);
69 } 69 }
70 70
71 void RespondWithObserver::contextDestroyed() 71 void RespondWithObserver::contextDestroyed()
72 { 72 {
73 ContextLifecycleObserver::contextDestroyed(); 73 ContextLifecycleObserver::contextDestroyed();
74 m_state = Done; 74 m_state = Done;
75 } 75 }
76 76
77 void RespondWithObserver::didDispatchEvent() 77 void RespondWithObserver::didDispatchEvent()
78 { 78 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return; 115 return;
116 } 116 }
117 Response* response = V8Response::toImplWithTypeCheck(toIsolate(executionCont ext()), value.v8Value()); 117 Response* response = V8Response::toImplWithTypeCheck(toIsolate(executionCont ext()), value.v8Value());
118 // "If either |response|'s type is |opaque| and |request|'s mode is not 118 // "If either |response|'s type is |opaque| and |request|'s mode is not
119 // |no CORS| or |response|'s type is |error|, return a network error." 119 // |no CORS| or |response|'s type is |error|, return a network error."
120 const FetchResponseData::Type responseType = response->response()->type(); 120 const FetchResponseData::Type responseType = response->response()->type();
121 if ((responseType == FetchResponseData::OpaqueType && m_requestMode != WebUR LRequest::FetchRequestModeNoCORS) || responseType == FetchResponseData::ErrorTyp e) { 121 if ((responseType == FetchResponseData::OpaqueType && m_requestMode != WebUR LRequest::FetchRequestModeNoCORS) || responseType == FetchResponseData::ErrorTyp e) {
122 responseWasRejected(); 122 responseWasRejected();
123 return; 123 return;
124 } 124 }
125 // Treat the opaque response as a network error for frame loading.
126 if (responseType == FetchResponseData::OpaqueType && m_frameType != WebURLRe quest::FrameTypeNone) {
Mike West 2014/10/02 12:07:46 You probably want to check for TopLevel or Nested
horo 2014/10/03 03:43:02 It may reasonable. But the current ServiceWorker s
127 responseWasRejected();
128 return;
129 }
125 WebServiceWorkerResponse webResponse; 130 WebServiceWorkerResponse webResponse;
126 response->populateWebServiceWorkerResponse(webResponse); 131 response->populateWebServiceWorkerResponse(webResponse);
127 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven t(m_eventID, webResponse); 132 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven t(m_eventID, webResponse);
128 m_state = Done; 133 m_state = Done;
129 } 134 }
130 135
131 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, WebURLRequest::FetchRequestMode requestMode) 136 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType )
132 : ContextLifecycleObserver(context) 137 : ContextLifecycleObserver(context)
133 , m_eventID(eventID) 138 , m_eventID(eventID)
134 , m_requestMode(requestMode) 139 , m_requestMode(requestMode)
140 , m_frameType(frameType)
135 , m_state(Initial) 141 , m_state(Initial)
136 { 142 {
137 } 143 }
138 144
139 } // namespace blink 145 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698