Commit 0ec13f96 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Make NetworkInformation a Supplement<NavigatorBase>

This removes the need for NavigatorNetworkInformation and
WorkerNavigatorNetworkInformation.

Bug: 1147612
Change-Id: I59f178cf746be7bf25c0246e6fc312f912b9ec47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533636
Commit-Queue: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827295}
parent 86678932
......@@ -6,11 +6,7 @@ import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("netinfo") {
sources = [
"navigator_network_information.cc",
"navigator_network_information.h",
"network_information.cc",
"network_information.h",
"worker_navigator_network_information.cc",
"worker_navigator_network_information.h",
]
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/netinfo/navigator_network_information.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/modules/netinfo/network_information.h"
namespace blink {
NavigatorNetworkInformation::NavigatorNetworkInformation(Navigator& navigator)
: ExecutionContextClient(navigator.DomWindow()) {}
NavigatorNetworkInformation& NavigatorNetworkInformation::From(
Navigator& navigator) {
NavigatorNetworkInformation* supplement =
ToNavigatorNetworkInformation(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NavigatorNetworkInformation>(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
NavigatorNetworkInformation*
NavigatorNetworkInformation::ToNavigatorNetworkInformation(
Navigator& navigator) {
return Supplement<Navigator>::From<NavigatorNetworkInformation>(navigator);
}
const char NavigatorNetworkInformation::kSupplementName[] =
"NavigatorNetworkInformation";
NetworkInformation* NavigatorNetworkInformation::connection(
Navigator& navigator) {
return NavigatorNetworkInformation::From(navigator).connection();
}
NetworkInformation* NavigatorNetworkInformation::connection() {
if (!connection_ && DomWindow())
connection_ = MakeGarbageCollected<NetworkInformation>(DomWindow());
return connection_.Get();
}
void NavigatorNetworkInformation::Trace(Visitor* visitor) const {
visitor->Trace(connection_);
Supplement<Navigator>::Trace(visitor);
ExecutionContextClient::Trace(visitor);
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_NETINFO_NAVIGATOR_NETWORK_INFORMATION_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NETINFO_NAVIGATOR_NETWORK_INFORMATION_H_
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Navigator;
class NetworkInformation;
class NavigatorNetworkInformation final
: public GarbageCollected<NavigatorNetworkInformation>,
public Supplement<Navigator>,
public ExecutionContextClient {
public:
static const char kSupplementName[];
static NavigatorNetworkInformation& From(Navigator&);
static NavigatorNetworkInformation* ToNavigatorNetworkInformation(Navigator&);
static NetworkInformation* connection(Navigator&);
explicit NavigatorNetworkInformation(Navigator&);
void Trace(Visitor*) const override;
private:
NetworkInformation* connection();
Member<NetworkInformation> connection_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_NETINFO_NAVIGATOR_NETWORK_INFORMATION_H_
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
[
ImplementedAs=NavigatorNetworkInformation
ImplementedAs=NetworkInformation
] partial interface Navigator {
[MeasureAs=NetInfo] readonly attribute NetworkInformation connection;
};
......@@ -10,6 +10,7 @@
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/execution_context/navigator_base.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
......@@ -270,8 +271,23 @@ void NetworkInformation::StopObserving() {
}
}
NetworkInformation::NetworkInformation(ExecutionContext* context)
: ExecutionContextLifecycleObserver(context),
const char NetworkInformation::kSupplementName[] = "NetworkInformation";
NetworkInformation* NetworkInformation::connection(NavigatorBase& navigator) {
if (!navigator.GetExecutionContext())
return nullptr;
NetworkInformation* supplement =
Supplement<NavigatorBase>::From<NetworkInformation>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NetworkInformation>(navigator);
ProvideTo(navigator, supplement);
}
return supplement;
}
NetworkInformation::NetworkInformation(NavigatorBase& navigator)
: Supplement<NavigatorBase>(navigator),
ExecutionContextLifecycleObserver(navigator.GetExecutionContext()),
web_holdback_console_message_shown_(false),
context_stopped_(false) {
base::Optional<base::TimeDelta> http_rtt;
......@@ -292,6 +308,7 @@ NetworkInformation::NetworkInformation(ExecutionContext* context)
void NetworkInformation::Trace(Visitor* visitor) const {
EventTargetWithInlineData::Trace(visitor);
Supplement<NavigatorBase>::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
}
......
......@@ -12,20 +12,27 @@
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class ExecutionContext;
class NavigatorBase;
class NetworkInformation final
: public EventTargetWithInlineData,
public ActiveScriptWrappable<NetworkInformation>,
public Supplement<NavigatorBase>,
public ExecutionContextLifecycleObserver,
public NetworkStateNotifier::NetworkStateObserver {
DEFINE_WRAPPERTYPEINFO();
public:
explicit NetworkInformation(ExecutionContext*);
static const char kSupplementName[];
// Web-exposed as navigator.connection.
static NetworkInformation* connection(NavigatorBase&);
explicit NetworkInformation(NavigatorBase&);
~NetworkInformation() override;
String type() const;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/netinfo/worker_navigator_network_information.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/workers/worker_navigator.h"
#include "third_party/blink/renderer/modules/netinfo/network_information.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
namespace blink {
WorkerNavigatorNetworkInformation::WorkerNavigatorNetworkInformation(
WorkerNavigator& navigator,
ExecutionContext* context)
: Supplement<WorkerNavigator>(navigator) {}
WorkerNavigatorNetworkInformation& WorkerNavigatorNetworkInformation::From(
WorkerNavigator& navigator,
ExecutionContext* context) {
WorkerNavigatorNetworkInformation* supplement =
ToWorkerNavigatorNetworkInformation(navigator, context);
if (!supplement) {
supplement = MakeGarbageCollected<WorkerNavigatorNetworkInformation>(
navigator, context);
ProvideTo(navigator, supplement);
}
return *supplement;
}
WorkerNavigatorNetworkInformation*
WorkerNavigatorNetworkInformation::ToWorkerNavigatorNetworkInformation(
WorkerNavigator& navigator,
ExecutionContext* context) {
return Supplement<WorkerNavigator>::From<WorkerNavigatorNetworkInformation>(
navigator);
}
const char WorkerNavigatorNetworkInformation::kSupplementName[] =
"WorkerNavigatorNetworkInformation";
NetworkInformation* WorkerNavigatorNetworkInformation::connection(
ScriptState* script_state,
WorkerNavigator& navigator) {
ExecutionContext* context = ExecutionContext::From(script_state);
return WorkerNavigatorNetworkInformation::From(navigator, context)
.connection(context);
}
void WorkerNavigatorNetworkInformation::Trace(Visitor* visitor) const {
visitor->Trace(connection_);
Supplement<WorkerNavigator>::Trace(visitor);
}
NetworkInformation* WorkerNavigatorNetworkInformation::connection(
ExecutionContext* context) {
DCHECK(context);
if (!connection_)
connection_ = MakeGarbageCollected<NetworkInformation>(context);
return connection_.Get();
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_NETINFO_WORKER_NAVIGATOR_NETWORK_INFORMATION_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NETINFO_WORKER_NAVIGATOR_NETWORK_INFORMATION_H_
#include "third_party/blink/renderer/core/workers/worker_navigator.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class ExecutionContext;
class NetworkInformation;
class ScriptState;
class WorkerNavigator;
class WorkerNavigatorNetworkInformation final
: public GarbageCollected<WorkerNavigatorNetworkInformation>,
public Supplement<WorkerNavigator> {
public:
static const char kSupplementName[];
static WorkerNavigatorNetworkInformation& From(WorkerNavigator&,
ExecutionContext*);
static WorkerNavigatorNetworkInformation* ToWorkerNavigatorNetworkInformation(
WorkerNavigator&,
ExecutionContext*);
static NetworkInformation* connection(ScriptState*, WorkerNavigator&);
WorkerNavigatorNetworkInformation(WorkerNavigator&, ExecutionContext*);
void Trace(Visitor*) const override;
private:
NetworkInformation* connection(ExecutionContext*);
Member<NetworkInformation> connection_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_NETINFO_WORKER_NAVIGATOR_NETWORK_INFORMATION_H_
......@@ -4,7 +4,7 @@
[
Exposed=Worker,
ImplementedAs=WorkerNavigatorNetworkInformation
ImplementedAs=NetworkInformation
] partial interface WorkerNavigator {
[CallWith=ScriptState, MeasureAs=NetInfo] readonly attribute NetworkInformation connection;
[MeasureAs=NetInfo] readonly attribute NetworkInformation connection;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment