summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorjamescook <jamescook@chromium.org>2014-10-20 07:35:11 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-20 14:35:30 +0000
commit62117928b7e16e4b1080e802f26ca43f8ce1e997 (patch)
treefbedb04f41badd87a7fac3e14715e58a5c6bccdf /extensions
parent34cb061236f5c334606379297c2dfdfded0a490e (diff)
downloadchromium_src-62117928b7e16e4b1080e802f26ca43f8ce1e997.zip
chromium_src-62117928b7e16e4b1080e802f26ca43f8ce1e997.tar.gz
chromium_src-62117928b7e16e4b1080e802f26ca43f8ce1e997.tar.bz2
Add support for app_shell-only extension APIs
Also add a stub for an identity-related API as an example. BUG=424651 TEST=app_shell_unittests Review URL: https://codereview.chromium.org/660333003 Cr-Commit-Position: refs/heads/master@{#300265}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/BUILD.gn9
-rw-r--r--extensions/extensions.gyp10
-rw-r--r--extensions/shell/BUILD.gn13
-rw-r--r--extensions/shell/DEPS3
-rw-r--r--extensions/shell/app_shell.gyp5
-rw-r--r--extensions/shell/app_shell_resources.grd15
-rw-r--r--extensions/shell/app_shell_resources.gyp25
-rw-r--r--extensions/shell/browser/api/api_registration.gyp22
-rw-r--r--extensions/shell/browser/api/shell_identity/shell_identity_api.cc23
-rw-r--r--extensions/shell/browser/api/shell_identity/shell_identity_api.h32
-rw-r--r--extensions/shell/browser/api/shell_identity/shell_identity_api_unittest.cc25
-rw-r--r--extensions/shell/browser/shell_extensions_browser_client.cc4
-rw-r--r--extensions/shell/common/api/_api_features.json15
-rw-r--r--extensions/shell/common/api/api.gyp19
-rw-r--r--extensions/shell/common/api/schemas.gypi20
-rw-r--r--extensions/shell/common/api/shell_identity.idl14
-rw-r--r--extensions/shell/common/shell_extensions_client.cc11
17 files changed, 258 insertions, 7 deletions
diff --git a/extensions/BUILD.gn b/extensions/BUILD.gn
index f0026dc..0a03f0b 100644
--- a/extensions/BUILD.gn
+++ b/extensions/BUILD.gn
@@ -66,6 +66,8 @@ source_set("test_support") {
"browser/api/storage/settings_test_util.h",
"browser/api_test_utils.cc",
"browser/api_test_utils.h",
+ "browser/api_unittest.cc",
+ "browser/api_unittest.h",
"browser/extensions_test.cc",
"browser/extensions_test.h",
"browser/mock_extension_system.cc",
@@ -97,6 +99,9 @@ source_set("test_support") {
deps = [
":extensions_resources",
"//base",
+ "//content/public/browser",
+ "//content/public/common",
+ "//content/test:test_support",
"//extensions/browser",
"//extensions/common",
"//extensions/common/api",
@@ -128,6 +133,7 @@ repack("shell_and_test_pak") {
"$root_gen_dir/content/shell/shell_resources.pak",
"$root_gen_dir/extensions/extensions_renderer_resources.pak",
"$root_gen_dir/extensions/extensions_resources.pak",
+ "$root_gen_dir/extensions/shell/app_shell_resources.pak",
"$root_gen_dir/extensions/strings/extensions_strings_en-US.pak",
"$root_gen_dir/ui/resources/ui_resources_100_percent.pak",
"$root_gen_dir/ui/strings/app_locale_settings_en-US.pak",
@@ -147,6 +153,7 @@ repack("shell_and_test_pak") {
"//content/browser/devtools:resources",
"//content/shell:resources",
"//content:resources",
+ "//extensions/shell:resources",
"//extensions/strings",
"//ui/resources",
"//ui/strings",
@@ -178,8 +185,6 @@ test("extensions_unittests") {
"browser/content_hash_tree_unittest.cc",
"browser/event_listener_map_unittest.cc",
"browser/event_router_unittest.cc",
- "browser/api_unittest.cc",
- "browser/api_unittest.h",
"browser/extension_pref_value_map_unittest.cc",
"browser/extension_registry_unittest.cc",
"browser/file_highlighter_unittest.cc",
diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp
index 2b866df..75ed4cb 100644
--- a/extensions/extensions.gyp
+++ b/extensions/extensions.gyp
@@ -966,6 +966,9 @@
'dependencies': [
'../base/base.gyp:base',
'../components/components.gyp:user_prefs',
+ '../content/content.gyp:content_browser',
+ '../content/content.gyp:content_common',
+ '../content/content_shell_and_tests.gyp:test_support_content',
'../net/net.gyp:net_test_support',
'../testing/gtest.gyp:gtest',
'browser/api/api_registration.gyp:extensions_api_registration',
@@ -986,6 +989,8 @@
'browser/api/storage/settings_test_util.h',
'browser/api_test_utils.cc',
'browser/api_test_utils.h',
+ 'browser/api_unittest.cc',
+ 'browser/api_unittest.h',
'browser/extension_error_test_util.cc',
'browser/extension_error_test_util.h',
'browser/extensions_test.cc',
@@ -1039,6 +1044,7 @@
'../ui/strings/ui_strings.gyp:ui_strings',
'extensions_resources.gyp:extensions_resources',
'extensions_strings.gyp:extensions_strings',
+ 'shell/app_shell_resources.gyp:app_shell_resources',
],
'actions': [
{
@@ -1051,7 +1057,7 @@
'<(SHARED_INTERMEDIATE_DIR)/extensions/extensions_browser_resources_100_percent.pak',
'<(SHARED_INTERMEDIATE_DIR)/extensions/extensions_renderer_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/extensions/extensions_resources.pak',
- '<(SHARED_INTERMEDIATE_DIR)/extensions/extensions_resources.pak',
+ '<(SHARED_INTERMEDIATE_DIR)/extensions/shell/app_shell_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/extensions/strings/extensions_strings_en-US.pak',
'<(SHARED_INTERMEDIATE_DIR)/ui/resources/ui_resources_100_percent.pak',
'<(SHARED_INTERMEDIATE_DIR)/ui/strings/app_locale_settings_en-US.pak',
@@ -1122,8 +1128,6 @@
'browser/content_hash_tree_unittest.cc',
'browser/event_listener_map_unittest.cc',
'browser/event_router_unittest.cc',
- 'browser/api_unittest.cc',
- 'browser/api_unittest.h',
'browser/error_map_unittest.cc',
'browser/extension_icon_image_unittest.cc',
'browser/extension_pref_value_map_unittest.cc',
diff --git a/extensions/shell/BUILD.gn b/extensions/shell/BUILD.gn
new file mode 100644
index 0000000..5e501e3c
--- /dev/null
+++ b/extensions/shell/BUILD.gn
@@ -0,0 +1,13 @@
+# Copyright 2014 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.
+
+import("//tools/grit/grit_rule.gni")
+
+grit("resources") {
+ source = "app_shell_resources.grd"
+ outputs = [
+ "grit/app_shell_resources.h",
+ "app_shell_resources.pak",
+ ]
+}
diff --git a/extensions/shell/DEPS b/extensions/shell/DEPS
index 58642fb..74cb6bb 100644
--- a/extensions/shell/DEPS
+++ b/extensions/shell/DEPS
@@ -16,8 +16,9 @@ include_rules = [
# the embedder before being used by the extension.
"+components/storage_monitor",
- # Only allow extensions resources, not general Chrome ones.
+ # Only allow app_shell and extensions resources, not general Chrome ones.
"-grit",
+ "+grit/app_shell_resources.h",
"+grit/extensions_resources.h",
# Real DEPS go in subdirectories, for example extensions/shell/browser/DEPS.
diff --git a/extensions/shell/app_shell.gyp b/extensions/shell/app_shell.gyp
index 0e1ad76..c6fd1cb 100644
--- a/extensions/shell/app_shell.gyp
+++ b/extensions/shell/app_shell.gyp
@@ -32,6 +32,8 @@
'<(DEPTH)/extensions/extensions.gyp:extensions_renderer',
'<(DEPTH)/extensions/extensions.gyp:extensions_shell_and_test_pak',
'<(DEPTH)/extensions/extensions_resources.gyp:extensions_resources',
+ '<(DEPTH)/extensions/shell/browser/api/api_registration.gyp:shell_api_registration',
+ '<(DEPTH)/extensions/shell/common/api/api.gyp:shell_api',
'<(DEPTH)/mojo/edk/mojo_edk.gyp:mojo_system_impl',
'<(DEPTH)/mojo/mojo_base.gyp:mojo_environment_chromium',
'<(DEPTH)/skia/skia.gyp:skia',
@@ -47,6 +49,8 @@
'sources': [
'app/shell_main_delegate.cc',
'app/shell_main_delegate.h',
+ 'browser/api/shell_identity/shell_identity_api.cc',
+ 'browser/api/shell_identity/shell_identity_api.h',
'browser/default_shell_browser_main_delegate.cc',
'browser/default_shell_browser_main_delegate.h',
'browser/desktop_controller.cc',
@@ -228,6 +232,7 @@
],
'sources': [
'../test/extensions_unittests_main.cc',
+ 'browser/api/shell_identity/shell_identity_api_unittest.cc',
'browser/shell_audio_controller_chromeos_unittest.cc',
'browser/shell_desktop_controller_unittest.cc',
'browser/shell_nacl_browser_delegate_unittest.cc',
diff --git a/extensions/shell/app_shell_resources.grd b/extensions/shell/app_shell_resources.grd
new file mode 100644
index 0000000..99f33da
--- /dev/null
+++ b/extensions/shell/app_shell_resources.grd
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grit latest_public_release="0" current_release="1">
+ <outputs>
+ <output filename="grit/app_shell_resources.h" type="rc_header">
+ <emit emit_type='prepend'></emit>
+ </output>
+ <output filename="app_shell_resources.pak" type="data_package" />
+ </outputs>
+ <release seq="1">
+ <includes>
+ <!-- Features specific to app_shell. -->
+ <include name="IDR_SHELL_EXTENSION_API_FEATURES" file="common\api\_api_features.json" type="BINDATA" />
+ </includes>
+ </release>
+</grit>
diff --git a/extensions/shell/app_shell_resources.gyp b/extensions/shell/app_shell_resources.gyp
new file mode 100644
index 0000000..162bd89
--- /dev/null
+++ b/extensions/shell/app_shell_resources.gyp
@@ -0,0 +1,25 @@
+# Copyright 2014 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.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'app_shell_resources',
+ 'type': 'none',
+ 'variables': {
+ 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/extensions/shell',
+ },
+ 'actions': [
+ {
+ 'action_name': 'generate_app_shell_resources',
+ 'variables': {
+ 'grit_grd_file': 'app_shell_resources.grd',
+ },
+ 'includes': [ '../../build/grit_action.gypi' ],
+ },
+ ],
+ 'includes': [ '../../build/grit_target.gypi' ],
+ },
+ ] # targets
+}
diff --git a/extensions/shell/browser/api/api_registration.gyp b/extensions/shell/browser/api/api_registration.gyp
new file mode 100644
index 0000000..6fc014c
--- /dev/null
+++ b/extensions/shell/browser/api/api_registration.gyp
@@ -0,0 +1,22 @@
+# Copyright 2014 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.
+
+{
+ 'targets': [
+ {
+ # GN version: //extensions/shell/browser/api
+ 'target_name': 'shell_api_registration',
+ 'type': 'static_library',
+ # TODO(jschuh): http://crbug.com/167187 size_t -> int
+ 'msvs_disabled_warnings': [ 4267 ],
+ 'includes': [
+ '../../../../build/json_schema_bundle_registration_compile.gypi',
+ '../../common/api/schemas.gypi',
+ ],
+ 'dependencies': [
+ '<(DEPTH)/extensions/shell/common/api/api.gyp:shell_api',
+ ],
+ },
+ ],
+}
diff --git a/extensions/shell/browser/api/shell_identity/shell_identity_api.cc b/extensions/shell/browser/api/shell_identity/shell_identity_api.cc
new file mode 100644
index 0000000..7118fac
--- /dev/null
+++ b/extensions/shell/browser/api/shell_identity/shell_identity_api.cc
@@ -0,0 +1,23 @@
+// Copyright 2014 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 "extensions/shell/browser/api/shell_identity/shell_identity_api.h"
+
+#include "base/logging.h"
+
+namespace extensions {
+
+ShellIdentityGetAuthTokenFunction::ShellIdentityGetAuthTokenFunction() {
+}
+
+ShellIdentityGetAuthTokenFunction::~ShellIdentityGetAuthTokenFunction() {
+}
+
+ExtensionFunction::ResponseAction ShellIdentityGetAuthTokenFunction::Run() {
+ // TODO(jamescook): Implement this.
+ NOTIMPLEMENTED();
+ return RespondNow(NoArguments());
+}
+
+} // namespace extensions
diff --git a/extensions/shell/browser/api/shell_identity/shell_identity_api.h b/extensions/shell/browser/api/shell_identity/shell_identity_api.h
new file mode 100644
index 0000000..999fe72
--- /dev/null
+++ b/extensions/shell/browser/api/shell_identity/shell_identity_api.h
@@ -0,0 +1,32 @@
+// Copyright 2014 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.
+
+#ifndef EXTENSIONS_SHELL_BROWSER_API_SHELL_IDENTITY_SHELL_IDENTITY_API_H_
+#define EXTENSIONS_SHELL_BROWSER_API_SHELL_IDENTITY_SHELL_IDENTITY_API_H_
+
+#include "base/macros.h"
+#include "extensions/browser/extension_function.h"
+
+namespace extensions {
+
+// TODO(jamescook): Implement this function.
+class ShellIdentityGetAuthTokenFunction : public UIThreadExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("shell.identity.getAuthToken", UNKNOWN);
+
+ ShellIdentityGetAuthTokenFunction();
+
+ protected:
+ virtual ~ShellIdentityGetAuthTokenFunction();
+
+ // ExtensionFunction:
+ virtual ResponseAction Run() override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ShellIdentityGetAuthTokenFunction);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_SHELL_BROWSER_API_SHELL_IDENTITY_SHELL_IDENTITY_API_H_
diff --git a/extensions/shell/browser/api/shell_identity/shell_identity_api_unittest.cc b/extensions/shell/browser/api/shell_identity/shell_identity_api_unittest.cc
new file mode 100644
index 0000000..097b988
--- /dev/null
+++ b/extensions/shell/browser/api/shell_identity/shell_identity_api_unittest.cc
@@ -0,0 +1,25 @@
+// Copyright 2014 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 "extensions/shell/browser/api/shell_identity/shell_identity_api.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "extensions/browser/api_unittest.h"
+
+namespace extensions {
+
+typedef ApiUnitTest ShellIdentityApiTest;
+
+// Verifies that the getAuthToken function exists and can be called without
+// crashing.
+TEST_F(ShellIdentityApiTest, GetAuthTokenBasics) {
+ scoped_ptr<base::Value> result =
+ RunFunctionAndReturnValue(new ShellIdentityGetAuthTokenFunction, "[]");
+
+ // Function returns nothing.
+ EXPECT_FALSE(result.get());
+}
+
+} // namespace extensions
diff --git a/extensions/shell/browser/shell_extensions_browser_client.cc b/extensions/shell/browser/shell_extensions_browser_client.cc
index b36494e..aa604b6 100644
--- a/extensions/shell/browser/shell_extensions_browser_client.cc
+++ b/extensions/shell/browser/shell_extensions_browser_client.cc
@@ -19,6 +19,7 @@
#include "extensions/browser/null_app_sorting.h"
#include "extensions/browser/updater/null_extension_cache.h"
#include "extensions/browser/url_request_util.h"
+#include "extensions/shell/browser/api/generated_api_registration.h"
#include "extensions/shell/browser/shell_extension_host_delegate.h"
#include "extensions/shell/browser/shell_extension_system_factory.h"
#include "extensions/shell/browser/shell_runtime_api_delegate.h"
@@ -187,6 +188,9 @@ void ShellExtensionsBrowserClient::RegisterExtensionFunctions(
ExtensionFunctionRegistry* registry) const {
// Register core extension-system APIs.
core_api::GeneratedFunctionRegistry::RegisterAll(registry);
+
+ // app_shell-only APIs.
+ shell_api::GeneratedFunctionRegistry::RegisterAll(registry);
}
scoped_ptr<RuntimeAPIDelegate>
diff --git a/extensions/shell/common/api/_api_features.json b/extensions/shell/common/api/_api_features.json
new file mode 100644
index 0000000..b4a1376
--- /dev/null
+++ b/extensions/shell/common/api/_api_features.json
@@ -0,0 +1,15 @@
+// Copyright 2014 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.
+
+// This file defines extension APIs implemented under src/extensions/shell.
+// See extensions/common/features/* to understand this file, in particular
+// feature.h, simple_feature.h, and base_feature_provider.h.
+
+{
+ "shell.identity": {
+ "channel": "dev",
+ "contexts": ["blessed_extension"],
+ "extension_types": ["platform_app"]
+ }
+}
diff --git a/extensions/shell/common/api/api.gyp b/extensions/shell/common/api/api.gyp
new file mode 100644
index 0000000..3421f05
--- /dev/null
+++ b/extensions/shell/common/api/api.gyp
@@ -0,0 +1,19 @@
+# Copyright 2014 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.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'shell_api',
+ 'type': 'static_library',
+ # TODO(jschuh): http://crbug.com/167187 size_t -> int
+ 'msvs_disabled_warnings': [ 4267 ],
+ 'includes': [
+ '../../../../build/json_schema_bundle_compile.gypi',
+ '../../../../build/json_schema_compile.gypi',
+ 'schemas.gypi',
+ ],
+ },
+ ],
+}
diff --git a/extensions/shell/common/api/schemas.gypi b/extensions/shell/common/api/schemas.gypi
new file mode 100644
index 0000000..13def4f
--- /dev/null
+++ b/extensions/shell/common/api/schemas.gypi
@@ -0,0 +1,20 @@
+# Copyright 2014 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.
+
+{
+ 'sources': [
+ '<@(schema_files)',
+ ],
+ 'variables': {
+ 'chromium_code': 1,
+ 'non_compiled_schema_files': [
+ ],
+ 'schema_files': [
+ 'shell_identity.idl',
+ ],
+ 'cc_dir': 'extensions/shell/common/api',
+ 'root_namespace': 'extensions::shell_api::%(namespace)s',
+ 'impl_dir_': 'extensions/shell/browser/api',
+ },
+}
diff --git a/extensions/shell/common/api/shell_identity.idl b/extensions/shell/common/api/shell_identity.idl
new file mode 100644
index 0000000..6772bae
--- /dev/null
+++ b/extensions/shell/common/api/shell_identity.idl
@@ -0,0 +1,14 @@
+// Copyright 2014 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.
+
+// Use the <code>chrome.shell.identity</code> API to retrieve OAuth2 tokens
+// for user accounts. See also <code>chrome.identity</code>.
+namespace shell.identity {
+
+ interface Functions {
+ // TODO(jamescook): Implement this with options and a callback.
+ static void getAuthToken();
+ };
+
+};
diff --git a/extensions/shell/common/shell_extensions_client.cc b/extensions/shell/common/shell_extensions_client.cc
index f27cd09..8eae902 100644
--- a/extensions/shell/common/shell_extensions_client.cc
+++ b/extensions/shell/common/shell_extensions_client.cc
@@ -20,6 +20,8 @@
#include "extensions/common/permissions/permissions_info.h"
#include "extensions/common/permissions/permissions_provider.h"
#include "extensions/common/url_pattern_set.h"
+#include "extensions/shell/common/api/generated_schemas.h"
+#include "grit/app_shell_resources.h"
#include "grit/extensions_resources.h"
namespace extensions {
@@ -127,6 +129,7 @@ ShellExtensionsClient::CreateFeatureProviderSource(
new JSONFeatureProviderSource(name));
if (name == "api") {
source->LoadJSON(IDR_EXTENSION_API_FEATURES);
+ source->LoadJSON(IDR_SHELL_EXTENSION_API_FEATURES);
} else if (name == "manifest") {
source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
} else if (name == "permission") {
@@ -171,11 +174,17 @@ bool ShellExtensionsClient::IsScriptableURL(const GURL& url,
bool ShellExtensionsClient::IsAPISchemaGenerated(
const std::string& name) const {
- return core_api::GeneratedSchemas::IsGenerated(name);
+ return core_api::GeneratedSchemas::IsGenerated(name) ||
+ shell_api::GeneratedSchemas::IsGenerated(name);
}
base::StringPiece ShellExtensionsClient::GetAPISchema(
const std::string& name) const {
+ // Schema for app_shell-only APIs.
+ if (shell_api::GeneratedSchemas::IsGenerated(name))
+ return shell_api::GeneratedSchemas::Get(name);
+
+ // Core extensions APIs.
return core_api::GeneratedSchemas::Get(name);
}