Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 2704083002: Remove Page dependency from NetworkStateNotifier (Closed)
Patch Set: DOMWindow -> Document Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/Document.cpp
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
index 13c590feef862ddb9edb151d758d49a7525602e5..30d0f1fc27574d687457796a8be1932e483f3323 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -205,6 +205,7 @@
#include "core/page/EventWithHitTestResults.h"
#include "core/page/FocusController.h"
#include "core/page/FrameTree.h"
+#include "core/page/NetworkStateNotifier.h"
#include "core/page/Page.h"
#include "core/page/PointerLockController.h"
#include "core/page/scrolling/RootScrollerController.h"
@@ -404,6 +405,40 @@ static void recordLoadReasonToHistogram(WouldLoadReason reason) {
unseenFrameHistogram.count(reason);
}
+class Document::NetworkStateObserver final
+ : public GarbageCollected<Document::NetworkStateObserver>,
+ public NetworkStateNotifier::NetworkStateObserver,
+ public ContextLifecycleObserver {
+ USING_GARBAGE_COLLECTED_MIXIN(Document::NetworkStateObserver);
+
+ public:
+ NetworkStateObserver(Document& document)
dcheng 2017/02/22 09:23:15 Nit: explicit
kinuko 2017/02/22 13:17:27 Done.
+ : ContextLifecycleObserver(document), m_document(&document) {
+ networkStateNotifier().addOnLineObserver(
+ this, TaskRunnerHelper::get(TaskType::Networking, m_document).get());
dcheng 2017/02/22 09:23:15 Is it safe to pass (and store) the WebTaskRunner a
kinuko 2017/02/22 13:17:27 Hmm, there was an assumption that the task runner
+ }
+
+ void onLineStateChange(bool onLine) override {
+ AtomicString eventName =
+ onLine ? EventTypeNames::online : EventTypeNames::offline;
+ m_document->domWindow()->dispatchEvent(Event::create(eventName));
+ InspectorInstrumentation::networkStateChanged(m_document->frame(), onLine);
+ }
+
+ void contextDestroyed(ExecutionContext* context) override {
+ networkStateNotifier().removeOnLineObserver(
+ this, TaskRunnerHelper::get(TaskType::Networking, context).get());
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE() {
+ visitor->trace(m_document);
+ ContextLifecycleObserver::trace(visitor);
+ }
+
+ private:
+ Member<Document> m_document;
+};
+
Document::Document(const DocumentInit& initializer,
DocumentClassFlags documentClasses)
: ContainerNode(0, CreateDocument),
@@ -496,7 +531,8 @@ Document::Document(const DocumentInit& initializer,
m_nodeCount(0),
m_wouldLoadReason(Created),
m_passwordCount(0),
- m_engagementLevel(mojom::blink::EngagementLevel::NONE) {
+ m_engagementLevel(mojom::blink::EngagementLevel::NONE),
+ m_networkStateObserver(new NetworkStateObserver(*this)) {
if (m_frame) {
DCHECK(m_frame->page());
provideContextFeaturesToDocumentFrom(*this, *m_frame->page());
@@ -6550,6 +6586,7 @@ DEFINE_TRACE(Document) {
visitor->trace(m_resizeObserverController);
visitor->trace(m_propertyRegistry);
visitor->trace(m_styleReattachDataMap);
+ visitor->trace(m_networkStateObserver);
Supplementable<Document>::trace(visitor);
TreeScope::trace(visitor);
ContainerNode::trace(visitor);

Powered by Google App Engine
This is Rietveld 408576698