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 "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;
|
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
|
|
|
//*****************************************************************************
|
|
|
|
|
2017-05-11 08:26:08 +03:00
|
|
|
class Location final : public nsISupports
|
2016-09-16 10:18:18 +03:00
|
|
|
, 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
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
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,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
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
|
|
|
{
|
2017-05-08 21:24:13 +03:00
|
|
|
if (!CallerSubsumes(&aSubjectPrincipal)) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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 SetHref(const nsAString& aHref,
|
2018-10-12 18:07:18 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetOrigin(nsAString& aOrigin,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetProtocol(nsAString& aProtocol,
|
2016-10-11 04:07:48 +03:00
|
|
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetHost(nsAString& aHost,
|
2016-10-11 04:07:48 +03:00
|
|
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetHostname(nsAString& aHostname,
|
2016-10-11 04:07:48 +03:00
|
|
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetPort(nsAString& aPort,
|
2016-10-11 04:07:48 +03:00
|
|
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetPathname(nsAString& aPathname,
|
2016-10-11 04:07:48 +03:00
|
|
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void GetSearch(nsAString& aSeach,
|
2016-10-11 04:07:48 +03:00
|
|
|
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,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
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,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
2016-09-29 09:55:21 +03:00
|
|
|
|
|
|
|
void SetHash(const nsAString& aHash,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2017-05-08 21:24:13 +03:00
|
|
|
ErrorResult& aError);
|
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
|
|
|
|
2017-05-08 21:24:13 +03:00
|
|
|
// Non WebIDL methods:
|
|
|
|
|
|
|
|
nsresult GetHref(nsAString& aHref);
|
|
|
|
|
|
|
|
nsresult ToString(nsAString& aString)
|
|
|
|
{
|
|
|
|
return GetHref(aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Reload(bool aForceget);
|
|
|
|
|
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
|
|
|
|
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-12 18:07:18 +03:00
|
|
|
void SetURI(nsIURI* aURL, nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv, bool aReplace = false);
|
2018-10-15 21:17:48 +03:00
|
|
|
void SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
|
2018-10-12 18:07:18 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2018-10-15 21:17:48 +03:00
|
|
|
bool aReplace, ErrorResult& aRv);
|
2018-10-12 18:07:17 +03:00
|
|
|
|
|
|
|
// Helper for Assign/SetHref/Replace
|
2018-10-12 18:07:18 +03:00
|
|
|
void DoSetHref(const nsAString& aHref, nsIPrincipal& aSubjectPrincipal,
|
|
|
|
bool aReplace, ErrorResult& aRv);
|
2011-08-03 08:22:40 +04:00
|
|
|
|
2018-10-12 18:07:17 +03:00
|
|
|
// Get the base URL we should be using for our relative URL
|
|
|
|
// resolution for SetHref/Assign/Replace.
|
|
|
|
already_AddRefed<nsIURI> GetSourceBaseURL();
|
2018-10-12 18:07:18 +03:00
|
|
|
|
|
|
|
// Check whether it's OK to load the given url with the given subject
|
|
|
|
// principal, and if so construct the right nsDocShellLoadInfo for the load
|
|
|
|
// and return it.
|
2018-10-29 22:28:02 +03:00
|
|
|
already_AddRefed<nsDocShellLoadInfo> CheckURL(nsIURI *url,
|
2018-10-12 18:07:18 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
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
|