OLD | NEW |
| (Empty) |
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 | |
7 // | |
8 // http://www.apache.org/licenses/LICENSE-2.0 | |
9 // | |
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"); | |
13 // | |
14 goog.provide('i18n.input.chrome.inputview.FeatureTracker'); | |
15 | |
16 goog.require('goog.object'); | |
17 goog.require('i18n.input.chrome.inputview.FeatureName'); | |
18 | |
19 goog.scope(function() { | |
20 var FeatureName = i18n.input.chrome.inputview.FeatureName; | |
21 | |
22 | |
23 /** | |
24 * Controller for experimental features. | |
25 * | |
26 * @constructor | |
27 */ | |
28 i18n.input.chrome.inputview.FeatureTracker = function() { | |
29 | |
30 /** | |
31 * Whether experimental flags is enabled. | |
32 * | |
33 * @private {Object.<string, boolean>} | |
34 */ | |
35 this.features_ = {}; | |
36 | |
37 /** | |
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. | |
40 * | |
41 * @const | |
42 * @private {!Array<FeatureName>} | |
43 */ | |
44 this.ENABLED_BY_DEFAULT_ = []; | |
45 | |
46 /** | |
47 * Whether the features list is ready. | |
48 * | |
49 * @private {boolean} | |
50 */ | |
51 this.ready_ = false; | |
52 }; | |
53 | |
54 var FeatureTracker = i18n.input.chrome.inputview.FeatureTracker; | |
55 | |
56 | |
57 /** | |
58 * Whether the feature is enabled. | |
59 * | |
60 * @param {!FeatureName} feature . | |
61 * @return {boolean} | |
62 */ | |
63 FeatureTracker.prototype.isEnabled = function(feature) { | |
64 if (!this.ready_) { | |
65 console.error('Features not present in config or not ready yet.'); | |
66 } | |
67 if (feature in this.features_) { | |
68 return this.features_[feature]; | |
69 } | |
70 return (this.ENABLED_BY_DEFAULT_.indexOf(feature) >= 0) || | |
71 !!this.features_[FeatureName.EXPERIMENTAL]; | |
72 }; | |
73 | |
74 | |
75 /** | |
76 * Inits the feature tracker. | |
77 * | |
78 * @param {!Object} config The keyboard config. | |
79 */ | |
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; | |
91 } else { | |
92 console.error('Unrecognized flag: ' + features[i]); | |
93 } | |
94 } | |
95 this.ready_ = true; | |
96 } else { | |
97 console.error('API Error. Features not present in config.'); | |
98 return; | |
99 } | |
100 }; | |
101 | |
102 }); // goog.scope | |
103 | |
OLD | NEW |