| // Copyright 2016 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. |
| |
| /** |
| * @fileoverview Settings that affect how Chrome interacts with the underlying |
| * operating system (i.e. network, background processes, hardware). |
| */ |
| |
| import 'chrome://resources/cr_elements/cr_button/cr_button.m.js'; |
| import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; |
| import 'chrome://resources/cr_elements/policy/cr_policy_pref_indicator.m.js'; |
| import 'chrome://resources/polymer/v3_0/iron-flex-layout/iron-flex-layout-classes.js'; |
| import '../controls/extension_controlled_indicator.js'; |
| import '../controls/settings_toggle_button.js'; |
| import '../prefs/prefs.js'; |
| import '../relaunch_confirmation_dialog.js'; |
| import '../settings_shared.css.js'; |
| |
| import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; |
| import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; |
| |
| import {SettingsToggleButtonElement} from '../controls/settings_toggle_button.js'; |
| import {RelaunchMixin, RestartType} from '../relaunch_mixin.js'; |
| |
| import {getTemplate} from './system_page.html.js'; |
| import {SystemPageBrowserProxyImpl} from './system_page_browser_proxy.js'; |
| |
| |
| export interface SettingsSystemPageElement { |
| $: { |
| proxy: HTMLElement, |
| hardwareAcceleration: SettingsToggleButtonElement, |
| }; |
| } |
| |
| const SettingsSystemPageElementBase = RelaunchMixin(PolymerElement); |
| |
| export class SettingsSystemPageElement extends SettingsSystemPageElementBase { |
| static get is() { |
| return 'settings-system-page'; |
| } |
| |
| static get template() { |
| return getTemplate(); |
| } |
| |
| static get properties() { |
| return { |
| prefs: { |
| type: Object, |
| notify: true, |
| }, |
| |
| isProxyEnforcedByPolicy_: Boolean, |
| isProxyDefault_: Boolean, |
| // <if expr="chromeos_lacros"> |
| isSecondaryUser_: Boolean, |
| // </if> |
| }; |
| } |
| |
| static get observers() { |
| return [ |
| 'observeProxyPrefChanged_(prefs.proxy.*)', |
| ]; |
| } |
| |
| constructor() { |
| super(); |
| // <if expr="chromeos_lacros"> |
| this.isSecondaryUser_ = loadTimeData.getBoolean('isSecondaryUser'); |
| // </if> |
| } |
| |
| prefs: {proxy: chrome.settingsPrivate.PrefObject}; |
| private isProxyEnforcedByPolicy_: boolean; |
| private isProxyDefault_: boolean; |
| // <if expr="chromeos_lacros"> |
| private isSecondaryUser_: boolean; |
| // </if> |
| |
| private observeProxyPrefChanged_() { |
| const pref = this.prefs.proxy; |
| // TODO(dbeam): do types of policy other than USER apply on ChromeOS? |
| this.isProxyEnforcedByPolicy_ = |
| pref.enforcement === chrome.settingsPrivate.Enforcement.ENFORCED && |
| pref.controlledBy === chrome.settingsPrivate.ControlledBy.USER_POLICY; |
| this.isProxyDefault_ = !this.isProxyEnforcedByPolicy_ && !pref.extensionId; |
| } |
| |
| private onExtensionDisable_() { |
| // TODO(dbeam): this is a pretty huge bummer. It means there are things |
| // (inputs) that our prefs system is not observing. And that changes from |
| // other sources (i.e. disabling/enabling an extension from |
| // chrome://extensions or from the omnibox directly) will not update |
| // |this.prefs.proxy| directly (nor the UI). We should fix this eventually. |
| this.dispatchEvent(new CustomEvent( |
| 'refresh-pref', {bubbles: true, composed: true, detail: 'proxy'})); |
| } |
| |
| private onProxyTap_() { |
| if (this.isProxyDefault_) { |
| SystemPageBrowserProxyImpl.getInstance().showProxySettings(); |
| } |
| } |
| |
| private onRestartTap_(e: Event) { |
| // Prevent event from bubbling up to the toggle button. |
| e.stopPropagation(); |
| this.performRestart(RestartType.RESTART); |
| } |
| |
| /** |
| * @param enabled Whether hardware acceleration is currently enabled. |
| */ |
| private shouldShowRestart_(enabled: boolean): boolean { |
| const proxy = SystemPageBrowserProxyImpl.getInstance(); |
| return enabled !== proxy.wasHardwareAccelerationEnabledAtStartup(); |
| } |
| } |
| |
| declare global { |
| interface HTMLElementTagNameMap { |
| 'settings-system-page': SettingsSystemPageElement; |
| } |
| } |
| |
| customElements.define(SettingsSystemPageElement.is, SettingsSystemPageElement); |