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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsSimpleURI methods:
|
|
|
|
|
2010-06-13 00:40:05 +04:00
|
|
|
nsSimpleURI::nsSimpleURI()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mMutable(true),
|
|
|
|
mIsRefValid(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)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable, nsIClassInfo,
|
2012-08-23 23:33:46 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
2011-05-22 05:12:45 +04:00
|
|
|
if (mIsRefValid) {
|
2012-08-23 23:33:46 +04:00
|
|
|
params.ref() = mRef;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
params.ref().SetIsVoid(true);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
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();
|
|
|
|
if (params.ref().IsVoid()) {
|
|
|
|
mRef.Truncate();
|
|
|
|
mIsRefValid = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mRef = params.ref();
|
|
|
|
mIsRefValid = true;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mScheme + NS_LITERAL_CSTRING(":") + mPath;
|
2011-05-22 05:12:45 +04:00
|
|
|
if (mIsRefValid) {
|
|
|
|
result += NS_LITERAL_CSTRING("#") + mRef;
|
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
|
|
|
}
|
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;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2003-07-09 00:09:17 +04:00
|
|
|
const nsAFlatCString& flat = PromiseFlatCString(aSpec);
|
|
|
|
const char* specPtr = flat.get();
|
|
|
|
|
|
|
|
// filter out unexpected chars "\r\n\t" if necessary
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString filteredSpec;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t specLen;
|
2003-07-09 00:09:17 +04:00
|
|
|
if (net_FilterURIString(specPtr, filteredSpec)) {
|
|
|
|
specPtr = filteredSpec.get();
|
|
|
|
specLen = filteredSpec.Length();
|
|
|
|
} else
|
|
|
|
specLen = flat.Length();
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// nsSimpleURI currently restricts the charset to US-ASCII
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2003-07-09 00:09:17 +04:00
|
|
|
NS_EscapeURL(specPtr, specLen, esc_OnlyNonASCII|esc_AlwaysCopy, spec);
|
2000-04-02 02:31:00 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t colonPos = spec.FindChar(':');
|
2011-05-22 05:12:45 +04:00
|
|
|
if (colonPos < 0 || !net_IsValidScheme(spec.get(), colonPos))
|
2003-07-15 11:01:16 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
mScheme.Truncate();
|
2012-08-22 19:56:38 +04:00
|
|
|
mozilla::DebugOnly<int32_t> n = spec.Left(mScheme, colonPos);
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_ASSERTION(n == colonPos, "Left failed");
|
2001-03-24 03:58:32 +03:00
|
|
|
ToLowerCase(mScheme);
|
2011-05-22 05:12:45 +04:00
|
|
|
|
|
|
|
// This sets both mPath and mRef.
|
|
|
|
return SetPath(Substring(spec, colonPos + 1));
|
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)) {
|
|
|
|
NS_ERROR("the given url scheme contains invalid characters");
|
|
|
|
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
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
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.
|
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);
|
|
|
|
|
2000-02-03 06:44:22 +03:00
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
1999-07-01 11:52:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::GetPath(nsACString &result)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mPath;
|
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
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::SetPath(const nsACString &path)
|
1999-07-01 11:52:52 +04:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_STATE(mMutable);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t hashPos = path.FindChar('#');
|
2011-05-22 05:12:45 +04:00
|
|
|
if (hashPos < 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsRefValid = false;
|
2011-05-24 19:40:10 +04:00
|
|
|
mRef.Truncate(); // invariant: mRef should be empty when it's not valid
|
2011-05-22 05:12:45 +04:00
|
|
|
mPath = path;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPath = StringHead(path, hashPos);
|
2012-08-22 19:56:38 +04:00
|
|
|
return SetRef(Substring(path, uint32_t(hashPos)));
|
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) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
|
2011-05-22 05:12:45 +04:00
|
|
|
result.Truncate();
|
|
|
|
} else {
|
|
|
|
result = mRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (aRef.IsEmpty()) {
|
|
|
|
// Empty string means to remove ref completely.
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsRefValid = false;
|
2011-05-24 19:40:10 +04:00
|
|
|
mRef.Truncate(); // invariant: mRef should be empty when it's not valid
|
2011-05-22 05:12:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsRefValid = true;
|
2011-05-22 05:12:45 +04:00
|
|
|
|
|
|
|
// Gracefully skip initial hash
|
|
|
|
if (aRef[0] == '#') {
|
|
|
|
mRef = Substring(aRef, 1);
|
|
|
|
} else {
|
|
|
|
mRef = aRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
nsRefPtr<nsSimpleURI> otherUri;
|
|
|
|
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);
|
|
|
|
|
|
|
|
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*
|
2011-05-22 05:12:45 +04:00
|
|
|
nsSimpleURI::StartClone(nsSimpleURI::RefHandlingEnum /* ignored */)
|
2006-05-02 22:54:19 +04:00
|
|
|
{
|
2010-06-13 00:40:05 +04:00
|
|
|
return new nsSimpleURI();
|
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
|
|
|
{
|
2011-05-22 05:12:45 +04:00
|
|
|
return CloneInternal(eHonorRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::CloneIgnoringRef(nsIURI** result)
|
|
|
|
{
|
|
|
|
return CloneInternal(eIgnoreRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSimpleURI::CloneInternal(nsSimpleURI::RefHandlingEnum refHandlingMode,
|
|
|
|
nsIURI** result)
|
|
|
|
{
|
2011-05-22 05:12:45 +04:00
|
|
|
nsRefPtr<nsSimpleURI> url = StartClone(refHandlingMode);
|
|
|
|
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;
|
2011-05-22 05:12:45 +04:00
|
|
|
if (refHandlingMode == eHonorRef) {
|
|
|
|
url->mRef = mRef;
|
2011-05-24 19:40:10 +04:00
|
|
|
url->mIsRefValid = mIsRefValid;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
2002-03-06 10:48:55 +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
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSimpleURI::Resolve(const nsACString &relativePath, nsACString &result)
|
|
|
|
{
|
|
|
|
result = relativePath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetAsciiSpec(nsACString &result)
|
1999-11-03 08:13:44 +03:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult rv = GetSpec(buf);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
NS_EscapeURL(buf, esc_OnlyNonASCII|esc_AlwaysCopy, result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetAsciiHost(nsACString &result)
|
|
|
|
{
|
|
|
|
result.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetOriginCharset(nsACString &result)
|
|
|
|
{
|
|
|
|
result.Truncate();
|
|
|
|
return NS_OK;
|
1999-11-03 08:13:44 +03:00
|
|
|
}
|
|
|
|
|
2005-06-30 01:03:24 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsSimpleURI::nsIClassInfo
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetContractID(char * *aContractID)
|
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
// Make sure to modify any subclasses as needed if this ever
|
|
|
|
// changes.
|
2012-07-30 18:20:58 +04:00
|
|
|
*aContractID = nullptr;
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleURI::GetClassDescription(char * *aClassDescription)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aClassDescription = nullptr;
|
2005-06-30 01:03:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsSimpleURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-20 07:51:48 +04:00
|
|
|
{
|
|
|
|
return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
mRef.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsSimpleURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
2012-02-20 07:51:48 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|