Commit 13125d5b authored by jlklein's avatar jlklein Committed by Commit bot

Fire an error if a pref used in the UI is missing once all prefs are fetched.

BUG=469919

Review URL: https://codereview.chromium.org/1029743002

Cr-Commit-Position: refs/heads/master@{#322120}
parent 2230e1f9
......@@ -17,3 +17,7 @@
margin: 0;
padding: 0 0 0.25em;
}
.more-a11y-link {
margin-bottom: 10px;
}
......@@ -13,6 +13,14 @@
<paper-shadow layout vertical cross-fade>
<cr-settings-page-header page="{{}}"></cr-settings-page-header>
<div class="more-a11y-link">
<a href="https://chrome.google.com/webstore/category/collection/accessibility"
target="_blank">
Add additional accessibility features
</a>
</div>
<if expr="chromeos">
<cr-settings-checkbox pref="{{prefs.settings.a11y.enable_menu}}"
label="Show accessibility options in the system menu">
</cr-settings-checkbox>
......@@ -53,6 +61,8 @@
<cr-settings-checkbox pref="{{prefs.settings.a11y.virtual_keyboard}}"
label="Enable on-screen keyboard"></cr-settings-checkbox>
</if>
</paper-shadow>
</template>
<script src="a11y_page.js"></script>
......
<link rel="import" href="chrome://resources/polymer/core-label/core-label.html">
<link rel="import" href="chrome://resources/cr_elements/cr_checkbox/cr_checkbox.html">
<link rel="import" href="chrome://resources/cr_elements/cr_events/cr_events.html">
<link rel="import" href="chrome://md-settings/pref_tracker/pref_tracker.html">
<polymer-element name="cr-settings-checkbox">
<template>
<link rel="stylesheet" href="checkbox.css">
<cr-events id="events"></cr-events>
<cr-settings-pref-tracker pref="{{pref}}"></cr-settings-pref-tracker>
<core-label horizontal layout>
<cr-checkbox id="checkbox" checked="{{pref.value}}"
disabled="{{pref.disabled}}" for></cr-checkbox>
......
<link rel="import" href="chrome://resources/polymer/polymer/polymer.html">
<polymer-element name="cr-settings-pref-tracker">
<script src="chrome://md-settings/prefs/prefs_types.js"></script>
<script src="pref_tracker.js"></script>
</polymer-element>
// 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.
/**
* @fileoverview
* `cr-settings-pref-tracker` is a utility element used to track the
* initialization of a specified preference and throw an error if the pref
* is not defined after prefs have all been fetched.
*
* Example:
*
* <cr-settings-pref-tracker pref="{{prefs.settings.foo.bar}}">
* </cr-settings-pref-tracker>
*
* @element cr-settings-pref-tracker
*/
(function() {
/**
* An array of all the tracker instances.
* @type {!Array<!CrSettingsPrefTrackerElement>}
*/
var instances = [];
/**
* Validates all tracker instances.
* @private
*/
var validateAll_ = function() {
instances.forEach(function(tracker) {
tracker.validate_();
});
};
document.addEventListener(CrSettingsPrefs.INITIALIZED, validateAll_);
Polymer('cr-settings-pref-tracker', {
publish: {
/**
* The Preference object being tracked.
*
* @attribute pref
* @type {Object}
* @default null
*/
pref: null,
},
observe: {
pref: 'validate_',
},
/** @override */
ready: function() {
this.validate_();
instances.push(this);
},
/**
* Throws an error if prefs are initialized and the tracked pref is not
* found.
* @private
*/
validate_: function() {
this.async(function() {
// Note that null == undefined.
if (CrSettingsPrefs.isInitialized && this.pref == null) {
// HACK ALERT: This is the best clue we have as to the pref key for
// this tracker. This value should not be relied upon anywhere or
// actually used besides for this error message.
var keyHint = '';
var parentPrefString = this.parentNode && this.parentNode.host &&
this.parentNode.host.getAttribute('pref');
if (parentPrefString) {
keyHint = parentPrefString.match(/{{([a-z._]+)}}/)[1];
}
throw new Error('Pref not found. Key Hint: ' + keyHint);
}
});
},
});
})();
......@@ -3,5 +3,6 @@
<link rel="import" href="chrome://resources/html/cr.html">
<polymer-element name="cr-settings-prefs">
<script src="prefs_types.js"></script>
<script src="prefs.js"></script>
</polymer-element>
......@@ -57,7 +57,7 @@
* Object containing all preferences.
*
* @attribute settings
* @type CrSettingsPrefs.Settings
* @type {Object}
* @default null
*/
settings: null,
......@@ -65,6 +65,7 @@
/** @override */
created: function() {
CrSettingsPrefs.isInitialized = false;
this.settings = {};
this.fetchSettings_();
},
......@@ -94,6 +95,8 @@
*/
onPrefsFetched_: function(dict) {
this.parsePrefDict_('', dict);
CrSettingsPrefs.isInitialized = true;
document.dispatchEvent(new Event(CrSettingsPrefs.INITIALIZED));
},
/**
......
......@@ -3,46 +3,21 @@
// found in the LICENSE file.
/**
* @fileoverview Typedefs for CrSettingsPrefsElement.
* @fileoverview Types for CrSettingsPrefsElement.
*/
var CrSettingsPrefs = {};
if (CrSettingsPrefs === undefined) {
var CrSettingsPrefs = {};
/**
* @typedef {{
* a11y: CrSettingsPrefs.A11y,
* touchpad: CrSettingsPrefs.Touchpad,
* downloads: CrSettingsPrefs.Downloads,
* accessibility: boolean
* }}
*/
CrSettingsPrefs.Settings;
/**
* @typedef {{
* enableMenu: boolean,
* largeCursorEnabled: boolean,
* highContrastEnabled: boolean,
* stickyKeysEnabled: boolean,
* screenMagnifier: boolean,
* autoclick: boolean,
* autoclickDelayMs: number,
* virtualKeyboard: boolean
* }}
*/
CrSettingsPrefs.A11y;
/**
* The type of the event fired when prefs have been fetched and initialized.
* @const {string}
*/
CrSettingsPrefs.INITIALIZED = 'cr-settings-prefs-initialized';
/**
* @typedef {{
* downloadLocation: string,
* promptForDownload: boolean
* }}
*/
CrSettingsPrefs.Downloads;
/**
* @typedef {{
* enableTapDragging: boolean
* }}
*/
CrSettingsPrefs.Touchpad;
/**
* Global boolean set to true when all settings have been initialized.
* @type {boolean}
*/
CrSettingsPrefs.isInitialized = false;
}
......@@ -17,7 +17,9 @@
type="chrome_html" />
<structure name="IDR_SETTINGS_A11Y_PAGE_HTML"
file="a11y_page/a11y_page.html"
type="chrome_html" />
type="chrome_html"
flattenhtml="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_A11Y_PAGE_CSS"
file="a11y_page/a11y_page.css"
type="chrome_html" />
......@@ -99,6 +101,15 @@
<structure name="IDR_SETTINGS_PREFS_HTML"
file="prefs/prefs.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_PREFS_TYPES_JS"
file="prefs/prefs_types.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_PREF_TRACKER_HTML"
file="pref_tracker/pref_tracker.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_PREF_TRACKER_JS"
file="pref_tracker/pref_tracker.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_SETTINGS_HTML"
file="settings.html"
type="chrome_html" />
......
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