blob: 97f494ac9b62c0441cb8c56050183d4952543b28 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/* Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
cr.define('sync.confirmation', function() {
'use strict';
/**
* @param {!Array<!HTMLElement>} path Path of the click event. Must contain
* a consent confirmation element.
* @return {string} The text of the consent confirmation element.
* @private
*/
function getConsentConfirmation(path) {
let consentConfirmation;
for (const element of path) {
if (element.nodeType !== Node.DOCUMENT_FRAGMENT_NODE &&
element.hasAttribute('consent-confirmation')) {
return element.innerHTML.trim();
}
}
assertNotReached('No consent confirmation element found.');
return '';
}
/** @return {!Array<string>} Text of the consent description elements. */
function getConsentDescription() {
const consentDescription =
Array.from(document.querySelectorAll('[consent-description]'))
.filter(element => element.clientWidth * element.clientHeight > 0)
.map(element => element.innerHTML.trim());
assert(consentDescription);
return consentDescription;
}
function onConfirm(e) {
chrome.send(
'confirm', [getConsentDescription(), getConsentConfirmation(e.path)]);
}
function onUndo(e) {
chrome.send('undo');
}
function initialize() {
cr.addWebUIListener('clear-focus', clearFocus);
document.addEventListener('keydown', onKeyDown);
$('confirmButton').addEventListener('click', onConfirm);
$('undoButton').addEventListener('click', onUndo);
// Prefer using |document.body.offsetHeight| instead of
// |document.body.scrollHeight| as it returns the correct height of the
// even when the page zoom in Chrome is different than 100%.
chrome.send('initializedWithSize', [document.body.offsetHeight]);
}
function clearFocus() {
document.activeElement.blur();
}
function onKeyDown(e) {
// If the currently focused element isn't something that performs an action
// on "enter" being pressed and the user hits "enter", perform the default
// action of the dialog, which is "OK, Got It".
if (e.key == 'Enter' &&
!/^(A|PAPER-(BUTTON|CHECKBOX))$/.test(document.activeElement.tagName)) {
$('confirmButton').click();
e.preventDefault();
}
}
return {initialize: initialize};
});
document.addEventListener('DOMContentLoaded', sync.confirmation.initialize);
|