-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiments.js
83 lines (76 loc) · 2.56 KB
/
experiments.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"use strict";
var { ExtensionSupport } = ChromeUtils.import(
"resource:///modules/ExtensionSupport.jsm",
);
var { ExtensionParent } = ChromeUtils.import(
"resource://gre/modules/ExtensionParent.jsm",
);
const EXTENSION_NAME = "[email protected]";
var extension = ExtensionParent.GlobalManager.getExtension(EXTENSION_NAME);
// Implements the functions defined in the experiments section of schema.json.
var userChromeJS = class extends ExtensionCommon.ExtensionAPI {
onStartup() {}
onShutdown(isAppShutdown) {
if (isAppShutdown) return;
// Looks like we got uninstalled. Maybe a new version will be installed
// now. Due to new versions not taking effect
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1634348)
// we invalidate the startup cache. That's the same effect as starting
// with -purgecaches (or deleting the startupCache directory from the
// profile).
Services.obs.notifyObservers(null, "startupcache-invalidate");
}
getAPI(context) {
context.callOnClose(this);
return {
userChromeJS: {
addWindowListener() {
var prefix = "chrome://messenger/content/";
var windows = [
"addressbook/addressbook",
"messenger",
"messageWindow",
"messengercompose/messengercompose",
];
var suffixes = ["xul", "xhtml"];
var urls = suffixes
.map((s) => windows.map((w) => prefix + w + "." + s))
.flat(1);
urls.push("chrome://calendar/content/calendar-event-dialog.xhtml");
// Adds a listener to detect new windows.
ExtensionSupport.registerWindowListener(EXTENSION_NAME, {
chromeURLs: urls,
onLoadWindow: paint,
});
},
reload(windowId) {
let window = context.extension.windowManager.get(windowId);
console.log(window);
paint(window.window);
},
},
};
}
close() {
ExtensionSupport.unregisterWindowListener(EXTENSION_NAME);
}
};
function paint(win) {
if (!win.document.location || win.document.location.protocol != "chrome:") {
return;
}
var file = Services.dirsvc.get("UChrm", Components.interfaces.nsIFile);
file.append("userChrome.js");
if (!file.exists()) {
return;
}
var url = Services.io
.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler)
.getURLSpecFromActualFile(file);
Services.scriptloader.loadSubScriptWithOptions(url, {
target: win.document.defaultView,
charset: "UTF-8",
ignoreCache: true,
});
}