Skip to content

Commit

Permalink
Create Shared Clipboard Chrome Enterprise Policy.
Browse files Browse the repository at this point in the history
Shared Clipboard feature is available in Win, Mac, Linux, Android and ChromeOS.
The default value for this policy should be True.
It's up to the admins to make sure this value is set consistently across all platforms.

Bug: 1005288
Change-Id: Ida556ccf633aa4cedc62d46cfe35ffa3123bc77b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819443
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: Julian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Yasmin Molazadeh <yasmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699817}
  • Loading branch information
Yasmin authored and Commit Bot committed Sep 25, 2019
1 parent 6708f3f commit f4d79c1
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions chrome/browser/policy/policy_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<base::Value>(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
10 changes: 10 additions & 0 deletions chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)));
}
1 change: 1 addition & 0 deletions chrome/browser/ui/browser_ui_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
6 changes: 6 additions & 0 deletions chrome/test/data/policy/policy_test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
28 changes: 27 additions & 1 deletion components/policy/resources/policy_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18124,6 +18124,7 @@ Called by update_net_error_codes.py.-->
<int value="607" label="DeviceLoginScreenVirtualKeyboardEnabled"/>
<int value="608" label="CloudExtensionRequestEnabled"/>
<int value="609" label="DeviceLoginScreenSystemInfoEnforced"/>
<int value="610" label="SharedClipboardEnabled"/>
</enum>

<enum name="EnterprisePolicyInvalidations">
Expand Down

0 comments on commit f4d79c1

Please sign in to comment.