| 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(); |
| 11 var sendRequest = require('sendRequest').sendRequest; | 11 var sendRequest = require('sendRequest').sendRequest; |
| 12 var validate = require('schemaUtils').validate; |
| 12 | 13 |
| 13 // WebRequestEvent object. This is used for special webRequest events with | 14 // WebRequestEvent object. This is used for special webRequest events with |
| 14 // extra parameters. Each invocation of addListener creates a new named | 15 // extra parameters. Each invocation of addListener creates a new named |
| 15 // sub-event. That sub-event is associated with the extra parameters in the | 16 // sub-event. That sub-event is associated with the extra parameters in the |
| 16 // browser process, so that only it is dispatched when the main event occurs | 17 // browser process, so that only it is dispatched when the main event occurs |
| 17 // matching the extra parameters. | 18 // matching the extra parameters. |
| 18 // | 19 // |
| 19 // Example: | 20 // Example: |
| 20 // chrome.webRequest.onBeforeRequest.addListener( | 21 // chrome.webRequest.onBeforeRequest.addListener( |
| 21 // callback, {urls: 'http://*.google.com/*'}); | 22 // callback, {urls: 'http://*.google.com/*'}); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // opt_filter is specified, then the callback is only called for events that | 57 // opt_filter is specified, then the callback is only called for events that |
| 57 // match the given filters. If opt_extraInfo is specified, the given optional | 58 // match the given filters. If opt_extraInfo is specified, the given optional |
| 58 // info is sent to the callback. | 59 // info is sent to the callback. |
| 59 WebRequestEvent.prototype.addListener = | 60 WebRequestEvent.prototype.addListener = |
| 60 function(cb, opt_filter, opt_extraInfo) { | 61 function(cb, opt_filter, opt_extraInfo) { |
| 61 if (!this.eventOptions_.supportsListeners) | 62 if (!this.eventOptions_.supportsListeners) |
| 62 throw new Error('This event does not support listeners.'); | 63 throw new Error('This event does not support listeners.'); |
| 63 var subEventName = GetUniqueSubEventName(this.eventName_); | 64 var subEventName = GetUniqueSubEventName(this.eventName_); |
| 64 // Note: this could fail to validate, in which case we would not add the | 65 // Note: this could fail to validate, in which case we would not add the |
| 65 // subEvent listener. | 66 // subEvent listener. |
| 66 chromeHidden.validate(Array.prototype.slice.call(arguments, 1), | 67 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_); |
| 67 this.extraArgSchemas_); | |
| 68 chromeHidden.internalAPIs.webRequestInternal.addEventListener( | 68 chromeHidden.internalAPIs.webRequestInternal.addEventListener( |
| 69 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); | 69 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); |
| 70 | 70 |
| 71 var subEvent = new chrome.Event(subEventName, this.argSchemas_); | 71 var subEvent = new chrome.Event(subEventName, this.argSchemas_); |
| 72 var subEventCallback = cb; | 72 var subEventCallback = cb; |
| 73 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { | 73 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { |
| 74 var eventName = this.eventName_; | 74 var eventName = this.eventName_; |
| 75 subEventCallback = function() { | 75 subEventCallback = function() { |
| 76 var requestId = arguments[0].requestId; | 76 var requestId = arguments[0].requestId; |
| 77 try { | 77 try { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 chromeHidden.registerCustomHook('webRequest', function(api) { | 153 chromeHidden.registerCustomHook('webRequest', function(api) { |
| 154 var apiFunctions = api.apiFunctions; | 154 var apiFunctions = api.apiFunctions; |
| 155 | 155 |
| 156 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { | 156 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { |
| 157 var args = Array.prototype.slice.call(arguments); | 157 var args = Array.prototype.slice.call(arguments); |
| 158 sendRequest(this.name, args, this.definition.parameters, | 158 sendRequest(this.name, args, this.definition.parameters, |
| 159 {forIOThread: true}); | 159 {forIOThread: true}); |
| 160 }); | 160 }); |
| 161 }); | 161 }); |
| OLD | NEW |