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

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

Issue 9309114: Allow "internal" APIs to be specified in extension API schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 var chrome = chrome || {}; 5 var chrome = chrome || {};
6 (function () { 6 (function () {
7 native function GetChromeHidden(); 7 native function GetChromeHidden();
8 native function AttachEvent(eventName); 8 native function AttachEvent(eventName);
9 native function DetachEvent(eventName); 9 native function DetachEvent(eventName);
10 native function Print(); 10 native function Print();
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 delete attachedNamedEvents[this.eventName_]; 240 delete attachedNamedEvents[this.eventName_];
241 }; 241 };
242 242
243 chrome.Event.prototype.destroy_ = function() { 243 chrome.Event.prototype.destroy_ = function() {
244 this.listeners_ = []; 244 this.listeners_ = [];
245 this.validate_ = []; 245 this.validate_ = [];
246 this.detach_(); 246 this.detach_();
247 }; 247 };
248 248
249 // Gets the declarative API object, or undefined if this extension doesn't
250 // have access to it.
251 //
252 // This is defined as a function (rather than a variable) because it isn't
253 // accessible until the schema bindings have been generated.
254 function getDeclarativeAPI() {
255 if (chromeHidden.internalAPIs.experimental)
256 return chromeHidden.internalAPIs.experimental.declarative;
257 else
258 return undefined;
259 }
260
249 chrome.Event.prototype.addRules = function(rules, opt_cb) { 261 chrome.Event.prototype.addRules = function(rules, opt_cb) {
250 if (!this.eventOptions_.supportsRules) 262 if (!this.eventOptions_.supportsRules)
251 throw new Error("This event does not support rules."); 263 throw new Error("This event does not support rules.");
252 if (!chrome.experimental || !chrome.experimental.declarative) { 264 if (!getDeclarativeAPI()) {
253 throw new Error("You must have access to the experimental.declarative " + 265 throw new Error("You must have permission to use the declarative " +
254 "API to support rules in events"); 266 "API to support rules in events");
255 } 267 }
256 chrome.experimental.declarative.addRules(this.eventName_, rules, opt_cb); 268 getDeclarativeAPI().addRules(this.eventName_, rules, opt_cb);
257 } 269 }
258 270
259 chrome.Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { 271 chrome.Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) {
260 if (!this.eventOptions_.supportsRules) 272 if (!this.eventOptions_.supportsRules)
261 throw new Error("This event does not support rules."); 273 throw new Error("This event does not support rules.");
262 if (!chrome.experimental || !chrome.experimental.declarative) { 274 if (!getDeclarativeAPI()) {
263 throw new Error("You must have access to the experimental.declarative " + 275 throw new Error("You must have permission to use the declarative " +
264 "API to support rules in events"); 276 "API to support rules in events");
265 } 277 }
266 chrome.experimental.declarative.removeRules( 278 getDeclarativeAPI().removeRules(
267 this.eventName_, ruleIdentifiers, opt_cb); 279 this.eventName_, ruleIdentifiers, opt_cb);
268 } 280 }
269 281
270 chrome.Event.prototype.getRules = function(ruleIdentifiers, cb) { 282 chrome.Event.prototype.getRules = function(ruleIdentifiers, cb) {
271 if (!this.eventOptions_.supportsRules) 283 if (!this.eventOptions_.supportsRules)
272 throw new Error("This event does not support rules."); 284 throw new Error("This event does not support rules.");
273 if (!chrome.experimental || !chrome.experimental.declarative) { 285 if (!getDeclarativeAPI()) {
274 throw new Error("You must have access to the experimental.declarative " + 286 throw new Error("You must have permission to use the declarative " +
275 "API to support rules in events"); 287 "API to support rules in events");
276 } 288 }
277 chrome.experimental.declarative.getRules( 289 getDeclarativeAPI().getRules(
278 this.eventName_, ruleIdentifiers, cb); 290 this.eventName_, ruleIdentifiers, cb);
279 } 291 }
280 292
281 // Special load events: we don't use the DOM unload because that slows 293 // Special load events: we don't use the DOM unload because that slows
282 // down tab shutdown. On the other hand, onUnload might not always fire, 294 // down tab shutdown. On the other hand, onUnload might not always fire,
283 // since Chrome will terminate renderers on shutdown (SuddenTermination). 295 // since Chrome will terminate renderers on shutdown (SuddenTermination).
284 chromeHidden.onLoad = new chrome.Event(); 296 chromeHidden.onLoad = new chrome.Event();
285 chromeHidden.onUnload = new chrome.Event(); 297 chromeHidden.onUnload = new chrome.Event();
286 298
287 chromeHidden.dispatchOnLoad = 299 chromeHidden.dispatchOnLoad =
288 chromeHidden.onLoad.dispatch.bind(chromeHidden.onLoad); 300 chromeHidden.onLoad.dispatch.bind(chromeHidden.onLoad);
289 301
290 chromeHidden.dispatchOnUnload = function() { 302 chromeHidden.dispatchOnUnload = function() {
291 chromeHidden.onUnload.dispatch(); 303 chromeHidden.onUnload.dispatch();
292 for (var i = 0; i < allAttachedEvents.length; ++i) { 304 for (var i = 0; i < allAttachedEvents.length; ++i) {
293 var event = allAttachedEvents[i]; 305 var event = allAttachedEvents[i];
294 if (event) 306 if (event)
295 event.detach_(); 307 event.detach_();
296 } 308 }
297 }; 309 };
298 310
299 chromeHidden.dispatchError = function(msg) { 311 chromeHidden.dispatchError = function(msg) {
300 console.error(msg); 312 console.error(msg);
301 }; 313 };
302 })(); 314 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698