Commit 5780ffac authored by dhnishi's avatar dhnishi Committed by Commit bot

Add getSelf method to management API to use without the "management" permission.

BUG=392215

Review URL: https://codereview.chromium.org/508263003

Cr-Commit-Position: refs/heads/master@{#292660}
parent 327a8e40
......@@ -326,6 +326,14 @@ bool ManagementGetFunction::RunSync() {
return true;
}
bool ManagementGetSelfFunction::RunSync() {
scoped_ptr<management::ExtensionInfo> info =
CreateExtensionInfo(*extension_, ExtensionSystem::Get(GetProfile()));
results_ = management::Get::Results::Create(*info);
return true;
}
bool ManagementGetPermissionWarningsByIdFunction::RunSync() {
scoped_ptr<management::GetPermissionWarningsById::Params> params(
management::GetPermissionWarningsById::Params::Create(*args_));
......
......@@ -61,6 +61,17 @@ class ManagementGetFunction : public ManagementFunction {
virtual bool RunSync() OVERRIDE;
};
class ManagementGetSelfFunction : public ManagementFunction {
public:
DECLARE_EXTENSION_FUNCTION("management.getSelf", MANAGEMENT_GETSELF)
protected:
virtual ~ManagementGetSelfFunction() {}
// ExtensionFunction:
virtual bool RunSync() OVERRIDE;
};
class ManagementGetPermissionWarningsByIdFunction : public ManagementFunction {
public:
DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsById",
......
......@@ -98,6 +98,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest,
ASSERT_TRUE(listener1.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest,
GetSelfNoPermissions) {
ExtensionTestMessageListener listener1("success", false);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("management/get_self")));
ASSERT_TRUE(listener1.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest,
UninstallWithConfirmDialog) {
ExtensionService* service = ExtensionSystem::Get(browser()->profile())->
......
......@@ -544,6 +544,11 @@
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app", "platform_app"]
},
"management.getSelf": {
"dependencies": [],
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app", "platform_app"]
},
"management.uninstallSelf": {
"dependencies": [],
"channel": "stable",
......
......@@ -180,6 +180,23 @@
}
]
},
{
"name": "getSelf",
"description": "Returns information about the calling extension, app, or theme. Note: This function can be used without requesting the 'management' permission in the manifest.",
"parameters": [
{
"type": "function",
"name": "callback",
"optional": true,
"parameters": [
{
"name": "result",
"$ref": "ExtensionInfo"
}
]
}
]
},
{
"name": "getPermissionWarningsById",
"description": "Returns a list of <a href='permission_warnings'>permission warnings</a> for the given extension id.",
......
......@@ -15,6 +15,7 @@ For example:</p>
}</pre>
<p>
$(ref:management.getPermissionWarningsByManifest) and
$(ref:management.uninstallSelf) do not require the management permission
$(ref:management.getPermissionWarningsByManifest),
$(ref:management.uninstallSelf), and $(ref:management.getSelf) do not require
the management permission.
</p>
// 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.
chrome.management.getSelf(function(info) {
chrome.test.assertTrue(info != null);
chrome.test.assertEq("Self Get Test (no permissions)", info.name);
chrome.test.assertEq("extension", info.type);
chrome.test.assertEq(true, info.enabled);
chrome.test.sendMessage("success");
});
{
"name": "Self Get Test (no permissions)",
"version": "1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
}
}
......@@ -947,6 +947,7 @@ enum HistogramValue {
MEDIAGALLERIES_REMOVEGALLERYWATCH,
MEDIAGALLERIES_GETALLGALLERYWATCH,
MEDIAGALLERIES_REMOVEALLGALLERYWATCH,
MANAGEMENT_GETSELF,
// Last entry: Add new entries above and ensure to update
// tools/metrics/histograms/histograms.xml.
ENUM_BOUNDARY
......
......@@ -41133,6 +41133,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="886" label="MEDIAGALLERIES_REMOVEGALLERYWATCH"/>
<int value="887" label="MEDIAGALLERIES_GETALLGALLERYWATCH"/>
<int value="888" label="MEDIAGALLERIES_REMOVEALLGALLERYWATCH"/>
<int value="889" label="MANAGEMENT_GETSELF"/>
</enum>
<enum name="ExtensionInstallCause" type="int">
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