diff --git a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp index 95686cd766d..791fc241096 100644 --- a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -978,7 +978,7 @@ NS_IMETHODIMP nsJSProtocolHandler::GetProtocolFlags(PRUint32 *result) { *result = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT | - URI_LOADABLE_BY_ANYONE; + URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE; return NS_OK; } diff --git a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp index 8adb72901a7..1f6b6d4d460 100644 --- a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp +++ b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Adam Lock * Kathleen Brade + * Ryan Jones * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -116,6 +117,7 @@ #include "nsITransport.h" #include "nsISocketTransport.h" #include "nsIStringBundle.h" +#include "nsIProtocolHandler.h" #include "nsWebBrowserPersist.h" @@ -211,25 +213,6 @@ const PRUint32 kDefaultMaxFilenameLength = 31; const PRUint32 kDefaultMaxFilenameLength = 64; #endif -// Schemes that cannot be saved because they contain no useful content -// strlen("view-source:")==12 -static const char kNonpersistableSchemes[][13] = { - "about:", - "news:", - "snews:", - "ldap:", - "ldaps:", - "mailto:", - "finger:", - "telnet:", - "gopher:", - "javascript:", - "view-source:", - "irc:", - "mailbox:", - "data:" -}; - // Default flags for persistence const PRUint32 kDefaultPersistFlags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION | @@ -3281,27 +3264,38 @@ nsWebBrowserPersist::StoreURI( { NS_ENSURE_ARG_POINTER(aURI); if (aData) + { *aData = nsnull; - - // Test whether this URL should be persisted - PRBool shouldPersistURI = PR_TRUE; - for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kNonpersistableSchemes); i++) - { - PRUint32 schemeLen = strlen(kNonpersistableSchemes[i]); - if (nsCRT::strncasecmp(aURI, kNonpersistableSchemes[i], schemeLen) == 0) - { - shouldPersistURI = PR_FALSE; - break; - } } - if (shouldPersistURI) + + // Test if this URI should be persisted. By default + // we should assume the URI is persistable. + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), + nsDependentCString(aURI), + mCurrentCharset.get(), + mCurrentBaseURI); + NS_ENSURE_SUCCESS(rv, rv); + + PRBool doNotPersistURI; + rv = NS_URIChainHasFlags(uri, + nsIProtocolHandler::URI_NON_PERSISTABLE, + &doNotPersistURI); + if (NS_FAILED(rv)) { - URIData *data = nsnull; - MakeAndStoreLocalFilenameInURIMap(aURI, aNeedsPersisting, &data); - if (aData) - { - *aData = data; - } + doNotPersistURI = PR_FALSE; + } + + if (doNotPersistURI) + { + return NS_OK; + } + + URIData *data = nsnull; + MakeAndStoreLocalFilenameInURIMap(uri, aNeedsPersisting, &data); + if (aData) + { + *aData = data; } return NS_OK; @@ -3678,19 +3672,12 @@ nsWebBrowserPersist::SaveDocumentWithFixup( // we store the current location as the key (absolutized version of domnode's attribute's value) nsresult nsWebBrowserPersist::MakeAndStoreLocalFilenameInURIMap( - const char *aURI, PRBool aNeedsPersisting, URIData **aData) + nsIURI *aURI, PRBool aNeedsPersisting, URIData **aData) { NS_ENSURE_ARG_POINTER(aURI); - nsresult rv; - - // Make a URI - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURI), - mCurrentCharset.get(), mCurrentBaseURI); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); nsCAutoString spec; - rv = uri->GetSpec(spec); + nsresult rv = aURI->GetSpec(spec); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // Create a sensibly named filename for the URI and store in the URI map @@ -3706,7 +3693,7 @@ nsWebBrowserPersist::MakeAndStoreLocalFilenameInURIMap( // Create a unique file name for the uri nsString filename; - rv = MakeFilenameFromURI(uri, filename); + rv = MakeFilenameFromURI(aURI, filename); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); // Store the file name diff --git a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.h b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.h index a1bf69dff9b..840980b54a4 100644 --- a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.h +++ b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.h @@ -116,7 +116,7 @@ private: nsresult GetLocalFileFromURI(nsIURI *aURI, nsILocalFile **aLocalFile) const; nsresult AppendPathToURI(nsIURI *aURI, const nsAString & aPath) const; nsresult MakeAndStoreLocalFilenameInURIMap( - const char *aURI, PRBool aNeedsPersisting, URIData **aData); + nsIURI *aURI, PRBool aNeedsPersisting, URIData **aData); nsresult MakeOutputStream( nsIURI *aFile, nsIOutputStream **aOutputStream); nsresult MakeOutputStreamFromFile( diff --git a/mozilla/extensions/irc/js/lib/chatzilla-service.js b/mozilla/extensions/irc/js/lib/chatzilla-service.js index e0580d73491..b5dc3aeb1ea 100644 --- a/mozilla/extensions/irc/js/lib/chatzilla-service.js +++ b/mozilla/extensions/irc/js/lib/chatzilla-service.js @@ -265,6 +265,10 @@ if ("URI_DANGEROUS_TO_LOAD" in nsIProtocolHandler) { IRCProtocolHandler.prototype.protocolFlags |= nsIProtocolHandler.URI_LOADABLE_BY_ANYONE; } +if ("URI_NON_PERSISTABLE" in nsIProtocolHandler) { + IRCProtocolHandler.prototype.protocolFlags |= + nsIProtocolHandler.URI_NON_PERSISTABLE; +} IRCProtocolHandler.prototype.allowPort = function ircph_allowPort(port, scheme) diff --git a/mozilla/mailnews/compose/src/nsSmtpService.cpp b/mozilla/mailnews/compose/src/nsSmtpService.cpp index 551400552b3..7643052265c 100644 --- a/mozilla/mailnews/compose/src/nsSmtpService.cpp +++ b/mozilla/mailnews/compose/src/nsSmtpService.cpp @@ -306,8 +306,9 @@ nsSmtpService::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) NS_IMETHODIMP nsSmtpService::GetProtocolFlags(PRUint32 *result) { - *result = URI_NORELATIVE | ALLOWS_PROXY | URI_LOADABLE_BY_ANYONE; - return NS_OK; + *result = URI_NORELATIVE | ALLOWS_PROXY | URI_LOADABLE_BY_ANYONE | + URI_NON_PERSISTABLE; + return NS_OK; } // the smtp service is also the protocol handler for mailto urls.... diff --git a/mozilla/netwerk/base/public/nsIProtocolHandler.idl b/mozilla/netwerk/base/public/nsIProtocolHandler.idl index dd4e15d82fc..5ea239ed5bc 100644 --- a/mozilla/netwerk/base/public/nsIProtocolHandler.idl +++ b/mozilla/netwerk/base/public/nsIProtocolHandler.idl @@ -208,6 +208,12 @@ interface nsIProtocolHandler : nsISupports * flag. */ const unsigned long URI_IS_LOCAL_FILE = (1<<9); + + /** + * Loading channels from this protocol has side-effects that make + * it unsuitable for saving to a local file. + */ + const unsigned long URI_NON_PERSISTABLE = (1<<10); /** * This protocol handler can be proxied via a proxy (socks or http) diff --git a/mozilla/netwerk/protocol/data/src/nsDataHandler.cpp b/mozilla/netwerk/protocol/data/src/nsDataHandler.cpp index 609e7f10cc6..8c53b994380 100644 --- a/mozilla/netwerk/protocol/data/src/nsDataHandler.cpp +++ b/mozilla/netwerk/protocol/data/src/nsDataHandler.cpp @@ -90,7 +90,7 @@ nsDataHandler::GetDefaultPort(PRInt32 *result) { NS_IMETHODIMP nsDataHandler::GetProtocolFlags(PRUint32 *result) { *result = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT | - URI_LOADABLE_BY_ANYONE; + URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE; return NS_OK; } diff --git a/mozilla/netwerk/protocol/viewsource/src/nsViewSourceHandler.cpp b/mozilla/netwerk/protocol/viewsource/src/nsViewSourceHandler.cpp index 6644a8e17f6..27c29c90f72 100644 --- a/mozilla/netwerk/protocol/viewsource/src/nsViewSourceHandler.cpp +++ b/mozilla/netwerk/protocol/viewsource/src/nsViewSourceHandler.cpp @@ -69,7 +69,8 @@ nsViewSourceHandler::GetDefaultPort(PRInt32 *result) NS_IMETHODIMP nsViewSourceHandler::GetProtocolFlags(PRUint32 *result) { - *result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE; + *result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE | + URI_NON_PERSISTABLE; return NS_OK; } diff --git a/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp b/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp index 2a26b1a4696..839d5b126ad 100644 --- a/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp +++ b/mozilla/uriloader/exthandler/nsExternalProtocolHandler.cpp @@ -355,7 +355,8 @@ PRBool nsExternalProtocolHandler::HaveProtocolHandler(nsIURI * aURI) NS_IMETHODIMP nsExternalProtocolHandler::GetProtocolFlags(PRUint32 *aUritype) { // Make it norelative since it is a simple uri - *aUritype = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE; + *aUritype = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE | + URI_NON_PERSISTABLE; return NS_OK; }