2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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"
|
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"
|
2017-11-20 19:11:30 +03:00
|
|
|
#include "nsIURIMutator.h"
|
2019-05-28 16:50:00 +03:00
|
|
|
#include "mozilla/net/MozURL.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
2019-05-01 11:47:10 +03:00
|
|
|
already_AddRefed<nsSimpleURI> nsSimpleURI::From(nsIURI* aURI) {
|
2017-07-07 12:29:44 +03:00
|
|
|
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() : mIsRefValid(false), mIsQueryValid(false) {}
|
1999-07-01 11:52:52 +04:00
|
|
|
|
2010-06-13 00:40:05 +04:00
|
|
|
NS_IMPL_ADDREF(nsSimpleURI)
|
|
|
|
NS_IMPL_RELEASE(nsSimpleURI)
|
|
|
|
NS_INTERFACE_TABLE_HEAD(nsSimpleURI)
|
2019-01-25 16:32:36 +03:00
|
|
|
NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable, nsIClassInfo)
|
2010-06-13 00:40:05 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE
|
|
|
|
if (aIID.Equals(kThisSimpleURIImplementationCID))
|
2019-05-01 11:47:10 +03:00
|
|
|
foundInterface = static_cast<nsIURI*>(this);
|
2010-06-13 00:40:05 +04:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::Read(nsIObjectInputStream* aStream) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead");
|
2018-03-19 22:22:32 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::ReadPrivate(nsIObjectInputStream* aStream) {
|
2001-07-31 23:05:34 +04:00
|
|
|
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;
|
2018-05-09 19:21:24 +03:00
|
|
|
Unused << 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);
|
2011-05-22 05:12:45 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isRefValid;
|
2011-05-22 05:12:45 +04:00
|
|
|
rv = aStream->ReadBoolean(&isRefValid);
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2011-05-22 05:12:45 +04:00
|
|
|
mIsRefValid = isRefValid;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
if (isRefValid) {
|
2011-05-22 05:12:45 +04:00
|
|
|
rv = aStream->ReadCString(mRef);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2011-05-22 05:12:45 +04:00
|
|
|
mRef.Truncate(); // invariant: mRef should be empty when it's not valid
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
|
|
|
|
bool isQueryValid;
|
2011-05-24 19:40:10 +04:00
|
|
|
rv = aStream->ReadBoolean(&isQueryValid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mIsQueryValid = isQueryValid;
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
if (isQueryValid) {
|
|
|
|
rv = aStream->ReadCString(mQuery);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2016-11-14 15:04:33 +03:00
|
|
|
mQuery.Truncate(); // invariant: mQuery should be empty when it's not valid
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::Write(nsIObjectOutputStream* aStream) {
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2018-05-09 19:21:24 +03:00
|
|
|
rv = aStream->WriteBoolean(false); // former mMutable
|
2006-05-02 22:54:19 +04:00
|
|
|
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());
|
2016-11-14 15:04:33 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
rv = aStream->WriteBoolean(mIsRefValid);
|
2001-07-31 23:05:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
if (mIsRefValid) {
|
|
|
|
rv = aStream->WriteStringZ(mRef.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
|
|
|
|
rv = aStream->WriteBoolean(mIsQueryValid);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
if (mIsQueryValid) {
|
|
|
|
rv = aStream->WriteStringZ(mQuery.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-11-14 15:04:33 +03:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void nsSimpleURI::Serialize(URIParams& aParams) {
|
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
|
|
|
aParams = params;
|
2010-10-11 15:35:10 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool nsSimpleURI::Deserialize(const URIParams& aParams) {
|
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
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const SimpleURIParams& params = aParams.get_SimpleURIParams();
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
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
|
|
|
return true;
|
2010-10-11 15:35:10 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIURI methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetSpec(nsACString& result) {
|
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;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2016-11-14 15:04:33 +03:00
|
|
|
MOZ_ASSERT(mQuery.IsEmpty(), "mIsQueryValid/mQuery invariant broken");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-11-14 15:04:33 +03:00
|
|
|
|
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-22 05:12:45 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
|
2018-11-30 13:46:48 +03: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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetSpecIgnoringRef(nsACString& result) {
|
2011-08-16 01:18:15 +04:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetDisplaySpec(nsACString& aUnicodeSpec) {
|
2017-07-11 20:09:10 +03:00
|
|
|
return GetSpec(aUnicodeSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetDisplayHostPort(nsACString& aUnicodeHostPort) {
|
2017-07-11 20:09:10 +03:00
|
|
|
return GetHostPort(aUnicodeHostPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetDisplayHost(nsACString& aUnicodeHost) {
|
2017-07-11 20:09:10 +03:00
|
|
|
return GetHost(aUnicodeHost);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:43:58 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetDisplayPrePath(nsACString& aPrePath) {
|
2017-08-09 18:43:58 +03:00
|
|
|
return GetPrePath(aPrePath);
|
|
|
|
}
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetHasRef(bool* result) {
|
2011-08-16 01:18:15 +04:00
|
|
|
*result = mIsRefValid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetSpecInternal(const nsACString& aSpec) {
|
2017-08-13 11:03:31 +03:00
|
|
|
nsresult rv = net_ExtractURLScheme(aSpec, mScheme);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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),
|
2018-04-30 19:46:04 +03:00
|
|
|
/* aNeedsEscape = */ false);
|
1999-07-01 11:52:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetScheme(nsACString& result) {
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mScheme;
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetScheme(const nsACString& scheme) {
|
|
|
|
const nsPromiseFlatCString& flat = PromiseFlatCString(scheme);
|
2007-02-16 04:10:39 +03:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetPrePath(nsACString& result) {
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mScheme + NS_LITERAL_CSTRING(":");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetUserPass(nsACString& result) { return NS_ERROR_FAILURE; }
|
2000-05-17 11:12:40 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetUserPass(const nsACString& userPass) {
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetUsername(nsACString& result) { return NS_ERROR_FAILURE; }
|
1999-07-01 11:52:52 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetUsername(const nsACString& userName) {
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-02-03 06:44:22 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetPassword(nsACString& result) { return NS_ERROR_FAILURE; }
|
2000-02-03 06:44:22 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetPassword(const nsACString& password) {
|
2000-02-03 06:44:22 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetHostPort(nsACString& result) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetHostPort(const nsACString& result) {
|
2000-02-03 06:44:22 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetHost(nsACString& result) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetHost(const nsACString& host) {
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetPort(int32_t* result) {
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsSimpleURI::SetPort(int32_t port) { return NS_ERROR_FAILURE; }
|
1999-07-01 11:52:52 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetPathQueryRef(nsACString& result) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetPathQueryRef(const nsACString& aPath) {
|
2017-08-13 11:03:28 +03:00
|
|
|
return SetPathQueryRefEscaped(aPath, true);
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetPathQueryRefEscaped(const nsACString& aPath,
|
2017-08-13 11:03:28 +03:00
|
|
|
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;
|
2017-03-06 00:55:45 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-11-21 22:36:01 +03:00
|
|
|
if (!path.Assign(aPath, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2018-11-30 13:46:48 +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);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +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
|
2019-05-01 11:47:10 +03:00
|
|
|
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 #).
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetRef(const nsACString& aRef) {
|
2016-11-14 15:04:33 +03:00
|
|
|
nsAutoCString ref;
|
2018-06-18 16:06:25 +03:00
|
|
|
nsresult rv =
|
|
|
|
NS_EscapeURL(aRef, esc_OnlyNonASCII | esc_Spaces, ref, fallible);
|
2016-11-14 15:04:33 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::Equals(nsIURI* other, bool* result) {
|
2011-05-22 05:12:45 +04:00
|
|
|
return EqualsInternal(other, eHonorRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::EqualsExceptRef(nsIURI* other, bool* result) {
|
2011-05-22 05:12:45 +04:00
|
|
|
return EqualsInternal(other, eIgnoreRef, result);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* virtual */
|
|
|
|
nsresult nsSimpleURI::EqualsInternal(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIURI* other, nsSimpleURI::RefHandlingEnum refHandlingMode, bool* result) {
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(other);
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(result, "null pointer");
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
RefPtr<nsSimpleURI> otherUri;
|
|
|
|
nsresult rv = other->QueryInterface(kThisSimpleURIImplementationCID,
|
|
|
|
getter_AddRefs(otherUri));
|
2011-05-22 05:12:45 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-05-26 00:23:07 +04:00
|
|
|
*result = false;
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
*result = EqualsInternal(otherUri, refHandlingMode);
|
2011-05-22 05:12:45 +04:00
|
|
|
return NS_OK;
|
2011-05-26 00:23:07 +04:00
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool nsSimpleURI::EqualsInternal(nsSimpleURI* otherUri,
|
2011-05-26 00:23:07 +04:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::SchemeIs(const char* i_Scheme, bool* o_Equals) {
|
2019-01-11 11:09:33 +03:00
|
|
|
MOZ_ASSERT(o_Equals, "null pointer");
|
2019-01-13 21:05:39 +03:00
|
|
|
if (!i_Scheme) {
|
|
|
|
*o_Equals = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-13 05:01:07 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* this_scheme = mScheme.get();
|
2002-03-06 10:48:55 +03:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
/* virtual */ nsSimpleURI* nsSimpleURI::StartClone(
|
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode, const nsACString& newRef) {
|
|
|
|
nsSimpleURI* url = new nsSimpleURI();
|
2016-07-27 01:38:46 +03:00
|
|
|
SetRefOnClone(url, refHandlingMode, newRef);
|
|
|
|
return url;
|
2006-05-02 22:54:19 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* virtual */
|
2019-05-01 11:47:10 +03:00
|
|
|
void nsSimpleURI::SetRefOnClone(nsSimpleURI* url,
|
2019-02-26 01:11:11 +03:00
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode,
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsACString& newRef) {
|
2016-07-27 01:38:46 +03:00
|
|
|
if (refHandlingMode == eHonorRef) {
|
|
|
|
url->mRef = mRef;
|
|
|
|
url->mIsRefValid = mIsRefValid;
|
|
|
|
} else if (refHandlingMode == eReplaceRef) {
|
|
|
|
url->SetRef(newRef);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::Clone(nsIURI** result) {
|
2016-07-27 01:38:46 +03:00
|
|
|
return CloneInternal(eHonorRef, EmptyCString(), result);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
nsresult nsSimpleURI::CloneInternal(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode, const nsACString& newRef,
|
|
|
|
nsIURI** result) {
|
2002-03-06 10:48:55 +03:00
|
|
|
RefPtr<nsSimpleURI> url = StartClone(refHandlingMode, newRef);
|
1999-07-01 11:52:52 +04:00
|
|
|
if (!url) return NS_ERROR_OUT_OF_MEMORY;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
url->mScheme = mScheme;
|
|
|
|
url->mPath = mPath;
|
|
|
|
|
|
|
|
url->mIsQueryValid = mIsQueryValid;
|
|
|
|
if (url->mIsQueryValid) {
|
|
|
|
url->mQuery = mQuery;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::Resolve(const nsACString& relativePath, nsACString& result) {
|
2019-05-28 16:50:00 +03:00
|
|
|
nsAutoCString scheme;
|
|
|
|
nsresult rv = net_ExtractURLScheme(relativePath, scheme);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
result = relativePath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
|
|
|
rv = GetAsciiSpec(spec);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If getting the spec fails for some reason, preserve behaviour and just
|
|
|
|
// return the relative path.
|
|
|
|
result = relativePath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MozURL> url;
|
|
|
|
rv = MozURL::Init(getter_AddRefs(url), spec);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If parsing the current url fails, we revert to the previous behaviour
|
|
|
|
// and just return the relative path.
|
|
|
|
result = relativePath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MozURL> url2;
|
|
|
|
rv = MozURL::Init(getter_AddRefs(url2), relativePath, url);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If parsing the relative url fails, we revert to the previous behaviour
|
|
|
|
// and just return the relative path.
|
|
|
|
result = relativePath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = url2->Spec();
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetAsciiSpec(nsACString& aResult) {
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetAsciiHostPort(nsACString& result) {
|
2015-08-17 22:34:17 +03:00
|
|
|
// XXX This behavior mimics GetHostPort.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetAsciiHost(nsACString& result) {
|
2002-03-06 10:48:55 +03:00
|
|
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetInterfaces(nsTArray<nsIID>& array) {
|
2019-02-14 00:42:08 +03:00
|
|
|
array.Clear();
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetScriptableHelper(nsIXPCScriptable** _retval) {
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetContractID(nsACString& aContractID) {
|
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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetClassDescription(nsACString& aClassDescription) {
|
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
|
2019-05-01 11:47:10 +03: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.
|
2019-05-01 11:47:10 +03:00
|
|
|
*aClassID = (nsCID*)moz_xmalloc(sizeof(nsCID));
|
2005-06-30 01:03:24 +04:00
|
|
|
return GetClassIDNoAlloc(*aClassID);
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:04:33 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03: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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc) {
|
2005-06-30 01:03:24 +04:00
|
|
|
*aClassIDNoAlloc = kSimpleURICID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-05-02 22:54:19 +04:00
|
|
|
|
2012-02-20 07:51:48 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsSimpleURI::nsISizeOf
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
size_t 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);
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
size_t 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
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetFilePath(nsACString& aFilePath) {
|
2016-11-14 15:04:33 +03:00
|
|
|
aFilePath = mPath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetFilePath(const nsACString& aFilePath) {
|
2018-12-12 01:01:58 +03:00
|
|
|
if (mPath.IsEmpty() || mPath.First() != '/') {
|
|
|
|
// cannot-be-a-base
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* current = aFilePath.BeginReading();
|
|
|
|
const char* end = aFilePath.EndReading();
|
2018-12-12 01:01:58 +03:00
|
|
|
|
|
|
|
// Only go up to the first ? or # symbol
|
|
|
|
for (; current < end; ++current) {
|
|
|
|
if (*current == '?' || *current == '#') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SetPathQueryRef(
|
|
|
|
nsDependentCSubstring(aFilePath.BeginReading(), current));
|
2016-11-14 15:04:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::GetQuery(nsACString& aQuery) {
|
2016-11-14 15:04:33 +03:00
|
|
|
if (!mIsQueryValid) {
|
|
|
|
MOZ_ASSERT(mQuery.IsEmpty(), "mIsQueryValid/mQuery invariant broken");
|
|
|
|
aQuery.Truncate();
|
|
|
|
} else {
|
|
|
|
aQuery = mQuery;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetQuery(const nsACString& aQuery) {
|
2016-11-14 15:04:33 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSimpleURI::SetQueryWithEncoding(const nsACString& aQuery,
|
|
|
|
const Encoding* aEncoding) {
|
2017-08-02 14:43:30 +03:00
|
|
|
return SetQuery(aQuery);
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:22:32 +03:00
|
|
|
// Queries this list of interfaces. If none match, it queries mURI.
|
|
|
|
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsSimpleURI::Mutator, nsIURISetters,
|
|
|
|
nsIURIMutator, nsISerializable)
|
2017-11-20 19:11:30 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSimpleURI::Mutate(nsIURIMutator** aMutator) {
|
2017-11-20 19:11:30 +03:00
|
|
|
RefPtr<nsSimpleURI::Mutator> mutator = new nsSimpleURI::Mutator();
|
|
|
|
nsresult rv = mutator->InitFromURI(this);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mutator.forget(aMutator);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|