Commit 433c5217 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Implement Hardware Platform API

Authorization via policy settings will be added in a follow-up CL before
enabling by default.

Bug: 860311
Change-Id: Ifadaa08b1a312f750654ebe51b862a8733b998a5
Reviewed-on: https://chromium-review.googlesource.com/1183195
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588245}
parent ba754bda
...@@ -3495,6 +3495,9 @@ are declared in tools/grit/grit_rule.gni. ...@@ -3495,6 +3495,9 @@ are declared in tools/grit/grit_rule.gni.
<message name="IDS_EXTENSION_PROMPT_WARNING_DOCUMENT_SCAN" desc="Permission string for access to document scanning."> <message name="IDS_EXTENSION_PROMPT_WARNING_DOCUMENT_SCAN" desc="Permission string for access to document scanning.">
Access document scanners attached via USB or on the local network Access document scanners attached via USB or on the local network
</message> </message>
<message name="IDS_EXTENSION_PROMPT_WARNING_ENTERPRISE_HARDWARE_PLATFORM" desc="Permission string for access to hardware platform information.">
Read the manufacturer and model of this computer
</message>
<message name="IDS_EXTENSION_PROMPT_WARNING_FAVICON" desc="Permission string for access to favicons."> <message name="IDS_EXTENSION_PROMPT_WARNING_FAVICON" desc="Permission string for access to favicons.">
Read the icons of the websites you visit Read the icons of the websites you visit
</message> </message>
......
...@@ -160,6 +160,8 @@ jumbo_static_library("extensions") { ...@@ -160,6 +160,8 @@ jumbo_static_library("extensions") {
"api/downloads/downloads_api.h", "api/downloads/downloads_api.h",
"api/downloads_internal/downloads_internal_api.cc", "api/downloads_internal/downloads_internal_api.cc",
"api/downloads_internal/downloads_internal_api.h", "api/downloads_internal/downloads_internal_api.h",
"api/enterprise_hardware_platform/enterprise_hardware_platform_api.cc",
"api/enterprise_hardware_platform/enterprise_hardware_platform_api.h",
"api/extension_action/extension_action_api.cc", "api/extension_action/extension_action_api.cc",
"api/extension_action/extension_action_api.h", "api/extension_action/extension_action_api.h",
"api/extension_action/extension_page_actions_api_constants.cc", "api/extension_action/extension_page_actions_api_constants.cc",
......
// Copyright 2018 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/enterprise_hardware_platform/enterprise_hardware_platform_api.h"
#include <utility>
#include "base/bind.h"
#include "chrome/common/extensions/api/enterprise_hardware_platform.h"
namespace extensions {
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction() = default;
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
~EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction() = default;
ExtensionFunction::ResponseAction
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::Run() {
base::SysInfo::GetHardwareInfo(base::BindOnce(
&EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
OnHardwarePlatformInfo,
this));
return RespondLater();
}
void EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
OnHardwarePlatformInfo(base::SysInfo::HardwareInfo info) {
api::enterprise_hardware_platform::HardwarePlatformInfo result;
result.manufacturer = std::move(info.manufacturer);
result.model = std::move(info.model);
Respond(ArgumentList(api::enterprise_hardware_platform::
GetHardwarePlatformInfo::Results::Create(result)));
}
} // namespace extensions
// Copyright 2018 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_ENTERPRISE_HARDWARE_PLATFORM_ENTERPRISE_HARDWARE_PLATFORM_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_HARDWARE_PLATFORM_ENTERPRISE_HARDWARE_PLATFORM_API_H_
#include "base/macros.h"
#include "base/sys_info.h"
#include "extensions/browser/extension_function.h"
namespace extensions {
class EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction
: public UIThreadExtensionFunction {
public:
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction();
protected:
~EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction() override;
ResponseAction Run() override;
private:
DECLARE_EXTENSION_FUNCTION(
"enterprise.hardwarePlatform.getHardwarePlatformInfo",
ENTERPRISE_HARDWAREPLATFORM_GETHARDWAREPLATFORMINFO);
void OnHardwarePlatformInfo(base::SysInfo::HardwareInfo info);
DISALLOW_COPY_AND_ASSIGN(
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_HARDWARE_PLATFORM_ENTERPRISE_HARDWARE_PLATFORM_API_H_
// Copyright 2018 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/enterprise_hardware_platform/enterprise_hardware_platform_api.h"
#include <memory>
#include <string>
#include "base/json/json_writer.h"
#include "chrome/browser/extensions/extension_api_unittest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_with_install.h"
#include "components/crx_file/id_util.h"
#include "extensions/common/extension_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
class EnterpriseHardwarePlatformAPITest
: public ExtensionServiceTestWithInstall {
public:
EnterpriseHardwarePlatformAPITest() = default;
~EnterpriseHardwarePlatformAPITest() override = default;
Browser* browser() { return browser_.get(); }
private:
void SetUp() override {
ExtensionServiceTestWithInstall::SetUp();
InitializeEmptyExtensionService();
browser_window_ = std::make_unique<TestBrowserWindow>();
Browser::CreateParams params(profile(), true);
params.type = Browser::TYPE_TABBED;
params.window = browser_window_.get();
browser_ = std::make_unique<Browser>(params);
}
void TearDown() override {
browser_.reset();
browser_window_.reset();
ExtensionServiceTestWithInstall::TearDown();
}
std::unique_ptr<TestBrowserWindow> browser_window_;
std::unique_ptr<Browser> browser_;
DISALLOW_COPY_AND_ASSIGN(EnterpriseHardwarePlatformAPITest);
};
TEST_F(EnterpriseHardwarePlatformAPITest, GetHardwarePlatformInfo) {
scoped_refptr<const Extension> extension = ExtensionBuilder("Test").Build();
scoped_refptr<EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction>
function =
new EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction();
function->set_extension(extension.get());
function->set_has_callback(true);
std::string args;
base::JSONWriter::Write(base::ListValue(), &args);
std::unique_ptr<base::Value> result(
extension_function_test_utils::RunFunctionAndReturnSingleResult(
function.get(), args, browser()));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(result);
ASSERT_TRUE(result->is_dict());
ASSERT_EQ(result->DictSize(), 2u);
const base::Value* val =
result->FindKeyOfType("manufacturer", base::Value::Type::STRING);
ASSERT_TRUE(val);
const std::string& manufacturer = val->GetString();
val = result->FindKeyOfType("model", base::Value::Type::STRING);
ASSERT_TRUE(val);
const std::string& model = val->GetString();
EXPECT_FALSE(manufacturer.empty());
EXPECT_FALSE(model.empty());
}
} // namespace extensions
...@@ -372,6 +372,10 @@ ...@@ -372,6 +372,10 @@
"dependencies": ["permission:echoPrivate"], "dependencies": ["permission:echoPrivate"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, },
"enterprise.hardwarePlatform": {
"dependencies": ["permission:enterprise.hardwarePlatform"],
"contexts": ["blessed_extension"]
},
"enterprise.deviceAttributes": { "enterprise.deviceAttributes": {
"dependencies": ["permission:enterprise.deviceAttributes"], "dependencies": ["permission:enterprise.deviceAttributes"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
......
...@@ -292,6 +292,11 @@ ...@@ -292,6 +292,11 @@
"extension_types": ["extension", "platform_app"], "extension_types": ["extension", "platform_app"],
"location": "policy" "location": "policy"
}, },
"enterprise.hardwarePlatform": {
"channel": "canary",
"extension_types": ["extension"],
"location": "policy"
},
"enterprise.platformKeys": [{ "enterprise.platformKeys": [{
"channel": "stable", "channel": "stable",
"platforms": ["chromeos"], "platforms": ["chromeos"],
......
...@@ -37,6 +37,7 @@ schema_sources_ = [ ...@@ -37,6 +37,7 @@ schema_sources_ = [
"developer_private.idl", "developer_private.idl",
"downloads.idl", "downloads.idl",
"downloads_internal.idl", "downloads_internal.idl",
"enterprise_hardware_platform.idl",
"font_settings.json", "font_settings.json",
"gcm.json", "gcm.json",
"history.json", "history.json",
......
// Copyright 2018 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.enterprise.hardwarePlatform</code> API to get the
// manufacturer and model of the hardware platform where the browser runs.
// Note: This API is only available to extensions installed by enterprise
// policy.
namespace enterprise.hardwarePlatform {
dictionary HardwarePlatformInfo {
DOMString model;
DOMString manufacturer;
};
callback HardwarePlatformInfoCallback = void(HardwarePlatformInfo info);
interface Functions {
// Obtains the manufacturer and model for the hardware platform and, if
// the extension is authorized, returns it via |callback|.
// |callback|: Called with the hardware platform info.
static void getHardwarePlatformInfo(HardwarePlatformInfoCallback callback);
};
};
...@@ -74,6 +74,8 @@ ChromeAPIPermissions::GetAllPermissions() const { ...@@ -74,6 +74,8 @@ ChromeAPIPermissions::GetAllPermissions() const {
APIPermissionInfo::kFlagCannotBeOptional}, APIPermissionInfo::kFlagCannotBeOptional},
{APIPermission::kEnterpriseDeviceAttributes, {APIPermission::kEnterpriseDeviceAttributes,
"enterprise.deviceAttributes"}, "enterprise.deviceAttributes"},
{APIPermission::kEnterpriseHardwarePlatform,
"enterprise.hardwarePlatform"},
{APIPermission::kEnterprisePlatformKeys, "enterprise.platformKeys"}, {APIPermission::kEnterprisePlatformKeys, "enterprise.platformKeys"},
{APIPermission::kFileBrowserHandler, "fileBrowserHandler", {APIPermission::kFileBrowserHandler, "fileBrowserHandler",
APIPermissionInfo::kFlagCannotBeOptional}, APIPermissionInfo::kFlagCannotBeOptional},
......
...@@ -639,6 +639,9 @@ ChromePermissionMessageRule::GetAllRules() { ...@@ -639,6 +639,9 @@ ChromePermissionMessageRule::GetAllRules() {
{IDS_EXTENSION_PROMPT_WARNING_DISPLAY_SOURCE, {IDS_EXTENSION_PROMPT_WARNING_DISPLAY_SOURCE,
{APIPermission::kDisplaySource}, {APIPermission::kDisplaySource},
{}}, {}},
{IDS_EXTENSION_PROMPT_WARNING_ENTERPRISE_HARDWARE_PLATFORM,
{APIPermission::kEnterpriseHardwarePlatform},
{}},
}; };
return std::vector<ChromePermissionMessageRule>( return std::vector<ChromePermissionMessageRule>(
......
...@@ -3511,6 +3511,7 @@ test("unit_tests") { ...@@ -3511,6 +3511,7 @@ test("unit_tests") {
"../browser/extensions/api/developer_private/extension_info_generator_unittest.cc", "../browser/extensions/api/developer_private/extension_info_generator_unittest.cc",
"../browser/extensions/api/device_permissions_manager_unittest.cc", "../browser/extensions/api/device_permissions_manager_unittest.cc",
"../browser/extensions/api/downloads/downloads_api_unittest.cc", "../browser/extensions/api/downloads/downloads_api_unittest.cc",
"../browser/extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api_unittest.cc",
"../browser/extensions/api/extension_action/browser_action_unittest.cc", "../browser/extensions/api/extension_action/browser_action_unittest.cc",
"../browser/extensions/api/extension_action/extension_action_prefs_unittest.cc", "../browser/extensions/api/extension_action/extension_action_prefs_unittest.cc",
"../browser/extensions/api/file_system/file_system_api_unittest.cc", "../browser/extensions/api/file_system/file_system_api_unittest.cc",
......
...@@ -1331,6 +1331,7 @@ enum HistogramValue { ...@@ -1331,6 +1331,7 @@ enum HistogramValue {
AUTOFILLPRIVATE_MIGRATECREDITCARDS = 1268, AUTOFILLPRIVATE_MIGRATECREDITCARDS = 1268,
AUTOTESTPRIVATE_ISAPPSHOWN = 1269, AUTOTESTPRIVATE_ISAPPSHOWN = 1269,
ENTERPRISEREPORTINGPRIVATE_GETDEVICEID = 1270, ENTERPRISEREPORTINGPRIVATE_GETDEVICEID = 1270,
ENTERPRISE_HARDWAREPLATFORM_GETHARDWAREPLATFORMINFO = 1271,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -197,7 +197,7 @@ class APIPermission { ...@@ -197,7 +197,7 @@ class APIPermission {
kWallpaper = 153, kWallpaper = 153,
kWallpaperPrivate = 154, kWallpaperPrivate = 154,
kWebcamPrivate = 155, kWebcamPrivate = 155,
kWebConnectable = 156, // for externally_connectable manifest key kWebConnectable = 156, // for externally_connectable manifest key
kWebNavigation = 157, kWebNavigation = 157,
kWebRequest = 158, kWebRequest = 158,
kWebRequestBlocking = 159, kWebRequestBlocking = 159,
...@@ -257,6 +257,7 @@ class APIPermission { ...@@ -257,6 +257,7 @@ class APIPermission {
kFileSystemRequestDownloads = 213, kFileSystemRequestDownloads = 213,
kSystemPowerSource = 214, kSystemPowerSource = 214,
kArcAppsPrivate = 215, kArcAppsPrivate = 215,
kEnterpriseHardwarePlatform = 216,
// Last entry: Add new entries above and ensure to update the // Last entry: Add new entries above and ensure to update the
// "ExtensionPermission3" enum in tools/metrics/histograms/histograms.xml // "ExtensionPermission3" enum in tools/metrics/histograms/histograms.xml
// (by running update_extension_permission.py). // (by running update_extension_permission.py).
......
...@@ -16582,6 +16582,8 @@ Called by update_net_error_codes.py.--> ...@@ -16582,6 +16582,8 @@ Called by update_net_error_codes.py.-->
<int value="1268" label="AUTOFILLPRIVATE_MIGRATECREDITCARDS"/> <int value="1268" label="AUTOFILLPRIVATE_MIGRATECREDITCARDS"/>
<int value="1269" label="AUTOTESTPRIVATE_ISAPPSHOWN"/> <int value="1269" label="AUTOTESTPRIVATE_ISAPPSHOWN"/>
<int value="1270" label="ENTERPRISEREPORTINGPRIVATE_GETDEVICEID"/> <int value="1270" label="ENTERPRISEREPORTINGPRIVATE_GETDEVICEID"/>
<int value="1271"
label="ENTERPRISE_HARDWAREPLATFORM_GETHARDWAREPLATFORMINFO"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
...@@ -17028,6 +17030,7 @@ Called by update_net_error_codes.py.--> ...@@ -17028,6 +17030,7 @@ Called by update_net_error_codes.py.-->
<int value="213" label="kFileSystemRequestDownloads"/> <int value="213" label="kFileSystemRequestDownloads"/>
<int value="214" label="kSystemPowerSource"/> <int value="214" label="kSystemPowerSource"/>
<int value="215" label="kArcAppsPrivate"/> <int value="215" label="kArcAppsPrivate"/>
<int value="216" label="kEnterpriseHardwarePlatform"/>
</enum> </enum>
<enum name="ExtensionServiceVerifyAllSuccess"> <enum name="ExtensionServiceVerifyAllSuccess">
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