1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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/. */
8 #include "mozilla/Hal.h"
9 #include "ConnectionMainThread.h"
11 namespace mozilla::dom::network
{
13 ConnectionMainThread::ConnectionMainThread(nsPIDOMWindowInner
* aWindow
,
14 bool aShouldResistFingerprinting
)
15 : Connection(aWindow
, aShouldResistFingerprinting
) {
16 hal::RegisterNetworkObserver(this);
18 hal::NetworkInformation networkInfo
;
19 hal::GetCurrentNetworkInformation(&networkInfo
);
21 UpdateFromNetworkInfo(networkInfo
, false);
24 ConnectionMainThread::~ConnectionMainThread() { Shutdown(); }
26 void ConnectionMainThread::ShutdownInternal() {
27 hal::UnregisterNetworkObserver(this);
30 void ConnectionMainThread::UpdateFromNetworkInfo(
31 const hal::NetworkInformation
& aNetworkInfo
, bool aNotify
) {
32 Update(static_cast<ConnectionType
>(aNetworkInfo
.type()),
33 aNetworkInfo
.isWifi(), aNetworkInfo
.dhcpGateway(), aNotify
);
36 void ConnectionMainThread::Notify(const hal::NetworkInformation
& aNetworkInfo
) {
37 UpdateFromNetworkInfo(aNetworkInfo
, true);
40 } // namespace mozilla::dom::network