diff --git a/caps/idl/nsIScriptSecurityManager.idl b/caps/idl/nsIScriptSecurityManager.idl index aa4bb778453..abead19d5d4 100644 --- a/caps/idl/nsIScriptSecurityManager.idl +++ b/caps/idl/nsIScriptSecurityManager.idl @@ -84,21 +84,6 @@ interface nsIScriptSecurityManager : nsIXPCSecurityManager in nsIURI uri, in unsigned long flags); - /** - * Check that content from "from" can load "uri". - * - * Will return error code NS_ERROR_DOM_BAD_URI if the load request - * should be denied. - * - * @param from the URI causing the load - * @param uri the URI that is being loaded - * @param flags the permission set, see above - * - * @deprecated Use checkLoadURIWithPrincipal instead of this function. - */ - [deprecated] void checkLoadURI(in nsIURI from, in nsIURI uri, - in unsigned long flags); - /** * Similar to checkLoadURIWithPrincipal but there are two differences: * diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 7350f3bfbf4..a8deca5bd74 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -1262,25 +1262,6 @@ nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, nsIURI *aURI) return NS_ERROR_DOM_BAD_URI; } -NS_IMETHODIMP -nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, - PRUint32 aFlags) -{ - // FIXME: bug 327244 -- this function should really die... Really truly. - NS_PRECONDITION(aSourceURI, "CheckLoadURI called with null source URI"); - NS_ENSURE_ARG_POINTER(aSourceURI); - - // Note: this is not _quite_ right if aSourceURI has - // NS_NULLPRINCIPAL_SCHEME, but we'll just extract the scheme in - // CheckLoadURIWithPrincipal anyway, so this is good enough. This method - // really needs to go away.... - nsCOMPtr sourcePrincipal; - nsresult rv = CreateCodebasePrincipal(aSourceURI, - getter_AddRefs(sourcePrincipal)); - NS_ENSURE_SUCCESS(rv, rv); - return CheckLoadURIWithPrincipal(sourcePrincipal, aTargetURI, aFlags); -} - /** * Helper method to handle cases where a flag passed to * CheckLoadURIWithPrincipal means denying loading if the given URI has certain diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 2fbb03a8aaf..37444f7fb05 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -3087,7 +3087,7 @@ nsDocument::SetHeaderData(nsIAtom* aHeaderField, const nsAString& aData) // should really be the same thing). Note that this code can run // before the current URI of the webnavigation has been updated, so we // can't assert equality here. - refresher->SetupRefreshURIFromHeader(mDocumentURI, + refresher->SetupRefreshURIFromHeader(mDocumentURI, NodePrincipal(), NS_ConvertUTF16toUTF8(aData)); } } diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.cpp b/content/xslt/src/xslt/txMozillaXMLOutput.cpp index 84c986d70bb..afe9df24375 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp +++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp @@ -241,6 +241,7 @@ txMozillaXMLOutput::endDocument(nsresult aResult) do_QueryInterface(win->GetDocShell()); if (refURI) { refURI->SetupRefreshURIFromHeader(mDocument->GetDocBaseURI(), + mDocument->NodePrincipal(), mRefreshString); } } diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 3ac4f9d328c..be9146787a7 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -5528,6 +5528,7 @@ nsDocShell::ForceRefreshURI(nsIURI * aURI, nsresult nsDocShell::SetupRefreshURIFromHeader(nsIURI * aBaseURI, + nsIPrincipal* aPrincipal, const nsACString & aHeader) { // Refresh headers are parsed with the following format in mind @@ -5569,6 +5570,8 @@ nsDocShell::SetupRefreshURIFromHeader(nsIURI * aBaseURI, // when done, seconds is 0 or the given number of seconds // uriAttrib is empty or the URI specified + MOZ_ASSERT(aPrincipal); + nsCAutoString uriAttrib; PRInt32 seconds = 0; bool specifiesSeconds = false; @@ -5733,9 +5736,8 @@ nsDocShell::SetupRefreshURIFromHeader(nsIURI * aBaseURI, (NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = securityManager-> - CheckLoadURI(aBaseURI, uri, - nsIScriptSecurityManager:: - LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT); + CheckLoadURIWithPrincipal(aPrincipal, uri, + nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT); if (NS_SUCCEEDED(rv)) { bool isjs = true; @@ -5771,8 +5773,16 @@ NS_IMETHODIMP nsDocShell::SetupRefreshURI(nsIChannel * aChannel) refreshHeader); if (!refreshHeader.IsEmpty()) { + nsCOMPtr secMan = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr principal; + rv = secMan->GetChannelPrincipal(aChannel, getter_AddRefs(principal)); + NS_ENSURE_SUCCESS(rv, rv); + SetupReferrerFromChannel(aChannel); - rv = SetupRefreshURIFromHeader(mCurrentURI, refreshHeader); + rv = SetupRefreshURIFromHeader(mCurrentURI, principal, refreshHeader); if (NS_SUCCEEDED(rv)) { return NS_REFRESHURI_HEADER_FOUND; } diff --git a/docshell/base/nsIRefreshURI.idl b/docshell/base/nsIRefreshURI.idl index 590c559043f..3dadc183cb7 100644 --- a/docshell/base/nsIRefreshURI.idl +++ b/docshell/base/nsIRefreshURI.idl @@ -7,8 +7,9 @@ #include "nsISupports.idl" #include "nsIURI.idl" interface nsIChannel; +interface nsIPrincipal; -[scriptable, uuid(cb0ad623-6b46-4c09-a473-c1d6ca63d3c7)] +[scriptable, uuid(a5e61a3c-51bd-45be-ac0c-e87b71860656)] interface nsIRefreshURI : nsISupports { /** * Load a uri after waiting for aMillis milliseconds. If the docshell @@ -55,10 +56,11 @@ interface nsIRefreshURI : nsISupports { * the current page finishes loading. * * @param aBaseURI base URI to resolve refresh uri with. + * @param principal the associated principal * @param aHeader The meta refresh header string. */ - void setupRefreshURIFromHeader(in nsIURI aBaseURI, in ACString aHeader); - + void setupRefreshURIFromHeader(in nsIURI aBaseURI, in nsIPrincipal principal, in ACString aHeader); + /** * Cancels all timer loads. */ diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index 8d0ca1f4bd4..d080e9c134c 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -713,14 +713,6 @@ FullTrustSecMan::CheckLoadURIWithPrincipal(nsIPrincipal *aPrincipal, return NS_OK; } -NS_IMETHODIMP -FullTrustSecMan::CheckLoadURI(nsIURI *from, - nsIURI *uri, - PRUint32 flags) -{ - return NS_OK; -} - NS_IMETHODIMP FullTrustSecMan::CheckLoadURIStrWithPrincipal(nsIPrincipal *aPrincipal, const nsACString & uri, diff --git a/js/xpconnect/shell/xpcshell.cpp b/js/xpconnect/shell/xpcshell.cpp index d95594d782c..99ccdaef50a 100644 --- a/js/xpconnect/shell/xpcshell.cpp +++ b/js/xpconnect/shell/xpcshell.cpp @@ -1332,13 +1332,6 @@ FullTrustSecMan::CheckLoadURIWithPrincipal(nsIPrincipal *aPrincipal, return NS_OK; } -/* void checkLoadURI (in nsIURI from, in nsIURI uri, in unsigned long flags); */ -NS_IMETHODIMP -FullTrustSecMan::CheckLoadURI(nsIURI *from, nsIURI *uri, PRUint32 flags) -{ - return NS_OK; -} - /* void checkLoadURIStrWithPrincipal (in nsIPrincipal aPrincipal, in AUTF8String uri, in unsigned long flags); */ NS_IMETHODIMP FullTrustSecMan::CheckLoadURIStrWithPrincipal(nsIPrincipal *aPrincipal, diff --git a/layout/tools/reftest/reftest.js b/layout/tools/reftest/reftest.js index 33812a2621c..0e6833fe67f 100644 --- a/layout/tools/reftest/reftest.js +++ b/layout/tools/reftest/reftest.js @@ -809,12 +809,14 @@ function ReadManifest(aURL, inherited_status) } } + var principal = secMan.getCodebasePrincipal(aURL); + if (items[0] == "include") { if (items.length != 2 || runHttp) throw "Error 2 in manifest file " + aURL.spec + " line " + lineNo; var incURI = gIOService.newURI(items[1], null, listURL); - secMan.checkLoadURI(aURL, incURI, - CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); + secMan.checkLoadURIWithPrincipal(principal, incURI, + CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); ReadManifest(incURI, expected_status); } else if (items[0] == TYPE_LOAD) { if (items.length != 2 || @@ -822,14 +824,14 @@ function ReadManifest(aURL, inherited_status) expected_status != EXPECTED_DEATH)) throw "Error 3 in manifest file " + aURL.spec + " line " + lineNo; var [testURI] = runHttp - ? ServeFiles(aURL, httpDepth, + ? ServeFiles(principal, httpDepth, listURL, [items[1]]) : [gIOService.newURI(items[1], null, listURL)]; var prettyPath = runHttp ? gIOService.newURI(items[1], null, listURL).spec : testURI.spec; - secMan.checkLoadURI(aURL, testURI, - CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); + secMan.checkLoadURIWithPrincipal(principal, testURI, + CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); gURLs.push( { type: TYPE_LOAD, expected: expected_status, allowSilentFail: allow_silent_fail, @@ -848,14 +850,14 @@ function ReadManifest(aURL, inherited_status) if (items.length != 2) throw "Error 4 in manifest file " + aURL.spec + " line " + lineNo; var [testURI] = runHttp - ? ServeFiles(aURL, httpDepth, + ? ServeFiles(principal, httpDepth, listURL, [items[1]]) : [gIOService.newURI(items[1], null, listURL)]; var prettyPath = runHttp ? gIOService.newURI(items[1], null, listURL).spec : testURI.spec; - secMan.checkLoadURI(aURL, testURI, - CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); + secMan.checkLoadURIWithPrincipal(principal, testURI, + CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); gURLs.push( { type: TYPE_SCRIPT, expected: expected_status, allowSilentFail: allow_silent_fail, @@ -874,17 +876,17 @@ function ReadManifest(aURL, inherited_status) if (items.length != 3) throw "Error 5 in manifest file " + aURL.spec + " line " + lineNo; var [testURI, refURI] = runHttp - ? ServeFiles(aURL, httpDepth, + ? ServeFiles(principal, httpDepth, listURL, [items[1], items[2]]) : [gIOService.newURI(items[1], null, listURL), gIOService.newURI(items[2], null, listURL)]; var prettyPath = runHttp ? gIOService.newURI(items[1], null, listURL).spec : testURI.spec; - secMan.checkLoadURI(aURL, testURI, - CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); - secMan.checkLoadURI(aURL, refURI, - CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); + secMan.checkLoadURIWithPrincipal(principal, testURI, + CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); + secMan.checkLoadURIWithPrincipal(principal, refURI, + CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); gURLs.push( { type: items[0], expected: expected_status, allowSilentFail: allow_silent_fail, @@ -936,7 +938,7 @@ function BuildUseCounts() } } -function ServeFiles(manifestURL, depth, aURL, files) +function ServeFiles(manifestPrincipal, depth, aURL, files) { var listURL = aURL.QueryInterface(CI.nsIFileURL); var directory = listURL.file.parent; @@ -968,8 +970,8 @@ function ServeFiles(manifestURL, depth, aURL, files) var testURI = gIOService.newURI(file, null, testbase); // XXX necessary? manifestURL guaranteed to be file, others always HTTP - secMan.checkLoadURI(manifestURL, testURI, - CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); + secMan.checkLoadURIWithPrincipal(manifestPrincipal, testURI, + CI.nsIScriptSecurityManager.DISALLOW_SCRIPT); return testURI; }