зеркало из https://github.com/mozilla/pjs.git
Make the documentURI of a document and the currentURI of a docshell immutable objects.
Bug 336699, r=darin, sr=jst
This commit is contained in:
Родитель
5634520b16
Коммит
7197f4d213
|
@ -91,8 +91,8 @@ class nsIDocumentObserver;
|
|||
|
||||
// IID for the nsIDocument interface
|
||||
#define NS_IDOCUMENT_IID \
|
||||
{ 0x982d6716, 0xdb0b, 0x4bbf, \
|
||||
{ 0xb7, 0x23, 0x81, 0x24, 0x6c, 0x10, 0xdb, 0xbd } }
|
||||
{ 0x3ab900ba, 0xe30d, 0x4a42, \
|
||||
{ 0x98, 0x50, 0x21, 0x82, 0x99, 0x51, 0x6c, 0xd6 } }
|
||||
|
||||
|
||||
// Flag for AddStyleSheet().
|
||||
|
@ -167,10 +167,11 @@ public:
|
|||
{
|
||||
return mDocumentURI;
|
||||
}
|
||||
void SetDocumentURI(nsIURI* aURI)
|
||||
{
|
||||
mDocumentURI = aURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URI for the document.
|
||||
*/
|
||||
virtual void SetDocumentURI(nsIURI* aURI) = 0;
|
||||
|
||||
/**
|
||||
* Set the principal responsible for this document.
|
||||
|
|
|
@ -960,7 +960,7 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
|
|||
// Release the stylesheets list.
|
||||
mDOMStyleSheets = nsnull;
|
||||
|
||||
mDocumentURI = aURI;
|
||||
SetDocumentURI(aURI);
|
||||
mDocumentBaseURI = mDocumentURI;
|
||||
|
||||
if (aLoadGroup) {
|
||||
|
@ -1181,6 +1181,12 @@ nsDocument::StopDocumentLoad()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsDocument::SetDocumentURI(nsIURI* aURI)
|
||||
{
|
||||
mDocumentURI = NS_TryToMakeImmutable(aURI);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocument::GetLastModified(nsAString& aLastModified)
|
||||
{
|
||||
|
@ -1242,7 +1248,7 @@ nsDocument::SetBaseURI(nsIURI* aURI)
|
|||
CheckLoadURIWithPrincipal(NodePrincipal(), aURI,
|
||||
nsIScriptSecurityManager::STANDARD);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mDocumentBaseURI = aURI;
|
||||
mDocumentBaseURI = NS_TryToMakeImmutable(aURI);
|
||||
}
|
||||
} else {
|
||||
mDocumentBaseURI = nsnull;
|
||||
|
|
|
@ -308,6 +308,8 @@ public:
|
|||
|
||||
virtual void StopDocumentLoad();
|
||||
|
||||
virtual void SetDocumentURI(nsIURI* aURI);
|
||||
|
||||
/**
|
||||
* Set the principal responsible for this document.
|
||||
*/
|
||||
|
|
|
@ -130,7 +130,7 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
|
|||
return rv;
|
||||
}
|
||||
|
||||
doc->nsIDocument::SetDocumentURI(aDocumentURI);
|
||||
doc->nsDocument::SetDocumentURI(aDocumentURI);
|
||||
// Must set the principal first, since SetBaseURI checks it.
|
||||
doc->SetPrincipal(aPrincipal);
|
||||
doc->SetBaseURI(aBaseURI);
|
||||
|
|
|
@ -1267,7 +1267,8 @@ nsDocShell::SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
mCurrentURI = aURI; //This assignment addrefs
|
||||
mCurrentURI = NS_TryToMakeImmutable(aURI);
|
||||
|
||||
PRBool isRoot = PR_FALSE; // Is this the root docshell
|
||||
PRBool isSubFrame = PR_FALSE; // Is this a subframe navigation?
|
||||
|
||||
|
@ -3343,9 +3344,11 @@ nsDocShell::GetCurrentURI(nsIURI ** aURI)
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
|
||||
*aURI = mCurrentURI;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
if (mCurrentURI) {
|
||||
return NS_EnsureSafeToReturn(mCurrentURI, aURI);
|
||||
}
|
||||
|
||||
*aURI = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -544,6 +544,8 @@ protected:
|
|||
nsCOMPtr<nsIDeviceContext> mDeviceContext;
|
||||
nsCOMPtr<nsIWidget> mParentWidget;
|
||||
nsCOMPtr<nsIPrefBranch> mPrefs;
|
||||
|
||||
// mCurrentURI should be marked immutable on set if possible.
|
||||
nsCOMPtr<nsIURI> mCurrentURI;
|
||||
nsCOMPtr<nsIURI> mReferrerURI;
|
||||
nsCOMPtr<nsIScriptGlobalObject> mScriptGlobal;
|
||||
|
|
|
@ -44,7 +44,7 @@ interface nsIURI;
|
|||
/**
|
||||
* nsINetUtil provides various network-related utility methods.
|
||||
*/
|
||||
[scriptable, uuid(4a1f4ab4-d527-4606-b0f7-53a27f20804c)]
|
||||
[scriptable, uuid(c2bf4fea-7f9f-44a4-a7e0-8b323fdcc5d5)]
|
||||
interface nsINetUtil : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -103,4 +103,12 @@ interface nsINetUtil : nsISupports
|
|||
* in aFlags.
|
||||
*/
|
||||
boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags);
|
||||
|
||||
/**
|
||||
* Take aURI and produce an immutable version of it for the caller. If aURI
|
||||
* is immutable this will be aURI itself; otherwise this will be a clone,
|
||||
* marked immutable if possible. Passing null to this method is allowed; in
|
||||
* that case it will return null.
|
||||
*/
|
||||
nsIURI toImmutableURI(in nsIURI aURI);
|
||||
};
|
||||
|
|
|
@ -1099,6 +1099,34 @@ NS_TryToSetImmutable(nsIURI* uri)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for calling ToImmutableURI. If all else fails, returns
|
||||
* the input URI. The optional second arg indicates whether we had to fall
|
||||
* back to the input URI. Passing in a null URI is ok.
|
||||
*/
|
||||
inline already_AddRefed<nsIURI>
|
||||
NS_TryToMakeImmutable(nsIURI* uri,
|
||||
nsresult* outRv = nsnull)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsINetUtil> util = do_GetIOService(&rv);
|
||||
nsIURI* result = nsnull;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION(util, "do_GetIOService lied");
|
||||
rv = util->ToImmutableURI(uri, &result);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_IF_ADDREF(result = uri);
|
||||
}
|
||||
|
||||
if (outRv) {
|
||||
*outRv = rv;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for testing whether the given URI, or any of its
|
||||
* inner URIs, has all the given protocol flags.
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
#include "nsISocketTransport.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsINestedURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#define PORT_PREF_PREFIX "network.security.ports."
|
||||
#define PORT_PREF(x) PORT_PREF_PREFIX x
|
||||
|
@ -842,6 +843,21 @@ nsIOService::URIChainHasFlags(nsIURI *uri,
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::ToImmutableURI(nsIURI* uri, nsIURI** result)
|
||||
{
|
||||
if (!uri) {
|
||||
*result = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_EnsureSafeToReturn(uri, result);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_TryToSetImmutable(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::SetManageOfflineStatus(PRBool aManage) {
|
||||
PRBool wasManaged = mManageOfflineStatus;
|
||||
|
|
Загрузка…
Ссылка в новой задаче