1 // Copyright 2015 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License.
3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License");
14 goog.provide('i18n.input.chrome.inputview.FeatureTracker');
16 goog.require('goog.object');
17 goog.require('i18n.input.chrome.inputview.FeatureName');
19 goog.scope(function() {
20 var FeatureName = i18n.input.chrome.inputview.FeatureName;
24 * Controller for experimental features.
28 i18n.input.chrome.inputview.FeatureTracker = function() {
31 * Whether experimental flags is enabled.
33 * @private {Object.<string, boolean>}
38 * Features that are enabled by default. Any feature not on this list is
39 * disabled unless the runtime --enable-inputview-{feature} flag is present.
42 * @private {!Array<FeatureName>}
44 this.ENABLED_BY_DEFAULT_ = [];
47 * Whether the features list is ready.
54 var FeatureTracker = i18n.input.chrome.inputview.FeatureTracker;
58 * Whether the feature is enabled.
60 * @param {!FeatureName} feature .
63 FeatureTracker.prototype.isEnabled = function(feature) {
65 console.error('Features not present in config or not ready yet.');
67 if (feature in this.features_) {
68 return this.features_[feature];
70 return (this.ENABLED_BY_DEFAULT_.indexOf(feature) >= 0) ||
71 !!this.features_[FeatureName.EXPERIMENTAL];
76 * Inits the feature tracker.
78 * @param {!Object} config The keyboard config.
80 FeatureTracker.prototype.initialize = function(config) {
81 if (config.features) {
82 var features = config.features;
83 // Parse the run time flags.
84 for (var i = 0; i < features.length; i++) {
85 var pieces = features[i].split('-');
86 var state = pieces.pop();
87 if (state == 'enabled') {
88 this.features_[pieces.join('-')] = true;
89 } else if (state == 'disabled') {
90 this.features_[pieces.join('-')] = false;
92 console.error('Unrecognized flag: ' + features[i]);
97 console.error('API Error. Features not present in config.');