Implement Command Line Private extension API.

API proposal: https://docs.google.com/document/d/1joXXu06G3XtvJf8fSNVVvB7UCMadVO07E_v3EulPB00/edit

BUG=226915
TEST=browser_tests

Review URL: https://chromiumcodereview.appspot.com/14027005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195161 0039d316-1c4b-4281-b951-d872f2087c98
parent b53d7570
// Copyright 2013 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/browser/extensions/api/command_line_private/command_line_private_api.h"
#include <string>
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/common/extensions/api/command_line_private.h"
namespace {
// This should be consistent with
// chrome/test/data/extensions/api_test/command_line/basics/test.js.
const char kEmptySwitchName[] = "Switch name is empty.";
} // namespace
namespace extensions {
namespace command_line_private = api::command_line_private;
bool CommandLinePrivateHasSwitchFunction::RunImpl() {
scoped_ptr<command_line_private::HasSwitch::Params> params(
command_line_private::HasSwitch::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
if (params->name.empty()) {
error_ = kEmptySwitchName;
return false;
}
results_ = command_line_private::HasSwitch::Results::Create(
CommandLine::ForCurrentProcess()->HasSwitch(params->name));
return true;
}
} // namespace extensions
// Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_COMMAND_LINE_PRIVATE_COMMAND_LINE_PRIVATE_API_H__
#define CHROME_BROWSER_EXTENSIONS_API_COMMAND_LINE_PRIVATE_COMMAND_LINE_PRIVATE_API_H__
#include "chrome/browser/extensions/extension_function.h"
namespace extensions {
class CommandLinePrivateHasSwitchFunction : public SyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION("commandLinePrivate.hasSwitch",
COMMANDLINEPRIVATE_HASSWITCH)
protected:
virtual ~CommandLinePrivateHasSwitchFunction() {}
// ExtensionFunction:
virtual bool RunImpl() OVERRIDE;
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_COMMAND_LINE_PRIVATE_COMMAND_LINE_PRIVATE_API_H__
// Copyright 2013 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 "base/command_line.h"
#include "chrome/browser/extensions/extension_apitest.h"
namespace {
// This should be consistent with
// chrome/test/data/extensions/api_test/command_line/basics/test.js.
const char kTestCommandLineSwitch[] = "command-line-private-api-test-foo";
} // namespace
class CommandLinePrivateApiTest : public ExtensionApiTest {
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(kTestCommandLineSwitch);
}
};
IN_PROC_BROWSER_TEST_F(CommandLinePrivateApiTest, Basics) {
EXPECT_TRUE(RunComponentExtensionTest("command_line/basics")) << message_;
}
......@@ -508,6 +508,7 @@ enum HistogramValue {
DEVELOPERPRIVATE_LOADPROJECTTOSYNCFS,
DEVELOPERPRIVATE_GETPROJECTSINFO,
DEVELOPERPRIVATE_LOADPROJECT,
COMMANDLINEPRIVATE_HASSWITCH,
ENUM_BOUNDARY // Last entry: Add new entries above.
};
......
......@@ -114,6 +114,8 @@
'browser/extensions/api/browsing_data/browsing_data_api.h',
'browser/extensions/api/cloud_print_private/cloud_print_private_api.cc',
'browser/extensions/api/cloud_print_private/cloud_print_private_api.h',
'browser/extensions/api/command_line_private/command_line_private_api.cc',
'browser/extensions/api/command_line_private/command_line_private_api.h',
'browser/extensions/api/commands/command_service.cc',
'browser/extensions/api/commands/command_service.h',
'browser/extensions/api/content_settings/content_settings_api.cc',
......
......@@ -1243,6 +1243,7 @@
'browser/extensions/api/bookmarks/bookmark_apitest.cc',
'browser/extensions/api/browsing_data/browsing_data_test.cc',
'browser/extensions/api/cloud_print_private/cloud_print_private_apitest.cc',
'browser/extensions/api/command_line_private/command_line_private_apitest.cc',
'browser/extensions/api/content_settings/content_settings_apitest.cc',
'browser/extensions/api/context_menus/context_menu_apitest.cc',
'browser/extensions/api/cookies/cookies_apitest.cc',
......
......@@ -93,6 +93,11 @@
// CloudPrint
"whitelist": ["mfehgcgbbipciphmccgaenjidiccnmng"]
},
"commandLinePrivate": {
"channel": "stable",
"extension_types": ["extension", "packaged_app", "platform_app"],
"location": "component"
},
"contentSettings": {
"channel": "stable",
"extension_types": ["extension", "packaged_app"]
......
......@@ -29,6 +29,7 @@
'bookmarks.json',
'chromeos_info_private.json',
'cloud_print_private.json',
'command_line_private.json',
'content_settings.json',
'context_menus.json',
'cookies.json',
......
// Copyright 2013 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.
[
{
"namespace": "commandLinePrivate",
"functions": [
{
"name": "hasSwitch",
"type": "function",
"description": "Returns whether a switch is specified on the command line when launching Chrome.",
"parameters": [
{
"name": "name",
"type": "string",
"description": "The name of a command line switch, without leading \"--\", such as \"enable-experimental-extension-apis\"."
},
{
"name": "callback",
"type": "function",
"parameters": [
{
"name": "result",
"type": "boolean",
"description": "Whether the switch is specified on the command line."
}
]
}
]
}
]
}
]
......@@ -53,6 +53,7 @@ class APIPermission {
kClipboardRead,
kClipboardWrite,
kCloudPrintPrivate,
kCommandLinePrivate,
kContentSettings,
kContextMenus,
kCookie,
......
......@@ -126,6 +126,8 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions()
APIPermissionInfo::kFlagCannotBeOptional },
{ APIPermission::kChromeosInfoPrivate, "chromeosInfoPrivate",
APIPermissionInfo::kFlagCannotBeOptional },
{ APIPermission::kCommandLinePrivate, "commandLinePrivate",
APIPermissionInfo::kFlagCannotBeOptional },
{ APIPermission::kDeveloperPrivate, "developerPrivate",
APIPermissionInfo::kFlagCannotBeOptional },
{ APIPermission::kDial, "dial", APIPermissionInfo::kFlagCannotBeOptional },
......
......@@ -715,6 +715,7 @@ TEST_F(PermissionsTest, PermissionMessages) {
skip.insert(APIPermission::kBookmarkManagerPrivate);
skip.insert(APIPermission::kChromeosInfoPrivate);
skip.insert(APIPermission::kCloudPrintPrivate);
skip.insert(APIPermission::kCommandLinePrivate);
skip.insert(APIPermission::kDeveloperPrivate);
skip.insert(APIPermission::kDial);
skip.insert(APIPermission::kDownloadsInternal);
......
{
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAv7LaUkPmrLmT9bbz0Zz6u7+FGmGo9xUfGlNEy4krUinwAIugLc+WqU/wQqhTsS26fgsnKk6WbsabcMtq8pDhanJgygcsXrs9nG1B2FO3VhEKRqCs+zrpl7vm6AzBMW1sHGCDkisSZt99QXoHjd99UzeJMnRVISMSxoG+B1I2EQIDAQAB",
"name": "command_line/basics",
"version": "0.1",
"manifest_version": 2,
"background": { "scripts": ["test.js"] },
"permissions": ["commandLinePrivate"]
}
// Copyright 2013 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.
// These string constants should be consistent with those in
// chrome/browser/extensions/api/command_line_private/.
var kTestCommandLineSwitch = 'command-line-private-api-test-foo';
var kEmptySwitchName = 'Switch name is empty.';
var kNonExistingSwitch = 'foo-bar-non-existing-switch';
var pass = chrome.test.callbackPass;
var fail = chrome.test.callbackFail;
var assertTrue = chrome.test.assertTrue;
var assertFalse = chrome.test.assertFalse;
chrome.test.runTests([
function testHaveSwitch() {
chrome.commandLinePrivate.hasSwitch(kTestCommandLineSwitch,
pass(function(result) {
assertTrue(result);
}));
},
function testNotHaveSwitch() {
chrome.commandLinePrivate.hasSwitch(kNonExistingSwitch,
pass(function(result) {
assertFalse(result);
}));
},
function testInvalidArgs() {
chrome.commandLinePrivate.hasSwitch('', fail(kEmptySwitchName));
}
]);
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