Skip to content

Commit 2072b3f

Browse files
committed
Remove BootstrapLoader API
Use LegacyHelper API and dedicated TbSync API instead
1 parent c234837 commit 2072b3f

20 files changed

+318
-1286
lines changed

Makebeta

-37
This file was deleted.

Makefile.bat

-19
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TbSync
22

3-
[TbSync](https://addons.thunderbird.net/addon/tbsync/) was a central user interface to manage cloud accounts and to synchronize their contact, task and calendar information with [Thunderbird](https://www.thunderbird.net/). Its main objective was to simplify the setup process for such accounts. Thunderbird is working on a new account-hub UI, which will make TbSync obsolete.
3+
[TbSync](https://addons.thunderbird.net/addon/tbsync/) is a central user interface to manage cloud accounts and to synchronize their contact, task and calendar information with [Thunderbird](https://www.thunderbird.net/). Its main objective is to simplify the setup process for such accounts. Thunderbird is working on a new account-hub UI, which will make TbSync obsolete.
44

55
## Icon sources and attributions
66

UPDATE68.md

-24
This file was deleted.

api/LegacyHelper/README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Objective
2+
3+
This API is a temporary helper while converting legacy extensions to modern WebExtensions. It allows to register `resource://` URLs, which are needed to load custom system modules (*.sys.mjs), and `chrome://` URLs, which are needed to open legacy XUL dialogs.
4+
5+
## Usage
6+
7+
Add the [LegacyHelper API](https://github.com/thunderbird/webext-support/tree/master/experiments/LegacyHelper) to your add-on. Your `manifest.json` needs an entry like this:
8+
9+
```json
10+
"experiment_apis": {
11+
"LegacyHelper": {
12+
"schema": "api/LegacyHelper/schema.json",
13+
"parent": {
14+
"scopes": ["addon_parent"],
15+
"paths": [["LegacyHelper"]],
16+
"script": "api/LegacyHelper/implementation.js"
17+
}
18+
}
19+
},
20+
```
21+
22+
## API Functions
23+
24+
This API provides the following functions:
25+
26+
### async registerGlobalUrls(data)
27+
28+
Register `chrome://*/content/` and `resource://*/` URLs. The function accepts a `data` parameter, which is an array of URL definition items. For example:
29+
30+
```javascript
31+
await browser.LegacyHelper.registerGlobalUrls([
32+
["content", "myaddon", "chrome/content/"],
33+
["resource", "myaddon", "modules/"],
34+
]);
35+
```
36+
37+
This registers the following URLs:
38+
* `chrome://myaddon/content/` pointing to the `/chrome/content/` folder (the `/content/` part in the URL is fix and does not depend on the name of the folder it is pointing to)
39+
* `resource://myaddon/` pointing to the `/modules/` folder. To register a `resource://` URL which points to the root folder, use `.` instead".
40+
41+
### async openDialog(name, path)
42+
43+
Open a XUL dialog. The `name` parameter is a unique name identifying the dialog. If the dialog with that name is already open, it will be focused instead of being re-opened. The `path` parameter is a `chrome://*/content/` URL pointing to the XUL dialog file (*.xul or *.xhtml).
44+
45+
```javascript
46+
browser.LegacyHelper.openDialog(
47+
"XulAddonOptions",
48+
"chrome://myaddon/content/options.xhtml"
49+
);
50+
```

api/LegacyHelper/implementation.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* This file is provided by the webext-support repository at
3+
* https://github.com/thunderbird/webext-support
4+
*
5+
* Version 1.1
6+
* - registerGlobalUrls() is now async, to be able to properly await registration
7+
*
8+
* Version 1.0
9+
* - initial release
10+
*
11+
* Author:
12+
* - John Bieling ([email protected])
13+
*
14+
* This Source Code Form is subject to the terms of the Mozilla Public
15+
* License, v. 2.0. If a copy of the MPL was not distributed with this
16+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
17+
*/
18+
19+
"use strict";
20+
21+
// Using a closure to not leak anything but the API to the outside world.
22+
(function (exports) {
23+
24+
const aomStartup = Cc[
25+
"@mozilla.org/addons/addon-manager-startup;1"
26+
].getService(Ci.amIAddonManagerStartup);
27+
const resProto = Cc[
28+
"@mozilla.org/network/protocol;1?name=resource"
29+
].getService(Ci.nsISubstitutingProtocolHandler);
30+
31+
const chromeHandlers = [];
32+
const resourceUrls = [];
33+
34+
var LegacyHelper = class extends ExtensionCommon.ExtensionAPI {
35+
getAPI(context) {
36+
return {
37+
LegacyHelper: {
38+
registerGlobalUrls(data) {
39+
const manifestURI = Services.io.newURI(
40+
"manifest.json",
41+
null,
42+
context.extension.rootURI
43+
);
44+
45+
for (let entry of data) {
46+
// [ "resource", "shortname" , "path" ]
47+
48+
switch (entry[0]) {
49+
case "resource":
50+
{
51+
let uri = Services.io.newURI(
52+
entry[2],
53+
null,
54+
context.extension.rootURI
55+
);
56+
resProto.setSubstitutionWithFlags(
57+
entry[1],
58+
uri,
59+
resProto.ALLOW_CONTENT_ACCESS
60+
);
61+
resourceUrls.push(entry[1]);
62+
}
63+
break;
64+
65+
case "content":
66+
case "locale":
67+
{
68+
let handle = aomStartup.registerChrome(
69+
manifestURI,
70+
[entry]
71+
);
72+
chromeHandlers.push(handle);
73+
}
74+
break;
75+
76+
default:
77+
console.warn(`LegacyHelper: Unsupported url type: ${entry[0]}`)
78+
}
79+
}
80+
},
81+
82+
openDialog(name, path) {
83+
let window = Services.wm.getMostRecentWindow("mail:3pane");
84+
window.openDialog(
85+
path,
86+
name,
87+
"chrome,resizable,centerscreen"
88+
);
89+
},
90+
},
91+
};
92+
}
93+
94+
onShutdown(isAppShutdown) {
95+
if (isAppShutdown) {
96+
return; // the application gets unloaded anyway
97+
}
98+
99+
for (let chromeHandler of chromeHandlers) {
100+
if (chromeHandler) {
101+
chromeHandler.destruct();
102+
chromeHandler = null;
103+
}
104+
}
105+
106+
for (let resourceUrl of resourceUrls) {
107+
resProto.setSubstitution(
108+
resourceUrl,
109+
null
110+
);
111+
}
112+
113+
// Flush all caches.
114+
Services.obs.notifyObservers(null, "startupcache-invalidate");
115+
}
116+
};
117+
exports.LegacyHelper = LegacyHelper;
118+
})(this);

api/LegacyHelper/schema.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"namespace": "LegacyHelper",
4+
"functions": [
5+
{
6+
"name": "registerGlobalUrls",
7+
"type": "function",
8+
"async": true,
9+
"description": "Register folders which should be available as legacy chrome:// urls or resource:// urls",
10+
"parameters": [
11+
{
12+
"name": "data",
13+
"type": "array",
14+
"items": {
15+
"type": "array",
16+
"items": {
17+
"type": "string"
18+
}
19+
},
20+
"description": "Array of manifest url definitions (content, locale or resource)"
21+
}
22+
]
23+
},
24+
{
25+
"name": "openDialog",
26+
"type": "function",
27+
"parameters": [
28+
{
29+
"name": "name",
30+
"type": "string",
31+
"description": "name of the new dialog"
32+
},
33+
{
34+
"name": "path",
35+
"type": "string",
36+
"description": "path of the dialog to be opened"
37+
}
38+
]
39+
}
40+
]
41+
}
42+
]

api/TbSync/implementation.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
"use strict";
8+
9+
// Using a closure to not leak anything but the API to the outside world.
10+
(function (exports) {
11+
12+
var { AddonManager } = ChromeUtils.importESModule("resource://gre/modules/AddonManager.sys.mjs");
13+
var { TbSync: TbSyncModule } = ChromeUtils.importESModule("chrome://tbsync/content/tbsync.sys.mjs");
14+
15+
let defaults = Services.prefs.getDefaultBranch("extensions.tbsync.");
16+
defaults.setBoolPref("debug.testoptions", false);
17+
defaults.setBoolPref("log.toconsole", false);
18+
defaults.setIntPref("log.userdatalevel", 0); //0 - off 1 - userdata only on errors 2 - including full userdata, 3 - extra infos
19+
20+
var TbSync = class extends ExtensionCommon.ExtensionAPI {
21+
getAPI(context) {
22+
return {
23+
TbSync: {
24+
async load(windowId) {
25+
let { window } = context.extension.windowManager.get(windowId);
26+
let { TbSync } = ChromeUtils.importESModule("chrome://tbsync/content/tbsync.sys.mjs");
27+
if (!TbSync.enabled) {
28+
let addon = await AddonManager.getAddonByID(context.extension.id);
29+
TbSync.load(window, addon, context.extension);
30+
}
31+
},
32+
openManagerWindow() {
33+
TbSyncModule.manager.openManagerWindow();
34+
}
35+
},
36+
};
37+
}
38+
39+
onShutdown(isAppShutdown) {
40+
if (isAppShutdown) {
41+
return; // the application gets unloaded anyway
42+
}
43+
}
44+
};
45+
exports.TbSync = TbSync;
46+
})(this);

api/TbSync/schema.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"namespace": "TbSync",
4+
"functions": [
5+
{
6+
"name": "load",
7+
"type": "function",
8+
"async": true,
9+
"parameters": [
10+
{
11+
"name": "windowId",
12+
"type": "integer"
13+
}
14+
]
15+
},
16+
{
17+
"name": "openManagerWindow",
18+
"type": "function",
19+
"async": true,
20+
"parameters": []
21+
}
22+
]
23+
}
24+
]

0 commit comments

Comments
 (0)