diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-25 04:40:15 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-25 04:40:15 +0000 |
commit | 093eceb36cac846cdfd5e1d67b50a8a34374eec8 (patch) | |
tree | ff3017a422f910b406a879240d72371ece0b93c4 /chrome/common | |
parent | 7b56f0813b23bca66949efc7b29a713ce7521ad1 (diff) | |
download | chromium_src-093eceb36cac846cdfd5e1d67b50a8a34374eec8.zip chromium_src-093eceb36cac846cdfd5e1d67b50a8a34374eec8.tar.gz chromium_src-093eceb36cac846cdfd5e1d67b50a8a34374eec8.tar.bz2 |
Add the ability to express dependencies between JSON schema files for the extension APIs by setting a "dependencies" attribute, and add a dependency for "tts" from "ttsEngine".
BUG=110944
TEST=unit_tests --gtest_filter=ExtensionAPI*, and as in bug
Review URL: http://codereview.chromium.org/9280006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/extensions/api/browserAction.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/contextMenus.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/experimental.bookmarkManager.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/experimental.infobars.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/experimental.privacy.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api.cc | 35 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api.h | 6 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api_unittest.cc | 32 | ||||
-rw-r--r-- | chrome/common/extensions/api/pageAction.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/proxy.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/tabs.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/ttsEngine.json | 1 | ||||
-rw-r--r-- | chrome/common/extensions/api/windows.json | 1 |
14 files changed, 82 insertions, 2 deletions
diff --git a/chrome/common/extensions/api/browserAction.json b/chrome/common/extensions/api/browserAction.json index c99ec92..a7f0f85 100644 --- a/chrome/common/extensions/api/browserAction.json +++ b/chrome/common/extensions/api/browserAction.json @@ -1,6 +1,7 @@ [ { "namespace": "browserAction", + "dependencies": [ "tabs" ], "types": [], "functions": [ { diff --git a/chrome/common/extensions/api/contextMenus.json b/chrome/common/extensions/api/contextMenus.json index dbbbe6d..aa60918 100644 --- a/chrome/common/extensions/api/contextMenus.json +++ b/chrome/common/extensions/api/contextMenus.json @@ -1,6 +1,7 @@ [ { "namespace": "contextMenus", + "dependencies": [ "tabs" ], "types": [ { "id": "OnClickData", diff --git a/chrome/common/extensions/api/experimental.bookmarkManager.json b/chrome/common/extensions/api/experimental.bookmarkManager.json index 24a9844..c8cd6cd 100644 --- a/chrome/common/extensions/api/experimental.bookmarkManager.json +++ b/chrome/common/extensions/api/experimental.bookmarkManager.json @@ -2,6 +2,7 @@ { "namespace": "experimental.bookmarkManager", "nodoc": true, + "dependencies": [ "bookmarks" ], "types": [ { "id": "BookmarkNodeDataElement", diff --git a/chrome/common/extensions/api/experimental.infobars.json b/chrome/common/extensions/api/experimental.infobars.json index 59b493e..7bffdc3 100644 --- a/chrome/common/extensions/api/experimental.infobars.json +++ b/chrome/common/extensions/api/experimental.infobars.json @@ -1,6 +1,7 @@ [ { "namespace": "experimental.infobars", + "dependencies": [ "windows" ], "types": [], "functions": [ { diff --git a/chrome/common/extensions/api/experimental.privacy.json b/chrome/common/extensions/api/experimental.privacy.json index aa0330a..2ad53e2 100644 --- a/chrome/common/extensions/api/experimental.privacy.json +++ b/chrome/common/extensions/api/experimental.privacy.json @@ -1,6 +1,7 @@ [ { "namespace": "experimental.privacy", + "dependencies": [ "types" ], "properties": { "network": { "type": "object", diff --git a/chrome/common/extensions/api/extension.json b/chrome/common/extensions/api/extension.json index 0e5dd4f..0b10faa 100644 --- a/chrome/common/extensions/api/extension.json +++ b/chrome/common/extensions/api/extension.json @@ -1,6 +1,7 @@ [ { "namespace": "extension", + "dependencies": [ "tabs" ], "types": [ { "id": "MessageSender", diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc index 66a0c5e..9e22c7d 100644 --- a/chrome/common/extensions/api/extension_api.cc +++ b/chrome/common/extensions/api/extension_api.cc @@ -19,6 +19,26 @@ namespace extensions { +namespace { + +// Adds any APIs listed in "dependencies" found in |schema| but not in +// |reference| to |out|. +void GetMissingDependencies( + const DictionaryValue& schema, + const ExtensionAPI::SchemaMap& reference, + std::set<std::string>* out) { + ListValue* dependencies = NULL; + if (!schema.GetList("dependencies", &dependencies)) + return; + for (size_t i = 0; i < dependencies->GetSize(); ++i) { + std::string api_name; + if (dependencies->GetString(i, &api_name) && !reference.count(api_name)) + out->insert(api_name); + } +} + +} // namespace + // static ExtensionAPI* ExtensionAPI::GetInstance() { return Singleton<ExtensionAPI>::get(); @@ -189,6 +209,21 @@ void ExtensionAPI::GetSchemasForExtension( // to return all schemas that might be needed. GetSchemasForPermissions(*extension.required_permission_set(), out); GetSchemasForPermissions(*extension.optional_permission_set(), out); + ResolveDependencies(out); +} + +void ExtensionAPI::ResolveDependencies(SchemaMap* out) const { + std::set<std::string> missing_dependencies; + for (SchemaMap::const_iterator i = out->begin(); i != out->end(); ++i) + GetMissingDependencies(*i->second, *out, &missing_dependencies); + + while (missing_dependencies.size()) { + std::string api_name = *missing_dependencies.begin(); + missing_dependencies.erase(api_name); + linked_ptr<const DictionaryValue> schema = schemas_.find(api_name)->second; + (*out)[api_name] = schema; + GetMissingDependencies(*schema, *out, &missing_dependencies); + } } void ExtensionAPI::GetDefaultSchemas(SchemaMap* out) const { diff --git a/chrome/common/extensions/api/extension_api.h b/chrome/common/extensions/api/extension_api.h index 82c2a24..cd97f44 100644 --- a/chrome/common/extensions/api/extension_api.h +++ b/chrome/common/extensions/api/extension_api.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -79,6 +79,10 @@ class ExtensionAPI { void GetSchemasForPermissions( const ExtensionPermissionSet& permissions, SchemaMap* out) const; + // Adds dependent schemas to |out| as determined by the "dependencies" + // property. + void ResolveDependencies(SchemaMap* out) const; + static ExtensionAPI* instance_; // Schemas for each namespace. diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc index 7ea1cf9..be481d1 100644 --- a/chrome/common/extensions/api/extension_api_unittest.cc +++ b/chrome/common/extensions/api/extension_api_unittest.cc @@ -1,9 +1,16 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/common/extensions/api/extension_api.h" +#include <string> + +#include "base/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/values.h" +#include "chrome/common/extensions/extension.h" #include "testing/gtest/include/gtest/gtest.h" using extensions::ExtensionAPI; @@ -25,3 +32,26 @@ TEST(ExtensionAPI, IsPrivileged) { EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews")); EXPECT_TRUE(extension_api->IsPrivileged("history.search")); } + +TEST(ExtensionAPI, Depends) { + // Fake extension with the "ttsEngine" permission but not the "tts" + // permission; it must load TTS. + DictionaryValue manifest; + manifest.SetString("name", "test extension"); + manifest.SetString("version", "1.0"); + { + scoped_ptr<ListValue> permissions(new ListValue()); + permissions->Append(Value::CreateStringValue("ttsEngine")); + manifest.Set("permissions", permissions.release()); + } + + std::string error; + scoped_refptr<Extension> extension(Extension::CreateWithId( + FilePath(), Extension::LOAD, manifest, Extension::NO_FLAGS, "x", &error)); + CHECK(extension.get()); + CHECK(error.empty()); + + ExtensionAPI::SchemaMap schemas; + ExtensionAPI::GetInstance()->GetSchemasForExtension(*extension, &schemas); + EXPECT_EQ(1u, schemas.count("tts")); +} diff --git a/chrome/common/extensions/api/pageAction.json b/chrome/common/extensions/api/pageAction.json index bed0bf3..16c5b4c 100644 --- a/chrome/common/extensions/api/pageAction.json +++ b/chrome/common/extensions/api/pageAction.json @@ -1,6 +1,7 @@ [ { "namespace": "pageAction", + "dependencies": [ "tabs" ], "types": [], "functions": [ { diff --git a/chrome/common/extensions/api/proxy.json b/chrome/common/extensions/api/proxy.json index 3a93830..1b6065a 100644 --- a/chrome/common/extensions/api/proxy.json +++ b/chrome/common/extensions/api/proxy.json @@ -1,6 +1,7 @@ [ { "namespace": "proxy", + "dependencies": [ "types" ], "types": [ { "id": "ProxyServer", diff --git a/chrome/common/extensions/api/tabs.json b/chrome/common/extensions/api/tabs.json index 35c38f6..cf248b8 100644 --- a/chrome/common/extensions/api/tabs.json +++ b/chrome/common/extensions/api/tabs.json @@ -1,6 +1,7 @@ [ { "namespace": "tabs", + "dependencies": [ "extension", "windows" ], "types": [ { "id": "Tab", diff --git a/chrome/common/extensions/api/ttsEngine.json b/chrome/common/extensions/api/ttsEngine.json index 0be8ef4..1272beb 100644 --- a/chrome/common/extensions/api/ttsEngine.json +++ b/chrome/common/extensions/api/ttsEngine.json @@ -1,6 +1,7 @@ [ { "namespace": "ttsEngine", + "dependencies": [ "tts" ], "functions": [ { "name": "sendTtsEvent", diff --git a/chrome/common/extensions/api/windows.json b/chrome/common/extensions/api/windows.json index 4c7b7ac..e72f303 100644 --- a/chrome/common/extensions/api/windows.json +++ b/chrome/common/extensions/api/windows.json @@ -1,6 +1,7 @@ [ { "namespace": "windows", + "dependencies": [ "tabs" ], "types": [ { "id": "Window", |