Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/netwerk/dns/nsEffectiveTLDService.cpp b/netwerk/dns/nsEffectiveTLDService.cpp
- --- a/netwerk/dns/nsEffectiveTLDService.cpp
- +++ b/netwerk/dns/nsEffectiveTLDService.cpp
- @@ -9,18 +9,23 @@
- // http://wiki.mozilla.org/Gecko:Effective_TLD_Service
- #include "mozilla/ArrayUtils.h"
- +#include "mozilla/AutoMemMap.h"
- #include "mozilla/HashFunctions.h"
- #include "mozilla/Maybe.h"
- #include "mozilla/MemoryReporting.h"
- +#include "mozilla/ResultExtensions.h"
- #include "MainThreadUtils.h"
- +#include "nsCRT.h"
- #include "nsEffectiveTLDService.h"
- +#include "nsIFile.h"
- #include "nsIIDNService.h"
- -#include "nsNetUtil.h"
- -#include "prnetdb.h"
- +#include "nsIObserverService.h"
- #include "nsIURI.h"
- #include "nsNetCID.h"
- +#include "nsNetUtil.h"
- #include "nsServiceManagerUtils.h"
- +#include "prnetdb.h"
- namespace etld_dafsa {
- @@ -32,7 +37,7 @@ namespace etld_dafsa {
- using namespace mozilla;
- NS_IMPL_ISUPPORTS(nsEffectiveTLDService, nsIEffectiveTLDService,
- - nsIMemoryReporter)
- + nsIMemoryReporter, nsIObserver)
- // ----------------------------------------------------------------------
- @@ -42,6 +47,9 @@ nsEffectiveTLDService::nsEffectiveTLDSer
- : mIDNService(), mGraph(etld_dafsa::kDafsa) {}
- nsresult nsEffectiveTLDService::Init() {
- + nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
- + obs->AddObserver(this, "public-suffix-list-updated", false);
- +
- if (gService) {
- return NS_ERROR_ALREADY_INITIALIZED;
- }
- @@ -56,6 +64,30 @@ nsresult nsEffectiveTLDService::Init() {
- return NS_OK;
- }
- +NS_IMETHODIMP nsEffectiveTLDService::Observe(nsISupports* aSubject,
- + const char* aTopic,
- + const char16_t* aData) {
- + /*
- + * Signal sent from netwerk/dns/PublicSuffixList.jsm
- + * aSubject is the nsIFile object for dafsa.bin
- + * aData is the absolute path to the dafsa.bin file (not used)
- + */
- + if (aSubject && (nsCRT::strcmp(aTopic, "public-suffix-list-updated") == 0)) {
- + nsCOMPtr<nsIFile> mDafsaBinFile(do_QueryInterface(aSubject));
- + NS_ENSURE_TRUE(mDafsaBinFile, NS_ERROR_ILLEGAL_VALUE);
- +
- + loader::AutoMemMap mMap;
- + MOZ_TRY(mMap.init(mDafsaBinFile));
- +
- + uint32_t size = mMap.size();
- + const unsigned char* remoteDafsaPtr = mMap.get<unsigned char>().get();
- +
- + nsEffectiveTLDService::mGraph =
- + mozilla::Dafsa(MakeSpan(remoteDafsaPtr, size));
- + }
- + return NS_OK;
- +}
- +
- nsEffectiveTLDService::~nsEffectiveTLDService() {
- UnregisterWeakMemoryReporter(this);
- if (mIDNService) {
- diff --git a/netwerk/dns/nsEffectiveTLDService.h b/netwerk/dns/nsEffectiveTLDService.h
- --- a/netwerk/dns/nsEffectiveTLDService.h
- +++ b/netwerk/dns/nsEffectiveTLDService.h
- @@ -8,23 +8,27 @@
- #include "nsIEffectiveTLDService.h"
- -#include "nsHashKeys.h"
- -#include "nsIMemoryReporter.h"
- -#include "nsString.h"
- -#include "nsCOMPtr.h"
- #include "mozilla/Attributes.h"
- #include "mozilla/Dafsa.h"
- #include "mozilla/MemoryReporting.h"
- #include "mozilla/MruCache.h"
- +#include "nsCOMPtr.h"
- +#include "nsHashKeys.h"
- +#include "nsIMemoryReporter.h"
- +#include "nsIObserver.h"
- +#include "nsString.h"
- +
- class nsIIDNService;
- class nsEffectiveTLDService final : public nsIEffectiveTLDService,
- + public nsIObserver,
- public nsIMemoryReporter {
- public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIEFFECTIVETLDSERVICE
- NS_DECL_NSIMEMORYREPORTER
- + NS_DECL_NSIOBSERVER
- nsEffectiveTLDService();
- nsresult Init();
- diff --git a/netwerk/dns/tests/unit/data/fake_public_suffix_list.dat b/netwerk/dns/tests/unit/data/fake_public_suffix_list.dat
- new file mode 100644
- --- /dev/null
- +++ b/netwerk/dns/tests/unit/data/fake_public_suffix_list.dat
- @@ -0,0 +1,56 @@
- +// 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 https://mozilla.org/MPL/2.0/.
- +
- +// This is a fake suffix list created only for the purposes of testing,
- +// The real PSL is rather large thus this file is kept small by cutting out most of the suffixes
- +
- +// The Original list can be found at https://publicsuffix.org/list/public_suffix_list.dat,
- +// Learn more about the PSL at https://publicsuffix.org.
- +
- +// .xpcshelltest is the fake domain created specifically for the the tests while
- +// the others are ripped from the real list, serving as examples.
- +
- +// This fake public suffix list was used to create the binary file dafsa_xpcShellTest.bin
- +// found at netwerk/dns/tests/unit/data/ along with this file.
- +
- +// The list created with help of netwerk/dns/prepare_tlds.py and xpcom/ds/tools/make_dafsa.py
- +// To rebuild the DAFSA, simply pull the two python scripts and run
- +// $ python3 prepare_tlds.py fake_public_suffix_list.dat --bin > dafsa_xpcShellTest.bin
- +
- +
- +// ===BEGIN ICANN DOMAINS===
- +
- +// xpcshelltest : Used in tests
- +xpcshelltest
- +website.xpcshelltest
- +com.xpcshelltest
- +edu.xpcshelltest
- +gov.xpcshelltest
- +net.xpcshelltest
- +mil.xpcshelltest
- +org.xpcshelltest
- +
- +// ac : https://en.wikipedia.org/wiki/.ac
- +ac
- +coc.ac
- +com.ac
- +edu.ac
- +gov.ac
- +net.ac
- +mil.ac
- +org.ac
- +
- +// bj : https://en.wikipedia.org/wiki/.bj
- +bj
- +asso.bj
- +barreau.bj
- +gouv.bj
- +
- +// bm : http://www.bermudanic.bm/dnr-text.txt
- +bm
- +com.bm
- +edu.bm
- +gov.bm
- +net.bm
- +org.bm
- diff --git a/netwerk/dns/tests/unit/test_nsEffectiveTLDService_Reload_DAFSA.js b/netwerk/dns/tests/unit/test_nsEffectiveTLDService_Reload_DAFSA.js
- new file mode 100644
- --- /dev/null
- +++ b/netwerk/dns/tests/unit/test_nsEffectiveTLDService_Reload_DAFSA.js
- @@ -0,0 +1,32 @@
- +"use strict";
- +
- +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
- +const eTLDService = Services.eTLD;
- +
- +const SIGNAL = "public-suffix-list-updated";
- +
- +add_task(async () => {
- + info("Fake Suffix does not exist in current PSL.");
- +
- + let suffix = eTLDService.getPublicSuffixFromHost("website.xpcshelltest");
- + Assert.notEqual(
- + suffix, // suffix is actually "xpcshelltest"
- + "website.xpcshelltest",
- + "Fake Suffix does not exist in current PSL."
- + );
- +});
- +
- +add_task(async () => {
- + info("Fake Suffix now exists in PSL after DAFSA reload.");
- +
- + // reload the PSL with fake data containing .xpcshelltest
- + const fakeDafsaFile = do_get_file("data/dafsa_xpcShellTest.bin");
- + Services.obs.notifyObservers(fakeDafsaFile, SIGNAL, fakeDafsaFile.path);
- +
- + let suffix = eTLDService.getPublicSuffixFromHost("website.xpcshelltest");
- + Assert.equal(
- + suffix,
- + "website.xpcshelltest",
- + "Fake Suffix now exists in PSL after DAFSA reload."
- + );
- +});
- diff --git a/netwerk/dns/tests/unit/xpcshell.ini b/netwerk/dns/tests/unit/xpcshell.ini
- --- a/netwerk/dns/tests/unit/xpcshell.ini
- +++ b/netwerk/dns/tests/unit/xpcshell.ini
- @@ -4,3 +4,4 @@ firefox-appdir = browser
- support-files = data/**
- [test_PublicSuffixList.js]
- +[test_nsEffectiveTLDService_Reload_DAFSA.js]
- diff --git a/xpcom/ds/Dafsa.h b/xpcom/ds/Dafsa.h
- --- a/xpcom/ds/Dafsa.h
- +++ b/xpcom/ds/Dafsa.h
- @@ -33,6 +33,11 @@ class Dafsa {
- */
- explicit Dafsa(const Graph& aData) : mData(aData) {}
- + Dafsa& operator=(Dafsa other) {
- + mData = Graph(other.mData);
- + return *this;
- + }
- +
- ~Dafsa() = default;
- /**
- @@ -46,7 +51,7 @@ class Dafsa {
- static const int kKeyNotFound;
- private:
- - const Graph mData;
- + Graph mData;
- };
- } // namespace mozilla
Add Comment
Please, Sign In to add comment