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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 38 additions & 0 deletions
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
Lines changed: 37 additions & 0 deletions
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_
Lines changed: 84 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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",
Lines changed: 23 additions & 0 deletions
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+
};

0 commit comments

Comments
 (0)