1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "mozilla/net/TRRServiceChild.h"
8 #include "mozilla/ClearOnShutdown.h"
9 #include "mozilla/DataStorage.h"
10 #include "mozilla/StaticPtr.h"
11 #include "nsIDNService.h"
12 #include "nsIObserverService.h"
13 #include "TRRService.h"
14
15 namespace mozilla {
16 namespace net {
17
18 static StaticRefPtr<nsIDNSService> sDNSService;
19
Init(const bool & aCaptiveIsPassed,const bool & aParentalControlEnabled,nsTArray<nsCString> && aDNSSuffixList)20 void TRRServiceChild::Init(const bool& aCaptiveIsPassed,
21 const bool& aParentalControlEnabled,
22 nsTArray<nsCString>&& aDNSSuffixList) {
23 nsCOMPtr<nsIDNSService> dns =
24 do_GetService("@mozilla.org/network/dns-service;1");
25 sDNSService = dns;
26 ClearOnShutdown(&sDNSService);
27 MOZ_ASSERT(sDNSService);
28 MOZ_ASSERT(gTRRService);
29
30 gTRRService->mCaptiveIsPassed = aCaptiveIsPassed;
31 gTRRService->mParentalControlEnabled = aParentalControlEnabled;
32 gTRRService->RebuildSuffixList(std::move(aDNSSuffixList));
33 }
34
RecvNotifyObserver(const nsCString & aTopic,const nsString & aData)35 mozilla::ipc::IPCResult TRRServiceChild::RecvNotifyObserver(
36 const nsCString& aTopic, const nsString& aData) {
37 nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
38 if (obs) {
39 obs->NotifyObservers(nullptr, aTopic.get(), aData.get());
40 }
41 return IPC_OK();
42 }
43
RecvUpdatePlatformDNSInformation(nsTArray<nsCString> && aDNSSuffixList,const bool & aPlatformDisabledTRR)44 mozilla::ipc::IPCResult TRRServiceChild::RecvUpdatePlatformDNSInformation(
45 nsTArray<nsCString>&& aDNSSuffixList, const bool& aPlatformDisabledTRR) {
46 gTRRService->RebuildSuffixList(std::move(aDNSSuffixList));
47 gTRRService->mPlatformDisabledTRR = aPlatformDisabledTRR;
48 return IPC_OK();
49 }
50
RecvInitTRRBLStorage(const psm::DataStorageEntry & aEntry,const FileDescriptor & aWriteFd)51 mozilla::ipc::IPCResult TRRServiceChild::RecvInitTRRBLStorage(
52 const psm::DataStorageEntry& aEntry, const FileDescriptor& aWriteFd) {
53 RefPtr<DataStorage> storage =
54 DataStorage::Get(DataStorageClass::TRRBlacklist);
55 if (storage) {
56 storage->Init(&aEntry.items(), aWriteFd);
57 }
58 return IPC_OK();
59 }
60
RecvUpdateParentalControlEnabled(const bool & aEnabled)61 mozilla::ipc::IPCResult TRRServiceChild::RecvUpdateParentalControlEnabled(
62 const bool& aEnabled) {
63 gTRRService->mParentalControlEnabled = aEnabled;
64 return IPC_OK();
65 }
66
RecvClearDNSCache(const bool & aTrrToo)67 mozilla::ipc::IPCResult TRRServiceChild::RecvClearDNSCache(
68 const bool& aTrrToo) {
69 Unused << sDNSService->ClearCache(aTrrToo);
70 return IPC_OK();
71 }
72
RecvSetDetectedTrrURI(const nsCString & aURI)73 mozilla::ipc::IPCResult TRRServiceChild::RecvSetDetectedTrrURI(
74 const nsCString& aURI) {
75 gTRRService->SetDetectedTrrURI(aURI);
76 return IPC_OK();
77 }
78
79 } // namespace net
80 } // namespace mozilla
81