| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char kDeclarativeEventPrefix[] = "declarative"; | 38 const char kDeclarativeEventPrefix[] = "declarative"; |
| 39 | 39 |
| 40 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict); | 40 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict); |
| 41 | 41 |
| 42 // Encodes |binary| as base64 and returns a new StringValue populated with the | 42 // Encodes |binary| as base64 and returns a new StringValue populated with the |
| 43 // encoded string. | 43 // encoded string. |
| 44 std::unique_ptr<base::Value> ConvertBinaryToBase64(base::Value* binary) { | 44 std::unique_ptr<base::Value> ConvertBinaryToBase64(base::Value* binary) { |
| 45 std::string binary_data = std::string(binary->GetBuffer(), binary->GetSize()); | 45 std::string binary_data(binary->GetBlob().data(), binary->GetBlob().size()); |
| 46 std::string data64; | 46 std::string data64; |
| 47 base::Base64Encode(binary_data, &data64); | 47 base::Base64Encode(binary_data, &data64); |
| 48 return std::unique_ptr<base::Value>(new base::Value(data64)); | 48 return std::unique_ptr<base::Value>(new base::Value(data64)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Parses through |args| replacing any BinaryValues with base64 encoded | 51 // Parses through |args| replacing any BinaryValues with base64 encoded |
| 52 // StringValues. Recurses over any nested ListValues, and calls | 52 // StringValues. Recurses over any nested ListValues, and calls |
| 53 // ConvertBinaryDictionaryValuesToBase64 for any nested DictionaryValues. | 53 // ConvertBinaryDictionaryValuesToBase64 for any nested DictionaryValues. |
| 54 void ConvertBinaryListElementsToBase64(base::ListValue* args) { | 54 void ConvertBinaryListElementsToBase64(base::ListValue* args) { |
| 55 size_t index = 0; | 55 size_t index = 0; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 std::unique_ptr<base::ListValue> rules_value(new base::ListValue()); | 219 std::unique_ptr<base::ListValue> rules_value(new base::ListValue()); |
| 220 for (const auto& rule : rules) | 220 for (const auto& rule : rules) |
| 221 rules_value->Append(rule->ToValue()); | 221 rules_value->Append(rule->ToValue()); |
| 222 SetResult(std::move(rules_value)); | 222 SetResult(std::move(rules_value)); |
| 223 | 223 |
| 224 return true; | 224 return true; |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace extensions | 227 } // namespace extensions |
| OLD | NEW |