DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (27a812186ff4)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

this.EXPORTED_SYMBOLS = ["gDevToolsExtensions"];

Components.utils.import("resource://gre/modules/Services.jsm");

let globalsCache = {};

this.gDevToolsExtensions = {
  addContentGlobal: function(options) {
    if (!options || !options.global || !options['inner-window-id']) {
      throw Error('Invalid arguments');
    }
    let cache = getGlobalCache(options['inner-window-id']);
    cache.push(options.global);
    return undefined;
  },
  getContentGlobals: function(options) {
    if (!options || !options['inner-window-id']) {
      throw Error('Invalid arguments');
    }
    return Array.slice(globalsCache[options['inner-window-id']] || []);
  },
  removeContentGlobal: function(options) {
    if (!options || !options.global || !options['inner-window-id']) {
      throw Error('Invalid arguments');
    }
    let cache = getGlobalCache(options['inner-window-id']);
    let index = cache.indexOf(options.global);
    cache.splice(index, 1);
    return undefined;
  }
};

function getGlobalCache(aInnerWindowID) {
  return globalsCache[aInnerWindowID] = globalsCache[aInnerWindowID] || [];
}

// when the window is destroyed, eliminate the associated globals cache
Services.obs.addObserver(function observer(subject, topic, data) {
  let id = subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
  delete globalsCache[id];
}, 'inner-window-destroyed', false);