mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1003095 - Convert DevToolsExtensions.jsm into an SDK module;r=past;r=ZER0
This commit is contained in:
parent
53c79d0fc5
commit
ab4d9fcd80
@ -15,9 +15,9 @@ const self = require('sdk/self');
|
|||||||
const { getTabId, getTabForContentWindow } = require('../tabs/utils');
|
const { getTabId, getTabForContentWindow } = require('../tabs/utils');
|
||||||
const { getInnerId } = require('../window/utils');
|
const { getInnerId } = require('../window/utils');
|
||||||
|
|
||||||
const { gDevToolsExtensions: {
|
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||||
addContentGlobal, removeContentGlobal
|
const { require: devtoolsRequire } = devtools;
|
||||||
} } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
|
const { addContentGlobal, removeContentGlobal } = devtoolsRequire("devtools/server/content-globals");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a new sandbox that inherits given `source`'s principals. Source can be
|
* Make a new sandbox that inherits given `source`'s principals. Source can be
|
||||||
|
@ -29,7 +29,9 @@ const { LoaderWithHookedConsole } = require('sdk/test/loader');
|
|||||||
const { waitUntil } = require("sdk/test/utils");
|
const { waitUntil } = require("sdk/test/utils");
|
||||||
const data = require("./fixtures");
|
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");
|
const testPageURI = data.url("test.html");
|
||||||
|
|
||||||
@ -1492,7 +1494,7 @@ exports.testDevToolsExtensionsGetContentGlobals = function(assert, done) {
|
|||||||
contentScriptWhen: "start",
|
contentScriptWhen: "start",
|
||||||
contentScript: "null;",
|
contentScript: "null;",
|
||||||
}], function(win, done) {
|
}], 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();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
/* 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);
|
|
@ -681,9 +681,7 @@ ThreadActor.prototype = {
|
|||||||
*/
|
*/
|
||||||
globalManager: {
|
globalManager: {
|
||||||
findGlobals: function () {
|
findGlobals: function () {
|
||||||
const { gDevToolsExtensions: {
|
const { getContentGlobals } = require("devtools/server/content-globals");
|
||||||
getContentGlobals
|
|
||||||
} } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
|
|
||||||
|
|
||||||
this.globalDebugObject = this._addDebuggees(this.global);
|
this.globalDebugObject = this._addDebuggees(this.global);
|
||||||
|
|
||||||
|
45
toolkit/devtools/server/content-globals.js
Normal file
45
toolkit/devtools/server/content-globals.js
Normal file
@ -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);
|
@ -18,9 +18,10 @@
|
|||||||
<script type="application/javascript;version=1.8">
|
<script type="application/javascript;version=1.8">
|
||||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||||
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
|
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");
|
Cu.import("resource://gre/modules/devtools/Loader.jsm");
|
||||||
const { require } = devtools;
|
const { require } = devtools;
|
||||||
|
const contentGlobals = require("devtools/server/content-globals");
|
||||||
const tabs = require('sdk/tabs');
|
const tabs = require('sdk/tabs');
|
||||||
const { getMostRecentBrowserWindow, getInnerId } = require('sdk/window/utils');
|
const { getMostRecentBrowserWindow, getInnerId } = require('sdk/window/utils');
|
||||||
const { PageMod } = require('sdk/page-mod');
|
const { PageMod } = require('sdk/page-mod');
|
||||||
@ -58,7 +59,7 @@
|
|||||||
let id = getInnerId(getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow);
|
let id = getInnerId(getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow);
|
||||||
|
|
||||||
// getting
|
// getting
|
||||||
is(gDevToolsExtensions.getContentGlobals({
|
is(contentGlobals.getContentGlobals({
|
||||||
'inner-window-id': id
|
'inner-window-id': id
|
||||||
}).length, 1, 'found a global for inner-id = ' + id);
|
}).length, 1, 'found a global for inner-id = ' + id);
|
||||||
|
|
||||||
@ -67,7 +68,7 @@
|
|||||||
Services.obs.removeObserver(observer, 'inner-window-destroyed');
|
Services.obs.removeObserver(observer, 'inner-window-destroyed');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
// closing the tab window should have removed the global
|
// closing the tab window should have removed the global
|
||||||
is(gDevToolsExtensions.getContentGlobals({
|
is(contentGlobals.getContentGlobals({
|
||||||
'inner-window-id': id
|
'inner-window-id': id
|
||||||
}).length, 0, 'did not find a global for inner-id = ' + id);
|
}).length, 0, 'did not find a global for inner-id = ' + id);
|
||||||
|
|
||||||
@ -90,21 +91,21 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// adding
|
// adding
|
||||||
gDevToolsExtensions.addContentGlobal(globalDetails);
|
contentGlobals.addContentGlobal(globalDetails);
|
||||||
|
|
||||||
// getting
|
// getting
|
||||||
is(gDevToolsExtensions.getContentGlobals({
|
is(contentGlobals.getContentGlobals({
|
||||||
'inner-window-id': 5
|
'inner-window-id': 5
|
||||||
}).length, 1, 'found a global for inner-id = 5');
|
}).length, 1, 'found a global for inner-id = 5');
|
||||||
is(gDevToolsExtensions.getContentGlobals({
|
is(contentGlobals.getContentGlobals({
|
||||||
'inner-window-id': 4
|
'inner-window-id': 4
|
||||||
}).length, 0, 'did not find a global for inner-id = 4');
|
}).length, 0, 'did not find a global for inner-id = 4');
|
||||||
|
|
||||||
// remove
|
// remove
|
||||||
gDevToolsExtensions.removeContentGlobal(globalDetails);
|
contentGlobals.removeContentGlobal(globalDetails);
|
||||||
|
|
||||||
// getting again
|
// getting again
|
||||||
is(gDevToolsExtensions.getContentGlobals({
|
is(contentGlobals.getContentGlobals({
|
||||||
'inner-window-id': 5
|
'inner-window-id': 5
|
||||||
}).length, 0, 'did not find a global for inner-id = 5');
|
}).length, 0, 'did not find a global for inner-id = 5');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user