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 declarativeContent API. | 5 // Custom binding for the declarativeContent API. |
6 | 6 |
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 7 var binding = require('binding').Binding.create('declarativeContent'); |
| 8 |
8 var utils = require('utils'); | 9 var utils = require('utils'); |
9 var validate = require('schemaUtils').validate; | 10 var validate = require('schemaUtils').validate; |
10 | 11 |
11 chromeHidden.registerCustomHook('declarativeContent', function(api) { | 12 binding.registerCustomHook( function(api) { |
| 13 var declarativeContent = api.compiledApi; |
| 14 |
12 // Returns the schema definition of type |typeId| defined in |namespace|. | 15 // Returns the schema definition of type |typeId| defined in |namespace|. |
13 function getSchema(namespace, typeId) { | 16 function getSchema(typeId) { |
14 var apiSchema = utils.lookup(api.apiDefinitions, 'namespace', namespace); | 17 return utils.lookup(api.schema.types, |
15 var resultSchema = utils.lookup( | 18 'id', |
16 apiSchema.types, 'id', namespace + '.' + typeId); | 19 'declarativeContent.' + typeId); |
17 return resultSchema; | |
18 } | 20 } |
19 | 21 |
20 // Helper function for the constructor of concrete datatypes of the | 22 // Helper function for the constructor of concrete datatypes of the |
21 // declarative content API. | 23 // declarative content API. |
22 // Makes sure that |this| contains the union of parameters and | 24 // Makes sure that |this| contains the union of parameters and |
23 // {'instanceType': 'declarativeContent.' + typeId} and validates the | 25 // {'instanceType': 'declarativeContent.' + typeId} and validates the |
24 // generated union dictionary against the schema for |typeId|. | 26 // generated union dictionary against the schema for |typeId|. |
25 function setupInstance(instance, parameters, typeId) { | 27 function setupInstance(instance, parameters, typeId) { |
26 for (var key in parameters) { | 28 for (var key in parameters) { |
27 if (parameters.hasOwnProperty(key)) { | 29 if (parameters.hasOwnProperty(key)) { |
28 instance[key] = parameters[key]; | 30 instance[key] = parameters[key]; |
29 } | 31 } |
30 } | 32 } |
31 instance.instanceType = 'declarativeContent.' + typeId; | 33 instance.instanceType = 'declarativeContent.' + typeId; |
32 var schema = getSchema('declarativeContent', typeId); | 34 var schema = getSchema(typeId); |
33 validate([instance], [schema]); | 35 validate([instance], [schema]); |
34 } | 36 } |
35 | 37 |
36 // Setup all data types for the declarative content API. | 38 // Setup all data types for the declarative content API. |
37 chrome.declarativeContent.PageStateMatcher = function(parameters) { | 39 declarativeContent.PageStateMatcher = function(parameters) { |
38 setupInstance(this, parameters, 'PageStateMatcher'); | 40 setupInstance(this, parameters, 'PageStateMatcher'); |
39 }; | 41 }; |
40 chrome.declarativeContent.ShowPageAction = function(parameters) { | 42 declarativeContent.ShowPageAction = function(parameters) { |
41 setupInstance(this, parameters, 'ShowPageAction'); | 43 setupInstance(this, parameters, 'ShowPageAction'); |
42 }; | 44 }; |
43 }); | 45 }); |
| 46 |
| 47 exports.binding = binding.generate(); |
OLD | NEW |