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

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

Issue 14730002: Remove features code from ExtensionAPI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add CHECK back Created 7 years, 7 months 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
« no previous file with comments | « chrome/common/extensions/api/extension_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // there are unprivileged properties (e.g. in extensions), access to those 259 // there are unprivileged properties (e.g. in extensions), access to those
260 // never reaches C++ land. 260 // never reaches C++ land.
261 bool unprivileged = false; 261 bool unprivileged = false;
262 if (schema->GetBoolean("unprivileged", &unprivileged) && unprivileged) { 262 if (schema->GetBoolean("unprivileged", &unprivileged) && unprivileged) {
263 completely_unprivileged_apis_.insert(schema_namespace); 263 completely_unprivileged_apis_.insert(schema_namespace);
264 } else if (HasUnprivilegedChild(schema, "functions") || 264 } else if (HasUnprivilegedChild(schema, "functions") ||
265 HasUnprivilegedChild(schema, "events") || 265 HasUnprivilegedChild(schema, "events") ||
266 HasUnprivilegedChild(schema, "properties")) { 266 HasUnprivilegedChild(schema, "properties")) {
267 partially_unprivileged_apis_.insert(schema_namespace); 267 partially_unprivileged_apis_.insert(schema_namespace);
268 } 268 }
269
270 bool uses_feature_system = false;
271 schema->GetBoolean("uses_feature_system", &uses_feature_system);
272
273 if (!uses_feature_system) {
274 // Populate |url_matching_apis_|.
275 ListValue* matches = NULL;
276 if (schema->GetList("matches", &matches)) {
277 URLPatternSet pattern_set;
278 for (size_t i = 0; i < matches->GetSize(); ++i) {
279 std::string pattern;
280 CHECK(matches->GetString(i, &pattern));
281 pattern_set.AddPattern(
282 URLPattern(UserScript::ValidUserScriptSchemes(), pattern));
283 }
284 url_matching_apis_[schema_namespace] = pattern_set;
285 }
286 continue;
287 }
288
289 // Populate feature maps.
290 // TODO(aa): Consider not storing features that can never run on the current
291 // machine (e.g., because of platform restrictions).
292 SimpleFeature* feature = new SimpleFeature();
293 feature->set_name(schema_namespace);
294 feature->Parse(schema);
295
296 FeatureMap* schema_features = new FeatureMap();
297 CHECK(features_.insert(
298 std::make_pair(schema_namespace,
299 make_linked_ptr(schema_features))).second);
300 CHECK(schema_features->insert(
301 std::make_pair("", make_linked_ptr(feature))).second);
302
303 for (size_t i = 0; i < arraysize(kChildKinds); ++i) {
304 ListValue* child_list = NULL;
305 schema->GetList(kChildKinds[i], &child_list);
306 if (!child_list)
307 continue;
308
309 for (size_t j = 0; j < child_list->GetSize(); ++j) {
310 DictionaryValue* child = NULL;
311 CHECK(child_list->GetDictionary(j, &child));
312
313 scoped_ptr<SimpleFeature> child_feature(new SimpleFeature(*feature));
314 child_feature->Parse(child);
315 if (child_feature->Equals(*feature))
316 continue; // no need to store no-op features
317
318 std::string child_name;
319 CHECK(child->GetString("name", &child_name));
320 child_feature->set_name(schema_namespace + "." + child_name);
321 CHECK(schema_features->insert(
322 std::make_pair(child_name,
323 make_linked_ptr(child_feature.release()))).second);
324 }
325 }
326 } 269 }
327 } 270 }
328 271
329 ExtensionAPI::ExtensionAPI() { 272 ExtensionAPI::ExtensionAPI() {
330 } 273 }
331 274
332 ExtensionAPI::~ExtensionAPI() { 275 ExtensionAPI::~ExtensionAPI() {
333 } 276 }
334 277
335 void ExtensionAPI::InitDefaultConfiguration() { 278 void ExtensionAPI::InitDefaultConfiguration() {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 // Same as BLESSED_EXTENSION_CONTEXT, but only those APIs that are 501 // Same as BLESSED_EXTENSION_CONTEXT, but only those APIs that are
559 // unprivileged. 502 // unprivileged.
560 if (!IsAPIAllowed(name, extension)) 503 if (!IsAPIAllowed(name, extension))
561 return false; 504 return false;
562 if (!IsPrivilegedAPI(name)) 505 if (!IsPrivilegedAPI(name))
563 return false; 506 return false;
564 } 507 }
565 break; 508 break;
566 509
567 case Feature::WEB_PAGE_CONTEXT: 510 case Feature::WEB_PAGE_CONTEXT:
568 if (!url_matching_apis_.count(name)) 511 return false;
569 return false;
570 CHECK(url.is_valid());
571 // Availablility is determined by the url.
572 return url_matching_apis_[name].MatchesURL(url);
573 } 512 }
574 513
575 return true; 514 return true;
576 } 515 }
577 516
578 std::set<std::string> ExtensionAPI::GetAllAPINames() { 517 std::set<std::string> ExtensionAPI::GetAllAPINames() {
579 std::set<std::string> result; 518 std::set<std::string> result;
580 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) 519 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i)
581 result.insert(i->first); 520 result.insert(i->first);
582 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin(); 521 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin();
(...skipping 20 matching lines...) Expand all
603 feature = provider->second->GetFeature( 542 feature = provider->second->GetFeature(
604 GetAPINameFromFullName(feature_name, &child_name)); 543 GetAPINameFromFullName(feature_name, &child_name));
605 } 544 }
606 return feature; 545 return feature;
607 } 546 }
608 547
609 std::string ExtensionAPI::GetAPINameFromFullName(const std::string& full_name, 548 std::string ExtensionAPI::GetAPINameFromFullName(const std::string& full_name,
610 std::string* child_name) { 549 std::string* child_name) {
611 std::string api_name_candidate = full_name; 550 std::string api_name_candidate = full_name;
612 while (true) { 551 while (true) {
613 if (features_.find(api_name_candidate) != features_.end() || 552 if (schemas_.find(api_name_candidate) != schemas_.end() ||
614 schemas_.find(api_name_candidate) != schemas_.end() ||
615 unloaded_schemas_.find(api_name_candidate) != unloaded_schemas_.end()) { 553 unloaded_schemas_.find(api_name_candidate) != unloaded_schemas_.end()) {
616 std::string result = api_name_candidate; 554 std::string result = api_name_candidate;
617 555
618 if (child_name) { 556 if (child_name) {
619 if (result.length() < full_name.length()) 557 if (result.length() < full_name.length())
620 *child_name = full_name.substr(result.length() + 1); 558 *child_name = full_name.substr(result.length() + 1);
621 else 559 else
622 *child_name = ""; 560 *child_name = "";
623 } 561 }
624 562
(...skipping 16 matching lines...) Expand all
641 return extension->required_permission_set()->HasAnyAccessToAPI(name) || 579 return extension->required_permission_set()->HasAnyAccessToAPI(name) ||
642 extension->optional_permission_set()->HasAnyAccessToAPI(name); 580 extension->optional_permission_set()->HasAnyAccessToAPI(name);
643 } 581 }
644 582
645 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { 583 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) {
646 return completely_unprivileged_apis_.count(name) || 584 return completely_unprivileged_apis_.count(name) ||
647 partially_unprivileged_apis_.count(name); 585 partially_unprivileged_apis_.count(name);
648 } 586 }
649 587
650 } // namespace extensions 588 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698