1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NetworkInformation_h
6 #define NetworkInformation_h
8 #include "core/dom/ActiveDOMObject.h"
9 #include "core/events/EventTarget.h"
10 #include "core/page/NetworkStateNotifier.h"
11 #include "public/platform/WebConnectionType.h"
15 class ExecutionContext;
17 class NetworkInformation final
18 : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<NetworkInformation>
19 , public ActiveDOMObject
20 , public EventTargetWithInlineData
21 , public NetworkStateNotifier::NetworkStateObserver {
22 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<NetworkInformation>);
23 DEFINE_WRAPPERTYPEINFO();
24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation);
26 static NetworkInformation* create(ExecutionContext*);
27 virtual ~NetworkInformation();
31 virtual void connectionTypeChange(WebConnectionType) override;
33 // EventTarget overrides.
34 virtual const AtomicString& interfaceName() const override;
35 virtual ExecutionContext* executionContext() const override;
36 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture = false) override;
37 virtual bool removeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture = false) override;
38 virtual void removeAllEventListeners() override;
40 // ActiveDOMObject overrides.
41 virtual bool hasPendingActivity() const override;
42 virtual void stop() override;
44 DEFINE_ATTRIBUTE_EVENT_LISTENER(typechange);
47 explicit NetworkInformation(ExecutionContext*);
48 void startObserving();
51 // Touched only on context thread.
52 WebConnectionType m_type;
54 // Whether this object is listening for events from NetworkStateNotifier.
57 // Whether ActiveDOMObject::stop has been called.
58 bool m_contextStopped;
63 #endif // NetworkInformation_h