Chromium Code Reviews| Index: chrome/renderer/resources/extensions/webview_request_custom_bindings.js |
| diff --git a/chrome/renderer/resources/extensions/webview_request_custom_bindings.js b/chrome/renderer/resources/extensions/webview_request_custom_bindings.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3d336e8e795753919d37e90c9289b5b993e3bb5b |
| --- /dev/null |
| +++ b/chrome/renderer/resources/extensions/webview_request_custom_bindings.js |
| @@ -0,0 +1,54 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Custom binding for the webViewRequest API. |
| + |
| +var binding = require('binding').Binding.create('webViewRequest'); |
| + |
| +var declarativeWebRequestSchema = |
| + requireNative('schema_registry').GetSchema('declarativeWebRequest'); |
| +var utils = require('utils'); |
| +var validate = require('schemaUtils').validate; |
| + |
| +binding.registerCustomHook(function(api) { |
| + var webViewRequest = api.compiledApi; |
| + |
| + // 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.
|
| + function getSchema(typeId) { |
| + return utils.lookup(declarativeWebRequestSchema.types, |
| + 'id', |
| + 'declarativeWebRequest.' + typeId); |
| + } |
| + |
| + // Helper function for the constructor of concrete datatypes of the |
| + // declarative webRequest API. |
| + // Makes sure that |this| contains the union of parameters and |
| + // {'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.
|
| + // generated union dictionary against the schema for |typeId|. |
| + function setupInstance(instance, parameters, typeId) { |
| + for (var key in parameters) { |
| + if ($Object.hasOwnProperty(parameters, key)) { |
| + instance[key] = parameters[key]; |
| + } |
| + } |
| + |
| + instance.instanceType = 'declarativeWebRequest.' + typeId; |
| + var schema = getSchema(typeId); |
| + validate([instance], [schema]); |
| + } |
| + |
| + // Setup all data types for the declarative webRequest API from the schema. |
| + for (var i = 0; i < declarativeWebRequestSchema.types.length; ++i) { |
| + var typeSchema = declarativeWebRequestSchema.types[i]; |
| + var typeId = typeSchema.id.replace('declarativeWebRequest.', ''); |
| + var action = function(typeId) { |
| + return function(parameters) { |
| + setupInstance(this, parameters, typeId); |
| + }; |
| + }(typeId); |
| + webViewRequest[typeId] = action; |
| + } |
| +}); |
| + |
| +exports.binding = binding.generate(); |