| 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 webRequest API. | 5 // Custom binding for the webRequest API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('webRequest'); | 7 var binding = require('binding').Binding.create('webRequest'); |
| 8 | 8 |
| 9 var webRequestNatives = requireNative('web_request'); | 9 var webRequestNatives = requireNative('web_request'); |
| 10 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; | 10 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Registers a callback to be called when this event is dispatched. If | 57 // Registers a callback to be called when this event is dispatched. If |
| 58 // opt_filter is specified, then the callback is only called for events that | 58 // opt_filter is specified, then the callback is only called for events that |
| 59 // match the given filters. If opt_extraInfo is specified, the given optional | 59 // match the given filters. If opt_extraInfo is specified, the given optional |
| 60 // info is sent to the callback. | 60 // info is sent to the callback. |
| 61 WebRequestEvent.prototype.addListener = | 61 WebRequestEvent.prototype.addListener = |
| 62 function(cb, opt_filter, opt_extraInfo) { | 62 function(cb, opt_filter, opt_extraInfo) { |
| 63 if (!this.eventOptions_.supportsListeners) | 63 if (!this.eventOptions_.supportsListeners) |
| 64 throw new Error('This event does not support listeners.'); | 64 throw new Error('This event does not support listeners.'); |
| 65 // NOTE(benjhayden) New APIs should not use this subEventName trick! It does |
| 66 // not play well with event pages. See downloads.onDeterminingFilename and |
| 67 // ExtensionDownloadsEventRouter for an alternative approach. |
| 65 var subEventName = GetUniqueSubEventName(this.eventName_); | 68 var subEventName = GetUniqueSubEventName(this.eventName_); |
| 66 // Note: this could fail to validate, in which case we would not add the | 69 // Note: this could fail to validate, in which case we would not add the |
| 67 // subEvent listener. | 70 // subEvent listener. |
| 68 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_); | 71 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_); |
| 69 webRequestInternal.addEventListener( | 72 webRequestInternal.addEventListener( |
| 70 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); | 73 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); |
| 71 | 74 |
| 72 var subEvent = new chrome.Event(subEventName, this.argSchemas_); | 75 var subEvent = new chrome.Event(subEventName, this.argSchemas_); |
| 73 var subEventCallback = cb; | 76 var subEventCallback = cb; |
| 74 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { | 77 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 var apiFunctions = api.apiFunctions; | 158 var apiFunctions = api.apiFunctions; |
| 156 | 159 |
| 157 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 160 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
| 158 var args = Array.prototype.slice.call(arguments); | 161 var args = Array.prototype.slice.call(arguments); |
| 159 sendRequest(this.name, args, this.definition.parameters, | 162 sendRequest(this.name, args, this.definition.parameters, |
| 160 {forIOThread: true}); | 163 {forIOThread: true}); |
| 161 }); | 164 }); |
| 162 }); | 165 }); |
| 163 | 166 |
| 164 exports.binding = binding.generate(); | 167 exports.binding = binding.generate(); |
| OLD | NEW |