Extension Manager:Install Hooks: Difference between revisions

no edit summary
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 installed or uninstalled. While there are currently ways to detect this they are not totally reliable and fail in many situations.
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:


* Installation
* Enabling (also runs during add-on installation)
* Uninstallation
* Disabling (also runs if an enabled add-on is uninstalled)
* Enabling
* Disabling (either by user choice or application incompatibilities)
* Upgrading
* Upgrading


Line 19: Line 17:
*install.rdf
*install.rdf
*hooks/
*hooks/
**install.js
**enable.js
**enable.js
**disable.js
**disable.js
**uninstall.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 install hook in order to perform some kind of first run behaviour like creating databases in the profile etc.
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 no alterations to it will have any effect.
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/uninstall 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.
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==


It is important to note that aside from some exceptions listed later, this specification suggests that hooks will always be executed. This means that even if an add-on is disabled when it is uninstalled then the uninstall hook will still execute. 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.
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:


===Install, enable and upgrade===
===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. This means that there will be no main application window yet.
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 and uninstall===
===Disable===


The hooks that are focused on stopping the extension from executing will run during early startup as the add-on is disabled/uninstalled. These hooks should not expect to be able to display any UI. Shortly after the hook's execution the application's process will be restarted
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 uninstall hook will 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 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.
canmove, Confirmed users
1,570

edits