OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Bridge that sends TTS messages from content scripts or | 6 * @fileoverview Bridge that sends TTS messages from content scripts or |
7 * other pages to the main background page. | 7 * other pages to the main background page. |
8 * | 8 * |
9 */ | 9 */ |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 /** @override */ | 52 /** @override */ |
53 cvox.ChromeTts.prototype.isSpeaking = function() { | 53 cvox.ChromeTts.prototype.isSpeaking = function() { |
54 cvox.ChromeTts.superClass_.isSpeaking.call(this); | 54 cvox.ChromeTts.superClass_.isSpeaking.call(this); |
55 return false; | 55 return false; |
56 }; | 56 }; |
57 | 57 |
58 /** @override */ | 58 /** @override */ |
59 cvox.ChromeTts.prototype.stop = function() { | 59 cvox.ChromeTts.prototype.stop = function() { |
60 cvox.ChromeTts.superClass_.stop.call(this); | 60 cvox.ChromeTts.superClass_.stop.call(this); |
61 cvox.ExtensionBridge.send( | 61 cvox.ExtensionBridge.send({'target': 'TTS', 'action': 'stop'}); |
62 {'target': 'TTS', | |
63 'action': 'stop'}); | |
64 }; | 62 }; |
65 | 63 |
66 /** @override */ | 64 /** @override */ |
67 cvox.ChromeTts.prototype.increaseOrDecreaseProperty = | 65 cvox.ChromeTts.prototype.increaseOrDecreaseProperty = function( |
68 function(propertyName, increase) { | 66 propertyName, increase) { |
69 cvox.ExtensionBridge.send( | 67 cvox.ExtensionBridge.send({ |
70 {'target': 'TTS', | 68 'target': 'TTS', |
71 'action': 'increaseOrDecrease', | 69 'action': 'increaseOrDecrease', |
72 'property': propertyName, | 70 'property': propertyName, |
73 'increase': increase}); | 71 'increase': increase |
| 72 }); |
74 }; | 73 }; |
75 | 74 |
76 /** | 75 /** |
77 * Increases a TTS speech property. | 76 * Increases a TTS speech property. |
78 * @param {string} property_name The name of the property to increase. | 77 * @param {string} property_name The name of the property to increase. |
79 * @param {boolean} announce Whether to announce that the property is | 78 * @param {boolean} announce Whether to announce that the property is |
80 * changing. | 79 * changing. |
81 */ | 80 */ |
82 cvox.ChromeTts.prototype.increaseProperty = function(property_name, announce) { | 81 cvox.ChromeTts.prototype.increaseProperty = function(property_name, announce) { |
83 goog.base(this, 'increaseProperty', property_name, announce); | 82 goog.base(this, 'increaseProperty', property_name, announce); |
84 cvox.ExtensionBridge.send( | 83 cvox.ExtensionBridge.send({ |
85 {'target': 'TTS', | 84 'target': 'TTS', |
86 'action': 'increase' + property_name, | 85 'action': 'increase' + property_name, |
87 'announce': announce}); | 86 'announce': announce |
| 87 }); |
88 }; | 88 }; |
89 | 89 |
90 /** | 90 /** |
91 * Listens for TTS_COMPLETED message and executes the callback function. | 91 * Listens for TTS_COMPLETED message and executes the callback function. |
92 */ | 92 */ |
93 cvox.ChromeTts.prototype.addBridgeListener = function() { | 93 cvox.ChromeTts.prototype.addBridgeListener = function() { |
94 cvox.ExtensionBridge.addMessageListener( | 94 cvox.ExtensionBridge.addMessageListener(function(msg, port) { |
95 function(msg, port) { | 95 var message = msg['message']; |
96 var message = msg['message']; | 96 if (message == 'TTS_CALLBACK') { |
97 if (message == 'TTS_CALLBACK') { | 97 var id = msg['id']; |
98 var id = msg['id']; | 98 var func = cvox.ChromeTts.functionMap[id]; |
99 var func = cvox.ChromeTts.functionMap[id]; | 99 if (func != undefined) { |
100 if (func != undefined) { | 100 if (!msg['cleanupOnly']) { |
101 if (!msg['cleanupOnly']) { | 101 func(); |
102 func(); | |
103 } | |
104 delete cvox.ChromeTts.functionMap[id]; | |
105 } | |
106 } | 102 } |
107 }); | 103 delete cvox.ChromeTts.functionMap[id]; |
| 104 } |
| 105 } |
| 106 }); |
108 }; | 107 }; |
109 | 108 |
110 /** | 109 /** |
111 * Creates a message suitable for sending as a speak action to background tts. | 110 * Creates a message suitable for sending as a speak action to background tts. |
112 * @param {string} textString The string of text to be spoken. | 111 * @param {string} textString The string of text to be spoken. |
113 * @param {cvox.QueueMode} queueMode The queue mode. | 112 * @param {cvox.QueueMode} queueMode The queue mode. |
114 * @param {Object=} properties Speech properties to use for this utterance. | 113 * @param {Object=} properties Speech properties to use for this utterance. |
115 * @return {Object} A message. | 114 * @return {Object} A message. |
116 * @private | 115 * @private |
117 */ | 116 */ |
118 cvox.ChromeTts.prototype.createMessageForProperties_ = | 117 cvox.ChromeTts.prototype.createMessageForProperties_ = function( |
119 function(textString, queueMode, properties) { | 118 textString, queueMode, properties) { |
120 var message = {'target': 'TTS', | 119 var message = { |
121 'action': 'speak', | 120 'target': 'TTS', |
122 'text': textString, | 121 'action': 'speak', |
123 'queueMode': queueMode, | 122 'text': textString, |
124 'properties': properties}; | 123 'queueMode': queueMode, |
| 124 'properties': properties |
| 125 }; |
125 | 126 |
126 if (properties['startCallback'] != undefined) { | 127 if (properties['startCallback'] != undefined) { |
127 cvox.ChromeTts.functionMap[cvox.ChromeTts.callId] = | 128 cvox.ChromeTts.functionMap[cvox.ChromeTts.callId] = |
128 properties['startCallback']; | 129 properties['startCallback']; |
129 message['startCallbackId'] = cvox.ChromeTts.callId++; | 130 message['startCallbackId'] = cvox.ChromeTts.callId++; |
130 } | 131 } |
131 if (properties['endCallback'] != undefined) { | 132 if (properties['endCallback'] != undefined) { |
132 cvox.ChromeTts.functionMap[cvox.ChromeTts.callId] = | 133 cvox.ChromeTts.functionMap[cvox.ChromeTts.callId] = |
133 properties['endCallback']; | 134 properties['endCallback']; |
134 message['endCallbackId'] = cvox.ChromeTts.callId++; | 135 message['endCallbackId'] = cvox.ChromeTts.callId++; |
135 } | 136 } |
136 return message; | 137 return message; |
137 }; | 138 }; |
138 | 139 |
139 /** @override */ | 140 /** @override */ |
140 cvox.HostFactory.ttsConstructor = cvox.ChromeTts; | 141 cvox.HostFactory.ttsConstructor = cvox.ChromeTts; |
OLD | NEW |