| 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 webRequest API. | 5 // Custom bindings for the webRequest API. |
| 6 | 6 |
| 7 var Bindings = require('schema_binding_generator').Bindings; |
| 8 var bindings = new Bindings('webRequest'); |
| 9 |
| 7 var webRequestNatives = requireNative('web_request'); | 10 var webRequestNatives = requireNative('web_request'); |
| 8 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; | 11 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; |
| 9 | 12 |
| 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 13 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 11 var sendRequest = require('sendRequest').sendRequest; | 14 var sendRequest = require('sendRequest').sendRequest; |
| 12 var validate = require('schemaUtils').validate; | 15 var validate = require('schemaUtils').validate; |
| 13 | 16 |
| 14 // WebRequestEvent object. This is used for special webRequest events with | 17 // WebRequestEvent object. This is used for special webRequest events with |
| 15 // extra parameters. Each invocation of addListener creates a new named | 18 // extra parameters. Each invocation of addListener creates a new named |
| 16 // sub-event. That sub-event is associated with the extra parameters in the | 19 // sub-event. That sub-event is associated with the extra parameters in the |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 throw new Error('This event does not support rules.'); | 142 throw new Error('This event does not support rules.'); |
| 140 this.eventForRules_.removeRules(ruleIdentifiers, opt_cb); | 143 this.eventForRules_.removeRules(ruleIdentifiers, opt_cb); |
| 141 } | 144 } |
| 142 | 145 |
| 143 WebRequestEvent.prototype.getRules = function(ruleIdentifiers, cb) { | 146 WebRequestEvent.prototype.getRules = function(ruleIdentifiers, cb) { |
| 144 if (!this.eventOptions_.supportsRules) | 147 if (!this.eventOptions_.supportsRules) |
| 145 throw new Error('This event does not support rules.'); | 148 throw new Error('This event does not support rules.'); |
| 146 this.eventForRules_.getRules(ruleIdentifiers, cb); | 149 this.eventForRules_.getRules(ruleIdentifiers, cb); |
| 147 } | 150 } |
| 148 | 151 |
| 149 chromeHidden.registerCustomEvent('webRequest', WebRequestEvent); | 152 bindings.registerCustomEvent(WebRequestEvent); |
| 150 | 153 |
| 151 chromeHidden.registerCustomHook('webRequest', function(api) { | 154 bindings.registerCustomHook(function(api) { |
| 152 var apiFunctions = api.apiFunctions; | 155 var apiFunctions = api.apiFunctions; |
| 153 | 156 |
| 154 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 157 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
| 155 var args = Array.prototype.slice.call(arguments); | 158 var args = Array.prototype.slice.call(arguments); |
| 156 sendRequest(this.name, args, this.definition.parameters, | 159 sendRequest(this.name, args, this.definition.parameters, |
| 157 {forIOThread: true}); | 160 {forIOThread: true}); |
| 158 }); | 161 }); |
| 159 }); | 162 }); |
| 163 |
| 164 // TODO(cduvall): Make sure this is right. |
| 165 if (!('webRequestInternal' in chromeHidden.internalAPIs)) |
| 166 require('webRequestInternal'); |
| 167 |
| 168 exports.bindings = bindings.generate(); |
| OLD | NEW |