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

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

Issue 2684533002: [WIP] Mojofy respondwith
Patch Set: rebase Created 3 years, 8 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/FetchRespondWithObserver.h" 5 #include "modules/serviceworkers/FetchRespondWithObserver.h"
6 6
7 #include <v8.h> 7 #include <v8.h>
8 #include "bindings/core/v8/ScriptValue.h" 8 #include "bindings/core/v8/ScriptValue.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/modules/v8/V8Response.h" 10 #include "bindings/modules/v8/V8Response.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 DCHECK(getExecutionContext()); 144 DCHECK(getExecutionContext());
145 getExecutionContext()->addConsoleMessage( 145 getExecutionContext()->addConsoleMessage(
146 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, 146 ConsoleMessage::create(JSMessageSource, WarningMessageLevel,
147 getMessageForResponseError(error, m_requestURL))); 147 getMessageForResponseError(error, m_requestURL)));
148 148
149 // The default value of WebServiceWorkerResponse's status is 0, which maps 149 // The default value of WebServiceWorkerResponse's status is 0, which maps
150 // to a network error. 150 // to a network error.
151 WebServiceWorkerResponse webResponse; 151 WebServiceWorkerResponse webResponse;
152 webResponse.setError(error); 152 webResponse.setError(error);
153 ServiceWorkerGlobalScopeClient::from(getExecutionContext()) 153 ServiceWorkerGlobalScopeClient::from(getExecutionContext())
154 ->respondToFetchEvent(m_eventID, webResponse, m_eventDispatchTime); 154 ->respondToFetchEventWithResponse(m_eventID, webResponse,
155 m_eventDispatchTime);
155 } 156 }
156 157
157 void FetchRespondWithObserver::onResponseFulfilled(const ScriptValue& value) { 158 void FetchRespondWithObserver::onResponseFulfilled(const ScriptValue& value) {
158 DCHECK(getExecutionContext()); 159 DCHECK(getExecutionContext());
159 if (!V8Response::hasInstance(value.v8Value(), 160 if (!V8Response::hasInstance(value.v8Value(),
160 toIsolate(getExecutionContext()))) { 161 toIsolate(getExecutionContext()))) {
161 onResponseRejected(WebServiceWorkerResponseErrorNoV8Instance); 162 onResponseRejected(WebServiceWorkerResponseErrorNoV8Instance);
162 return; 163 return;
163 } 164 }
164 Response* response = V8Response::toImplWithTypeCheck( 165 Response* response = V8Response::toImplWithTypeCheck(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return; 207 return;
207 } 208 }
208 if (response->bodyUsed()) { 209 if (response->bodyUsed()) {
209 onResponseRejected(WebServiceWorkerResponseErrorBodyUsed); 210 onResponseRejected(WebServiceWorkerResponseErrorBodyUsed);
210 return; 211 return;
211 } 212 }
212 213
213 WebServiceWorkerResponse webResponse; 214 WebServiceWorkerResponse webResponse;
214 response->populateWebServiceWorkerResponse(webResponse); 215 response->populateWebServiceWorkerResponse(webResponse);
215 BodyStreamBuffer* buffer = response->internalBodyBuffer(); 216 BodyStreamBuffer* buffer = response->internalBodyBuffer();
216 if (buffer) { 217 if (!buffer) {
218 ServiceWorkerGlobalScopeClient::from(getExecutionContext())
219 ->respondToFetchEventWithResponse(m_eventID, webResponse,
220 m_eventDispatchTime);
221 } else {
217 RefPtr<BlobDataHandle> blobDataHandle = buffer->drainAsBlobDataHandle( 222 RefPtr<BlobDataHandle> blobDataHandle = buffer->drainAsBlobDataHandle(
218 BytesConsumer::BlobSizePolicy::AllowBlobWithInvalidSize); 223 BytesConsumer::BlobSizePolicy::AllowBlobWithInvalidSize);
219 if (blobDataHandle) { 224 if (blobDataHandle) {
220 webResponse.setBlobDataHandle(blobDataHandle); 225 webResponse.setBlobDataHandle(blobDataHandle);
226 ServiceWorkerGlobalScopeClient::from(getExecutionContext())
227 ->respondToFetchEventWithResponse(m_eventID, webResponse,
228 m_eventDispatchTime);
221 } else { 229 } else {
222 Stream* outStream = Stream::create(getExecutionContext(), ""); 230 MojoCreateDataPipeOptions options;
223 webResponse.setStreamURL(outStream->url()); 231 options.struct_size = sizeof(MojoCreateDataPipeOptions);
224 buffer->startLoading(FetchDataLoader::createLoaderAsStream(outStream), 232 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
233 options.element_num_bytes = 1;
234 options.capacity_num_bytes = 512 * 1024;
235 mojo::DataPipe data_pipe(options);
236 DCHECK(data_pipe.producer_handle.is_valid());
237 DCHECK(data_pipe.consumer_handle.is_valid());
238 buffer->startLoading(FetchDataLoader::createLoaderAsDataPipe(
239 std::move(data_pipe.producer_handle)),
225 new NoopLoaderClient); 240 new NoopLoaderClient);
241 ServiceWorkerGlobalScopeClient::from(getExecutionContext())
242 ->respondToFetchEventWithResponseStream(
243 m_eventID, webResponse, std::move(data_pipe.consumer_handle),
244 m_eventDispatchTime);
226 } 245 }
227 } 246 }
228 ServiceWorkerGlobalScopeClient::from(getExecutionContext())
229 ->respondToFetchEvent(m_eventID, webResponse, m_eventDispatchTime);
230 } 247 }
231 248
232 void FetchRespondWithObserver::onNoResponse() { 249 void FetchRespondWithObserver::onNoResponse() {
233 ServiceWorkerGlobalScopeClient::from(getExecutionContext()) 250 ServiceWorkerGlobalScopeClient::from(getExecutionContext())
234 ->respondToFetchEvent(m_eventID, m_eventDispatchTime); 251 ->respondToFetchEvent(m_eventID, m_eventDispatchTime);
235 } 252 }
236 253
237 FetchRespondWithObserver::FetchRespondWithObserver( 254 FetchRespondWithObserver::FetchRespondWithObserver(
238 ExecutionContext* context, 255 ExecutionContext* context,
239 int fetchEventID, 256 int fetchEventID,
240 const KURL& requestURL, 257 const KURL& requestURL,
241 WebURLRequest::FetchRequestMode requestMode, 258 WebURLRequest::FetchRequestMode requestMode,
242 WebURLRequest::FetchRedirectMode redirectMode, 259 WebURLRequest::FetchRedirectMode redirectMode,
243 WebURLRequest::FrameType frameType, 260 WebURLRequest::FrameType frameType,
244 WebURLRequest::RequestContext requestContext, 261 WebURLRequest::RequestContext requestContext,
245 WaitUntilObserver* observer) 262 WaitUntilObserver* observer)
246 : RespondWithObserver(context, fetchEventID, observer), 263 : RespondWithObserver(context, fetchEventID, observer),
247 m_requestURL(requestURL), 264 m_requestURL(requestURL),
248 m_requestMode(requestMode), 265 m_requestMode(requestMode),
249 m_redirectMode(redirectMode), 266 m_redirectMode(redirectMode),
250 m_frameType(frameType), 267 m_frameType(frameType),
251 m_requestContext(requestContext) {} 268 m_requestContext(requestContext) {}
252 269
253 DEFINE_TRACE(FetchRespondWithObserver) { 270 DEFINE_TRACE(FetchRespondWithObserver) {
254 RespondWithObserver::trace(visitor); 271 RespondWithObserver::trace(visitor);
255 } 272 }
256 273
257 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698