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

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

Issue 12632004: Revert 186643 - Caused a 10% regression on SunSpider benchmark (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 binding for the webRequest API. 5 // Custom bindings for the webRequest API.
6
7 var binding = require('binding').Binding.create('webRequest');
8 6
9 var webRequestNatives = requireNative('web_request'); 7 var webRequestNatives = requireNative('web_request');
10 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName; 8 var GetUniqueSubEventName = webRequestNatives.GetUniqueSubEventName;
11 9
12 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
13 var sendRequest = require('sendRequest').sendRequest; 11 var sendRequest = require('sendRequest').sendRequest;
14 var validate = require('schemaUtils').validate; 12 var validate = require('schemaUtils').validate;
15 var webRequestInternal = require('webRequestInternal').binding;
16 13
17 // WebRequestEvent object. This is used for special webRequest events with 14 // WebRequestEvent object. This is used for special webRequest events with
18 // extra parameters. Each invocation of addListener creates a new named 15 // extra parameters. Each invocation of addListener creates a new named
19 // 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
20 // 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
21 // matching the extra parameters. 18 // matching the extra parameters.
22 // 19 //
23 // Example: 20 // Example:
24 // chrome.webRequest.onBeforeRequest.addListener( 21 // chrome.webRequest.onBeforeRequest.addListener(
25 // callback, {urls: 'http://*.google.com/*'}); 22 // callback, {urls: 'http://*.google.com/*'});
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 function(cb, opt_filter, opt_extraInfo) { 59 function(cb, opt_filter, opt_extraInfo) {
63 if (!this.eventOptions_.supportsListeners) 60 if (!this.eventOptions_.supportsListeners)
64 throw new Error('This event does not support listeners.'); 61 throw new Error('This event does not support listeners.');
65 // NOTE(benjhayden) New APIs should not use this subEventName trick! It does 62 // NOTE(benjhayden) New APIs should not use this subEventName trick! It does
66 // not play well with event pages. See downloads.onDeterminingFilename and 63 // not play well with event pages. See downloads.onDeterminingFilename and
67 // ExtensionDownloadsEventRouter for an alternative approach. 64 // ExtensionDownloadsEventRouter for an alternative approach.
68 var subEventName = GetUniqueSubEventName(this.eventName_); 65 var subEventName = GetUniqueSubEventName(this.eventName_);
69 // Note: this could fail to validate, in which case we would not add the 66 // Note: this could fail to validate, in which case we would not add the
70 // subEvent listener. 67 // subEvent listener.
71 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_); 68 validate(Array.prototype.slice.call(arguments, 1), this.extraArgSchemas_);
72 webRequestInternal.addEventListener( 69 chromeHidden.internalAPIs.webRequestInternal.addEventListener(
73 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName); 70 cb, opt_filter, opt_extraInfo, this.eventName_, subEventName);
74 71
75 var subEvent = new chrome.Event(subEventName, this.argSchemas_); 72 var subEvent = new chrome.Event(subEventName, this.argSchemas_);
76 var subEventCallback = cb; 73 var subEventCallback = cb;
77 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) { 74 if (opt_extraInfo && opt_extraInfo.indexOf('blocking') >= 0) {
78 var eventName = this.eventName_; 75 var eventName = this.eventName_;
79 subEventCallback = function() { 76 subEventCallback = function() {
80 var requestId = arguments[0].requestId; 77 var requestId = arguments[0].requestId;
81 try { 78 try {
82 var result = cb.apply(null, arguments); 79 var result = cb.apply(null, arguments);
83 webRequestInternal.eventHandled( 80 chromeHidden.internalAPIs.webRequestInternal.eventHandled(
84 eventName, subEventName, requestId, result); 81 eventName, subEventName, requestId, result);
85 } catch (e) { 82 } catch (e) {
86 webRequestInternal.eventHandled( 83 chromeHidden.internalAPIs.webRequestInternal.eventHandled(
87 eventName, subEventName, requestId); 84 eventName, subEventName, requestId);
88 throw e; 85 throw e;
89 } 86 }
90 }; 87 };
91 } else if (opt_extraInfo && opt_extraInfo.indexOf('asyncBlocking') >= 0) { 88 } else if (opt_extraInfo && opt_extraInfo.indexOf('asyncBlocking') >= 0) {
92 var eventName = this.eventName_; 89 var eventName = this.eventName_;
93 subEventCallback = function() { 90 subEventCallback = function() {
94 var details = arguments[0]; 91 var details = arguments[0];
95 var requestId = details.requestId; 92 var requestId = details.requestId;
96 var handledCallback = function(response) { 93 var handledCallback = function(response) {
97 webRequestInternal.eventHandled( 94 chromeHidden.internalAPIs.webRequestInternal.eventHandled(
98 eventName, subEventName, requestId, response); 95 eventName, subEventName, requestId, response);
99 }; 96 };
100 cb.apply(null, [details, handledCallback]); 97 cb.apply(null, [details, handledCallback]);
101 }; 98 };
102 } 99 }
103 this.subEvents_.push( 100 this.subEvents_.push(
104 {subEvent: subEvent, callback: cb, subEventCallback: subEventCallback}); 101 {subEvent: subEvent, callback: cb, subEventCallback: subEventCallback});
105 subEvent.addListener(subEventCallback); 102 subEvent.addListener(subEventCallback);
106 }; 103 };
107 104
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 throw new Error('This event does not support rules.'); 142 throw new Error('This event does not support rules.');
146 this.eventForRules_.removeRules(ruleIdentifiers, opt_cb); 143 this.eventForRules_.removeRules(ruleIdentifiers, opt_cb);
147 } 144 }
148 145
149 WebRequestEvent.prototype.getRules = function(ruleIdentifiers, cb) { 146 WebRequestEvent.prototype.getRules = function(ruleIdentifiers, cb) {
150 if (!this.eventOptions_.supportsRules) 147 if (!this.eventOptions_.supportsRules)
151 throw new Error('This event does not support rules.'); 148 throw new Error('This event does not support rules.');
152 this.eventForRules_.getRules(ruleIdentifiers, cb); 149 this.eventForRules_.getRules(ruleIdentifiers, cb);
153 } 150 }
154 151
155 binding.registerCustomEvent(WebRequestEvent); 152 chromeHidden.registerCustomEvent('webRequest', WebRequestEvent);
156 153
157 binding.registerCustomHook(function(api) { 154 chromeHidden.registerCustomHook('webRequest', function(api) {
158 var apiFunctions = api.apiFunctions; 155 var apiFunctions = api.apiFunctions;
159 156
160 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() { 157 apiFunctions.setHandleRequest('handlerBehaviorChanged', function() {
161 var args = Array.prototype.slice.call(arguments); 158 var args = Array.prototype.slice.call(arguments);
162 sendRequest(this.name, args, this.definition.parameters, 159 sendRequest(this.name, args, this.definition.parameters,
163 {forIOThread: true}); 160 {forIOThread: true});
164 }); 161 });
165 }); 162 });
166
167 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698