| 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); |
| 78 chrome.webRequest.eventHandled( | 78 chromeHidden.internalAPIs.webRequestInternal.eventHandled( |
| 79 eventName, subEventName, requestId, result); | 79 eventName, subEventName, requestId, result); |
| 80 } catch (e) { | 80 } catch (e) { |
| 81 chrome.webRequest.eventHandled( | 81 chromeHidden.internalAPIs.webRequestInternal.eventHandled( |
| 82 eventName, subEventName, requestId); | 82 eventName, subEventName, requestId); |
| 83 throw e; | 83 throw e; |
| 84 } | 84 } |
| 85 }; | 85 }; |
| 86 } else if (opt_extraInfo && opt_extraInfo.indexOf('asyncBlocking') >= 0) { | 86 } else if (opt_extraInfo && opt_extraInfo.indexOf('asyncBlocking') >= 0) { |
| 87 var eventName = this.eventName_; | 87 var eventName = this.eventName_; |
| 88 subEventCallback = function() { | 88 subEventCallback = function() { |
| 89 var details = arguments[0]; | 89 var details = arguments[0]; |
| 90 var requestId = details.requestId; | 90 var requestId = details.requestId; |
| 91 var handledCallback = function(response) { | 91 var handledCallback = function(response) { |
| 92 chrome.webRequest.eventHandled( | 92 chromeHidden.internalAPIs.webRequestInternal.eventHandled( |
| 93 eventName, subEventName, requestId, response); | 93 eventName, subEventName, requestId, response); |
| 94 }; | 94 }; |
| 95 cb.apply(null, [details, handledCallback]); | 95 cb.apply(null, [details, handledCallback]); |
| 96 }; | 96 }; |
| 97 } | 97 } |
| 98 this.subEvents_.push( | 98 this.subEvents_.push( |
| 99 {subEvent: subEvent, callback: cb, subEventCallback: subEventCallback}); | 99 {subEvent: subEvent, callback: cb, subEventCallback: subEventCallback}); |
| 100 subEvent.addListener(subEventCallback); | 100 subEvent.addListener(subEventCallback); |
| 101 }; | 101 }; |
| 102 | 102 |
| (...skipping 42 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() { | |
| 162 var args = Array.prototype.slice.call(arguments); | |
| 163 sendRequest(this.name, args, this.definition.parameters, | |
| 164 {forIOThread: true}); | |
| 165 }); | |
| 166 | |
| 167 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 155 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
| 168 var args = Array.prototype.slice.call(arguments); | 156 var args = Array.prototype.slice.call(arguments); |
| 169 sendRequest(this.name, args, this.definition.parameters, | 157 sendRequest(this.name, args, this.definition.parameters, |
| 170 {forIOThread: true}); | 158 {forIOThread: true}); |
| 171 }); | 159 }); |
| 172 }); | 160 }); |
| OLD | NEW |