Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/renderer/resources/extensions/web_request_custom_bindings.js

Issue 10392008: Move declarative API into events API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12
13 // WebRequestEvent object. This is used for special webRequest events with 13 // WebRequestEvent object. This is used for special webRequest events with
14 // extra parameters. Each invocation of addListener creates a new named 14 // extra parameters. Each invocation of addListener creates a new named
15 // sub-event. That sub-event is associated with the extra parameters in the 15 // 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 16 // browser process, so that only it is dispatched when the main event occurs
17 // matching the extra parameters. 17 // matching the extra parameters.
18 // 18 //
19 // Example: 19 // Example:
20 // chrome.webRequest.onBeforeRequest.addListener( 20 // chrome.webRequest.onBeforeRequest.addListener(
21 // callback, {urls: 'http://*.google.com/*'}); 21 // callback, {urls: 'http://*.google.com/*'});
22 // ^ callback will only be called for onBeforeRequests matching the filter. 22 // ^ callback will only be called for onBeforeRequests matching the filter.
23 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas, 23 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas,
24 opt_eventOptions) { 24 opt_eventOptions, opt_eventsSchema) {
25 if (typeof eventName != 'string') 25 if (typeof eventName != 'string')
26 throw new Error('chrome.WebRequestEvent requires an event name.'); 26 throw new Error('chrome.WebRequestEvent requires an event name.');
27 27
28 this.eventName_ = eventName; 28 this.eventName_ = eventName;
29 this.argSchemas_ = opt_argSchemas; 29 this.argSchemas_ = opt_argSchemas;
30 this.extraArgSchemas_ = opt_extraArgSchemas; 30 this.extraArgSchemas_ = opt_extraArgSchemas;
31 this.subEvents_ = []; 31 this.subEvents_ = [];
32 this.eventOptions_ = opt_eventOptions || 32 this.eventOptions_ = opt_eventOptions ||
33 {'supportsListeners': true, 'supportsRules': false}; 33 {'supportsListeners': true, 'supportsRules': false};
34 34
35 if (this.eventOptions_.supportsRules) 35 if (this.eventOptions_.supportsRules) {
36 this.eventForRules_ = 36 this.eventForRules_ =
37 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions); 37 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions,
38 opt_eventsSchema);
not at google - send to devlin 2012/05/10 09:01:25 nit: 1 line or vertical arguments (I can see that
39 }
38 }; 40 };
39 41
40 // Test if the given callback is registered for this event. 42 // Test if the given callback is registered for this event.
41 WebRequestEvent.prototype.hasListener = function(cb) { 43 WebRequestEvent.prototype.hasListener = function(cb) {
42 if (!this.eventOptions_.supportsListeners) 44 if (!this.eventOptions_.supportsListeners)
43 throw new Error('This event does not support listeners.'); 45 throw new Error('This event does not support listeners.');
44 return this.findListener_(cb) > -1; 46 return this.findListener_(cb) > -1;
45 }; 47 };
46 48
47 // Test if any callbacks are registered fur thus event. 49 // Test if any callbacks are registered fur thus event.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 sendRequest(this.name, args, this.definition.parameters, 165 sendRequest(this.name, args, this.definition.parameters,
164 {forIOThread: true}); 166 {forIOThread: true});
165 }); 167 });
166 168
167 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { 169 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() {
168 var args = Array.prototype.slice.call(arguments); 170 var args = Array.prototype.slice.call(arguments);
169 sendRequest(this.name, args, this.definition.parameters, 171 sendRequest(this.name, args, this.definition.parameters,
170 {forIOThread: true}); 172 {forIOThread: true});
171 }); 173 });
172 }); 174 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698