⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 194077 in webkit


Ignore:
Timestamp:
Dec 14, 2015, 4:35:35 PM (11 years ago)
Author:
matthew_hanson@apple.com
Message:

Merge r192270. rdar://problem/23435543

Location:
branches/safari-601-branch
Files:
25 added
18 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-601-branch/LayoutTests/ChangeLog

    r194065 r194077  
     12015-12-14  Harris Papadopoulos  <cpapadopoulos@apple.com>
     2
     3        Merge r192270. rdar://problem/23435543
     4
     5    2015-11-10  Geoffrey Garen  <ggaren@apple.com>
     6
     7            alert, confirm, prompt, showModalDialog should be forbidden during page close and navigation
     8            https://bugs.webkit.org/show_bug.cgi?id=150980
     9
     10            Reviewed by Chris Dumez.
     11
     12            Added tests to cover the matrix of [ alert, confirm, prompt, showModalDialog ] x [ beforeunload, unload, pagehide ].
     13
     14            * fast/events/beforeunload-alert-expected.txt: Added.
     15            * fast/events/beforeunload-alert.html: Added.
     16            * fast/events/beforeunload-confirm-expected.txt: Added.
     17            * fast/events/beforeunload-confirm.html: Added.
     18            * fast/events/beforeunload-prompt-expected.txt: Added.
     19            * fast/events/beforeunload-prompt.html: Added.
     20            * fast/events/beforeunload-showModalDialog-expected.txt: Added.
     21            * fast/events/beforeunload-showModalDialog.html: Added.
     22            * fast/events/onunload-expected.txt:
     23            * fast/events/onunload-not-on-body-expected.txt:
     24            * fast/events/onunload-window-property-expected.txt:
     25            * fast/events/pagehide-alert-expected.txt: Added.
     26            * fast/events/pagehide-alert.html: Added.
     27            * fast/events/pagehide-confirm-expected.txt: Added.
     28            * fast/events/pagehide-confirm.html: Added.
     29            * fast/events/pagehide-prompt-expected.txt: Added.
     30            * fast/events/pagehide-prompt.html: Added.
     31            * fast/events/pagehide-showModalDialog-expected.txt: Added.
     32            * fast/events/pagehide-showModalDialog.html: Added.
     33            * fast/events/pageshow-pagehide-on-back-cached-expected.txt:
     34            * fast/events/pageshow-pagehide-on-back-uncached-expected.txt:
     35            * fast/events/resources/prompt-landing-page.html: Added.
     36            * fast/events/unload-alert-expected.txt: Added.
     37            * fast/events/unload-alert.html: Added.
     38            * fast/events/unload-confirm-expected.txt: Added.
     39            * fast/events/unload-confirm.html: Added.
     40            * fast/events/unload-prompt-expected.txt: Added.
     41            * fast/events/unload-prompt.html: Added.
     42            * fast/events/unload-showModalDialog-expected.txt: Added.
     43            * fast/events/unload-showModalDialog.html: Added.
     44
     45            * platform/wk2/TestExpectations: WebKit2 can't handle showModalDialog tests.
     46
     47            * compositing/iframes/page-cache-layer-tree-expected.txt:
     48            * fast/dom/Geolocation/notimer-after-unload-expected.txt:
     49            * fast/history/timed-refresh-in-cached-frame-expected.txt:
     50            * fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt:
     51            * fast/loader/page-dismissal-modal-dialogs-expected.txt: These were
     52            pre-existing tests that tried to alert during unload.
     53
    1542015-12-14  Matthew Hanson  <matthew_hanson@apple.com>
    255
  • branches/safari-601-branch/LayoutTests/compositing/iframes/page-cache-layer-tree-expected.txt

    r168244 r194077  
    11ALERT: pageshow - not from cache
    2 ALERT: pagehide - entering cache
     2CONSOLE MESSAGE: line 70: Use of window.alert is not allowed while unloading a page.
    33ALERT: pageshow - from cache
    44This tests that layers are rebuilt properly after the page is restored from the page cache.
  • branches/safari-601-branch/LayoutTests/fast/dom/Geolocation/notimer-after-unload-expected.txt

    r59859 r194077  
    11main frame - has 1 onunload handler(s)
    2 ALERT: unload-called
     2CONSOLE MESSAGE: line 15: Use of window.alert is not allowed while unloading a page.
    33You should have seen one unload alert appear.
  • branches/safari-601-branch/LayoutTests/fast/events/onunload-expected.txt

    r36652 r194077  
    11main frame - has 1 onunload handler(s)
    2 ALERT: unload
     2CONSOLE MESSAGE: line 16: Use of window.alert is not allowed while unloading a page.
    33You should have seen an unload alert appear.
  • branches/safari-601-branch/LayoutTests/fast/events/onunload-not-on-body-expected.txt

    r36652 r194077  
    11frame "<!--framePath //<!--frame2-->-->" - has 1 onunload handler(s)
    2 ALERT: unload
     2CONSOLE MESSAGE: line 1: Use of window.alert is not allowed while unloading a page.
    33you should only see one unload alert appear.
  • branches/safari-601-branch/LayoutTests/fast/events/onunload-window-property-expected.txt

    r39097 r194077  
    1 ALERT: unload
     1CONSOLE MESSAGE: line 13: Use of window.alert is not allowed while unloading a page.
    22You should have seen an unload alert appear.
  • branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-cached-expected.txt

    r47824 r194077  
    11ALERT: window.onload
    22ALERT: window.onpageshow, target = [object HTMLDocument], persisted = false
    3 ALERT: window.onpagehide, target = [object HTMLDocument], persisted = true
     3CONSOLE MESSAGE: line 25: Use of window.alert is not allowed while unloading a page.
    44ALERT: window.onpageshow, target = [object HTMLDocument], persisted = true
    55Test pageshow/pagehide event behavior when navigating back to an cached page.
  • branches/safari-601-branch/LayoutTests/fast/events/pageshow-pagehide-on-back-uncached-expected.txt

    r47824 r194077  
    22ALERT: window.onload
    33ALERT: window.onpageshow, target = [object HTMLDocument], persisted = false
    4 ALERT: window.onpagehide, target = [object HTMLDocument], persisted = false
     4CONSOLE MESSAGE: line 28: Use of window.alert is not allowed while unloading a page.
    55main frame "pageshow/pagehide" - has 1 onunload handler(s)
    66ALERT: window.onload
  • branches/safari-601-branch/LayoutTests/fast/history/timed-refresh-in-cached-frame-expected.txt

    r61801 r194077  
    1 ALERT: pagehide true
     1CONSOLE MESSAGE: line 1: Use of window.alert is not allowed while unloading a page.
    22PASSED if didn't crash in two seconds.
  • branches/safari-601-branch/LayoutTests/fast/loader/frames-with-unload-handlers-in-page-cache-expected.txt

    r48036 r194077  
    22ALERT: Subframe onload
    33ALERT: Subframe onpageshow
    4 ALERT: Main frame window.onpagehide called
    5 ALERT: Subframe onpagehide
    6 ALERT: Subframe onunload
     4CONSOLE MESSAGE: line 16: Use of window.alert is not allowed while unloading a page.
     5CONSOLE MESSAGE: line 18: Use of window.alert is not allowed while unloading a page.
     6CONSOLE MESSAGE: line 10: Use of window.alert is not allowed while unloading a page.
    77
  • branches/safari-601-branch/LayoutTests/fast/loader/page-dismissal-modal-dialogs-expected.txt

    r178527 r194077  
    11frame "<!--framePath //<!--frame0-->-->" - has 1 onunload handler(s)
    2 CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
    3 CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
    4 CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
    5 CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
    6 CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
    7 CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
    8 CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
    9 CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
    10 CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
    11 CONSOLE MESSAGE: line 8: Use of window.alert is not allowed during beforeunload event dispatch.
    12 CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed during beforeunload event dispatch.
    13 CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed during beforeunload event dispatch.
    14 ALERT: mainFrame pagehide PASS
    15 CONFIRM: mainFrame pagehide PASS
    16 PROMPT: mainFrame pagehide PASS, default text: PASS
    17 ALERT: iFrame click PASS
    18 CONFIRM: iFrame click PASS
    19 PROMPT: iFrame click PASS, default text: PASS
    20 ALERT: mainFrame unload PASS
    21 CONFIRM: mainFrame unload PASS
    22 PROMPT: mainFrame unload PASS, default text: PASS
    23 ALERT: iFrame click PASS
    24 CONFIRM: iFrame click PASS
    25 PROMPT: iFrame click PASS, default text: PASS
    26 ALERT: iFrame pagehide PASS
    27 CONFIRM: iFrame pagehide PASS
    28 PROMPT: iFrame pagehide PASS, default text: PASS
    29 ALERT: iFrame unload PASS
    30 CONFIRM: iFrame unload PASS
    31 PROMPT: iFrame unload PASS, default text: PASS
     2CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     3CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     4CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     5CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     6CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     7CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     8CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     9CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     10CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     11CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     12CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     13CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     14CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     15CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     16CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     17CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     18CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     19CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     20CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     21CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     22CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     23CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     24CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     25CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     26CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     27CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     28CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
     29CONSOLE MESSAGE: line 8: Use of window.alert is not allowed while unloading a page.
     30CONSOLE MESSAGE: line 9: Use of window.confirm is not allowed while unloading a page.
     31CONSOLE MESSAGE: line 10: Use of window.prompt is not allowed while unloading a page.
    3232PASS
  • branches/safari-601-branch/LayoutTests/platform/wk2/TestExpectations

    r186671 r194077  
    142142# <https://bugs.webkit.org/show_bug.cgi?id=69548>
    143143fast/events/show-modal-dialog-onblur-onfocus.html
     144fast/events/beforeunload-showModalDialog.html
     145fast/events/pagehide-showModalDialog.html
     146fast/events/unload-showModalDialog.html
    144147
    145148# WebKitTestRunner needs testRunner.setWillSendRequestClearHeader
  • branches/safari-601-branch/Source/WebCore/ChangeLog

    r194075 r194077  
     12015-12-14  Harris Papadopoulos  <cpapadopoulos@apple.com>
     2
     3        Merge r192270. rdar://problem/23435543
     4
     5    2015-11-10  Geoffrey Garen  <ggaren@apple.com>
     6
     7            alert, confirm, prompt, showModalDialog should be forbidden during page close and navigation
     8            https://bugs.webkit.org/show_bug.cgi?id=150980
     9
     10            Reviewed by Chris Dumez.
     11
     12            Tests: fast/events/beforeunload-alert.html
     13                   fast/events/beforeunload-confirm.html
     14                   fast/events/beforeunload-prompt.html
     15                   fast/events/beforeunload-showModalDialog.html
     16                   fast/events/pagehide-alert.html
     17                   fast/events/pagehide-confirm.html
     18                   fast/events/pagehide-prompt.html
     19                   fast/events/pagehide-showModalDialog.html
     20                   fast/events/unload-alert.html
     21                   fast/events/unload-confirm.html
     22                   fast/events/unload-prompt.html
     23                   fast/events/unload-showModalDialog.html
     24
     25            * loader/FrameLoader.cpp:
     26            (WebCore::FrameLoader::stopLoading): Factored out a helper function for
     27            unload event processing.
     28            (WebCore::FrameLoader::handleUnloadEvents): Forbid prompts in unload
     29            events just like we do in beforeunload events, and for the same reasons.
     30
     31            (WebCore::FrameLoader::handleBeforeUnloadEvent): Updated for renames.
     32
     33            * loader/FrameLoader.h:
     34
     35            * page/DOMWindow.cpp:
     36            (WebCore::DOMWindow::print):
     37            (WebCore::DOMWindow::alert):
     38            (WebCore::DOMWindow::confirm):
     39            (WebCore::DOMWindow::prompt):
     40            (WebCore::DOMWindow::showModalDialog): Updated for renames. Refactored
     41            some of this code to handle null pages more cleanly. In particular, we
     42            sometimes used to treat null page as "everything is permitted" -- but it
     43            is best practice in a permissions context to treat lack of information
     44            as no permission granted rather than all permissions granted. (I don't
     45            know of a way to trigger this condition in practice.)
     46
     47            * page/Page.cpp:
     48            (WebCore::Page::Page):
     49            (WebCore::Page::forbidPrompts):
     50            (WebCore::Page::allowPrompts):
     51            (WebCore::Page::arePromptsAllowed): Renamed to make these functions
     52            reflect their new, broader context.
     53
     54            (WebCore::Page::incrementFrameHandlingBeforeUnloadEventCount): Deleted.
     55            (WebCore::Page::decrementFrameHandlingBeforeUnloadEventCount): Deleted.
     56            (WebCore::Page::isAnyFrameHandlingBeforeUnloadEvent): Deleted.
     57
     58            * page/Page.h:
     59
    1602015-12-08  Harris Papadopoulos  <cpapadopoulos@apple.com>
    261
  • branches/safari-601-branch/Source/WebCore/loader/FrameLoader.cpp

    r194075 r194077  
    176176}
    177177
     178struct ForbidPromptsScope {
     179    ForbidPromptsScope(Page* page) : m_page(page)
     180    {
     181        if (!m_page)
     182            return;
     183        m_page->forbidPrompts();
     184    }
     185
     186    ~ForbidPromptsScope()
     187    {
     188        if (!m_page)
     189            return;
     190        m_page->allowPrompts();
     191    }
     192
     193    Page* m_page;
     194};
     195
    178196class FrameLoader::FrameProgressTracker {
    179197public:
     
    420438        m_frame.document()->parser()->stopParsing();
    421439
    422     if (unloadEventPolicy != UnloadEventPolicyNone) {
    423         if (m_frame.document()) {
    424             if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) {
    425                 Element* currentFocusedElement = m_frame.document()->focusedElement();
    426                 if (currentFocusedElement && currentFocusedElement->toInputElement())
    427                     currentFocusedElement->toInputElement()->endEditing();
    428                 if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) {
    429                     if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) {
    430                         m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide;
    431                         m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->inPageCache()), m_frame.document());
    432                     }
    433 
    434                     // FIXME: update Page Visibility state here.
    435                     // https://bugs.webkit.org/show_bug.cgi?id=116770
    436 
    437                     if (!m_frame.document()->inPageCache()) {
    438                         RefPtr<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false));
    439                         // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed
    440                         // while dispatching the event, so protect it to prevent writing the end
    441                         // time into freed memory.
    442                         RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader;
    443                         m_pageDismissalEventBeingDispatched = PageDismissalType::Unload;
    444                         if (documentLoader && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) {
    445                             DocumentLoadTiming& timing = documentLoader->timing();
    446                             ASSERT(timing.navigationStart());
    447                             timing.markUnloadEventStart();
    448                             m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
    449                             timing.markUnloadEventEnd();
    450                         } else
    451                             m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
    452                     }
    453                 }
    454                 m_pageDismissalEventBeingDispatched = PageDismissalType::None;
    455                 if (m_frame.document())
    456                     m_frame.document()->updateStyleIfNeeded();
    457                 m_wasUnloadEventEmitted = true;
    458             }
    459         }
    460 
    461         // Dispatching the unload event could have made m_frame.document() null.
    462         if (m_frame.document() && !m_frame.document()->inPageCache()) {
    463             // Don't remove event listeners from a transitional empty document (see bug 28716 for more information).
    464             bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader
    465                 && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url());
    466 
    467             if (!keepEventListeners)
    468                 m_frame.document()->removeAllEventListeners();
    469         }
    470     }
     440    if (unloadEventPolicy != UnloadEventPolicyNone)
     441        handleUnloadEvents(unloadEventPolicy);
    471442
    472443    m_isComplete = true; // to avoid calling completed() in finishedParsing()
     
    28702841}
    28712842
     2843void FrameLoader::handleUnloadEvents(UnloadEventPolicy unloadEventPolicy)
     2844{
     2845    if (!m_frame.document())
     2846        return;
     2847
     2848    // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent.
     2849    ForbidPromptsScope forbidPrompts(m_frame.page());
     2850
     2851    if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) {
     2852        auto* currentFocusedElement = m_frame.document()->focusedElement();
     2853        if (is<HTMLInputElement>(currentFocusedElement))
     2854            downcast<HTMLInputElement>(*currentFocusedElement).endEditing();
     2855        if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) {
     2856            if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) {
     2857                m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide;
     2858                m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->inPageCache()), m_frame.document());
     2859            }
     2860
     2861            // FIXME: update Page Visibility state here.
     2862            // https://bugs.webkit.org/show_bug.cgi?id=116770
     2863
     2864            if (!m_frame.document()->inPageCache()) {
     2865                RefPtr<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false));
     2866                // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed
     2867                // while dispatching the event, so protect it to prevent writing the end
     2868                // time into freed memory.
     2869                RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader;
     2870                m_pageDismissalEventBeingDispatched = PageDismissalType::Unload;
     2871                if (documentLoader && documentLoader->timing().navigationStart() && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) {
     2872                    auto& timing = documentLoader->timing();
     2873                    timing.markUnloadEventStart();
     2874                    m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
     2875                    timing.markUnloadEventEnd();
     2876                } else
     2877                    m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document());
     2878            }
     2879        }
     2880        m_pageDismissalEventBeingDispatched = PageDismissalType::None;
     2881        if (m_frame.document())
     2882            m_frame.document()->updateStyleIfNeeded();
     2883        m_wasUnloadEventEmitted = true;
     2884    }
     2885
     2886    // Dispatching the unload event could have made m_frame.document() null.
     2887    if (!m_frame.document())
     2888        return;
     2889
     2890    if (m_frame.document()->inPageCache())
     2891        return;
     2892
     2893    // Don't remove event listeners from a transitional empty document (see bug 28716 for more information).
     2894    bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader
     2895        && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url());
     2896
     2897    if (!keepEventListeners)
     2898        m_frame.document()->removeAllEventListeners();
     2899}
     2900
    28722901bool FrameLoader::handleBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLoaderBeingNavigated)
    28732902{
     
    28832912    m_pageDismissalEventBeingDispatched = PageDismissalType::BeforeUnload;
    28842913
    2885     // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent.
    2886     Page* page = m_frame.page();
    2887     page->incrementFrameHandlingBeforeUnloadEventCount();
    2888     domWindow->dispatchEvent(beforeUnloadEvent.get(), domWindow->document());
    2889     page->decrementFrameHandlingBeforeUnloadEventCount();
     2914    {
     2915        ForbidPromptsScope forbidPrompts(m_frame.page());
     2916        domWindow->dispatchEvent(beforeUnloadEvent.get(), domWindow->document());
     2917    }
    28902918
    28912919    m_pageDismissalEventBeingDispatched = PageDismissalType::None;
  • branches/safari-601-branch/Source/WebCore/loader/FrameLoader.h

    r186005 r194077  
    318318
    319319    bool handleBeforeUnloadEvent(Chrome&, FrameLoader* frameLoaderBeingNavigated);
     320    void handleUnloadEvents(UnloadEventPolicy);
    320321
    321322    void continueLoadAfterNavigationPolicy(const ResourceRequest&, PassRefPtr<FormState>, bool shouldContinue, AllowNavigationToInvalidURL);
  • branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp

    r191073 r194077  
    10491049        return;
    10501050
    1051     Page* page = m_frame->page();
     1051    auto* page = m_frame->page();
    10521052    if (!page)
    10531053        return;
    10541054
    1055     // Pages are not allowed to bring up a modal print dialog during BeforeUnload dispatch.
    1056     if (page->isAnyFrameHandlingBeforeUnloadEvent()) {
    1057         printErrorMessage("Use of window.print is not allowed during beforeunload event dispatch.");
     1055    if (!page->arePromptsAllowed()) {
     1056        printErrorMessage("Use of window.print is not allowed while unloading a page.");
    10581057        return;
    10591058    }
     
    10821081        return;
    10831082
    1084     // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
    1085     if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
    1086         printErrorMessage("Use of window.alert is not allowed during beforeunload event dispatch.");
     1083    auto* page = m_frame->page();
     1084    if (!page)
     1085        return;
     1086
     1087    if (!page->arePromptsAllowed()) {
     1088        printErrorMessage("Use of window.alert is not allowed while unloading a page.");
    10871089        return;
    10881090    }
    10891091
    10901092    m_frame->document()->updateStyleIfNeeded();
    1091 
    1092     Page* page = m_frame->page();
    1093     if (!page)
    1094         return;
    10951093
    10961094    page->chrome().runJavaScriptAlert(m_frame, message);
     
    11021100        return false;
    11031101   
    1104     // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
    1105     if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
    1106         printErrorMessage("Use of window.confirm is not allowed during beforeunload event dispatch.");
    1107         return false;
    1108     }
    1109 
    1110     m_frame->document()->updateStyleIfNeeded();
    1111 
    1112     Page* page = m_frame->page();
     1102    auto* page = m_frame->page();
    11131103    if (!page)
    11141104        return false;
    11151105
     1106    if (!page->arePromptsAllowed()) {
     1107        printErrorMessage("Use of window.confirm is not allowed while unloading a page.");
     1108        return false;
     1109    }
     1110
     1111    m_frame->document()->updateStyleIfNeeded();
     1112
    11161113    return page->chrome().runJavaScriptConfirm(m_frame, message);
    11171114}
     
    11221119        return String();
    11231120
    1124     // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
    1125     if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
    1126         printErrorMessage("Use of window.prompt is not allowed during beforeunload event dispatch.");
    1127         return String();
    1128     }
    1129 
    1130     m_frame->document()->updateStyleIfNeeded();
    1131 
    1132     Page* page = m_frame->page();
     1121    auto* page = m_frame->page();
    11331122    if (!page)
    11341123        return String();
     1124
     1125    if (!page->arePromptsAllowed()) {
     1126        printErrorMessage("Use of window.prompt is not allowed while unloading a page.");
     1127        return String();
     1128    }
     1129
     1130    m_frame->document()->updateStyleIfNeeded();
    11351131
    11361132    String returnValue;
     
    22372233        return;
    22382234
    2239     // Pages are not allowed to cause modal alerts during BeforeUnload dispatch.
    2240     if (page() && page()->isAnyFrameHandlingBeforeUnloadEvent()) {
    2241         printErrorMessage("Use of window.showModalDialog is not allowed during beforeunload event dispatch.");
     2235    auto* page = m_frame->page();
     2236    if (!page)
     2237        return;
     2238
     2239    if (!page->arePromptsAllowed()) {
     2240        printErrorMessage("Use of window.showModalDialog is not allowed while unloading a page.");
    22422241        return;
    22432242    }
  • branches/safari-601-branch/Source/WebCore/page/Page.cpp

    r187390 r194077  
    210210#endif
    211211    , m_lastSpatialNavigationCandidatesCount(0) // NOTE: Only called from Internals for Spatial Navigation testing.
    212     , m_framesHandlingBeforeUnloadEvent(0)
     212    , m_forbidPromptsDepth(0)
    213213    , m_applicationCacheStorage(pageConfiguration.applicationCacheStorage ? *WTF::move(pageConfiguration.applicationCacheStorage) : ApplicationCacheStorage::singleton())
    214214    , m_databaseProvider(*WTF::move(pageConfiguration.databaseProvider))
     
    15981598#endif
    15991599
    1600 void Page::incrementFrameHandlingBeforeUnloadEventCount()
    1601 {
    1602     ++m_framesHandlingBeforeUnloadEvent;
    1603 }
    1604 
    1605 void Page::decrementFrameHandlingBeforeUnloadEventCount()
    1606 {
    1607     ASSERT(m_framesHandlingBeforeUnloadEvent);
    1608     --m_framesHandlingBeforeUnloadEvent;
    1609 }
    1610 
    1611 bool Page::isAnyFrameHandlingBeforeUnloadEvent()
    1612 {
    1613     return m_framesHandlingBeforeUnloadEvent;
     1600void Page::forbidPrompts()
     1601{
     1602    ++m_forbidPromptsDepth;
     1603}
     1604
     1605void Page::allowPrompts()
     1606{
     1607    ASSERT(m_forbidPromptsDepth);
     1608    --m_forbidPromptsDepth;
     1609}
     1610
     1611bool Page::arePromptsAllowed()
     1612{
     1613    return !m_forbidPromptsDepth;
    16141614}
    16151615
  • branches/safari-601-branch/Source/WebCore/page/Page.h

    r187421 r194077  
    410410#endif
    411411
    412     void incrementFrameHandlingBeforeUnloadEventCount();
    413     void decrementFrameHandlingBeforeUnloadEventCount();
    414     bool isAnyFrameHandlingBeforeUnloadEvent();
     412    void forbidPrompts();
     413    void allowPrompts();
     414    bool arePromptsAllowed();
     415
    415416    void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
    416417    unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
     
    607608
    608609    unsigned m_lastSpatialNavigationCandidatesCount;
    609     unsigned m_framesHandlingBeforeUnloadEvent;
     610    unsigned m_forbidPromptsDepth;
    610611
    611612    Ref<ApplicationCacheStorage> m_applicationCacheStorage;
Note: See TracChangeset for help on using the changeset viewer.