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 Adapter
= i18n
.input
.chrome
.inputview
.Adapter
;
21 var FeatureName
= i18n
.input
.chrome
.inputview
.FeatureName
;
25 * Controller for experimental features.
29 i18n
.input
.chrome
.inputview
.FeatureTracker = function() {
32 * Whether experimental flags is enabled.
34 * @private {Object.<string, boolean>}
39 * Features that are enabled by default. Any feature not on this list is
40 * disabled unless the runtime --enable-inputview-{feature} flag is present.
43 * @private {!Array<FeatureName>}
45 this.ENABLED_BY_DEFAULT_
= [];
48 var FeatureTracker
= i18n
.input
.chrome
.inputview
.FeatureTracker
;
52 * Whether the feature is enabled.
54 * @param {!FeatureName} feature .
57 FeatureTracker
.prototype.isEnabled = function(feature
) {
58 if (feature
in this.features_
) {
59 return this.features_
[feature
];
61 return (this.ENABLED_BY_DEFAULT_
.indexOf(feature
) >= 0) ||
62 !!this.features_
[FeatureName
.EXPERIMENTAL
];
67 * Inits the feature tracker.
69 * @param {!Object} config The keyboard config.
71 FeatureTracker
.prototype.initialize = function(config
) {
72 if (config
.features
) {
73 var features
= config
.features
;
74 // Parse the run time flags.
75 for (var i
= 0; i
< features
.length
; i
++) {
76 var pieces
= features
[i
].split('-');
77 var state
= pieces
.pop();
78 if (state
== 'enabled') {
79 this.features_
[pieces
.join('-')] = true;
80 } else if (state
== 'disabled') {
81 this.features_
[pieces
.join('-')] = false;
83 console
.error('Unrecognized flag: ' + features
[i
]);
87 console
.error('API Error. Features not present in config.');