fixes bug 309335 "Unknown content type dialog(helper app dialog) shows escaped file name if it has non-ASCII char" patch by biesi+darin r=bzbarsky

This commit is contained in:
darin%meer.net 2005-10-13 21:50:25 +00:00
Родитель 4824910e9f
Коммит 363a58640d
13 изменённых файлов: 161 добавлений и 474 удалений

Просмотреть файл

@ -1,324 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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
* for the specific language governing rights and limitations under the
* 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) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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.
*
* ***** END LICENSE BLOCK ***** */
#include <windows.h>
#include "nsNativeUConvService.h"
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "nsICharRepresentable.h"
#include "nsIPlatformCharset.h"
#include "nsIServiceManager.h"
#include "pldhash.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsURLProperties.h"
extern nsURLProperties* gCodePageInfo;
// maps charset names to windows codepages
static PLDHashTable* gCharsetToCPMap = nsnull;
struct CodePageMapEntry : public PLDHashEntryHdr
{
const char* mCharset;
UINT mCodePage;
};
static const struct PLDHashTableOps charsetMapOps = {
PL_DHashAllocTable,
PL_DHashFreeTable,
PL_DHashGetKeyStub,
PL_DHashStringKey,
PL_DHashMatchStringKey,
PL_DHashMoveEntryStub,
PL_DHashFreeStringKey,
PL_DHashFinalizeStub,
nsnull
};
BOOL CALLBACK AddCodePageEntry(LPTSTR aCodePageString)
{
CodePageMapEntry* entry =
NS_STATIC_CAST(CodePageMapEntry*,
PL_DHashTableOperate(gCharsetToCPMap, aCodePageString, PL_DHASH_ADD));
// always continue
if (!entry) return TRUE;
// add an entry
PRInt32 error;
entry->mCodePage = nsCAutoString(aCodePageString).ToInteger(&error);
// XXX handle error
nsAutoString charset;
gCodePageInfo->Get(NS_LITERAL_STRING("acp.") +
NS_ConvertASCIItoUCS2(aCodePageString), charset);
entry->mCharset = ToNewCString(charset);
printf("AddCodePageEntry(%d -> %s)\n", entry->mCodePage, entry->mCharset);
#if 1
// now try GetCPInfoEx
CPINFOEX cpinfo;
// now have to look this up with GetCPInfoEx()
GetCPInfoEx(entry->mCodePage, 0, &cpinfo);
// XXX handle error
printf(" --> %s\n", cpinfo.CodePageName);
#endif
return TRUE;
}
static
void InitCharsetToCPMap() {
NS_ASSERTION(!gCharsetToCPMap, "Double-init of charset table");
gCharsetToCPMap = new PLDHashTable;
PL_DHashTableInit(gCharsetToCPMap, &charsetMapOps,
nsnull, sizeof(CodePageMapEntry), 10);
EnumSystemCodePages(AddCodePageEntry, CP_INSTALLED); // CP_SUPPORTED
}
static void
FreeCharsetToCPMap() {
// free up codepage strings
}
static UINT CharsetToCodePage(const char* aCharset)
{
CodePageMapEntry* entry =
NS_STATIC_CAST(CodePageMapEntry*,
PL_DHashTableOperate(gCharsetToCPMap, aCharset,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_FREE(entry))
return 0;
return entry->mCodePage;
}
class WinUConvAdapter : public nsIUnicodeDecoder,
public nsIUnicodeEncoder,
public nsICharRepresentable
{
public:
WinUConvAdapter();
virtual ~WinUConvAdapter();
nsresult Init(const char* from, const char* to);
NS_DECL_ISUPPORTS;
// Decoder methods:
NS_IMETHOD Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength);
NS_IMETHOD Reset();
// Encoder methods:
NS_IMETHOD Convert(const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength);
NS_IMETHOD Finish(char * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength);
// defined by the Decoder: NS_IMETHOD Reset();
NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior,
nsIUnicharEncoder * aEncoder,
PRUnichar aChar);
NS_IMETHOD FillInfo(PRUint32* aInfo);
private:
static PRUint32 gRefCnt;
};
PRUint32 WinUConvAdapter::gRefCnt = 0;
NS_IMPL_ISUPPORTS3(WinUConvAdapter,
nsIUnicodeDecoder,
nsIUnicodeEncoder,
nsICharRepresentable)
WinUConvAdapter::WinUConvAdapter()
{
if (++gRefCnt == 1) {
nsCOMPtr<nsIPlatformCharset> platformCharset =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
InitCharsetToCPMap();
}
}
WinUConvAdapter::~WinUConvAdapter()
{
if (--gRefCnt == 0) {
FreeCharsetToCPMap();
}
}
nsresult
WinUConvAdapter::Init(const char* from, const char* to)
{
UINT fromCP = CharsetToCodePage(from);
UINT toCP = CharsetToCodePage(to);
printf("WinUConvAdapter::Init(%s -> %d, %s -> %d)\n",
from, fromCP,
to, toCP);
return NS_OK;
}
NS_IMETHODIMP
WinUConvAdapter::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
WinUConvAdapter::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
WinUConvAdapter::Reset()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// Encoder methods:
NS_IMETHODIMP
WinUConvAdapter::Convert(const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
WinUConvAdapter::Finish(char * aDest, PRInt32 * aDestLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
WinUConvAdapter::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// defined by the Decoder: NS_IMETHOD Reset();
NS_IMETHODIMP
WinUConvAdapter::SetOutputErrorBehavior(PRInt32 aBehavior,
nsIUnicharEncoder * aEncoder,
PRUnichar aChar)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
WinUConvAdapter::FillInfo(PRUint32* aInfo)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// NativeUConvService
NS_IMPL_ISUPPORTS1(NativeUConvService,
nsINativeUConvService);
NS_IMETHODIMP
NativeUConvService::GetNativeConverter(const char* from,
const char* to,
nsISupports** aResult)
{
*aResult = nsnull;
WinUConvAdapter* ucl = new WinUConvAdapter();
if (!ucl)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = ucl->Init(from, to);
if (NS_SUCCEEDED(rv)) {
NS_ADDREF(*aResult = (nsISupports*)(nsIUnicharEncoder*)ucl);
}
return rv;
}

Просмотреть файл

@ -77,7 +77,7 @@ CPPSRCS = \
nsConverterInputStream.cpp \
nsConverterOutputStream.cpp \
nsTextToSubURI.cpp \
nsURLProperties.cpp \
nsGREResProperties.cpp \
nsCharsetConverterManager.cpp \
nsUTF8ConverterService.cpp \
nsUTF8ToUnicode.cpp \

Просмотреть файл

@ -38,7 +38,7 @@
#define nsCharsetAlias_h__
#include "nsICharsetAlias.h"
#include "nsURLProperties.h"
#include "nsGREResProperties.h"
//==============================================================
class nsCharsetAlias2 : public nsICharsetAlias
@ -55,7 +55,7 @@ public:
NS_IMETHOD Equals(const nsACString& aCharset1, const nsACString& aCharset2, PRBool* oResult) ;
private:
nsURLProperties* mDelegate;
nsGREResProperties* mDelegate;
};
#endif // nsCharsetAlias_h__

Просмотреть файл

@ -45,7 +45,7 @@
#include "nsUConvDll.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsURLProperties.h"
#include "nsGREResProperties.h"
#include "nsITimelineService.h"
#include "nsCharsetAlias.h"
@ -99,9 +99,9 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsACString& aAlias,
if(!mDelegate) {
//load charsetalias.properties string bundle with all remaining aliases
// we may need to protect the following section with a lock so we won't call the
// 'new nsURLProperties' from two different threads
mDelegate = new nsURLProperties( NS_LITERAL_CSTRING("resource://gre/res/charsetalias.properties") );
NS_ASSERTION(mDelegate, "cannot create nsURLProperties");
// 'new nsGREResProperties' from two different threads
mDelegate = new nsGREResProperties( NS_LITERAL_CSTRING("charsetalias.properties") );
NS_ASSERTION(mDelegate, "cannot create nsGREResProperties");
if(nsnull == mDelegate)
return NS_ERROR_OUT_OF_MEMORY;
}
@ -109,7 +109,7 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsACString& aAlias,
NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred");
NS_TIMELINE_MARK_TIMER("nsCharsetAlias2:GetPreferred");
// hack for now, have to fix nsURLProperties, but we can't until
// hack for now, have to fix nsGREResProperties, but we can't until
// string bundles use UTF8 keys
nsAutoString result;
nsresult rv = mDelegate->Get(NS_ConvertASCIItoUCS2(aKey), result);

Просмотреть файл

@ -0,0 +1,81 @@
/* vim: set sts=2 sw=2 et cin: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is gre/res property file loading code.
*
* The Initial Developer of the Original Code is
* Christian Biesinger <cbiesinger@web.de>.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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.
*
* ***** END LICENSE BLOCK ***** */
#include "nsGREResProperties.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsILocalFile.h"
#include "nsNetUtil.h"
nsGREResProperties::nsGREResProperties(const nsACString& aFile)
{
nsCOMPtr<nsIFile> file;
nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
if (NS_FAILED(rv))
return;
file->AppendNative(NS_LITERAL_CSTRING("res"));
file->AppendNative(aFile);
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(file));
NS_ENSURE_TRUE(lf, /**/);
nsCOMPtr<nsIInputStream> inStr;
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), lf);
if (NS_FAILED(rv))
return;
mProps = do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
if (mProps) {
rv = mProps->Load(inStr);
if (NS_FAILED(rv))
mProps = nsnull;
}
}
PRBool nsGREResProperties::DidLoad() const
{
return mProps != nsnull;
}
nsresult nsGREResProperties::Get(const nsAString& aKey, nsAString& aValue)
{
if (!mProps)
return NS_ERROR_NOT_INITIALIZED;
return mProps->GetStringProperty(NS_ConvertUTF16toUTF8(aKey), aValue);
}

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sts=2 sw=2 et cin: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -12,18 +12,18 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is gre/res property file loading code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* Christian Biesinger <cbiesinger@web.de>.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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"),
* 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
@ -35,28 +35,32 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsURLProperties_h__
#define nsURLProperties_h__
#ifndef nsGREResProperties_h__
#define nsGREResProperties_h__
#include "nsIStringBundle.h"
#include "nsString.h"
#include "nsIPersistentProperties2.h"
#include "nsCOMPtr.h"
#include "nsAString.h"
class nsURLProperties {
/**
* This class loads a .properties file from the gre/res directory; the file
* to load is specified as a constructor argument.
*/
class nsGREResProperties {
public:
nsURLProperties(const nsACString& aUrl);
virtual ~nsURLProperties();
/**
* @param aFile The file to load. Must be an ASCII string.
*/
nsGREResProperties(const nsACString& aFile);
NS_IMETHOD DidLoad(PRBool&);
NS_IMETHOD Get( const nsAString& aKey, nsAString& value);
/**
* Returns whether loading the file succeeded.
*/
PRBool DidLoad() const;
nsresult Get(const nsAString& aKey, nsAString& value);
private:
static nsIStringBundleService* gStringBundleService; // to speed up getting bundles
static nsrefcnt gRefCnt;
nsCOMPtr<nsIStringBundle> mBundle;
nsCOMPtr<nsIPersistentProperties> mProps;
};
#endif /* nsURLProperties_h__ */
#endif // nsGREResProperties_h__

Просмотреть файл

@ -39,7 +39,7 @@
#include <TextCommon.h>
#include "nsIPlatformCharset.h"
#include "pratom.h"
#include "nsURLProperties.h"
#include "nsGREResProperties.h"
#include "nsUConvDll.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
@ -49,7 +49,7 @@
#include "nsPlatformCharset.h"
#include "nsEncoderDecoderUtils.h"
static nsURLProperties *gInfo = nsnull;
static nsGREResProperties *gInfo = nsnull;
static PRInt32 gCnt = 0;
NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
@ -71,7 +71,8 @@ nsresult nsPlatformCharset::InitInfo()
{
// load the .property file if necessary
if (gInfo == nsnull) {
nsURLProperties *info = new nsURLProperties( NS_LITERAL_CSTRING("resource://gre/res/maccharset.properties") );
nsGREResProperties *info =
new nsGREResProperties(NS_LITERAL_CSTRING("maccharset.properties"));
NS_ASSERTION(info , "cannot open properties file");
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
gInfo = info;

Просмотреть файл

@ -39,7 +39,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsIPlatformCharset.h"
#include "nsURLProperties.h"
#include "nsGREResProperties.h"
#include "pratom.h"
#define INCL_WIN
#include <os2.h>
@ -52,7 +52,7 @@
#include "nsITimelineService.h"
#include "nsPlatformCharset.h"
static nsURLProperties *gInfo = nsnull;
static nsGREResProperties *gInfo = nsnull;
static PRInt32 gCnt= 0;
NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
@ -85,7 +85,8 @@ nsPlatformCharset::InitInfo()
PR_AtomicIncrement(&gCnt); // count for gInfo
if (gInfo == nsnull) {
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource://gre/res/os2charset.properties"));
nsGREResProperties *info =
new nsGREResProperties(NS_LITERAL_CSTRING("os2charset.properties"));
NS_ASSERTION(info , "cannot open properties file");
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);

Просмотреть файл

@ -38,7 +38,7 @@
#include <locale.h>
#include "nsIPlatformCharset.h"
#include "pratom.h"
#include "nsURLProperties.h"
#include "nsGREResProperties.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsLocaleCID.h"
@ -65,8 +65,8 @@
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
static nsURLProperties *gNLInfo = nsnull;
static nsURLProperties *gInfo_deprecated = nsnull;
static nsGREResProperties *gNLInfo = nsnull;
static nsGREResProperties *gInfo_deprecated = nsnull;
static PRInt32 gCnt=0;
//this lock is for protecting above static variable operation
@ -96,8 +96,9 @@ nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale
{
nsAutoLock guard(gLock);
if (!gInfo_deprecated) {
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource://gre/res/unixcharset.properties"));
NS_ASSERTION( info, "cannot create nsURLProperties");
nsGREResProperties *info =
new nsGREResProperties(NS_LITERAL_CSTRING("unixcharset.properties"));
NS_ASSERTION(info, "cannot create nsGREResProperties");
gInfo_deprecated = info;
}
}
@ -237,17 +238,15 @@ nsPlatformCharset::InitGetCharset(nsACString &oString)
nsAutoLock guard(gLock);
if (!gNLInfo) {
nsCAutoString propertyURL;
// note: NS_LITERAL_STRING("resource:/res/unixcharset." OSARCH ".properties") does not compile on AIX
propertyURL.AssignLiteral("resource://gre/res/unixcharset.");
propertyURL.Append(OSARCH);
propertyURL.AppendLiteral(".properties");
nsURLProperties *info;
info = new nsURLProperties( propertyURL );
NS_ASSERTION( info, "cannot create nsURLProperties");
nsCAutoString propertyFile;
// note: NS_LITERAL_CSTRING("unixcharset." OSARCH ".properties") does not compile on AIX
propertyFile.AssignLiteral("unixcharset.");
propertyFile.Append(OSARCH);
propertyFile.AppendLiteral(".properties");
nsGREResProperties *info = new nsGREResProperties(propertyFile);
NS_ASSERTION(info, "cannot create nsGREResProperties");
if (info) {
PRBool didLoad;
info->DidLoad(didLoad);
PRBool didLoad = info->DidLoad();
if (!didLoad) {
delete info;
info = nsnull;

Просмотреть файл

@ -1,91 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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
* for the specific language governing rights and limitations under the
* 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):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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.
*
* ***** END LICENSE BLOCK ***** */
#include "nsURLProperties.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsAString.h"
#include "nsPromiseFlatString.h"
#include "nsXPIDLString.h"
nsIStringBundleService* nsURLProperties::gStringBundleService = nsnull;
nsrefcnt nsURLProperties::gRefCnt = 0;
nsURLProperties::nsURLProperties(const nsACString& aUrl)
{
nsresult res = NS_OK;
if (gRefCnt == 0) {
res = CallGetService(NS_STRINGBUNDLE_CONTRACTID, &gStringBundleService);
if (NS_FAILED(res)) return;
gRefCnt++;
}
if (NS_SUCCEEDED(res)) {
gStringBundleService->CreateBundle(PromiseFlatCString(aUrl).get(), getter_AddRefs(mBundle));
}
}
nsURLProperties::~nsURLProperties()
{
if (--gRefCnt == 0) {
NS_RELEASE(gStringBundleService);
}
}
NS_IMETHODIMP nsURLProperties::Get(const nsAString& aKey,
nsAString& oValue)
{
if(mBundle) {
nsXPIDLString value;
nsresult rv;
rv = mBundle->GetStringFromName(PromiseFlatString(aKey).get(),
getter_Copies(value));
if (NS_SUCCEEDED(rv))
oValue = value;
return rv;
}
else
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsURLProperties::DidLoad(PRBool &oDidLoad)
{
oDidLoad = (mBundle!=nsnull);
return NS_OK;
}

Просмотреть файл

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsIPlatformCharset.h"
#include "nsURLProperties.h"
#include "nsGREResProperties.h"
#include "pratom.h"
#include <windows.h>
#include "nsUConvDll.h"
@ -48,7 +48,7 @@
#include "nsITimelineService.h"
#include "nsPlatformCharset.h"
static nsURLProperties *gInfo = nsnull;
static nsGREResProperties *gInfo = nsnull;
static PRInt32 gCnt= 0;
NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
@ -80,7 +80,7 @@ nsPlatformCharset::InitInfo()
PR_AtomicIncrement(&gCnt); // count for gInfo
if (gInfo == nsnull) {
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource://gre/res/wincharset.properties"));
nsGREResProperties *info = new nsGREResProperties(NS_LITERAL_CSTRING("wincharset.properties"));
NS_ASSERTION(info , "cannot open properties file");
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIIDNService.h"
#include "nsIPlatformCharset.h"
#include "nsNetUtil.h"
#include "prlog.h"
#include "nsAutoPtr.h"
@ -2454,7 +2455,14 @@ nsStandardURL::SetFile(nsIFile *file)
rv = net_GetURLSpecFromFile(file, url);
if (NS_FAILED(rv)) return rv;
rv = SetSpec(url);
// We should always set the charset until bug 278161 is fixed.
nsCOMPtr <nsIPlatformCharset> platformCharset =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
nsCAutoString charset;
if (platformCharset)
platformCharset->GetCharset(kPlatformCharsetSel_FileName, charset);
rv = Init(mURLType, mDefaultPort, url, charset.get(), nsnull);
// must clone |file| since its value is not guaranteed to remain constant
if (NS_SUCCEEDED(rv)) {

Просмотреть файл

@ -46,6 +46,7 @@
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIPlatformCharset.h"
#include "nsNetUtil.h"
@ -269,8 +270,15 @@ nsFileProtocolHandler::NewURI(const nsACString &spec,
specPtr = &buf;
#endif
// XXX perhaps we should convert |charset| to whatever the system charset
// is so that nsStandardURL will normalize our URL string properly?
nsCAutoString urlCharset;
// We should set file system charset until bug 278161 is fixed.
nsCOMPtr <nsIPlatformCharset> platformCharset =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
if (platformCharset) {
platformCharset->GetCharset(kPlatformCharsetSel_FileName, urlCharset);
if (!urlCharset.IsEmpty())
charset = urlCharset.get();
}
nsresult rv = url->Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
*specPtr, charset, baseURI);
@ -333,8 +341,8 @@ nsFileProtocolHandler::NewFileURI(nsIFile *file, nsIURI **result)
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
// XXX shouldn't we set nsIURI::originCharset ??
// NOTE: the origin charset is assigned the value of the platform
// charset by the SetFile method.
rv = url->SetFile(file);
if (NS_FAILED(rv)) return rv;