Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/credentialmanager/PasswordCredential.h" | 5 #include "modules/credentialmanager/PasswordCredential.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "core/HTMLNames.h" | 9 #include "core/HTMLNames.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| 11 #include "core/dom/URLSearchParams.h" | 11 #include "core/dom/URLSearchParams.h" |
| 12 #include "core/html/FormData.h" | 12 #include "core/html/FormData.h" |
| 13 #include "core/html/HTMLFormElement.h" | 13 #include "core/html/HTMLFormElement.h" |
| 14 #include "core/html/ListedElement.h" | 14 #include "core/html/ListedElement.h" |
| 15 #include "modules/credentialmanager/FormDataOptions.h" | 15 #include "modules/credentialmanager/FormDataOptions.h" |
| 16 #include "modules/credentialmanager/PasswordCredentialData.h" | 16 #include "modules/credentialmanager/PasswordCredentialData.h" |
| 17 #include "platform/RuntimeEnabledFeatures.h" | |
| 17 #include "platform/credentialmanager/PlatformPasswordCredential.h" | 18 #include "platform/credentialmanager/PlatformPasswordCredential.h" |
| 18 #include "platform/weborigin/SecurityOrigin.h" | 19 #include "platform/weborigin/SecurityOrigin.h" |
| 19 #include "public/platform/WebCredential.h" | 20 #include "public/platform/WebCredential.h" |
| 20 #include "public/platform/WebPasswordCredential.h" | 21 #include "public/platform/WebPasswordCredential.h" |
| 21 | 22 |
| 22 namespace blink { | 23 namespace blink { |
| 23 | 24 |
| 24 PasswordCredential* PasswordCredential::Create( | 25 PasswordCredential* PasswordCredential::Create( |
| 25 WebPasswordCredential* web_password_credential) { | 26 WebPasswordCredential* web_password_credential) { |
| 26 return new PasswordCredential(web_password_credential); | 27 return new PasswordCredential(web_password_credential); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 126 |
| 126 PasswordCredential::PasswordCredential(const String& id, | 127 PasswordCredential::PasswordCredential(const String& id, |
| 127 const String& password, | 128 const String& password, |
| 128 const String& name, | 129 const String& name, |
| 129 const KURL& icon) | 130 const KURL& icon) |
| 130 : CredentialUserData( | 131 : CredentialUserData( |
| 131 PlatformPasswordCredential::Create(id, password, name, icon)), | 132 PlatformPasswordCredential::Create(id, password, name, icon)), |
| 132 id_name_("username"), | 133 id_name_("username"), |
| 133 password_name_("password") {} | 134 password_name_("password") {} |
| 134 | 135 |
| 136 const String& PasswordCredential::password() const { | |
| 137 return RuntimeEnabledFeatures::passwordCredentialPasswordEnabled() | |
|
Mike West
2017/05/16 09:30:45
I think you can safely change this to:
```
return
jdoerrie
2017/05/17 15:39:22
Done.
| |
| 138 ? static_cast<PlatformPasswordCredential*>( | |
| 139 platform_credential_.Get()) | |
| 140 ->Password() | |
| 141 : empty_password_; | |
| 142 } | |
| 143 | |
| 135 PassRefPtr<EncodedFormData> PasswordCredential::EncodeFormData( | 144 PassRefPtr<EncodedFormData> PasswordCredential::EncodeFormData( |
| 136 String& content_type) const { | 145 String& content_type) const { |
| 137 if (additional_data_.isURLSearchParams()) { | 146 if (additional_data_.isURLSearchParams()) { |
| 138 // If |additionalData| is a 'URLSearchParams' object, build a urlencoded | 147 // If |additionalData| is a 'URLSearchParams' object, build a urlencoded |
| 139 // response. | 148 // response. |
| 140 URLSearchParams* params = URLSearchParams::Create(String()); | 149 URLSearchParams* params = URLSearchParams::Create(String()); |
| 141 URLSearchParams* additional_data = additional_data_.getAsURLSearchParams(); | 150 URLSearchParams* additional_data = additional_data_.getAsURLSearchParams(); |
| 142 for (const auto& param : additional_data->Params()) { | 151 for (const auto& param : additional_data->Params()) { |
| 143 const String& name = param.first; | 152 const String& name = param.first; |
| 144 if (name != idName() && name != passwordName()) | 153 if (name != idName() && name != passwordName()) |
| 145 params->append(name, param.second); | 154 params->append(name, param.second); |
| 146 } | 155 } |
| 147 params->append(idName(), id()); | 156 params->append(idName(), id()); |
| 148 params->append(passwordName(), Password()); | 157 params->append(passwordName(), password()); |
|
Mike West
2017/05/16 09:30:45
I don't think this is going to work, as the curren
jdoerrie
2017/05/17 15:39:22
Acknowledged.
| |
| 149 | 158 |
| 150 content_type = | 159 content_type = |
| 151 AtomicString("application/x-www-form-urlencoded;charset=UTF-8"); | 160 AtomicString("application/x-www-form-urlencoded;charset=UTF-8"); |
| 152 | 161 |
| 153 return params->ToEncodedFormData(); | 162 return params->ToEncodedFormData(); |
| 154 } | 163 } |
| 155 | 164 |
| 156 // Otherwise, we'll build a multipart response. | 165 // Otherwise, we'll build a multipart response. |
| 157 FormData* form_data = FormData::Create(nullptr); | 166 FormData* form_data = FormData::Create(nullptr); |
| 158 if (additional_data_.isFormData()) { | 167 if (additional_data_.isFormData()) { |
| 159 FormData* additional_data = additional_data_.getAsFormData(); | 168 FormData* additional_data = additional_data_.getAsFormData(); |
| 160 for (const FormData::Entry* entry : additional_data->Entries()) { | 169 for (const FormData::Entry* entry : additional_data->Entries()) { |
| 161 const String& name = form_data->Decode(entry->name()); | 170 const String& name = form_data->Decode(entry->name()); |
| 162 if (name == idName() || name == passwordName()) | 171 if (name == idName() || name == passwordName()) |
| 163 continue; | 172 continue; |
| 164 | 173 |
| 165 if (entry->GetBlob()) | 174 if (entry->GetBlob()) |
| 166 form_data->append(name, entry->GetBlob(), entry->Filename()); | 175 form_data->append(name, entry->GetBlob(), entry->Filename()); |
| 167 else | 176 else |
| 168 form_data->append(name, form_data->Decode(entry->Value())); | 177 form_data->append(name, form_data->Decode(entry->Value())); |
| 169 } | 178 } |
| 170 } | 179 } |
| 171 form_data->append(idName(), id()); | 180 form_data->append(idName(), id()); |
| 172 form_data->append(passwordName(), Password()); | 181 form_data->append(passwordName(), password()); |
| 173 | 182 |
| 174 RefPtr<EncodedFormData> encoded_data = form_data->EncodeMultiPartFormData(); | 183 RefPtr<EncodedFormData> encoded_data = form_data->EncodeMultiPartFormData(); |
| 175 content_type = AtomicString("multipart/form-data; boundary=") + | 184 content_type = AtomicString("multipart/form-data; boundary=") + |
| 176 encoded_data->Boundary().data(); | 185 encoded_data->Boundary().data(); |
| 177 return encoded_data.Release(); | 186 return encoded_data.Release(); |
| 178 } | 187 } |
| 179 | 188 |
| 180 const String& PasswordCredential::Password() const { | |
| 181 return static_cast<PlatformPasswordCredential*>(platform_credential_.Get()) | |
| 182 ->Password(); | |
| 183 } | |
| 184 | |
| 185 DEFINE_TRACE(PasswordCredential) { | 189 DEFINE_TRACE(PasswordCredential) { |
| 186 CredentialUserData::Trace(visitor); | 190 CredentialUserData::Trace(visitor); |
| 187 visitor->Trace(additional_data_); | 191 visitor->Trace(additional_data_); |
| 188 } | 192 } |
| 189 | 193 |
| 190 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |