Skip to content

Commit bb5d6c7

Browse files
author
Guido Urdaneta
committed
Implement Hardware Platform API
Authorization via policy settings will be added in a follow-up CL before enabling by default. [email protected] (cherry picked from commit 433c521) Bug: 860311 Change-Id: Ifadaa08b1a312f750654ebe51b862a8733b998a5 Reviewed-on: https://chromium-review.googlesource.com/1183195 Commit-Queue: Guido Urdaneta <[email protected]> Reviewed-by: Devlin <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#588245} Reviewed-on: https://chromium-review.googlesource.com/1199405 Reviewed-by: Guido Urdaneta <[email protected]> Cr-Commit-Position: refs/branch-heads/3538@{#83} Cr-Branched-From: 79f7c91-refs/heads/master@{#587811}
1 parent ec82e30 commit bb5d6c7

16 files changed

+210
-1
lines changed

chrome/app/generated_resources.grd

+3
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,9 @@ are declared in tools/grit/grit_rule.gni.
35013501
<message name="IDS_EXTENSION_PROMPT_WARNING_DOCUMENT_SCAN" desc="Permission string for access to document scanning.">
35023502
Access document scanners attached via USB or on the local network
35033503
</message>
3504+
<message name="IDS_EXTENSION_PROMPT_WARNING_ENTERPRISE_HARDWARE_PLATFORM" desc="Permission string for access to hardware platform information.">
3505+
Read the manufacturer and model of this computer
3506+
</message>
35043507
<message name="IDS_EXTENSION_PROMPT_WARNING_FAVICON" desc="Permission string for access to favicons.">
35053508
Read the icons of the websites you visit
35063509
</message>

chrome/browser/extensions/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ jumbo_static_library("extensions") {
160160
"api/downloads/downloads_api.h",
161161
"api/downloads_internal/downloads_internal_api.cc",
162162
"api/downloads_internal/downloads_internal_api.h",
163+
"api/enterprise_hardware_platform/enterprise_hardware_platform_api.cc",
164+
"api/enterprise_hardware_platform/enterprise_hardware_platform_api.h",
163165
"api/extension_action/extension_action_api.cc",
164166
"api/extension_action/extension_action_api.h",
165167
"api/extension_action/extension_page_actions_api_constants.cc",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "chrome/browser/extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api.h"
6+
7+
#include <utility>
8+
9+
#include "base/bind.h"
10+
#include "chrome/common/extensions/api/enterprise_hardware_platform.h"
11+
12+
namespace extensions {
13+
14+
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
15+
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction() = default;
16+
17+
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
18+
~EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction() = default;
19+
20+
ExtensionFunction::ResponseAction
21+
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::Run() {
22+
base::SysInfo::GetHardwareInfo(base::BindOnce(
23+
&EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
24+
OnHardwarePlatformInfo,
25+
this));
26+
return RespondLater();
27+
}
28+
29+
void EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction::
30+
OnHardwarePlatformInfo(base::SysInfo::HardwareInfo info) {
31+
api::enterprise_hardware_platform::HardwarePlatformInfo result;
32+
result.manufacturer = std::move(info.manufacturer);
33+
result.model = std::move(info.model);
34+
Respond(ArgumentList(api::enterprise_hardware_platform::
35+
GetHardwarePlatformInfo::Results::Create(result)));
36+
}
37+
38+
} // namespace extensions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_HARDWARE_PLATFORM_ENTERPRISE_HARDWARE_PLATFORM_API_H_
6+
#define CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_HARDWARE_PLATFORM_ENTERPRISE_HARDWARE_PLATFORM_API_H_
7+
8+
#include "base/macros.h"
9+
#include "base/sys_info.h"
10+
#include "extensions/browser/extension_function.h"
11+
12+
namespace extensions {
13+
14+
class EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction
15+
: public UIThreadExtensionFunction {
16+
public:
17+
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction();
18+
19+
protected:
20+
~EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction() override;
21+
22+
ResponseAction Run() override;
23+
24+
private:
25+
DECLARE_EXTENSION_FUNCTION(
26+
"enterprise.hardwarePlatform.getHardwarePlatformInfo",
27+
ENTERPRISE_HARDWAREPLATFORM_GETHARDWAREPLATFORMINFO);
28+
29+
void OnHardwarePlatformInfo(base::SysInfo::HardwareInfo info);
30+
31+
DISALLOW_COPY_AND_ASSIGN(
32+
EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction);
33+
};
34+
35+
} // namespace extensions
36+
37+
#endif // CHROME_BROWSER_EXTENSIONS_API_ENTERPRISE_HARDWARE_PLATFORM_ENTERPRISE_HARDWARE_PLATFORM_API_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "chrome/browser/extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api.h"
6+
7+
#include <memory>
8+
#include <string>
9+
10+
#include "base/json/json_writer.h"
11+
#include "chrome/browser/extensions/extension_api_unittest.h"
12+
#include "chrome/browser/extensions/extension_function_test_utils.h"
13+
#include "chrome/browser/extensions/extension_service.h"
14+
#include "chrome/browser/extensions/extension_service_test_with_install.h"
15+
#include "components/crx_file/id_util.h"
16+
#include "extensions/common/extension_builder.h"
17+
#include "testing/gtest/include/gtest/gtest.h"
18+
19+
namespace extensions {
20+
21+
class EnterpriseHardwarePlatformAPITest
22+
: public ExtensionServiceTestWithInstall {
23+
public:
24+
EnterpriseHardwarePlatformAPITest() = default;
25+
~EnterpriseHardwarePlatformAPITest() override = default;
26+
Browser* browser() { return browser_.get(); }
27+
28+
private:
29+
void SetUp() override {
30+
ExtensionServiceTestWithInstall::SetUp();
31+
InitializeEmptyExtensionService();
32+
browser_window_ = std::make_unique<TestBrowserWindow>();
33+
Browser::CreateParams params(profile(), true);
34+
params.type = Browser::TYPE_TABBED;
35+
params.window = browser_window_.get();
36+
browser_ = std::make_unique<Browser>(params);
37+
}
38+
39+
void TearDown() override {
40+
browser_.reset();
41+
browser_window_.reset();
42+
ExtensionServiceTestWithInstall::TearDown();
43+
}
44+
45+
std::unique_ptr<TestBrowserWindow> browser_window_;
46+
std::unique_ptr<Browser> browser_;
47+
48+
DISALLOW_COPY_AND_ASSIGN(EnterpriseHardwarePlatformAPITest);
49+
};
50+
51+
TEST_F(EnterpriseHardwarePlatformAPITest, GetHardwarePlatformInfo) {
52+
scoped_refptr<const Extension> extension = ExtensionBuilder("Test").Build();
53+
scoped_refptr<EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction>
54+
function =
55+
new EnterpriseHardwarePlatformGetHardwarePlatformInfoFunction();
56+
function->set_extension(extension.get());
57+
function->set_has_callback(true);
58+
59+
std::string args;
60+
base::JSONWriter::Write(base::ListValue(), &args);
61+
62+
std::unique_ptr<base::Value> result(
63+
extension_function_test_utils::RunFunctionAndReturnSingleResult(
64+
function.get(), args, browser()));
65+
base::RunLoop().RunUntilIdle();
66+
67+
ASSERT_TRUE(result);
68+
ASSERT_TRUE(result->is_dict());
69+
ASSERT_EQ(result->DictSize(), 2u);
70+
71+
const base::Value* val =
72+
result->FindKeyOfType("manufacturer", base::Value::Type::STRING);
73+
ASSERT_TRUE(val);
74+
const std::string& manufacturer = val->GetString();
75+
76+
val = result->FindKeyOfType("model", base::Value::Type::STRING);
77+
ASSERT_TRUE(val);
78+
const std::string& model = val->GetString();
79+
80+
EXPECT_FALSE(manufacturer.empty());
81+
EXPECT_FALSE(model.empty());
82+
}
83+
84+
} // namespace extensions

chrome/common/extensions/api/_api_features.json

+4
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@
372372
"dependencies": ["permission:echoPrivate"],
373373
"contexts": ["blessed_extension"]
374374
},
375+
"enterprise.hardwarePlatform": {
376+
"dependencies": ["permission:enterprise.hardwarePlatform"],
377+
"contexts": ["blessed_extension"]
378+
},
375379
"enterprise.deviceAttributes": {
376380
"dependencies": ["permission:enterprise.deviceAttributes"],
377381
"contexts": ["blessed_extension"]

chrome/common/extensions/api/_permission_features.json

+5
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@
292292
"extension_types": ["extension", "platform_app"],
293293
"location": "policy"
294294
},
295+
"enterprise.hardwarePlatform": {
296+
"channel": "canary",
297+
"extension_types": ["extension"],
298+
"location": "policy"
299+
},
295300
"enterprise.platformKeys": [{
296301
"channel": "stable",
297302
"platforms": ["chromeos"],

chrome/common/extensions/api/api_sources.gni

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ schema_sources_ = [
3737
"developer_private.idl",
3838
"downloads.idl",
3939
"downloads_internal.idl",
40+
"enterprise_hardware_platform.idl",
4041
"font_settings.json",
4142
"gcm.json",
4243
"history.json",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Use the <code>chrome.enterprise.hardwarePlatform</code> API to get the
6+
// manufacturer and model of the hardware platform where the browser runs.
7+
// Note: This API is only available to extensions installed by enterprise
8+
// policy.
9+
namespace enterprise.hardwarePlatform {
10+
dictionary HardwarePlatformInfo {
11+
DOMString model;
12+
DOMString manufacturer;
13+
};
14+
15+
callback HardwarePlatformInfoCallback = void(HardwarePlatformInfo info);
16+
17+
interface Functions {
18+
// Obtains the manufacturer and model for the hardware platform and, if
19+
// the extension is authorized, returns it via |callback|.
20+
// |callback|: Called with the hardware platform info.
21+
static void getHardwarePlatformInfo(HardwarePlatformInfoCallback callback);
22+
};
23+
};

chrome/common/extensions/permissions/chrome_api_permissions.cc

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ ChromeAPIPermissions::GetAllPermissions() const {
7474
APIPermissionInfo::kFlagCannotBeOptional},
7575
{APIPermission::kEnterpriseDeviceAttributes,
7676
"enterprise.deviceAttributes"},
77+
{APIPermission::kEnterpriseHardwarePlatform,
78+
"enterprise.hardwarePlatform"},
7779
{APIPermission::kEnterprisePlatformKeys, "enterprise.platformKeys"},
7880
{APIPermission::kFileBrowserHandler, "fileBrowserHandler",
7981
APIPermissionInfo::kFlagCannotBeOptional},

chrome/common/extensions/permissions/chrome_permission_message_rules.cc

+3
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ ChromePermissionMessageRule::GetAllRules() {
639639
{IDS_EXTENSION_PROMPT_WARNING_DISPLAY_SOURCE,
640640
{APIPermission::kDisplaySource},
641641
{}},
642+
{IDS_EXTENSION_PROMPT_WARNING_ENTERPRISE_HARDWARE_PLATFORM,
643+
{APIPermission::kEnterpriseHardwarePlatform},
644+
{}},
642645
};
643646

644647
return std::vector<ChromePermissionMessageRule>(

chrome/test/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,7 @@ test("unit_tests") {
35093509
"../browser/extensions/api/developer_private/extension_info_generator_unittest.cc",
35103510
"../browser/extensions/api/device_permissions_manager_unittest.cc",
35113511
"../browser/extensions/api/downloads/downloads_api_unittest.cc",
3512+
"../browser/extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api_unittest.cc",
35123513
"../browser/extensions/api/extension_action/browser_action_unittest.cc",
35133514
"../browser/extensions/api/extension_action/extension_action_prefs_unittest.cc",
35143515
"../browser/extensions/api/file_system/file_system_api_unittest.cc",

extensions/browser/extension_function_histogram_value.h

+1
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ enum HistogramValue {
13291329
ARCAPPSPRIVATE_LAUNCHAPP = 1266,
13301330
AUTOTESTPRIVATE_RUNCROSTINIINSTALLER = 1267,
13311331
AUTOFILLPRIVATE_MIGRATECREDITCARDS = 1268,
1332+
ENTERPRISE_HARDWAREPLATFORM_GETHARDWAREPLATFORMINFO = 1271,
13321333
// Last entry: Add new entries above, then run:
13331334
// python tools/metrics/histograms/update_extension_histograms.py
13341335
ENUM_BOUNDARY

extensions/common/permissions/api_permission.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class APIPermission {
197197
kWallpaper = 153,
198198
kWallpaperPrivate = 154,
199199
kWebcamPrivate = 155,
200-
kWebConnectable = 156, // for externally_connectable manifest key
200+
kWebConnectable = 156, // for externally_connectable manifest key
201201
kWebNavigation = 157,
202202
kWebRequest = 158,
203203
kWebRequestBlocking = 159,
@@ -257,6 +257,7 @@ class APIPermission {
257257
kFileSystemRequestDownloads = 213,
258258
kSystemPowerSource = 214,
259259
kArcAppsPrivate = 215,
260+
kEnterpriseHardwarePlatform = 216,
260261
// Last entry: Add new entries above and ensure to update the
261262
// "ExtensionPermission3" enum in tools/metrics/histograms/histograms.xml
262263
// (by running update_extension_permission.py).

tools/metrics/histograms/enums.xml

+3
Original file line numberDiff line numberDiff line change
@@ -16555,6 +16555,8 @@ Called by update_net_error_codes.py.-->
1655516555
<int value="1266" label="ARCAPPSPRIVATE_LAUNCHAPP"/>
1655616556
<int value="1267" label="AUTOTESTPRIVATE_RUNCROSTINIINSTALLER"/>
1655716557
<int value="1268" label="AUTOFILLPRIVATE_MIGRATECREDITCARDS"/>
16558+
<int value="1271"
16559+
label="ENTERPRISE_HARDWAREPLATFORM_GETHARDWAREPLATFORMINFO"/>
1655816560
</enum>
1655916561

1656016562
<enum name="ExtensionIconState">
@@ -17001,6 +17003,7 @@ Called by update_net_error_codes.py.-->
1700117003
<int value="213" label="kFileSystemRequestDownloads"/>
1700217004
<int value="214" label="kSystemPowerSource"/>
1700317005
<int value="215" label="kArcAppsPrivate"/>
17006+
<int value="216" label="kEnterpriseHardwarePlatform"/>
1700417007
</enum>
1700517008

1700617009
<enum name="ExtensionServiceVerifyAllSuccess">

0 commit comments

Comments
 (0)