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

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

Issue 1773813007: blink: Rename modules/ method to prefix with get when they collide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clash-modules: rebase-fixes Created 4 years, 9 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 "modules/serviceworkers/RespondWithObserver.h" 5 #include "modules/serviceworkers/RespondWithObserver.h"
6 6
7 #include "bindings/core/v8/ScriptFunction.h" 7 #include "bindings/core/v8/ScriptFunction.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptValue.h" 9 #include "bindings/core/v8/ScriptValue.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 , m_resolveType(type) 115 , m_resolveType(type)
116 { 116 {
117 } 117 }
118 118
119 ScriptValue call(ScriptValue value) override 119 ScriptValue call(ScriptValue value) override
120 { 120 {
121 ASSERT(m_observer); 121 ASSERT(m_observer);
122 ASSERT(m_resolveType == Fulfilled || m_resolveType == Rejected); 122 ASSERT(m_resolveType == Fulfilled || m_resolveType == Rejected);
123 if (m_resolveType == Rejected) { 123 if (m_resolveType == Rejected) {
124 m_observer->responseWasRejected(WebServiceWorkerResponseErrorPromise Rejected); 124 m_observer->responseWasRejected(WebServiceWorkerResponseErrorPromise Rejected);
125 value = ScriptPromise::reject(value.scriptState(), value).getScriptV alue(); 125 value = ScriptPromise::reject(value.getScriptState(), value).getScri ptValue();
126 } else { 126 } else {
127 m_observer->responseWasFulfilled(value); 127 m_observer->responseWasFulfilled(value);
128 } 128 }
129 m_observer = nullptr; 129 m_observer = nullptr;
130 return value; 130 return value;
131 } 131 }
132 132
133 Member<RespondWithObserver> m_observer; 133 Member<RespondWithObserver> m_observer;
134 ResolveType m_resolveType; 134 ResolveType m_resolveType;
135 }; 135 };
136 136
137 RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, We bURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext) 137 RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, We bURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext)
138 { 138 {
139 return new RespondWithObserver(context, eventID, requestURL, requestMode, fr ameType, requestContext); 139 return new RespondWithObserver(context, eventID, requestURL, requestMode, fr ameType, requestContext);
140 } 140 }
141 141
142 void RespondWithObserver::contextDestroyed() 142 void RespondWithObserver::contextDestroyed()
143 { 143 {
144 ContextLifecycleObserver::contextDestroyed(); 144 ContextLifecycleObserver::contextDestroyed();
145 m_state = Done; 145 m_state = Done;
146 } 146 }
147 147
148 void RespondWithObserver::didDispatchEvent(DispatchEventResult dispatchResult) 148 void RespondWithObserver::didDispatchEvent(DispatchEventResult dispatchResult)
149 { 149 {
150 ASSERT(executionContext()); 150 ASSERT(getExecutionContext());
151 if (m_state != Initial) 151 if (m_state != Initial)
152 return; 152 return;
153 153
154 if (dispatchResult != DispatchEventResult::NotCanceled) { 154 if (dispatchResult != DispatchEventResult::NotCanceled) {
155 responseWasRejected(WebServiceWorkerResponseErrorDefaultPrevented); 155 responseWasRejected(WebServiceWorkerResponseErrorDefaultPrevented);
156 return; 156 return;
157 } 157 }
158 158
159 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven t(m_eventID); 159 ServiceWorkerGlobalScopeClient::from(getExecutionContext())->didHandleFetchE vent(m_eventID);
160 m_state = Done; 160 m_state = Done;
161 } 161 }
162 162
163 void RespondWithObserver::respondWith(ScriptState* scriptState, ScriptPromise sc riptPromise, ExceptionState& exceptionState) 163 void RespondWithObserver::respondWith(ScriptState* scriptState, ScriptPromise sc riptPromise, ExceptionState& exceptionState)
164 { 164 {
165 if (m_state != Initial) { 165 if (m_state != Initial) {
166 exceptionState.throwDOMException(InvalidStateError, "The fetch event has already been responded to."); 166 exceptionState.throwDOMException(InvalidStateError, "The fetch event has already been responded to.");
167 return; 167 return;
168 } 168 }
169 169
170 m_state = Pending; 170 m_state = Pending;
171 scriptPromise.then( 171 scriptPromise.then(
172 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) , 172 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) ,
173 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ; 173 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ;
174 } 174 }
175 175
176 void RespondWithObserver::responseWasRejected(WebServiceWorkerResponseError erro r) 176 void RespondWithObserver::responseWasRejected(WebServiceWorkerResponseError erro r)
177 { 177 {
178 ASSERT(executionContext()); 178 ASSERT(getExecutionContext());
179 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource , WarningMessageLevel, getMessageForResponseError(error, m_requestURL))); 179 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSou rce, WarningMessageLevel, getMessageForResponseError(error, m_requestURL)));
180 180
181 // The default value of WebServiceWorkerResponse's status is 0, which maps 181 // The default value of WebServiceWorkerResponse's status is 0, which maps
182 // to a network error. 182 // to a network error.
183 WebServiceWorkerResponse webResponse; 183 WebServiceWorkerResponse webResponse;
184 webResponse.setError(error); 184 webResponse.setError(error);
185 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven t(m_eventID, webResponse); 185 ServiceWorkerGlobalScopeClient::from(getExecutionContext())->didHandleFetchE vent(m_eventID, webResponse);
186 m_state = Done; 186 m_state = Done;
187 } 187 }
188 188
189 void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) 189 void RespondWithObserver::responseWasFulfilled(const ScriptValue& value)
190 { 190 {
191 ASSERT(executionContext()); 191 ASSERT(getExecutionContext());
192 if (!V8Response::hasInstance(value.v8Value(), toIsolate(executionContext())) ) { 192 if (!V8Response::hasInstance(value.v8Value(), toIsolate(getExecutionContext( )))) {
193 responseWasRejected(WebServiceWorkerResponseErrorNoV8Instance); 193 responseWasRejected(WebServiceWorkerResponseErrorNoV8Instance);
194 return; 194 return;
195 } 195 }
196 Response* response = V8Response::toImplWithTypeCheck(toIsolate(executionCont ext()), value.v8Value()); 196 Response* response = V8Response::toImplWithTypeCheck(toIsolate(getExecutionC ontext()), value.v8Value());
197 // "If one of the following conditions is true, return a network error: 197 // "If one of the following conditions is true, return a network error:
198 // - |response|'s type is |error|. 198 // - |response|'s type is |error|.
199 // - |request|'s mode is not |no-cors| and response's type is |opaque|. 199 // - |request|'s mode is not |no-cors| and response's type is |opaque|.
200 // - |request| is a client request and |response|'s type is neither 200 // - |request| is a client request and |response|'s type is neither
201 // |basic| nor |default|." 201 // |basic| nor |default|."
202 const FetchResponseData::Type responseType = response->response()->getType() ; 202 const FetchResponseData::Type responseType = response->response()->getType() ;
203 if (responseType == FetchResponseData::ErrorType) { 203 if (responseType == FetchResponseData::ErrorType) {
204 responseWasRejected(WebServiceWorkerResponseErrorResponseTypeError); 204 responseWasRejected(WebServiceWorkerResponseErrorResponseTypeError);
205 return; 205 return;
206 } 206 }
(...skipping 27 matching lines...) Expand all
234 } 234 }
235 235
236 WebServiceWorkerResponse webResponse; 236 WebServiceWorkerResponse webResponse;
237 response->populateWebServiceWorkerResponse(webResponse); 237 response->populateWebServiceWorkerResponse(webResponse);
238 BodyStreamBuffer* buffer = response->internalBodyBuffer(); 238 BodyStreamBuffer* buffer = response->internalBodyBuffer();
239 if (buffer) { 239 if (buffer) {
240 RefPtr<BlobDataHandle> blobDataHandle = buffer->drainAsBlobDataHandle(Fe tchDataConsumerHandle::Reader::AllowBlobWithInvalidSize); 240 RefPtr<BlobDataHandle> blobDataHandle = buffer->drainAsBlobDataHandle(Fe tchDataConsumerHandle::Reader::AllowBlobWithInvalidSize);
241 if (blobDataHandle) { 241 if (blobDataHandle) {
242 webResponse.setBlobDataHandle(blobDataHandle); 242 webResponse.setBlobDataHandle(blobDataHandle);
243 } else { 243 } else {
244 Stream* outStream = Stream::create(executionContext(), ""); 244 Stream* outStream = Stream::create(getExecutionContext(), "");
245 webResponse.setStreamURL(outStream->url()); 245 webResponse.setStreamURL(outStream->url());
246 buffer->startLoading(executionContext(), FetchDataLoader::createLoad erAsStream(outStream), new NoopLoaderClient); 246 buffer->startLoading(getExecutionContext(), FetchDataLoader::createL oaderAsStream(outStream), new NoopLoaderClient);
247 } 247 }
248 } 248 }
249 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleFetchEven t(m_eventID, webResponse); 249 ServiceWorkerGlobalScopeClient::from(getExecutionContext())->didHandleFetchE vent(m_eventID, webResponse);
250 m_state = Done; 250 m_state = Done;
251 } 251 }
252 252
253 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequ est::FrameType frameType, WebURLRequest::RequestContext requestContext) 253 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequ est::FrameType frameType, WebURLRequest::RequestContext requestContext)
254 : ContextLifecycleObserver(context) 254 : ContextLifecycleObserver(context)
255 , m_eventID(eventID) 255 , m_eventID(eventID)
256 , m_requestURL(requestURL) 256 , m_requestURL(requestURL)
257 , m_requestMode(requestMode) 257 , m_requestMode(requestMode)
258 , m_frameType(frameType) 258 , m_frameType(frameType)
259 , m_requestContext(requestContext) 259 , m_requestContext(requestContext)
260 , m_state(Initial) 260 , m_state(Initial)
261 { 261 {
262 } 262 }
263 263
264 DEFINE_TRACE(RespondWithObserver) 264 DEFINE_TRACE(RespondWithObserver)
265 { 265 {
266 ContextLifecycleObserver::trace(visitor); 266 ContextLifecycleObserver::trace(visitor);
267 } 267 }
268 268
269 } // namespace blink 269 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698