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

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: 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"
(...skipping 26 matching lines...) Expand all
37 } else { 37 } else {
38 areAnyMembersSet |= DictionaryHelper::get(options, "headers", header sDictionary); 38 areAnyMembersSet |= DictionaryHelper::get(options, "headers", header sDictionary);
39 } 39 }
40 } 40 }
41 areAnyMembersSet |= DictionaryHelper::get(options, "mode", mode); 41 areAnyMembersSet |= DictionaryHelper::get(options, "mode", mode);
42 areAnyMembersSet |= DictionaryHelper::get(options, "redirect", redirect); 42 areAnyMembersSet |= DictionaryHelper::get(options, "redirect", redirect);
43 AtomicString referrerString; 43 AtomicString referrerString;
44 bool isReferrerStringSet = DictionaryHelper::get(options, "referrer", referr erString); 44 bool isReferrerStringSet = DictionaryHelper::get(options, "referrer", referr erString);
45 areAnyMembersSet |= isReferrerStringSet; 45 areAnyMembersSet |= isReferrerStringSet;
46 areAnyMembersSet |= DictionaryHelper::get(options, "integrity", integrity); 46 areAnyMembersSet |= DictionaryHelper::get(options, "integrity", integrity);
47 AtomicString referrerPolicyString;
48 bool isReferrerPolicySet = DictionaryHelper::get(options, "referrerPolicy", referrerPolicyString);
49 areAnyMembersSet |= isReferrerPolicySet;
47 50
48 v8::Local<v8::Value> v8Body; 51 v8::Local<v8::Value> v8Body;
49 bool isBodySet = DictionaryHelper::get(options, "body", v8Body); 52 bool isBodySet = DictionaryHelper::get(options, "body", v8Body);
50 areAnyMembersSet |= isBodySet; 53 areAnyMembersSet |= isBodySet;
51 54
52 v8::Local<v8::Value> v8Credential; 55 v8::Local<v8::Value> v8Credential;
53 bool isCredentialSet = DictionaryHelper::get(options, "credentials", v8Crede ntial); 56 bool isCredentialSet = DictionaryHelper::get(options, "credentials", v8Crede ntial);
54 areAnyMembersSet |= isCredentialSet; 57 areAnyMembersSet |= isCredentialSet;
55 58
56 if (areAnyMembersSet) { 59 if (areAnyMembersSet) {
57 // A part of the Request constructor algorithm is performed here. See 60 // A part of the Request constructor algorithm is performed here. See
58 // the comments in the Request constructor code for the detail. 61 // the comments in the Request constructor code for the detail.
59 62
60 // We need to use "about:client" instead of |clientReferrerString|, 63 // We need to use "about:client" instead of |clientReferrerString|,
61 // because "about:client" => |clientReferrerString| conversion is done 64 // because "about:client" => |clientReferrerString| conversion is done
62 // in Request::createRequestWithRequestOrString. 65 // in Request::createRequestWithRequestOrString.
63 referrer = Referrer("about:client", ReferrerPolicyDefault); 66 referrer = Referrer("about:client", ReferrerPolicyDefault);
64 if (isReferrerStringSet) 67 if (isReferrerStringSet)
65 referrer.referrer = referrerString; 68 referrer.referrer = referrerString;
69 if (isReferrerPolicySet) {
70 if (referrerPolicyString == "") {
71 referrer.referrerPolicy = ReferrerPolicyDefault;
72 } else if (referrerPolicyString == "no-referrer") {
73 referrer.referrerPolicy = ReferrerPolicyNever;
74 } else if (referrerPolicyString == "no-referrer-when-downgrade") {
75 referrer.referrerPolicy = ReferrerPolicyNoReferrerWhenDowngrade;
76 } else if (referrerPolicyString == "origin-only") {
77 referrer.referrerPolicy = ReferrerPolicyOrigin;
78 } else if (referrerPolicyString == "origin-when-cross-origin") {
79 referrer.referrerPolicy = ReferrerPolicyOriginWhenCrossOrigin;
80 } else if (referrerPolicyString == "unsafe-url") {
81 referrer.referrerPolicy = ReferrerPolicyAlways;
82 } else {
83 exceptionState.throwTypeError("Invalid referrer policy");
84 return;
85 }
86 }
66 } 87 }
67 88
68 v8::Isolate* isolate = toIsolate(context); 89 v8::Isolate* isolate = toIsolate(context);
69 if (isCredentialSet) { 90 if (isCredentialSet) {
70 if (V8PasswordCredential::hasInstance(v8Credential, isolate)) { 91 if (V8PasswordCredential::hasInstance(v8Credential, isolate)) {
71 // TODO(mkwst): According to the spec, we'd serialize this once we t ouch the network. We're 92 // 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 93 // 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 94 // 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 95 // 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, 96 // 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(); 124 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"); 125 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8");
105 body = FetchFormDataConsumerHandle::create(context, formData.release()); 126 body = FetchFormDataConsumerHandle::create(context, formData.release());
106 } else if (v8Body->IsString()) { 127 } else if (v8Body->IsString()) {
107 contentType = "text/plain;charset=UTF-8"; 128 contentType = "text/plain;charset=UTF-8";
108 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); 129 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState));
109 } 130 }
110 } 131 }
111 132
112 } // namespace blink 133 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698