Extensions: Management: Detect user gesture usage
Bug: chromium:403156550 Change-Id: If1ca0976616f99b4b3d59718ed32ac70298e961f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6378955 Reviewed-by: David Bertoni <dbertoni@chromium.org> Reviewed-by: Justin Lulejian <jlulejian@chromium.org> Commit-Queue: Solomon Kinard <solomonkinard@chromium.org> Cr-Commit-Position: refs/heads/main@{#1436388}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
57d1ea0d27
commit
ca69f0de98
chrome/browser/extensions/api/management
extensions/browser/api/management
tools/metrics/histograms/metadata/extensions
@ -230,6 +230,28 @@ TEST_F(ManagementApiUnitTest, ManagementSetEnabled) {
|
||||
policy->UnregisterProvider(&provider);
|
||||
}
|
||||
|
||||
// chrome.management.setEnabled can be called with or without a user gesture.
|
||||
// Verify that the associated histogram is set accordingly.
|
||||
TEST_F(ManagementApiUnitTest, ManagementSetEnabledMaybeHasUserGesture) {
|
||||
base::HistogramTester histogram_tester;
|
||||
base::UserActionTester user_action_tester;
|
||||
|
||||
scoped_refptr<const Extension> extension = ExtensionBuilder("Test").Build();
|
||||
registrar()->AddExtension(extension.get());
|
||||
auto run_set_enabled_function = [&](bool use_user_gesture) {
|
||||
bool success = RunSetEnabledFunction(
|
||||
/*web_contents=*/nullptr, extension->id(), use_user_gesture,
|
||||
/*accept_dialog=*/true, nullptr);
|
||||
ASSERT_TRUE(success);
|
||||
histogram_tester.ExpectBucketCount(
|
||||
ManagementSetEnabledFunction::kSetEnabledHasUserGestureHistogramName,
|
||||
use_user_gesture, 1);
|
||||
};
|
||||
|
||||
run_set_enabled_function(/*use_user_gesture=*/true);
|
||||
run_set_enabled_function(/*use_user_gesture=*/false);
|
||||
}
|
||||
|
||||
// Test that component extensions cannot be disabled, and that policy extensions
|
||||
// can be disabled only by component/policy extensions.
|
||||
TEST_F(ManagementApiUnitTest, ComponentPolicyDisabling) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "base/location.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/metrics/histogram.h"
|
||||
#include "base/metrics/histogram_functions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
@ -433,6 +434,8 @@ ExtensionFunction::ResponseAction ManagementSetEnabledFunction::Run() {
|
||||
management::SetEnabled::Params::Create(args());
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
extension_id_ = params->id;
|
||||
base::UmaHistogramBoolean(kSetEnabledHasUserGestureHistogramName,
|
||||
user_gesture());
|
||||
|
||||
if (ExtensionsBrowserClient::Get()->IsAppModeForcedForApp(extension_id_)) {
|
||||
return RespondNow(Error(keys::kCannotChangePrimaryKioskAppError));
|
||||
|
@ -106,6 +106,10 @@ class ManagementSetEnabledFunction : public ExtensionFunction {
|
||||
|
||||
ManagementSetEnabledFunction();
|
||||
|
||||
// UMA metrics.
|
||||
static constexpr char kSetEnabledHasUserGestureHistogramName[] =
|
||||
"Extensions.Management.SetEnabled.HasUserGesture";
|
||||
|
||||
protected:
|
||||
~ManagementSetEnabledFunction() override;
|
||||
|
||||
|
@ -3812,6 +3812,16 @@ This is emitted for two scenarios when a worker may be unregistered:
|
||||
</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="Extensions.Management.SetEnabled.HasUserGesture"
|
||||
enum="Boolean" expires_after="2026-03-20">
|
||||
<owner>solomonkinard@chromium.org</owner>
|
||||
<owner>extensions-core@chromium.org</owner>
|
||||
<summary>
|
||||
Emitted whenever an extension calls the chrome.management.setEnabled() API
|
||||
method. Emits whether API call was made using a user gesture.
|
||||
</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="Extensions.Management_Refresh" units="ms"
|
||||
expires_after="2023-05-07">
|
||||
<owner>jam@chromium.org</owner>
|
||||
|
Reference in New Issue
Block a user