| 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 binding for the declarativeWebRequest API. | 5 // Custom binding for the declarativeWebRequest API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('declarativeWebRequest'); | 7 var binding = require('binding').Binding.create('declarativeWebRequest'); |
| 8 | 8 |
| 9 var utils = require('utils'); | 9 var utils = require('utils'); |
| 10 var validate = require('schemaUtils').validate; | 10 var validate = require('schemaUtils').validate; |
| 11 | 11 |
| 12 binding.registerCustomHook(function(api) { | 12 binding.registerCustomHook(function(api) { |
| 13 var declarativeWebRequest = api.compiledApi; | 13 var declarativeWebRequest = api.compiledApi; |
| 14 | 14 |
| 15 // Returns the schema definition of type |typeId| defined in |namespace|. | 15 // Returns the schema definition of type |typeId| defined in |namespace|. |
| 16 function getSchema(typeId) { | 16 function getSchema(typeId) { |
| 17 return utils.lookup(api.schema.types, | 17 return utils.lookup(api.schema.types, |
| 18 'id', | 18 'id', |
| 19 'declarativeWebRequest.' + typeId); | 19 'declarativeWebRequest.' + typeId); |
| 20 } | 20 } |
| 21 | 21 |
| 22 // Helper function for the constructor of concrete datatypes of the | 22 // Helper function for the constructor of concrete datatypes of the |
| 23 // declarative webRequest API. | 23 // declarative webRequest API. |
| 24 // Makes sure that |this| contains the union of parameters and | 24 // Makes sure that |this| contains the union of parameters and |
| 25 // {'instanceType': 'declarativeWebRequest.' + typeId} and validates the | 25 // {'instanceType': 'declarativeWebRequest.' + typeId} and validates the |
| 26 // generated union dictionary against the schema for |typeId|. | 26 // generated union dictionary against the schema for |typeId|. |
| 27 function setupInstance(instance, parameters, typeId) { | 27 function setupInstance(instance, parameters, typeId) { |
| 28 for (var key in parameters) { | 28 for (var key in parameters) { |
| 29 if (parameters.hasOwnProperty(key)) { | 29 if ($Object.hasOwnProperty(parameters, key)) { |
| 30 instance[key] = parameters[key]; | 30 instance[key] = parameters[key]; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 instance.instanceType = 'declarativeWebRequest.' + typeId; | 33 instance.instanceType = 'declarativeWebRequest.' + typeId; |
| 34 var schema = getSchema(typeId); | 34 var schema = getSchema(typeId); |
| 35 validate([instance], [schema]); | 35 validate([instance], [schema]); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Setup all data types for the declarative webRequest API. | 38 // Setup all data types for the declarative webRequest API. |
| 39 declarativeWebRequest.RequestMatcher = function(parameters) { | 39 declarativeWebRequest.RequestMatcher = function(parameters) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 }; | 87 }; |
| 88 declarativeWebRequest.RemoveResponseCookie = function(parameters) { | 88 declarativeWebRequest.RemoveResponseCookie = function(parameters) { |
| 89 setupInstance(this, parameters, 'RemoveResponseCookie'); | 89 setupInstance(this, parameters, 'RemoveResponseCookie'); |
| 90 }; | 90 }; |
| 91 declarativeWebRequest.SendMessageToExtension = function(parameters) { | 91 declarativeWebRequest.SendMessageToExtension = function(parameters) { |
| 92 setupInstance(this, parameters, 'SendMessageToExtension'); | 92 setupInstance(this, parameters, 'SendMessageToExtension'); |
| 93 }; | 93 }; |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 exports.binding = binding.generate(); | 96 exports.binding = binding.generate(); |
| OLD | NEW |