2009-03-29 11:49:31 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2002-09-26 03:49:08 +04:00
|
|
|
|
|
|
|
#ifndef nsIDNService_h__
|
|
|
|
#define nsIDNService_h__
|
|
|
|
|
|
|
|
#include "nsIIDNService.h"
|
2003-01-18 02:56:33 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2003-04-11 21:05:56 +04:00
|
|
|
#include "nsIObserver.h"
|
2016-04-21 20:58:59 +03:00
|
|
|
#include "nsUnicodeScriptCodes.h"
|
2003-04-11 21:05:56 +04:00
|
|
|
#include "nsWeakReference.h"
|
2015-10-28 17:05:15 +03:00
|
|
|
|
|
|
|
#ifdef IDNA2008
|
|
|
|
#include "unicode/uidna.h"
|
|
|
|
#else
|
2003-01-18 02:56:33 +03:00
|
|
|
#include "nsIUnicodeNormalizer.h"
|
|
|
|
#include "nsIDNKitInterface.h"
|
2015-10-28 17:05:15 +03:00
|
|
|
#endif
|
|
|
|
|
2005-07-22 19:07:33 +04:00
|
|
|
#include "nsString.h"
|
2002-09-26 03:49:08 +04:00
|
|
|
|
2005-02-17 23:02:37 +03:00
|
|
|
class nsIPrefBranch;
|
|
|
|
|
2002-09-26 03:49:08 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIDNService
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 21:35:18 +03:00
|
|
|
class nsIDNService final : public nsIIDNService,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsSupportsWeakReference
|
2002-09-26 03:49:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2002-09-26 03:49:08 +04:00
|
|
|
NS_DECL_NSIIDNSERVICE
|
2003-04-11 21:05:56 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2002-09-26 03:49:08 +04:00
|
|
|
|
|
|
|
nsIDNService();
|
2003-01-18 02:56:33 +03:00
|
|
|
|
2003-04-11 21:05:56 +04:00
|
|
|
nsresult Init();
|
|
|
|
|
2014-06-24 20:36:44 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsIDNService();
|
|
|
|
|
2003-01-18 02:56:33 +03:00
|
|
|
private:
|
2015-10-02 11:27:34 +03:00
|
|
|
enum stringPrepFlag {
|
|
|
|
eStringPrepForDNS,
|
|
|
|
eStringPrepForUI,
|
|
|
|
eStringPrepIgnoreErrors
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the following characters that must be recognized as label
|
|
|
|
* separators per RFC 3490 to ASCII full stop characters
|
|
|
|
*
|
|
|
|
* U+3002 (ideographic full stop)
|
|
|
|
* U+FF0E (fullwidth full stop)
|
|
|
|
* U+FF61 (halfwidth ideographic full stop)
|
|
|
|
*/
|
2003-01-18 02:56:33 +03:00
|
|
|
void normalizeFullStops(nsAString& s);
|
2015-10-02 11:27:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert and encode a DNS label in ACE/punycode.
|
|
|
|
* @param flag
|
|
|
|
* if eStringPrepIgnoreErrors, all non-ASCII labels are
|
|
|
|
* converted to punycode.
|
|
|
|
* if eStringPrepForUI, only labels that are considered safe
|
|
|
|
* for display are converted.
|
|
|
|
* @see isLabelSafe
|
|
|
|
* if eStringPrepForDNS and stringPrep finds an illegal
|
|
|
|
* character, returns NS_FAILURE and out is empty
|
|
|
|
*/
|
2009-03-29 11:49:31 +04:00
|
|
|
nsresult stringPrepAndACE(const nsAString& in, nsACString& out,
|
2015-10-02 11:27:34 +03:00
|
|
|
stringPrepFlag flag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a DNS label using the stringprep profile defined in RFC 3454
|
|
|
|
*/
|
|
|
|
nsresult stringPrep(const nsAString& in, nsAString& out, stringPrepFlag flag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode an ACE-encoded DNS label to UTF-8
|
|
|
|
*
|
|
|
|
* @param flag
|
|
|
|
* if eStringPrepForUI and the label is not considered safe to
|
|
|
|
* display, the output is the same as the input
|
|
|
|
* @see isLabelSafe
|
|
|
|
*/
|
2009-03-29 11:49:31 +04:00
|
|
|
nsresult decodeACE(const nsACString& in, nsACString& out,
|
2015-10-02 11:27:34 +03:00
|
|
|
stringPrepFlag flag);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert complete domain names between UTF8 and ACE and vice versa
|
|
|
|
*
|
|
|
|
* @param flag is passed to decodeACE or stringPrepAndACE for each
|
|
|
|
* label individually, so the output may contain some labels in
|
|
|
|
* punycode and some in UTF-8
|
|
|
|
*/
|
2013-03-01 15:56:44 +04:00
|
|
|
nsresult UTF8toACE(const nsACString& input, nsACString& ace,
|
2015-10-02 11:27:34 +03:00
|
|
|
stringPrepFlag flag);
|
2013-03-01 15:56:44 +04:00
|
|
|
nsresult ACEtoUTF8(const nsACString& input, nsACString& _retval,
|
2015-10-02 11:27:34 +03:00
|
|
|
stringPrepFlag flag);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isInWhitelist(const nsACString &host);
|
2014-01-04 19:02:17 +04:00
|
|
|
void prefsChanged(nsIPrefBranch *prefBranch, const char16_t *pref);
|
2015-10-02 11:27:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether a label is considered safe to display to the user
|
|
|
|
* according to the algorithm defined in UTR 39 and the profile
|
|
|
|
* selected in mRestrictionProfile.
|
|
|
|
*
|
|
|
|
* For the ASCII-only profile, returns false for all labels containing
|
|
|
|
* non-ASCII characters.
|
|
|
|
*
|
|
|
|
* For the other profiles, returns false for labels containing any of
|
|
|
|
* the following:
|
|
|
|
*
|
|
|
|
* Characters in scripts other than the "recommended scripts" and
|
|
|
|
* "aspirational scripts" defined in
|
|
|
|
* http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts
|
|
|
|
* and http://www.unicode.org/reports/tr31/#Aspirational_Use_Scripts
|
|
|
|
* This includes codepoints that are not defined as Unicode
|
|
|
|
* characters
|
|
|
|
*
|
|
|
|
* Illegal combinations of scripts (@see illegalScriptCombo)
|
|
|
|
*
|
|
|
|
* Numbers from more than one different numbering system
|
|
|
|
*
|
|
|
|
* Sequences of the same non-spacing mark
|
|
|
|
*
|
|
|
|
* Both simplified-only and traditional-only Chinese characters
|
|
|
|
* XXX this test was disabled by bug 857481
|
|
|
|
*/
|
2013-03-01 15:56:44 +04:00
|
|
|
bool isLabelSafe(const nsAString &label);
|
2015-10-02 11:27:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether a combination of scripts in a single label is
|
|
|
|
* permitted according to the algorithm defined in UTR 39 and the
|
|
|
|
* profile selected in mRestrictionProfile.
|
|
|
|
*
|
|
|
|
* For the "Highly restrictive" profile, all characters in each
|
|
|
|
* identifier must be from a single script, or from the combinations:
|
|
|
|
* Latin + Han + Hiragana + Katakana;
|
|
|
|
* Latin + Han + Bopomofo; or
|
|
|
|
* Latin + Han + Hangul
|
|
|
|
*
|
|
|
|
* For the "Moderately restrictive" profile, Latin is also allowed
|
|
|
|
* with other scripts except Cyrillic and Greek
|
|
|
|
*/
|
2016-04-21 20:58:59 +03:00
|
|
|
bool illegalScriptCombo(mozilla::unicode::Script script,
|
|
|
|
int32_t& savedScript);
|
2005-07-22 19:07:33 +04:00
|
|
|
|
2015-10-28 17:05:15 +03:00
|
|
|
#ifdef IDNA2008
|
|
|
|
/**
|
|
|
|
* Convert a DNS label from ASCII to Unicode using IDNA2008
|
|
|
|
*/
|
|
|
|
nsresult IDNA2008ToUnicode(const nsACString& input, nsAString& output);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a DNS label to a normalized form conforming to IDNA2008
|
|
|
|
*/
|
|
|
|
nsresult IDNA2008StringPrep(const nsAString& input, nsAString& output,
|
|
|
|
stringPrepFlag flag);
|
|
|
|
|
|
|
|
UIDNA* mIDNA;
|
|
|
|
#else
|
2003-01-18 02:56:33 +03:00
|
|
|
idn_nameprep_t mNamePrepHandle;
|
|
|
|
nsCOMPtr<nsIUnicodeNormalizer> mNormalizer;
|
2015-10-28 17:05:15 +03:00
|
|
|
#endif
|
2005-07-22 19:07:33 +04:00
|
|
|
nsXPIDLString mIDNBlacklist;
|
2015-10-02 11:27:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag set by the pref network.IDN_show_punycode. When it is true,
|
|
|
|
* IDNs containing non-ASCII characters are always displayed to the
|
|
|
|
* user in punycode
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mShowPunycode;
|
2015-10-02 11:27:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restriction-level Detection profiles defined in UTR 39
|
|
|
|
* http://www.unicode.org/reports/tr39/#Restriction_Level_Detection,
|
|
|
|
* and selected by the pref network.IDN.restriction_profile
|
|
|
|
*/
|
|
|
|
enum restrictionProfile {
|
2013-03-01 15:56:44 +04:00
|
|
|
eASCIIOnlyProfile,
|
|
|
|
eHighlyRestrictiveProfile,
|
|
|
|
eModeratelyRestrictiveProfile
|
|
|
|
};
|
|
|
|
restrictionProfile mRestrictionProfile;
|
2007-12-04 09:30:47 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch> mIDNWhitelistPrefBranch;
|
2013-03-01 15:56:44 +04:00
|
|
|
bool mIDNUseWhitelist;
|
2002-09-26 03:49:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsIDNService_h__
|