| 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 webRequestInternal API. | 5 // Custom binding for the webRequestInternal API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('webRequestInternal'); | 7 var binding = require('binding').Binding.create('webRequestInternal'); |
| 8 var eventBindings = require('event_bindings'); | 8 var eventBindings = require('event_bindings'); |
| 9 var sendRequest = require('sendRequest').sendRequest; | 9 var sendRequest = require('sendRequest').sendRequest; |
| 10 var validate = require('schemaUtils').validate; | 10 var validate = require('schemaUtils').validate; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // callback, {urls: 'http://*.google.com/*'}); | 27 // callback, {urls: 'http://*.google.com/*'}); |
| 28 // ^ callback will only be called for onBeforeRequests matching the filter. | 28 // ^ callback will only be called for onBeforeRequests matching the filter. |
| 29 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas, | 29 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas, |
| 30 opt_eventOptions, opt_webViewInstanceId) { | 30 opt_eventOptions, opt_webViewInstanceId) { |
| 31 if (typeof eventName != 'string') | 31 if (typeof eventName != 'string') |
| 32 throw new Error('chrome.WebRequestEvent requires an event name.'); | 32 throw new Error('chrome.WebRequestEvent requires an event name.'); |
| 33 | 33 |
| 34 this.eventName_ = eventName; | 34 this.eventName_ = eventName; |
| 35 this.argSchemas_ = opt_argSchemas; | 35 this.argSchemas_ = opt_argSchemas; |
| 36 this.extraArgSchemas_ = opt_extraArgSchemas; | 36 this.extraArgSchemas_ = opt_extraArgSchemas; |
| 37 this.webViewInstanceId_ = opt_webViewInstanceId ? opt_webViewInstanceId : 0; | 37 this.webViewInstanceId_ = opt_webViewInstanceId || 0; |
| 38 this.subEvents_ = []; | 38 this.subEvents_ = []; |
| 39 this.eventOptions_ = eventBindings.parseEventOptions(opt_eventOptions); | 39 this.eventOptions_ = eventBindings.parseEventOptions(opt_eventOptions); |
| 40 if (this.eventOptions_.supportsRules) { | 40 if (this.eventOptions_.supportsRules) { |
| 41 this.eventForRules_ = | 41 this.eventForRules_ = |
| 42 new eventBindings.Event(eventName, opt_argSchemas, opt_eventOptions); | 42 new eventBindings.Event(eventName, opt_argSchemas, opt_eventOptions, |
| 43 opt_webViewInstanceId); |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Test if the given callback is registered for this event. | 47 // Test if the given callback is registered for this event. |
| 47 WebRequestEvent.prototype.hasListener = function(cb) { | 48 WebRequestEvent.prototype.hasListener = function(cb) { |
| 48 if (!this.eventOptions_.supportsListeners) | 49 if (!this.eventOptions_.supportsListeners) |
| 49 throw new Error('This event does not support listeners.'); | 50 throw new Error('This event does not support listeners.'); |
| 50 return this.findListener_(cb) > -1; | 51 return this.findListener_(cb) > -1; |
| 51 }; | 52 }; |
| 52 | 53 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 apiFunctions.setHandleRequest('eventHandled', function() { | 169 apiFunctions.setHandleRequest('eventHandled', function() { |
| 169 var args = $Array.slice(arguments); | 170 var args = $Array.slice(arguments); |
| 170 sendRequest(this.name, args, this.definition.parameters, | 171 sendRequest(this.name, args, this.definition.parameters, |
| 171 {forIOThread: true}); | 172 {forIOThread: true}); |
| 172 }); | 173 }); |
| 173 }); | 174 }); |
| 174 | 175 |
| 175 webRequestInternal = binding.generate(); | 176 webRequestInternal = binding.generate(); |
| 176 exports.binding = webRequestInternal; | 177 exports.binding = webRequestInternal; |
| 177 exports.WebRequestEvent = WebRequestEvent; | 178 exports.WebRequestEvent = WebRequestEvent; |
| OLD | NEW |