| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "extensions/browser/api/declarative/declarative_api.h" | 5 #include "extensions/browser/api/declarative/declarative_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return std::unique_ptr<base::StringValue>(new base::StringValue(data64)); | 49 return std::unique_ptr<base::StringValue>(new base::StringValue(data64)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Parses through |args| replacing any BinaryValues with base64 encoded | 52 // Parses through |args| replacing any BinaryValues with base64 encoded |
| 53 // StringValues. Recurses over any nested ListValues, and calls | 53 // StringValues. Recurses over any nested ListValues, and calls |
| 54 // ConvertBinaryDictionaryValuesToBase64 for any nested DictionaryValues. | 54 // ConvertBinaryDictionaryValuesToBase64 for any nested DictionaryValues. |
| 55 void ConvertBinaryListElementsToBase64(base::ListValue* args) { | 55 void ConvertBinaryListElementsToBase64(base::ListValue* args) { |
| 56 size_t index = 0; | 56 size_t index = 0; |
| 57 for (base::ListValue::iterator iter = args->begin(); iter != args->end(); | 57 for (base::ListValue::iterator iter = args->begin(); iter != args->end(); |
| 58 ++iter, ++index) { | 58 ++iter, ++index) { |
| 59 if ((*iter)->IsType(base::Value::TYPE_BINARY)) { | 59 if ((*iter)->IsType(base::Value::Type::BINARY)) { |
| 60 base::BinaryValue* binary = NULL; | 60 base::BinaryValue* binary = NULL; |
| 61 if (args->GetBinary(index, &binary)) | 61 if (args->GetBinary(index, &binary)) |
| 62 args->Set(index, ConvertBinaryToBase64(binary).release()); | 62 args->Set(index, ConvertBinaryToBase64(binary).release()); |
| 63 } else if ((*iter)->IsType(base::Value::TYPE_LIST)) { | 63 } else if ((*iter)->IsType(base::Value::Type::LIST)) { |
| 64 base::ListValue* list; | 64 base::ListValue* list; |
| 65 (*iter)->GetAsList(&list); | 65 (*iter)->GetAsList(&list); |
| 66 ConvertBinaryListElementsToBase64(list); | 66 ConvertBinaryListElementsToBase64(list); |
| 67 } else if ((*iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 67 } else if ((*iter)->IsType(base::Value::Type::DICTIONARY)) { |
| 68 base::DictionaryValue* dict; | 68 base::DictionaryValue* dict; |
| 69 (*iter)->GetAsDictionary(&dict); | 69 (*iter)->GetAsDictionary(&dict); |
| 70 ConvertBinaryDictionaryValuesToBase64(dict); | 70 ConvertBinaryDictionaryValuesToBase64(dict); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Parses through |dict| replacing any BinaryValues with base64 encoded | 75 // Parses through |dict| replacing any BinaryValues with base64 encoded |
| 76 // StringValues. Recurses over any nested DictionaryValues, and calls | 76 // StringValues. Recurses over any nested DictionaryValues, and calls |
| 77 // ConvertBinaryListElementsToBase64 for any nested ListValues. | 77 // ConvertBinaryListElementsToBase64 for any nested ListValues. |
| 78 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict) { | 78 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict) { |
| 79 for (base::DictionaryValue::Iterator iter(*dict); !iter.IsAtEnd(); | 79 for (base::DictionaryValue::Iterator iter(*dict); !iter.IsAtEnd(); |
| 80 iter.Advance()) { | 80 iter.Advance()) { |
| 81 if (iter.value().IsType(base::Value::TYPE_BINARY)) { | 81 if (iter.value().IsType(base::Value::Type::BINARY)) { |
| 82 base::BinaryValue* binary = NULL; | 82 base::BinaryValue* binary = NULL; |
| 83 if (dict->GetBinary(iter.key(), &binary)) | 83 if (dict->GetBinary(iter.key(), &binary)) |
| 84 dict->Set(iter.key(), ConvertBinaryToBase64(binary).release()); | 84 dict->Set(iter.key(), ConvertBinaryToBase64(binary).release()); |
| 85 } else if (iter.value().IsType(base::Value::TYPE_LIST)) { | 85 } else if (iter.value().IsType(base::Value::Type::LIST)) { |
| 86 const base::ListValue* list; | 86 const base::ListValue* list; |
| 87 iter.value().GetAsList(&list); | 87 iter.value().GetAsList(&list); |
| 88 ConvertBinaryListElementsToBase64(const_cast<base::ListValue*>(list)); | 88 ConvertBinaryListElementsToBase64(const_cast<base::ListValue*>(list)); |
| 89 } else if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { | 89 } else if (iter.value().IsType(base::Value::Type::DICTIONARY)) { |
| 90 const base::DictionaryValue* dict; | 90 const base::DictionaryValue* dict; |
| 91 iter.value().GetAsDictionary(&dict); | 91 iter.value().GetAsDictionary(&dict); |
| 92 ConvertBinaryDictionaryValuesToBase64( | 92 ConvertBinaryDictionaryValuesToBase64( |
| 93 const_cast<base::DictionaryValue*>(dict)); | 93 const_cast<base::DictionaryValue*>(dict)); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 std::unique_ptr<base::ListValue> rules_value(new base::ListValue()); | 220 std::unique_ptr<base::ListValue> rules_value(new base::ListValue()); |
| 221 for (const auto& rule : rules) | 221 for (const auto& rule : rules) |
| 222 rules_value->Append(rule->ToValue()); | 222 rules_value->Append(rule->ToValue()); |
| 223 SetResult(std::move(rules_value)); | 223 SetResult(std::move(rules_value)); |
| 224 | 224 |
| 225 return true; | 225 return true; |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace extensions | 228 } // namespace extensions |
| OLD | NEW |