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

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

Issue 516603004: [ServiceWorker] Support setting body to Request object in ServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 3 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
« no previous file with comments | « Source/modules/serviceworkers/RequestInit.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "RequestInit.h"
7
8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/V8Blob.h"
10 #include "bindings/core/v8/V8FormData.h"
11 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
12 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
13 #include "modules/serviceworkers/Headers.h"
14 #include "wtf/ArrayBuffer.h"
15
16 namespace blink {
17
18 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState)
19 {
20 DictionaryHelper::get(options, "method", method);
21 DictionaryHelper::get(options, "headers", headers);
22 if (!headers) {
23 DictionaryHelper::get(options, "headers", headersDictionary);
24 }
25 DictionaryHelper::get(options, "mode", mode);
26 DictionaryHelper::get(options, "credentials", credentials);
27
28 v8::Local<v8::Value> body;
29 if (!DictionaryHelper::get(options, "body", body) || body->IsUndefined() || body->IsNull())
30 return;
31 OwnPtr<BlobData> blobData = BlobData::create();
32 v8::Isolate* isolate = toIsolate(context);
33 if (body->IsArrayBuffer()) {
34 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object >::Cast(body));
35 ASSERT(arrayBuffer);
36 blobData->appendArrayBuffer(arrayBuffer);
37 } else if (body->IsArrayBufferView()) {
38 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handl e<v8::Object>::Cast(body));
39 ASSERT(arrayBufferView);
40 blobData->appendArrayBufferView(arrayBufferView);
41 } else if (V8Blob::hasInstance(body, isolate)) {
42 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(body));
43 ASSERT(blob);
44 blob->appendTo(*blobData);
45 blobData->setContentType(blob->type());
46 } else if (V8FormData::hasInstance(body, isolate)) {
47 DOMFormData* domFormData = V8FormData::toNative(v8::Handle<v8::Object>:: Cast(body));
48 ASSERT(domFormData);
49 RefPtr<FormData> httpBody = domFormData->createMultiPartFormData();
50 for (size_t i = 0; i < httpBody->elements().size(); ++i) {
51 const FormDataElement& element = httpBody->elements()[i];
52 switch (element.m_type) {
53 case FormDataElement::data: {
54 RefPtr<RawData> rawData = RawData::create();
55 rawData->mutableData()->append(element.m_data.data(), element.m_ data.size());
56 blobData->appendData(rawData, 0, -1);
57 break;
58 }
59 case FormDataElement::encodedFile:
60 blobData->appendFile(element.m_filename, element.m_fileStart, el ement.m_fileLength, element.m_expectedFileModificationTime);
61 break;
62 case FormDataElement::encodedBlob:
63 if (element.m_optionalBlobDataHandle)
64 blobData->appendBlob(element.m_optionalBlobDataHandle, 0, el ement.m_optionalBlobDataHandle->size());
65 break;
66 case FormDataElement::encodedFileSystemURL:
67 blobData->appendFileSystemURL(element.m_fileSystemURL, element.m _fileStart, element.m_fileLength, element.m_expectedFileModificationTime);
68 break;
69 default:
70 ASSERT_NOT_REACHED();
71 }
72 }
73 blobData->setContentType(AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data());
74 } else if (body->IsString()) {
75 String stringValue(toScalarValueString(body, exceptionState));
76 blobData->appendText(stringValue, false);
77 blobData->setContentType("text/plain;charset=UTF-8");
78 }
yhirano 2014/08/29 15:56:07 else { return; } ?
horo 2014/09/01 02:31:28 Done.
79 const long long blobSize = blobData->length();
80 bodyBlobHandle = BlobDataHandle::create(blobData.release(), blobSize);
81 }
82
83 }
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/RequestInit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698