2 * (C) Copyright 2004-2007 Shawn Betts
3 * (C) Copyright 2007-2010 John J. Foerch
4 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
10 function register_user_stylesheet (url
) {
11 var uri
= make_uri(url
);
12 var sss
= Cc
["@mozilla.org/content/style-sheet-service;1"]
13 .getService(Ci
.nsIStyleSheetService
);
14 sss
.loadAndRegisterSheet(uri
, sss
.USER_SHEET
);
17 function unregister_user_stylesheet (url
) {
18 var uri
= make_uri(url
);
19 var sss
= Cc
["@mozilla.org/content/style-sheet-service;1"]
20 .getService(Ci
.nsIStyleSheetService
);
21 if (sss
.sheetRegistered(uri
, sss
.USER_SHEET
))
22 sss
.unregisterSheet(uri
, sss
.USER_SHEET
);
25 function register_agent_stylesheet (url
) {
26 var uri
= make_uri(url
);
27 var sss
= Cc
["@mozilla.org/content/style-sheet-service;1"]
28 .getService(Ci
.nsIStyleSheetService
);
29 sss
.loadAndRegisterSheet(uri
, sss
.AGENT_SHEET
);
32 function unregister_agent_stylesheet (url
) {
33 var uri
= make_uri(url
);
34 var sss
= Cc
["@mozilla.org/content/style-sheet-service;1"]
35 .getService(Ci
.nsIStyleSheetService
);
36 if (sss
.sheetRegistered(uri
, sss
.AGENT_SHEET
))
37 sss
.unregisterSheet(uri
, sss
.AGENT_SHEET
);
40 function agent_stylesheet_registered_p (url
) {
41 var uri
= make_uri(url
);
42 var sss
= Cc
["@mozilla.org/content/style-sheet-service;1"]
43 .getService(Ci
.nsIStyleSheetService
);
44 return sss
.sheetRegistered(uri
, sss
.AGENT_SHEET
);
47 function user_stylesheet_registered_p (url
) {
48 var uri
= make_uri(url
);
49 var sss
= Cc
["@mozilla.org/content/style-sheet-service;1"]
50 .getService(Ci
.nsIStyleSheetService
);
51 return sss
.sheetRegistered(uri
, sss
.USER_SHEET
);
55 * make_css_data_uri takes specifications for a css data uri in its
56 * positional and keyword arguments, and returns a new nsIURI object.
58 * rules: css rules, not including any @namespace or @-moz-document
59 * headers. given as a string or an array of strings.
61 * $namespace: optional string url for a @namespace header.
63 * $domains: optional string, or array of strings, for a @-moz-document
66 * $urls: optional string, or array of strings, for a @-moz-document
69 * $url_prefixes: optional string, or array of strings, for a
70 * @-moz-document url-prefix(...) header.
72 * $regexps: optional string or RegExp, or array of strings or RegExps,
73 * for a @-moz-document regexp(...) header. This header is only
74 * available in XULRunner 6 or higher.
76 define_keywords("$namespace", "$domains", "$urls", "$url_prefixes", "$regexps");
77 function make_css_data_uri (rules
) {
79 var namespace = arguments
.$namespace;
80 var domains
= arguments
.$domains
;
81 var urls
= arguments
.$urls
;
82 var url_prefixes
= arguments
.$url_prefixes
;
83 var regexps
= arguments
.$regexps
;
84 rules
= make_array(rules
).join("\n");
85 var restrictions
= Array
.prototype.concat(
86 make_array(domains
).map(function (x
) "domain("+x
+")"),
87 make_array(urls
).map(function (x
) "url("+x
+")"),
88 make_array(url_prefixes
).map(function (x
) "url-prefix("+x
+")"),
89 make_array(regexps
).map(function (x
) {
91 ((x
instanceof RegExp
) ? x
.source
: x
)+
96 rules
= "@-moz-document "+restrictions
+" {\n"+rules
+"\n}";
98 rules
= "@namespace url("+namespace+");\n"+rules
;
99 return make_uri("data:text/css,"+escape(rules
));
102 provide("stylesheet");