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 12 matching lines...) Expand all Loading... |
23 // ^ callback will only be called for onBeforeRequests matching the filter. | 23 // ^ callback will only be called for onBeforeRequests matching the filter. |
24 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas, | 24 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas, |
25 opt_eventOptions) { | 25 opt_eventOptions) { |
26 if (typeof eventName != 'string') | 26 if (typeof eventName != 'string') |
27 throw new Error('chrome.WebRequestEvent requires an event name.'); | 27 throw new Error('chrome.WebRequestEvent requires an event name.'); |
28 | 28 |
29 this.eventName_ = eventName; | 29 this.eventName_ = eventName; |
30 this.argSchemas_ = opt_argSchemas; | 30 this.argSchemas_ = opt_argSchemas; |
31 this.extraArgSchemas_ = opt_extraArgSchemas; | 31 this.extraArgSchemas_ = opt_extraArgSchemas; |
32 this.subEvents_ = []; | 32 this.subEvents_ = []; |
33 this.eventOptions_ = opt_eventOptions || | 33 this.eventOptions_ = chromeHidden.parseEventOptions(opt_eventOptions); |
34 {'supportsListeners': true, 'supportsRules': false}; | |
35 | |
36 if (this.eventOptions_.supportsRules) { | 34 if (this.eventOptions_.supportsRules) { |
37 this.eventForRules_ = | 35 this.eventForRules_ = |
38 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions); | 36 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions); |
39 } | 37 } |
40 }; | 38 }; |
41 | 39 |
42 // Test if the given callback is registered for this event. | 40 // Test if the given callback is registered for this event. |
43 WebRequestEvent.prototype.hasListener = function(cb) { | 41 WebRequestEvent.prototype.hasListener = function(cb) { |
44 if (!this.eventOptions_.supportsListeners) | 42 if (!this.eventOptions_.supportsListeners) |
45 throw new Error('This event does not support listeners.'); | 43 throw new Error('This event does not support listeners.'); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 150 |
153 chromeHidden.registerCustomHook('webRequest', function(api) { | 151 chromeHidden.registerCustomHook('webRequest', function(api) { |
154 var apiFunctions = api.apiFunctions; | 152 var apiFunctions = api.apiFunctions; |
155 | 153 |
156 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 154 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
157 var args = Array.prototype.slice.call(arguments); | 155 var args = Array.prototype.slice.call(arguments); |
158 sendRequest(this.name, args, this.definition.parameters, | 156 sendRequest(this.name, args, this.definition.parameters, |
159 {forIOThread: true}); | 157 {forIOThread: true}); |
160 }); | 158 }); |
161 }); | 159 }); |
OLD | NEW |