OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "components/password_manager/content/public/cpp/type_converters.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "components/password_manager/core/common/credential_manager_types.h" |
| 9 #include "mojo/common/common_type_converters.h" |
| 10 #include "mojo/common/url_type_converters.h" |
| 11 #include "third_party/WebKit/public/platform/WebCredential.h" |
| 12 #include "third_party/WebKit/public/platform/WebFederatedCredential.h" |
| 13 #include "third_party/WebKit/public/platform/WebPasswordCredential.h" |
| 14 |
| 15 using namespace password_manager; |
| 16 |
| 17 namespace mojo { |
| 18 |
| 19 namespace { |
| 20 |
| 21 mojom::CredentialType CMCredentialTypeToMojo(CredentialType type) { |
| 22 switch (type) { |
| 23 case CredentialType::CREDENTIAL_TYPE_EMPTY: |
| 24 return mojom::CredentialType::EMPTY; |
| 25 case CredentialType::CREDENTIAL_TYPE_PASSWORD: |
| 26 return mojom::CredentialType::PASSWORD; |
| 27 case CredentialType::CREDENTIAL_TYPE_FEDERATED: |
| 28 return mojom::CredentialType::FEDERATED; |
| 29 } |
| 30 |
| 31 NOTREACHED(); |
| 32 return mojom::CredentialType::EMPTY; |
| 33 } |
| 34 |
| 35 CredentialType MojoCredentialTypeToCM(mojom::CredentialType type) { |
| 36 switch (type) { |
| 37 case mojom::CredentialType::EMPTY: |
| 38 return CredentialType::CREDENTIAL_TYPE_EMPTY; |
| 39 case mojom::CredentialType::PASSWORD: |
| 40 return CredentialType::CREDENTIAL_TYPE_PASSWORD; |
| 41 case mojom::CredentialType::FEDERATED: |
| 42 return CredentialType::CREDENTIAL_TYPE_FEDERATED; |
| 43 } |
| 44 |
| 45 NOTREACHED(); |
| 46 return CredentialType::CREDENTIAL_TYPE_EMPTY; |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 mojom::CredentialInfoPtr |
| 52 TypeConverter<mojom::CredentialInfoPtr, CredentialInfo>::Convert( |
| 53 const CredentialInfo& input) { |
| 54 mojom::CredentialInfoPtr output(mojom::CredentialInfo::New()); |
| 55 output->type = CMCredentialTypeToMojo(input.type); |
| 56 output->id = mojo::String::From(input.id); |
| 57 output->name = mojo::String::From(input.name); |
| 58 output->icon = mojo::String::From(input.icon); |
| 59 output->password = mojo::String::From(input.password); |
| 60 output->federation = input.federation; |
| 61 |
| 62 return output; |
| 63 } |
| 64 |
| 65 CredentialInfo TypeConverter<CredentialInfo, mojom::CredentialInfoPtr>::Convert( |
| 66 const mojom::CredentialInfoPtr& input) { |
| 67 CredentialInfo output; |
| 68 output.type = MojoCredentialTypeToCM(input->type); |
| 69 output.id = input->id.To<base::string16>(); |
| 70 output.name = input->name.To<base::string16>(); |
| 71 output.icon = input->icon.To<GURL>(); |
| 72 output.password = input->password.To<base::string16>(); |
| 73 output.federation = input->federation; |
| 74 |
| 75 return output; |
| 76 } |
| 77 |
| 78 mojom::CredentialInfoPtr |
| 79 TypeConverter<mojom::CredentialInfoPtr, blink::WebCredential>::Convert( |
| 80 const blink::WebCredential& input) { |
| 81 mojom::CredentialInfoPtr output(mojom::CredentialInfo::New()); |
| 82 |
| 83 if (input.isPasswordCredential()) { |
| 84 // blink::WebPasswordCredential |
| 85 output->type = mojom::CredentialType::PASSWORD; |
| 86 output->password = mojo::String::From(base::string16( |
| 87 static_cast<const blink::WebPasswordCredential&>(input).password())); |
| 88 } else { |
| 89 DCHECK(input.isFederatedCredential()); |
| 90 // blink::WebFederatedCredential |
| 91 output->type = mojom::CredentialType::FEDERATED; |
| 92 output->federation = |
| 93 static_cast<const blink::WebFederatedCredential&>(input).provider(); |
| 94 } |
| 95 output->id = mojo::String::From(base::string16(input.id())); |
| 96 output->name = mojo::String::From(base::string16(input.name())); |
| 97 output->icon = mojo::String::From(GURL(input.iconURL())); |
| 98 |
| 99 return output; |
| 100 } |
| 101 |
| 102 scoped_ptr<blink::WebCredential> TypeConverter< |
| 103 scoped_ptr<blink::WebCredential>, |
| 104 mojom::CredentialInfoPtr>::Convert(const mojom::CredentialInfoPtr& input) { |
| 105 scoped_ptr<blink::WebCredential> output; |
| 106 |
| 107 switch (input->type) { |
| 108 case mojom::CredentialType::PASSWORD: |
| 109 output.reset(new blink::WebPasswordCredential( |
| 110 input->id.To<base::string16>(), input->password.To<base::string16>(), |
| 111 input->name.To<base::string16>(), input->icon.To<GURL>())); |
| 112 break; |
| 113 case mojom::CredentialType::FEDERATED: |
| 114 output.reset(new blink::WebFederatedCredential( |
| 115 input->id.To<base::string16>(), input->federation, |
| 116 input->name.To<base::string16>(), input->icon.To<GURL>())); |
| 117 break; |
| 118 case mojom::CredentialType::EMPTY: |
| 119 // Intentionally empty, return nullptr. |
| 120 break; |
| 121 default: |
| 122 NOTREACHED(); |
| 123 } |
| 124 |
| 125 return output; |
| 126 } |
| 127 |
| 128 } // namespace mojo |
OLD | NEW |