| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NetworkInformation_h | 5 #ifndef NetworkInformation_h |
| 6 #define NetworkInformation_h | 6 #define NetworkInformation_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ActiveScriptWrappable.h" | 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 9 #include "core/dom/ActiveDOMObject.h" | 9 #include "core/dom/ActiveDOMObject.h" |
| 10 #include "core/events/EventTarget.h" | 10 #include "core/events/EventTarget.h" |
| 11 #include "core/page/NetworkStateNotifier.h" | 11 #include "core/page/NetworkStateNotifier.h" |
| 12 #include "public/platform/WebConnectionType.h" | 12 #include "public/platform/WebConnectionType.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class ExecutionContext; | 16 class ExecutionContext; |
| 17 | 17 |
| 18 class NetworkInformation final | 18 class NetworkInformation final |
| 19 : public RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformat
ion> | 19 : public RefCountedGarbageCollectedEventTargetWithInlineData<NetworkInformat
ion> |
| 20 , public ActiveScriptWrappable | 20 , public ActiveScriptWrappable |
| 21 , public ActiveDOMObject | 21 , public ActiveDOMObject |
| 22 , public NetworkStateNotifier::NetworkStateObserver { | 22 , public NetworkStateNotifier::NetworkStateObserver { |
| 23 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(NetworkInformation); | 23 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(NetworkInformation); |
| 24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); | 24 USING_GARBAGE_COLLECTED_MIXIN(NetworkInformation); |
| 25 DEFINE_WRAPPERTYPEINFO(); | 25 DEFINE_WRAPPERTYPEINFO(); |
| 26 public: | 26 public: |
| 27 static NetworkInformation* create(ExecutionContext*); | 27 static NetworkInformation* create(ExecutionContext*); |
| 28 ~NetworkInformation() override; | 28 ~NetworkInformation() override; |
| 29 | 29 |
| 30 String type() const; | 30 String type() const; |
| 31 double downlinkMax() const; | 31 double downlinkMax() const; |
| 32 | 32 |
| 33 // NetworkStateObserver overrides. | 33 // NetworkStateObserver overrides. |
| 34 void connectionChange(WebConnectionType, double downlinkMaxMbps) override; | 34 void connectionChange(WebConnectionType, double downlinkMaxMbps) override; |
| 35 | 35 |
| 36 // EventTarget overrides. | 36 // EventTarget overrides. |
| 37 const AtomicString& interfaceName() const override; | 37 const AtomicString& interfaceName() const override; |
| 38 ExecutionContext* getExecutionContext() const override; | 38 ExecutionContext* getExecutionContext() const override; |
| 39 void removeAllEventListeners() override; | 39 void removeAllEventListeners() override; |
| 40 | 40 |
| 41 // ActiveScriptWrappable | 41 // ActiveScriptWrappable |
| 42 bool hasPendingActivity() const final; | 42 bool hasPendingActivity() const final; |
| 43 | 43 |
| 44 // ActiveDOMObject overrides. | 44 // ActiveDOMObject overrides. |
| 45 void stop() override; | 45 void stop() override; |
| 46 | 46 |
| 47 DECLARE_VIRTUAL_TRACE(); | 47 DECLARE_VIRTUAL_TRACE(); |
| 48 | 48 |
| 49 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); | 49 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); |
| 50 DEFINE_ATTRIBUTE_EVENT_LISTENER(typechange); // Deprecated | 50 DEFINE_ATTRIBUTE_EVENT_LISTENER(typechange); // Deprecated |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 // EventTarget overrides. | 53 // EventTarget overrides. |
| 54 bool addEventListenerInternal(const AtomicString& eventType, PassRefPtrWillB
eRawPtr<EventListener>, const EventListenerOptions&) override; | 54 bool addEventListenerInternal(const AtomicString& eventType, RawPtr<EventLis
tener>, const EventListenerOptions&) override; |
| 55 bool removeEventListenerInternal(const AtomicString& eventType, PassRefPtrWi
llBeRawPtr<EventListener>, const EventListenerOptions&) override; | 55 bool removeEventListenerInternal(const AtomicString& eventType, RawPtr<Event
Listener>, const EventListenerOptions&) override; |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 explicit NetworkInformation(ExecutionContext*); | 58 explicit NetworkInformation(ExecutionContext*); |
| 59 void startObserving(); | 59 void startObserving(); |
| 60 void stopObserving(); | 60 void stopObserving(); |
| 61 | 61 |
| 62 // Touched only on context thread. | 62 // Touched only on context thread. |
| 63 WebConnectionType m_type; | 63 WebConnectionType m_type; |
| 64 | 64 |
| 65 // Touched only on context thread. | 65 // Touched only on context thread. |
| 66 double m_downlinkMaxMbps; | 66 double m_downlinkMaxMbps; |
| 67 | 67 |
| 68 // Whether this object is listening for events from NetworkStateNotifier. | 68 // Whether this object is listening for events from NetworkStateNotifier. |
| 69 bool m_observing; | 69 bool m_observing; |
| 70 | 70 |
| 71 // Whether ActiveDOMObject::stop has been called. | 71 // Whether ActiveDOMObject::stop has been called. |
| 72 bool m_contextStopped; | 72 bool m_contextStopped; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace blink | 75 } // namespace blink |
| 76 | 76 |
| 77 #endif // NetworkInformation_h | 77 #endif // NetworkInformation_h |
| OLD | NEW |