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

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

Issue 12189018: <webview>: Implement WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Support all events Created 7 years, 10 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 var validate = require('schemaUtils').validate; 12 var validate = require('schemaUtils').validate;
13 13
14 // WebRequestEvent object. This is used for special webRequest events with 14 // WebRequestEvent object. This is used for special webRequest events with
15 // extra parameters. Each invocation of addListener creates a new named 15 // extra parameters. Each invocation of addListener creates a new named
16 // 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
17 // 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
18 // matching the extra parameters. 18 // matching the extra parameters.
19 // 19 //
20 // Example: 20 // Example:
21 // chrome.webRequest.onBeforeRequest.addListener( 21 // chrome.webRequest.onBeforeRequest.addListener(
22 // callback, {urls: 'http://*.google.com/*'}); 22 // callback, {urls: 'http://*.google.com/*'});
23 // ^ callback will only be called for onBeforeRequests matching the filter. 23 // ^ callback will only be called for onBeforeRequests matching the filter.
24 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas, 24 function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas,
25 opt_eventOptions) { 25 opt_eventOptions, opt_processId, opt_routeId) {
26 if (typeof eventName != 'string') 26 if (typeof eventName != 'string')
27 throw new Error('chrome.WebRequestEvent requires an event name.'); 27 throw new Error('chrome.WebRequestEvent requires an event name.');
28 28
29 this.eventName_ = eventName; 29 this.eventName_ = eventName;
30 this.argSchemas_ = opt_argSchemas; 30 this.argSchemas_ = opt_argSchemas;
31 this.extraArgSchemas_ = opt_extraArgSchemas; 31 this.extraArgSchemas_ = opt_extraArgSchemas;
32 this.processId_ = opt_processId ? opt_processId : -1;
33 this.routeId_ = opt_routeId ? opt_routeId : -1;
32 this.subEvents_ = []; 34 this.subEvents_ = [];
33 this.eventOptions_ = chromeHidden.parseEventOptions(opt_eventOptions); 35 this.eventOptions_ = chromeHidden.parseEventOptions(opt_eventOptions);
34 if (this.eventOptions_.supportsRules) { 36 if (this.eventOptions_.supportsRules) {
35 this.eventForRules_ = 37 this.eventForRules_ =
36 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions); 38 new chrome.Event(eventName, opt_argSchemas, opt_eventOptions);
37 } 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) {
(...skipping 15 matching lines...) Expand all
57 // info is sent to the callback. 59 // info is sent to the callback.
58 WebRequestEvent.prototype.addListener = 60 WebRequestEvent.prototype.addListener =
59 function(cb, opt_filter, opt_extraInfo) { 61 function(cb, opt_filter, opt_extraInfo) {
60 if (!this.eventOptions_.supportsListeners) 62 if (!this.eventOptions_.supportsListeners)
61 throw new Error('This event does not support listeners.'); 63 throw new Error('This event does not support listeners.');
62 var subEventName = GetUniqueSubEventName(this.eventName_); 64 var subEventName = GetUniqueSubEventName(this.eventName_);
63 // 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
64 // subEvent listener. 66 // subEvent listener.
65 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_); 67 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_);
66 chromeHidden.internalAPIs.webRequestInternal.addEventListener( 68 chromeHidden.internalAPIs.webRequestInternal.addEventListener(
67 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); 69 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName,
70 this.processId_, this.routeId_);
68 71
69 var subEvent = new chrome.Event(subEventName, this.argSchemas_); 72 var subEvent = new chrome.Event(subEventName, this.argSchemas_);
70 var subEventCallback = cb; 73 var subEventCallback = cb;
71 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { 74 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) {
72 var eventName = this.eventName_; 75 var eventName = this.eventName_;
73 subEventCallback = function() { 76 subEventCallback = function() {
74 var requestId = arguments[0].requestId; 77 var requestId = arguments[0].requestId;
75 try { 78 try {
76 var result = cb.apply(null, arguments); 79 var result = cb.apply(null, arguments);
77 chromeHidden.internalAPIs.webRequestInternal.eventHandled( 80 chromeHidden.internalAPIs.webRequestInternal.eventHandled(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 153
151 chromeHidden.registerCustomHook('webRequest', function(api) { 154 chromeHidden.registerCustomHook('webRequest', function(api) {
152 var apiFunctions = api.apiFunctions; 155 var apiFunctions = api.apiFunctions;
153 156
154 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { 157 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() {
155 var args = Array.prototype.slice.call(arguments); 158 var args = Array.prototype.slice.call(arguments);
156 sendRequest(this.name, args, this.definition.parameters, 159 sendRequest(this.name, args, this.definition.parameters,
157 {forIOThread: true}); 160 {forIOThread: true});
158 }); 161 });
159 }); 162 });
163
164 exports.webRequestEvent = WebRequestEvent;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698