Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_network_Connection_h
8 : #define mozilla_dom_network_Connection_h
9 :
10 : #include "mozilla/DOMEventTargetHelper.h"
11 : #include "mozilla/dom/NetworkInformationBinding.h"
12 : #include "nsContentUtils.h"
13 : #include "nsCycleCollectionParticipant.h"
14 : #include "nsINetworkProperties.h"
15 :
16 : namespace mozilla {
17 :
18 : namespace hal {
19 : class NetworkInformation;
20 : } // namespace hal
21 :
22 : namespace dom {
23 :
24 : namespace workers {
25 : class WorkerPrivate;
26 : } // namespace workers
27 :
28 : namespace network {
29 :
30 : class Connection : public DOMEventTargetHelper
31 : , public nsINetworkProperties
32 : {
33 : public:
34 : NS_DECL_ISUPPORTS_INHERITED
35 : NS_DECL_NSINETWORKPROPERTIES
36 : NS_DECL_OWNINGTHREAD
37 :
38 0 : NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
39 :
40 : static bool IsEnabled(JSContext* aCx, JSObject* aObj);
41 :
42 : static Connection*
43 : CreateForWindow(nsPIDOMWindowInner* aWindow);
44 :
45 : static already_AddRefed<Connection>
46 : CreateForWorker(workers::WorkerPrivate* aWorkerPrivate,
47 : ErrorResult& aRv);
48 :
49 : void Shutdown();
50 :
51 : // WebIDL
52 :
53 : virtual JSObject* WrapObject(JSContext* aCx,
54 : JS::Handle<JSObject*> aGivenProto) override;
55 :
56 0 : ConnectionType Type() const
57 : {
58 0 : return nsContentUtils::ShouldResistFingerprinting() ?
59 0 : static_cast<ConnectionType>(ConnectionType::Unknown) : mType;
60 : }
61 :
62 0 : IMPL_EVENT_HANDLER(typechange)
63 :
64 : protected:
65 : Connection(nsPIDOMWindowInner* aWindow);
66 : virtual ~Connection();
67 :
68 : void Update(ConnectionType aType, bool aIsWifi, uint32_t aDHCPGateway,
69 : bool aNotify);
70 :
71 : virtual void ShutdownInternal() = 0;
72 :
73 : private:
74 : /**
75 : * The type of current connection.
76 : */
77 : ConnectionType mType;
78 :
79 : /**
80 : * If the connection is WIFI
81 : */
82 : bool mIsWifi;
83 :
84 : /**
85 : * DHCP Gateway information for IPV4, in network byte order. 0 if unassigned.
86 : */
87 : uint32_t mDHCPGateway;
88 :
89 : bool mBeenShutDown;
90 : };
91 :
92 : } // namespace network
93 : } // namespace dom
94 : } // namespace mozilla
95 :
96 : #endif // mozilla_dom_network_Connection_h
|