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 "chrome/common/extensions/api/extension_api.h" | 5 #include "chrome/common/extensions/api/extension_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/common/extensions/api/generated_schemas.h" |
16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_permission_set.h" | 18 #include "chrome/common/extensions/extension_permission_set.h" |
18 #include "grit/common_resources.h" | 19 #include "grit/common_resources.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // Adds any APIs listed in "dependencies" found in |schema| but not in | 26 // Adds any APIs listed in "dependencies" found in |schema| but not in |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 resource_id).as_string(), | 75 resource_id).as_string(), |
75 kAllowTrailingCommas, | 76 kAllowTrailingCommas, |
76 NULL, // error code | 77 NULL, // error code |
77 &error_message); | 78 &error_message); |
78 CHECK(result) << error_message; | 79 CHECK(result) << error_message; |
79 CHECK(result->IsType(base::Value::TYPE_LIST)); | 80 CHECK(result->IsType(base::Value::TYPE_LIST)); |
80 return static_cast<base::ListValue*>(result); | 81 return static_cast<base::ListValue*>(result); |
81 } | 82 } |
82 | 83 |
83 void ExtensionAPI::LoadSchemaFromResource(int resource_id) { | 84 void ExtensionAPI::LoadSchemaFromResource(int resource_id) { |
84 scoped_ptr<base::ListValue> loaded(LoadSchemaList(resource_id)); | 85 RegisterSchema(LoadSchemaList(resource_id)); |
| 86 } |
| 87 |
| 88 void ExtensionAPI::RegisterSchema(base::ListValue* loaded_schema) { |
| 89 // We take ownership of loaded_schema, so we need to delete it. |
| 90 scoped_ptr<base::ListValue> scoped_loaded_schema(loaded_schema); |
85 Value* value = NULL; | 91 Value* value = NULL; |
86 std::string schema_namespace; | 92 std::string schema_namespace; |
87 while (!loaded->empty()) { | 93 while (!loaded_schema->empty()) { |
88 loaded->Remove(loaded->GetSize() - 1, &value); | 94 loaded_schema->Remove(loaded_schema->GetSize() - 1, &value); |
89 CHECK(value->IsType(Value::TYPE_DICTIONARY)); | 95 CHECK(value->IsType(Value::TYPE_DICTIONARY)); |
90 const DictionaryValue* schema = static_cast<const DictionaryValue*>(value); | 96 const DictionaryValue* schema = static_cast<const DictionaryValue*>(value); |
91 CHECK(schema->GetString("namespace", &schema_namespace)); | 97 CHECK(schema->GetString("namespace", &schema_namespace)); |
92 schemas_[schema_namespace] = linked_ptr<const DictionaryValue>(schema); | 98 schemas_[schema_namespace] = linked_ptr<const DictionaryValue>(schema); |
93 } | 99 } |
94 } | 100 } |
95 | 101 |
96 ExtensionAPI::ExtensionAPI() { | 102 ExtensionAPI::ExtensionAPI() { |
97 static int kJsonApiResourceIds[] = { | 103 static int kJsonApiResourceIds[] = { |
98 IDR_EXTENSION_API_JSON_BOOKMARKS, | 104 IDR_EXTENSION_API_JSON_BOOKMARKS, |
99 IDR_EXTENSION_API_JSON_BROWSERACTION, | 105 IDR_EXTENSION_API_JSON_BROWSERACTION, |
100 IDR_EXTENSION_API_JSON_BROWSING_DATA, | 106 IDR_EXTENSION_API_JSON_BROWSING_DATA, |
101 IDR_EXTENSION_API_JSON_CHROMEAUTHPRIVATE, | 107 IDR_EXTENSION_API_JSON_CHROMEAUTHPRIVATE, |
102 IDR_EXTENSION_API_JSON_CHROMEOSINFOPRIVATE, | 108 IDR_EXTENSION_API_JSON_CHROMEOSINFOPRIVATE, |
103 IDR_EXTENSION_API_JSON_CHROMEPRIVATE, | 109 IDR_EXTENSION_API_JSON_CHROMEPRIVATE, |
104 IDR_EXTENSION_API_JSON_CONTENTSETTINGS, | 110 IDR_EXTENSION_API_JSON_CONTENTSETTINGS, |
105 IDR_EXTENSION_API_JSON_CONTEXTMENUS, | 111 IDR_EXTENSION_API_JSON_CONTEXTMENUS, |
106 IDR_EXTENSION_API_JSON_COOKIES, | 112 IDR_EXTENSION_API_JSON_COOKIES, |
107 IDR_EXTENSION_API_JSON_DEBUGGER, | 113 IDR_EXTENSION_API_JSON_DEBUGGER, |
108 IDR_EXTENSION_API_JSON_DEVTOOLS, | 114 IDR_EXTENSION_API_JSON_DEVTOOLS, |
109 IDR_EXTENSION_API_JSON_EXPERIMENTAL_ACCESSIBILITY, | 115 IDR_EXTENSION_API_JSON_EXPERIMENTAL_ACCESSIBILITY, |
110 IDR_EXTENSION_API_JSON_EXPERIMENTAL_APP, | 116 IDR_EXTENSION_API_JSON_EXPERIMENTAL_APP, |
111 IDR_EXTENSION_API_JSON_EXPERIMENTAL_BOOKMARKMANAGER, | 117 IDR_EXTENSION_API_JSON_EXPERIMENTAL_BOOKMARKMANAGER, |
112 IDR_EXTENSION_API_JSON_EXPERIMENTAL_DECLARATIVE, | 118 IDR_EXTENSION_API_JSON_EXPERIMENTAL_DECLARATIVE, |
113 IDR_EXTENSION_API_JSON_EXPERIMENTAL_DNS, | |
114 IDR_EXTENSION_API_JSON_EXPERIMENTAL_DOWNLOADS, | 119 IDR_EXTENSION_API_JSON_EXPERIMENTAL_DOWNLOADS, |
115 IDR_EXTENSION_API_JSON_EXPERIMENTAL_EXTENSIONS, | 120 IDR_EXTENSION_API_JSON_EXPERIMENTAL_EXTENSIONS, |
116 IDR_EXTENSION_API_JSON_EXPERIMENTAL_FONTS, | 121 IDR_EXTENSION_API_JSON_EXPERIMENTAL_FONTS, |
117 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INFOBARS, | 122 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INFOBARS, |
118 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_UI, | 123 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_UI, |
119 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD, | 124 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD, |
120 IDR_EXTENSION_API_JSON_EXPERIMENTAL_KEYBINDING, | 125 IDR_EXTENSION_API_JSON_EXPERIMENTAL_KEYBINDING, |
121 IDR_EXTENSION_API_JSON_EXPERIMENTAL_MANAGED_MODE, | 126 IDR_EXTENSION_API_JSON_EXPERIMENTAL_MANAGED_MODE, |
122 IDR_EXTENSION_API_JSON_EXPERIMENTAL_OFFSCREENTABS, | 127 IDR_EXTENSION_API_JSON_EXPERIMENTAL_OFFSCREENTABS, |
123 IDR_EXTENSION_API_JSON_EXPERIMENTAL_PROCESSES, | 128 IDR_EXTENSION_API_JSON_EXPERIMENTAL_PROCESSES, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 IDR_EXTENSION_API_JSON_WEBNAVIGATION, | 161 IDR_EXTENSION_API_JSON_WEBNAVIGATION, |
157 IDR_EXTENSION_API_JSON_WEBREQUEST, | 162 IDR_EXTENSION_API_JSON_WEBREQUEST, |
158 IDR_EXTENSION_API_JSON_WEBSOCKETPROXYPRIVATE, | 163 IDR_EXTENSION_API_JSON_WEBSOCKETPROXYPRIVATE, |
159 IDR_EXTENSION_API_JSON_WEBSTOREPRIVATE, | 164 IDR_EXTENSION_API_JSON_WEBSTOREPRIVATE, |
160 IDR_EXTENSION_API_JSON_WINDOWS, | 165 IDR_EXTENSION_API_JSON_WINDOWS, |
161 }; | 166 }; |
162 | 167 |
163 for (size_t i = 0; i < arraysize(kJsonApiResourceIds); i++) { | 168 for (size_t i = 0; i < arraysize(kJsonApiResourceIds); i++) { |
164 LoadSchemaFromResource(kJsonApiResourceIds[i]); | 169 LoadSchemaFromResource(kJsonApiResourceIds[i]); |
165 } | 170 } |
| 171 RegisterSchema(api::GeneratedSchemas::Get()); |
166 | 172 |
167 // Populate {completely,partially}_unprivileged_apis_. | 173 // Populate {completely,partially}_unprivileged_apis_. |
168 for (SchemaMap::iterator it = schemas_.begin(); it != schemas_.end(); ++it) { | 174 for (SchemaMap::iterator it = schemas_.begin(); it != schemas_.end(); ++it) { |
169 bool unprivileged = false; | 175 bool unprivileged = false; |
170 it->second->GetBoolean("unprivileged", &unprivileged); | 176 it->second->GetBoolean("unprivileged", &unprivileged); |
171 if (unprivileged) { | 177 if (unprivileged) { |
172 completely_unprivileged_apis_.insert(it->first); | 178 completely_unprivileged_apis_.insert(it->first); |
173 continue; | 179 continue; |
174 } | 180 } |
175 | 181 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 (*out)[it->first] = it->second; | 314 (*out)[it->first] = it->second; |
309 } | 315 } |
310 } | 316 } |
311 | 317 |
312 bool ExtensionAPI::IsWholeAPIPrivileged(const std::string& api_name) const { | 318 bool ExtensionAPI::IsWholeAPIPrivileged(const std::string& api_name) const { |
313 return !completely_unprivileged_apis_.count(api_name) && | 319 return !completely_unprivileged_apis_.count(api_name) && |
314 !partially_unprivileged_apis_.count(api_name); | 320 !partially_unprivileged_apis_.count(api_name); |
315 } | 321 } |
316 | 322 |
317 } // namespace extensions | 323 } // namespace extensions |
OLD | NEW |