Bug 1361975 window.location is not nullable, r=bz

This patch adds a check on mDocShell in order to do not throw exceptions when
Location is used with a null mDocShell. This is needed because the location
object is not nullable anymore and it can be used also when the window is not
connected to a docshell.
This commit is contained in:
Andrea Marchesini 2017-05-08 15:49:08 +02:00
parent 21d0203054
commit 28cfe0edb3
4 changed files with 16 additions and 25 deletions

View File

@ -87,19 +87,6 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Location)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Location)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Location)
void
Location::SetDocShell(nsIDocShell *aDocShell)
{
mDocShell = do_GetWeakReference(aDocShell);
}
nsIDocShell *
Location::GetDocShell()
{
nsCOMPtr<nsIDocShell> docshell(do_QueryReferent(mDocShell));
return docshell;
}
nsresult
Location::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
{
@ -210,8 +197,12 @@ Location::GetURI(nsIURI** aURI, bool aGetInnermostURI)
{
*aURI = nullptr;
nsresult rv;
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
if (!mDocShell) {
return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell, &rv));
if (NS_FAILED(rv)) {
return rv;
@ -896,9 +887,10 @@ Location::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL)
// this happens, try falling back on the current document associated with the
// docshell. If that fails, just return null and hope that the caller passed
// an absolute URI.
if (!doc && GetDocShell()) {
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
if (!doc && docShell) {
nsCOMPtr<nsPIDOMWindowOuter> docShellWin =
do_QueryInterface(GetDocShell()->GetScriptGlobalObject());
do_QueryInterface(docShell->GetScriptGlobalObject());
if (docShellWin) {
doc = docShellWin->GetDoc();
}

View File

@ -37,9 +37,6 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Location,
nsIDOMLocation)
void SetDocShell(nsIDocShell *aDocShell);
nsIDocShell *GetDocShell();
// nsIDOMLocation
NS_DECL_NSIDOMLOCATION
@ -233,7 +230,11 @@ protected:
// In the case of jar: uris, we sometimes want the place the jar was
// fetched from as the URI instead of the jar: uri itself. Pass in
// true for aGetInnermostURI when that's the case.
// Note, this method can return NS_OK with a null value for aURL. This happens
// if the docShell is null.
nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
// Note, this method can return NS_OK with a null value for aURL. This happens
// if the docShell is null.
nsresult GetWritableURI(nsIURI** aURL,
// If not null, give it the new ref
const nsACString* aNewRef = nullptr);

View File

@ -1933,7 +1933,6 @@ nsGlobalWindow::CleanUp()
mPersonalbar = nullptr;
mStatusbar = nullptr;
mScrollbars = nullptr;
mLocation = nullptr;
mHistory = nullptr;
mCustomElements = nullptr;
mFrames = nullptr;
@ -2096,7 +2095,6 @@ nsGlobalWindow::FreeInnerObjects()
mListenerManager = nullptr;
}
mLocation = nullptr;
mHistory = nullptr;
mCustomElements = nullptr;
@ -10444,10 +10442,10 @@ nsGlobalWindow::GetLocation(ErrorResult& aError)
{
MOZ_RELEASE_ASSERT(IsInnerWindow());
nsIDocShell *docShell = GetDocShell();
if (!mLocation && docShell) {
mLocation = new Location(AsInner(), docShell);
if (!mLocation) {
mLocation = new Location(AsInner(), GetDocShell());
}
return mLocation;
}

View File

@ -36,7 +36,7 @@ interface nsIDOMCrypto;
[Unforgeable, StoreInSlot, Pure] readonly attribute Document? document;
[Throws] attribute DOMString name;
[PutForwards=href, Unforgeable, Throws,
CrossOriginReadable, CrossOriginWritable] readonly attribute Location? location;
CrossOriginReadable, CrossOriginWritable] readonly attribute Location location;
[Throws] readonly attribute History history;
[Func="CustomElementRegistry::IsCustomElementEnabled"]
readonly attribute CustomElementRegistry customElements;