OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "grit/common_resources.h" | 15 #include "grit/common_resources.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 // static | 20 // static |
21 ExtensionAPI* ExtensionAPI::GetInstance() { | 21 ExtensionAPI* ExtensionAPI::GetInstance() { |
22 return Singleton<ExtensionAPI>::get(); | 22 return Singleton<ExtensionAPI>::get(); |
23 } | 23 } |
24 | 24 |
25 ExtensionAPI::ExtensionAPI() { | 25 static base::ListValue* LoadSchemaList(int resource_id) { |
26 const bool kAllowTrailingCommas = false; | 26 const bool kAllowTrailingCommas = false; |
27 std::string error_message; | 27 std::string error_message; |
28 scoped_ptr<Value> temp_value( | 28 Value* result = |
29 base::JSONReader::ReadAndReturnError( | 29 base::JSONReader::ReadAndReturnError( |
30 ResourceBundle::GetSharedInstance().GetRawDataResource( | 30 ResourceBundle::GetSharedInstance().GetRawDataResource( |
31 IDR_EXTENSION_API_JSON).as_string(), | 31 resource_id).as_string(), |
32 kAllowTrailingCommas, | 32 kAllowTrailingCommas, |
33 NULL, // error code | 33 NULL, // error code |
34 &error_message)); | 34 &error_message); |
35 CHECK(temp_value.get()) << error_message; | 35 CHECK(result) << error_message; |
36 CHECK(temp_value->IsType(base::Value::TYPE_LIST)) | 36 CHECK(result->IsType(base::Value::TYPE_LIST)); |
37 << "Top-level node in extension API is not dictionary"; | 37 return static_cast<base::ListValue*>(result); |
| 38 } |
38 | 39 |
39 value_.reset(static_cast<base::ListValue*>(temp_value.release())); | 40 static void AppendExtraSchemaList(base::ListValue* list, int resource_id) { |
| 41 Value* value; |
| 42 scoped_ptr<base::ListValue> to_append(LoadSchemaList(resource_id)); |
| 43 while (to_append->Remove(0, &value)) { |
| 44 list->Append(value); |
| 45 } |
| 46 } |
| 47 |
| 48 ExtensionAPI::ExtensionAPI() { |
| 49 value_.reset(LoadSchemaList(IDR_EXTENSION_API_JSON)); |
| 50 AppendExtraSchemaList(value_.get(), IDR_EXTENSION_API_JSON_EXTENSION); |
40 } | 51 } |
41 | 52 |
42 ExtensionAPI::~ExtensionAPI() { | 53 ExtensionAPI::~ExtensionAPI() { |
43 } | 54 } |
44 | 55 |
45 bool ExtensionAPI::IsPrivileged(const std::string& full_name) const { | 56 bool ExtensionAPI::IsPrivileged(const std::string& full_name) const { |
46 std::vector<std::string> split_full_name; | 57 std::vector<std::string> split_full_name; |
47 base::SplitString(full_name, '.', &split_full_name); | 58 base::SplitString(full_name, '.', &split_full_name); |
48 std::string name = split_full_name.back(); | 59 std::string name = split_full_name.back(); |
49 split_full_name.pop_back(); | 60 split_full_name.pop_back(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 104 |
94 bool unprivileged = false; | 105 bool unprivileged = false; |
95 DictionaryValue* child = FindListItem(child_list, "name", child_name); | 106 DictionaryValue* child = FindListItem(child_list, "name", child_name); |
96 if (!child || !child->GetBoolean("unprivileged", &unprivileged)) | 107 if (!child || !child->GetBoolean("unprivileged", &unprivileged)) |
97 return true; | 108 return true; |
98 | 109 |
99 return !unprivileged; | 110 return !unprivileged; |
100 } | 111 } |
101 | 112 |
102 } | 113 } |
OLD | NEW |