From: uazo Date: Thu, 14 Jul 2022 09:48:45 +0000 Subject: Remove navigator.connection info Change the result of navigator.connection to default values and disable observers Original License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html --- .../modules/netinfo/network_information.cc | 6 +++++- .../platform/network/network_state_notifier.cc | 15 +++++++++++++++ .../platform/network/network_state_notifier.h | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/third_party/blink/renderer/modules/netinfo/network_information.cc b/third_party/blink/renderer/modules/netinfo/network_information.cc --- a/third_party/blink/renderer/modules/netinfo/network_information.cc +++ b/third_party/blink/renderer/modules/netinfo/network_information.cc @@ -80,7 +80,7 @@ NetworkInformation::~NetworkInformation() { } bool NetworkInformation::IsObserving() const { - return !!connection_observer_handle_; + return false; } V8ConnectionType NetworkInformation::type() const { @@ -181,6 +181,7 @@ void NetworkInformation::ConnectionChange( const std::optional& transport_rtt, const std::optional& downlink_mbps, bool save_data) { + if ((true)) return; DCHECK(GetExecutionContext()->IsContextThread()); const String host = Host(); @@ -262,6 +263,7 @@ void NetworkInformation::RemoveAllEventListeners() { } bool NetworkInformation::HasPendingActivity() const { + if ((true)) return false; DCHECK(context_stopped_ || IsObserving() == HasEventListeners()); // Prevent collection of this object when there are active listeners. @@ -274,6 +276,7 @@ void NetworkInformation::ContextDestroyed() { } void NetworkInformation::StartObserving() { + if ((true)) return; if (!IsObserving() && !context_stopped_) { type_ = GetNetworkStateNotifier().ConnectionType(); DCHECK(!connection_observer_handle_); @@ -284,6 +287,7 @@ void NetworkInformation::StartObserving() { } void NetworkInformation::StopObserving() { + if ((true)) return; if (IsObserving()) { DCHECK(connection_observer_handle_); connection_observer_handle_ = nullptr; diff --git a/third_party/blink/renderer/platform/network/network_state_notifier.cc b/third_party/blink/renderer/platform/network/network_state_notifier.cc --- a/third_party/blink/renderer/platform/network/network_state_notifier.cc +++ b/third_party/blink/renderer/platform/network/network_state_notifier.cc @@ -105,6 +105,21 @@ NetworkStateNotifier::ScopedNotifier::~ScopedNotifier() { } } +NetworkStateNotifier::NetworkStateNotifier() : has_override_(false) { + // set default data + SetNetworkConnectionInfoOverride( + /* on_line */ true, + /* type */ WebConnectionType::kWebConnectionTypeWifi, + /* effective_type */ std::nullopt, + /* http_rtt_msec */ 50, + /* max_bandwidth_mbps */ std::numeric_limits::max()); + SetNetworkQuality( + /* effective_type */ WebEffectiveConnectionType::kType4G, + /* http_rtt */ base::Milliseconds(50), + /* transport_rtt */ base::TimeDelta(), + /* downlink_throughput_kbps */ 10000); +} + NetworkStateNotifier::NetworkStateObserverHandle::NetworkStateObserverHandle( NetworkStateNotifier* notifier, NetworkStateNotifier::ObserverType type, diff --git a/third_party/blink/renderer/platform/network/network_state_notifier.h b/third_party/blink/renderer/platform/network/network_state_notifier.h --- a/third_party/blink/renderer/platform/network/network_state_notifier.h +++ b/third_party/blink/renderer/platform/network/network_state_notifier.h @@ -121,7 +121,7 @@ class PLATFORM_EXPORT NetworkStateNotifier { scoped_refptr task_runner_; }; - NetworkStateNotifier() : has_override_(false) {} + NetworkStateNotifier(); NetworkStateNotifier(const NetworkStateNotifier&) = delete; NetworkStateNotifier& operator=(const NetworkStateNotifier&) = delete; --