|
@@ -0,0 +1,222 @@
|
|
|
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
+From: Adam Rice <[email protected]>
|
|
|
+Date: Thu, 30 Sep 2021 13:35:07 +0000
|
|
|
+Subject: Move NetworkStateObserver from document to window
|
|
|
+
|
|
|
+Previously NetworkStateObserver was a nested class of Document. Make it
|
|
|
+a nested class of LocalDOMWindow instead, since they have the same
|
|
|
+lifetime and it fires "online" and "offline" events at the window, not
|
|
|
+the document.
|
|
|
+
|
|
|
+BUG=1206928
|
|
|
+
|
|
|
+(cherry picked from commit af84d38b5cf5ee24f432ae8273bc2dad1e075f0e)
|
|
|
+
|
|
|
+Change-Id: I2a1080915cf56cfa47eae65594fe6edcc8c2130a
|
|
|
+Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3167550
|
|
|
+Reviewed-by: Kentaro Hara <[email protected]>
|
|
|
+Commit-Queue: Adam Rice <[email protected]>
|
|
|
+Cr-Original-Commit-Position: refs/heads/main@{#922429}
|
|
|
+Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3196231
|
|
|
+Cr-Commit-Position: refs/branch-heads/4638@{#476}
|
|
|
+Cr-Branched-From: 159257cab5585bc8421abf347984bb32fdfe9eb9-refs/heads/main@{#920003}
|
|
|
+
|
|
|
+diff --git a/third_party/blink/renderer/core/dom/document.cc b/third_party/blink/renderer/core/dom/document.cc
|
|
|
+index e600be44138a17d2fc6e7c6e615d47387e87dfd8..ab7b51f997548f594462e45ff37fd5681fad35c2 100644
|
|
|
+--- a/third_party/blink/renderer/core/dom/document.cc
|
|
|
++++ b/third_party/blink/renderer/core/dom/document.cc
|
|
|
+@@ -324,7 +324,6 @@
|
|
|
+ #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
|
|
|
+ #include "third_party/blink/renderer/platform/network/content_security_policy_parsers.h"
|
|
|
+ #include "third_party/blink/renderer/platform/network/http_parsers.h"
|
|
|
+-#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
|
|
|
+ #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
|
|
|
+ #include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
|
|
|
+ #include "third_party/blink/renderer/platform/scheduler/public/frame_or_worker_scheduler.h"
|
|
|
+@@ -578,43 +577,6 @@ uint64_t Document::global_tree_version_ = 0;
|
|
|
+
|
|
|
+ static bool g_threaded_parsing_enabled_for_testing = true;
|
|
|
+
|
|
|
+-class Document::NetworkStateObserver final
|
|
|
+- : public GarbageCollected<Document::NetworkStateObserver>,
|
|
|
+- public NetworkStateNotifier::NetworkStateObserver,
|
|
|
+- public ExecutionContextLifecycleObserver {
|
|
|
+- public:
|
|
|
+- explicit NetworkStateObserver(ExecutionContext* context)
|
|
|
+- : ExecutionContextLifecycleObserver(context) {
|
|
|
+- online_observer_handle_ = GetNetworkStateNotifier().AddOnLineObserver(
|
|
|
+- this, GetExecutionContext()->GetTaskRunner(TaskType::kNetworking));
|
|
|
+- }
|
|
|
+-
|
|
|
+- void OnLineStateChange(bool on_line) override {
|
|
|
+- AtomicString event_name =
|
|
|
+- on_line ? event_type_names::kOnline : event_type_names::kOffline;
|
|
|
+- auto* window = To<LocalDOMWindow>(GetExecutionContext());
|
|
|
+- window->DispatchEvent(*Event::Create(event_name));
|
|
|
+- probe::NetworkStateChanged(window->GetFrame(), on_line);
|
|
|
+- }
|
|
|
+-
|
|
|
+- void ContextDestroyed() override {
|
|
|
+- UnregisterAsObserver(GetExecutionContext());
|
|
|
+- }
|
|
|
+-
|
|
|
+- void UnregisterAsObserver(ExecutionContext* context) {
|
|
|
+- DCHECK(context);
|
|
|
+- online_observer_handle_ = nullptr;
|
|
|
+- }
|
|
|
+-
|
|
|
+- void Trace(Visitor* visitor) const override {
|
|
|
+- ExecutionContextLifecycleObserver::Trace(visitor);
|
|
|
+- }
|
|
|
+-
|
|
|
+- private:
|
|
|
+- std::unique_ptr<NetworkStateNotifier::NetworkStateObserverHandle>
|
|
|
+- online_observer_handle_;
|
|
|
+-};
|
|
|
+-
|
|
|
+ ExplicitlySetAttrElementsMap* Document::GetExplicitlySetAttrElementsMap(
|
|
|
+ Element* element) {
|
|
|
+ DCHECK(element);
|
|
|
+@@ -2694,12 +2656,6 @@ void Document::Initialize() {
|
|
|
+
|
|
|
+ if (View())
|
|
|
+ View()->DidAttachDocument();
|
|
|
+-
|
|
|
+- // Observer(s) should not be initialized until the document is initialized /
|
|
|
+- // attached to a frame. Otherwise
|
|
|
+- // ExecutionContextLifecycleObserver::contextDestroyed wouldn't be fired.
|
|
|
+- network_state_observer_ =
|
|
|
+- MakeGarbageCollected<NetworkStateObserver>(GetExecutionContext());
|
|
|
+ }
|
|
|
+
|
|
|
+ void Document::Shutdown() {
|
|
|
+@@ -7913,7 +7869,6 @@ void Document::Trace(Visitor* visitor) const {
|
|
|
+ visitor->Trace(intersection_observer_controller_);
|
|
|
+ visitor->Trace(snap_coordinator_);
|
|
|
+ visitor->Trace(property_registry_);
|
|
|
+- visitor->Trace(network_state_observer_);
|
|
|
+ visitor->Trace(policy_);
|
|
|
+ visitor->Trace(slot_assignment_engine_);
|
|
|
+ visitor->Trace(viewport_data_);
|
|
|
+diff --git a/third_party/blink/renderer/core/dom/document.h b/third_party/blink/renderer/core/dom/document.h
|
|
|
+index bc4b61badba0bbf96619c09345788fca224f5dcf..2eda9ae6b731aa0fad623a82303cbea0e8335ea2 100644
|
|
|
+--- a/third_party/blink/renderer/core/dom/document.h
|
|
|
++++ b/third_party/blink/renderer/core/dom/document.h
|
|
|
+@@ -1742,7 +1742,6 @@ class CORE_EXPORT Document : public ContainerNode,
|
|
|
+ BeforeMatchExpandedHiddenMatchableUkm);
|
|
|
+ FRIEND_TEST_ALL_PREFIXES(TextFinderSimTest,
|
|
|
+ BeforeMatchExpandedHiddenMatchableUkmNoHandler);
|
|
|
+- class NetworkStateObserver;
|
|
|
+
|
|
|
+ friend class AXContext;
|
|
|
+ void AddAXContext(AXContext*);
|
|
|
+@@ -2172,8 +2171,6 @@ class CORE_EXPORT Document : public ContainerNode,
|
|
|
+
|
|
|
+ Member<PropertyRegistry> property_registry_;
|
|
|
+
|
|
|
+- Member<NetworkStateObserver> network_state_observer_;
|
|
|
+-
|
|
|
+ // |ukm_recorder_| and |source_id_| will allow objects that are part of
|
|
|
+ // the document to record UKM.
|
|
|
+ std::unique_ptr<ukm::UkmRecorder> ukm_recorder_;
|
|
|
+diff --git a/third_party/blink/renderer/core/frame/local_dom_window.cc b/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
|
+index 61bec75d4a144e094f79053f86173f0e9af96412..afb278b466dfc2bb2db8e5c568e38e796a50cfcf 100644
|
|
|
+--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
|
++++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
|
+@@ -129,6 +129,7 @@
|
|
|
+ #include "third_party/blink/renderer/platform/bindings/script_state.h"
|
|
|
+ #include "third_party/blink/renderer/platform/heap/heap.h"
|
|
|
+ #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
|
|
|
++#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
|
|
|
+ #include "third_party/blink/renderer/platform/scheduler/public/dummy_schedulers.h"
|
|
|
+ #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
|
|
|
+ #include "third_party/blink/renderer/platform/storage/blink_storage_key.h"
|
|
|
+@@ -166,6 +167,38 @@ bool ShouldRecordPostMessageIncomingFrameUkmEvent(
|
|
|
+
|
|
|
+ } // namespace
|
|
|
+
|
|
|
++class LocalDOMWindow::NetworkStateObserver final
|
|
|
++ : public GarbageCollected<LocalDOMWindow::NetworkStateObserver>,
|
|
|
++ public NetworkStateNotifier::NetworkStateObserver,
|
|
|
++ public ExecutionContextLifecycleObserver {
|
|
|
++ public:
|
|
|
++ explicit NetworkStateObserver(ExecutionContext* context)
|
|
|
++ : ExecutionContextLifecycleObserver(context) {}
|
|
|
++
|
|
|
++ void Initialize() {
|
|
|
++ online_observer_handle_ = GetNetworkStateNotifier().AddOnLineObserver(
|
|
|
++ this, GetExecutionContext()->GetTaskRunner(TaskType::kNetworking));
|
|
|
++ }
|
|
|
++
|
|
|
++ void OnLineStateChange(bool on_line) override {
|
|
|
++ AtomicString event_name =
|
|
|
++ on_line ? event_type_names::kOnline : event_type_names::kOffline;
|
|
|
++ auto* window = To<LocalDOMWindow>(GetExecutionContext());
|
|
|
++ window->DispatchEvent(*Event::Create(event_name));
|
|
|
++ probe::NetworkStateChanged(window->GetFrame(), on_line);
|
|
|
++ }
|
|
|
++
|
|
|
++ void ContextDestroyed() override { online_observer_handle_ = nullptr; }
|
|
|
++
|
|
|
++ void Trace(Visitor* visitor) const override {
|
|
|
++ ExecutionContextLifecycleObserver::Trace(visitor);
|
|
|
++ }
|
|
|
++
|
|
|
++ private:
|
|
|
++ std::unique_ptr<NetworkStateNotifier::NetworkStateObserverHandle>
|
|
|
++ online_observer_handle_;
|
|
|
++};
|
|
|
++
|
|
|
+ LocalDOMWindow::LocalDOMWindow(LocalFrame& frame, WindowAgent* agent)
|
|
|
+ : DOMWindow(frame),
|
|
|
+ ExecutionContext(V8PerIsolateData::MainThreadIsolate(), agent),
|
|
|
+@@ -183,7 +216,9 @@ LocalDOMWindow::LocalDOMWindow(LocalFrame& frame, WindowAgent* agent)
|
|
|
+ isolated_world_csp_map_(
|
|
|
+ MakeGarbageCollected<
|
|
|
+ HeapHashMap<int, Member<ContentSecurityPolicy>>>()),
|
|
|
+- token_(frame.GetLocalFrameToken()) {}
|
|
|
++ token_(frame.GetLocalFrameToken()),
|
|
|
++ network_state_observer_(
|
|
|
++ MakeGarbageCollected<NetworkStateObserver>(this)) {}
|
|
|
+
|
|
|
+ void LocalDOMWindow::BindContentSecurityPolicy() {
|
|
|
+ DCHECK(!GetContentSecurityPolicy()->IsBound());
|
|
|
+@@ -193,6 +228,7 @@ void LocalDOMWindow::BindContentSecurityPolicy() {
|
|
|
+
|
|
|
+ void LocalDOMWindow::Initialize() {
|
|
|
+ GetAgent()->AttachContext(this);
|
|
|
++ network_state_observer_->Initialize();
|
|
|
+ }
|
|
|
+
|
|
|
+ void LocalDOMWindow::ResetWindowAgent(WindowAgent* agent) {
|
|
|
+@@ -2089,6 +2125,7 @@ void LocalDOMWindow::Trace(Visitor* visitor) const {
|
|
|
+ visitor->Trace(spell_checker_);
|
|
|
+ visitor->Trace(text_suggestion_controller_);
|
|
|
+ visitor->Trace(isolated_world_csp_map_);
|
|
|
++ visitor->Trace(network_state_observer_);
|
|
|
+ DOMWindow::Trace(visitor);
|
|
|
+ ExecutionContext::Trace(visitor);
|
|
|
+ Supplementable<LocalDOMWindow>::Trace(visitor);
|
|
|
+diff --git a/third_party/blink/renderer/core/frame/local_dom_window.h b/third_party/blink/renderer/core/frame/local_dom_window.h
|
|
|
+index b37537bcf85ac5333dd317ecfe6c783486486a28..8e7e544f901a1d957a03a834efa30f7cd1286f7a 100644
|
|
|
+--- a/third_party/blink/renderer/core/frame/local_dom_window.h
|
|
|
++++ b/third_party/blink/renderer/core/frame/local_dom_window.h
|
|
|
+@@ -448,6 +448,8 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
|
|
|
+ LocalDOMWindow* source) override;
|
|
|
+
|
|
|
+ private:
|
|
|
++ class NetworkStateObserver;
|
|
|
++
|
|
|
+ // Intentionally private to prevent redundant checks when the type is
|
|
|
+ // already LocalDOMWindow.
|
|
|
+ bool IsLocalDOMWindow() const override { return true; }
|
|
|
+@@ -555,6 +557,9 @@ class CORE_EXPORT LocalDOMWindow final : public DOMWindow,
|
|
|
+
|
|
|
+ // The storage key for this LocalDomWindow.
|
|
|
+ BlinkStorageKey storage_key_;
|
|
|
++
|
|
|
++ // Fire "online" and "offline" events.
|
|
|
++ Member<NetworkStateObserver> network_state_observer_;
|
|
|
+ };
|
|
|
+
|
|
|
+ template <>
|