Bug 1359092 - Extend loadURI within nsIWebNavigation.idl by a triggeringPrincipal argument. r=bz

This commit is contained in:
Christoph Kerschbaumer 2017-04-24 21:57:25 +02:00
parent 47c1689c86
commit 10ba7f4ab5
12 changed files with 55 additions and 31 deletions

View File

@ -22,6 +22,7 @@
#include "nsIScriptError.h"
#include "nsDocShellLoadTypes.h"
#include "nsIMultiPartChannel.h"
#include "NullPrincipal.h"
using namespace mozilla;
@ -448,8 +449,10 @@ nsDSURIContentListener::CheckFrameOptions(nsIRequest* aRequest)
if (mDocShell) {
nsCOMPtr<nsIWebNavigation> webNav(do_QueryObject(mDocShell));
if (webNav) {
RefPtr<NullPrincipal> nullPrincipal = NullPrincipal::Create();
webNav->LoadURI(u"about:blank",
0, nullptr, nullptr, nullptr);
0, nullptr, nullptr, nullptr,
nullPrincipal);
}
}
return false;

View File

@ -4746,11 +4746,12 @@ nsDocShell::LoadURI(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
nsIInputStream* aPostStream,
nsIInputStream* aHeaderStream)
nsIInputStream* aHeaderStream,
nsIPrincipal* aTriggeringPrincipal)
{
return LoadURIWithOptions(aURI, aLoadFlags, aReferringURI,
mozilla::net::RP_Unset, aPostStream,
aHeaderStream, nullptr, nullptr);
aHeaderStream, nullptr, aTriggeringPrincipal);
}
NS_IMETHODIMP
@ -7926,11 +7927,16 @@ nsDocShell::EndPageLoad(nsIWebProgress* aProgress,
// can increment counts from the search engine
MaybeNotifyKeywordSearchLoading(keywordProviderName, keywordAsSent);
return LoadURI(newSpecW.get(), // URI string
LOAD_FLAGS_NONE, // Load flags
nullptr, // Referring URI
newPostData, // Post data stream
nullptr); // Headers stream
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
nsCOMPtr<nsIPrincipal> triggeringPrincipal = loadInfo
? loadInfo->TriggeringPrincipal()
: nsContentUtils::GetSystemPrincipal();
return LoadURI(newSpecW.get(), // URI string
LOAD_FLAGS_NONE, // Load flags
nullptr, // Referring URI
newPostData, // Post data stream
nullptr, // Headers stream
triggeringPrincipal); // TriggeringPrincipal
}
}
}

View File

@ -9,6 +9,7 @@
#include "nsWebBrowser.h"
// Helper Classes
#include "nsContentUtils.h"
#include "nsStyleCoord.h"
#include "nsSize.h"
#include "mozilla/ReflowInput.h"
@ -1004,7 +1005,8 @@ nsDocShellTreeOwner::HandleEvent(nsIDOMEvent* aEvent)
nsAutoString url;
if (NS_SUCCEEDED(links[0]->GetUrl(url))) {
if (!url.IsEmpty()) {
webnav->LoadURI(url.get(), 0, nullptr, nullptr, nullptr);
webnav->LoadURI(url.get(), 0, nullptr, nullptr, nullptr,
nsContentUtils::GetSystemPrincipal());
}
}

View File

@ -236,12 +236,18 @@ interface nsIWebNavigation : nsISupports
* header stream is formatted as:
* ( HEADER "\r\n" )*
* This parameter is optional and may be null.
* @param aTriggeringPrincipal
* The principal that initiated the load of aURI. If omitted docShell
* tries to create a codeBasePrincipal from aReferrer if not null. If
* aReferrer is also null docShell peforms a load using the
* SystemPrincipal as the triggeringPrincipal.
*/
void loadURI(in wstring aURI,
in unsigned long aLoadFlags,
in nsIURI aReferrer,
in nsIInputStream aPostData,
in nsIInputStream aHeaders);
void loadURI(in wstring aURI,
in unsigned long aLoadFlags,
in nsIURI aReferrer,
in nsIInputStream aPostData,
in nsIInputStream aHeaders,
[optional] in nsIPrincipal aTriggeringPrincipal);
/**
* Loads a given URI. This will give priority to loading the requested URI

View File

@ -1624,7 +1624,8 @@ nsSHistory::LoadURI(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
nsIInputStream* aPostStream,
nsIInputStream* aExtraHeaderStream)
nsIInputStream* aExtraHeaderStream,
nsIPrincipal* aTriggeringPrincipal)
{
return NS_OK;
}

View File

@ -7832,7 +7832,7 @@ nsGlobalWindow::Forward(ErrorResult& aError)
}
void
nsGlobalWindow::HomeOuter(ErrorResult& aError)
nsGlobalWindow::HomeOuter(nsIPrincipal& aSubjectPrincipal, ErrorResult& aError)
{
MOZ_RELEASE_ASSERT(IsOuterWindow());
@ -7880,13 +7880,14 @@ nsGlobalWindow::HomeOuter(ErrorResult& aError)
nsIWebNavigation::LOAD_FLAGS_NONE,
nullptr,
nullptr,
nullptr);
nullptr,
&aSubjectPrincipal);
}
void
nsGlobalWindow::Home(ErrorResult& aError)
nsGlobalWindow::Home(nsIPrincipal& aSubjectPrincipal, ErrorResult& aError)
{
FORWARD_TO_OUTER_OR_THROW(HomeOuter, (aError), aError, );
FORWARD_TO_OUTER_OR_THROW(HomeOuter, (aSubjectPrincipal, aError), aError, );
}
void

View File

@ -1183,8 +1183,8 @@ public:
void Back(mozilla::ErrorResult& aError);
void ForwardOuter(mozilla::ErrorResult& aError);
void Forward(mozilla::ErrorResult& aError);
void HomeOuter(mozilla::ErrorResult& aError);
void Home(mozilla::ErrorResult& aError);
void HomeOuter(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError);
void Home(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError);
bool FindOuter(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
bool aShowDialog, mozilla::ErrorResult& aError);

View File

@ -1171,7 +1171,7 @@ TabChild::RecvLoadURL(const nsCString& aURI,
WebNavigation()->LoadURI(NS_ConvertUTF8toUTF16(aURI).get(),
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL,
nullptr, nullptr, nullptr);
nullptr, nullptr, nullptr, nsContentUtils::GetSystemPrincipal());
if (NS_FAILED(rv)) {
NS_WARNING("WebNavigation()->LoadURI failed. Eating exception, what else can I do?");
}

View File

@ -278,11 +278,11 @@ partial interface Window {
[Replaceable, Throws] readonly attribute long scrollMaxX;
[Replaceable, Throws] readonly attribute long scrollMaxY;
[Throws, UnsafeInPrerendering] attribute boolean fullScreen;
[Throws, UnsafeInPrerendering] attribute boolean fullScreen;
[Throws, ChromeOnly, UnsafeInPrerendering] void back();
[Throws, ChromeOnly, UnsafeInPrerendering] void forward();
[Throws, ChromeOnly, UnsafeInPrerendering] void home();
[Throws, ChromeOnly, UnsafeInPrerendering] void back();
[Throws, ChromeOnly, UnsafeInPrerendering] void forward();
[Throws, ChromeOnly, UnsafeInPrerendering, NeedsSubjectPrincipal] void home();
// XXX Should this be in nsIDOMChromeWindow?
void updateCommands(DOMString action,

View File

@ -12,6 +12,7 @@
#include "nsAString.h"
#include "nsComponentManagerUtils.h" // for do_CreateInstance
#include "nsComposerCommandsUpdater.h" // for nsComposerCommandsUpdater
#include "nsContentUtils.h"
#include "nsDebug.h" // for NS_ENSURE_SUCCESS, etc
#include "nsEditingSession.h"
#include "nsError.h" // for NS_ERROR_FAILURE, NS_OK, etc
@ -992,7 +993,8 @@ nsEditingSession::TimerCallback(nsITimer* aTimer, void* aClosure)
if (docShell) {
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
if (webNav) {
webNav->LoadURI(u"about:blank", 0, nullptr, nullptr, nullptr);
webNav->LoadURI(u"about:blank", 0, nullptr, nullptr, nullptr,
nsContentUtils::GetSystemPrincipal());
}
}
}

View File

@ -673,12 +673,14 @@ NS_IMETHODIMP
nsWebBrowser::LoadURI(const char16_t* aURI, uint32_t aLoadFlags,
nsIURI* aReferringURI,
nsIInputStream* aPostDataStream,
nsIInputStream* aExtraHeaderStream)
nsIInputStream* aExtraHeaderStream,
nsIPrincipal* aTriggeringPrincipal)
{
NS_ENSURE_STATE(mDocShell);
return mDocShellAsNav->LoadURI(
aURI, aLoadFlags, aReferringURI, aPostDataStream, aExtraHeaderStream);
return mDocShellAsNav->LoadURI(aURI, aLoadFlags, aReferringURI,
aPostDataStream, aExtraHeaderStream,
aTriggeringPrincipal);
}
NS_IMETHODIMP

View File

@ -257,7 +257,8 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
nsIWebNavigation::LOAD_FLAGS_NONE,
nullptr,
nullptr,
nullptr);
nullptr,
nsContentUtils::GetSystemPrincipal());
NS_ENSURE_SUCCESS(rv, rv);
}