Commit 62117928 authored by jamescook's avatar jamescook Committed by Commit bot

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}
parent 34cb0612
......@@ -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",
......
......@@ -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',
......
# 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",
]
}
......@@ -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.
......
......@@ -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',
......
<?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>
# 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
}
# 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',
],
},
],
}
// 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
// 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_
// 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
......@@ -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>
......
// 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"]
}
}
# 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',
],
},
],
}
# 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',
},
}
// 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();
};
};
......@@ -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);
}
......
......@@ -185,6 +185,9 @@
"extensions/extensions_strings.grd": {
"messages": [27000],
},
"extensions/shell/app_shell_resources.grd": {
"includes": [27400],
},
"chrome/browser/resources/memory_internals_resources.grd": {
"includes": [27500],
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment