From 10ba7f4ab58798dd36a2611638f57f9f60887a80 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Mon, 24 Apr 2017 21:57:25 +0200 Subject: [PATCH] Bug 1359092 - Extend loadURI within nsIWebNavigation.idl by a triggeringPrincipal argument. r=bz --- docshell/base/nsDSURIContentListener.cpp | 5 ++++- docshell/base/nsDocShell.cpp | 20 +++++++++++++------- docshell/base/nsDocShellTreeOwner.cpp | 4 +++- docshell/base/nsIWebNavigation.idl | 16 +++++++++++----- docshell/shistory/nsSHistory.cpp | 3 ++- dom/base/nsGlobalWindow.cpp | 9 +++++---- dom/base/nsGlobalWindow.h | 4 ++-- dom/ipc/TabChild.cpp | 2 +- dom/webidl/Window.webidl | 8 ++++---- editor/composer/nsEditingSession.cpp | 4 +++- toolkit/components/browser/nsWebBrowser.cpp | 8 +++++--- xpfe/appshell/nsWebShellWindow.cpp | 3 ++- 12 files changed, 55 insertions(+), 31 deletions(-) diff --git a/docshell/base/nsDSURIContentListener.cpp b/docshell/base/nsDSURIContentListener.cpp index c3732fd85a6f..63c3cdb87a14 100644 --- a/docshell/base/nsDSURIContentListener.cpp +++ b/docshell/base/nsDSURIContentListener.cpp @@ -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 webNav(do_QueryObject(mDocShell)); if (webNav) { + RefPtr nullPrincipal = NullPrincipal::Create(); webNav->LoadURI(u"about:blank", - 0, nullptr, nullptr, nullptr); + 0, nullptr, nullptr, nullptr, + nullPrincipal); } } return false; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 4e9c7baf835e..7c4fd9f0e596 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -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 loadInfo = aChannel->GetLoadInfo(); + nsCOMPtr 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 } } } diff --git a/docshell/base/nsDocShellTreeOwner.cpp b/docshell/base/nsDocShellTreeOwner.cpp index 46684f97af31..14cd8c6da9e9 100644 --- a/docshell/base/nsDocShellTreeOwner.cpp +++ b/docshell/base/nsDocShellTreeOwner.cpp @@ -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()); } } diff --git a/docshell/base/nsIWebNavigation.idl b/docshell/base/nsIWebNavigation.idl index 5e74b36eb425..78e89a41359f 100644 --- a/docshell/base/nsIWebNavigation.idl +++ b/docshell/base/nsIWebNavigation.idl @@ -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 diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp index 94ffe9508857..c080e228c35d 100644 --- a/docshell/shistory/nsSHistory.cpp +++ b/docshell/shistory/nsSHistory.cpp @@ -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; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index d21312b962e7..4e2437383bfc 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -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 diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index bb5da2684654..27c8d40aaa3c 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -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); diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 509a46b63117..538880452f1f 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -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?"); } diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index eafcb8780b80..31559d68c2be 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -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, diff --git a/editor/composer/nsEditingSession.cpp b/editor/composer/nsEditingSession.cpp index e0ee9751dc54..b95621b61d8a 100644 --- a/editor/composer/nsEditingSession.cpp +++ b/editor/composer/nsEditingSession.cpp @@ -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 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()); } } } diff --git a/toolkit/components/browser/nsWebBrowser.cpp b/toolkit/components/browser/nsWebBrowser.cpp index 2cde7247b9eb..e7b62b6c1314 100644 --- a/toolkit/components/browser/nsWebBrowser.cpp +++ b/toolkit/components/browser/nsWebBrowser.cpp @@ -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 diff --git a/xpfe/appshell/nsWebShellWindow.cpp b/xpfe/appshell/nsWebShellWindow.cpp index 84dfa0c1fb0e..e6a7bed29913 100644 --- a/xpfe/appshell/nsWebShellWindow.cpp +++ b/xpfe/appshell/nsWebShellWindow.cpp @@ -257,7 +257,8 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, nsIWebNavigation::LOAD_FLAGS_NONE, nullptr, nullptr, - nullptr); + nullptr, + nsContentUtils::GetSystemPrincipal()); NS_ENSURE_SUCCESS(rv, rv); }