From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/ru/mozilla/tech/xpcom/index.html | 47 +++ files/ru/mozilla/tech/xpcom/reference/index.html | 21 ++ .../tech/xpcom/reference/interface/index.html | 17 + .../interface/nsidomhtmlmediaelement/index.html | 29 ++ .../reference/interface/nsiloginmanager/index.html | 372 +++++++++++++++++++++ .../using_nsiloginmanager/index.html | 169 ++++++++++ 6 files changed, 655 insertions(+) create mode 100644 files/ru/mozilla/tech/xpcom/index.html create mode 100644 files/ru/mozilla/tech/xpcom/reference/index.html create mode 100644 files/ru/mozilla/tech/xpcom/reference/interface/index.html create mode 100644 files/ru/mozilla/tech/xpcom/reference/interface/nsidomhtmlmediaelement/index.html create mode 100644 files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/index.html create mode 100644 files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/using_nsiloginmanager/index.html (limited to 'files/ru/mozilla/tech/xpcom') diff --git a/files/ru/mozilla/tech/xpcom/index.html b/files/ru/mozilla/tech/xpcom/index.html new file mode 100644 index 0000000000..07687c0f82 --- /dev/null +++ b/files/ru/mozilla/tech/xpcom/index.html @@ -0,0 +1,47 @@ +--- +title: XPCOM +slug: Mozilla/Tech/XPCOM +tags: + - Landing + - Mozilla + - NeedsTranslation + - TopicStub + - XPCOM +translation_of: Mozilla/Tech/XPCOM +--- +

XPCOM is a cross platform component object model, similar to Microsoft COM. It has multiple language bindings, allowing XPCOM components to be used and implemented in JavaScript, Java, and Python in addition to C++. Interfaces in XPCOM are defined in a dialect of IDL called XPIDL.

+ +
+

XPCOM is no longer available for use by Firefox extensions. Use WebExtensions instead.

+
+ +

XPCOM itself provides a set of core components and classes, e.g. file and memory management, threads, basic data structures (strings, arrays, variants), etc. The majority of XPCOM components are not part of this core set and are provided by other parts of the platform (e.g. Gecko or Necko) or by an application or even by an extension.

+ +
+
Accessing the Windows Registry Using XPCOM
When implementing Windows-specific functionality, it is often useful to access the Windows registry for information about the environment or other installed programs. To this end, there exist XPCOM interfaces to read and write registry data. This article will show you how to use the available interfaces in several Mozilla products.
Aggregating the In-Memory Datasource
already_AddRefed
already_AddRefed in association with nsCOMPtr allows you to assign in a pointer without AddRefing it.
Binary compatibility
If Mozilla decides to upgrade to a compiler that does not have the same ABI as the current version, any built component may fail. It is a possiblity that is introduced when upgrading to a new compiler without recompiling everything. Effectively, it is a different platform.
Bundling multiple binary components
Binary XPCOM components are sometimes required to implement low-level features for extensions. Since binary components are linked against a single Gecko SDK, a dependency to a particular version of Gecko is created. If the component uses only "frozen" XPCOM interfaces, there is a good chance the same binary component will work with different versions of Gecko (version 1.8 and 1.9, for example). The more likely case is that the component uses "unfrozen" interfaces and those interfaces can change between Gecko versions. This can create a difficult situation for extension developers trying to support multiple Gecko versions (Firefox 2 and 3, for example).
Creating a Python XPCOM component
Creating Applications with Mozilla already provides a tutorial for making a simple JavaScript or C++ component (implementing the nsISimple interface). Here is how to make the same component in Python using PyXPCOM.
Fun With XBL and XPConnect
Generating GUIDs
GUIDs are used in Mozilla programming for identifying several types of entities, including XPCOM Interfaces (this type of GUIDs is callled IID), components (CID), and legacy add-ons—like extensions and themes—that were created prior to Firefox 1.5. Add-ons can (and should) be identified with IDs of the form extensionname@organization.tld since Firefox 1.5.
Generic factory
Most XPCOM factories can be very simple. Rick Potts wrote a templated-based generic factory (nsFactory<t>) that simplifies the factory creation process that just requires writing a CreateInstance() method. The new nsIGenericFactory interface takes this a step further, by providing a single interface that can be reused anytime a simple implementation of nsIFactory is needed. Here is the interface, and a description of its use.</t>
How to build a binary XPCOM component using Visual Studio
This is a simple tutorial for building XPCOM objects in C++ using Visual Studio. XPCOM is Mozilla’s cross platform component object model, similar to Microsoft’s COM technology. XPCOM components can be implemented in C, C++, and JavaScript, and can be used from C, C++, and JavaScript. That means you can call JavaScript methods from C++ and vice versa. For more information on the workings of XPCOM look elsewhere.
How To Pass an XPCOM Object to a New Window
If you want to be able to call functions within an XPCOM object from a XUL window's code, you can do so if you pass the XPCOM object as one of the arguments to the window creation method.
Interfacing with the XPCOM cycle collector
This is a quick overview of the cycle collector introduced into XPCOM for Firefox 3, including a description of the steps involved in modifying an existing C++ class to participate in XPCOM cycle collection. If you have a class that you think is involved in a cyclical-ownership leak, this page is for you.
Introduction to XPCOM for the DOM
Warning: this document has not yet been reviewed by the DOM gurus, it might contain some errors.
Language bindings
An XPCOM Language Binding is a bridge between a particular language and XPCOM to provide access to XPCOM objects from that language, and to let modules written in that language be used as XPCOM objects by all other languages for which there are XPCOM bindings.
Monitoring HTTP activity
Gecko includes the nsIHttpActivityObserver interface, which you can implement in your code to monitor HTTP transactions in real time, receiving a callback as the transactions take place.
nsCOMPtr versus RefPtr
Gecko code uses both nsCOMPtr and RefPtr as smart pointers. This guide provides some explanation and advice on how to choose between them.
Observer Notifications
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.
Setting HTTP request headers
HTTP is one of the core technologies behind the Web. In addition to the actual content, some important information is passed with HTTP headers for both HTTP requests and responses.
Storage
Storage is a SQLite database API. It is available to trusted callers, meaning extensions and Firefox components only.
The Thread Manager
The Thread Manager, introduced in Firefox 3, offers an easy to use mechanism for creating threads and dispatching events to them for processing.
+
Troubleshooting XPCOM components registration
Often the first time you create an XPCOM component, it may fail to register correctly.
Using nsCOMPtr
This document is the sum total of everything written down about nsCOMPtr. If you have a question about nsCOMPtr, and this document doesn't answer it, there probably isn't a document that answers it. You'll have to turn to the XPCOM newsgroup or another experienced nsCOMPtr user, or find the answer by experimentation.
Using nsIClassInfo
If you use a C++ class which implements nsIClassInfo from JavaScript, then you don't have to explicitly call QueryInterface on the JavaScript object to access the object's interfaces.
Using nsIDirectoryService
nsDirectoryService implements the nsIProperties interface. This implementation will allow you to Get(), Set(), Define(), and Undefine() nsIFile.
Using nsIPasswordManager
Technical review completed.
Using nsISimpleEnumerator
Using the clipboard
This section provides information about cutting, copying, and pasting to and from the clipboard.
Using the Gecko SDK
Weak reference
In XPCOM, a weak reference is a special object that contains a pointer to an XPCOM object, but doesnot keep that object alive. If the referent object is destroyed before the weak reference, the pointer inside the weak reference is set to nsnull.
Working with Multiple Versions of Interfaces
In this short note we illustrate how one can update an XPCOM module in +order for it to work in both Firefox 2 and Firefox 3, even if the interfaces have +changed in the interim.
Working with out parameters
wrappedJSObject
wrappedJSObject is a property sometimes available on XPConnect wrappers. When available, it lets you access the JavaScript object hidden by the wrapper.
XPCOM ABI
XPCOM ABI is the binary interface of XPCOM components. While XPCOM components written in a scripting language (such as JavaScript) can be moved across platforms (such as Windows and OS X) without adaptation, those written in a compiled language (such as C++) require recompilation when moving to a different platform. Often, compiled XPCOM components are called 'binary' or 'native'.
XPCOM category image-sniffing-services
In versions of Firefox prior to Firefox 3, extensions could add decoders for new image types. However, such decoders relied on servers sending correct MIME types; images sent with incorrect MIME types would not be correctly displayed.
XPCOM glue
The XPCOM Glue is a static library which component developers and embedders can link against. It allows developers to link only against the frozen XPCOM method symbols and maintain compatibility with multiple versions of XPCOM.
XPCOM guide
These articles provide tutorials and usage documentation for XPCOM, including how to use it in your own projects and how to build XPCOM components for your Firefox add-ons and the like.
XPCOM ownership guidelines
...naturally. If you create a temporary object, obviously it's up to you to destroy it. That's a sure sign of ownership. If you create an object with a longer lifespan, you will own it until you give ownership away.
XPCOM reference
This reference describes the interfaces and functions provided by the XPCOM library. In addition, it details the various helper classes and functions, as well as the components, provided by the XPCOM glue library. The contents herein are oriented primarily toward extension developers and people embedding XPCOM in other projects.
XPCOM tasks
The XPCOM module roughly parallels the C/C++ standard libraries. It overlaps them significantly, but goes beyond them in capabilities. XPCOM sits above the standard libraries. Its role is to extend them with facilities tailored to XPCOM development in general, and specifically the needs of Mozilla. Like the standard libraries, XPCOM must be a fairly self-contained library, so as not to encumber clients with any unnecessary external dependencies.
XPCOM Thread Synchronization
XPCOM thread synchronization primitives have the same semantics as those in NSPR, and each method of these synchronization objects (e.g. Mutex::Lock()) has a matching function in NSPR (PR_Lock()). This is no accident, as mozilla:: primitives are merely bare-minimum wrappers around NSPR's.
xptcall FAQ
xptcall is a small low level XPCOM method call library. It is implemented using platform specific C/C++ and assembly language code. It is used to facilitate cross language and cross thread method calls. Porting this code is required in order to make Mozilla run on any given platform.
Xptcall Porting Guide
Original Author: John Bandhauer, 31 May 1999.
Xptcall Porting Status
This is a status page for the multiplatform porting of xptcall. xptcall has a FAQ and a Porting Guide.
+
+ +
+ +
+

Join the XPCOM community

+
+
Choose your preferred method for joining the discussion:
+ +
+ +
+
+ + diff --git a/files/ru/mozilla/tech/xpcom/reference/index.html b/files/ru/mozilla/tech/xpcom/reference/index.html new file mode 100644 index 0000000000..7724292115 --- /dev/null +++ b/files/ru/mozilla/tech/xpcom/reference/index.html @@ -0,0 +1,21 @@ +--- +title: XPCOM reference +slug: Mozilla/Tech/XPCOM/Reference +tags: + - Landing + - Mozilla + - NeedsTranslation + - Reference + - TopicStub + - XPCOM +translation_of: Mozilla/Tech/XPCOM/Reference +--- +

This reference describes the interfaces and functions provided by the XPCOM library. In addition, it details the various helper classes and functions, as well as the components, provided by the XPCOM glue library. The contents herein are oriented primarily toward extension developers and people embedding XPCOM in other projects.

+
+

Note: If you're working on a module in the Mozilla codebase that's compiled with the MOZILLA_INTERNAL_API flag set, some of these APIs -- the string functions and classes in particular -- are not the ones you should be using. See the XPCOM internal string guide for documentation of the internal string API used within the Mozilla codebase.

+
+

+
+
XPCOM Interface Reference
This is a reference to the XPCOM interfaces provided by the Mozilla platform.
+

+

Many XPCOM pages return an nsresult. Prior to Gecko 19 (Firefox 19 / Thunderbird 19 / SeaMonkey 2.16), this was an integer that simply returned an error code. It is now a strongly typed enum when XPCOM is built using a C++11 compiler. This causes compile-time errors to occur when improper values are returned as nsresult values, thereby making it easier to catch many bugs.

diff --git a/files/ru/mozilla/tech/xpcom/reference/interface/index.html b/files/ru/mozilla/tech/xpcom/reference/interface/index.html new file mode 100644 index 0000000000..61f0ae4fca --- /dev/null +++ b/files/ru/mozilla/tech/xpcom/reference/interface/index.html @@ -0,0 +1,17 @@ +--- +title: XPCOM Interface Reference +slug: Mozilla/Tech/XPCOM/Reference/Interface +tags: + - NeedsTranslation + - TopicStub + - XPCOM + - XPCOM Interface Reference +translation_of: Mozilla/Tech/XPCOM/Reference/Interface +--- +

This is a reference to the XPCOM interfaces provided by the Mozilla platform.

+
+
+

See also

+ diff --git a/files/ru/mozilla/tech/xpcom/reference/interface/nsidomhtmlmediaelement/index.html b/files/ru/mozilla/tech/xpcom/reference/interface/nsidomhtmlmediaelement/index.html new file mode 100644 index 0000000000..90109df203 --- /dev/null +++ b/files/ru/mozilla/tech/xpcom/reference/interface/nsidomhtmlmediaelement/index.html @@ -0,0 +1,29 @@ +--- +title: nsIDOMHTMLMediaElement +slug: Mozilla/Tech/XPCOM/Reference/Interface/NsIDOMHTMLMediaElement +translation_of: Web/API/DOMMatrixReadOnly/translate +--- +
+
+
dom/interfaces/html/nsIDOMHTMLMediaElement.idlScriptable
+The basis for the nsIDOMHTMLAudioElement and nsIDOMHTMLVideoElement interfaces, which in turn implement the <audio> and <video> HTML5 elements. + +
+
1.0
+ +
67
+ +
+ +
+ +
Introduced
+ +
Gecko 1.9.1
+
+ +
Inherits from: nsIDOMHTMLElement Last changed in Gecko 1.1
+
+
+ +
The nsIDOMHTMLMediaElement interface implements the DOM HTMLMediaElement interface. See that page for details.
diff --git a/files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/index.html b/files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/index.html new file mode 100644 index 0000000000..8fe801e95f --- /dev/null +++ b/files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/index.html @@ -0,0 +1,372 @@ +--- +title: nsILoginManager +slug: Mozilla/Tech/XPCOM/Reference/Interface/nsILoginManager +tags: + - Firefox 3 + - Interfaces + - 'Interfaces:Scriptable' + - Login Manager + - NeedsTranslation + - Thunderbird 3 + - TopicStub + - XPCOM + - XPCOM API Reference + - thunderbird +translation_of: Mozilla/Tech/XPCOM/Reference/Interface/nsILoginManager +--- +

+
toolkit/components/passwordmgr/public/nsILoginManager.idlСо скриптами
+ + +Used to interface with the built-in Password Manager + + +
+ +
1.0
+ +
66
+ +
+ +
+ +
Introduced
+
Gecko 1.9
+ +
+ +
+ +
+Наследуется из: nsISupports +Последнее изменение в Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)
+

+

Replaces nsIPasswordManager which was used in older versions of Gecko.

+

Implemented by: @mozilla.org/login-manager;1. To create an instance, use:

+
var loginManager = Components.classes["@mozilla.org/login-manager;1"]
+                   .getService(Components.interfaces.nsILoginManager);
+
+

Method overview

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void addLogin(in nsILoginInfo aLogin);
nsIAutoCompleteResult autoCompleteSearch(in AString aSearchString, in nsIAutoCompleteResult aPreviousResult, in nsIDOMHTMLInputElement aElement);
unsigned long countLogins(in AString aHostname, in AString aActionURL, in AString aHttpRealm);
boolean fillForm(in nsIDOMHTMLFormElement aForm);
void findLogins(out unsigned long count, in AString aHostname, in AString aActionURL, in AString aHttpRealm, [retval, array, size_is(count)] out nsILoginInfo logins);
void getAllDisabledHosts([optional] out unsigned long count, [retval, array, size_is(count)] out wstring hostnames);
void getAllLogins([optional] out unsigned long count, [retval, array, size_is(count)] out nsILoginInfo logins);
boolean getLoginSavingEnabled(in AString aHost);
void modifyLogin(in nsILoginInfo oldLogin, in nsISupports newLoginData);
void removeAllLogins();
void removeLogin(in nsILoginInfo aLogin);
void searchLogins(out unsigned long count, in nsIPropertyBag matchData, [retval, array, size_is(count)] out nsILoginInfo logins);
void setLoginSavingEnabled(in AString aHost, in boolean isEnabled);
+

Methods

+

addLogin()

+

Stores a new login in the Login Manager.

+

Примечание: Default values for the nsILoginMetaInfo properties are created if the specified login doesn't explicitly specify them.

+
void addLogin(
+  in nsILoginInfo aLogin
+);
+
+
Parameters
+
+
+ aLogin
+
+ The login to store.
+
+
Exceptions thrown
+
+
+  
+
+ An exception is thrown if the login information is already stored in the Login Manager. To change a login, you have to use modifyLogin().
+
+

autoCompleteSearch()

+

Generates results for a user field autocomplete menu.

+

Примечание: This method is provided for use only by the FormFillController, which calls it directly. It should not be used for any other purpose.

+
nsIAutoCompleteResult autoCompleteSearch(
+  in AString aSearchString,
+  in nsIAutoCompleteResult aPreviousResult,
+  in nsIDOMHTMLInputElement aElement
+);
+
+
Parameters
+
+
+ aSearchString
+
+ Missing Description
+
+ aPreviousResult
+
+ Missing Description
+
+ aElement
+
+ Missing Description
+
+
Return value
+

Missing Description

+

countLogins()

+

Returns the number of logins matching the specified criteria. Called when only the number of logins is needed, and not the actual logins (which avoids prompting the user for a Master Password, as the logins don't need to be decrypted).

+
unsigned long countLogins(
+  in AString aHostname,
+  in AString aActionURL,
+  in AString aHttpRealm
+);
+
+
Parameters
+
+
+ aHostname
+
+ The hostname to which to restrict searches, formatted as a URL. For example, "http://www.bar.com". To match all hostnames, specify "" (empty string). A value of null will cause countLogins() to not match any logins.
+
+ aActionURL
+
+ For form logins, this parameter should specify the URL to which the form will be submitted. To match any form login, specify "" (empty string). To not match any form logins (For example when interested in protocol logins only), specify null.
+
+ aHttpRealm
+
+ For protocol logins, specify the HTTP Realm for which the login applies; this is obtained from the WWW-Authenticate header (see RFC 2617). To match any protocol login, specify "" (empty string). To not match any protocol logins (For example when interested in form logins only), specify null.
+
+
Return value
+

The number of logins matching the parameters passed.

+

fillForm()

+

Fills out a form with login information, if appropriate information is available.

+

Примечание: This method will attempt to fill out the form regardless of the setting of the signon.autofillForms preference.

+
boolean fillForm(
+  in nsIDOMHTMLFormElement aForm
+);
+
+
Parameters
+
+
+ aForm
+
+ The HTMLform to attempt to fill out.
+
+
Return value
+

true if the form was successfully filled out; otherwise false.

+

findLogins()

+

Searches for logins matching the specified criteria. Called when looking for logins that might be applicable to a given form or authentication request.

+
void findLogins(
+  out unsigned long count,
+  in AString aHostname,
+  in AString aActionURL,
+  in AString aHttpRealm,
+  [retval, array, size_is(count)] out nsILoginInfo logins
+);
+
+
Parameters
+
+
+ count
+
+ The number of elements in the returned array. JavaScript callers can simply use the array's length property and supply a dummy argument for this parameter.
+
+ aHostname
+
+ The hostname to restrict searches to, formatted as a URL. For example, "http://www.bar.com".
+
+ aActionURL
+
+ For form logins, this parameter should specify the URL to which the form will be submitted. For protocol logins, specify null. An empty string ("") will match any value (except null).
+
+ aHttpRealm
+
+ For protocol logins, specify the HTTP Realm for which the login applies; this is obtained from the WWW-Authenticate header (see RFC 2617). For form logins, this parameter should be null. An empty string ("") will match any value (except null).
+
+ logins
+
+ An array of nsILoginInfo objects.
+
+
Example
+

This method can be called from JavaScript like this:

+
 var logins = myLoginMgr.findLogins({}, hostname, ...);
+
+

getAllDisabledHosts()

+

Returns a list of all hosts for which login saving is disabled.

+
void getAllDisabledHosts(
+  [optional] out unsigned long count,
+  [retval, array, size_is(count)] out wstring hostnames
+);
+
+
Parameters
+
+
+ count
+
+ The number of elements in the returned array. JavaScript callers can simply use the array's length property and supply a dummy argument for this parameter.
+
+ hostnames
+
+ An array of hostname strings in URL format without a pathname. For example: "https://www.site.com".
+
+
Example
+

You can call this method from JavaScript like this:

+
 var disabledHosts = myLoginMgr.getAllDisabledHosts({});
+
+

getAllLogins()

+

Returns an array containing all logins recorded by the Login Manager.

+

If you just want to see if any logins are stored, use countLogins() instead. It's more efficient, and avoids the possibility of the user being prompted for their master password.

+
void getAllLogins(
+  [optional] out unsigned long count,
+  [retval, array, size_is(count)] out nsILoginInfo logins
+);
+
+
Parameters
+
+
+ count
+
+ The number of elements in the returned array. JavaScript callers can simply use the array's length property and supply a dummy argument for this parameter.
+
+ logins
+
+ An array of nsILoginInfo objects containing all the logins the Login Manager has on record.
+
+
Example
+

You can call this method from JavaScript like this:

+
 var logins = myLoginMgr.getAllLogins({});
+
+

getLoginSavingEnabled()

+

Reports whether or not saving login information is enabled for a host.

+
boolean getLoginSavingEnabled(
+  in AString aHost
+);
+
+
Parameters
+
+
+ aHost
+
+ The hostname to check. This argument should be in the origin URL format, with no pathname. For example: "https://www.site.com".
+
+
Return value
+

true if login saving is enabled for the host, otherwise false.

+

modifyLogin()

+

Modifies an existing login by replacing it with a new one.

+

If newLoginData is a nsILoginInfo, all of the old login's nsILoginInfo properties are changed to the values from newLoginData (but the old login's nsILoginMetaInfo properties are unmodified).

+

If newLoginData is a nsIPropertyBag, only the specified properties will be changed. The nsILoginMetaInfo properties of oldLogin can be changed in this manner.

+

If the propertybag contains an item named "timesUsedIncrement", the login's timesUsed property will be incremented by the item's value.

+
void modifyLogin(
+  in nsILoginInfo oldLogin,
+  in nsISupports newLoginData
+);
+
+
Parameters
+
+
+ oldLogin
+
+ The login to be modified.
+
+ newLoginData
+
+ The login information to replace the oldLogin with. This may be specified as either an nsILoginInfo or an nsIPropertyBag2 object.
+
+

removeAllLogins()

+

Removes all logins known by the Login Manager. This works without a need for the master password, if one is set.

+
void removeAllLogins();
+
+
Parameters
+

None.

+

removeLogin()

+

Removes a login from the Login Manager.

+

Примечание: The specified login must exactly match a stored login. However, the values of any nsILoginMetaInfo properties are ignored.

+
void removeLogin(
+  in nsILoginInfo aLogin
+);
+
+
Parameters
+
+
+ aLogin
+
+ The login to remove from the Login Manager. Only a login that is an exact match is deleted.
+
+

searchLogins()

+

Searches for logins in the login manager's data store, returning an array of matching logins. If there are no matching logins, an empty array is returned.

+
void searchLogins(
+  out unsigned long count,
+  in nsIPropertyBag matchData,
+  [retval, array, size_is(count)] out nsILoginInfo logins
+);
+
+
Parameters
+
+
+ count
+
+ The number of elements in the returned array.
+
+ matchData
+
+ The data used for the search. This does not follow the same requirements as findLogins() for those fields; wildcard matches are not specified.
+
+ logins
+
+ An array of matching nsILoginInfo objects.
+
+
Example
+

This method can be called from JavaScript like this:

+
 var logins = myLoginMgr.searchLogins({}, matchData);
+ var numLogins = logins.length;
+
+

setLoginSavingEnabled()

+

Enables or disables storing logins for a specified host. When login storing is disabled, the Login Manager won't prompt the user to store logins for that host. Existing logins are not affected.

+
void setLoginSavingEnabled(
+  in AString aHost,
+  in boolean isEnabled
+);
+
+
Parameters
+
+
+ aHost
+
+ The hostname to adjust the setting for. This argument should be in the origin URL format, with no pathname. For example: "https://www.site.com".
+
+ isEnabled
+
+ If true, login saving is enabled for the specified host. If false, login saving is disabled.
+
+

See also

+ +

diff --git a/files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/using_nsiloginmanager/index.html b/files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/using_nsiloginmanager/index.html new file mode 100644 index 0000000000..16c2c5a029 --- /dev/null +++ b/files/ru/mozilla/tech/xpcom/reference/interface/nsiloginmanager/using_nsiloginmanager/index.html @@ -0,0 +1,169 @@ +--- +title: Using nsILoginManager +slug: Mozilla/Tech/XPCOM/Reference/Interface/nsILoginManager/Using_nsILoginManager +translation_of: Mozilla/Tech/XPCOM/Reference/Interface/nsILoginManager/Using_nsILoginManager +--- +
+
+

Working with the Login Manager

+

Extensions often need to securely store passwords to external sites, web applications, and so on. To do so securely, they can use nsILoginManager, which provides for secure storage of sensitive password information and nsILoginInfo, which provides a way of storing login information.

+

Getting nsILoginManager

+

To get a component implementing nsILoginManager, use the following:

+
+
var passwordManager = Components.classes["@mozilla.org/login-manager;1"].getService(
+	Components.interfaces.nsILoginManager
+);
+
+

Most Login Manager functions take an nsILoginInfo object as a parameter. An nsILoginInfo object contains the following attributes: hostname, form submit URL, HTTP realm, username, username field, password, and password field. The hostname, username and password attributes are mandatory, while the other fields are set based on whether the login is for a web page form or an HTTP/FTP authentication site login. See the nsILoginInfo attribute definitions for more details. Defining an nsILoginInfo object is simple:

+
+
var nsLoginInfo = new Components.Constructor(
+	"@mozilla.org/login-manager/loginInfo;1",
+	Components.interfaces.nsILoginInfo,
+	"init"
+);
+
+var loginInfo = new nsLoginInfo(
+	hostname, formSubmitURL, httprealm, username, password, usernameField, passwordField
+);
+
+
+

Examples

+

Creating a login for a web page

+
var formLoginInfo = new nsLoginInfo(
+	'http://www.example.com',
+	'http://login.example.com',
+	null,
+	'joe',
+	'SeCrEt123',
+	'uname',
+	'pword'
+);
+

This login would correspond to a HTML form such as:

+
<form action="http://login.example.com/foo/authenticate.cgi">
+	<div>Please log in.</div>
+	<label>Username:</label> <input type="text" name="uname">
+	<label>Password:</label> <input type="password" name="pword">
+</form>
+
+

Creating a site authentication login

+
var authLoginInfo = new nsLoginInfo(
+	'http://www.example.com',
+	null,
+	'ExampleCo Login',
+	'alice',
+	'SeCrEt321',
+	"",
+	""
+);
+
+

This would correspond to a login on http://www.example.com when the server sends a reply such as:

+
 HTTP/1.0 401 Authorization Required
+ Server: Apache/1.3.27
+ WWW-Authenticate: Basic realm="ExampleCo Login"
+
+
+

Creating a local extension login

+
var extLoginInfo = new nsLoginInfo(
+	'chrome://firefoo',
+	null,
+	'User Registration',
+	'bob',
+	'123sEcReT',
+	"",
+	""
+);
+

From a component creating a new info block is done slightly differently:

+
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init");
+var extLoginInfo = new nsLoginInfo('chrome://firefoo', null, 'User Registration', 'bob', '123sEcReT', '', '');
+//var extLoginInfo = new nsLoginInfo(aHostname, aFormSubmitURL, aHttpRealm, aUsername, aPassword, aUsernameField, aPasswordField)
+
+

The Login Manager treats this as if it was a web site login. You should use your extension's chrome:// URL to prevent conflicts with other extensions, and a realm string which briefly denotes the login's purpose.

+

Storing a password

+

To store a password in the Login Manager, you first need to create an nsILoginInfo object as defined above. Then you simply need to call the nsILoginManager method addLogin().

+
myLoginManager.addLogin(loginInfo);
+
+

Примечание: This will throw an exception if both the httprealm and formSubmitURL parameters are NULL. One must be specified when storing a password. The hostname, username and password parameters are also mandatory.

+

Retrieving a password

+

Retrieving a password from the Login Manager is slightly more difficult. In order to locate a password, the hostname, formSubmitURL and httprealm must match exactly what is stored for the password to be found. The only exception is that if the stored formSubmitURL is blank, in which case the formSubmitURL parameter is ignored. Note that the hostname and formSubmitURL arguments should not include the path from the full URL. The example below should serve as a starting point for matching form logins:

+
var hostname = 'http://www.example.com';
+var formSubmitURL = 'http://www.example.com';  // not http://www.example.com/foo/auth.cgi
+var httprealm = null;
+var username = 'user';
+var password;
+
+try {
+	// Get Login Manager
+	var myLoginManager = Components.classes["@mozilla.org/login-manager;1"].
+		getService(Components.interfaces.nsILoginManager);
+
+	// Find users for the given parameters
+	var logins = myLoginManager.findLogins({}, hostname, formSubmitURL, httprealm);
+
+	// Find user from returned array of nsILoginInfo objects
+	for (var i = 0; i < logins.length; i++) {
+		if (logins[i].username == username) {
+			password = logins[i].password;
+			break;
+		}
+	}
+}
+
+catch(ex) {
+	// This will only happen if there is no nsILoginManager component class
+}
+

Note that the user will be prompted for their master password if they have chosen to set one to secure their passwords.

+

Removing a password

+

Removing a password is simple:

+
myLoginManager.removeLogin(loginInfo);
+
+

When removing a password the specified nsILoginInfo object must exactly match what was stored or an exception will be thrown. This includes the password attribute. Here's an example on how to remove the password without actually knowing what the password is:

+
// example values
+var hostname = 'http://www.example.com';
+var formSubmitURL = 'http://www.example.com';
+var httprealm = null;
+var username = 'user';
+
+try {
+	// Get Login Manager
+	var passwordManager = Components.classes["@mozilla.org/login-manager;1"].
+		getService(Components.interfaces.nsILoginManager);
+
+	// Find users for this extension
+	var logins = passwordManager.findLogins({}, hostname, formSubmitURL, httprealm);
+
+	for (var i = 0; i < logins.length; i++) {
+		if (logins[i].username == username) {
+			passwordManager.removeLogin(logins[i]);
+			break;
+		}
+	}
+}
+catch(ex) {
+	// This will only happen if there is no nsILoginManager component class
+}
+

Changing stored login information

+

Changing a password is rather simple. Since all this does is make a removeLogin() call followed by an addLogin() call, it has the same caveats as both of them: namely that the oldLogin must match an existing login exactly (see above) and that the newLogin attributes must be set correctly.:

+
myLoginManager.modifyLogin(oldLogin, newLogin);
+

Login Manager notifications

+

+

Замечание по Firefox 3.5

+

The Login Manager notifications were added in Firefox 3.5.

+

+

Firefox 3.5 and later send assorted notifications when various Login Manager related events occur, including when form autofill does not occur for various reasons, as well as when changes are made to the Login Manager's database. See the Login Manager section of the article on observer notifications for details.

+

Debugging

+

The login manager implementation has the ability to send debug messages to the Error Console, which can provide some visibility into what it's doing. To enable the debug logging, see http://wiki.mozilla.org/Firefox:Pass...ager_Debugging.

+

Supporting older versions of Gecko

+

If you want your extension to support both Gecko 1.9 (Firefox 3, Thunderbird 3, SeaMonkey 2) and older versions it will need to implement both the nsILoginManager and nsIPasswordManager components. A simple method to do this is as follows:

+
if ("@mozilla.org/passwordmanager;1" in Components.classes) {
+	// Password Manager exists so this is not Firefox 3 (could be Firefox 2, Netscape, SeaMonkey, etc).
+	// Password Manager code
+} else if ("@mozilla.org/login-manager;1" in Components.classes) {
+	// Login Manager exists so this is Firefox 3
+	// Login Manager code
+}
+

See also

+ -- cgit v1.2.3-54-g00ecf