desk-api: Add DeskAPIThirdPartyAccessEnabled enterprise policy

Bug: 1356742, b/243584674
Change-Id: Ic8ed9a3b81af3978db2f9f0db73d3b4a27e9baa7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3852827
Reviewed-by: Igor <[email protected]>
Commit-Queue: Yanzhu Du <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Pavol Marko <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1049415}
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index bb6b11f..8b149ca 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -1581,6 +1581,9 @@
 #endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS)
 
 #if BUILDFLAG(IS_CHROMEOS)
+  { key::kDeskAPIThirdPartyAccessEnabled,
+    prefs::kDeskAPIThirdPartyAccessEnabled,
+    base::Value::Type::BOOLEAN },
   { key::kDeviceAttributesAllowedForOrigins,
     prefs::kDeviceAttributesAllowedForOrigins,
     base::Value::Type::LIST },
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 5733764..196f7b2 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -1463,6 +1463,7 @@
   extensions::platform_keys::RegisterProfilePrefs(registry);
   certificate_manager::CertificatesHandler::RegisterProfilePrefs(registry);
   policy::PolicyCertService::RegisterProfilePrefs(registry);
+  registry->RegisterBooleanPref(prefs::kDeskAPIThirdPartyAccessEnabled, false);
   registry->RegisterBooleanPref(prefs::kInsightsExtensionEnabled, false);
   // By default showing Sync Consent is set to true. It can changed by policy.
   registry->RegisterBooleanPref(prefs::kEnableSyncConsent, true);
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index c27fca0..fc8501f 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -478,6 +478,12 @@
 // attestation.
 const char kAttestationExtensionAllowlist[] = "attestation.extension_allowlist";
 
+// A boolean specifying whether the Desk API is enabled for third party web
+// applications. If set to true, the Desk API bridge component extension will be
+// installed.
+const char kDeskAPIThirdPartyAccessEnabled[] =
+    "desk_api_third_party_access_enabled";
+
 // The list of extensions allowed to skip print job confirmation dialog when
 // they use the chrome.printing.submitJob() function. Note that this used to be
 // `kPrintingAPIExtensionsWhitelist`, hence the difference between the variable
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 264c4ee..7d44889 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -375,6 +375,7 @@
 extern const char kSharedStorage[];
 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 #if BUILDFLAG(IS_CHROMEOS)
+extern const char kDeskAPIThirdPartyAccessEnabled[];
 extern const char kForceMaximizeOnFirstRun[];
 extern const char kInsightsExtensionEnabled[];
 extern const char kOOMKillsDailyCount[];
diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json
index 04c3a04..5eaa67b 100644
--- a/chrome/test/data/policy/policy_test_cases.json
+++ b/chrome/test/data/policy/policy_test_cases.json
@@ -20037,5 +20037,41 @@
         }
       }
     ]
+  },
+  "DeskAPIThirdPartyAccessEnabled": {
+    "os": [
+      "chromeos_ash",
+      "chromeos_lacros"
+    ],
+    "policy_pref_mapping_tests": [
+      {
+        "policies": {
+          "DeskAPIThirdPartyAccessEnabled": true
+        },
+        "prefs": {
+          "desk_api_third_party_access_enabled": {
+            "value": true
+          }
+        }
+      },
+      {
+        "policies": {
+          "DeskAPIThirdPartyAccessEnabled": false
+        },
+        "prefs": {
+          "desk_api_third_party_access_enabled": {
+            "value": false
+          }
+        }
+      },
+      {
+        "policies": {},
+        "prefs": {
+          "desk_api_third_party_access_enabled": {
+            "default_value": false
+          }
+        }
+      }
+    ]
   }
 }