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 --- .../renderer/modules/netinfo/network_information.cc | 6 +++++- .../platform/network/network_state_notifier.cc | 11 +++++++++++ .../platform/network/network_state_notifier.h | 2 +- 3 files changed, 17 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 @@ -61,7 +61,7 @@ NetworkInformation::~NetworkInformation() { } bool NetworkInformation::IsObserving() const { - return !!connection_observer_handle_; + return false; } String NetworkInformation::type() const { @@ -155,6 +155,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(); @@ -236,6 +237,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. @@ -248,6 +250,7 @@ void NetworkInformation::ContextDestroyed() { } void NetworkInformation::StartObserving() { + if ((true)) return; if (!IsObserving() && !context_stopped_) { type_ = GetNetworkStateNotifier().ConnectionType(); DCHECK(!connection_observer_handle_); @@ -258,6 +261,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 @@ -102,6 +102,17 @@ NetworkStateNotifier::ScopedNotifier::~ScopedNotifier() { } } +NetworkStateNotifier::NetworkStateNotifier() : has_override_(false) { + // set default data + SetNetworkConnectionInfoOverride( + /*on_line*/ true, + /*type*/ WebConnectionType::kWebConnectionTypeWifi, + /*effective_type*/ absl::nullopt, + /*http_rtt_msec*/ 0, + /*max_bandwidth_mbps*/ std::numeric_limits::max()); + SetNetworkQuality(/*effective_type*/ WebEffectiveConnectionType::kType4G, base::TimeDelta(), base::TimeDelta(), 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 @@ -122,7 +122,7 @@ class PLATFORM_EXPORT NetworkStateNotifier { scoped_refptr task_runner_; }; - NetworkStateNotifier() : has_override_(false) {} + NetworkStateNotifier(); NetworkStateNotifier(const NetworkStateNotifier&) = delete; NetworkStateNotifier& operator=(const NetworkStateNotifier&) = delete; --