OLD | NEW |
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 Loading... |
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) | 66 RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int
eventID, WebURLRequest::FetchRequestMode requestMode) |
67 { | 67 { |
68 return new RespondWithObserver(context, eventID); | 68 return new RespondWithObserver(context, eventID, requestMode); |
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 28 matching lines...) Expand all Loading... |
107 m_state = Done; | 107 m_state = Done; |
108 } | 108 } |
109 | 109 |
110 void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) | 110 void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
111 { | 111 { |
112 ASSERT(executionContext()); | 112 ASSERT(executionContext()); |
113 if (!V8Response::hasInstance(value.v8Value(), toIsolate(executionContext()))
) { | 113 if (!V8Response::hasInstance(value.v8Value(), toIsolate(executionContext()))
) { |
114 responseWasRejected(); | 114 responseWasRejected(); |
115 return; | 115 return; |
116 } | 116 } |
| 117 Response* response = V8Response::toImplWithTypeCheck(toIsolate(executionCont
ext()), value.v8Value()); |
| 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." |
| 120 const FetchResponseData::Type responseType = response->response()->type(); |
| 121 if ((responseType == FetchResponseData::OpaqueType && m_requestMode != WebUR
LRequest::FetchRequestModeNoCORS) || responseType == FetchResponseData::ErrorTyp
e) { |
| 122 responseWasRejected(); |
| 123 return; |
| 124 } |
117 WebServiceWorkerResponse webResponse; | 125 WebServiceWorkerResponse webResponse; |
118 V8Response::toImplWithTypeCheck(toIsolate(executionContext()), value.v8Value
())->populateWebServiceWorkerResponse(webResponse); | 126 response->populateWebServiceWorkerResponse(webResponse); |
119 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven
t(m_eventID, webResponse); | 127 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven
t(m_eventID, webResponse); |
120 m_state = Done; | 128 m_state = Done; |
121 } | 129 } |
122 | 130 |
123 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID) | 131 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID,
WebURLRequest::FetchRequestMode requestMode) |
124 : ContextLifecycleObserver(context) | 132 : ContextLifecycleObserver(context) |
125 , m_eventID(eventID) | 133 , m_eventID(eventID) |
| 134 , m_requestMode(requestMode) |
126 , m_state(Initial) | 135 , m_state(Initial) |
127 { | 136 { |
128 } | 137 } |
129 | 138 |
130 } // namespace blink | 139 } // namespace blink |
OLD | NEW |