2001-09-20 04:02:59 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2015-02-13 02:41:21 +03:00
|
|
|
* vim: set sw=2 sts=2 ts=2 et tw=80:
|
2001-04-10 07:40:02 +04:00
|
|
|
*
|
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/. */
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2016-06-30 20:27:03 +03:00
|
|
|
#include "nsIconURI.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2016-06-30 20:27:03 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2015-02-13 02:41:21 +03:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2015-02-13 02:41:21 +03:00
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
#include "nsIIOService.h"
|
2001-04-14 03:58:24 +04:00
|
|
|
#include "nsIURL.h"
|
2015-08-26 12:24:04 +03:00
|
|
|
#include "nsNetUtil.h"
|
2006-04-27 18:41:11 +04:00
|
|
|
#include "plstr.h"
|
|
|
|
#include <stdlib.h>
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2015-02-13 02:41:21 +03:00
|
|
|
using namespace mozilla::ipc;
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2010-05-14 00:20:30 +04:00
|
|
|
#define DEFAULT_IMAGE_SIZE 16
|
|
|
|
|
|
|
|
#if defined(MAX_PATH)
|
|
|
|
#define SANE_FILE_NAME_LEN MAX_PATH
|
|
|
|
#elif defined(PATH_MAX)
|
|
|
|
#define SANE_FILE_NAME_LEN PATH_MAX
|
|
|
|
#else
|
|
|
|
#define SANE_FILE_NAME_LEN 1024
|
|
|
|
#endif
|
2001-04-13 04:08:25 +04:00
|
|
|
|
|
|
|
// helper function for parsing out attributes like size, and contentType
|
|
|
|
// from the icon url.
|
2014-11-14 20:59:00 +03:00
|
|
|
static void extractAttributeValue(const char* aSearchString,
|
|
|
|
const char* aAttributeName,
|
|
|
|
nsCString& aResult);
|
|
|
|
|
|
|
|
static const char* kSizeStrings[] =
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
"button",
|
|
|
|
"toolbar",
|
|
|
|
"toolbarsmall",
|
|
|
|
"menu",
|
2007-12-05 04:08:23 +03:00
|
|
|
"dnd",
|
2007-11-09 11:23:13 +03:00
|
|
|
"dialog"
|
2005-01-19 14:27:21 +03:00
|
|
|
};
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
static const char* kStateStrings[] =
|
2006-04-27 18:41:11 +04:00
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
"normal",
|
|
|
|
"disabled"
|
2006-04-27 18:41:11 +04:00
|
|
|
};
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-11-14 20:59:00 +03:00
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
nsMozIconURI::nsMozIconURI()
|
2007-11-09 11:23:13 +03:00
|
|
|
: mSize(DEFAULT_IMAGE_SIZE),
|
|
|
|
mIconSize(-1),
|
|
|
|
mIconState(-1)
|
2014-11-14 20:59:00 +03:00
|
|
|
{ }
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
nsMozIconURI::~nsMozIconURI()
|
2014-11-14 20:59:00 +03:00
|
|
|
{ }
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2015-02-13 02:41:21 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI, nsIIPCSerializableURI)
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2010-05-14 00:20:30 +04:00
|
|
|
#define MOZICON_SCHEME "moz-icon:"
|
|
|
|
#define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2007-11-09 11:23:13 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-02-20 07:51:48 +04:00
|
|
|
// nsIURI methods:
|
2007-11-09 11:23:13 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetSpec(nsACString& aSpec)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
aSpec = MOZICON_SCHEME;
|
2001-04-14 03:58:24 +04:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconURL) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString fileIconSpec;
|
2010-05-14 00:20:30 +04:00
|
|
|
nsresult rv = mIconURL->GetSpec(fileIconSpec);
|
2001-04-13 04:08:25 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += fileIconSpec;
|
2014-11-14 20:59:00 +03:00
|
|
|
} else if (!mStockIcon.IsEmpty()) {
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += "//stock/";
|
|
|
|
aSpec += mStockIcon;
|
2014-11-14 20:59:00 +03:00
|
|
|
} else {
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += "//";
|
2010-05-14 00:20:30 +04:00
|
|
|
aSpec += mFileName;
|
2001-04-13 04:08:25 +04:00
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += "?size=";
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconSize >= 0) {
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += kSizeStrings[mIconSize];
|
2014-11-14 20:59:00 +03:00
|
|
|
} else {
|
2006-04-27 18:41:11 +04:00
|
|
|
char buf[20];
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(buf, "%d", mSize);
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec.Append(buf);
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
|
|
|
|
2007-11-09 11:23:13 +03:00
|
|
|
if (mIconState >= 0) {
|
|
|
|
aSpec += "&state=";
|
|
|
|
aSpec += kStateStrings[mIconState];
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!mContentType.IsEmpty()) {
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += "&contentType=";
|
|
|
|
aSpec += mContentType.get();
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
2014-11-14 20:59:00 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_OK;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetSpecIgnoringRef(nsACString& result)
|
2011-08-16 01:18:15 +04:00
|
|
|
{
|
|
|
|
return GetSpec(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetHasRef(bool* result)
|
2011-08-16 01:18:15 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2011-08-16 01:18:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
// takes a string like ?size=32&contentType=text/html and returns a new string
|
2001-04-13 04:08:25 +04:00
|
|
|
// containing just the attribute value. i.e you could pass in this string with
|
2006-04-14 23:45:39 +04:00
|
|
|
// an attribute name of 'size=', this will return 32
|
2001-04-13 04:08:25 +04:00
|
|
|
// Assumption: attribute pairs in the string are separated by '&'.
|
2014-11-14 20:59:00 +03:00
|
|
|
void
|
|
|
|
extractAttributeValue(const char* aSearchString,
|
|
|
|
const char* aAttributeName,
|
|
|
|
nsCString& aResult)
|
2001-04-13 04:08:25 +04:00
|
|
|
{
|
|
|
|
//NS_ENSURE_ARG_POINTER(extractAttributeValue);
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
aResult.Truncate();
|
2006-04-27 18:41:11 +04:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (aSearchString && aAttributeName) {
|
2006-04-27 18:41:11 +04:00
|
|
|
// search the string for attributeName
|
2014-11-14 20:59:00 +03:00
|
|
|
uint32_t attributeNameSize = strlen(aAttributeName);
|
|
|
|
const char* startOfAttribute = PL_strcasestr(aSearchString, aAttributeName);
|
2007-05-01 03:25:10 +04:00
|
|
|
if (startOfAttribute &&
|
2014-11-14 20:59:00 +03:00
|
|
|
( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') ) {
|
2006-04-27 18:41:11 +04:00
|
|
|
startOfAttribute += attributeNameSize; // skip over the attributeName
|
2014-11-14 20:59:00 +03:00
|
|
|
// is there something after the attribute name
|
|
|
|
if (*startOfAttribute) {
|
|
|
|
const char* endofAttribute = strchr(startOfAttribute, '&');
|
|
|
|
if (endofAttribute) {
|
|
|
|
aResult.Assign(Substring(startOfAttribute, endofAttribute));
|
|
|
|
} else {
|
|
|
|
aResult.Assign(startOfAttribute);
|
|
|
|
}
|
2006-04-27 18:41:11 +04:00
|
|
|
} // if we have a attribute value
|
|
|
|
} // if we have a attribute name
|
|
|
|
} // if we got non-null search string and attribute name values
|
2001-04-13 04:08:25 +04:00
|
|
|
}
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetSpec(const nsACString& aSpec)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
// Reset everything to default values.
|
2012-07-30 18:20:58 +04:00
|
|
|
mIconURL = nullptr;
|
2010-05-14 00:20:30 +04:00
|
|
|
mSize = DEFAULT_IMAGE_SIZE;
|
|
|
|
mContentType.Truncate();
|
|
|
|
mFileName.Truncate();
|
|
|
|
mStockIcon.Truncate();
|
|
|
|
mIconSize = -1;
|
|
|
|
mIconState = -1;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString iconSpec(aSpec);
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!Substring(iconSpec, 0,
|
|
|
|
MOZICON_SCHEME_LEN).EqualsLiteral(MOZICON_SCHEME)) {
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t questionMarkPos = iconSpec.Find("?");
|
2014-11-14 20:59:00 +03:00
|
|
|
if (questionMarkPos != -1 &&
|
|
|
|
static_cast<int32_t>(iconSpec.Length()) > (questionMarkPos + 1)) {
|
2010-05-14 00:20:30 +04:00
|
|
|
extractAttributeValue(iconSpec.get(), "contentType=", mContentType);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString sizeString;
|
2010-05-14 00:20:30 +04:00
|
|
|
extractAttributeValue(iconSpec.get(), "size=", sizeString);
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!sizeString.IsEmpty()) {
|
|
|
|
const char* sizeStr = sizeString.get();
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(kSizeStrings); i++) {
|
|
|
|
if (PL_strcasecmp(sizeStr, kSizeStrings[i]) == 0) {
|
2010-05-14 00:20:30 +04:00
|
|
|
mIconSize = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t sizeValue = atoi(sizeString.get());
|
2016-06-23 17:47:36 +03:00
|
|
|
if (sizeValue > 0) {
|
2010-05-14 00:20:30 +04:00
|
|
|
mSize = sizeValue;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2001-04-13 04:08:25 +04:00
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString stateString;
|
2010-05-14 00:20:30 +04:00
|
|
|
extractAttributeValue(iconSpec.get(), "state=", stateString);
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!stateString.IsEmpty()) {
|
|
|
|
const char* stateStr = stateString.get();
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(kStateStrings); i++) {
|
|
|
|
if (PL_strcasecmp(stateStr, kStateStrings[i]) == 0) {
|
2010-05-14 00:20:30 +04:00
|
|
|
mIconState = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t pathLength = iconSpec.Length() - MOZICON_SCHEME_LEN;
|
2014-11-14 20:59:00 +03:00
|
|
|
if (questionMarkPos != -1) {
|
2010-05-14 00:20:30 +04:00
|
|
|
pathLength = questionMarkPos - MOZICON_SCHEME_LEN;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
|
|
|
if (pathLength < 3) {
|
2010-05-14 00:20:30 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString iconPath(Substring(iconSpec, MOZICON_SCHEME_LEN, pathLength));
|
2010-05-14 00:20:30 +04:00
|
|
|
|
|
|
|
// Icon URI path can have three forms:
|
|
|
|
// (1) //stock/<icon-identifier>
|
2001-04-14 03:58:24 +04:00
|
|
|
// (2) //<some dummy file with an extension>
|
2010-05-14 00:20:30 +04:00
|
|
|
// (3) a valid URL
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!strncmp("//stock/", iconPath.get(), 8)) {
|
2010-05-14 00:20:30 +04:00
|
|
|
mStockIcon.Assign(Substring(iconPath, 8));
|
2011-04-06 22:31:14 +04:00
|
|
|
// An icon identifier must always be specified.
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mStockIcon.IsEmpty()) {
|
2011-04-06 22:31:14 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (StringBeginsWith(iconPath, NS_LITERAL_CSTRING("//"))) {
|
2010-05-14 00:20:30 +04:00
|
|
|
// Sanity check this supposed dummy file name.
|
2014-11-14 20:59:00 +03:00
|
|
|
if (iconPath.Length() > SANE_FILE_NAME_LEN) {
|
2010-05-14 00:20:30 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2010-06-17 15:27:14 +04:00
|
|
|
iconPath.Cut(0, 2);
|
|
|
|
mFileName.Assign(iconPath);
|
2010-05-14 00:20:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2012-07-30 18:20:58 +04:00
|
|
|
ioService->NewURI(iconPath, nullptr, nullptr, getter_AddRefs(uri));
|
2010-06-17 15:27:14 +04:00
|
|
|
mIconURL = do_QueryInterface(uri);
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconURL) {
|
2010-06-17 15:27:14 +04:00
|
|
|
mFileName.Truncate();
|
2014-11-14 20:59:00 +03:00
|
|
|
} else if (mFileName.IsEmpty()) {
|
2010-06-17 15:27:14 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
|
2010-06-17 15:27:14 +04:00
|
|
|
return NS_OK;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetPrePath(nsACString& prePath)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
prePath = MOZICON_SCHEME;
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_OK;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetScheme(nsACString& aScheme)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
aScheme = "moz-icon";
|
|
|
|
return NS_OK;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetScheme(const nsACString& aScheme)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
// doesn't make sense to set the scheme of a moz-icon URL
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetUsername(nsACString& aUsername)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetUsername(const nsACString& aUsername)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetPassword(nsACString& aPassword)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetPassword(const nsACString& aPassword)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetUserPass(nsACString& aUserPass)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetUserPass(const nsACString& aUserPass)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetHostPort(nsACString& aHostPort)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetHostPort(const nsACString& aHostPort)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:25:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::SetHostAndPort(const nsACString& aHostPort)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetHost(nsACString& aHost)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetHost(const nsACString& aHost)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-07 05:12:00 +03:00
|
|
|
nsMozIconURI::GetPort(int32_t* aPort)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-11-14 20:59:00 +03:00
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsMozIconURI::SetPort(int32_t aPort)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetPath(nsACString& aPath)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
aPath.Truncate();
|
|
|
|
return NS_OK;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetPath(const nsACString& aPath)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetRef(nsACString& aRef)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
aRef.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetRef(const nsACString& aRef)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-07 05:12:00 +03:00
|
|
|
nsMozIconURI::Equals(nsIURI* other, bool* result)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2016-08-29 08:34:32 +03:00
|
|
|
*result = false;
|
2003-02-01 12:09:24 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(other);
|
|
|
|
NS_PRECONDITION(result, "null pointer");
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec1;
|
|
|
|
nsAutoCString spec2;
|
2001-04-12 04:19:52 +04:00
|
|
|
|
2016-08-29 08:34:32 +03:00
|
|
|
nsresult rv = GetSpec(spec1);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = other->GetSpec(spec2);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!PL_strcasecmp(spec1.get(), spec2.get())) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = true;
|
2014-11-14 20:59:00 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::EqualsExceptRef(nsIURI* other, bool* result)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
// GetRef/SetRef not supported by nsMozIconURI, so
|
|
|
|
// EqualsExceptRef() is the same as Equals().
|
|
|
|
return Equals(other, result);
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SchemeIs(const char* aScheme, bool* aEquals)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2014-11-14 20:59:00 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEquals);
|
|
|
|
if (!aScheme) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aEquals = PL_strcasecmp("moz-icon", aScheme) ? false : true;
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::Clone(nsIURI** result)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
nsCOMPtr<nsIURL> newIconURL;
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconURL) {
|
2010-05-14 00:20:30 +04:00
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
nsresult rv = mIconURL->Clone(getter_AddRefs(newURI));
|
2014-11-14 20:59:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2010-05-14 00:20:30 +04:00
|
|
|
return rv;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
newIconURL = do_QueryInterface(newURI, &rv);
|
2014-11-14 20:59:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2006-04-23 23:02:19 +04:00
|
|
|
return rv;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2006-04-23 23:02:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI* uri = new nsMozIconURI();
|
2010-05-14 00:20:30 +04:00
|
|
|
newIconURL.swap(uri->mIconURL);
|
2006-04-23 23:02:19 +04:00
|
|
|
uri->mSize = mSize;
|
|
|
|
uri->mContentType = mContentType;
|
2010-05-14 00:20:30 +04:00
|
|
|
uri->mFileName = mFileName;
|
2006-04-23 23:02:19 +04:00
|
|
|
uri->mStockIcon = mStockIcon;
|
|
|
|
uri->mIconSize = mIconSize;
|
|
|
|
uri->mIconState = mIconState;
|
|
|
|
NS_ADDREF(*result = uri);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::CloneIgnoringRef(nsIURI** result)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
// GetRef/SetRef not supported by nsMozIconURI, so
|
|
|
|
// CloneIgnoringRef() is the same as Clone().
|
|
|
|
return Clone(result);
|
|
|
|
}
|
|
|
|
|
2016-07-27 01:38:46 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::CloneWithNewRef(const nsACString& newRef, nsIURI** result)
|
|
|
|
{
|
|
|
|
// GetRef/SetRef not supported by nsMozIconURI, so
|
|
|
|
// CloneWithNewRef() is the same as Clone().
|
|
|
|
return Clone(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::Resolve(const nsACString& relativePath, nsACString& result)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
2005-11-08 23:13:39 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetAsciiSpec(nsACString& aSpecA)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
return GetSpec(aSpecA);
|
|
|
|
}
|
|
|
|
|
2015-08-17 22:34:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetAsciiHostPort(nsACString& aHostPortA)
|
|
|
|
{
|
|
|
|
return GetHostPort(aHostPortA);
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetAsciiHost(nsACString& aHostA)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
return GetHost(aHostA);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetOriginCharset(nsACString& result)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result.Truncate();
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-04-14 03:58:24 +04:00
|
|
|
// nsIIconUri methods:
|
2001-04-10 07:40:02 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetIconURL(nsIURL** aFileUrl)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
*aFileUrl = mIconURL;
|
2001-04-14 03:58:24 +04:00
|
|
|
NS_IF_ADDREF(*aFileUrl);
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-14 00:20:30 +04:00
|
|
|
nsMozIconURI::SetIconURL(nsIURL* aFileUrl)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2007-05-01 03:25:10 +04:00
|
|
|
// this isn't called anywhere, needs to go through SetSpec parsing
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-04-07 05:12:00 +03:00
|
|
|
nsMozIconURI::GetImageSize(uint32_t* aImageSize)
|
2014-11-14 20:59:00 +03:00
|
|
|
// measured by # of pixels in a row. defaults to 16.
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
*aImageSize = mSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetImageSize(uint32_t aImageSize)
|
|
|
|
// measured by # of pixels in a row. defaults to 16.
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
mSize = aImageSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetContentType(nsACString& aContentType)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
aContentType = mContentType;
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::SetContentType(const nsACString& aContentType)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
mContentType = aContentType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-14 03:58:24 +04:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetFileExtension(nsACString& aFileExtension)
|
2001-04-14 03:58:24 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
// First, try to get the extension from mIconURL if we have one
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconURL) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString fileExt;
|
2014-11-14 20:59:00 +03:00
|
|
|
if (NS_SUCCEEDED(mIconURL->GetFileExtension(fileExt))) {
|
|
|
|
if (!fileExt.IsEmpty()) {
|
|
|
|
// unfortunately, this code doesn't give us the required '.' in
|
|
|
|
// front of the extension so we have to do it ourselves.
|
2006-04-27 18:41:11 +04:00
|
|
|
aFileExtension.Assign('.');
|
|
|
|
aFileExtension.Append(fileExt);
|
2001-04-14 03:58:24 +04:00
|
|
|
}
|
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
return NS_OK;
|
2001-04-14 03:58:24 +04:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
if (!mFileName.IsEmpty()) {
|
2010-05-14 00:20:30 +04:00
|
|
|
// truncate the extension out of the file path...
|
2014-11-14 20:59:00 +03:00
|
|
|
const char* chFileName = mFileName.get(); // get the underlying buffer
|
|
|
|
const char* fileExt = strrchr(chFileName, '.');
|
|
|
|
if (!fileExt) {
|
2010-05-14 00:20:30 +04:00
|
|
|
return NS_OK;
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
aFileExtension = fileExt;
|
2001-04-14 03:58:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-19 14:27:21 +03:00
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetStockIcon(nsACString& aStockIcon)
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
aStockIcon = mStockIcon;
|
2005-01-19 14:27:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetIconSize(nsACString& aSize)
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconSize >= 0) {
|
2007-11-09 11:23:13 +03:00
|
|
|
aSize = kSizeStrings[mIconSize];
|
2014-11-14 20:59:00 +03:00
|
|
|
} else {
|
2007-11-09 11:23:13 +03:00
|
|
|
aSize.Truncate();
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-11-14 20:59:00 +03:00
|
|
|
nsMozIconURI::GetIconState(nsACString& aState)
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2014-11-14 20:59:00 +03:00
|
|
|
if (mIconState >= 0) {
|
2007-11-09 11:23:13 +03:00
|
|
|
aState = kStateStrings[mIconState];
|
2014-11-14 20:59:00 +03:00
|
|
|
} else {
|
2007-11-09 11:23:13 +03:00
|
|
|
aState.Truncate();
|
2014-11-14 20:59:00 +03:00
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-02-13 02:41:21 +03:00
|
|
|
// nsIIPCSerializableURI methods:
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMozIconURI::Serialize(URIParams& aParams)
|
|
|
|
{
|
|
|
|
IconURIParams params;
|
|
|
|
|
|
|
|
if (mIconURL) {
|
|
|
|
URIParams iconURLParams;
|
|
|
|
SerializeURI(mIconURL, iconURLParams);
|
|
|
|
if (iconURLParams.type() == URIParams::T__None) {
|
|
|
|
// Serialization failed, bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
params.uri() = iconURLParams;
|
|
|
|
} else {
|
|
|
|
params.uri() = void_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
params.size() = mSize;
|
|
|
|
params.fileName() = mFileName;
|
|
|
|
params.stockIcon() = mStockIcon;
|
|
|
|
params.iconSize() = mIconSize;
|
|
|
|
params.iconState() = mIconState;
|
|
|
|
|
|
|
|
aParams = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsMozIconURI::Deserialize(const URIParams& aParams)
|
|
|
|
{
|
|
|
|
if (aParams.type() != URIParams::TIconURIParams) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Received unknown URI from other process!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IconURIParams& params = aParams.get_IconURIParams();
|
|
|
|
if (params.uri().type() != OptionalURIParams::Tvoid_t) {
|
|
|
|
nsCOMPtr<nsIURI> uri = DeserializeURI(params.uri().get_URIParams());
|
|
|
|
mIconURL = do_QueryInterface(uri);
|
|
|
|
if (!mIconURL) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("bad nsIURI passed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mSize = params.size();
|
|
|
|
mContentType = params.contentType();
|
|
|
|
mFileName = params.fileName();
|
|
|
|
mStockIcon = params.stockIcon();
|
|
|
|
mIconSize = params.iconSize();
|
|
|
|
mIconState = params.iconState();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-26 12:24:04 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Nested version of nsIconURI
|
|
|
|
|
|
|
|
nsNestedMozIconURI::nsNestedMozIconURI()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsNestedMozIconURI::~nsNestedMozIconURI()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsNestedMozIconURI, nsMozIconURI, nsINestedURI)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNestedMozIconURI::GetInnerURI(nsIURI** aURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> iconURL = do_QueryInterface(mIconURL);
|
|
|
|
if (iconURL) {
|
|
|
|
iconURL.forget(aURI);
|
|
|
|
} else {
|
|
|
|
*aURI = nullptr;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNestedMozIconURI::GetInnermostURI(nsIURI** aURI)
|
|
|
|
{
|
|
|
|
return NS_ImplGetInnermostURI(this, aURI);
|
|
|
|
}
|
|
|
|
|