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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/RequestInit.cpp

Issue 1844413006: Support ReferrerPolicy in Fetch API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update-referrer-policy
Patch Set: rebase Created 4 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/fetch/RequestInit.h" 5 #include "modules/fetch/RequestInit.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/V8ArrayBuffer.h" 8 #include "bindings/core/v8/V8ArrayBuffer.h"
9 #include "bindings/core/v8/V8ArrayBufferView.h" 9 #include "bindings/core/v8/V8ArrayBufferView.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "bindings/core/v8/V8Blob.h" 11 #include "bindings/core/v8/V8Blob.h"
12 #include "bindings/core/v8/V8FormData.h" 12 #include "bindings/core/v8/V8FormData.h"
13 #include "bindings/core/v8/V8URLSearchParams.h" 13 #include "bindings/core/v8/V8URLSearchParams.h"
14 #include "bindings/modules/v8/V8PasswordCredential.h" 14 #include "bindings/modules/v8/V8PasswordCredential.h"
15 #include "core/dom/URLSearchParams.h" 15 #include "core/dom/URLSearchParams.h"
16 #include "core/fileapi/Blob.h" 16 #include "core/fileapi/Blob.h"
17 #include "core/html/FormData.h" 17 #include "core/html/FormData.h"
18 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 18 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
19 #include "modules/fetch/FetchFormDataConsumerHandle.h" 19 #include "modules/fetch/FetchFormDataConsumerHandle.h"
20 #include "modules/fetch/Headers.h" 20 #include "modules/fetch/Headers.h"
21 #include "platform/RuntimeEnabledFeatures.h"
21 #include "platform/blob/BlobData.h" 22 #include "platform/blob/BlobData.h"
22 #include "platform/network/EncodedFormData.h" 23 #include "platform/network/EncodedFormData.h"
23 #include "platform/weborigin/ReferrerPolicy.h" 24 #include "platform/weborigin/ReferrerPolicy.h"
24 25
25 namespace blink { 26 namespace blink {
26 27
27 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState) 28 RequestInit::RequestInit(ExecutionContext* context, const Dictionary& options, E xceptionState& exceptionState)
28 : areAnyMembersSet(false) 29 : areAnyMembersSet(false)
29 { 30 {
30 areAnyMembersSet |= DictionaryHelper::get(options, "method", method); 31 areAnyMembersSet |= DictionaryHelper::get(options, "method", method);
31 areAnyMembersSet |= DictionaryHelper::get(options, "headers", headers); 32 areAnyMembersSet |= DictionaryHelper::get(options, "headers", headers);
32 if (!headers) { 33 if (!headers) {
33 Vector<Vector<String>> headersVector; 34 Vector<Vector<String>> headersVector;
34 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt ate)) { 35 if (DictionaryHelper::get(options, "headers", headersVector, exceptionSt ate)) {
35 headers = Headers::create(headersVector, exceptionState); 36 headers = Headers::create(headersVector, exceptionState);
36 areAnyMembersSet = true; 37 areAnyMembersSet = true;
37 } else { 38 } else {
38 areAnyMembersSet |= DictionaryHelper::get(options, "headers", header sDictionary); 39 areAnyMembersSet |= DictionaryHelper::get(options, "headers", header sDictionary);
39 } 40 }
40 } 41 }
41 areAnyMembersSet |= DictionaryHelper::get(options, "mode", mode); 42 areAnyMembersSet |= DictionaryHelper::get(options, "mode", mode);
42 areAnyMembersSet |= DictionaryHelper::get(options, "redirect", redirect); 43 areAnyMembersSet |= DictionaryHelper::get(options, "redirect", redirect);
43 AtomicString referrerString; 44 AtomicString referrerString;
44 bool isReferrerStringSet = DictionaryHelper::get(options, "referrer", referr erString); 45 bool isReferrerStringSet = DictionaryHelper::get(options, "referrer", referr erString);
45 areAnyMembersSet |= isReferrerStringSet; 46 areAnyMembersSet |= isReferrerStringSet;
46 areAnyMembersSet |= DictionaryHelper::get(options, "integrity", integrity); 47 areAnyMembersSet |= DictionaryHelper::get(options, "integrity", integrity);
48 AtomicString referrerPolicyString;
49 bool isReferrerPolicySet = DictionaryHelper::get(options, "referrerPolicy", referrerPolicyString);
50 areAnyMembersSet |= isReferrerPolicySet;
47 51
48 v8::Local<v8::Value> v8Body; 52 v8::Local<v8::Value> v8Body;
49 bool isBodySet = DictionaryHelper::get(options, "body", v8Body); 53 bool isBodySet = DictionaryHelper::get(options, "body", v8Body);
50 areAnyMembersSet |= isBodySet; 54 areAnyMembersSet |= isBodySet;
51 55
52 v8::Local<v8::Value> v8Credential; 56 v8::Local<v8::Value> v8Credential;
53 bool isCredentialSet = DictionaryHelper::get(options, "credentials", v8Crede ntial); 57 bool isCredentialSet = DictionaryHelper::get(options, "credentials", v8Crede ntial);
54 areAnyMembersSet |= isCredentialSet; 58 areAnyMembersSet |= isCredentialSet;
55 59
56 if (areAnyMembersSet) { 60 if (areAnyMembersSet) {
57 // A part of the Request constructor algorithm is performed here. See 61 // A part of the Request constructor algorithm is performed here. See
58 // the comments in the Request constructor code for the detail. 62 // the comments in the Request constructor code for the detail.
59 63
60 // We need to use "about:client" instead of |clientReferrerString|, 64 // We need to use "about:client" instead of |clientReferrerString|,
61 // because "about:client" => |clientReferrerString| conversion is done 65 // because "about:client" => |clientReferrerString| conversion is done
62 // in Request::createRequestWithRequestOrString. 66 // in Request::createRequestWithRequestOrString.
63 referrer = Referrer("about:client", ReferrerPolicyDefault); 67 referrer = Referrer("about:client", ReferrerPolicyDefault);
64 if (isReferrerStringSet) 68 if (isReferrerStringSet)
65 referrer.referrer = referrerString; 69 referrer.referrer = referrerString;
70 if (isReferrerPolicySet) {
71 if (referrerPolicyString == "") {
72 referrer.referrerPolicy = ReferrerPolicyDefault;
73 } else if (referrerPolicyString == "no-referrer") {
74 referrer.referrerPolicy = ReferrerPolicyNever;
75 } else if (referrerPolicyString == "no-referrer-when-downgrade") {
76 referrer.referrerPolicy = ReferrerPolicyNoReferrerWhenDowngrade;
77 } else if (referrerPolicyString == "origin") {
78 referrer.referrerPolicy = ReferrerPolicyOrigin;
79 } else if (referrerPolicyString == "origin-when-cross-origin") {
80 referrer.referrerPolicy = ReferrerPolicyOriginWhenCrossOrigin;
81 } else if (referrerPolicyString == "unsafe-url") {
82 referrer.referrerPolicy = ReferrerPolicyAlways;
83 } else if (referrerPolicyString == "no-referrer-when-downgrade-origi n-when-cross-origin" && RuntimeEnabledFeatures::reducedReferrerGranularityEnable d()) {
84 referrer.referrerPolicy = ReferrerPolicyNoReferrerWhenDowngradeO riginWhenCrossOrigin;
85 } else {
86 exceptionState.throwTypeError("Invalid referrer policy");
87 return;
88 }
89 }
66 } 90 }
67 91
68 v8::Isolate* isolate = toIsolate(context); 92 v8::Isolate* isolate = toIsolate(context);
69 if (isCredentialSet) { 93 if (isCredentialSet) {
70 if (V8PasswordCredential::hasInstance(v8Credential, isolate)) { 94 if (V8PasswordCredential::hasInstance(v8Credential, isolate)) {
71 // TODO(mkwst): According to the spec, we'd serialize this once we t ouch the network. We're 95 // TODO(mkwst): According to the spec, we'd serialize this once we t ouch the network. We're
72 // serializing it here, ahead of time, because lifetime issues aroun d ResourceRequest make 96 // serializing it here, ahead of time, because lifetime issues aroun d ResourceRequest make
73 // it pretty difficult to pass a PasswordCredential around at the pl atform level, and the 97 // it pretty difficult to pass a PasswordCredential around at the pl atform level, and the
74 // hop between the browser and renderer processes to deal with servi ce workers is equally 98 // hop between the browser and renderer processes to deal with servi ce workers is equally
75 // painful. There should be no developer-visible difference in behav ior with this option, 99 // painful. There should be no developer-visible difference in behav ior with this option,
(...skipping 27 matching lines...) Expand all
103 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(v8::Local<v 8::Object>::Cast(v8Body))->encodeFormData(); 127 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(v8::Local<v 8::Object>::Cast(v8Body))->encodeFormData();
104 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8"); 128 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8");
105 body = FetchFormDataConsumerHandle::create(context, formData.release()); 129 body = FetchFormDataConsumerHandle::create(context, formData.release());
106 } else if (v8Body->IsString()) { 130 } else if (v8Body->IsString()) {
107 contentType = "text/plain;charset=UTF-8"; 131 contentType = "text/plain;charset=UTF-8";
108 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); 132 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState));
109 } 133 }
110 } 134 }
111 135
112 } // namespace blink 136 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/Request.idl ('k') | third_party/WebKit/Source/modules/fetch/RequestTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698