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

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

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed browser_tests build Created 7 years, 1 month 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
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 var eventNatives = requireNative('event_natives'); 5 var eventNatives = requireNative('event_natives');
6 var logging = requireNative('logging'); 6 var logging = requireNative('logging');
7 var schemaRegistry = requireNative('schema_registry'); 7 var schemaRegistry = requireNative('schema_registry');
8 var sendRequest = require('sendRequest').sendRequest; 8 var sendRequest = require('sendRequest').sendRequest;
9 var utils = require('utils'); 9 var utils = require('utils');
10 var validate = require('schemaUtils').validate; 10 var validate = require('schemaUtils').validate;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // 180 //
181 // Example: 181 // Example:
182 // var Event = require('event_bindings').Event; 182 // var Event = require('event_bindings').Event;
183 // chrome.tabs.onChanged = new Event("tab-changed"); 183 // chrome.tabs.onChanged = new Event("tab-changed");
184 // chrome.tabs.onChanged.addListener(function(data) { alert(data); }); 184 // chrome.tabs.onChanged.addListener(function(data) { alert(data); });
185 // Event.dispatch("tab-changed", "hi"); 185 // Event.dispatch("tab-changed", "hi");
186 // will result in an alert dialog that says 'hi'. 186 // will result in an alert dialog that says 'hi'.
187 // 187 //
188 // If opt_eventOptions exists, it is a dictionary that contains the boolean 188 // If opt_eventOptions exists, it is a dictionary that contains the boolean
189 // entries "supportsListeners" and "supportsRules". 189 // entries "supportsListeners" and "supportsRules".
190 var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) { 190 var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions,
191 opt_webViewInstanceId) {
Jeffrey Yasskin 2013/11/09 02:47:22 Add a comment for this parameter.
Fady Samuel 2013/11/10 03:39:56 Done.
191 this.eventName_ = opt_eventName; 192 this.eventName_ = opt_eventName;
192 this.argSchemas_ = opt_argSchemas; 193 this.argSchemas_ = opt_argSchemas;
193 this.listeners_ = []; 194 this.listeners_ = [];
194 this.eventOptions_ = parseEventOptions(opt_eventOptions); 195 this.eventOptions_ = parseEventOptions(opt_eventOptions);
196 this.webViewInstanceId_ = opt_webViewInstanceId || 0;
195 197
196 if (!this.eventName_) { 198 if (!this.eventName_) {
197 if (this.eventOptions_.supportsRules) 199 if (this.eventOptions_.supportsRules)
198 throw new Error("Events that support rules require an event name."); 200 throw new Error("Events that support rules require an event name.");
199 // Events without names cannot be managed by the browser by definition 201 // Events without names cannot be managed by the browser by definition
200 // (the browser has no way of identifying them). 202 // (the browser has no way of identifying them).
201 this.eventOptions_.unmanaged = true; 203 this.eventOptions_.unmanaged = true;
202 } 204 }
203 205
204 // Track whether the event has been destroyed to help track down the cause 206 // Track whether the event has been destroyed to help track down the cause
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 'actions in the API specification.'); 442 'actions in the API specification.');
441 } 443 }
442 444
443 validateRules(rules, 445 validateRules(rules,
444 this.eventOptions_.conditions, 446 this.eventOptions_.conditions,
445 this.eventOptions_.actions); 447 this.eventOptions_.actions);
446 448
447 ensureRuleSchemasLoaded(); 449 ensureRuleSchemasLoaded();
448 // We remove the first parameter from the validation to give the user more 450 // We remove the first parameter from the validation to give the user more
449 // meaningful error messages. 451 // meaningful error messages.
450 validate([rules, opt_cb], 452 validate([this.webViewInstanceId_, rules, opt_cb],
451 $Array.splice( 453 $Array.splice(
452 $Array.slice(ruleFunctionSchemas.addRules.parameters), 1)); 454 $Array.slice(ruleFunctionSchemas.addRules.parameters), 1));
453 sendRequest("events.addRules", [this.eventName_, rules, opt_cb], 455 sendRequest("events.addRules",
456 [this.eventName_, this.webViewInstanceId_, rules, opt_cb],
454 ruleFunctionSchemas.addRules.parameters); 457 ruleFunctionSchemas.addRules.parameters);
455 } 458 }
456 459
457 Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { 460 Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) {
458 if (!this.eventOptions_.supportsRules) 461 if (!this.eventOptions_.supportsRules)
459 throw new Error("This event does not support rules."); 462 throw new Error("This event does not support rules.");
460 ensureRuleSchemasLoaded(); 463 ensureRuleSchemasLoaded();
461 // We remove the first parameter from the validation to give the user more 464 // We remove the first parameter from the validation to give the user more
462 // meaningful error messages. 465 // meaningful error messages.
463 validate([ruleIdentifiers, opt_cb], 466 validate([this.webViewInstanceId_, ruleIdentifiers, opt_cb],
464 $Array.splice( 467 $Array.splice(
465 $Array.slice(ruleFunctionSchemas.removeRules.parameters), 1)); 468 $Array.slice(ruleFunctionSchemas.removeRules.parameters), 1));
466 sendRequest("events.removeRules", 469 sendRequest("events.removeRules",
467 [this.eventName_, ruleIdentifiers, opt_cb], 470 [this.eventName_,
471 this.webViewInstanceId_,
472 ruleIdentifiers,
473 opt_cb],
468 ruleFunctionSchemas.removeRules.parameters); 474 ruleFunctionSchemas.removeRules.parameters);
469 } 475 }
470 476
471 Event.prototype.getRules = function(ruleIdentifiers, cb) { 477 Event.prototype.getRules = function(ruleIdentifiers, cb) {
472 if (!this.eventOptions_.supportsRules) 478 if (!this.eventOptions_.supportsRules)
473 throw new Error("This event does not support rules."); 479 throw new Error("This event does not support rules.");
474 ensureRuleSchemasLoaded(); 480 ensureRuleSchemasLoaded();
475 // We remove the first parameter from the validation to give the user more 481 // We remove the first parameter from the validation to give the user more
476 // meaningful error messages. 482 // meaningful error messages.
477 validate([ruleIdentifiers, cb], 483 validate([this.webViewInstanceId_, ruleIdentifiers, cb],
478 $Array.splice( 484 $Array.splice(
479 $Array.slice(ruleFunctionSchemas.getRules.parameters), 1)); 485 $Array.slice(ruleFunctionSchemas.getRules.parameters), 1));
480 486
481 sendRequest("events.getRules", 487 sendRequest("events.getRules",
482 [this.eventName_, ruleIdentifiers, cb], 488 [this.eventName_, this.webViewInstanceId_, ruleIdentifiers, cb],
483 ruleFunctionSchemas.getRules.parameters); 489 ruleFunctionSchemas.getRules.parameters);
484 } 490 }
485 491
486 unloadEvent.addListener(function() { 492 unloadEvent.addListener(function() {
487 for (var i = 0; i < allAttachedEvents.length; ++i) { 493 for (var i = 0; i < allAttachedEvents.length; ++i) {
488 var event = allAttachedEvents[i]; 494 var event = allAttachedEvents[i];
489 if (event) 495 if (event)
490 event.detach_(); 496 event.detach_();
491 } 497 }
492 }); 498 });
493 499
494 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. 500 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc.
495 exports.Event = Event; 501 exports.Event = Event;
496 502
497 exports.dispatchEvent = dispatchEvent; 503 exports.dispatchEvent = dispatchEvent;
498 exports.parseEventOptions = parseEventOptions; 504 exports.parseEventOptions = parseEventOptions;
499 exports.registerArgumentMassager = registerArgumentMassager; 505 exports.registerArgumentMassager = registerArgumentMassager;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698