OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Custom bindings for the i18n API. | 5 // Custom bindings for the i18n API. |
6 | 6 |
| 7 var Bindings = require('schema_binding_generator').Bindings; |
| 8 var bindings = new Bindings('i18n'); |
| 9 |
7 var i18nNatives = requireNative('i18n'); | 10 var i18nNatives = requireNative('i18n'); |
8 var GetL10nMessage = i18nNatives.GetL10nMessage; | 11 var GetL10nMessage = i18nNatives.GetL10nMessage; |
9 | 12 |
10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 13 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
11 | 14 |
12 chromeHidden.registerCustomHook('i18n', function(bindingsAPI, extensionId) { | 15 bindings.registerCustomHook(function(bindingsAPI, extensionId) { |
13 var apiFunctions = bindingsAPI.apiFunctions; | 16 var apiFunctions = bindingsAPI.apiFunctions; |
14 | 17 |
15 apiFunctions.setUpdateArgumentsPreValidate('getMessage', function() { | 18 apiFunctions.setUpdateArgumentsPreValidate('getMessage', function() { |
16 var args = Array.prototype.slice.call(arguments); | 19 var args = Array.prototype.slice.call(arguments); |
17 | 20 |
18 // The first argument is the message, and should be a string. | 21 // The first argument is the message, and should be a string. |
19 var message = args[0]; | 22 var message = args[0]; |
20 if (typeof(message) !== 'string') { | 23 if (typeof(message) !== 'string') { |
21 console.warn(extensionId + ': the first argument to getMessage should ' + | 24 console.warn(extensionId + ': the first argument to getMessage should ' + |
22 'be type "string", was ' + message + | 25 'be type "string", was ' + message + |
23 ' (type "' + typeof(message) + '")'); | 26 ' (type "' + typeof(message) + '")'); |
24 args[0] = String(message); | 27 args[0] = String(message); |
25 } | 28 } |
26 | 29 |
27 return args; | 30 return args; |
28 }); | 31 }); |
29 | 32 |
30 apiFunctions.setHandleRequest('getMessage', | 33 apiFunctions.setHandleRequest('getMessage', |
31 function(messageName, substitutions) { | 34 function(messageName, substitutions) { |
32 return GetL10nMessage(messageName, substitutions, extensionId); | 35 return GetL10nMessage(messageName, substitutions, extensionId); |
33 }); | 36 }); |
34 }); | 37 }); |
| 38 |
| 39 exports.bindings = bindings.generate(); |
OLD | NEW |