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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 1778753003: Fire visibilitychange event on unload (behind the flag) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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 r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 } 1359 }
1360 1360
1361 PageVisibilityState Document::pageVisibilityState() const 1361 PageVisibilityState Document::pageVisibilityState() const
1362 { 1362 {
1363 // The visibility of the document is inherited from the visibility of the 1363 // The visibility of the document is inherited from the visibility of the
1364 // page. If there is no page associated with the document, we will assume 1364 // page. If there is no page associated with the document, we will assume
1365 // that the page is hidden, as specified by the spec: 1365 // that the page is hidden, as specified by the spec:
1366 // http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview. html#dom-document-hidden 1366 // http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview. html#dom-document-hidden
1367 if (!m_frame || !m_frame->page()) 1367 if (!m_frame || !m_frame->page())
1368 return PageVisibilityStateHidden; 1368 return PageVisibilityStateHidden;
1369 // While visibilitychange is being dispatched during unloading it is
1370 // expected that the visibility is hidden regardless of the page's
1371 // visibility.
1372 if (m_loadEventProgress >= UnloadVisibilityChangeInProgress)
1373 return PageVisibilityStateHidden;
1369 return m_frame->page()->visibilityState(); 1374 return m_frame->page()->visibilityState();
1370 } 1375 }
1371 1376
1372 String Document::visibilityState() const 1377 String Document::visibilityState() const
1373 { 1378 {
1374 return pageVisibilityStateString(pageVisibilityState()); 1379 return pageVisibilityStateString(pageVisibilityState());
1375 } 1380 }
1376 1381
1377 bool Document::hidden() const 1382 bool Document::hidden() const
1378 { 1383 {
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
2772 Element* currentFocusedElement = focusedElement(); 2777 Element* currentFocusedElement = focusedElement();
2773 if (isHTMLInputElement(currentFocusedElement)) 2778 if (isHTMLInputElement(currentFocusedElement))
2774 toHTMLInputElement(*currentFocusedElement).endEditing(); 2779 toHTMLInputElement(*currentFocusedElement).endEditing();
2775 if (m_loadEventProgress < PageHideInProgress) { 2780 if (m_loadEventProgress < PageHideInProgress) {
2776 m_loadEventProgress = PageHideInProgress; 2781 m_loadEventProgress = PageHideInProgress;
2777 if (LocalDOMWindow* window = domWindow()) 2782 if (LocalDOMWindow* window = domWindow())
2778 window->dispatchEvent(PageTransitionEvent::create(EventTypeNames ::pagehide, false), this); 2783 window->dispatchEvent(PageTransitionEvent::create(EventTypeNames ::pagehide, false), this);
2779 if (!m_frame) 2784 if (!m_frame)
2780 return; 2785 return;
2781 2786
2787 PageVisibilityState visibilityState = pageVisibilityState();
2788 m_loadEventProgress = UnloadVisibilityChangeInProgress;
2789 if (visibilityState != PageVisibilityStateHidden && RuntimeEnabledFe atures::visibilityChangeOnUnloadEnabled()) {
2790 // Dispatch visibilitychange event, but don't bother doing
2791 // other notifications as we're about to be unloaded.
2792 dispatchEvent(Event::createBubble(EventTypeNames::visibilitychan ge));
2793 dispatchEvent(Event::createBubble(EventTypeNames::webkitvisibili tychange));
2794 }
2795 if (!m_frame)
2796 return;
2797
2782 // The DocumentLoader (and thus its DocumentLoadTiming) might get de stroyed 2798 // The DocumentLoader (and thus its DocumentLoadTiming) might get de stroyed
2783 // while dispatching the event, so protect it to prevent writing the end 2799 // while dispatching the event, so protect it to prevent writing the end
2784 // time into freed memory. 2800 // time into freed memory.
2785 RefPtrWillBeRawPtr<DocumentLoader> documentLoader = m_frame->loader( ).provisionalDocumentLoader(); 2801 RefPtrWillBeRawPtr<DocumentLoader> documentLoader = m_frame->loader( ).provisionalDocumentLoader();
2786 m_loadEventProgress = UnloadEventInProgress; 2802 m_loadEventProgress = UnloadEventInProgress;
2787 RefPtrWillBeRawPtr<Event> unloadEvent(Event::create(EventTypeNames:: unload)); 2803 RefPtrWillBeRawPtr<Event> unloadEvent(Event::create(EventTypeNames:: unload));
2788 if (documentLoader && !documentLoader->timing().unloadEventStart() & & !documentLoader->timing().unloadEventEnd()) { 2804 if (documentLoader && !documentLoader->timing().unloadEventStart() & & !documentLoader->timing().unloadEventEnd()) {
2789 DocumentLoadTiming& timing = documentLoader->timing(); 2805 DocumentLoadTiming& timing = documentLoader->timing();
2790 ASSERT(timing.navigationStart()); 2806 ASSERT(timing.navigationStart());
2791 timing.markUnloadEventStart(); 2807 timing.markUnloadEventStart();
(...skipping 11 matching lines...) Expand all
2803 2819
2804 // Don't remove event listeners from a transitional empty document (see http s://bugs.webkit.org/show_bug.cgi?id=28716 for more information). 2820 // Don't remove event listeners from a transitional empty document (see http s://bugs.webkit.org/show_bug.cgi?id=28716 for more information).
2805 bool keepEventListeners = m_frame->loader().provisionalDocumentLoader() 2821 bool keepEventListeners = m_frame->loader().provisionalDocumentLoader()
2806 && m_frame->shouldReuseDefaultView(m_frame->loader().provisionalDocument Loader()->url()); 2822 && m_frame->shouldReuseDefaultView(m_frame->loader().provisionalDocument Loader()->url());
2807 if (!keepEventListeners) 2823 if (!keepEventListeners)
2808 removeAllEventListenersRecursively(); 2824 removeAllEventListenersRecursively();
2809 } 2825 }
2810 2826
2811 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const 2827 Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const
2812 { 2828 {
2813 if (m_loadEventProgress == BeforeUnloadEventInProgress) 2829 switch (m_loadEventProgress) {
2830 case BeforeUnloadEventInProgress:
2814 return BeforeUnloadDismissal; 2831 return BeforeUnloadDismissal;
2815 if (m_loadEventProgress == PageHideInProgress) 2832 case PageHideInProgress:
2816 return PageHideDismissal; 2833 return PageHideDismissal;
2817 if (m_loadEventProgress == UnloadEventInProgress) 2834 case UnloadVisibilityChangeInProgress:
2835 return UnloadVisibilityChangeDismissal;
2836 case UnloadEventInProgress:
2818 return UnloadDismissal; 2837 return UnloadDismissal;
2838
2839 case LoadEventNotRun:
2840 case LoadEventInProgress:
2841 case LoadEventCompleted:
2842 case BeforeUnloadEventCompleted:
2843 case UnloadEventHandled:
2844 return NoDismissal;
2845 }
2846 ASSERT_NOT_REACHED();
2819 return NoDismissal; 2847 return NoDismissal;
2820 } 2848 }
2821 2849
2822 void Document::setParsingState(ParsingState parsingState) 2850 void Document::setParsingState(ParsingState parsingState)
2823 { 2851 {
2824 m_parsingState = parsingState; 2852 m_parsingState = parsingState;
2825 2853
2826 if (parsing() && !m_elementDataCache) 2854 if (parsing() && !m_elementDataCache)
2827 m_elementDataCache = ElementDataCache::create(); 2855 m_elementDataCache = ElementDataCache::create();
2828 } 2856 }
(...skipping 3166 matching lines...) Expand 10 before | Expand all | Expand 10 after
5995 #ifndef NDEBUG 6023 #ifndef NDEBUG
5996 using namespace blink; 6024 using namespace blink;
5997 void showLiveDocumentInstances() 6025 void showLiveDocumentInstances()
5998 { 6026 {
5999 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 6027 Document::WeakDocumentSet& set = Document::liveDocumentSet();
6000 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6028 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
6001 for (Document* document : set) 6029 for (Document* document : set)
6002 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 6030 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
6003 } 6031 }
6004 #endif 6032 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.h ('k') | third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698