| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/test/test_extensions_client.h" | 5 #include "extensions/test/test_extensions_client.h" |
| 6 | 6 |
| 7 #include "extensions/common/api/generated_schemas.h" |
| 7 #include "extensions/common/common_manifest_handlers.h" | 8 #include "extensions/common/common_manifest_handlers.h" |
| 9 #include "extensions/common/features/api_feature.h" |
| 10 #include "extensions/common/features/base_feature_provider.h" |
| 8 #include "extensions/common/features/feature_provider.h" | 11 #include "extensions/common/features/feature_provider.h" |
| 9 #include "extensions/common/features/json_feature_provider_source.h" | 12 #include "extensions/common/features/json_feature_provider_source.h" |
| 13 #include "extensions/common/features/manifest_feature.h" |
| 14 #include "extensions/common/features/permission_feature.h" |
| 10 #include "extensions/common/manifest_handler.h" | 15 #include "extensions/common/manifest_handler.h" |
| 11 #include "extensions/common/url_pattern_set.h" | 16 #include "extensions/common/url_pattern_set.h" |
| 12 #include "extensions/test/test_permission_message_provider.h" | 17 #include "extensions/test/test_permission_message_provider.h" |
| 18 #include "grit/extensions_resources.h" |
| 13 | 19 |
| 14 namespace extensions { | 20 namespace extensions { |
| 15 | 21 |
| 22 namespace { |
| 23 |
| 24 template <class FeatureClass> |
| 25 SimpleFeature* CreateFeature() { |
| 26 return new FeatureClass; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 16 TestExtensionsClient::TestExtensionsClient() { | 31 TestExtensionsClient::TestExtensionsClient() { |
| 17 } | 32 } |
| 18 | 33 |
| 19 TestExtensionsClient::~TestExtensionsClient() { | 34 TestExtensionsClient::~TestExtensionsClient() { |
| 20 } | 35 } |
| 21 | 36 |
| 22 void TestExtensionsClient::Initialize() { | 37 void TestExtensionsClient::Initialize() { |
| 23 // Registration could already be finalized in unit tests, where the utility | 38 // Registration could already be finalized in unit tests, where the utility |
| 24 // thread runs in-process. | 39 // thread runs in-process. |
| 25 if (!ManifestHandler::IsRegistrationFinalized()) { | 40 if (!ManifestHandler::IsRegistrationFinalized()) { |
| 26 RegisterCommonManifestHandlers(); | 41 RegisterCommonManifestHandlers(); |
| 27 ManifestHandler::FinalizeRegistration(); | 42 ManifestHandler::FinalizeRegistration(); |
| 28 } | 43 } |
| 29 } | 44 } |
| 30 | 45 |
| 31 const PermissionMessageProvider& | 46 const PermissionMessageProvider& |
| 32 TestExtensionsClient::GetPermissionMessageProvider() const { | 47 TestExtensionsClient::GetPermissionMessageProvider() const { |
| 33 static TestPermissionMessageProvider provider; | 48 static TestPermissionMessageProvider provider; |
| 34 return provider; | 49 return provider; |
| 35 } | 50 } |
| 36 | 51 |
| 37 // TODO(yoz): Implement something reasonable here. | |
| 38 scoped_ptr<FeatureProvider> TestExtensionsClient::CreateFeatureProvider( | 52 scoped_ptr<FeatureProvider> TestExtensionsClient::CreateFeatureProvider( |
| 39 const std::string& name) const { | 53 const std::string& name) const { |
| 40 return scoped_ptr<FeatureProvider>(); | 54 scoped_ptr<FeatureProvider> provider; |
| 55 scoped_ptr<JSONFeatureProviderSource> source( |
| 56 CreateFeatureProviderSource(name)); |
| 57 if (name == "api") { |
| 58 provider.reset(new BaseFeatureProvider(source->dictionary(), |
| 59 CreateFeature<APIFeature>)); |
| 60 } else if (name == "manifest") { |
| 61 provider.reset(new BaseFeatureProvider(source->dictionary(), |
| 62 CreateFeature<ManifestFeature>)); |
| 63 } else if (name == "permission") { |
| 64 provider.reset(new BaseFeatureProvider(source->dictionary(), |
| 65 CreateFeature<PermissionFeature>)); |
| 66 } else { |
| 67 NOTREACHED(); |
| 68 } |
| 69 return provider.Pass(); |
| 41 } | 70 } |
| 42 | 71 |
| 43 // TODO(yoz): Implement something reasonable here. | |
| 44 scoped_ptr<JSONFeatureProviderSource> | 72 scoped_ptr<JSONFeatureProviderSource> |
| 45 TestExtensionsClient::CreateFeatureProviderSource( | 73 TestExtensionsClient::CreateFeatureProviderSource( |
| 46 const std::string& name) const { | 74 const std::string& name) const { |
| 47 return scoped_ptr<JSONFeatureProviderSource>(); | 75 scoped_ptr<JSONFeatureProviderSource> source( |
| 76 new JSONFeatureProviderSource(name)); |
| 77 if (name == "api") { |
| 78 source->LoadJSON(IDR_EXTENSION_API_FEATURES); |
| 79 } else if (name == "manifest") { |
| 80 source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES); |
| 81 } else if (name == "permission") { |
| 82 source->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES); |
| 83 } else { |
| 84 NOTREACHED(); |
| 85 source.reset(); |
| 86 } |
| 87 return source.Pass(); |
| 48 } | 88 } |
| 49 | 89 |
| 50 void TestExtensionsClient::FilterHostPermissions( | 90 void TestExtensionsClient::FilterHostPermissions( |
| 51 const URLPatternSet& hosts, | 91 const URLPatternSet& hosts, |
| 52 URLPatternSet* new_hosts, | 92 URLPatternSet* new_hosts, |
| 53 std::set<PermissionMessage>* messages) const { | 93 std::set<PermissionMessage>* messages) const { |
| 54 } | 94 } |
| 55 | 95 |
| 56 void TestExtensionsClient::SetScriptingWhitelist( | 96 void TestExtensionsClient::SetScriptingWhitelist( |
| 57 const ExtensionsClient::ScriptingWhitelist& whitelist) { | 97 const ExtensionsClient::ScriptingWhitelist& whitelist) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 return hosts; | 110 return hosts; |
| 71 } | 111 } |
| 72 | 112 |
| 73 bool TestExtensionsClient::IsScriptableURL(const GURL& url, | 113 bool TestExtensionsClient::IsScriptableURL(const GURL& url, |
| 74 std::string* error) const { | 114 std::string* error) const { |
| 75 return true; | 115 return true; |
| 76 } | 116 } |
| 77 | 117 |
| 78 bool TestExtensionsClient::IsAPISchemaGenerated( | 118 bool TestExtensionsClient::IsAPISchemaGenerated( |
| 79 const std::string& name) const { | 119 const std::string& name) const { |
| 80 return false; | 120 return core_api::GeneratedSchemas::IsGenerated(name); |
| 81 } | 121 } |
| 82 | 122 |
| 83 base::StringPiece TestExtensionsClient::GetAPISchema( | 123 base::StringPiece TestExtensionsClient::GetAPISchema( |
| 84 const std::string& name) const { | 124 const std::string& name) const { |
| 85 return base::StringPiece(); | 125 return core_api::GeneratedSchemas::Get(name); |
| 86 } | 126 } |
| 87 | 127 |
| 88 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI* api) const { | 128 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI* api) const { |
| 89 } | 129 } |
| 90 | 130 |
| 91 bool TestExtensionsClient::ShouldSuppressFatalErrors() const { | 131 bool TestExtensionsClient::ShouldSuppressFatalErrors() const { |
| 92 return true; | 132 return true; |
| 93 } | 133 } |
| 94 | 134 |
| 95 } // namespace extensions | 135 } // namespace extensions |
| OLD | NEW |