Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Custom binding for the webViewRequest API. | |
| 6 | |
| 7 var binding = require('binding').Binding.create('webViewRequest'); | |
| 8 | |
| 9 var declarativeWebRequestSchema = | |
| 10 requireNative('schema_registry').GetSchema('declarativeWebRequest'); | |
| 11 var utils = require('utils'); | |
| 12 var validate = require('schemaUtils').validate; | |
| 13 | |
| 14 binding.registerCustomHook(function(api) { | |
| 15 var webViewRequest = api.compiledApi; | |
| 16 | |
| 17 // Returns the schema definition of type |typeId| defined in |namespace|. | |
|
lazyboy
2013/11/04 23:16:01
There's no |namespace| here, you probably mean |de
Fady Samuel
2013/11/05 19:53:01
Done.
| |
| 18 function getSchema(typeId) { | |
| 19 return utils.lookup(declarativeWebRequestSchema.types, | |
| 20 'id', | |
| 21 'declarativeWebRequest.' + typeId); | |
| 22 } | |
| 23 | |
| 24 // Helper function for the constructor of concrete datatypes of the | |
| 25 // declarative webRequest API. | |
| 26 // Makes sure that |this| contains the union of parameters and | |
| 27 // {'instanceType': 'webViewRequest.' + typeId} and validates the | |
|
lazyboy
2013/11/04 23:16:01
s/webViewRequest/declarativeWebRequest
Fady Samuel
2013/11/05 19:53:01
Done.
| |
| 28 // generated union dictionary against the schema for |typeId|. | |
| 29 function setupInstance(instance, parameters, typeId) { | |
| 30 for (var key in parameters) { | |
| 31 if ($Object.hasOwnProperty(parameters, key)) { | |
| 32 instance[key] = parameters[key]; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 instance.instanceType = 'declarativeWebRequest.' + typeId; | |
| 37 var schema = getSchema(typeId); | |
| 38 validate([instance], [schema]); | |
| 39 } | |
| 40 | |
| 41 // Setup all data types for the declarative webRequest API from the schema. | |
| 42 for (var i = 0; i < declarativeWebRequestSchema.types.length; ++i) { | |
| 43 var typeSchema = declarativeWebRequestSchema.types[i]; | |
| 44 var typeId = typeSchema.id.replace('declarativeWebRequest.', ''); | |
| 45 var action = function(typeId) { | |
| 46 return function(parameters) { | |
| 47 setupInstance(this, parameters, typeId); | |
| 48 }; | |
| 49 }(typeId); | |
| 50 webViewRequest[typeId] = action; | |
| 51 } | |
| 52 }); | |
| 53 | |
| 54 exports.binding = binding.generate(); | |
| OLD | NEW |