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(nsPIDOMWindow
* aWindow
)
32 : DOMEventTargetHelper(aWindow
)
33 , mType(static_cast<ConnectionType
>(kDefaultType
))
34 , mIsWifi(kDefaultIsWifi
)
35 , mDHCPGateway(kDefaultDHCPGateway
)
37 hal::RegisterNetworkObserver(this);
39 hal::NetworkInformation networkInfo
;
40 hal::GetCurrentNetworkInformation(&networkInfo
);
42 UpdateFromNetworkInfo(networkInfo
);
46 Connection::Shutdown()
48 hal::UnregisterNetworkObserver(this);
52 Connection::GetIsWifi(bool *aIsWifi
)
59 Connection::GetDhcpGateway(uint32_t *aGW
)
66 Connection::UpdateFromNetworkInfo(const hal::NetworkInformation
& aNetworkInfo
)
68 mType
= static_cast<ConnectionType
>(aNetworkInfo
.type());
69 mIsWifi
= aNetworkInfo
.isWifi();
70 mDHCPGateway
= aNetworkInfo
.dhcpGateway();
74 Connection::Notify(const hal::NetworkInformation
& aNetworkInfo
)
76 ConnectionType previousType
= mType
;
78 UpdateFromNetworkInfo(aNetworkInfo
);
80 if (previousType
== mType
) {
84 DispatchTrustedEvent(CHANGE_EVENT_NAME
);
88 Connection::WrapObject(JSContext
* aCx
)
90 return NetworkInformationBinding::Wrap(aCx
, this);
93 } // namespace network
95 } // namespace mozilla