diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc index e1ad4504d9a3ee..fffe15dcb05b76 100644 --- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc +++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc @@ -391,6 +391,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = { { key::kSpellcheckEnabled, spellcheck::prefs::kSpellCheckEnable, base::Value::Type::BOOLEAN }, + { key::kSharedClipboardEnabled, + prefs::kSharedClipboardEnabled, + base::Value::Type::BOOLEAN }, // First run import. { key::kImportBookmarks, diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index 24eaf8f8e1fad2..63420e83a50d31 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -5799,4 +5799,22 @@ IN_PROC_BROWSER_TEST_F(PolicyTestSyncXHR, CheckAllowSyncXHRInPageDismissal) { EXPECT_EQ("true", message); } +class SharedClipboardPolicyTest : public PolicyTest { + void SetUpInProcessBrowserTestFixture() override { + PolicyTest::SetUpInProcessBrowserTestFixture(); + PolicyMap policies; + policies.Set(policy::key::kSharedClipboardEnabled, + policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, + policy::POLICY_SOURCE_CLOUD, + std::make_unique(true), nullptr); + provider_.UpdateChromePolicy(policies); + } +}; + +IN_PROC_BROWSER_TEST_F(SharedClipboardPolicyTest, SharedClipboardEnabled) { + PrefService* prefs = browser()->profile()->GetPrefs(); + EXPECT_TRUE(prefs->IsManagedPreference(prefs::kSharedClipboardEnabled)); + EXPECT_TRUE(prefs->GetBoolean(prefs::kSharedClipboardEnabled)); +} + } // namespace policy diff --git a/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.cc b/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.cc index 3afa77a17d0b6c..1087e0906d82e8 100644 --- a/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.cc +++ b/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.cc @@ -4,13 +4,23 @@ #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/sharing/shared_clipboard/feature_flags.h" #include "chrome/browser/sharing/sharing_service.h" #include "chrome/browser/sharing/sharing_service_factory.h" +#include "chrome/common/pref_names.h" +#include "components/prefs/pref_service.h" #include "content/public/browser/browser_context.h" bool ShouldOfferSharedClipboard(content::BrowserContext* browser_context, const base::string16& text) { + // Check Chrome enterprise policy for Shared Clipboard. + Profile* profile = Profile::FromBrowserContext(browser_context); + if (profile && + !profile->GetPrefs()->GetBoolean(prefs::kSharedClipboardEnabled)) { + return false; + } + SharingService* sharing_service = SharingServiceFactory::GetForBrowserContext(browser_context); return sharing_service && base::FeatureList::IsEnabled(kSharedClipboardUI) && diff --git a/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils_unittest.cc b/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils_unittest.cc index bc7f3a521eef95..312c3130046aea 100644 --- a/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils_unittest.cc +++ b/chrome/browser/sharing/shared_clipboard/shared_clipboard_utils_unittest.cc @@ -16,7 +16,9 @@ #include "chrome/browser/sharing/sharing_service_factory.h" #include "chrome/browser/sharing/sharing_sync_preference.h" #include "chrome/browser/sharing/vapid_key_manager.h" +#include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" +#include "components/prefs/pref_service.h" #include "content/public/test/browser_task_environment.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -115,3 +117,11 @@ TEST_F(SharedClipboardUtilsTest, NoSharingService_DoNotShowMenu) { EXPECT_FALSE( ShouldOfferSharedClipboard(&profile_, base::ASCIIToUTF16(kText))); } + +TEST_F(SharedClipboardUtilsTest, EnterprisePolicy_Disabled) { + scoped_feature_list_.InitAndEnableFeature(kSharedClipboardUI); + // Set the enterprise policy to false: + profile_.GetPrefs()->SetBoolean(prefs::kSharedClipboardEnabled, false); + EXPECT_FALSE( + ShouldOfferSharedClipboard(&profile_, base::ASCIIToUTF16(kText))); +} diff --git a/chrome/browser/ui/browser_ui_prefs.cc b/chrome/browser/ui/browser_ui_prefs.cc index 149f4b566636c0..43e31eb9854a6f 100644 --- a/chrome/browser/ui/browser_ui_prefs.cc +++ b/chrome/browser/ui/browser_ui_prefs.cc @@ -101,6 +101,7 @@ void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) { // them even though they're only typically controlled via policy. registry->RegisterBooleanPref(prefs::kClearPluginLSODataEnabled, true); registry->RegisterBooleanPref(prefs::kHideWebStoreIcon, false); + registry->RegisterBooleanPref(prefs::kSharedClipboardEnabled, true); #if defined(OS_MACOSX) // This really belongs in platform code, but there's no good place to // initialize it between the time when the AppController is created diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index d8a3807172eeee..ab6018a87b31da 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1587,6 +1587,10 @@ const char kDefaultTasksByMimeType[] = const char kDefaultTasksBySuffix[] = "filebrowser.tasks.default_by_suffix"; +// A flag to enable/disable the Shared Clipboard feature which enables users to +// send text across devices. +const char kSharedClipboardEnabled[] = "browser.shared_clipboard_enabled"; + // Extensions which should be opened upon completion. const char kDownloadExtensionsToOpen[] = "download.extensions_to_open"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 1bb60ef1793b67..1fa644a7e30240 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -528,6 +528,8 @@ extern const char kAllowFileSelectionDialogs[]; extern const char kDefaultTasksByMimeType[]; extern const char kDefaultTasksBySuffix[]; +extern const char kSharedClipboardEnabled[]; + extern const char kSelectFileLastDirectory[]; extern const char kExcludedSchemes[]; diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json index 447587526255f7..23ceadb8e1ead7 100644 --- a/chrome/test/data/policy/policy_test_cases.json +++ b/chrome/test/data/policy/policy_test_cases.json @@ -3808,6 +3808,12 @@ ] }, + "SharedClipboardEnabled" : { + "os": ["win", "linux", "mac", "chromeos", "android"], + "test_policy": { "SharedClipboardEnabled": false }, + "pref_mappings": [{ "pref": "browser.shared_clipboard_enabled" }] + }, + "----- Chrome OS device policies ---------------------------------------": {}, "DevicePolicyRefreshRate": { diff --git a/components/policy/resources/policy_templates.json b/components/policy/resources/policy_templates.json index 0707af799342e0..cb1cc4dba3af80 100644 --- a/components/policy/resources/policy_templates.json +++ b/components/policy/resources/policy_templates.json @@ -10300,6 +10300,32 @@ If this policy is left unset, the virtual keyboard is disabled on the login screen initially but can be enabled by the user anytime.''', }, + { + 'name': 'SharedClipboardEnabled', + 'owners': ['mvanouwerkerk@chromium.org', 'yasmo@chromium.org'], + 'type': 'main', + 'schema': { 'type': 'boolean' }, + 'supported_on': ['chrome.*:79-', 'chrome_os:79-', 'android:79-'], + 'features': { + 'dynamic_refresh': True, + 'per_profile': True, + }, + 'example_value': True, + 'id': 610, + 'caption': '''Enable the Shared Clipboard Feature''', + 'tags': [], + 'desc': '''Enable the Shared Clipboard feature which allows users to send text between Chrome Desktops and an Android device when Sync is enabled and the user is Signed-in. + + If this policy is set to true, the capability of sending text, cross device, for chrome user is enabled. + + If this policy is set to false, the capability of sending text, cross device, for chrome user is disabled. + + If you set this policy, users cannot change or override it. + + If this policy is left unset, the shared clipboard feature is enabled by default. + + It is up to the admins to set policies in all platforms they care about. It's recommended to set this policy to one value in all platforms.''', + }, { 'name': 'DeviceLoginScreenDefaultScreenMagnifierType', 'owners': ['file://components/policy/resources/OWNERS'], @@ -18631,6 +18657,6 @@ The recommended way to configure policy on Windows is via GPO, although provisio ], 'placeholders': [], 'deleted_policy_ids': [412, 546, 562, 569], - 'highest_id_currently_used': 609, + 'highest_id_currently_used': 610, 'highest_atomic_group_id_currently_used': 37 } diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml index f8e8079664fb73..fa4d27554b4b6e 100644 --- a/tools/metrics/histograms/enums.xml +++ b/tools/metrics/histograms/enums.xml @@ -18124,6 +18124,7 @@ Called by update_net_error_codes.py.--> +