Skip to content

Commit

Permalink
Bug 1003095 - Convert DevToolsExtensions.jsm into an SDK module;r=pas…
Browse files Browse the repository at this point in the history
…t;r=ZER0
  • Loading branch information
ejpbruel committed May 22, 2014
1 parent 5edff1b commit f8fd30a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 62 deletions.
6 changes: 3 additions & 3 deletions addon-sdk/source/lib/sdk/loader/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const self = require('sdk/self');
const { getTabId, getTabForContentWindow } = require('../tabs/utils');
const { getInnerId } = require('../window/utils');

const { gDevToolsExtensions: {
addContentGlobal, removeContentGlobal
} } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
const { require: devtoolsRequire } = devtools;
const { addContentGlobal, removeContentGlobal } = devtoolsRequire("devtools/server/content-globals");

/**
* Make a new sandbox that inherits given `source`'s principals. Source can be
Expand Down
6 changes: 4 additions & 2 deletions addon-sdk/source/test/test-page-mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const { LoaderWithHookedConsole } = require('sdk/test/loader');
const { waitUntil } = require("sdk/test/utils");
const data = require("./fixtures");

const { gDevToolsExtensions } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
const { require: devtoolsRequire } = devtools;
const contentGlobals = devtoolsRequire("devtools/server/content-globals");

const testPageURI = data.url("test.html");

Expand Down Expand Up @@ -1492,7 +1494,7 @@ exports.testDevToolsExtensionsGetContentGlobals = function(assert, done) {
contentScriptWhen: "start",
contentScript: "null;",
}], function(win, done) {
assert.equal(gDevToolsExtensions.getContentGlobals({ 'inner-window-id': getInnerId(win) }).length, 1);
assert.equal(contentGlobals.getContentGlobals({ 'inner-window-id': getInnerId(win) }).length, 1);
done();
}
);
Expand Down
46 changes: 0 additions & 46 deletions toolkit/devtools/DevToolsExtensions.jsm

This file was deleted.

4 changes: 1 addition & 3 deletions toolkit/devtools/server/actors/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,7 @@ ThreadActor.prototype = {
*/
globalManager: {
findGlobals: function () {
const { gDevToolsExtensions: {
getContentGlobals
} } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
const { getContentGlobals } = require("devtools/server/content-globals");

this.globalDebugObject = this._addDebuggees(this.global);

Expand Down
45 changes: 45 additions & 0 deletions toolkit/devtools/server/content-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* 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";

const { Ci } = require("chrome");
const Services = require("Services");

let globalsCache = {};

exports.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;
}

exports.getContentGlobals = function(options) {
if (!options || !options['inner-window-id']) {
throw Error('Invalid arguments');
}
return Array.slice(globalsCache[options['inner-window-id']] || []);
}

exports.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(Ci.nsISupportsPRUint64).data;
delete globalsCache[id];
}, 'inner-window-destroyed', false);
17 changes: 9 additions & 8 deletions toolkit/devtools/tests/mochitest/test_devtools_extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
<script type="application/javascript;version=1.8">
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
const { gDevToolsExtensions } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});

Cu.import("resource://gre/modules/devtools/Loader.jsm");
const { require } = devtools;
const contentGlobals = require("devtools/server/content-globals");
const tabs = require('sdk/tabs');
const { getMostRecentBrowserWindow, getInnerId } = require('sdk/window/utils');
const { PageMod } = require('sdk/page-mod');
Expand Down Expand Up @@ -58,7 +59,7 @@
let id = getInnerId(getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow);

// getting
is(gDevToolsExtensions.getContentGlobals({
is(contentGlobals.getContentGlobals({
'inner-window-id': id
}).length, 1, 'found a global for inner-id = ' + id);

Expand All @@ -67,7 +68,7 @@
Services.obs.removeObserver(observer, 'inner-window-destroyed');
setTimeout(function() {
// closing the tab window should have removed the global
is(gDevToolsExtensions.getContentGlobals({
is(contentGlobals.getContentGlobals({
'inner-window-id': id
}).length, 0, 'did not find a global for inner-id = ' + id);

Expand All @@ -90,21 +91,21 @@
};

// adding
gDevToolsExtensions.addContentGlobal(globalDetails);
contentGlobals.addContentGlobal(globalDetails);

// getting
is(gDevToolsExtensions.getContentGlobals({
is(contentGlobals.getContentGlobals({
'inner-window-id': 5
}).length, 1, 'found a global for inner-id = 5');
is(gDevToolsExtensions.getContentGlobals({
is(contentGlobals.getContentGlobals({
'inner-window-id': 4
}).length, 0, 'did not find a global for inner-id = 4');

// remove
gDevToolsExtensions.removeContentGlobal(globalDetails);
contentGlobals.removeContentGlobal(globalDetails);

// getting again
is(gDevToolsExtensions.getContentGlobals({
is(contentGlobals.getContentGlobals({
'inner-window-id': 5
}).length, 0, 'did not find a global for inner-id = 5');

Expand Down

0 comments on commit f8fd30a

Please sign in to comment.