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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 // Parses through |args| replacing any BinaryValues with base64 encoded | 67 // Parses through |args| replacing any BinaryValues with base64 encoded |
68 // StringValues. Recurses over any nested ListValues, and calls | 68 // StringValues. Recurses over any nested ListValues, and calls |
69 // ConvertBinaryDictionaryValuesToBase64 for any nested DictionaryValues. | 69 // ConvertBinaryDictionaryValuesToBase64 for any nested DictionaryValues. |
70 void ConvertBinaryListElementsToBase64(base::ListValue* args) { | 70 void ConvertBinaryListElementsToBase64(base::ListValue* args) { |
71 size_t index = 0; | 71 size_t index = 0; |
72 for (base::ListValue::iterator iter = args->begin(); iter != args->end(); | 72 for (base::ListValue::iterator iter = args->begin(); iter != args->end(); |
73 ++iter, ++index) { | 73 ++iter, ++index) { |
74 if ((*iter)->IsType(base::Value::TYPE_BINARY)) { | 74 if ((*iter)->IsType(base::Value::TYPE_BINARY)) { |
75 base::BinaryValue* binary = NULL; | 75 base::BinaryValue* binary = nullptr; |
76 if (args->GetBinary(index, &binary)) | 76 if (args->GetBinary(index, &binary)) |
77 args->Set(index, ConvertBinaryToBase64(binary).release()); | 77 args->Set(index, ConvertBinaryToBase64(binary).release()); |
78 } else if ((*iter)->IsType(base::Value::TYPE_LIST)) { | 78 } else if ((*iter)->IsType(base::Value::TYPE_LIST)) { |
79 base::ListValue* list; | 79 base::ListValue* list; |
80 (*iter)->GetAsList(&list); | 80 (*iter)->GetAsList(&list); |
81 ConvertBinaryListElementsToBase64(list); | 81 ConvertBinaryListElementsToBase64(list); |
82 } else if ((*iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 82 } else if ((*iter)->IsType(base::Value::TYPE_DICTIONARY)) { |
83 base::DictionaryValue* dict; | 83 base::DictionaryValue* dict; |
84 (*iter)->GetAsDictionary(&dict); | 84 (*iter)->GetAsDictionary(&dict); |
85 ConvertBinaryDictionaryValuesToBase64(dict); | 85 ConvertBinaryDictionaryValuesToBase64(dict); |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 // Parses through |dict| replacing any BinaryValues with base64 encoded | 90 // Parses through |dict| replacing any BinaryValues with base64 encoded |
91 // StringValues. Recurses over any nested DictionaryValues, and calls | 91 // StringValues. Recurses over any nested DictionaryValues, and calls |
92 // ConvertBinaryListElementsToBase64 for any nested ListValues. | 92 // ConvertBinaryListElementsToBase64 for any nested ListValues. |
93 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict) { | 93 void ConvertBinaryDictionaryValuesToBase64(base::DictionaryValue* dict) { |
94 for (base::DictionaryValue::Iterator iter(*dict); !iter.IsAtEnd(); | 94 for (base::DictionaryValue::Iterator iter(*dict); !iter.IsAtEnd(); |
95 iter.Advance()) { | 95 iter.Advance()) { |
96 if (iter.value().IsType(base::Value::TYPE_BINARY)) { | 96 if (iter.value().IsType(base::Value::TYPE_BINARY)) { |
97 base::BinaryValue* binary = NULL; | 97 base::BinaryValue* binary = nullptr; |
98 if (dict->GetBinary(iter.key(), &binary)) | 98 if (dict->GetBinary(iter.key(), &binary)) |
99 dict->Set(iter.key(), ConvertBinaryToBase64(binary).release()); | 99 dict->Set(iter.key(), ConvertBinaryToBase64(binary).release()); |
100 } else if (iter.value().IsType(base::Value::TYPE_LIST)) { | 100 } else if (iter.value().IsType(base::Value::TYPE_LIST)) { |
101 const base::ListValue* list; | 101 const base::ListValue* list; |
102 iter.value().GetAsList(&list); | 102 iter.value().GetAsList(&list); |
103 ConvertBinaryListElementsToBase64(const_cast<base::ListValue*>(list)); | 103 ConvertBinaryListElementsToBase64(const_cast<base::ListValue*>(list)); |
104 } else if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { | 104 } else if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { |
105 const base::DictionaryValue* dict; | 105 const base::DictionaryValue* dict; |
106 iter.value().GetAsDictionary(&dict); | 106 iter.value().GetAsDictionary(&dict); |
107 ConvertBinaryDictionaryValuesToBase64( | 107 ConvertBinaryDictionaryValuesToBase64( |
108 const_cast<base::DictionaryValue*>(dict)); | 108 const_cast<base::DictionaryValue*>(dict)); |
109 } | 109 } |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 } // namespace | 113 } // namespace |
114 | 114 |
115 RulesFunction::RulesFunction() | 115 RulesFunction::RulesFunction() : rules_registry_(nullptr) { |
116 : rules_registry_(NULL) { | |
117 } | 116 } |
118 | 117 |
119 RulesFunction::~RulesFunction() {} | 118 RulesFunction::~RulesFunction() {} |
120 | 119 |
121 bool RulesFunction::HasPermission() { | 120 bool RulesFunction::HasPermission() { |
122 std::string event_name; | 121 std::string event_name; |
123 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); | 122 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); |
124 if (IsWebViewEvent(event_name) && | 123 if (IsWebViewEvent(event_name) && |
125 extension_->permissions_data()->HasAPIPermission( | 124 extension_->permissions_data()->HasAPIPermission( |
126 extensions::APIPermission::kWebView)) | 125 extensions::APIPermission::kWebView)) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } else { | 214 } else { |
216 rules_registry_->GetAllRules(extension_id(), &rules); | 215 rules_registry_->GetAllRules(extension_id(), &rules); |
217 } | 216 } |
218 | 217 |
219 results_ = GetRules::Results::Create(rules); | 218 results_ = GetRules::Results::Create(rules); |
220 | 219 |
221 return true; | 220 return true; |
222 } | 221 } |
223 | 222 |
224 } // namespace extensions | 223 } // namespace extensions |
OLD | NEW |