Bug 1350646: Part 11 - Remove SDK stylesheet modules. r=Mossop

MozReview-Commit-ID: BwWPklao5iS

--HG--
extra : source : 096ff315b48b51aae1863b687fff74707e8e04c3
This commit is contained in:
Kris Maglione 2017-08-05 21:38:01 -07:00
Родитель fac0146987
Коммит 8f7f2f32d9
3 изменённых файлов: 0 добавлений и 150 удалений

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

@ -38,9 +38,7 @@ modules = [
'sdk/console/traceback.js',
'sdk/content/events.js',
'sdk/content/loader.js',
'sdk/content/mod.js',
'sdk/content/thumbnail.js',
'sdk/content/utils.js',
'sdk/core/disposable.js',
'sdk/core/heritage.js',
'sdk/core/namespace.js',
@ -49,7 +47,6 @@ modules = [
'sdk/core/reference.js',
'sdk/deprecated/api-utils.js',
'sdk/deprecated/events/assembler.js',
'sdk/deprecated/sync-worker.js',
'sdk/deprecated/unit-test-finder.js',
'sdk/deprecated/unit-test.js',
'sdk/deprecated/window-utils.js',
@ -75,7 +72,6 @@ modules = [
'sdk/lang/functional/helpers.js',
'sdk/lang/type.js',
'sdk/lang/weak-set.js',
'sdk/loader/sandbox.js',
'sdk/messaging.js',
'sdk/model/core.js',
'sdk/net/url.js',
@ -95,8 +91,6 @@ modules = [
'sdk/self.js',
'sdk/simple-prefs.js',
'sdk/simple-storage.js',
'sdk/stylesheet/style.js',
'sdk/stylesheet/utils.js',
'sdk/system.js',
'sdk/system/environment.js',
'sdk/system/events-shimmed.js',

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

@ -1,69 +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";
module.metadata = {
"stability": "experimental"
};
const { Class } = require("../core/heritage");
lazyRequire(this, "../url", "isLocalURL");
lazyRequire(this, "./utils", "loadSheet", "removeSheet", "isTypeValid");
lazyRequire(this, "../lang/type", "isString");
const { attachTo, detachFrom } = require("../content/mod");
lazyRequire(this, '../self', "data");
const { freeze, create } = Object;
function Style({ source, uri, type }) {
source = source == null ? null : freeze([].concat(source));
uri = uri == null ? null : freeze([].concat(uri));
type = type == null ? "author" : type;
if (source && !source.every(isString))
throw new Error('Style.source must be a string or an array of strings.');
if (uri && !uri.every(isLocalURL))
throw new Error('Style.uri must be a local URL or an array of local URLs');
if (type && !isTypeValid(type))
throw new Error('Style.type must be "agent", "user" or "author"');
return freeze(create(Style.prototype, {
"source": { value: source, enumerable: true },
"uri": { value: uri, enumerable: true },
"type": { value: type, enumerable: true }
}));
};
exports.Style = Style;
attachTo.define(Style, function (style, window) {
if (style.uri) {
for (let uri of style.uri)
loadSheet(window, data.url(uri), style.type);
}
if (style.source) {
let uri = "data:text/css;charset=utf-8,";
uri += encodeURIComponent(style.source.join(""));
loadSheet(window, uri, style.type);
}
});
detachFrom.define(Style, function (style, window) {
if (style.uri)
for (let uri of style.uri)
removeSheet(window, data.url(uri));
if (style.source) {
let uri = "data:text/css;charset=utf-8,";
uri += encodeURIComponent(style.source.join(""));
removeSheet(window, uri, style.type);
}
});

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

@ -1,75 +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";
module.metadata = {
"stability": "experimental"
};
const { Ci } = require("chrome");
const SHEET_TYPE = {
"agent": "AGENT_SHEET",
"user": "USER_SHEET",
"author": "AUTHOR_SHEET"
};
function getDOMWindowUtils(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
};
/**
* Synchronously loads a 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 loadSheet(window, url, type) {
if (!(type && type in SHEET_TYPE))
type = "author";
type = SHEET_TYPE[type];
if (url instanceof Ci.nsIURI)
url = url.spec;
let winUtils = getDOMWindowUtils(window);
try {
winUtils.loadSheetUsingURIString(url, winUtils[type]);
}
catch (e) {};
};
exports.loadSheet = loadSheet;
/**
* Remove the document style sheet at `sheetURI` from the list of additional
* style sheets of the document. The removal takes effect immediately.
*/
function removeSheet(window, url, type) {
if (!(type && type in SHEET_TYPE))
type = "author";
type = SHEET_TYPE[type];
if (url instanceof Ci.nsIURI)
url = url.spec;
let winUtils = getDOMWindowUtils(window);
try {
winUtils.removeSheetUsingURIString(url, winUtils[type]);
}
catch (e) {};
};
exports.removeSheet = removeSheet;
/**
* Returns `true` if the `type` given is valid, otherwise `false`.
* The values currently accepted are: "agent", "user" and "author".
*/
function isTypeValid(type) {
return type in SHEET_TYPE;
}
exports.isTypeValid = isTypeValid;