Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Side by Side Diff: chrome/common/extensions/api/extension_api.cc

Issue 8869003: Move the "extension" namespace from extension_api.json into extension_api_extension.json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 Value* LoadValue(int resource_id) {
not at google - send to devlin 2011/12/07 23:26:00 LoadSchema or something might be more descriptive.
koz (OOO until 15th September) 2011/12/09 19:24:18 I've changed this to be a pair of functions LoadSc
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 return result;
37 << "Top-level node in extension API is not dictionary"; 37 }
38 38
39 value_.reset(static_cast<base::ListValue*>(temp_value.release())); 39 ExtensionAPI::ExtensionAPI() {
40 value_.reset(
41 static_cast<base::ListValue*>(LoadValue(IDR_EXTENSION_API_JSON)));
42 value_->Append(LoadValue(IDR_EXTENSION_API_EXTENSION_JSON));
not at google - send to devlin 2011/12/07 23:26:00 It sounds awkward, but names like IDR_EXTENSION_ST
Aaron Boodman 2011/12/07 23:30:35 cute.
koz (OOO until 15th September) 2011/12/09 19:24:18 I've gone with aa's suggestion of IDR_EXTENSION_AP
40 } 43 }
41 44
42 ExtensionAPI::~ExtensionAPI() { 45 ExtensionAPI::~ExtensionAPI() {
43 } 46 }
44 47
45 bool ExtensionAPI::IsPrivileged(const std::string& full_name) const { 48 bool ExtensionAPI::IsPrivileged(const std::string& full_name) const {
46 std::vector<std::string> split_full_name; 49 std::vector<std::string> split_full_name;
47 base::SplitString(full_name, '.', &split_full_name); 50 base::SplitString(full_name, '.', &split_full_name);
48 std::string name = split_full_name.back(); 51 std::string name = split_full_name.back();
49 split_full_name.pop_back(); 52 split_full_name.pop_back();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 96
94 bool unprivileged = false; 97 bool unprivileged = false;
95 DictionaryValue* child = FindListItem(child_list, "name", child_name); 98 DictionaryValue* child = FindListItem(child_list, "name", child_name);
96 if (!child || !child->GetBoolean("unprivileged", &unprivileged)) 99 if (!child || !child->GetBoolean("unprivileged", &unprivileged))
97 return true; 100 return true;
98 101
99 return !unprivileged; 102 return !unprivileged;
100 } 103 }
101 104
102 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698