Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
| 7 * rights reserved. | 7 * rights reserved. |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 EnumerationHistogram, unseenFrameHistogram, | 403 EnumerationHistogram, unseenFrameHistogram, |
| 404 ("Navigation.DeferredDocumentLoading.StatesV3", WouldLoadReasonEnd)); | 404 ("Navigation.DeferredDocumentLoading.StatesV3", WouldLoadReasonEnd)); |
| 405 unseenFrameHistogram.count(reason); | 405 unseenFrameHistogram.count(reason); |
| 406 } | 406 } |
| 407 | 407 |
| 408 class Document::NetworkStateObserver final | 408 class Document::NetworkStateObserver final |
| 409 : public GarbageCollectedFinalized<Document::NetworkStateObserver>, | 409 : public GarbageCollectedFinalized<Document::NetworkStateObserver>, |
| 410 public NetworkStateNotifier::NetworkStateObserver, | 410 public NetworkStateNotifier::NetworkStateObserver, |
| 411 public ContextLifecycleObserver { | 411 public ContextLifecycleObserver { |
| 412 USING_GARBAGE_COLLECTED_MIXIN(Document::NetworkStateObserver); | 412 USING_GARBAGE_COLLECTED_MIXIN(Document::NetworkStateObserver); |
| 413 EAGERLY_FINALIZE(); | |
| 414 | 413 |
| 415 public: | 414 public: |
| 416 explicit NetworkStateObserver(Document& document) | 415 explicit NetworkStateObserver(Document& document) |
| 417 : ContextLifecycleObserver(&document) { | 416 : ContextLifecycleObserver(&document) { |
| 418 networkStateNotifier().addOnLineObserver( | 417 networkStateNotifier().addOnLineObserver( |
| 419 this, | 418 this, |
| 420 TaskRunnerHelper::get(TaskType::Networking, getExecutionContext())); | 419 TaskRunnerHelper::get(TaskType::Networking, getExecutionContext())); |
| 421 } | 420 } |
| 422 | 421 |
| 423 // We eagerly finalize, so it's safe to touch getExecutionContext() here. | |
| 424 ~NetworkStateObserver() { unregisterAsObserver(getExecutionContext()); } | |
| 425 | |
| 426 void onLineStateChange(bool onLine) override { | 422 void onLineStateChange(bool onLine) override { |
| 427 AtomicString eventName = | 423 AtomicString eventName = |
| 428 onLine ? EventTypeNames::online : EventTypeNames::offline; | 424 onLine ? EventTypeNames::online : EventTypeNames::offline; |
| 429 Document* document = toDocument(getExecutionContext()); | 425 Document* document = toDocument(getExecutionContext()); |
| 430 if (!document->domWindow()) | 426 if (!document->domWindow()) |
| 431 return; | 427 return; |
| 432 document->domWindow()->dispatchEvent(Event::create(eventName)); | 428 document->domWindow()->dispatchEvent(Event::create(eventName)); |
| 433 InspectorInstrumentation::networkStateChanged(document->frame(), onLine); | 429 InspectorInstrumentation::networkStateChanged(document->frame(), onLine); |
| 434 } | 430 } |
| 435 | 431 |
| 436 void contextDestroyed(ExecutionContext* context) override { | 432 void contextDestroyed(ExecutionContext* context) override { |
| 437 unregisterAsObserver(context); | 433 unregisterAsObserver(context); |
| 438 } | 434 } |
| 439 | 435 |
| 440 void unregisterAsObserver(ExecutionContext* context) { | 436 void unregisterAsObserver(ExecutionContext* context) { |
| 441 if (!context) | 437 DCHECK(context); |
| 442 return; | |
| 443 networkStateNotifier().removeOnLineObserver( | 438 networkStateNotifier().removeOnLineObserver( |
| 444 this, TaskRunnerHelper::get(TaskType::Networking, context)); | 439 this, TaskRunnerHelper::get(TaskType::Networking, context)); |
| 445 } | 440 } |
| 446 | 441 |
| 447 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } | 442 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } |
| 448 }; | 443 }; |
| 449 | 444 |
| 450 Document::Document(const DocumentInit& initializer, | 445 Document::Document(const DocumentInit& initializer, |
| 451 DocumentClassFlags documentClasses) | 446 DocumentClassFlags documentClasses) |
| 452 : ContainerNode(0, CreateDocument), | 447 : ContainerNode(0, CreateDocument), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 m_didAssociateFormControlsTimer( | 527 m_didAssociateFormControlsTimer( |
| 533 TaskRunnerHelper::get(TaskType::UnspecedLoading, this), | 528 TaskRunnerHelper::get(TaskType::UnspecedLoading, this), |
| 534 this, | 529 this, |
| 535 &Document::didAssociateFormControlsTimerFired), | 530 &Document::didAssociateFormControlsTimerFired), |
| 536 m_timers(TaskRunnerHelper::get(TaskType::Timer, this)), | 531 m_timers(TaskRunnerHelper::get(TaskType::Timer, this)), |
| 537 m_hasViewportUnits(false), | 532 m_hasViewportUnits(false), |
| 538 m_parserSyncPolicy(AllowAsynchronousParsing), | 533 m_parserSyncPolicy(AllowAsynchronousParsing), |
| 539 m_nodeCount(0), | 534 m_nodeCount(0), |
| 540 m_wouldLoadReason(Created), | 535 m_wouldLoadReason(Created), |
| 541 m_passwordCount(0), | 536 m_passwordCount(0), |
| 542 m_engagementLevel(mojom::blink::EngagementLevel::NONE), | 537 m_engagementLevel(mojom::blink::EngagementLevel::NONE) { |
| 543 m_networkStateObserver(new NetworkStateObserver(*this)) { | |
| 544 if (m_frame) { | 538 if (m_frame) { |
| 545 DCHECK(m_frame->page()); | 539 DCHECK(m_frame->page()); |
| 546 provideContextFeaturesToDocumentFrom(*this, *m_frame->page()); | 540 provideContextFeaturesToDocumentFrom(*this, *m_frame->page()); |
| 547 | 541 |
| 548 m_fetcher = m_frame->loader().documentLoader()->fetcher(); | 542 m_fetcher = m_frame->loader().documentLoader()->fetcher(); |
| 549 FrameFetchContext::provideDocumentToContext(m_fetcher->context(), this); | 543 FrameFetchContext::provideDocumentToContext(m_fetcher->context(), this); |
| 550 | 544 |
| 551 // TODO(dcheng): Why does this need to check that DOMWindow is non-null? | 545 // TODO(dcheng): Why does this need to check that DOMWindow is non-null? |
| 552 CustomElementRegistry* registry = | 546 CustomElementRegistry* registry = |
| 553 m_frame->domWindow() ? m_frame->domWindow()->maybeCustomElements() | 547 m_frame->domWindow() ? m_frame->domWindow()->maybeCustomElements() |
| (...skipping 1889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2443 // The TextAutosizer can't update layout view info while the Document is | 2437 // The TextAutosizer can't update layout view info while the Document is |
| 2444 // detached, so update now in case anything changed. | 2438 // detached, so update now in case anything changed. |
| 2445 if (TextAutosizer* autosizer = textAutosizer()) | 2439 if (TextAutosizer* autosizer = textAutosizer()) |
| 2446 autosizer->updatePageInfo(); | 2440 autosizer->updatePageInfo(); |
| 2447 | 2441 |
| 2448 m_frame->documentAttached(); | 2442 m_frame->documentAttached(); |
| 2449 m_lifecycle.advanceTo(DocumentLifecycle::StyleClean); | 2443 m_lifecycle.advanceTo(DocumentLifecycle::StyleClean); |
| 2450 | 2444 |
| 2451 if (view()) | 2445 if (view()) |
| 2452 view()->didAttachDocument(); | 2446 view()->didAttachDocument(); |
| 2447 | |
| 2448 m_networkStateObserver = new NetworkStateObserver(*this); | |
|
sof
2017/02/27 07:54:33
Could you add a short explanatory comment why this
kinuko
2017/02/27 09:15:05
Done.
| |
| 2453 } | 2449 } |
| 2454 | 2450 |
| 2455 void Document::shutdown() { | 2451 void Document::shutdown() { |
| 2456 TRACE_EVENT0("blink", "Document::shutdown"); | 2452 TRACE_EVENT0("blink", "Document::shutdown"); |
| 2457 RELEASE_ASSERT(!m_frame || m_frame->tree().childCount() == 0); | 2453 RELEASE_ASSERT(!m_frame || m_frame->tree().childCount() == 0); |
| 2458 if (!isActive()) | 2454 if (!isActive()) |
| 2459 return; | 2455 return; |
| 2460 | 2456 |
| 2461 // Frame navigation can cause a new Document to be attached. Don't allow that, | 2457 // Frame navigation can cause a new Document to be attached. Don't allow that, |
| 2462 // since that will cause a situation where LocalFrame still has a Document | 2458 // since that will cause a situation where LocalFrame still has a Document |
| (...skipping 4199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6662 } | 6658 } |
| 6663 | 6659 |
| 6664 void showLiveDocumentInstances() { | 6660 void showLiveDocumentInstances() { |
| 6665 WeakDocumentSet& set = liveDocumentSet(); | 6661 WeakDocumentSet& set = liveDocumentSet(); |
| 6666 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6662 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 6667 for (blink::Document* document : set) | 6663 for (blink::Document* document : set) |
| 6668 fprintf(stderr, "- Document %p URL: %s\n", document, | 6664 fprintf(stderr, "- Document %p URL: %s\n", document, |
| 6669 document->url().getString().utf8().data()); | 6665 document->url().getString().utf8().data()); |
| 6670 } | 6666 } |
| 6671 #endif | 6667 #endif |
| OLD | NEW |