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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
*
* 'settings-reset-profile-dialog' is the dialog shown for clearing profile
* settings. A triggered variant of this dialog can be shown under certain
* circumstances. See triggered_profile_resetter.h for when the triggered
* variant will be used.
*/
import 'chrome://resources/cr_elements/cr_button/cr_button.js';
import 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.js';
import 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js';
import 'chrome://resources/cr_elements/cr_spinner_style.css.js';
import 'chrome://resources/js/action_link.js';
import 'chrome://resources/cr_elements/action_link.css.js';
import '../settings_shared.css.js';
import type {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.js';
import type {CrCheckboxElement} from 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.js';
import type {CrDialogElement} from 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {loadTimeData} from '../i18n_setup.js';
import {routes} from '../route.js';
import {Router} from '../router.js';
import type {ResetBrowserProxy} from './reset_browser_proxy.js';
import {ResetBrowserProxyImpl} from './reset_browser_proxy.js';
import {getTemplate} from './reset_profile_dialog.html.js';
export interface SettingsResetProfileDialogElement {
$: {
cancel: CrButtonElement,
dialog: CrDialogElement,
reset: CrButtonElement,
sendSettings: CrCheckboxElement,
};
}
const SettingsResetProfileDialogElementBase = I18nMixin(PolymerElement);
export class SettingsResetProfileDialogElement extends
SettingsResetProfileDialogElementBase {
static get is() {
return 'settings-reset-profile-dialog';
}
static get template() {
return getTemplate();
}
static get properties() {
return {
// TODO(dpapad): Evaluate whether this needs to be synced across different
// settings tabs.
isTriggered_: {
type: Boolean,
value: false,
},
triggeredResetToolName_: {
type: String,
value: '',
},
resetRequestOrigin_: String,
clearingInProgress_: {
type: Boolean,
value: false,
},
};
}
declare private isTriggered_: boolean;
declare private triggeredResetToolName_: string;
declare private resetRequestOrigin_: string;
declare private clearingInProgress_: boolean;
private browserProxy_: ResetBrowserProxy =
ResetBrowserProxyImpl.getInstance();
private getExplanationText_(): TrustedHTML {
if (this.isTriggered_) {
return this.i18nAdvanced(
'triggeredResetPageExplanation',
{substitutions: [this.triggeredResetToolName_]});
}
if (loadTimeData.getBoolean('showExplanationWithBulletPoints')) {
return this.i18nAdvanced('resetPageExplanationBulletPoints', {
tags: ['LINE_BREAKS', 'LINE_BREAK'],
});
}
return this.i18nAdvanced('resetPageExplanation');
}
private getPageTitle_(): string {
if (this.isTriggered_) {
return loadTimeData.getStringF(
'triggeredResetPageTitle', this.triggeredResetToolName_);
}
return loadTimeData.getStringF('resetDialogTitle');
}
override ready() {
super.ready();
this.addEventListener('cancel', () => {
this.browserProxy_.onHideResetProfileDialog();
});
this.shadowRoot!.querySelector('cr-checkbox a')!.addEventListener(
'click', this.onShowReportedSettingsClick_.bind(this));
}
private showDialog_() {
if (!this.$.dialog.open) {
this.$.dialog.showModal();
}
this.browserProxy_.onShowResetProfileDialog();
}
show() {
this.isTriggered_ = Router.getInstance().getCurrentRoute() ===
routes.TRIGGERED_RESET_DIALOG;
if (this.isTriggered_) {
this.browserProxy_.getTriggeredResetToolName().then(name => {
this.resetRequestOrigin_ = 'triggeredreset';
this.triggeredResetToolName_ = name;
this.showDialog_();
});
} else {
this.resetRequestOrigin_ =
Router.getInstance().getQueryParameters().get('origin') || '';
this.showDialog_();
}
}
private onCancelClick_() {
this.cancel();
}
cancel() {
if (this.$.dialog.open) {
this.$.dialog.cancel();
}
}
private onResetClick_() {
this.clearingInProgress_ = true;
this.browserProxy_
.performResetProfileSettings(
this.$.sendSettings.checked, this.resetRequestOrigin_)
.then(() => {
this.clearingInProgress_ = false;
if (this.$.dialog.open) {
this.$.dialog.close();
}
this.dispatchEvent(
new CustomEvent('reset-done', {bubbles: true, composed: true}));
});
}
/**
* Displays the settings that will be reported in a new tab.
*/
private onShowReportedSettingsClick_(e: Event) {
this.browserProxy_.showReportedSettings();
e.stopPropagation();
}
}
declare global {
interface HTMLElementTagNameMap {
'settings-reset-profile-dialog': SettingsResetProfileDialogElement;
}
}
customElements.define(
SettingsResetProfileDialogElement.is, SettingsResetProfileDialogElement);
|