Bug 1353045 - Remove SDK usage from RDM. r=pbro

MozReview-Commit-ID: I2dodBb9NHh

--HG--
extra : rebase_source : 0ce62635307c19e1d449f2c773bacaaf998a5970
This commit is contained in:
J. Ryan Stinnett 2017-04-06 21:42:21 -05:00
Родитель 3a1c3e7365
Коммит 5de2d8377f
10 изменённых файлов: 89 добавлений и 21 удалений

Просмотреть файл

@ -12,7 +12,7 @@ const {
} = require("./index");
const { getFormatStr } = require("../utils/l10n");
const { getToplevelWindow } = require("sdk/window/utils");
const { getToplevelWindow } = require("../utils/window");
const { Task: { spawn } } = require("devtools/shared/task");
const e10s = require("../utils/e10s");
const Services = require("Services");

Просмотреть файл

@ -8,7 +8,7 @@
const { Task } = require("devtools/shared/task");
const flags = require("devtools/shared/flags");
const { getToplevelWindow } = require("sdk/window/utils");
const { getToplevelWindow } = require("../utils/window");
const { DOM: dom, createClass, addons, PropTypes } =
require("devtools/client/shared/vendor/react");

Просмотреть файл

@ -15,7 +15,7 @@ const { require } = BrowserLoader({
});
const { Task } = require("devtools/shared/task");
const Telemetry = require("devtools/client/shared/telemetry");
const { loadSheet } = require("sdk/stylesheet/utils");
const { loadAgentSheet } = require("./utils/css");
const { createFactory, createElement } =
require("devtools/client/shared/vendor/react");
@ -42,9 +42,10 @@ let bootstrap = {
init: Task.async(function* () {
// Load a special UA stylesheet to reset certain styles such as dropdown
// lists.
loadSheet(window,
"resource://devtools/client/responsive.html/responsive-ua.css",
"agent");
loadAgentSheet(
window,
"resource://devtools/client/responsive.html/responsive-ua.css"
);
this.telemetry.toolOpened("responsive");
let store = this.store = Store();
let provider = createElement(Provider, { store }, App());

Просмотреть файл

@ -8,8 +8,7 @@ const { Ci } = require("chrome");
const promise = require("promise");
const { Task } = require("devtools/shared/task");
const EventEmitter = require("devtools/shared/event-emitter");
const { getOwnerWindow } = require("sdk/tabs/utils");
const { startup } = require("sdk/window/helpers");
const { startup } = require("./utils/window");
const message = require("./utils/message");
const { swapToInnerBrowser } = require("./browser/swap");
const { EmulationFront } = require("devtools/shared/fronts/emulation");
@ -145,7 +144,7 @@ const ResponsiveUIManager = exports.ResponsiveUIManager = {
* @return boolean
*/
isActiveForWindow(window) {
return [...this.activeTabs.keys()].some(t => getOwnerWindow(t) === window);
return [...this.activeTabs.keys()].some(t => t.ownerGlobal === window);
},
/**
@ -209,7 +208,7 @@ const ResponsiveUIManager = exports.ResponsiveUIManager = {
}
},
setMenuCheckFor: Task.async(function* (tab, window = getOwnerWindow(tab)) {
setMenuCheckFor: Task.async(function* (tab, window = tab.ownerGlobal) {
yield startup(window);
let menu = window.document.getElementById("menu_responsiveUI");

Просмотреть файл

@ -7,18 +7,18 @@
const TEST_URL = "data:text/html;charset=utf-8,";
const tabUtils = require("sdk/tabs/utils");
const { startup } = require("sdk/window/helpers");
const { startup } = require("devtools/client/responsive.html/utils/window");
const activateTab = (tab) => new Promise(resolve => {
let { tabContainer } = tabUtils.getOwnerWindow(tab).gBrowser;
let { gBrowser } = tab.ownerGlobal;
let { tabContainer } = gBrowser;
tabContainer.addEventListener("TabSelect", function listener({type}) {
tabContainer.removeEventListener(type, listener);
resolve();
});
tabUtils.activateTab(tab);
gBrowser.selectedTab = tab;
});
const isMenuChecked = () => {

Просмотреть файл

@ -7,8 +7,6 @@
const TEST_URL = "data:text/html;charset=utf-8,";
const { getMostRecentBrowserWindow } = require("sdk/window/utils");
const isMenuCheckedFor = ({document}) => {
let menu = document.getElementById("menu_responsiveUI");
return menu.getAttribute("checked") === "true";
@ -22,7 +20,7 @@ add_task(function* () {
function* (browser) {
let tab = gBrowser.getTabForBrowser(browser);
is(window1, getMostRecentBrowserWindow(),
is(window1, Services.wm.getMostRecentWindow("navigator:browser"),
"The new window is the active one");
ok(!isMenuCheckedFor(window1),
@ -41,7 +39,7 @@ add_task(function* () {
yield BrowserTestUtils.closeWindow(window1);
is(window, getMostRecentBrowserWindow(),
is(window, Services.wm.getMostRecentWindow("navigator:browser"),
"The original window is the active one");
ok(!isMenuCheckedFor(window),

Просмотреть файл

@ -36,7 +36,6 @@ const TEST_URI_ROOT = "http://example.com/browser/devtools/client/responsive.htm
const OPEN_DEVICE_MODAL_VALUE = "OPEN_DEVICE_MODAL";
const { _loadPreferredDevices } = require("devtools/client/responsive.html/actions/devices");
const { getOwnerWindow } = require("sdk/tabs/utils");
const asyncStorage = require("devtools/shared/async-storage");
const { addDevice, removeDevice } = require("devtools/client/shared/devices");
@ -72,7 +71,7 @@ const { ResponsiveUIManager } = require("resource://devtools/client/responsivede
var openRDM = Task.async(function* (tab) {
info("Opening responsive design mode");
let manager = ResponsiveUIManager;
let ui = yield manager.openIfNeeded(getOwnerWindow(tab), tab);
let ui = yield manager.openIfNeeded(tab.ownerGlobal, tab);
info("Responsive design mode opened");
return { ui, manager };
});
@ -83,7 +82,7 @@ var openRDM = Task.async(function* (tab) {
var closeRDM = Task.async(function* (tab, options) {
info("Closing responsive design mode");
let manager = ResponsiveUIManager;
yield manager.closeIfNeeded(getOwnerWindow(tab), tab, options);
yield manager.closeIfNeeded(tab.ownerGlobal, tab, options);
info("Responsive design mode closed");
});

Просмотреть файл

@ -0,0 +1,18 @@
/* 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 { getDOMWindowUtils } = require("./window");
/**
* Synchronously loads an agent style sheet from `uri` and adds it to the list of
* additional style sheets of the document. The sheets added takes effect immediately,
* and only on the document of the `window` given.
*/
function loadAgentSheet(window, url) {
let winUtils = getDOMWindowUtils(window);
winUtils.loadSheetUsingURIString(url, winUtils.AGENT_SHEET);
}
exports.loadAgentSheet = loadAgentSheet;

Просмотреть файл

@ -5,7 +5,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
'css.js',
'e10s.js',
'l10n.js',
'message.js',
'window.js',
)

Просмотреть файл

@ -0,0 +1,51 @@
/* 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");
/**
* Returns the `nsIDOMWindow` toplevel window for any child/inner window
*/
function getToplevelWindow(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
}
exports.getToplevelWindow = getToplevelWindow;
function getDOMWindowUtils(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
}
exports.getDOMWindowUtils = getDOMWindowUtils;
/**
* Check if the given browser window has finished the startup.
* @params {nsIDOMWindow} window
*/
const isStartupFinished = (window) =>
window.gBrowserInit &&
window.gBrowserInit.delayedStartupFinished;
function startup(window) {
return new Promise(resolve => {
if (isStartupFinished(window)) {
resolve(window);
return;
}
Services.obs.addObserver(function listener({ subject }) {
if (subject === window) {
Services.obs.removeObserver(listener, "browser-delayed-startup-finished");
resolve(window);
}
}, "browser-delayed-startup-finished", false);
});
}
exports.startup = startup;