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"
|
2019-01-02 16:29:18 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2019-08-24 01:26:51 +03:00
|
|
|
#include "mozilla/dom/LocationBase.h"
|
2016-09-16 10:18:18 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2011-08-03 08:22:40 +04:00
|
|
|
|
|
|
|
class nsIDocShell;
|
2020-11-23 19:12:02 +03:00
|
|
|
class nsIPrincipal;
|
2016-09-16 10:18:18 +03:00
|
|
|
class nsIURI;
|
2020-11-23 19:12:02 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2016-09-16 10:18:18 +03:00
|
|
|
|
|
|
|
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
|
|
|
//*****************************************************************************
|
|
|
|
|
2019-08-24 01:26:51 +03:00
|
|
|
class Location final : public nsISupports,
|
|
|
|
public LocationBase,
|
|
|
|
public nsWrapperCache {
|
2011-08-03 08:22:40 +04:00
|
|
|
public:
|
2019-02-28 21:23:15 +03:00
|
|
|
typedef BrowsingContext::LocationProxy RemoteProxy;
|
2019-01-02 16:29:18 +03:00
|
|
|
|
2019-09-17 04:17:17 +03:00
|
|
|
Location(nsPIDOMWindowInner* aWindow, BrowsingContext* aBrowsingContext);
|
2011-08-03 08:22:40 +04:00
|
|
|
|
2012-11-07 02:29:09 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2017-05-11 08:26:08 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Location)
|
2011-08-03 08:22:40 +04:00
|
|
|
|
2014-07-12 03:31:46 +04:00
|
|
|
// WebIDL API:
|
2016-09-29 09:55:21 +03:00
|
|
|
void Assign(const nsAString& aUrl, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2015-10-15 00:38:52 +03:00
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
void Reload(bool aForceget, nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError) {
|
2017-05-08 21:24:13 +03:00
|
|
|
if (!CallerSubsumes(&aSubjectPrincipal)) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:02:11 +03:00
|
|
|
Reload(aForceget, aError);
|
2014-07-12 03:31:46 +04:00
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
void GetHref(nsAString& aHref, nsIPrincipal& aSubjectPrincipal,
|
2016-09-29 09:55:21 +03:00
|
|
|
ErrorResult& aError) {
|
2017-05-08 21:24:13 +03:00
|
|
|
if (!CallerSubsumes(&aSubjectPrincipal)) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-08 21:14:21 +03:00
|
|
|
aError = GetHref(aHref);
|
2014-07-12 03:31:46 +04:00
|
|
|
}
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetOrigin(nsAString& aOrigin, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetProtocol(nsAString& aProtocol, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetProtocol(const nsAString& aProtocol, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
void GetHost(nsAString& aHost, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHost(const nsAString& aHost, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetHostname(nsAString& aHostname, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHostname(const nsAString& aHostname, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
void GetPort(nsAString& aPort, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetPort(const nsAString& aPort, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetPathname(nsAString& aPathname, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetPathname(const nsAString& aPathname, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetSearch(nsAString& aSeach, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetSearch(const nsAString& aSeach, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2014-08-08 04:45:21 +04:00
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
void GetHash(nsAString& aHash, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHash(const nsAString& aHash, nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const { 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
|
|
|
|
2017-05-08 21:24:13 +03:00
|
|
|
// Non WebIDL methods:
|
|
|
|
|
|
|
|
nsresult GetHref(nsAString& aHref);
|
|
|
|
|
|
|
|
nsresult ToString(nsAString& aString) { return GetHref(aString); }
|
|
|
|
|
2019-08-02 21:02:11 +03:00
|
|
|
void Reload(bool aForceget, ErrorResult& aRv);
|
2017-05-08 21:24:13 +03: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
|
|
|
|
2019-08-24 01:26:51 +03:00
|
|
|
BrowsingContext* GetBrowsingContext() override;
|
|
|
|
already_AddRefed<nsIDocShell> GetDocShell() override;
|
|
|
|
|
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.
|
2017-05-08 16:49:08 +03:00
|
|
|
// Note, this method can return NS_OK with a null value for aURL. This happens
|
|
|
|
// if the docShell is null.
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
|
2018-10-30 03:13:29 +03:00
|
|
|
|
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;
|
2019-09-17 04:17:17 +03:00
|
|
|
uint64_t mBrowsingContextId = 0;
|
2011-08-03 08:22:40 +04:00
|
|
|
};
|
|
|
|
|
2016-09-16 10:18:18 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Location_h
|