diff options
Diffstat (limited to 'chrome/common/extensions/api')
-rw-r--r-- | chrome/common/extensions/api/extension_api.cc | 19 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api.h | 7 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api_unittest.cc | 49 | ||||
-rw-r--r-- | chrome/common/extensions/api/test.json | 199 |
4 files changed, 32 insertions, 242 deletions
diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc index f280bba..20021a3 100644 --- a/chrome/common/extensions/api/extension_api.cc +++ b/chrome/common/extensions/api/extension_api.cc @@ -543,7 +543,7 @@ void RemoveDisallowedAPIs(const Extension& extension, } // namespace -std::set<std::string> ExtensionAPI::GetAPIsForContext( +scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( Feature::Context context, const Extension* extension, const GURL& url) { // We're forced to load all schemas now because we need to know the metadata // about every API -- and the metadata is stored in the schemas themselves. @@ -601,28 +601,17 @@ std::set<std::string> ExtensionAPI::GetAPIsForContext( // Filter out all non-API features and remove the feature type part of the // name. - std::set<std::string> result; + scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); for (std::set<std::string>::iterator iter = temp_result.begin(); iter != temp_result.end(); ++iter) { std::string feature_type; std::string feature_name; SplitDependencyName(*iter, &feature_type, &feature_name); if (feature_type == "api") - result.insert(feature_name); + result->insert(feature_name); } - return result; -} - -std::set<std::string> ExtensionAPI::GetAllAPINames() { - std::set<std::string> result; - for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) - result.insert(i->first); - for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin(); - i != unloaded_schemas_.end(); ++i) { - result.insert(i->first); - } - return result; + return result.Pass(); } Feature* ExtensionAPI::GetFeature(const std::string& full_name) { diff --git a/chrome/common/extensions/api/extension_api.h b/chrome/common/extensions/api/extension_api.h index 128129e..b74bdcc 100644 --- a/chrome/common/extensions/api/extension_api.h +++ b/chrome/common/extensions/api/extension_api.h @@ -88,11 +88,9 @@ class ExtensionAPI : public FeatureProvider { // Gets the APIs available to |context| given an |extension| and |url|. The // extension or URL may not be relevant to all contexts, and may be left // NULL/empty. - std::set<std::string> GetAPIsForContext( + scoped_ptr<std::set<std::string> > GetAPIsForContext( Feature::Context context, const Extension* extension, const GURL& url); - std::set<std::string> GetAllAPINames(); - // Gets a Feature object describing the API with the specified |full_name|. // This can be either an API namespace (like history, or // experimental.bookmarks), or it can be an individual function or event. @@ -160,8 +158,7 @@ class ExtensionAPI : public FeatureProvider { // Map from each API that hasn't been loaded yet to the schema which defines // it. Note that there may be multiple APIs per schema. - typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; - UnloadedSchemaMap unloaded_schemas_; + std::map<std::string, base::StringPiece> unloaded_schemas_; // Schemas for each namespace. typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc index 8584a1e..125085c 100644 --- a/chrome/common/extensions/api/extension_api_unittest.cc +++ b/chrome/common/extensions/api/extension_api_unittest.cc @@ -235,29 +235,32 @@ TEST(ExtensionAPI, ExtensionWithUnprivilegedAPIs) { scoped_ptr<ExtensionAPI> extension_api( ExtensionAPI::CreateWithDefaultConfiguration()); - std::set<std::string> privileged_apis = extension_api->GetAPIsForContext( - Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); + scoped_ptr<std::set<std::string> > privileged_apis = + extension_api->GetAPIsForContext( + Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); - std::set<std::string> unprivileged_apis = extension_api->GetAPIsForContext( - Feature::UNBLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); + scoped_ptr<std::set<std::string> > unprivileged_apis = + extension_api->GetAPIsForContext( + Feature::UNBLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); - std::set<std::string> content_script_apis = extension_api->GetAPIsForContext( - Feature::CONTENT_SCRIPT_CONTEXT, extension.get(), GURL()); + scoped_ptr<std::set<std::string> > content_script_apis = + extension_api->GetAPIsForContext( + Feature::CONTENT_SCRIPT_CONTEXT, extension.get(), GURL()); // "storage" is completely unprivileged. - EXPECT_EQ(1u, privileged_apis.count("storage")); - EXPECT_EQ(1u, unprivileged_apis.count("storage")); - EXPECT_EQ(1u, content_script_apis.count("storage")); + EXPECT_EQ(1u, privileged_apis->count("storage")); + EXPECT_EQ(1u, unprivileged_apis->count("storage")); + EXPECT_EQ(1u, content_script_apis->count("storage")); // "extension" is partially unprivileged. - EXPECT_EQ(1u, privileged_apis.count("extension")); - EXPECT_EQ(1u, unprivileged_apis.count("extension")); - EXPECT_EQ(1u, content_script_apis.count("extension")); + EXPECT_EQ(1u, privileged_apis->count("extension")); + EXPECT_EQ(1u, unprivileged_apis->count("extension")); + EXPECT_EQ(1u, content_script_apis->count("extension")); // "history" is entirely privileged. - EXPECT_EQ(1u, privileged_apis.count("history")); - EXPECT_EQ(0u, unprivileged_apis.count("history")); - EXPECT_EQ(0u, content_script_apis.count("history")); + EXPECT_EQ(1u, privileged_apis->count("history")); + EXPECT_EQ(0u, unprivileged_apis->count("history")); + EXPECT_EQ(0u, content_script_apis->count("history")); } TEST(ExtensionAPI, ExtensionWithDependencies) { @@ -268,10 +271,10 @@ TEST(ExtensionAPI, ExtensionWithDependencies) { CreateExtensionWithPermission("ttsEngine"); scoped_ptr<ExtensionAPI> api( ExtensionAPI::CreateWithDefaultConfiguration()); - std::set<std::string> apis = api->GetAPIsForContext( + scoped_ptr<std::set<std::string> > apis = api->GetAPIsForContext( Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); - EXPECT_EQ(1u, apis.count("ttsEngine")); - EXPECT_EQ(1u, apis.count("tts")); + EXPECT_EQ(1u, apis->count("ttsEngine")); + EXPECT_EQ(1u, apis->count("tts")); } // Conversely, extension with the "tts" permission but not the "ttsEngine" @@ -281,18 +284,18 @@ TEST(ExtensionAPI, ExtensionWithDependencies) { CreateExtensionWithPermission("tts"); scoped_ptr<ExtensionAPI> api( ExtensionAPI::CreateWithDefaultConfiguration()); - std::set<std::string> apis = api->GetAPIsForContext( + scoped_ptr<std::set<std::string> > apis = api->GetAPIsForContext( Feature::BLESSED_EXTENSION_CONTEXT, extension.get(), GURL()); - EXPECT_EQ(0u, apis.count("ttsEngine")); - EXPECT_EQ(1u, apis.count("tts")); + EXPECT_EQ(0u, apis->count("ttsEngine")); + EXPECT_EQ(1u, apis->count("tts")); } } bool MatchesURL( ExtensionAPI* api, const std::string& api_name, const std::string& url) { - std::set<std::string> apis = + scoped_ptr<std::set<std::string> > apis = api->GetAPIsForContext(Feature::WEB_PAGE_CONTEXT, NULL, GURL(url)); - return apis.count(api_name); + return apis->count(api_name); } TEST(ExtensionAPI, URLMatching) { diff --git a/chrome/common/extensions/api/test.json b/chrome/common/extensions/api/test.json index add13d8..17ad531 100644 --- a/chrome/common/extensions/api/test.json +++ b/chrome/common/extensions/api/test.json @@ -104,205 +104,6 @@ ] } ] - }, - { - "name": "callbackAdded", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [] - }, - { - "name": "runNextTest", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [] - }, - { - "name": "fail", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - {"type": "any", "name": "message", "optional": true} - ] - }, - { - "name": "succeed", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - {"type": "any", "name": "message", "optional": true} - ] - }, - { - "name": "assertTrue", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - { - "name": "test", - "choices": [ - {"type": "string"}, - {"type": "boolean"} - ] - }, - {"type": "string", "name": "message", "optional": true} - ] - }, - { - "name": "assertFalse", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - { - "name": "test", - "choices": [ - {"type": "string"}, - {"type": "boolean"} - ] - }, - {"type": "string", "name": "message", "optional": true} - ] - }, - { - "name": "assertBool", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - { - "name": "test", - "choices": [ - {"type": "string"}, - {"type": "boolean"} - ] - }, - {"type": "boolean", "name": "expected"}, - {"type": "string", "name": "message", "optional": true} - ] - }, - { - "name": "checkDeepEq", - "type": "function", - "unprivileged": true, - "nocompile": true, - "allowAmbiguousOptionalArguments": true, - "parameters": [ - // These need to be optional because they can be null. - {"type": "any", "name": "expected", "optional": true}, - {"type": "any", "name": "actual", "optional": true} - ] - }, - { - "name": "assertEq", - "type": "function", - "unprivileged": true, - "nocompile": true, - "allowAmbiguousOptionalArguments": true, - "parameters": [ - // These need to be optional because they can be null. - {"type": "any", "name": "expected", "optional": true}, - {"type": "any", "name": "actual", "optional": true}, - {"type": "string", "name": "message", "optional": true} - ] - }, - { - "name": "assertNoLastError", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [] - }, - { - "name": "assertLastError", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - {"type": "string", "name": "expectedError"} - ] - }, - { - "name": "callback", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - {"type": "function", "name": "func", "optional": true}, - {"type": "string", "name": "expectedError", "optional": true} - ] - }, - { - "name": "listenOnce", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - // TODO(cduvall): Make this a $ref to events.Event. - {"type": "any", "name": "event"}, - {"type": "function", "name": "func"} - ] - }, - { - "name": "listenForever", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - // TODO(cduvall): Make this a $ref to events.Event. - {"type": "any", "name": "event"}, - {"type": "function", "name": "func"} - ] - }, - { - "name": "callbackPass", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - {"type": "function", "name": "func", "optional": true} - ] - }, - { - "name": "callbackFail", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - {"type": "string", "name": "expectedError"}, - {"type": "function", "name": "func", "optional": true} - ] - }, - { - "name": "runTests", - "type": "function", - "unprivileged": true, - "nocompile": true, - "parameters": [ - { - "type": "array", - "name": "tests", - "items": {"type": "function"} - } - ] - }, - { - "name": "getApiDefinitions", - "type": "function", - "nocompile": true, - "parameters": [ - { - "type": "array", - "name": "apiNames", - "optional": true, - "items": {"type": "string"} - } - ] } ], "events": [ |