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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 // info is sent to the callback. | 57 // info is sent to the callback. |
58 WebRequestEvent.prototype.addListener = | 58 WebRequestEvent.prototype.addListener = |
59 function(cb, opt_filter, opt_extraInfo) { | 59 function(cb, opt_filter, opt_extraInfo) { |
60 if (!this.eventOptions_.supportsListeners) | 60 if (!this.eventOptions_.supportsListeners) |
61 throw new Error('This event does not support listeners.'); | 61 throw new Error('This event does not support listeners.'); |
62 var subEventName = GetUniqueSubEventName(this.eventName_); | 62 var subEventName = GetUniqueSubEventName(this.eventName_); |
63 // Note: this could fail to validate, in which case we would not add the | 63 // Note: this could fail to validate, in which case we would not add the |
64 // subEvent listener. | 64 // subEvent listener. |
65 chromeHidden.validate(Array.prototype.slice.call(arguments, 1), | 65 chromeHidden.validate(Array.prototype.slice.call(arguments, 1), |
66 this.extraArgSchemas_); | 66 this.extraArgSchemas_); |
67 chrome.webRequest.addEventListener( | 67 chromeHidden.internalAPIs.webRequestInternal.addEventListener( |
68 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); | 68 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); |
69 | 69 |
70 var subEvent = new chrome.Event(subEventName, this.argSchemas_); | 70 var subEvent = new chrome.Event(subEventName, this.argSchemas_); |
71 var subEventCallback = cb; | 71 var subEventCallback = cb; |
72 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { | 72 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { |
73 var eventName = this.eventName_; | 73 var eventName = this.eventName_; |
74 subEventCallback = function() { | 74 subEventCallback = function() { |
75 var requestId = arguments[0].requestId; | 75 var requestId = arguments[0].requestId; |
76 try { | 76 try { |
77 var result = cb.apply(null, arguments); | 77 var result = cb.apply(null, arguments); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 if (!this.eventOptions_.supportsRules) | 145 if (!this.eventOptions_.supportsRules) |
146 throw new Error('This event does not support rules.'); | 146 throw new Error('This event does not support rules.'); |
147 this.eventForRules_.getRules(ruleIdentifiers, cb); | 147 this.eventForRules_.getRules(ruleIdentifiers, cb); |
148 } | 148 } |
149 | 149 |
150 chromeHidden.registerCustomEvent('webRequest', WebRequestEvent); | 150 chromeHidden.registerCustomEvent('webRequest', WebRequestEvent); |
151 | 151 |
152 chromeHidden.registerCustomHook('webRequest', function(api) { | 152 chromeHidden.registerCustomHook('webRequest', function(api) { |
153 var apiFunctions = api.apiFunctions; | 153 var apiFunctions = api.apiFunctions; |
154 | 154 |
155 apiFunctions.setHandleRequest('addEventListener', function() { | |
156 var args = Array.prototype.slice.call(arguments); | |
157 sendRequest(this.name, args, this.definition.parameters, | |
158 {forIOThread: true}); | |
159 }); | |
160 | |
161 apiFunctions.setHandleRequest('eventHandled', function() { | 155 apiFunctions.setHandleRequest('eventHandled', function() { |
162 var args = Array.prototype.slice.call(arguments); | 156 var args = Array.prototype.slice.call(arguments); |
163 sendRequest(this.name, args, this.definition.parameters, | 157 sendRequest(this.name, args, this.definition.parameters, |
164 {forIOThread: true}); | 158 {forIOThread: true}); |
165 }); | 159 }); |
166 | 160 |
167 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 161 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
168 var args = Array.prototype.slice.call(arguments); | 162 var args = Array.prototype.slice.call(arguments); |
169 sendRequest(this.name, args, this.definition.parameters, | 163 sendRequest(this.name, args, this.definition.parameters, |
170 {forIOThread: true}); | 164 {forIOThread: true}); |
165 }); | |
166 }); | |
167 | |
168 chromeHidden.registerCustomHook('webRequestInternal', function(api) { | |
battre
2012/05/15 09:23:38
I think this should go into web_request_internal_c
vabr (Chromium)
2012/05/15 11:57:52
Done.
| |
169 var apiFunctions = api.apiFunctions; | |
170 | |
171 apiFunctions.setHandleRequest('addEventListener', function() { | |
172 var args = Array.prototype.slice.call(arguments); | |
173 sendRequest(this.name, args, this.definition.parameters, | |
174 {forIOThread: true}); | |
171 }); | 175 }); |
172 }); | 176 }); |
OLD | NEW |