-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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}
- Loading branch information
Guido Urdaneta
committed
Sep 6, 2018
1 parent
ec82e30
commit bb5d6c7
Showing
16 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
chrome/browser/extensions/api/enterprise_hardware_platform/OWNERS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[email protected] |
38 changes: 38 additions & 0 deletions
38
...e/browser/extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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 |
37 changes: 37 additions & 0 deletions
37
...me/browser/extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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_ |
84 changes: 84 additions & 0 deletions
84
.../extensions/api/enterprise_hardware_platform/enterprise_hardware_platform_api_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
chrome/common/extensions/api/enterprise_hardware_platform.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters