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