Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIWebBrowserPersist

Cette page est en cours de traduction, son contenu peut donc être incomplet ou contenir des parties en anglais. N'hésitez pas à participer à sa traduction à partir de nsIWebBrowserPersist
IID : dd4e0a6a-210f-419a-ad85-40e8543b9465

Hérite de : nsICancelable

Statut : UNDER_REVIEW

Interface pour conserver des documents DOM et des URI dans une zone de stockage locale ou distante.

Implémentée par : @mozilla.org/embedding/browser/nsWebBrowser;1 @mozilla.org/embedding/browser/nsWebBrowserPersist;1

 

Constantes

PRUint32 	PERSIST_FLAGS_NONE 	= 0
PRUint32 	PERSIST_FLAGS_FROM_CACHE 	= 1
PRUint32 	PERSIST_FLAGS_BYPASS_CACHE 	= 2
PRUint32 	PERSIST_FLAGS_IGNORE_REDIRECTED_DATA 	= 4
PRUint32 	PERSIST_FLAGS_IGNORE_IFRAMES 	= 8
PRUint32 	PERSIST_FLAGS_NO_CONVERSION 	= 16
PRUint32 	PERSIST_FLAGS_REPLACE_EXISTING_FILES 	= 32
PRUint32 	PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS 	= 64
PRUint32 	PERSIST_FLAGS_FIXUP_ORIGINAL_DOM 	= 128
PRUint32 	PERSIST_FLAGS_FIXUP_LINKS_TO_DESTINATION 	= 256
PRUint32 	PERSIST_FLAGS_DONT_FIXUP_LINKS 	= 512
PRUint32 	PERSIST_FLAGS_SERIALIZE_OUTPUT 	= 1024
PRUint32 	PERSIST_FLAGS_DONT_CHANGE_FILENAMES 	= 2048
PRUint32 	PERSIST_FLAGS_FAIL_ON_BROKEN_LINKS 	= 4096

Automatically cleanup after a failed or cancelled operation, deleting all
created files and directories. This flag does nothing for failed upload
operations to remote servers.
PRUint32 	PERSIST_FLAGS_CLEANUP_ON_FAILURE 	= 8192

Let the WebBrowserPersist decide whether the incoming data is encoded and
whether it needs to go through a content converter e.g. to decompress it.
PRUint32 	PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION 	= 16384

PRUint32 	PERSIST_STATE_READY 	= 1
PRUint32 	PERSIST_STATE_SAVING 	= 2
PRUint32 	PERSIST_STATE_FINISHED 	= 3
PRUint32 	ENCODE_FLAGS_SELECTION_ONLY 	= 1

For plaintext output. Convert html to plaintext that looks like the html.
Implies wrap (except inside <pre>), since html wraps.
HTML output: always do prettyprinting, ignoring existing formatting.
PRUint32 	ENCODE_FLAGS_FORMATTED 	= 2

Output without formatting or wrapping the content. This flag may be used
to preserve the original formatting as much as possible.
PRUint32 	ENCODE_FLAGS_RAW 	= 4

PRUint32 	ENCODE_FLAGS_BODY_ONLY 	= 8
PRUint32 	ENCODE_FLAGS_PREFORMATTED 	= 16
PRUint32 	ENCODE_FLAGS_WRAP 	= 32

For plaintext output. Output for format flowed (RFC 2646). This is used
when converting to text for mail sending. This differs just slightly but
in an important way from normal formatted, and that is that lines are
space stuffed. This cannot (correctly) be done later.
PRUint32 	ENCODE_FLAGS_FORMAT_FLOWED 	= 64

PRUint32 	ENCODE_FLAGS_ABSOLUTE_LINKS 	= 128

Attempt to encode entities standardized at W3C (HTML, MathML, etc). This
is a catch-all flag for documents with mixed contents. Beware of
interoperability issues. See below for other flags which might likely do
what you want.
PRUint32 	ENCODE_FLAGS_ENCODE_W3C_ENTITIES 	= 256

Output with carriage return line breaks. May also be combined with
ENCODE_FLAGS_LF_LINEBREAKS and if neither is specified, the platform
default format is used.
PRUint32 	ENCODE_FLAGS_CR_LINEBREAKS 	= 512

Output with linefeed line breaks. May also be combined with
ENCODE_FLAGS_CR_LINEBREAKS and if neither is specified, the platform
default format is used.
PRUint32 	ENCODE_FLAGS_LF_LINEBREAKS 	= 1024

PRUint32 	ENCODE_FLAGS_NOSCRIPT_CONTENT 	= 2048
PRUint32 	ENCODE_FLAGS_NOFRAMES_CONTENT 	= 4096

Encode basic entities, e.g. output   instead of character code 0xa0.
The basic set is just   & < > " for interoperability with older products
that don't support α and friends.
PRUint32 	ENCODE_FLAGS_ENCODE_BASIC_ENTITIES 	= 8192

Encode Latin1 entities. This includes the basic set and accented letters
between 128 and 255.
PRUint32 	ENCODE_FLAGS_ENCODE_LATIN1_ENTITIES 	= 16384

Encode HTML4 entities. This includes the basic set, accented letters,
greek letters and certain special markup symbols.
PRUint32 	ENCODE_FLAGS_ENCODE_HTML_ENTITIES 	= 32768

Propriétés

readonly PRUint32 currentState

Current state of the persister object.

PRUint32 persistFlags

Flags governing how data is fetched and saved from the network. It is best to set this value explicitly unless you are prepared to accept the default values.

nsIWebProgressListener progressListener

Callback listener for progress notifications. The object that the embbedder supplies may also implement nsIInterfaceRequestor and be prepared to return nsIAuthPrompt or other interfaces that may be required to download data.

readonly PRUint32 result

Value indicating the success or failure of the persist operation.

Méthodes

cancelSave()

Cancels the current operation. The caller is responsible for cleaning up partially written files or directories. This has the same effect as calling cancel with an argument of NS_BINDING_ABORTED.

void cancelSave ( );

saveChannel()

Save a channel to a file. It must not be opened yet.

void saveChannel ( 
 nsIChannel channel,
 nsISupports file 
)

saveDocument()

Save the specified DOM document to file and optionally all linked files (e.g. images, CSS, JS & subframes). Do not call this method until the document has finished loading!

void saveDocument (
 nsIDOMDocument document, 
 nsISupports file, 
 nsISupports dataPath, 
 char* outputContentType, 
 PRUint32 encodingFlags, 
 PRUint32 wrapColumn 
)
Parameters
<tt>document</tt>
Document to save to file. Some implementations of this interface may also support nsnull to imply the currently loaded document.
<tt>file</tt>
Target local file. This may be a nsILocalFile object or an nsIURI object with a file scheme or a scheme that supports uploading (e.g. ftp).
<tt>dataPath</tt>
Path to directory where URIs linked to the document are saved or nsnull if no linked URIs should be saved. This may be a nsILocalFile object or an nsIURI object with a file scheme.
<tt>outputContentType</tt>
The desired MIME type format to save the document and all subdocuments into or nsnull to use the default behaviour.
<tt>encodingFlags</tt>
Flags to pass to the encoder.
<tt>wrapColumn</tt>
For text documents, indicates the desired width to wrap text at. Parameter is ignored if wrapping is not specified by the encoding flags.
Returns
<tt>NS_ERROR_INVALID_ARG</tt>
One or more arguments was invalid.

saveURI()

Save the specified URI to file.

void saveURI (
 nsIURI URI ,
 nsISupports cacheKey ,
 nsIURI referrer ,
 nsIInputStream postData ,
 char* extraHeaders ,
 nsISupports file
)
Parameters
<tt>URI</tt>
URI to save to file. Some implementations of this interface may also support nsnull to imply the currently loaded URI.
<tt>cacheKey</tt>
An object representing the URI in the cache or nsnull.
<tt>referrer</tt>
The referrer URI to pass with an HTTP request or nsnull.
<tt>postData</tt>
Post data to pass with an HTTP request or nsnull.
<tt>extraHeaders</tt>
Additional headers to supply with an HTTP request or nsnull.
<tt>file</tt>
Target file. This may be a nsILocalFile object or an nsIURI object with a file scheme or a scheme that supports uploading (e.g. ftp).
Returns
<tt>NS_ERROR_INVALID_ARG</tt>
One or more arguments was invalid.
Example
function downloadFile(httpLoc) {
	try {			
		//new obj_URI object
		var obj_URI = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(httpLoc, null, null);

		//new file object
		var obj_TargetFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);

		//set file with path
		obj_TargetFile.initWithPath("c:\\temp\\test.pdf");
		//if file doesn't exist, create
		if(!obj_TargetFile.exists()) {
			obj_TargetFile.create(0x00,0644);
		}
		//new persitence object
		var obj_Persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);

		//save file to target
		obj_Persist.saveURI(obj_URI,null,null,null,null,obj_TargetFile);
	} catch (e) {
		alert(e);
	}
}
Note concernant les cookies

If you want to send multiple cookies, you need to use one-line syntax. Multiple "Cookie:" lines cause saveURI to separate each name-value pairs by comma "," and it's not recognized by PHP.

Good syntax:
"Cookie: name1=value1; name2=value2\r\n"

Unrecognized syntax:
"Cookie: name1=value1\r\n
Cookie: name2=value2\r\n"

Will result in "Cookie: name1=value1, name2=value2\r\n"


See also XulPlanet reference

Voir également

nsICancelable

Étiquettes et contributeurs liés au document

 Contributeurs à cette page : tregagnon, BenoitL, Yanmorin
 Dernière mise à jour par : tregagnon,