canmove, Confirmed users
1,570
edits
No edit summary |
|||
| Line 1: | Line 1: | ||
One of the more common issues that add-on developers seem to be hitting is trying to run code when their add-on is | One of the more common issues that add-on developers seem to be hitting is trying to run code when their add-on is activated or deactivated. While there are currently ways to detect this they are not totally reliable and fail in many situations. | ||
=Overview= | =Overview= | ||
| Line 5: | Line 5: | ||
Add-on hooks are a proposed way that add-on developers can have JavaScript code executed whenever their add-on is acted on by the extension manager. The following operations would cause a hook to be executed: | Add-on hooks are a proposed way that add-on developers can have JavaScript code executed whenever their add-on is acted on by the extension manager. The following operations would cause a hook to be executed: | ||
* Enabling (also runs during add-on installation) | |||
* Disabling (also runs if an enabled add-on is uninstalled) | |||
* Enabling | |||
* Disabling ( | |||
* Upgrading | * Upgrading | ||
| Line 19: | Line 17: | ||
*install.rdf | *install.rdf | ||
*hooks/ | *hooks/ | ||
**enable.js | **enable.js | ||
**disable.js | **disable.js | ||
**upgrade.js | **upgrade.js | ||
Only the hooks that the developer wishes to implement need to be included. A likely common case will be just the | Only the hooks that the developer wishes to implement need to be included. A likely common case will be just the enable hook in order to perform some kind of first run behaviour like creating databases in the profile etc. | ||
==Hook API== | ==Hook API== | ||
| Line 42: | Line 38: | ||
</pre> | </pre> | ||
The ADDON structure may not be protected from being altered by the hook, however | The ADDON structure may not be protected from being altered by the hook, however the structure will get thrown away after the hook is executed. | ||
==Protected operations== | ==Protected operations== | ||
There are certain operations that need to be carefully protected from tampering with by hooks. In particular it should be close to impossible for a disable | There are certain operations that need to be carefully protected from tampering with by hooks. In particular it should be close to impossible for a disable hook to be able to cancel that action. Hooks are not designed to decide whether the operation should proceed, they should perform simple actions in response to the operation. | ||
==When hooks will run== | ==When hooks will run== | ||
Some consideration must be made whether to run hooks during safe mode or whether to potentially defer add-on changes until the next normal startup. | |||
The specific moment when hooks are executed depends on the type of hook: | The specific moment when hooks are executed depends on the type of hook: | ||
=== | ===Enable and upgrade=== | ||
These hooks will get executed in the early UI startup. Likely the final-ui-startup observer will be used to trigger them | These hooks will get executed in the early UI startup. Likely the final-ui-startup observer will be used to trigger them, though if a means of running them after the first UI windows are displayed is found then that would be a better choice. | ||
===Disable | ===Disable=== | ||
The | The disable hook will run during early startup as the add-on is disabled/uninstalled. This hook should not expect to be able to display any UI. Shortly after the hook's execution the application's process will be restarted. | ||
==When hooks won't run== | ==When hooks won't run== | ||
| Line 66: | Line 62: | ||
There are deliberately very few circumstances where hooks would not be executed. | There are deliberately very few circumstances where hooks would not be executed. | ||
The first is due to implementation details. If the directory for the extension in the install location is removed, or if the registry key for the extension in the registry install location is removed then no | The first is due to implementation details. If the directory for the extension in the install location is removed, or if the registry key for the extension in the registry install location is removed then no disable hook will be executed. | ||
Secondly if the add-on is blocklisted then no hooks will be run for that add-on until it is no longer blocklisted. This is obviously important to stop a malicious add-on getting the ability to run code even after being blocked. | Secondly if the add-on is blocklisted then no hooks will be run for that add-on until it is no longer blocklisted. This is obviously important to stop a malicious add-on getting the ability to run code even after being blocked. | ||