Bug 788829 - Call SetSizeConstraints even if a popup is not open. r=enndeakin
[gecko.git] / netwerk / dns / nsEffectiveTLDService.h
blob477e50f208289a5f90829074e2f3f3de47fb183e
1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsIEffectiveTLDService.h"
8 #include "nsTHashtable.h"
9 #include "nsString.h"
10 #include "nsCOMPtr.h"
11 #include "mozilla/Attributes.h"
13 class nsIIDNService;
15 #define ETLD_ENTRY_N_INDEX_BITS 30
17 // struct for static data generated from effective_tld_names.dat
18 struct ETLDEntry {
19 uint32_t strtab_index : ETLD_ENTRY_N_INDEX_BITS;
20 uint32_t exception : 1;
21 uint32_t wild : 1;
25 // hash entry class
26 class nsDomainEntry : public PLDHashEntryHdr
28 friend class nsEffectiveTLDService;
29 public:
30 // Hash methods
31 typedef const char* KeyType;
32 typedef const char* KeyTypePointer;
34 nsDomainEntry(KeyTypePointer aEntry)
38 nsDomainEntry(const nsDomainEntry& toCopy)
40 // if we end up here, things will break. nsTHashtable shouldn't
41 // allow this, since we set ALLOW_MEMMOVE to true.
42 NS_NOTREACHED("nsDomainEntry copy constructor is forbidden!");
45 ~nsDomainEntry()
49 KeyType GetKey() const
51 return GetEffectiveTLDName(mData->strtab_index);
54 bool KeyEquals(KeyTypePointer aKey) const
56 return !strcmp(GetKey(), aKey);
59 static KeyTypePointer KeyToPointer(KeyType aKey)
61 return aKey;
64 static PLDHashNumber HashKey(KeyTypePointer aKey)
66 // PL_DHashStringKey doesn't use the table parameter, so we can safely
67 // pass nullptr
68 return PL_DHashStringKey(nullptr, aKey);
71 enum { ALLOW_MEMMOVE = true };
73 void SetData(const ETLDEntry* entry) { mData = entry; }
75 bool IsNormal() { return mData->wild || !mData->exception; }
76 bool IsException() { return mData->exception; }
77 bool IsWild() { return mData->wild; }
79 static const char *GetEffectiveTLDName(size_t idx)
81 return strings.strtab + idx;
84 private:
85 const ETLDEntry* mData;
86 #define ETLD_STR_NUM_1(line) str##line
87 #define ETLD_STR_NUM(line) ETLD_STR_NUM_1(line)
88 struct etld_string_list {
89 #define ETLD_ENTRY(name, ex, wild) char ETLD_STR_NUM(__LINE__)[sizeof(name)];
90 #include "etld_data.inc"
91 #undef ETLD_ENTRY
93 static const union etld_strings {
94 struct etld_string_list list;
95 char strtab[1];
96 } strings;
97 static const ETLDEntry entries[];
98 void FuncForStaticAsserts(void);
99 #undef ETLD_STR_NUM
100 #undef ETLD_STR_NUM1
103 class nsEffectiveTLDService MOZ_FINAL : public nsIEffectiveTLDService
105 public:
106 NS_DECL_ISUPPORTS
107 NS_DECL_NSIEFFECTIVETLDSERVICE
109 nsEffectiveTLDService() { }
110 nsresult Init();
112 private:
113 nsresult GetBaseDomainInternal(nsCString &aHostname, uint32_t aAdditionalParts, nsACString &aBaseDomain);
114 nsresult NormalizeHostname(nsCString &aHostname);
115 ~nsEffectiveTLDService() { }
117 nsTHashtable<nsDomainEntry> mHash;
118 nsCOMPtr<nsIIDNService> mIDNService;