Commit 272c1f7d authored by Jérôme Gingras's avatar Jérôme Gingras Committed by Commit Bot

Add a button to copy a policy's value on the chrome://policy page.

Bug: 1020213
Change-Id: Ib637c351af63496ba9b7bb538b0df0639fd18f96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212630
Commit-Queue: Jerome Gingras <jgingras@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772268}
parent 408bded3
......@@ -57,6 +57,7 @@ content::WebUIDataSource* CreatePolicyUIHtmlSource() {
{"noPoliciesSet", IDS_POLICY_NO_POLICIES_SET},
{"offHoursActive", IDS_POLICY_OFFHOURS_ACTIVE},
{"offHoursNotActive", IDS_POLICY_OFFHOURS_NOT_ACTIVE},
{"policyCopyValue", IDS_POLICY_COPY_VALUE},
{"policiesPushOff", IDS_POLICY_PUSH_POLICIES_OFF},
{"policiesPushOn", IDS_POLICY_PUSH_POLICIES_ON},
{"policyLearnMore", IDS_POLICY_LEARN_MORE},
......@@ -91,5 +92,4 @@ PolicyUI::PolicyUI(content::WebUI* web_ui) : WebUIController(web_ui) {
CreatePolicyUIHtmlSource());
}
PolicyUI::~PolicyUI() {
}
PolicyUI::~PolicyUI() = default;
......@@ -190,6 +190,11 @@
<div class="value row" role="row" hidden>
<div class="name" role="rowheader">$i18n{value}</div>
<div class="value" role="cell"></div>
<div class="copy" role="cell">
<a is="action-link" class="copy-value link" role="cell">
<img src="../../../../ui/webui/resources/images/icon_copy_content.svg">
</a>
</div>
</div>
<div class="errors row" role="row" hidden>
<div class="name" role="rowheader">$i18n{error}</div>
......
......@@ -236,6 +236,9 @@ cr.define('policy', function() {
decorate() {
const toggle = this.querySelector('.policy.row .toggle');
toggle.addEventListener('click', this.toggleExpanded_.bind(this));
const copy = this.querySelector('.copy-value');
copy.addEventListener('click', this.copyValue_.bind(this));
},
/** @param {Policy} policy */
......@@ -295,6 +298,9 @@ cr.define('policy', function() {
const valueDisplay = this.querySelector('.value');
valueDisplay.textContent = truncatedValue;
const copyLink = this.querySelector('.copy .link');
copyLink.title =
loadTimeData.getStringF('policyCopyValue', policy.name);
const valueRowContentDisplay = this.querySelector('.value.row .value');
valueRowContentDisplay.textContent = policy.value;
......@@ -340,6 +346,27 @@ cr.define('policy', function() {
}
},
/**
* Copies the policy's value to the clipboard.
* @private
*/
copyValue_() {
const policyValueDisplay = this.querySelector('.value.row .value');
// Select the text that will be copied.
const selection = window.getSelection();
const range = window.document.createRange();
range.selectNodeContents(policyValueDisplay);
selection.removeAllRanges();
selection.addRange(range);
// Copy the policy value to the clipboard.
navigator.clipboard.writeText(policyValueDisplay.innerText)
.catch(error => {
console.error('Unable to copy policy value to clipboard:', error);
});
},
/**
* Toggle the visibility of an additional row containing the complete text.
* @private
......
......@@ -542,6 +542,9 @@ Additional details:
<message name="IDS_POLICY_SIGNIN_PROFILE" desc="Label to indicate that the policy is for the sign-in screen profile.">
sign-in screen profile
</message>
<message name ="IDS_POLICY_COPY_VALUE" desc="Help text for link that copies the value of a policy.">
Copy the value of <ph name="POLICY_NAME">$1<ex>AllowDinosaurEasterEgg</ex></ph> policy
</message>
<!-- Strings for Disabled chrome://.* screen -->
<message name="IDS_CHROME_URLS_DISABLED_PAGE_HEADER" desc="A heading for the user when the application is blocked.">
......
7c44516d21a097cdf1dfd1b1155a1f3e22de8228
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment