2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2011-08-03 08:22:40 +04:00
|
|
|
|
2016-09-16 10:18:18 +03:00
|
|
|
#ifndef mozilla_dom_Location_h
|
|
|
|
#define mozilla_dom_Location_h
|
2011-08-03 08:22:40 +04:00
|
|
|
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2014-07-12 03:31:46 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2016-09-16 10:18:18 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIDOMLocation.h"
|
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2014-07-12 03:31:46 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2016-09-16 10:18:18 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2011-08-03 08:22:40 +04:00
|
|
|
|
|
|
|
class nsIDocShell;
|
|
|
|
class nsIDocShellLoadInfo;
|
2016-09-16 10:18:18 +03:00
|
|
|
class nsIURI;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-08-03 08:22:40 +04:00
|
|
|
|
|
|
|
//*****************************************************************************
|
2016-09-16 10:18:18 +03:00
|
|
|
// Location: Script "location" object
|
2011-08-03 08:22:40 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
|
2016-09-16 10:18:18 +03:00
|
|
|
class Location final : public nsIDOMLocation
|
|
|
|
, public nsWrapperCache
|
2011-08-03 08:22:40 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-09-16 10:18:18 +03:00
|
|
|
Location(nsPIDOMWindowInner* aWindow, nsIDocShell *aDocShell);
|
2011-08-03 08:22:40 +04:00
|
|
|
|
2012-11-07 02:29:09 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2016-09-16 10:18:18 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Location,
|
2014-08-08 04:45:21 +04:00
|
|
|
nsIDOMLocation)
|
2011-08-03 08:22:40 +04:00
|
|
|
|
|
|
|
void SetDocShell(nsIDocShell *aDocShell);
|
|
|
|
nsIDocShell *GetDocShell();
|
|
|
|
|
|
|
|
// nsIDOMLocation
|
|
|
|
NS_DECL_NSIDOMLOCATION
|
|
|
|
|
2015-10-15 00:38:52 +03:00
|
|
|
#define THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME() { \
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CallerSubsumes(&aSubjectPrincipal)) { \
|
2015-10-15 00:38:52 +03:00
|
|
|
aError.Throw(NS_ERROR_DOM_SECURITY_ERR); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2014-07-12 03:31:46 +04:00
|
|
|
// WebIDL API:
|
2016-09-29 09:55:21 +03:00
|
|
|
void Assign(const nsAString& aUrl,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = Assign(aUrl);
|
|
|
|
}
|
2015-10-15 00:38:52 +03:00
|
|
|
|
2016-09-29 09:55:21 +03:00
|
|
|
void Replace(const nsAString& aUrl,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
|
|
|
aError = Replace(aUrl);
|
|
|
|
}
|
2015-10-15 00:38:52 +03:00
|
|
|
|
2016-09-29 09:55:21 +03:00
|
|
|
void Reload(bool aForceget,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = Reload(aForceget);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetHref(nsAString& aHref,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetHref(aHref);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHref(const nsAString& aHref,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
|
|
|
aError = SetHref(aHref);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetOrigin(nsAString& aOrigin,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetOrigin(aOrigin);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetProtocol(nsAString& aProtocol,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetProtocol(aProtocol);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetProtocol(const nsAString& aProtocol,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetProtocol(aProtocol);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetHost(nsAString& aHost,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetHost(aHost);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHost(const nsAString& aHost,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetHost(aHost);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetHostname(nsAString& aHostname,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetHostname(aHostname);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHostname(const nsAString& aHostname,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetHostname(aHostname);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetPort(nsAString& aPort,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetPort(aPort);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetPort(const nsAString& aPort,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetPort(aPort);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetPathname(nsAString& aPathname,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetPathname(aPathname);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetPathname(const nsAString& aPathname,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetPathname(aPathname);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetSearch(nsAString& aSeach,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetSearch(aSeach);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetSearch(const nsAString& aSeach,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetSearch(aSeach);
|
|
|
|
}
|
2014-08-08 04:45:21 +04:00
|
|
|
|
2016-09-29 09:55:21 +03:00
|
|
|
void GetHash(nsAString& aHash,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = GetHash(aHash);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHash(const nsAString& aHash,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:39:20 +03:00
|
|
|
THROW_AND_RETURN_IF_CALLER_DOESNT_SUBSUME();
|
2014-07-12 03:31:46 +04:00
|
|
|
aError = SetHash(aHash);
|
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void Stringify(nsAString& aRetval,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError)
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
2015-10-15 00:38:52 +03:00
|
|
|
// GetHref checks CallerSubsumes.
|
2016-09-29 09:55:21 +03:00
|
|
|
GetHref(aRetval, aSubjectPrincipal, aError);
|
2014-07-12 03:31:46 +04:00
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const
|
2014-07-12 03:31:46 +04:00
|
|
|
{
|
|
|
|
return mInnerWindow;
|
|
|
|
}
|
2016-09-16 10:18:18 +03:00
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-12 03:31:46 +04:00
|
|
|
|
2011-08-03 08:22:40 +04:00
|
|
|
protected:
|
2016-09-16 10:18:18 +03:00
|
|
|
virtual ~Location();
|
2014-06-23 23:56:07 +04:00
|
|
|
|
2014-08-08 04:45:21 +04:00
|
|
|
nsresult SetSearchInternal(const nsAString& aSearch);
|
|
|
|
|
2011-08-03 08:22:40 +04:00
|
|
|
// 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
|
2011-10-17 18:59:28 +04:00
|
|
|
// true for aGetInnermostURI when that's the case.
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
|
2016-08-30 19:55:40 +03:00
|
|
|
nsresult GetWritableURI(nsIURI** aURL,
|
|
|
|
// If not null, give it the new ref
|
|
|
|
const nsACString* aNewRef = nullptr);
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult SetURI(nsIURI* aURL, bool aReplace = false);
|
2011-08-03 08:22:40 +04:00
|
|
|
nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aReplace);
|
2011-08-03 08:22:40 +04:00
|
|
|
nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aReplace);
|
2011-08-03 08:22:40 +04:00
|
|
|
|
|
|
|
nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
|
|
|
|
nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
|
2016-09-29 09:55:21 +03:00
|
|
|
bool CallerSubsumes(nsIPrincipal* aSubjectPrincipal);
|
2011-08-03 08:22:40 +04:00
|
|
|
|
|
|
|
nsString mCachedHash;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mInnerWindow;
|
2011-08-03 08:22:40 +04:00
|
|
|
nsWeakPtr mDocShell;
|
|
|
|
};
|
|
|
|
|
2016-09-16 10:18:18 +03:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Location_h
|