| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/web/public/web_state/js/credential_util.h" | 5 #include "ios/web/public/web_state/js/credential_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "ios/web/public/web_state/credential.h" | 11 #include "ios/web/public/web_state/credential.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "url/origin.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // "type" value for a DictionaryValue representation of PasswordCredential. | 17 // "type" value for a DictionaryValue representation of PasswordCredential. |
| 17 const char* kPasswordCredentialType = "PasswordCredential"; | 18 const char* kPasswordCredentialType = "PasswordCredential"; |
| 18 | 19 |
| 19 // "type" value for a DictionaryValue representation of FederatedCredential. | 20 // "type" value for a DictionaryValue representation of FederatedCredential. |
| 20 const char* kFederatedCredentialType = "FederatedCredential"; | 21 const char* kFederatedCredentialType = "FederatedCredential"; |
| 21 | 22 |
| 22 } // namespace | 23 } // namespace |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 federation_url = GURL(federation); | 68 federation_url = GURL(federation); |
| 68 if (!federation_url.is_valid()) | 69 if (!federation_url.is_valid()) |
| 69 return false; | 70 return false; |
| 70 } | 71 } |
| 71 | 72 |
| 72 credential->type = credential_type; | 73 credential->type = credential_type; |
| 73 credential->id = id; | 74 credential->id = id; |
| 74 credential->name = name; | 75 credential->name = name; |
| 75 credential->avatar_url = avatar_url; | 76 credential->avatar_url = avatar_url; |
| 76 credential->password = password; | 77 credential->password = password; |
| 77 credential->federation_url = federation_url; | 78 credential->federation_origin = url::Origin(federation_url); |
| 78 return true; | 79 return true; |
| 79 } | 80 } |
| 80 | 81 |
| 81 void CredentialToDictionaryValue(const Credential& credential, | 82 void CredentialToDictionaryValue(const Credential& credential, |
| 82 base::DictionaryValue* value) { | 83 base::DictionaryValue* value) { |
| 83 DCHECK(value); | 84 DCHECK(value); |
| 84 switch (credential.type) { | 85 switch (credential.type) { |
| 85 case CredentialType::CREDENTIAL_TYPE_EMPTY: | 86 case CredentialType::CREDENTIAL_TYPE_EMPTY: |
| 86 // Return an empty dictionary. This will cause "null" to be returned to | 87 // Return an empty dictionary. This will cause "null" to be returned to |
| 87 // the JavaScript Promise resolver. | 88 // the JavaScript Promise resolver. |
| 88 value->Clear(); | 89 value->Clear(); |
| 89 return; | 90 return; |
| 90 case CredentialType::CREDENTIAL_TYPE_PASSWORD: | 91 case CredentialType::CREDENTIAL_TYPE_PASSWORD: |
| 91 value->SetString("type", kPasswordCredentialType); | 92 value->SetString("type", kPasswordCredentialType); |
| 92 value->SetString("password", credential.password); | 93 value->SetString("password", credential.password); |
| 93 break; | 94 break; |
| 94 case CredentialType::CREDENTIAL_TYPE_FEDERATED: | 95 case CredentialType::CREDENTIAL_TYPE_FEDERATED: |
| 95 value->SetString("type", kFederatedCredentialType); | 96 value->SetString("type", kFederatedCredentialType); |
| 96 value->SetString("federation", credential.federation_url.spec()); | 97 value->SetString("federation", credential.federation_origin.Serialize()); |
| 97 break; | 98 break; |
| 98 default: | 99 default: |
| 99 NOTREACHED(); | 100 NOTREACHED(); |
| 100 } | 101 } |
| 101 value->SetString("id", credential.id); | 102 value->SetString("id", credential.id); |
| 102 value->SetString("name", credential.name); | 103 value->SetString("name", credential.name); |
| 103 value->SetString("avatarURL", credential.avatar_url.spec()); | 104 value->SetString("avatarURL", credential.avatar_url.spec()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 } // web | 107 } // web |
| OLD | NEW |