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 webRequestNatives = requireNative('web_request'); | 7 var webRequestNatives = requireNative('web_request'); |
8 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; | 8 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; |
9 | 9 |
10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
(...skipping 14 matching lines...) Expand all Loading... |
25 if (typeof eventName != 'string') | 25 if (typeof eventName != 'string') |
26 throw new Error('chrome.WebRequestEvent requires an event name.'); | 26 throw new Error('chrome.WebRequestEvent requires an event name.'); |
27 | 27 |
28 this.eventName_ = eventName; | 28 this.eventName_ = eventName; |
29 this.argSchemas_ = opt_argSchemas; | 29 this.argSchemas_ = opt_argSchemas; |
30 this.extraArgSchemas_ = opt_extraArgSchemas; | 30 this.extraArgSchemas_ = opt_extraArgSchemas; |
31 this.subEvents_ = []; | 31 this.subEvents_ = []; |
32 this.eventOptions_ = opt_eventOptions || | 32 this.eventOptions_ = opt_eventOptions || |
33 {'supportsListeners': true, 'supportsRules': false}; | 33 {'supportsListeners': true, 'supportsRules': false}; |
34 | 34 |
35 if (this.eventOptions_.supportsRules) | 35 if (this.eventOptions_.supportsRules) { |
36 this.eventForRules_ = | 36 this.eventForRules_ = |
37 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions); | 37 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions); |
| 38 } |
38 }; | 39 }; |
39 | 40 |
40 // Test if the given callback is registered for this event. | 41 // Test if the given callback is registered for this event. |
41 WebRequestEvent.prototype.hasListener = function(cb) { | 42 WebRequestEvent.prototype.hasListener = function(cb) { |
42 if (!this.eventOptions_.supportsListeners) | 43 if (!this.eventOptions_.supportsListeners) |
43 throw new Error('This event does not support listeners.'); | 44 throw new Error('This event does not support listeners.'); |
44 return this.findListener_(cb) > -1; | 45 return this.findListener_(cb) > -1; |
45 }; | 46 }; |
46 | 47 |
47 // Test if any callbacks are registered fur thus event. | 48 // Test if any callbacks are registered fur thus event. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 sendRequest(this.name, args, this.definition.parameters, | 164 sendRequest(this.name, args, this.definition.parameters, |
164 {forIOThread: true}); | 165 {forIOThread: true}); |
165 }); | 166 }); |
166 | 167 |
167 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 168 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
168 var args = Array.prototype.slice.call(arguments); | 169 var args = Array.prototype.slice.call(arguments); |
169 sendRequest(this.name, args, this.definition.parameters, | 170 sendRequest(this.name, args, this.definition.parameters, |
170 {forIOThread: true}); | 171 {forIOThread: true}); |
171 }); | 172 }); |
172 }); | 173 }); |
OLD | NEW |