2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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/. */
|
1999-07-01 11:52:52 +04:00
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-11-21 02:55:44 +04:00
|
|
|
#undef LOG
|
2010-10-11 15:35:10 +04:00
|
|
|
#include "IPCMessageUtils.h"
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
#include "nsSimpleURI.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsString.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "plstr.h"
|
2000-02-03 06:44:22 +03:00
|
|
|
#include "nsURLHelper.h"
|
2001-04-10 10:01:08 +04:00
|
|
|
#include "nsNetCID.h"
|
2001-07-31 23:05:34 +04:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsEscape.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsIIPCSerializableURI.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
1999-07-01 11:52:52 +04:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
|
|
|
|
NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
|
2005-06-30 01:03:24 +04:00
|
|
|
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
1999-07-01 11:52:52 +04:00
|
|
|
|
2017-07-07 12:29:44 +03:00
|
|
|
/* static */ already_AddRefed<nsSimpleURI>
|
|
|
|
nsSimpleURI::From(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
RefPtr<nsSimpleURI> uri;
|
|
|
|
nsresult rv = aURI->QueryInterface(kThisSimpleURIImplementationCID,
|
|
|
|
getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsSimpleURI methods:
|
|
|
|
|
2010-06-13 00:40:05 +04:00
|
|
|
nsSimpleURI::nsSimpleURI()
|
2016-11-14 15:04:33 +03:00
|
|
|
: mMutable(true)
|
|
|
|
, mIsRefValid(false)
|
|
|
|
, mIsQueryValid(false)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSimpleURI::~nsSimpleURI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-13 00:40:05 +04:00
|
|
|
NS_IMPL_ADDREF(nsSimpleURI)
|
|
|
|
NS_IMPL_RELEASE(nsSimpleURI)
|
|
|
|
NS_INTERFACE_TABLE_HEAD(nsSimpleURI)
|
2016-12-28 14:40:21 +03:00
|
|
|
NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable,
|
2016-11-14 15:04:33 +03:00
|
|
|
nsIClassInfo, nsIMutable, nsIIPCSerializableURI)
|
2010-06-13 00:40:05 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE
|
|
|
|
if (aIID.Equals(kThisSimpleURIImplementationCID))
|
|
|
|
foundInterface = static_cast<nsIURI*>(this);
|
|
|
|
else
|
2012-02-20 07:51:48 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISizeOf)
|
2010-06-13 00:40:05 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-07-01 11:52:52 +04:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISerializable methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2013-01-11 05:56:51 +04:00
|
|
|
bool isMutable;
|
2011-05-22 05:12:45 +04:00
|
|
|
rv = aStream->ReadBoolean(&isMutable);
|
2006-05-02 22:54:19 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2011-05-22 05:12:45 +04:00
|
|
|
mMutable = isMutable;
|
2006-05-02 22:54:19 +04:00
|
|
|
|
2002-11-14 21:16:31 +03:00
|
|
|
rv = aStream->ReadCString(mScheme);
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-11-14 21:16:31 +03:00
|
|
|
rv = aStream->ReadCString(mPath);
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isRefValid;
|
2011-05-22 05:12:45 +04:00
|
|
|
rv = aStream->ReadBoolean(&isRefValid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mIsRefValid = isRefValid;
|
|
|
|
|
|
|
|
if (isRefValid) {
|
2011-05-24 19:40:10 +04:00
|
|
|
rv = aStream->ReadCString(mRef);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} else {
|
|
|
|
mRef.Truncate(); // invariant: mRef should be empty when it's not valid
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
bool isQueryValid;
|
|
|
|
rv = aStream->ReadBoolean(&isQueryValid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mIsQueryValid = isQueryValid;
|
|
|
|
|
|
|
|
if (isQueryValid) {
|
|
|
|
rv = aStream->ReadCString(mQuery);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} else {
|
|
|
|
mQuery.Truncate(); // invariant: mQuery should be empty when it's not valid
|
|
|
|
}
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2006-05-02 22:54:19 +04:00
|
|
|
rv = aStream->WriteBoolean(mMutable);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = aStream->WriteStringZ(mScheme.get());
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = aStream->WriteStringZ(mPath.get());
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
rv = aStream->WriteBoolean(mIsRefValid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (mIsRefValid) {
|
|
|
|
rv = aStream->WriteStringZ(mRef.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
rv = aStream->WriteBoolean(mIsQueryValid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (mIsQueryValid) {
|
|
|
|
rv = aStream->WriteStringZ(mQuery.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-11 15:35:10 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-08-23 23:33:46 +04:00
|
|
|
// nsIIPCSerializableURI methods:
|
2010-10-11 15:35:10 +04:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
void
|
|
|
|
nsSimpleURI::Serialize(URIParams& aParams)
|
2010-10-11 15:35:10 +04:00
|
|
|
{
|
2012-08-23 23:33:46 +04:00
|
|
|
SimpleURIParams params;
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
params.scheme() = mScheme;
|
|
|
|
params.path() = mPath;
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
if (mIsRefValid) {
|
2012-08-23 23:33:46 +04:00
|
|
|
params.ref() = mRef;
|
2016-11-14 15:04:33 +03:00
|
|
|
} else {
|
2012-08-23 23:33:46 +04:00
|
|
|
params.ref().SetIsVoid(true);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
2016-11-14 15:04:33 +03:00
|
|
|
|
|
|
|
if (mIsQueryValid) {
|
|
|
|
params.query() = mQuery;
|
|
|
|
} else {
|
|
|
|
params.query().SetIsVoid(true);
|
|
|
|
}
|
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
params.isMutable() = mMutable;
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
aParams = params;
|
2010-10-11 15:35:10 +04:00
|
|
|
}
|
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
bool
|
|
|
|
nsSimpleURI::Deserialize(const URIParams& aParams)
|
2010-10-11 15:35:10 +04:00
|
|
|
{
|
2012-08-23 23:33:46 +04:00
|
|
|
if (aParams.type() != URIParams::TSimpleURIParams) {
|
|
|
|
NS_ERROR("Received unknown parameters from the other process!");
|
|
|
|
return false;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
const SimpleURIParams& params = aParams.get_SimpleURIParams();
|
|
|
|
|
|
|
|
mScheme = params.scheme();
|
|
|
|
mPath = params.path();
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
if (params.ref().IsVoid()) {
|
|
|
|
mRef.Truncate();
|
|
|
|
mIsRefValid = false;
|
2016-11-14 15:04:33 +03:00
|
|
|
} else {
|
2012-08-23 23:33:46 +04:00
|
|
|
mRef = params.ref();
|
|
|
|
mIsRefValid = true;
|
|
|
|
}
|
2016-11-14 15:04:33 +03:00
|
|
|
|
|
|
|
if (params.query().IsVoid()) {
|
|
|
|
mQuery.Truncate();
|
|
|
|
mIsQueryValid = false;
|
|
|
|
} else {
|
|
|
|
mQuery = params.query();
|
|
|
|
mIsQueryValid = true;
|
|
|
|
}
|
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
mMutable = params.isMutable();
|
|
|
|
|
|
|
|
return true;
|
2010-10-11 15:35:10 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIURI methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetSpec(nsACString &result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2016-08-01 02:14:33 +03:00
|
|
|
if (!result.Assign(mScheme, fallible) ||
|
|
|
|
!result.Append(NS_LITERAL_CSTRING(":"), fallible) ||
|
|
|
|
!result.Append(mPath, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
if (mIsQueryValid) {
|
|
|
|
if (!result.Append(NS_LITERAL_CSTRING("?"), fallible) ||
|
|
|
|
!result.Append(mQuery, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mQuery.IsEmpty(), "mIsQueryValid/mQuery invariant broken");
|
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
if (mIsRefValid) {
|
2016-08-01 02:14:33 +03:00
|
|
|
if (!result.Append(NS_LITERAL_CSTRING("#"), fallible) ||
|
|
|
|
!result.Append(mRef, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2011-05-24 19:40:10 +04:00
|
|
|
} else {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
2016-11-14 15:04:33 +03:00
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
// result may contain unescaped UTF-8 characters
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetSpecIgnoringRef(nsACString &result)
|
|
|
|
{
|
|
|
|
result = mScheme + NS_LITERAL_CSTRING(":") + mPath;
|
2016-11-14 15:04:33 +03:00
|
|
|
if (mIsQueryValid) {
|
|
|
|
result += NS_LITERAL_CSTRING("?") + mQuery;
|
|
|
|
}
|
2011-08-16 01:18:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-11 20:09:10 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetDisplaySpec(nsACString &aUnicodeSpec)
|
|
|
|
{
|
|
|
|
return GetSpec(aUnicodeSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetDisplayHostPort(nsACString &aUnicodeHostPort)
|
|
|
|
{
|
|
|
|
return GetHostPort(aUnicodeHostPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetDisplayHost(nsACString &aUnicodeHost)
|
|
|
|
{
|
|
|
|
return GetHost(aUnicodeHost);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:43:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetDisplayPrePath(nsACString &aPrePath)
|
|
|
|
{
|
|
|
|
return GetPrePath(aPrePath);
|
|
|
|
}
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSimpleURI::GetHasRef(bool *result)
|
2011-08-16 01:18:15 +04:00
|
|
|
{
|
|
|
|
*result = mIsRefValid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetSpec(const nsACString &aSpec)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2017-08-13 11:03:31 +03:00
|
|
|
nsresult rv = net_ExtractURLScheme(aSpec, mScheme);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
ToLowerCase(mScheme);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2017-08-13 11:03:34 +03:00
|
|
|
rv = net_FilterAndEscapeURI(aSpec, esc_OnlyNonASCII, spec);
|
2016-06-27 21:10:47 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2017-08-13 11:03:34 +03:00
|
|
|
return rv;
|
2016-06-27 21:10:47 +03:00
|
|
|
}
|
2000-04-02 02:31:00 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t colonPos = spec.FindChar(':');
|
2017-08-13 11:03:31 +03:00
|
|
|
MOZ_ASSERT(colonPos != kNotFound, "A colon should be in this string");
|
2016-11-14 15:04:33 +03:00
|
|
|
// This sets mPath, mQuery and mRef.
|
2017-08-13 11:03:28 +03:00
|
|
|
return SetPathQueryRefEscaped(Substring(spec, colonPos + 1),
|
|
|
|
/* needsEscape = */ false);
|
1999-07-01 11:52:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetScheme(nsACString &result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mScheme;
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetScheme(const nsACString &scheme)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2007-02-16 04:10:39 +03:00
|
|
|
|
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(scheme);
|
|
|
|
if (!net_IsValidScheme(flat)) {
|
2016-04-30 17:08:33 +03:00
|
|
|
NS_WARNING("the given url scheme contains invalid characters");
|
2007-02-16 04:10:39 +03:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
mScheme = scheme;
|
2001-03-13 05:01:07 +03:00
|
|
|
ToLowerCase(mScheme);
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-17 11:12:40 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetPrePath(nsACString &result)
|
2000-05-17 11:12:40 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mScheme + NS_LITERAL_CSTRING(":");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetUserPass(nsACString &result)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-05-17 11:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetUserPass(const nsACString &userPass)
|
2000-05-17 11:12:40 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-05-17 11:12:40 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetUsername(nsACString &result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetUsername(const nsACString &userName)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-02-03 06:44:22 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetPassword(nsACString &result)
|
2000-02-03 06:44:22 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetPassword(const nsACString &password)
|
2000-02-03 06:44:22 +03:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2000-02-03 06:44:22 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetHostPort(nsACString &result)
|
2000-02-03 06:44:22 +03:00
|
|
|
{
|
2006-02-14 22:45:23 +03:00
|
|
|
// Note: Audit all callers before changing this to return an empty
|
|
|
|
// string -- CAPS and UI code may depend on this throwing.
|
2015-08-17 22:34:17 +03:00
|
|
|
// Note: If this is changed, change GetAsciiHostPort as well.
|
2000-02-03 06:44:22 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetHostPort(const nsACString &result)
|
2000-02-03 06:44:22 +03:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2000-02-03 06:44:22 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:25:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::SetHostAndPort(const nsACString &result)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mMutable);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetHost(nsACString &result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-02-14 22:45:23 +03:00
|
|
|
// Note: Audit all callers before changing this to return an empty
|
|
|
|
// string -- CAPS and UI code depend on this throwing.
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetHost(const nsACString &host)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSimpleURI::GetPort(int32_t *result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-02-14 22:45:23 +03:00
|
|
|
// Note: Audit all callers before changing this to return an empty
|
|
|
|
// string -- CAPS and UI code may depend on this throwing.
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSimpleURI::SetPort(int32_t port)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-07-29 14:50:21 +03:00
|
|
|
nsSimpleURI::GetPathQueryRef(nsACString &result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mPath;
|
2016-11-14 15:04:33 +03:00
|
|
|
if (mIsQueryValid) {
|
|
|
|
result += NS_LITERAL_CSTRING("?") + mQuery;
|
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
if (mIsRefValid) {
|
|
|
|
result += NS_LITERAL_CSTRING("#") + mRef;
|
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-07-29 14:50:21 +03:00
|
|
|
nsSimpleURI::SetPathQueryRef(const nsACString &aPath)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2017-08-13 11:03:28 +03:00
|
|
|
return SetPathQueryRefEscaped(aPath, true);
|
|
|
|
}
|
|
|
|
nsresult
|
|
|
|
nsSimpleURI::SetPathQueryRefEscaped(const nsACString &aPath, bool aNeedsEscape)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2017-03-06 00:55:45 +03:00
|
|
|
nsAutoCString path;
|
2017-08-13 11:03:28 +03:00
|
|
|
if (aNeedsEscape) {
|
|
|
|
rv = NS_EscapeURL(aPath, esc_OnlyNonASCII, path, fallible);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
path.Assign(aPath);
|
2017-03-06 00:55:45 +03:00
|
|
|
}
|
2017-08-13 11:03:28 +03:00
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
int32_t queryPos = path.FindChar('?');
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t hashPos = path.FindChar('#');
|
2016-11-14 15:04:33 +03:00
|
|
|
|
|
|
|
if (queryPos != kNotFound && hashPos != kNotFound && hashPos < queryPos) {
|
|
|
|
queryPos = kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString query;
|
|
|
|
if (queryPos != kNotFound) {
|
|
|
|
query.Assign(Substring(path, queryPos));
|
|
|
|
path.Truncate(queryPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString hash;
|
|
|
|
if (hashPos != kNotFound) {
|
|
|
|
if (query.IsEmpty()) {
|
|
|
|
hash.Assign(Substring(path, hashPos));
|
|
|
|
path.Truncate(hashPos);
|
|
|
|
} else {
|
|
|
|
// We have to search the hash character in the query
|
|
|
|
hashPos = query.FindChar('#');
|
|
|
|
hash.Assign(Substring(query, hashPos));
|
|
|
|
query.Truncate(hashPos);
|
2016-08-01 02:13:29 +03:00
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
mIsQueryValid = false;
|
|
|
|
mQuery.Truncate();
|
|
|
|
|
|
|
|
mIsRefValid = false;
|
|
|
|
mRef.Truncate();
|
|
|
|
|
|
|
|
// The path
|
|
|
|
if (!mPath.Assign(path, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2017-08-13 11:03:28 +03:00
|
|
|
rv = SetQuery(query);
|
2016-11-14 15:04:33 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetRef(hash);
|
1999-07-01 11:52:52 +04:00
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetRef(nsACString &result)
|
|
|
|
{
|
2011-05-22 05:12:45 +04:00
|
|
|
if (!mIsRefValid) {
|
2016-11-14 15:04:33 +03:00
|
|
|
MOZ_ASSERT(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
|
|
|
|
result.Truncate();
|
2011-05-22 05:12:45 +04:00
|
|
|
} else {
|
2016-11-14 15:04:33 +03:00
|
|
|
result = mRef;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
// NOTE: SetRef("") removes our ref, whereas SetRef("#") sets it to the empty
|
|
|
|
// string (and will result in .spec and .path having a terminal #).
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_IMETHODIMP
|
2011-05-22 05:12:45 +04:00
|
|
|
nsSimpleURI::SetRef(const nsACString &aRef)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
nsAutoCString ref;
|
|
|
|
nsresult rv = NS_EscapeURL(aRef, esc_OnlyNonASCII, ref, fallible);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref.IsEmpty()) {
|
|
|
|
// Empty string means to remove ref completely.
|
|
|
|
mIsRefValid = false;
|
|
|
|
mRef.Truncate(); // invariant: mRef should be empty when it's not valid
|
|
|
|
return NS_OK;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsRefValid = true;
|
2011-05-22 05:12:45 +04:00
|
|
|
|
|
|
|
// Gracefully skip initial hash
|
2016-11-14 15:04:33 +03:00
|
|
|
if (ref[0] == '#') {
|
|
|
|
mRef = Substring(ref, 1);
|
2011-05-22 05:12:45 +04:00
|
|
|
} else {
|
2016-11-14 15:04:33 +03:00
|
|
|
mRef = ref;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSimpleURI::Equals(nsIURI* other, bool *result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2011-05-22 05:12:45 +04:00
|
|
|
return EqualsInternal(other, eHonorRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSimpleURI::EqualsExceptRef(nsIURI* other, bool *result)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
return EqualsInternal(other, eIgnoreRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsresult
|
|
|
|
nsSimpleURI::EqualsInternal(nsIURI* other,
|
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* result)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(other);
|
|
|
|
NS_PRECONDITION(result, "null pointer");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSimpleURI> otherUri;
|
2011-05-22 05:12:45 +04:00
|
|
|
nsresult rv = other->QueryInterface(kThisSimpleURIImplementationCID,
|
|
|
|
getter_AddRefs(otherUri));
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2011-05-22 05:12:45 +04:00
|
|
|
return NS_OK;
|
1999-07-01 11:52:52 +04:00
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
*result = EqualsInternal(otherUri, refHandlingMode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
bool
|
|
|
|
nsSimpleURI::EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode)
|
|
|
|
{
|
|
|
|
bool result = (mScheme == otherUri->mScheme &&
|
|
|
|
mPath == otherUri->mPath);
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
if (result) {
|
|
|
|
result = (mIsQueryValid == otherUri->mIsQueryValid &&
|
|
|
|
(!mIsQueryValid || mQuery == otherUri->mQuery));
|
|
|
|
}
|
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
if (result && refHandlingMode == eHonorRef) {
|
|
|
|
result = (mIsRefValid == otherUri->mIsRefValid &&
|
|
|
|
(!mIsRefValid || mRef == otherUri->mRef));
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
return result;
|
1999-07-01 11:52:52 +04:00
|
|
|
}
|
|
|
|
|
2001-01-31 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSimpleURI::SchemeIs(const char *i_Scheme, bool *o_Equals)
|
2001-01-31 04:33:03 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(o_Equals);
|
2001-03-13 05:01:07 +03:00
|
|
|
if (!i_Scheme) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
const char *this_scheme = mScheme.get();
|
|
|
|
|
2001-03-13 05:01:07 +03:00
|
|
|
// mScheme is guaranteed to be lower case.
|
2002-03-06 10:48:55 +03:00
|
|
|
if (*i_Scheme == *this_scheme || *i_Scheme == (*this_scheme - ('a' - 'A')) ) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*o_Equals = PL_strcasecmp(this_scheme, i_Scheme) ? false : true;
|
2001-03-13 05:01:07 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*o_Equals = false;
|
2001-03-13 05:01:07 +03:00
|
|
|
}
|
|
|
|
|
2001-01-31 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-02 22:54:19 +04:00
|
|
|
/* virtual */ nsSimpleURI*
|
2016-07-27 01:38:46 +03:00
|
|
|
nsSimpleURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode,
|
|
|
|
const nsACString& newRef)
|
2006-05-02 22:54:19 +04:00
|
|
|
{
|
2016-07-27 01:38:46 +03:00
|
|
|
nsSimpleURI* url = new nsSimpleURI();
|
|
|
|
SetRefOnClone(url, refHandlingMode, newRef);
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsSimpleURI::SetRefOnClone(nsSimpleURI* url,
|
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode,
|
|
|
|
const nsACString& newRef)
|
|
|
|
{
|
|
|
|
if (refHandlingMode == eHonorRef) {
|
|
|
|
url->mRef = mRef;
|
|
|
|
url->mIsRefValid = mIsRefValid;
|
|
|
|
} else if (refHandlingMode == eReplaceRef) {
|
|
|
|
url->SetRef(newRef);
|
|
|
|
}
|
2006-05-02 22:54:19 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
NS_IMETHODIMP
|
2011-05-22 05:12:45 +04:00
|
|
|
nsSimpleURI::Clone(nsIURI** result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2016-07-27 01:38:46 +03:00
|
|
|
return CloneInternal(eHonorRef, EmptyCString(), result);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::CloneIgnoringRef(nsIURI** result)
|
|
|
|
{
|
2016-07-27 01:38:46 +03:00
|
|
|
return CloneInternal(eIgnoreRef, EmptyCString(), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::CloneWithNewRef(const nsACString &newRef, nsIURI** result)
|
|
|
|
{
|
|
|
|
return CloneInternal(eReplaceRef, newRef, result);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSimpleURI::CloneInternal(nsSimpleURI::RefHandlingEnum refHandlingMode,
|
2016-07-27 01:38:46 +03:00
|
|
|
const nsACString &newRef,
|
2011-05-22 05:12:45 +04:00
|
|
|
nsIURI** result)
|
|
|
|
{
|
2016-07-27 01:38:46 +03:00
|
|
|
RefPtr<nsSimpleURI> url = StartClone(refHandlingMode, newRef);
|
2011-05-22 05:12:45 +04:00
|
|
|
if (!url)
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2006-05-02 22:54:19 +04:00
|
|
|
// Note: |url| may well have mMutable false at this point, so
|
|
|
|
// don't call any setter methods.
|
2002-03-06 10:48:55 +03:00
|
|
|
url->mScheme = mScheme;
|
|
|
|
url->mPath = mPath;
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
url->mIsQueryValid = mIsQueryValid;
|
|
|
|
if (url->mIsQueryValid) {
|
|
|
|
url->mQuery = mQuery;
|
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
url.forget(result);
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-03 08:13:44 +03:00
|
|
|
NS_IMETHODIMP
|
2016-11-14 15:04:33 +03:00
|
|
|
nsSimpleURI::Resolve(const nsACString &relativePath, nsACString &result)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
result = relativePath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-08-13 11:03:10 +03:00
|
|
|
nsSimpleURI::GetAsciiSpec(nsACString &aResult)
|
1999-11-03 08:13:44 +03:00
|
|
|
{
|
2017-08-13 11:03:10 +03:00
|
|
|
nsresult rv = GetSpec(aResult);
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2017-08-13 11:03:10 +03:00
|
|
|
MOZ_ASSERT(IsASCII(aResult), "The spec should be ASCII");
|
|
|
|
return NS_OK;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
2015-08-17 22:34:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetAsciiHostPort(nsACString &result)
|
|
|
|
{
|
|
|
|
// XXX This behavior mimics GetHostPort.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetAsciiHost(nsACString &result)
|
|
|
|
{
|
|
|
|
result.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-30 01:03:24 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsSimpleURI::nsIClassInfo
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSimpleURI::GetInterfaces(uint32_t *count, nsIID * **array)
|
2005-06-30 01:03:24 +04:00
|
|
|
{
|
|
|
|
*count = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
*array = nullptr;
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2015-03-29 17:52:54 +03:00
|
|
|
nsSimpleURI::GetScriptableHelper(nsIXPCScriptable **_retval)
|
2005-06-30 01:03:24 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2017-10-18 05:17:26 +03:00
|
|
|
nsSimpleURI::GetContractID(nsACString& aContractID)
|
2005-06-30 01:03:24 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
// Make sure to modify any subclasses as needed if this ever
|
|
|
|
// changes.
|
2017-10-18 05:17:26 +03:00
|
|
|
aContractID.SetIsVoid(true);
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2017-10-18 05:17:26 +03:00
|
|
|
nsSimpleURI::GetClassDescription(nsACString& aClassDescription)
|
2005-06-30 01:03:24 +04:00
|
|
|
{
|
2017-10-18 05:17:26 +03:00
|
|
|
aClassDescription.SetIsVoid(true);
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2005-06-30 01:03:24 +04:00
|
|
|
nsSimpleURI::GetClassID(nsCID * *aClassID)
|
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
// Make sure to modify any subclasses as needed if this ever
|
|
|
|
// changes to not call the virtual GetClassIDNoAlloc.
|
2015-03-27 03:01:12 +03:00
|
|
|
*aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
|
2005-06-30 01:03:24 +04:00
|
|
|
if (!*aClassID)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return GetClassIDNoAlloc(*aClassID);
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSimpleURI::GetFlags(uint32_t *aFlags)
|
2005-06-30 01:03:24 +04:00
|
|
|
{
|
|
|
|
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2005-06-30 01:03:24 +04:00
|
|
|
nsSimpleURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
|
|
|
{
|
|
|
|
*aClassIDNoAlloc = kSimpleURICID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-05-02 22:54:19 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsSimpleURI::nsISimpleURI
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSimpleURI::GetMutable(bool *value)
|
2006-05-02 22:54:19 +04:00
|
|
|
{
|
|
|
|
*value = mMutable;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSimpleURI::SetMutable(bool value)
|
2006-05-02 22:54:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(mMutable || !value);
|
|
|
|
|
|
|
|
mMutable = value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-02-20 07:51:48 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsSimpleURI::nsISizeOf
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
size_t
|
2016-05-19 05:02:57 +03:00
|
|
|
nsSimpleURI::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-20 07:51:48 +04:00
|
|
|
{
|
|
|
|
return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
2016-11-14 15:04:33 +03:00
|
|
|
mQuery.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
2012-02-20 07:51:48 +04:00
|
|
|
mRef.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2016-05-19 05:02:57 +03:00
|
|
|
nsSimpleURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
2012-02-20 07:51:48 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetFilePath(nsACString& aFilePath)
|
|
|
|
{
|
|
|
|
aFilePath = mPath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::SetFilePath(const nsACString& aFilePath)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetQuery(nsACString& aQuery)
|
|
|
|
{
|
|
|
|
if (!mIsQueryValid) {
|
|
|
|
MOZ_ASSERT(mQuery.IsEmpty(), "mIsQueryValid/mQuery invariant broken");
|
|
|
|
aQuery.Truncate();
|
|
|
|
} else {
|
|
|
|
aQuery = mQuery;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::SetQuery(const nsACString& aQuery)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mMutable);
|
|
|
|
|
|
|
|
nsAutoCString query;
|
2017-01-06 14:56:14 +03:00
|
|
|
nsresult rv = NS_EscapeURL(aQuery, esc_OnlyNonASCII, query, fallible);
|
2016-11-14 15:04:33 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.IsEmpty()) {
|
2017-01-06 14:56:14 +03:00
|
|
|
// Empty string means to remove query completely.
|
2016-11-14 15:04:33 +03:00
|
|
|
mIsQueryValid = false;
|
|
|
|
mQuery.Truncate(); // invariant: mQuery should be empty when it's not valid
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsQueryValid = true;
|
|
|
|
|
2017-01-06 14:56:14 +03:00
|
|
|
// Gracefully skip initial question mark
|
2016-11-14 15:04:33 +03:00
|
|
|
if (query[0] == '?') {
|
|
|
|
mQuery = Substring(query, 1);
|
|
|
|
} else {
|
|
|
|
mQuery = query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::SetQueryWithEncoding(const nsACString& aQuery,
|
|
|
|
const Encoding* aEncoding)
|
|
|
|
{
|
|
|
|
return SetQuery(aQuery);
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|