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/. */
7 #include "mozilla/Hal.h"
8 #include "mozilla/dom/network/Connection.h"
9 #include "nsIDOMClassInfo.h"
10 #include "mozilla/Preferences.h"
11 #include "Constants.h"
14 * We have to use macros here because our leak analysis tool things we are
15 * leaking strings when we have |static const nsString|. Sad :(
17 #define CHANGE_EVENT_NAME NS_LITERAL_STRING("typechange")
23 NS_IMPL_QUERY_INTERFACE_INHERITED(Connection
, DOMEventTargetHelper
,
26 // Don't use |Connection| alone, since that confuses nsTraceRefcnt since
27 // we're not the only class with that name.
28 NS_IMPL_ADDREF_INHERITED(dom::network::Connection
, DOMEventTargetHelper
)
29 NS_IMPL_RELEASE_INHERITED(dom::network::Connection
, DOMEventTargetHelper
)
31 Connection::Connection()
32 : mType(static_cast<ConnectionType
>(kDefaultType
))
33 , mIsWifi(kDefaultIsWifi
)
34 , mDHCPGateway(kDefaultDHCPGateway
)
40 Connection::Init(nsPIDOMWindow
* aWindow
)
44 hal::RegisterNetworkObserver(this);
46 hal::NetworkInformation networkInfo
;
47 hal::GetCurrentNetworkInformation(&networkInfo
);
49 UpdateFromNetworkInfo(networkInfo
);
53 Connection::Shutdown()
55 hal::UnregisterNetworkObserver(this);
59 Connection::GetIsWifi(bool *aIsWifi
)
66 Connection::GetDhcpGateway(uint32_t *aGW
)
73 Connection::UpdateFromNetworkInfo(const hal::NetworkInformation
& aNetworkInfo
)
75 mType
= static_cast<ConnectionType
>(aNetworkInfo
.type());
76 mIsWifi
= aNetworkInfo
.isWifi();
77 mDHCPGateway
= aNetworkInfo
.dhcpGateway();
81 Connection::Notify(const hal::NetworkInformation
& aNetworkInfo
)
83 ConnectionType previousType
= mType
;
85 UpdateFromNetworkInfo(aNetworkInfo
);
87 if (previousType
== mType
) {
91 DispatchTrustedEvent(CHANGE_EVENT_NAME
);
95 Connection::WrapObject(JSContext
* aCx
)
97 return NetworkInformationBinding::Wrap(aCx
, this);
100 } // namespace network
102 } // namespace mozilla