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 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 return unprivileged; | 57 return unprivileged; |
58 } | 58 } |
59 | 59 |
60 return false; | 60 return false; |
61 } | 61 } |
62 | 62 |
63 base::StringPiece ReadFromResource(int resource_id) { | 63 base::StringPiece ReadFromResource(int resource_id) { |
64 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 64 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
65 } | 65 } |
66 | 66 |
67 scoped_ptr<ListValue> LoadSchemaList(const base::StringPiece& schema) { | 67 scoped_ptr<ListValue> LoadSchemaList(const std::string& name, |
68 const base::StringPiece& schema) { | |
68 std::string error_message; | 69 std::string error_message; |
69 scoped_ptr<Value> result( | 70 scoped_ptr<Value> result( |
70 base::JSONReader::ReadAndReturnError( | 71 base::JSONReader::ReadAndReturnError( |
71 schema.as_string(), | 72 schema.as_string(), |
72 base::JSON_PARSE_RFC, // options | 73 base::JSON_PARSE_RFC, // options |
73 NULL, // error code | 74 NULL, // error code |
74 &error_message)); | 75 &error_message)); |
76 | |
77 // Tracking down http://crbug.com/121424 | |
78 char buf[128]; | |
79 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", | |
80 name.c_str(), | |
81 result.get() ? result->GetType() : -1, | |
82 error_message.c_str()); | |
83 | |
75 CHECK(result.get()) << error_message << " for schema " << schema; | 84 CHECK(result.get()) << error_message << " for schema " << schema; |
76 CHECK(result->IsType(Value::TYPE_LIST)) << " for schema " << schema; | 85 CHECK(result->IsType(Value::TYPE_LIST)) << " for schema " << schema; |
77 return scoped_ptr<ListValue>(static_cast<ListValue*>(result.release())); | 86 return scoped_ptr<ListValue>(static_cast<ListValue*>(result.release())); |
78 } | 87 } |
79 | 88 |
80 DictionaryValue* FindListItem(const ListValue* list, | 89 DictionaryValue* FindListItem(const ListValue* list, |
81 const std::string& property_name, | 90 const std::string& property_name, |
82 const std::string& property_value) { | 91 const std::string& property_value) { |
83 for (size_t i = 0; i < list->GetSize(); ++i) { | 92 for (size_t i = 0; i < list->GetSize(); ++i) { |
84 DictionaryValue* item = NULL; | 93 DictionaryValue* item = NULL; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 // TODO(aa): Remove this code when all API descriptions have been updated. | 148 // TODO(aa): Remove this code when all API descriptions have been updated. |
140 *feature_type = "api"; | 149 *feature_type = "api"; |
141 *feature_name = full_name; | 150 *feature_name = full_name; |
142 return; | 151 return; |
143 } | 152 } |
144 | 153 |
145 *feature_type = full_name.substr(0, colon_index); | 154 *feature_type = full_name.substr(0, colon_index); |
146 *feature_name = full_name.substr(colon_index + 1); | 155 *feature_name = full_name.substr(colon_index + 1); |
147 } | 156 } |
148 | 157 |
149 void ExtensionAPI::LoadSchema(const base::StringPiece& schema) { | 158 void ExtensionAPI::LoadSchema(const std::string& name, |
150 scoped_ptr<ListValue> schema_list(LoadSchemaList(schema)); | 159 const base::StringPiece& schema) { |
160 scoped_ptr<ListValue> schema_list(LoadSchemaList(name, schema)); | |
151 std::string schema_namespace; | 161 std::string schema_namespace; |
152 | 162 |
153 while (!schema_list->empty()) { | 163 while (!schema_list->empty()) { |
154 const DictionaryValue* schema = NULL; | 164 const DictionaryValue* schema = NULL; |
155 { | 165 { |
156 Value* value = NULL; | 166 Value* value = NULL; |
157 schema_list->Remove(schema_list->GetSize() - 1, &value); | 167 schema_list->Remove(schema_list->GetSize() - 1, &value); |
158 CHECK(value->IsType(Value::TYPE_DICTIONARY)); | 168 CHECK(value->IsType(Value::TYPE_DICTIONARY)); |
159 schema = static_cast<const DictionaryValue*>(value); | 169 schema = static_cast<const DictionaryValue*>(value); |
160 } | 170 } |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 SchemaMap::iterator maybe_schema = schemas_.find(api_name); | 477 SchemaMap::iterator maybe_schema = schemas_.find(api_name); |
468 if (maybe_schema != schemas_.end()) { | 478 if (maybe_schema != schemas_.end()) { |
469 result = maybe_schema->second.get(); | 479 result = maybe_schema->second.get(); |
470 } else { | 480 } else { |
471 // Might not have loaded yet; or might just not exist. | 481 // Might not have loaded yet; or might just not exist. |
472 std::map<std::string, base::StringPiece>::iterator maybe_schema_resource = | 482 std::map<std::string, base::StringPiece>::iterator maybe_schema_resource = |
473 unloaded_schemas_.find(api_name); | 483 unloaded_schemas_.find(api_name); |
474 if (maybe_schema_resource == unloaded_schemas_.end()) | 484 if (maybe_schema_resource == unloaded_schemas_.end()) |
475 return NULL; | 485 return NULL; |
476 | 486 |
477 LoadSchema(maybe_schema_resource->second); | 487 LoadSchema(maybe_schema_resource->first, maybe_schema_resource->second); |
478 maybe_schema = schemas_.find(api_name); | 488 maybe_schema = schemas_.find(api_name); |
479 CHECK(schemas_.end() != maybe_schema); | 489 CHECK(schemas_.end() != maybe_schema); |
480 result = maybe_schema->second.get(); | 490 result = maybe_schema->second.get(); |
481 } | 491 } |
482 | 492 |
483 if (!child_name.empty()) | 493 if (!child_name.empty()) |
484 result = GetSchemaChild(result, child_name); | 494 result = GetSchemaChild(result, child_name); |
485 | 495 |
486 return result; | 496 return result; |
487 } | 497 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 continue; | 719 continue; |
710 } | 720 } |
711 | 721 |
712 if (i->second.MatchesURL(url)) | 722 if (i->second.MatchesURL(url)) |
713 out->insert(i->first); | 723 out->insert(i->first); |
714 } | 724 } |
715 } | 725 } |
716 | 726 |
717 void ExtensionAPI::LoadAllSchemas() { | 727 void ExtensionAPI::LoadAllSchemas() { |
718 while (unloaded_schemas_.size()) { | 728 while (unloaded_schemas_.size()) { |
719 LoadSchema(unloaded_schemas_.begin()->second); | 729 std::map<std::string, base::StringPiece>::iterator next = |
koz (OOO until 15th September)
2012/04/30 01:18:41
nit: next -> it
not at google - send to devlin
2012/04/30 04:43:32
Done.
| |
730 unloaded_schemas_.begin(); | |
731 LoadSchema(next->first, next->second); | |
720 } | 732 } |
721 } | 733 } |
722 | 734 |
723 } // namespace extensions | 735 } // namespace extensions |
OLD | NEW |