Bug 1513241: Update loadURI interface and pass a loadURIOptions dictionary from frontend to docshell loads. r=bz

This commit is contained in:
Christoph Kerschbaumer 2019-01-11 12:43:39 +01:00
parent 76512d9aef
commit fbb4bafd5c
10 changed files with 173 additions and 177 deletions

View file

@ -58,6 +58,7 @@
#include "mozilla/dom/TabGroup.h" #include "mozilla/dom/TabGroup.h"
#include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/ChildSHistory.h" #include "mozilla/dom/ChildSHistory.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/net/ReferrerPolicy.h" #include "mozilla/net/ReferrerPolicy.h"
@ -3802,37 +3803,22 @@ nsDocShell::GotoIndex(int32_t aIndex) {
return rootSH->LegacySHistory()->GotoIndex(aIndex); return rootSH->LegacySHistory()->GotoIndex(aIndex);
} }
NS_IMETHODIMP nsresult nsDocShell::LoadURI(const nsAString& aURI,
nsDocShell::LoadURI(const nsAString& aURI, uint32_t aLoadFlags, const LoadURIOptions& aLoadURIOptions) {
nsIURI* aReferringURI, nsIInputStream* aPostStream, uint32_t loadFlags = aLoadURIOptions.mLoadFlags;
nsIInputStream* aHeaderStream,
nsIPrincipal* aTriggeringPrincipal) {
if (mUseStrictSecurityChecks && !aTriggeringPrincipal) {
return NS_ERROR_FAILURE;
}
return LoadURIWithOptions(aURI, aLoadFlags, aReferringURI, RP_Unset,
aPostStream, aHeaderStream, nullptr,
aTriggeringPrincipal);
}
NS_IMETHODIMP NS_ASSERTION((loadFlags & INTERNAL_LOAD_FLAGS_LOADURI_SETUP_FLAGS) == 0,
nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
nsIURI* aReferringURI, uint32_t aReferrerPolicy,
nsIInputStream* aPostStream,
nsIInputStream* aHeaderStream, nsIURI* aBaseURI,
nsIPrincipal* aTriggeringPrincipal) {
NS_ASSERTION((aLoadFlags & INTERNAL_LOAD_FLAGS_LOADURI_SETUP_FLAGS) == 0,
"Unexpected flags"); "Unexpected flags");
if (!IsNavigationAllowed()) { if (!IsNavigationAllowed()) {
return NS_OK; // JS may not handle returning of an error code return NS_OK; // JS may not handle returning of an error code
} }
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIInputStream> postStream(aPostStream); nsCOMPtr<nsIInputStream> postData(aLoadURIOptions.mPostData);
nsresult rv = NS_OK; nsresult rv = NS_OK;
// Create a URI from our string; if that succeeds, we want to // Create a URI from our string; if that succeeds, we want to
// change aLoadFlags to not include the ALLOW_THIRD_PARTY_FIXUP // change loadFlags to not include the ALLOW_THIRD_PARTY_FIXUP
// flag. // flag.
NS_ConvertUTF16toUTF8 uriString(aURI); NS_ConvertUTF16toUTF8 uriString(aURI);
@ -3842,13 +3828,13 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
uriString.StripCRLF(); uriString.StripCRLF();
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE); NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
if (mUseStrictSecurityChecks && !aTriggeringPrincipal) { if (mUseStrictSecurityChecks && !aLoadURIOptions.mTriggeringPrincipal) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
rv = NS_NewURI(getter_AddRefs(uri), uriString); rv = NS_NewURI(getter_AddRefs(uri), uriString);
if (uri) { if (uri) {
aLoadFlags &= ~LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; loadFlags &= ~LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
} }
nsCOMPtr<nsIURIFixupInfo> fixupInfo; nsCOMPtr<nsIURIFixupInfo> fixupInfo;
@ -3858,10 +3844,10 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
// if NS_NewURI returned a URI, because fixup handles nested URIs, etc // if NS_NewURI returned a URI, because fixup handles nested URIs, etc
// (things like view-source:mozilla.org for example). // (things like view-source:mozilla.org for example).
uint32_t fixupFlags = 0; uint32_t fixupFlags = 0;
if (aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) { if (loadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
fixupFlags |= nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP; fixupFlags |= nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
} }
if (aLoadFlags & LOAD_FLAGS_FIXUP_SCHEME_TYPOS) { if (loadFlags & LOAD_FLAGS_FIXUP_SCHEME_TYPOS) {
fixupFlags |= nsIURIFixup::FIXUP_FLAG_FIX_SCHEME_TYPOS; fixupFlags |= nsIURIFixup::FIXUP_FLAG_FIX_SCHEME_TYPOS;
} }
nsCOMPtr<nsIInputStream> fixupStream; nsCOMPtr<nsIInputStream> fixupStream;
@ -3878,10 +3864,10 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
// GetFixupURIInfo only returns a post data stream if it succeeded // GetFixupURIInfo only returns a post data stream if it succeeded
// and changed the URI, in which case we should override the // and changed the URI, in which case we should override the
// passed-in post data. // passed-in post data.
postStream = fixupStream; postData = fixupStream;
} }
if (aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) { if (loadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
nsCOMPtr<nsIObserverService> serv = services::GetObserverService(); nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
if (serv) { if (serv) {
serv->NotifyObservers(fixupInfo, "keyword-uri-fixup", serv->NotifyObservers(fixupInfo, "keyword-uri-fixup",
@ -3894,7 +3880,7 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
if (NS_ERROR_MALFORMED_URI == rv) { if (NS_ERROR_MALFORMED_URI == rv) {
if (DisplayLoadError(rv, uri, PromiseFlatString(aURI).get(), nullptr) && if (DisplayLoadError(rv, uri, PromiseFlatString(aURI).get(), nullptr) &&
(aLoadFlags & LOAD_FLAGS_ERROR_LOAD_CHANGES_RV) != 0) { (loadFlags & LOAD_FLAGS_ERROR_LOAD_CHANGES_RV) != 0) {
return NS_ERROR_LOAD_SHOWED_ERRORPAGE; return NS_ERROR_LOAD_SHOWED_ERRORPAGE;
} }
} }
@ -3904,21 +3890,21 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
} }
PopupBlocker::PopupControlState popupState; PopupBlocker::PopupControlState popupState;
if (aLoadFlags & LOAD_FLAGS_ALLOW_POPUPS) { if (loadFlags & LOAD_FLAGS_ALLOW_POPUPS) {
popupState = PopupBlocker::openAllowed; popupState = PopupBlocker::openAllowed;
aLoadFlags &= ~LOAD_FLAGS_ALLOW_POPUPS; loadFlags &= ~LOAD_FLAGS_ALLOW_POPUPS;
} else { } else {
popupState = PopupBlocker::openOverridden; popupState = PopupBlocker::openOverridden;
} }
nsAutoPopupStatePusher statePusher(popupState); nsAutoPopupStatePusher statePusher(popupState);
bool forceAllowDataURI = aLoadFlags & LOAD_FLAGS_FORCE_ALLOW_DATA_URI; bool forceAllowDataURI = loadFlags & LOAD_FLAGS_FORCE_ALLOW_DATA_URI;
// Don't pass certain flags that aren't needed and end up confusing // Don't pass certain flags that aren't needed and end up confusing
// ConvertLoadTypeToDocShellInfoLoadType. We do need to ensure that they are // ConvertLoadTypeToDocShellInfoLoadType. We do need to ensure that they are
// passed to LoadURI though, since it uses them. // passed to LoadURI though, since it uses them.
uint32_t extraFlags = (aLoadFlags & EXTRA_LOAD_FLAGS); uint32_t extraFlags = (loadFlags & EXTRA_LOAD_FLAGS);
aLoadFlags &= ~EXTRA_LOAD_FLAGS; loadFlags &= ~EXTRA_LOAD_FLAGS;
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(uri); RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(uri);
@ -3926,21 +3912,22 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
* If the user "Disables Protection on This Page", we have to make sure to * If the user "Disables Protection on This Page", we have to make sure to
* remember the users decision when opening links in child tabs [Bug 906190] * remember the users decision when opening links in child tabs [Bug 906190]
*/ */
if (aLoadFlags & LOAD_FLAGS_ALLOW_MIXED_CONTENT) { if (loadFlags & LOAD_FLAGS_ALLOW_MIXED_CONTENT) {
loadState->SetLoadType( loadState->SetLoadType(
MAKE_LOAD_TYPE(LOAD_NORMAL_ALLOW_MIXED_CONTENT, aLoadFlags)); MAKE_LOAD_TYPE(LOAD_NORMAL_ALLOW_MIXED_CONTENT, loadFlags));
} else { } else {
loadState->SetLoadType(MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags)); loadState->SetLoadType(MAKE_LOAD_TYPE(LOAD_NORMAL, loadFlags));
} }
loadState->SetLoadFlags(extraFlags); loadState->SetLoadFlags(extraFlags);
loadState->SetFirstParty(true); loadState->SetFirstParty(true);
loadState->SetPostDataStream(postStream); loadState->SetPostDataStream(postData);
loadState->SetReferrer(aReferringURI); loadState->SetReferrer(aLoadURIOptions.mReferrerURI);
loadState->SetReferrerPolicy((mozilla::net::ReferrerPolicy)aReferrerPolicy); loadState->SetReferrerPolicy(
loadState->SetHeadersStream(aHeaderStream); (mozilla::net::ReferrerPolicy)aLoadURIOptions.mReferrerPolicy);
loadState->SetBaseURI(aBaseURI); loadState->SetHeadersStream(aLoadURIOptions.mHeaders);
loadState->SetTriggeringPrincipal(aTriggeringPrincipal); loadState->SetBaseURI(aLoadURIOptions.mBaseURI);
loadState->SetTriggeringPrincipal(aLoadURIOptions.mTriggeringPrincipal);
loadState->SetForceAllowDataURI(forceAllowDataURI); loadState->SetForceAllowDataURI(forceAllowDataURI);
if (fixupInfo) { if (fixupInfo) {
@ -3959,6 +3946,18 @@ nsDocShell::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags,
return rv; return rv;
} }
NS_IMETHODIMP
nsDocShell::LoadURIFromScript(const nsAString& aURI,
JS::Handle<JS::Value> aLoadURIOptions,
JSContext* aCx) {
// generate dictionary for aLoadURIOptions and forward call
LoadURIOptions loadURIOptions;
if (!loadURIOptions.Init(aCx, aLoadURIOptions)) {
return NS_ERROR_INVALID_ARG;
}
return LoadURI(aURI, loadURIOptions);
}
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI, nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
const char16_t* aURL, nsIChannel* aFailedChannel, const char16_t* aURL, nsIChannel* aFailedChannel,
@ -6910,12 +6909,11 @@ nsresult nsDocShell::EndPageLoad(nsIWebProgress* aProgress,
MOZ_ASSERT(loadInfo, "loadInfo is required on all channels"); MOZ_ASSERT(loadInfo, "loadInfo is required on all channels");
nsCOMPtr<nsIPrincipal> triggeringPrincipal = nsCOMPtr<nsIPrincipal> triggeringPrincipal =
loadInfo->TriggeringPrincipal(); loadInfo->TriggeringPrincipal();
return LoadURI(newSpecW, // URI string
LOAD_FLAGS_NONE, // Load flags LoadURIOptions loadURIOptions;
nullptr, // Referring URI loadURIOptions.mTriggeringPrincipal = triggeringPrincipal;
newPostData, // Post data stream loadURIOptions.mPostData = newPostData;
nullptr, // Headers stream return LoadURI(newSpecW, loadURIOptions);
triggeringPrincipal); // TriggeringPrincipal
} }
} }
} }

View file

@ -56,6 +56,7 @@
#include "mozilla/dom/Event.h" // for Event #include "mozilla/dom/Event.h" // for Event
#include "mozilla/dom/File.h" // for input type=file #include "mozilla/dom/File.h" // for input type=file
#include "mozilla/dom/FileList.h" // for input type=file #include "mozilla/dom/FileList.h" // for input type=file
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/TextEvents.h" #include "mozilla/TextEvents.h"
using namespace mozilla; using namespace mozilla;
@ -896,8 +897,9 @@ nsDocShellTreeOwner::HandleEvent(Event* aEvent) {
"nsDocShellTreeOwner::HandleEvent: Need a valid " "nsDocShellTreeOwner::HandleEvent: Need a valid "
"triggeringPrincipal"); "triggeringPrincipal");
#endif #endif
webnav->LoadURI(url, 0, nullptr, nullptr, nullptr, LoadURIOptions loadURIOptions;
triggeringPrincipal); loadURIOptions.mTriggeringPrincipal = triggeringPrincipal;
webnav->LoadURI(url, loadURIOptions);
} }
} }

View file

@ -14,8 +14,15 @@ webidl Document;
%{ C++ %{ C++
#include "mozilla/dom/ChildSHistory.h" #include "mozilla/dom/ChildSHistory.h"
namespace mozilla {
namespace dom {
struct LoadURIOptions;
} // namespace dom
} // namespace mozilla
%} %}
[ref] native LoadURIOptionsRef(const mozilla::dom::LoadURIOptions);
/** /**
* The nsIWebNavigation interface defines an interface for navigating the web. * The nsIWebNavigation interface defines an interface for navigating the web.
* It provides methods and attributes to direct an object to navigate to a new * It provides methods and attributes to direct an object to navigate to a new
@ -229,93 +236,20 @@ interface nsIWebNavigation : nsISupports
* The URI string to load. For HTTP and FTP URLs and possibly others, * The URI string to load. For HTTP and FTP URLs and possibly others,
* characters above U+007F will be converted to UTF-8 and then URL- * characters above U+007F will be converted to UTF-8 and then URL-
* escaped per the rules of RFC 2396. * escaped per the rules of RFC 2396.
* @param aLoadFlags * @param aLoadURIOptions
* Flags modifying load behaviour. This parameter is a bitwise * A JSObject defined in LoadURIOptions.webidl holding info like e.g.
* combination of the load flags defined above. (Undefined bits are * the triggeringPrincipal, the referrer URI, the referrer policy.
* reserved for future use.) Generally you will pass LOAD_FLAGS_NONE
* for this parameter.
* @param aReferrer
* The referring URI. If this argument is null, then the referring
* URI will be inferred internally.
* @param aPostData
* If the URI corresponds to a HTTP request, then this stream is
* appended directly to the HTTP request headers. It may be prefixed
* with additional HTTP headers. This stream must contain a "\r\n"
* sequence separating any HTTP headers from the HTTP request body.
* This parameter is optional and may be null.
* @param aHeaders
* If the URI corresponds to a HTTP request, then any HTTP headers
* contained in this stream are set on the HTTP request. The HTTP
* 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.
*/ */
[implicit_jscontext, binaryname(LoadURIFromScript)]
void loadURI(in AString aURI, void loadURI(in AString aURI,
in unsigned long aLoadFlags, in jsval aLoadURIOptions);
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 * A C++ friendly version of loadURI
* in the object implementing this interface. If it can't be loaded here
* however, the URI dispatcher will go through its normal process of content
* loading.
*
* Behaves like loadURI, but allows passing of additional parameters.
*
* @param aURI
* The URI string to load. For HTTP and FTP URLs and possibly others,
* characters above U+007F will be converted to UTF-8 and then URL-
* escaped per the rules of RFC 2396.
* @param aLoadFlags
* Flags modifying load behaviour. This parameter is a bitwise
* combination of the load flags defined above. (Undefined bits are
* reserved for future use.) Generally you will pass LOAD_FLAGS_NONE
* for this parameter.
* @param aReferrer
* The referring URI. If this argument is null, then the referring
* URI will be inferred internally.
* @param aReferrerPolicy
* One of the REFERRER_POLICY_* constants from nsIHttpChannel.
* Normal case is REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE.
* @param aPostData
* If the URI corresponds to a HTTP request, then this stream is
* appended directly to the HTTP request headers. It may be prefixed
* with additional HTTP headers. This stream must contain a "\r\n"
* sequence separating any HTTP headers from the HTTP request body.
* This parameter is optional and may be null.
* @param aHeaders
* If the URI corresponds to a HTTP request, then any HTTP headers
* contained in this stream are set on the HTTP request. The HTTP
* header stream is formatted as:
* ( HEADER "\r\n" )*
* This parameter is optional and may be null.
* @param aBaseURI
* Set to indicate a base URI to be associated with the load. Note
* that at present this argument is only used with view-source aURIs
* and cannot be used to resolve aURI.
* 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 loadURIWithOptions(in AString aURI, [nostdcall, binaryname(LoadURI)]
in unsigned long aLoadFlags, void binaryLoadURI(in AString aURI,
in nsIURI aReferrer, in LoadURIOptionsRef aLoadURIOptions);
in unsigned long aReferrerPolicy,
in nsIInputStream aPostData,
in nsIInputStream aHeaders,
in nsIURI aBaseURI,
[optional] in nsIPrincipal aTriggeringPrincipal);
/** /**
* Tells the Object to reload the current page. There may be cases where the * Tells the Object to reload the current page. There may be cases where the

View file

@ -23,6 +23,7 @@
#include "mozilla/dom/DataTransfer.h" #include "mozilla/dom/DataTransfer.h"
#include "mozilla/dom/Event.h" #include "mozilla/dom/Event.h"
#include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h" #include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/dom/MessageManagerBinding.h" #include "mozilla/dom/MessageManagerBinding.h"
#include "mozilla/dom/MouseEventBinding.h" #include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/Nullable.h" #include "mozilla/dom/Nullable.h"
@ -1007,11 +1008,14 @@ mozilla::ipc::IPCResult TabChild::RecvLoadURL(const nsCString& aURI,
ApplyShowInfo(aInfo); ApplyShowInfo(aInfo);
} }
nsresult rv = WebNavigation()->LoadURI( LoadURIOptions loadURIOptions;
NS_ConvertUTF8toUTF16(aURI), loadURIOptions.mTriggeringPrincipal = nsContentUtils::GetSystemPrincipal();
loadURIOptions.mLoadFlags =
nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL, nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL;
nullptr, nullptr, nullptr, nsContentUtils::GetSystemPrincipal());
nsresult rv =
WebNavigation()->LoadURI(NS_ConvertUTF8toUTF16(aURI), loadURIOptions);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING( NS_WARNING(
"WebNavigation()->LoadURI failed. Eating exception, what else can I " "WebNavigation()->LoadURI failed. Eating exception, what else can I "

View file

@ -15,6 +15,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
#include "mozilla/dom/nsCSPUtils.h" #include "mozilla/dom/nsCSPUtils.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/NullPrincipal.h" #include "mozilla/NullPrincipal.h"
using namespace mozilla; using namespace mozilla;
@ -257,8 +258,10 @@ static bool ShouldIgnoreFrameOptions(nsIChannel* aChannel,
RefPtr<NullPrincipal> principal = RefPtr<NullPrincipal> principal =
NullPrincipal::CreateWithInheritedAttributes( NullPrincipal::CreateWithInheritedAttributes(
loadInfo->TriggeringPrincipal()); loadInfo->TriggeringPrincipal());
webNav->LoadURI(NS_LITERAL_STRING("about:blank"), 0, nullptr, nullptr,
nullptr, principal); LoadURIOptions loadURIOptions;
loadURIOptions.mTriggeringPrincipal = principal;
webNav->LoadURI(NS_LITERAL_STRING("about:blank"), loadURIOptions);
} }
} }
return false; return false;

View file

@ -0,0 +1,60 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
interface Principal;
interface URI;
interface InputStream;
/**
* This dictionary holds load arguments for docshell loads.
*/
dictionary LoadURIOptions {
/**
* The principal that initiated the load.
*/
Principal? triggeringPrincipal = null;
/**
* Flags modifying load behaviour. This parameter is a bitwise
* combination of the load flags defined in nsIWebNavigation.idl.
*/
long loadFlags = 0;
/**
* The referring URI. If this argument is null, then the referring
* URI will be inferred internally.
*/
URI? referrerURI = null;
/**
* Referrer Policy for the load, defaults to REFERRER_POLICY_UNSET.
* Alternatively use one of REFERRER_POLICY_* constants from
* nsIHttpChannel.
*/
long referrerPolicy = 0;
/**
* If the URI to be loaded corresponds to a HTTP request, then this stream is
* appended directly to the HTTP request headers. It may be prefixed
* with additional HTTP headers. This stream must contain a "\r\n"
* sequence separating any HTTP headers from the HTTP request body.
*/
InputStream? postData = null;
/**
* If the URI corresponds to a HTTP request, then any HTTP headers
* contained in this stream are set on the HTTP request. The HTTP
* header stream is formatted as:
* ( HEADER "\r\n" )*
*/
InputStream? headers = null;
/**
* Set to indicate a base URI to be associated with the load. Note
* that at present this argument is only used with view-source aURIs
* and cannot be used to resolve aURI.
*/
URI? baseURI = null;
};

View file

@ -632,6 +632,7 @@ WEBIDL_FILES = [
'L10nUtils.webidl', 'L10nUtils.webidl',
'LegacyQueryInterface.webidl', 'LegacyQueryInterface.webidl',
'LinkStyle.webidl', 'LinkStyle.webidl',
'LoadURIOptions.webidl',
'Location.webidl', 'Location.webidl',
'MediaCapabilities.webidl', 'MediaCapabilities.webidl',
'MediaDeviceInfo.webidl', 'MediaDeviceInfo.webidl',

View file

@ -50,6 +50,7 @@
#include "mozilla/dom/Selection.h" // for AutoHideSelectionChanges, etc #include "mozilla/dom/Selection.h" // for AutoHideSelectionChanges, etc
#include "nsFrameSelection.h" // for nsFrameSelection #include "nsFrameSelection.h" // for nsFrameSelection
#include "nsBaseCommandController.h" // for nsBaseCommandController #include "nsBaseCommandController.h" // for nsBaseCommandController
#include "mozilla/dom/LoadURIOptionsBinding.h"
class nsISupports; class nsISupports;
class nsIURI; class nsIURI;
@ -940,8 +941,10 @@ void nsEditingSession::TimerCallback(nsITimer* aTimer, void* aClosure) {
if (docShell) { if (docShell) {
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell)); nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
if (webNav) { if (webNav) {
webNav->LoadURI(NS_LITERAL_STRING("about:blank"), 0, nullptr, nullptr, LoadURIOptions loadURIOptions;
nullptr, nsContentUtils::GetSystemPrincipal()); loadURIOptions.mTriggeringPrincipal =
nsContentUtils::GetSystemPrincipal();
webNav->LoadURI(NS_LITERAL_STRING("about:blank"), loadURIOptions);
} }
} }
} }

View file

@ -38,6 +38,7 @@
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
// for painting the background window // for painting the background window
#include "mozilla/LookAndFeel.h" #include "mozilla/LookAndFeel.h"
@ -547,24 +548,27 @@ nsWebBrowser::GoForward() {
return mDocShellAsNav->GoForward(); return mDocShellAsNav->GoForward();
} }
NS_IMETHODIMP nsresult nsWebBrowser::LoadURI(const nsAString& aURI,
nsWebBrowser::LoadURIWithOptions(const nsAString& aURI, uint32_t aLoadFlags, const dom::LoadURIOptions& aLoadURIOptions) {
nsIURI* aReferringURI,
uint32_t aReferrerPolicy,
nsIInputStream* aPostDataStream,
nsIInputStream* aExtraHeaderStream,
nsIURI* aBaseURI,
nsIPrincipal* aTriggeringPrincipal) {
#ifndef ANDROID #ifndef ANDROID
MOZ_ASSERT( MOZ_ASSERT(aLoadURIOptions.mTriggeringPrincipal,
aTriggeringPrincipal, "nsWebBrowser::LoadURI - Need a valid triggeringPrincipal");
"nsWebBrowser::LoadURIWithOptions - Need a valid triggeringPrincipal");
#endif #endif
NS_ENSURE_STATE(mDocShell); NS_ENSURE_STATE(mDocShell);
return mDocShellAsNav->LoadURIWithOptions( return mDocShellAsNav->LoadURI(aURI, aLoadURIOptions);
aURI, aLoadFlags, aReferringURI, aReferrerPolicy, aPostDataStream, }
aExtraHeaderStream, aBaseURI, aTriggeringPrincipal);
NS_IMETHODIMP
nsWebBrowser::LoadURIFromScript(const nsAString& aURI,
JS::Handle<JS::Value> aLoadURIOptions,
JSContext* aCx) {
// generate dictionary for loadURIOptions and forward call
dom::LoadURIOptions loadURIOptions;
if (!loadURIOptions.Init(aCx, aLoadURIOptions)) {
return NS_ERROR_INVALID_ARG;
}
return LoadURI(aURI, loadURIOptions);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -574,22 +578,6 @@ nsWebBrowser::SetOriginAttributesBeforeLoading(
aCx); aCx);
} }
NS_IMETHODIMP
nsWebBrowser::LoadURI(const nsAString& aURI, uint32_t aLoadFlags,
nsIURI* aReferringURI, nsIInputStream* aPostDataStream,
nsIInputStream* aExtraHeaderStream,
nsIPrincipal* aTriggeringPrincipal) {
#ifndef ANDROID
MOZ_ASSERT(aTriggeringPrincipal,
"nsWebBrowser::LoadURI - Need a valid triggeringPrincipal");
#endif
NS_ENSURE_STATE(mDocShell);
return mDocShellAsNav->LoadURI(aURI, aLoadFlags, aReferringURI,
aPostDataStream, aExtraHeaderStream,
aTriggeringPrincipal);
}
NS_IMETHODIMP NS_IMETHODIMP
nsWebBrowser::Reload(uint32_t aReloadFlags) { nsWebBrowser::Reload(uint32_t aReloadFlags) {
NS_ENSURE_STATE(mDocShell); NS_ENSURE_STATE(mDocShell);

View file

@ -64,6 +64,7 @@
#include "mozilla/MouseEvents.h" #include "mozilla/MouseEvents.h"
#include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "nsPIWindowRoot.h" #include "nsPIWindowRoot.h"
@ -245,9 +246,11 @@ nsresult nsWebShellWindow::Initialize(
NS_ConvertUTF8toUTF16 urlString(tmpStr); NS_ConvertUTF8toUTF16 urlString(tmpStr);
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell)); nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
rv =
webNav->LoadURI(urlString, nsIWebNavigation::LOAD_FLAGS_NONE, nullptr, LoadURIOptions loadURIOptions;
nullptr, nullptr, nsContentUtils::GetSystemPrincipal()); loadURIOptions.mTriggeringPrincipal = nsContentUtils::GetSystemPrincipal();
rv = webNav->LoadURI(urlString, loadURIOptions);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }