From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../tech/xpcom/observer_notifications/index.html | 880 +++++++++++++++++++++ 1 file changed, 880 insertions(+) create mode 100644 files/zh-cn/mozilla/tech/xpcom/observer_notifications/index.html (limited to 'files/zh-cn/mozilla/tech/xpcom/observer_notifications/index.html') diff --git a/files/zh-cn/mozilla/tech/xpcom/observer_notifications/index.html b/files/zh-cn/mozilla/tech/xpcom/observer_notifications/index.html new file mode 100644 index 0000000000..86fdd81a37 --- /dev/null +++ b/files/zh-cn/mozilla/tech/xpcom/observer_notifications/index.html @@ -0,0 +1,880 @@ +--- +title: Observer Notifications +slug: Mozilla/Tech/XPCOM/Observer_Notifications +translation_of: Mozilla/Tech/XPCOM/Observer_Notifications +--- +

Observer topics

+ +

The following are topics that you can observe during the course of an application. Unless otherwise noted you register for the topics using the nsIObserverService.

+ +

Application startup

+ +

These are the topics that you can observe on startup, in order of appearance.

+ +

If your component requires access to the user profile, or any services which require access to the profile (preferences, bookmarks, and so on) then a common pattern is to register with the nsICategoryManager for the app-startup topic which can be done in the component's registration code, and then in that notification register with the observer service for the profile-after-change notification. See Receiving startup notifications for more information about how this works.

+ +

Starting in Firefox 3.5 components can simply register for the profile-after-change notification in nsICategoryManager.

+ + + + + + + + + + + + +
TopicDescription
* +

Everything.  [nsObserverService.cpp]

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDescription
xpcom-startup +

Note: An extension can no longer be registered to receive this notification in Firefox 4 and later. See XPCOM changes in Gecko 2.0 for details.

+ +

Called when xpcom is initialized. Many things are not available for use at this point. To receive this notification you have to register with nsICategoryManager. The registered component is always retrieved as a singleton (That is getService() will be used to instantiate it).

+
app-startup +

Note: An extension can no longer be registered to receive this notification in Firefox 4 and later. See XPCOM changes in Gecko 2.0 for details.

+ +

General event for application startup. To receive this notification you have to register with nsICategoryManager. Prepend "service," to the contract ID in the category registration to be invoked via getService() instead of createInstance().

+
profile-do-changeThis is fired after the profile has been selected. You will not be able to access user preferences, bookmarks, or anything that uses the profile folder until this event occurs. This occurs after any profile migration.
profile-after-change +

This is fired after all the observers for profile-do-change have been notified.

+ +

You can register with nsICategoryManager to receive this notification. Prior to Firefox 3.5, this was available to observers observing the app-startup/xpcom-startup notification.

+
final-ui-startup +

Triggered just before the first window for the application is displayed.

+
sessionstore-windows-restored +

Sent by the session restore process to indicate that all initial browser windows have opened. Note that while the window are open and the chrome loaded the tabs in the windows may still be being restored after this notification.

+ +

Note: This notification is specific to Firefox and SeaMonkey 2.0 applications

+
+ +

Application shutdown

+ +

These are the topics that you can observe on shutdown, in order of appearance.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDescription
quit-application-requestedSomething has requested that the application be shutdown. You can cancel the shutdown from here by setting aSubject.data to true (aSubject is the first parameter to your observer, the data value is an nsISupportsPRBool).
quit-application-grantedAll observers have agreed to the shutdown.
quit-applicationThe application is about to quit. This can be in response to a normal shutdown, or a restart.
Note: The data value for this notification is either 'shutdown' or 'restart'.
profile-change-net-teardownThe network connection is going offline at this point.
Note: The data value for this notification is either 'shutdown-persist' or 'shutdown-cleanse'.
profile-change-teardownPart of the shutdown, profile data is still available at this point.
Note: The data value for this notification is either 'shutdown-persist' or 'shutdown-cleanse'.
profile-before-changeCalled just before the profile is lost.
Note: The data value for this notification is either 'shutdown-persist' or 'shutdown-cleanse'.
xpcom-will-shutdown Called just before xpcom-shutdown. Observer must not spin event loop.
xpcom-shutdownThis is the end. Many things will not be available here.
+ +

Browser

+ +

These topics indicate interesting things that happen that the browser alerts you to.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDescription
browser:purge-session-historySent when the sanitizer runs to purge all history and other information.
browser:purge-domain-dataSent after domain-specific history and other information have been purged. The data value is a string form of the domain.
browser-lastwindow-close-requestedSent when the browser wishes to close the last open browser window. When this is sent, it is possible that other windows may still be open, such as the download manager or preferences. The data value is an nsISupportsPRBool. Recipients may set this to true to abort the close.
browser-lastwindow-close-grantedSent when all interested parties have responded to the browser-lastwindow-close-requested notification and none of them requested that the close be aborted. After this is sent and handled, the browser window will close.
browser-delayed-startup-finishedSent when the browser window and all its components have been loaded and initialized.
+ +

Documents

+ +

These topics indicate notifications you can monitor related to DOM documents.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicSubjectDataDescription
chrome-document-global-created nsIDOMWindownullSent immediately after a chrome document window has been set up, but before any script code has been executed. This lets extensions inject API into chrome windows as needed (see nsIDOMGlobalPropertyInitializer for an alternative method of doing this, which uses significantly less memory).
+ data is intentionally left blank.
content-document-global-created nsIDOMWindoworiginSent immediately after a web content document window has been set up, but before any script code has been executed. This lets extensions inject API into content windows as needed (see nsIDOMGlobalPropertyInitializer for an alternative method of doing this).
+ data is a string form of the origin (for use in security checks), eg "http://developer.mozilla.org".
document-element-inserted DocumentnullSent immediately after the root element of a document has been created, but before executing any script on it.
user-interaction-active nsIDOMWindownull +

Sent once every 5000ms while this chrome document sees some kind of user activity (for example, keyboard or mouse events), and at the exact moment of the state transition from idle to active.

+
user-interaction-inactive nsIDOMWindownull +

Sent when the chrome document has seen no user activity for a while. The notification is not repeated during a continuous inactivity period.

+
+ +

Windows

+ +

These topics indicate points of interest during the lifetime of a window.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
dom-window-destroyed  Called just before a DOM window is destroyed.
inner-window-destroyed  nullCalled when an inner window is removed from the backward/forward cache. See Working With BFCache for information about the bfcache, and Inner and outer windows for details about how the window hierarchy works. Extensions that cache information about windows may wish to observe this so they can release information when the window is destroyed.  The window id can be obtained from subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data
outer-window-destroyed nullCalled when an outer window is disconnected from its docshell.  See Inner and outer windows for details about how the window hierarchy works. Extensions that cache information about windows may wish to observe this so they can release information when the window is destroyed.  The window id can be obtained from subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data
toplevel-window-ready Called just after a new top level window has been opened and is ready, but has not yet loaded a document.
xul-window-destroyed Called just before a XUL window is destroyed.
xul-window-registered Called just after a top level XUL window is registered with the window mediator service.
xul-window-visible Called just after a XUL window is made visible.
+ +

Spelling checker

+ +

These topics indicate activities that have occurred related to the spelling checker.

+ + + + + + + + + + + + + + +
TopicDataDescription
spellcheck-dictionary-update Sent by a spell checker implemented by the mozISpellingChecker interface when something has happened that causes a change that may interest the editor; these are received primarily by nsIEditor.
+ +

IO Notifications

+ +

These topics can be used to watch the IO service for useful information.

+ + + + + + + + + + + + + + + + + + + + +
TopicDescription
offline-requestedCalled to query whether the application can go offline. The attempt to go offline can be canceled. +

Note: If your code chooses to cancel the attempt to go offline, it must notify the user.

+
network:offline-about-to-go-offlineCalled just before all network IO is taken offline.
network:offline-status-changedCalled when the offline state has changed.
Note: The data value for this notification 'offline' or 'online' to indicate the new state.
+ +

HTTP requests

+ +

These are the topics that you can observe during a HTTP request (see Setting HTTP request headers and Creating Sandboxed HTTP Connections). Both are passed an nsIHttpChannel as the subject parameter.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDescription
http-on-modify-requestCalled as a http request is made. The channel is available to allow you to modify headers and such. See this code snippet to learn how to get the tab that issued the request.
http-on-opening-request Similar to http-on-modify-request, but called earlier (synchronously during the channel's asyncOpen() call), and some channel atttributes (proxyInfo) may be missing.  Use only if your observer must be called before asyncOpen returns.
http-on-examine-responseCalled after a response has been received from the web server. Headers are available on the channel. The response can be accessed and modified via nsITraceableChannel.
http-on-examine-cached-response Called instead of http-on-examine-response when a response will be read completely from the cache. Headers are available on the channel.
http-on-examine-merged-responseCalled instead of http-on-examine-response when a response will be read partially from cache, and partially from the network (HTTP 206 or 304 response). Headers are available on the channel.
+ +

Cookies

+ +

These topics indicate whenever a cookie has been changed (added, changed, cleared, or deleted) or its setting rejected by the browser. See nsICookieService for details.

+ + + + + + + + + + + + + + + + +
TopicDescription
cookie-changedCalled upon a cookie change (added, changed, cleared, or deleted)
cookie-rejectedCalled when the setting of a cookie was rejected by the browser (per the user's preferences)
+ +

Download Manager

+ +

These topics indicate that events related to the Download Manager have occurred.

+ + + + + + + + + + + + + + + + +
TopicDescription
download-manager-ui-doneCalled when the list of downloads in the Download Manager windows finishes updating.  This can happen multiple times, such as when the window first opens, when multiple items are removed, and when entering private browsing mode.
download-manager-remove-download Called when a download of the list is removed or all the list is cleared. The subject will be the download id wrapped in nsISupportsPRUint32, for one download removed, or null for multi download remove, for example when the download list is cleared.
+ +

Extension Manager

+ +
+

Note: These notifications are no longer available starting with Gecko 2.0, instead use AddonManager.addAddonListener() to receive similar events.

+
+ +

This topic indicates when the extension manager performs some action. Note that any action will be taken the next time the application starts. See nsIExtensionManager for details.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
em-action-requesteditem-installedA new extension has been installed.
em-action-requesteditem-upgradedA different version of an existing extension has been installed.
em-action-requesteditem-uninstalledAn addon has been marked to be uninstalled.
em-action-requesteditem-enabledAn addon has been enabled.
em-action-requesteditem-disabledAn addon has been disabled.
em-action-requesteditem-cancel-actionA previous action has been cancelled.
+ +

Idle Service

+ +

This topic indicates when actions related to the Idle Service, provided by the nsIIdleService interface. Unlike the user-interaction-active and user-interaction-inactive topics listed above, the Idle Service monitors user activity in general, whether related to the Mozilla application or not (acting somewhat like the user activity/inactivity events a screen saver would be interested in).

+ + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
idleThe length of time the user has been idle, in milliseconds.Sent when the user becomes idle.
idle-dailyThe length of time the user has been idle, in milliseconds.Sent once a day while the user is idle.
backThe length of time the user has been idle, in milliseconds.Sent when the user returns from being idle.
+ +

Computer sleep and wake

+ +

This topic indicates when actions related to the computer going to sleep or waking up occur.  (Note: these notifications are not currently available on Linux.  See bug 758848.)

+ + + + + + + + + + + + + + + + + + + +
TopicDataDescription
sleep_notificationnullSent when the computer is going to sleep.
wake_notificationnullSent when the computer is waking up.
+ +

Login Manager

+ +

This topic indicates when actions related to the Login Manager occur.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
passwordmgr-found-formnoAutofillFormsA login is available for this form, but autofill of forms is disabled, so the form was not automatically filled out. 
passwordmgr-found-formautocompleteOffA login is available for this form, but autocomplete is disabled.
passwordmgr-storage-changedaddLoginA login has been added to the Login Manager's database. The notification's subject is the login that was added to the database.
passwordmgr-storage-changedremoveLoginA login was removed from the Login Manager's database. The notification's subject is the login that was removed from the database.
passwordmgr-storage-changedmodifyLoginA login in the Login Manager's database was modified. The notification's subject is an array whose first entry is the old login and whose second entry is the new one.
passwordmgr-storage-changedremoveAllLoginsAll logins have been removed from the Login Manager's database.
passwordmgr-storage-changedhostSavingEnabledHost saving has been enabled.
passwordmgr-storage-changedhostSavingDisabledHost saving has been disabled.
+ +

Places

+ +

This topic indicates when actions related to Places (the history and bookmarks database) occur.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
places-autocomplete-feedback-updated Sent when Places updates the location bar's autocompletion display.
places-connection-closed Sent after Places has closed its database connection. Once this has been sent, no Places features will work.
places-connection-closing  +

Sent as the last notification before the Places service closes its database connection.

+ +
Warning: This is for internal use only.
+
places-database-locked The Places database is currently locked by a third-party process and cannot be opened.
places-favicons-expired Sent when all favicons have been expired.
places-init-complete The Places database has been successfully initialized. You should wait until this notification occurs before querying the places database.
places-maintenance-finished Sent when maintenance of the Places database is complete; this is done periodically in the background to keep the Places database tidy.
places-shutdown Sent when Places shuts down. If you are referencing instances of mozIStorageStatement referencing Places databases when this notification occurs, you should call their mozIStorageStatement.finalize() method
places-sync-finished Sent when the Places database has been successfully flushed to disk.
places-will-close-connection  +

Sent when the Places service is about to close its database connection. Only necessary cleanup tasks should run at this point, and nothing should be added to the database. In addition, after this has been sent, no Places APIs should be called.

+ +
Warning: This is for internal use only.
+
+ +

Session Store

+ +

These topics are used when actions related to Session Store occur.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
sessionstore-state-read Sent immediately after session store data is read and before it's used.
sessionstore-state-finalized Sent immediately after the session is restored.
sessionstore-state-write Sent immediately before the session store data is written to disk.
sessionstore-state-write-complete Sent immediately after the session store data is written to disk.
sessionstore-state-purge-complete  
+ +

Private browsing

+ +

These topics indicate when actions related to private browsing occur.

+ + + + + + + + + + + + + + + + + + + +
TopicDataDescription
private-browsingenterSent when private browsing mode is activated.
private-browsingexitSent when private browsing mode is deactivated.
+ +

Bookmarks

+ +

These topics indicate when actions related to bookmarks occur.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
bookmarks-restore-beginjsonSent just before bookmarks are restored from JSON.
bookmarks-restore-beginhtmlSent just before bookmarks are restored from HTML. If bookmarks will be restored into a specific folder, observers will be passed an nsISupportsPRInt64 through their subject parameters indicating the ID of the folder. The subject is null otherwise.
bookmarks-restore-beginhtml-initialSent just before bookmarks are restored from HTML on initial import. If bookmarks are restored into a specific folder, observers will be passed an nsISupportsPRInt64 through their subject parameters indicating the ID of the folder. The subject is null otherwise.
bookmarks-restore-successjsonSent just after bookmarks are restored from JSON.
bookmarks-restore-successhtmlSent just after bookmarks are restored from HTML. If bookmarks were restored into a specific folder, observers will be passed an nsISupportsPRInt64 through their subject parameters indicating the ID of the folder. The subject is null otherwise.
bookmarks-restore-successhtml-initialSent just after bookmarks are restored from HTML on initial import. If bookmarks were restored into a specific folder, observers will be passed an nsISupportsPRInt64 through their subject parameters indicating the ID of the folder. The subject is null otherwise.
bookmarks-restore-failedjsonSent when bookmarks could not be sucessfully restored from JSON.
bookmarks-restore-failedhtmlSent when bookmarks could not be successfully restored from HTML. If bookmarks were to have been restored into a specific folder, observers will be passed an nsISupportsPRInt64 through their subject parameters indicating the ID of the folder. The subject is null otherwise.
bookmarks-restore-failedhtml-initialSent when bookmarks could not be successfully restored from HTML on intial import. If bookmarks were to have been restored into a specific folder, observers will be passed an nsISupportsPRInt64 through their subject parameters indicating the ID of the folder. The subject is null otherwise.
+ +

Themes

+ +

These topics indicate when actions related to themes occur.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
lightweight-theme-preview-requested jsonSent when the user requests to preview a lightweight theme, but before existing windows are styled with the new theme.
lightweight-theme-change-requested jsonSent to indicate that the user has chosen a new theme in the add-ons manager, but before the change takes effect.
lightweight-theme-changed -Sent after the current theme is changed.
lightweight-theme-styling-update jsonSent when the current theme being used is changed; this is sent even when the user is previewing a theme, not just when the theme is actually selected.
lightweight-theme-list-changed -The list of available lightweight themes has changed.
+ +

Developer tools

+ +

These topics let you know about things that have happened related to Firefox's built-in developer tools.

+ +

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TopicDataDescription
highlighter-ready - +

Sent when the highlighter component is initialized.

+ +
Note: This is used by the Inspector to detect when it should begin its initialization process.
+
inspector-closed -Sent when the Inspector tool is closed.
inspector-editor-closed -Sent after the attribute-value editor has been closed.
inspector-editor-opened -Sent after the attribute-value editor has been opened and initialized.
inspector-editor-saved -Sent when changes have been saved in the attribute-value editor.
inspector-highlighting -Sent every time a different node in the page gets highlighted.
inspector-opened -Sent after the Inspector tool has finished its initialization.
inspector-ruleview-ready -Sent when the inspector's CSS Rule View is opened and initialized.
inspector-state-restored -Sent when the Inspector is re-opened after a tab switch.
inspector-treepanel-ready -Sent when the Inspector's Tree Panel is opened and initialized.
inspector-unhighlighting -Sent every time the highlighter stops highlighting a node.
+ +

Telemetry

+ + + + + + + + + + + + + + +
TopicDataDescription
gather-telemetry -Sent by the telemetry service when it's time to start gathering telemetry data, since the telemetry ping is coming soon.
+ +

Plugins

+ + + + + + + + + + + + + + +
TopicDataDescription
plugin-crashed-Sent when a plugin has crashed.
+ +

 

-- cgit v1.2.3-54-g00ecf