2001-09-20 04:02:59 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2001-04-10 07:40:02 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-04-10 07:40:02 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
2001-09-20 04:02:59 +04:00
|
|
|
* for the specific language governing rights and limitations under the
|
2004-04-19 02:01:16 +04:00
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org Code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Scott MacGregor <mscott@netscape.com>
|
2001-04-10 07:40:02 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-04-10 07:40:02 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
#include "nsIconURI.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIIOService.h"
|
2001-04-14 03:58:24 +04:00
|
|
|
#include "nsIURL.h"
|
2006-04-27 18:41:11 +04:00
|
|
|
#include "prprf.h"
|
|
|
|
#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;
|
|
|
|
|
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.
|
2006-04-27 18:41:11 +04:00
|
|
|
static void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& aResult);
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2007-11-09 11:23:13 +03:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2007-11-09 11:23:13 +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
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsMozIconURI::nsMozIconURI()
|
2007-11-09 11:23:13 +03:00
|
|
|
: mSize(DEFAULT_IMAGE_SIZE),
|
|
|
|
mIconSize(-1),
|
|
|
|
mIconState(-1)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMozIconURI::~nsMozIconURI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-08-01 00:21:01 +04:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsMozIconURI, nsIMozIconURI, nsIURI)
|
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
|
|
|
|
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
|
|
|
|
2010-05-14 00:20:30 +04:00
|
|
|
if (mIconURL)
|
2001-04-13 04:08:25 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString 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;
|
2001-04-14 03:58:24 +04:00
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
else if (!mStockIcon.IsEmpty())
|
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += "//stock/";
|
|
|
|
aSpec += mStockIcon;
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
2001-04-14 03:58:24 +04: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=";
|
|
|
|
if (mIconSize >= 0)
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
aSpec += kSizeStrings[mIconSize];
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-27 18:41:11 +04:00
|
|
|
char buf[20];
|
|
|
|
PR_snprintf(buf, sizeof(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
|
|
|
}
|
|
|
|
|
2001-04-10 07:40:02 +04: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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsMozIconURI::GetSpecIgnoringRef(nsACString &result)
|
|
|
|
{
|
|
|
|
return GetSpec(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04: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;
|
|
|
|
}
|
|
|
|
|
2001-04-13 04:08:25 +04:00
|
|
|
// takes a string like ?size=32&contentType=text/html and returns a new string
|
|
|
|
// 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 '&'.
|
2006-04-27 18:41:11 +04:00
|
|
|
void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& result)
|
2001-04-13 04:08:25 +04:00
|
|
|
{
|
|
|
|
//NS_ENSURE_ARG_POINTER(extractAttributeValue);
|
|
|
|
|
2006-04-27 18:41:11 +04:00
|
|
|
result.Truncate();
|
|
|
|
|
2007-05-01 03:25:10 +04:00
|
|
|
if (searchString && attributeName)
|
2006-04-27 18:41:11 +04:00
|
|
|
{
|
|
|
|
// search the string for attributeName
|
|
|
|
PRUint32 attributeNameSize = strlen(attributeName);
|
|
|
|
const char * startOfAttribute = PL_strcasestr(searchString, attributeName);
|
2007-05-01 03:25:10 +04:00
|
|
|
if (startOfAttribute &&
|
|
|
|
( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') )
|
2006-04-27 18:41:11 +04:00
|
|
|
{
|
|
|
|
startOfAttribute += attributeNameSize; // skip over the attributeName
|
|
|
|
if (*startOfAttribute) // is there something after the attribute name
|
|
|
|
{
|
|
|
|
const char * endofAttribute = strchr(startOfAttribute, '&');
|
|
|
|
if (endofAttribute)
|
|
|
|
result.Assign(Substring(startOfAttribute, endofAttribute));
|
|
|
|
else
|
|
|
|
result.Assign(startOfAttribute);
|
|
|
|
} // 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
|
2002-03-06 10:48:55 +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.
|
|
|
|
mIconURL = nsnull;
|
|
|
|
mSize = DEFAULT_IMAGE_SIZE;
|
|
|
|
mContentType.Truncate();
|
|
|
|
mFileName.Truncate();
|
|
|
|
mStockIcon.Truncate();
|
|
|
|
mIconSize = -1;
|
|
|
|
mIconState = -1;
|
|
|
|
|
|
|
|
nsCAutoString iconSpec(aSpec);
|
|
|
|
if (!Substring(iconSpec, 0, MOZICON_SCHEME_LEN).EqualsLiteral(MOZICON_SCHEME))
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
|
2010-05-14 00:20:30 +04:00
|
|
|
PRInt32 questionMarkPos = iconSpec.Find("?");
|
|
|
|
if (questionMarkPos != -1 && static_cast<PRInt32>(iconSpec.Length()) > (questionMarkPos + 1))
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
extractAttributeValue(iconSpec.get(), "contentType=", mContentType);
|
|
|
|
|
|
|
|
nsCAutoString sizeString;
|
|
|
|
extractAttributeValue(iconSpec.get(), "size=", sizeString);
|
|
|
|
if (!sizeString.IsEmpty())
|
|
|
|
{
|
|
|
|
const char *sizeStr = sizeString.get();
|
2011-10-11 09:50:08 +04:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(kSizeStrings); i++)
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
if (PL_strcasecmp(sizeStr, kSizeStrings[i]) == 0)
|
|
|
|
{
|
|
|
|
mIconSize = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
2010-05-14 00:20:30 +04:00
|
|
|
|
|
|
|
PRInt32 sizeValue = atoi(sizeString.get());
|
|
|
|
if (sizeValue)
|
|
|
|
mSize = sizeValue;
|
2001-04-13 04:08:25 +04:00
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
|
2010-05-14 00:20:30 +04:00
|
|
|
nsCAutoString stateString;
|
|
|
|
extractAttributeValue(iconSpec.get(), "state=", stateString);
|
|
|
|
if (!stateString.IsEmpty())
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
const char *stateStr = stateString.get();
|
2011-10-11 09:50:08 +04:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(kStateStrings); i++)
|
2005-01-19 14:27:21 +03:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
if (PL_strcasecmp(stateStr, kStateStrings[i]) == 0)
|
|
|
|
{
|
|
|
|
mIconState = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-19 14:27:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 00:20:30 +04:00
|
|
|
PRInt32 pathLength = iconSpec.Length() - MOZICON_SCHEME_LEN;
|
|
|
|
if (questionMarkPos != -1)
|
|
|
|
pathLength = questionMarkPos - MOZICON_SCHEME_LEN;
|
|
|
|
if (pathLength < 3)
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
|
|
|
|
nsCAutoString iconPath(Substring(iconSpec, MOZICON_SCHEME_LEN, pathLength));
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
if (!strncmp("//stock/", iconPath.get(), 8))
|
2001-04-14 03:58:24 +04:00
|
|
|
{
|
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.
|
|
|
|
if (mStockIcon.IsEmpty())
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2010-05-14 00:20:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-17 15:27:14 +04:00
|
|
|
if (StringBeginsWith(iconPath, NS_LITERAL_CSTRING("//")))
|
2010-05-14 00:20:30 +04:00
|
|
|
{
|
|
|
|
// Sanity check this supposed dummy file name.
|
|
|
|
if (iconPath.Length() > SANE_FILE_NAME_LEN)
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
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;
|
2010-06-17 15:27:14 +04:00
|
|
|
ioService->NewURI(iconPath, nsnull, nsnull, getter_AddRefs(uri));
|
|
|
|
mIconURL = do_QueryInterface(uri);
|
|
|
|
if (mIconURL)
|
|
|
|
mFileName.Truncate();
|
|
|
|
else if (mFileName.IsEmpty())
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
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
|
2002-03-06 10:48:55 +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
|
2002-03-06 10:48:55 +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
|
2002-03-06 10:48:55 +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
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::GetUsername(nsACString &aUsername)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::SetUsername(const nsACString &aUsername)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::GetPassword(nsACString &aPassword)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::SetPassword(const nsACString &aPassword)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::GetUserPass(nsACString &aUserPass)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::SetUserPass(const nsACString &aUserPass)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::GetHostPort(nsACString &aHostPort)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::SetHostPort(const nsACString &aHostPort)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::GetHost(nsACString &aHost)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::SetHost(const nsACString &aHost)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetPort(PRInt32 *aPort)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::SetPort(PRInt32 aPort)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +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
|
2002-03-06 10:48:55 +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
|
|
|
|
nsMozIconURI::GetRef(nsACString &aRef)
|
|
|
|
{
|
|
|
|
aRef.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::SetRef(const nsACString &aRef)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-10 07:40:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsMozIconURI::Equals(nsIURI *other, bool *result)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
2003-02-01 12:09:24 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(other);
|
|
|
|
NS_PRECONDITION(result, "null pointer");
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString spec1;
|
|
|
|
nsCAutoString spec2;
|
2001-04-12 04:19:52 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
other->GetSpec(spec2);
|
|
|
|
GetSpec(spec1);
|
2006-04-27 18:41:11 +04:00
|
|
|
if (!PL_strcasecmp(spec1.get(), spec2.get()))
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = true;
|
2001-04-12 04:19:52 +04:00
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04: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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsMozIconURI::SchemeIs(const char *i_Scheme, bool *o_Equals)
|
2001-04-10 07:40:02 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(o_Equals);
|
|
|
|
if (!i_Scheme) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*o_Equals = PL_strcasecmp("moz-icon", i_Scheme) ? false : true;
|
2001-04-10 07:40:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::Clone(nsIURI **result)
|
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
nsCOMPtr<nsIURL> newIconURL;
|
|
|
|
if (mIconURL)
|
2006-04-23 23:02:19 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
nsresult rv = mIconURL->Clone(getter_AddRefs(newURI));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
newIconURL = do_QueryInterface(newURI, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
2006-04-23 23:02:19 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
nsMozIconURI::CloneIgnoringRef(nsIURI **result)
|
|
|
|
{
|
|
|
|
// GetRef/SetRef not supported by nsMozIconURI, so
|
|
|
|
// CloneIgnoringRef() is the same as Clone().
|
|
|
|
return Clone(result);
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:40:02 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsMozIconURI::Resolve(const nsACString &relativePath, nsACString &result)
|
|
|
|
{
|
2005-11-08 23:13:39 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetAsciiSpec(nsACString &aSpecA)
|
|
|
|
{
|
|
|
|
return GetSpec(aSpecA);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetAsciiHost(nsACString &aHostA)
|
|
|
|
{
|
|
|
|
return GetHost(aHostA);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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
|
2010-05-14 00:20:30 +04: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
|
|
|
|
nsMozIconURI::GetImageSize(PRUint32 * aImageSize) // measured by # of pixels in a row. defaults to 16.
|
|
|
|
{
|
|
|
|
*aImageSize = mSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::SetImageSize(PRUint32 aImageSize) // measured by # of pixels in a row. defaults to 16.
|
|
|
|
{
|
|
|
|
mSize = aImageSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-14 00:20:30 +04: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
|
2002-04-27 09:33:09 +04: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
|
2002-04-27 09:33:09 +04: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
|
|
|
|
if (mIconURL)
|
2001-04-14 03:58:24 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString fileExt;
|
2010-05-14 00:20:30 +04:00
|
|
|
if (NS_SUCCEEDED(mIconURL->GetFileExtension(fileExt)))
|
2001-04-14 03:58:24 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
if (!fileExt.IsEmpty())
|
2001-04-14 03:58:24 +04:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
|
|
if (!mFileName.IsEmpty())
|
2001-04-14 03:58:24 +04:00
|
|
|
{
|
2010-05-14 00:20:30 +04:00
|
|
|
// truncate the extension out of the file path...
|
|
|
|
const char * chFileName = mFileName.get(); // get the underlying buffer
|
|
|
|
const char * fileExt = strrchr(chFileName, '.');
|
|
|
|
if (!fileExt)
|
|
|
|
return NS_OK;
|
|
|
|
aFileExtension = fileExt;
|
2001-04-14 03:58:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-19 14:27:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetStockIcon(nsACString &aStockIcon)
|
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
aStockIcon = mStockIcon;
|
2005-01-19 14:27:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetIconSize(nsACString &aSize)
|
|
|
|
{
|
2007-11-09 11:23:13 +03:00
|
|
|
if (mIconSize >= 0)
|
|
|
|
aSize = kSizeStrings[mIconSize];
|
|
|
|
else
|
|
|
|
aSize.Truncate();
|
2005-01-19 14:27:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMozIconURI::GetIconState(nsACString &aState)
|
|
|
|
{
|
2008-01-13 05:53:33 +03:00
|
|
|
if (mIconState >= 0)
|
2007-11-09 11:23:13 +03:00
|
|
|
aState = kStateStrings[mIconState];
|
|
|
|
else
|
|
|
|
aState.Truncate();
|
2005-01-19 14:27:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-10 07:40:02 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|