mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Initialize IDN service at nsStandardURL constructor,
added pref observers for IDN related prefs, bug 188218, r=darin, sr=alecf.
This commit is contained in:
parent
e73e8e38b4
commit
f2193fe99f
@ -347,6 +347,10 @@ nsStandardURL::InitGlobalObjects()
|
||||
nsCOMPtr<nsIObserver> obs( new nsPrefObserver() );
|
||||
pbi->AddObserver(NS_NET_PREF_ESCAPEUTF8, obs.get(), PR_FALSE);
|
||||
pbi->AddObserver(NS_NET_PREF_ENABLEIDN, obs.get(), PR_FALSE);
|
||||
// initialize IDN
|
||||
nsCOMPtr<nsIIDNService> serv(do_GetService(NS_IDNSERVICE_CONTRACTID));
|
||||
if (serv)
|
||||
NS_ADDREF(gIDNService = serv.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsResumableEntityID)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsIDNService.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIDNService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsIDNService, Init)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -44,6 +44,8 @@
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "punycode.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -52,13 +54,55 @@ static const PRUint32 kMaxDNSNodeLen = 63;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define NS_NET_PREF_IDNTESTBED "network.IDN_testbed"
|
||||
#define NS_NET_PREF_IDNPREFIX "network.IDN_prefix"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsIDNService
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/* Implementation file */
|
||||
NS_IMPL_ISUPPORTS1(nsIDNService, nsIIDNService)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsIDNService,
|
||||
nsIIDNService,
|
||||
nsIObserver,
|
||||
nsISupportsWeakReference);
|
||||
|
||||
nsresult nsIDNService::Init()
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefInternal) {
|
||||
prefInternal->AddObserver(NS_NET_PREF_IDNTESTBED, this, PR_TRUE);
|
||||
prefInternal->AddObserver(NS_NET_PREF_IDNPREFIX, this, PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIDNService::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch( do_QueryInterface(aSubject) );
|
||||
if (prefBranch) {
|
||||
// to support test environment which is a temporary testing environment
|
||||
// until IDN is actually deployed
|
||||
if (NS_LITERAL_STRING(NS_NET_PREF_IDNTESTBED).Equals(aData)) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNTESTBED, &val)))
|
||||
mMultilingualTestBed = val;
|
||||
}
|
||||
else if (NS_LITERAL_STRING(NS_NET_PREF_IDNPREFIX).Equals(aData)) {
|
||||
nsXPIDLCString prefix;
|
||||
if (NS_SUCCEEDED(prefBranch->GetCharPref(NS_NET_PREF_IDNPREFIX, getter_Copies(prefix))) &&
|
||||
prefix.Length() <= kACEPrefixLen)
|
||||
PL_strncpyz(nsIDNService::mACEPrefix, prefix.get(), kACEPrefixLen + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIDNService::nsIDNService()
|
||||
{
|
||||
@ -72,30 +116,6 @@ nsIDNService::nsIDNService()
|
||||
|
||||
mMultilingualTestBed = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
if (prefBranch) {
|
||||
|
||||
// to support test environment which is a temporary testing environment
|
||||
// until IDN is actually deployed
|
||||
PRBool value;
|
||||
rv = prefBranch->GetBoolPref("network.IDN_testbed", &value);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mMultilingualTestBed = value;
|
||||
|
||||
// read prefix from pref
|
||||
nsXPIDLCString prefix;
|
||||
rv = prefBranch->GetCharPref("network.IDN_prefix", getter_Copies(prefix));
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
prefix.Length() <= kACEPrefixLen) {
|
||||
strncpy(mACEPrefix, prefix.get(), kACEPrefixLen);
|
||||
mACEPrefix[sizeof(mACEPrefix)-1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (idn_success != idn_nameprep_create(NULL, &mNamePrepHandle))
|
||||
mNamePrepHandle = nsnull;
|
||||
|
||||
|
@ -41,6 +41,8 @@
|
||||
|
||||
#include "nsIIDNService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIUnicodeNormalizer.h"
|
||||
#include "nsIDNKitInterface.h"
|
||||
|
||||
@ -50,15 +52,20 @@
|
||||
|
||||
#define kACEPrefixLen 4
|
||||
|
||||
class nsIDNService : public nsIIDNService
|
||||
class nsIDNService : public nsIIDNService,
|
||||
public nsIObserver,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIDNSERVICE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsIDNService();
|
||||
virtual ~nsIDNService();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
private:
|
||||
void normalizeFullStops(nsAString& s);
|
||||
nsresult stringPrepAndACE(const nsAString& in, nsACString& out);
|
||||
|
Loading…
Reference in New Issue
Block a user