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

Side by Side Diff: components/payments/core/payment_method_data.cc

Issue 2797833002: [Payments] base::string16 -> std::string in PaymentMethodData (Closed)
Patch Set: addressed comments Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/payments/core/payment_method_data.h" 5 #include "components/payments/core/payment_method_data.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 11
12 namespace payments { 12 namespace payments {
13 13
14 namespace { 14 namespace {
15 15
16 // These are defined as part of the spec at: 16 // These are defined as part of the spec at:
17 // https://w3c.github.io/browser-payment-api/#paymentmethoddata-dictionary 17 // https://w3c.github.io/browser-payment-api/#paymentmethoddata-dictionary
18 static const char kMethodDataData[] = "data"; 18 static const char kMethodDataData[] = "data";
19 static const char kSupportedMethods[] = "supportedMethods"; 19 static const char kSupportedMethods[] = "supportedMethods";
(...skipping 23 matching lines...) Expand all
43 this->supported_networks.clear(); 43 this->supported_networks.clear();
44 this->supported_types.clear(); 44 this->supported_types.clear();
45 45
46 const base::ListValue* supported_methods_list = nullptr; 46 const base::ListValue* supported_methods_list = nullptr;
47 // At least one supported method is required. 47 // At least one supported method is required.
48 if (!value.GetList(kSupportedMethods, &supported_methods_list) || 48 if (!value.GetList(kSupportedMethods, &supported_methods_list) ||
49 supported_methods_list->GetSize() == 0) { 49 supported_methods_list->GetSize() == 0) {
50 return false; 50 return false;
51 } 51 }
52 for (size_t i = 0; i < supported_methods_list->GetSize(); ++i) { 52 for (size_t i = 0; i < supported_methods_list->GetSize(); ++i) {
53 base::string16 supported_method; 53 std::string supported_method;
54 if (!supported_methods_list->GetString(i, &supported_method)) { 54 if (!supported_methods_list->GetString(i, &supported_method) ||
55 !base::IsStringASCII(supported_method)) {
55 return false; 56 return false;
56 } 57 }
57 this->supported_methods.push_back(supported_method); 58 this->supported_methods.push_back(supported_method);
58 } 59 }
59 60
60 // Data is optional, but if a dictionary is present, save a stringified 61 // Data is optional, but if a dictionary is present, save a stringified
61 // version and attempt to parse supportedNetworks/supportedTypes. 62 // version and attempt to parse supportedNetworks/supportedTypes.
62 const base::DictionaryValue* data_dict = nullptr; 63 const base::DictionaryValue* data_dict = nullptr;
63 if (value.GetDictionary(kMethodDataData, &data_dict)) { 64 if (value.GetDictionary(kMethodDataData, &data_dict)) {
64 std::string json_data; 65 std::string json_data;
65 base::JSONWriter::Write(*data_dict, &json_data); 66 base::JSONWriter::Write(*data_dict, &json_data);
66 this->data = base::UTF8ToUTF16(json_data); 67 this->data = json_data;
67 const base::ListValue* supported_networks_list = nullptr; 68 const base::ListValue* supported_networks_list = nullptr;
68 if (data_dict->GetList(kSupportedNetworks, &supported_networks_list)) { 69 if (data_dict->GetList(kSupportedNetworks, &supported_networks_list)) {
69 for (size_t i = 0; i < supported_networks_list->GetSize(); ++i) { 70 for (size_t i = 0; i < supported_networks_list->GetSize(); ++i) {
70 base::string16 supported_network; 71 std::string supported_network;
71 if (!supported_networks_list->GetString(i, &supported_network)) { 72 if (!supported_networks_list->GetString(i, &supported_network) ||
73 !base::IsStringASCII(supported_network)) {
72 return false; 74 return false;
73 } 75 }
74 this->supported_networks.push_back(supported_network); 76 this->supported_networks.push_back(supported_network);
75 } 77 }
76 } 78 }
77 const base::ListValue* supported_types_list = nullptr; 79 const base::ListValue* supported_types_list = nullptr;
78 if (data_dict->GetList(kSupportedTypes, &supported_types_list)) { 80 if (data_dict->GetList(kSupportedTypes, &supported_types_list)) {
79 for (size_t i = 0; i < supported_types_list->GetSize(); ++i) { 81 for (size_t i = 0; i < supported_types_list->GetSize(); ++i) {
80 base::string16 supported_type; 82 std::string supported_type;
81 if (!supported_types_list->GetString(i, &supported_type)) { 83 if (!supported_types_list->GetString(i, &supported_type) ||
84 !base::IsStringASCII(supported_type)) {
82 return false; 85 return false;
83 } 86 }
84 this->supported_types.push_back(supported_type); 87 this->supported_types.push_back(supported_type);
85 } 88 }
86 } 89 }
87 } 90 }
88 return true; 91 return true;
89 } 92 }
90 93
91 } // namespace payments 94 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/payment_method_data.h ('k') | components/payments/core/payment_method_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698