Bug 229168 - Save Page (with mms:// embedded media) invokes Windows Media Playerp=sciguyryan@gmail.com (Ryan Jones)r=silver@warwickcompsoc.co.uk (James Ross)r+sr=cbiesinger@gmx.at (Christian Biesinger)

This commit is contained in:
gijskruitbosch@gmail.com 2007-04-15 05:31:18 -07:00
parent 48f1856f84
commit 3ae532001a
7 changed files with 47 additions and 52 deletions

View File

@ -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;
}

View File

@ -22,6 +22,7 @@
* Contributor(s):
* Adam Lock <adamlock@netscape.com>
* Kathleen Brade <brade@netscape.com>
* Ryan Jones <sciguyryan@gmail.com>
*
* 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<nsIURI> 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<nsIURI> 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

View File

@ -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(

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}