Title: [210856] branches/safari-603-branch/Source

Diff

Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (210855 => 210856)


--- branches/safari-603-branch/Source/WebCore/ChangeLog	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog	2017-01-18 19:09:13 UTC (rev 210856)
@@ -1,3 +1,42 @@
+2017-01-18  Matthew Hanson  <matthew_han...@apple.com>
+
+        Merge r210822. rdar://problem/15607819
+
+    2017-01-17  Joseph Pecoraro  <pecor...@apple.com>
+
+            Crash when closing tab with debugger paused
+            https://bugs.webkit.org/show_bug.cgi?id=161746
+            <rdar://problem/15607819>
+
+            Reviewed by Brian Burg and Brent Fulgham.
+
+            * page/Page.h:
+            (WebCore::Page::incrementNestedRunLoopCount):
+            (WebCore::Page::decrementNestedRunLoopCount):
+            (WebCore::Page::insideNestedRunLoop):
+            Keep track of whether or not this Page is inside of a nested run loop.
+            Currently the only nested run loop we know about is EventLoop used
+            by Web Inspector when debugging _javascript_.
+
+            (WebCore::Page::whenUnnested):
+            Callback that can be called when we are no longer inside of a nested
+            run loop.
+
+            (WebCore::Page::~Page):
+            Ensure we are not in a known nested run loop when destructing, since
+            that could be unsafe.
+
+            * inspector/PageScriptDebugServer.cpp:
+            (WebCore::PageScriptDebugServer::runEventLoopWhilePausedInternal):
+            Increment and decrement as we go into or leave the nested runloop.
+
+            * inspector/InspectorController.cpp:
+            (WebCore::InspectorController::inspectedPageDestroyed):
+            (WebCore::InspectorController::disconnectAllFrontends):
+            Rework destruction to allow disconnectAllFrontends to happen earlier
+            if necessary. WebKit clients may use this to disconnect remote
+            frontends when closing a Page.
+
 2017-01-12  Matthew Hanson  <matthew_han...@apple.com>
 
         Merge r210447. rdar://problem/29872292

Modified: branches/safari-603-branch/Source/WebCore/inspector/InspectorController.cpp (210855 => 210856)


--- branches/safari-603-branch/Source/WebCore/inspector/InspectorController.cpp	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebCore/inspector/InspectorController.cpp	2017-01-18 19:09:13 UTC (rev 210856)
@@ -203,16 +203,13 @@
 {
     m_injectedScriptManager->disconnect();
 
-    // If the local frontend page was destroyed, close the window.
-    if (m_inspectorFrontendClient)
-        m_inspectorFrontendClient->closeWindow();
-
-    // The frontend should call setInspectorFrontendClient(nullptr) under closeWindow().
-    ASSERT(!m_inspectorFrontendClient);
-
     // Clean up resources and disconnect local and remote frontends.
     disconnectAllFrontends();
 
+    // Disconnect the client.
+    m_inspectorClient->inspectedPageDestroyed();
+    m_inspectorClient = nullptr;
+
     m_agents.discardValues();
 }
 
@@ -300,9 +297,16 @@
 
 void InspectorController::disconnectAllFrontends()
 {
-    // The local frontend client should be disconnected already.
+    // If the local frontend page was destroyed, close the window.
+    if (m_inspectorFrontendClient)
+        m_inspectorFrontendClient->closeWindow();
+
+    // The frontend should call setInspectorFrontendClient(nullptr) under closeWindow().
     ASSERT(!m_inspectorFrontendClient);
 
+    if (!m_frontendRouter->hasFrontends())
+        return;
+
     for (unsigned i = 0; i < m_frontendRouter->frontendCount(); ++i)
         InspectorInstrumentation::frontendDeleted();
 
@@ -315,10 +319,6 @@
     // Destroy the inspector overlay's page.
     m_overlay->freePage();
 
-    // Disconnect local WK2 frontend and destroy the client.
-    m_inspectorClient->inspectedPageDestroyed();
-    m_inspectorClient = nullptr;
-
     // Disconnect any remaining remote frontends.
     m_frontendRouter->disconnectAllFrontends();
     m_isAutomaticInspection = false;

Modified: branches/safari-603-branch/Source/WebCore/inspector/PageScriptDebugServer.cpp (210855 => 210856)


--- branches/safari-603-branch/Source/WebCore/inspector/PageScriptDebugServer.cpp	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebCore/inspector/PageScriptDebugServer.cpp	2017-01-18 19:09:13 UTC (rev 210856)
@@ -114,9 +114,13 @@
 {
     TimerBase::fireTimersInNestedEventLoop();
 
+    m_page.incrementNestedRunLoopCount();
+
     EventLoop loop;
     while (!m_doneProcessingDebuggerEvents && !loop.ended())
         loop.cycle();
+
+    m_page.decrementNestedRunLoopCount();
 }
 
 bool PageScriptDebugServer::isContentScript(ExecState* exec) const

Modified: branches/safari-603-branch/Source/WebCore/page/Page.cpp (210855 => 210856)


--- branches/safari-603-branch/Source/WebCore/page/Page.cpp	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebCore/page/Page.cpp	2017-01-18 19:09:13 UTC (rev 210856)
@@ -189,7 +189,6 @@
     , m_plugInClient(pageConfiguration.plugInClient)
     , m_validationMessageClient(WTFMove(pageConfiguration.validationMessageClient))
     , m_diagnosticLoggingClient(WTFMove(pageConfiguration.diagnosticLoggingClient))
-    , m_subframeCount(0)
     , m_openedByDOM(false)
     , m_tabKeyCyclesThroughElements(true)
     , m_defersLoading(false)
@@ -275,6 +274,9 @@
 
 Page::~Page()
 {
+    ASSERT(!m_nestedRunLoopCount);
+    ASSERT(!m_unnestCallback);
+
     m_validationMessageClient = nullptr;
     m_diagnosticLoggingClient = nullptr;
     m_mainFrame->setView(nullptr);
@@ -1580,6 +1582,41 @@
 }
 #endif
 
+void Page::incrementNestedRunLoopCount()
+{
+    m_nestedRunLoopCount++;
+}
+
+void Page::decrementNestedRunLoopCount()
+{
+    ASSERT(m_nestedRunLoopCount);
+    if (m_nestedRunLoopCount <= 0)
+        return;
+
+    m_nestedRunLoopCount--;
+
+    if (!m_nestedRunLoopCount && m_unnestCallback) {
+        callOnMainThread([this] {
+            if (insideNestedRunLoop())
+                return;
+
+            // This callback may destruct the Page.
+            if (m_unnestCallback) {
+                auto callback = m_unnestCallback;
+                m_unnestCallback = nullptr;
+                callback();
+            }
+        });
+    }
+}
+
+void Page::whenUnnested(std::function<void()> callback)
+{
+    ASSERT(!m_unnestCallback);
+
+    m_unnestCallback = callback;
+}
+
 #if ENABLE(REMOTE_INSPECTOR)
 bool Page::remoteInspectionAllowed() const
 {

Modified: branches/safari-603-branch/Source/WebCore/page/Page.h (210855 => 210856)


--- branches/safari-603-branch/Source/WebCore/page/Page.h	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebCore/page/Page.h	2017-01-18 19:09:13 UTC (rev 210856)
@@ -190,6 +190,11 @@
     void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
     int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
 
+    void incrementNestedRunLoopCount();
+    void decrementNestedRunLoopCount();
+    bool insideNestedRunLoop() const { return m_nestedRunLoopCount > 0; }
+    WEBCORE_EXPORT void whenUnnested(std::function<void()>);
+
 #if ENABLE(REMOTE_INSPECTOR)
     WEBCORE_EXPORT bool remoteInspectionAllowed() const;
     WEBCORE_EXPORT void setRemoteInspectionAllowed(bool);
@@ -612,7 +617,10 @@
     std::unique_ptr<ValidationMessageClient> m_validationMessageClient;
     std::unique_ptr<DiagnosticLoggingClient> m_diagnosticLoggingClient;
 
-    int m_subframeCount;
+    int m_nestedRunLoopCount { 0 };
+    std::function<void()> m_unnestCallback;
+
+    int m_subframeCount { 0 };
     String m_groupName;
     bool m_openedByDOM;
 

Modified: branches/safari-603-branch/Source/WebKit/mac/ChangeLog (210855 => 210856)


--- branches/safari-603-branch/Source/WebKit/mac/ChangeLog	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebKit/mac/ChangeLog	2017-01-18 19:09:13 UTC (rev 210856)
@@ -1,3 +1,22 @@
+2017-01-18  Matthew Hanson  <matthew_han...@apple.com>
+
+        Merge r210822. rdar://problem/15607819
+
+    2017-01-17  Joseph Pecoraro  <pecor...@apple.com>
+
+            Crash when closing tab with debugger paused
+            https://bugs.webkit.org/show_bug.cgi?id=161746
+            <rdar://problem/15607819>
+
+            Reviewed by Brian Burg and Brent Fulgham.
+
+            * WebView/WebView.mm:
+            (WebKit::DeferredPageDestructor::createDeferredPageDestructor):
+            (WebKit::DeferredPageDestructor::DeferredPageDestructor):
+            (WebKit::DeferredPageDestructor::tryDestruction):
+            (-[WebView _close]):
+            Defer destruction of the Page if we are in a nested runloop.
+
 2017-01-12  Matthew Hanson  <matthew_han...@apple.com>
 
         Merge r210689. rdar://problem/29985957

Modified: branches/safari-603-branch/Source/WebKit/mac/WebView/WebView.mm (210855 => 210856)


--- branches/safari-603-branch/Source/WebKit/mac/WebView/WebView.mm	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebKit/mac/WebView/WebView.mm	2017-01-18 19:09:13 UTC (rev 210856)
@@ -582,6 +582,38 @@
     return WebPageVisibilityStateVisible;
 }
 
+namespace WebKit {
+
+class DeferredPageDestructor {
+public:
+    static void createDeferredPageDestructor(std::unique_ptr<Page> page)
+    {
+        new DeferredPageDestructor(WTFMove(page));
+    }
+
+private:
+    DeferredPageDestructor(std::unique_ptr<Page> page)
+        : m_page(WTFMove(page))
+    {
+        tryDestruction();
+    }
+
+    void tryDestruction()
+    {
+        if (m_page->insideNestedRunLoop()) {
+            m_page->whenUnnested([this] { tryDestruction(); });
+            return;
+        }
+
+        m_page = nullptr;
+        delete this;
+    }
+
+    std::unique_ptr<Page> m_page;
+};
+
+} // namespace WebKit
+
 @interface WebView (WebFileInternal)
 #if !PLATFORM(IOS)
 - (float)_deviceScaleFactor;
@@ -2148,8 +2180,8 @@
     // all the plug-ins in the page cache to break any retain cycles.
     // See comment in HistoryItem::releaseAllPendingPageCaches() for more information.
     Page* page = _private->page;
-    _private->page = 0;
-    delete page;
+    _private->page = nullptr;
+    WebKit::DeferredPageDestructor::createDeferredPageDestructor(std::unique_ptr<Page>(page));
 
 #if !PLATFORM(IOS)
     if (_private->hasSpellCheckerDocumentTag) {

Modified: branches/safari-603-branch/Source/WebKit2/ChangeLog (210855 => 210856)


--- branches/safari-603-branch/Source/WebKit2/ChangeLog	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebKit2/ChangeLog	2017-01-18 19:09:13 UTC (rev 210856)
@@ -1,3 +1,29 @@
+2017-01-18  Matthew Hanson  <matthew_han...@apple.com>
+
+        Merge r210822. rdar://problem/15607819
+
+    2017-01-17  Joseph Pecoraro  <pecor...@apple.com>
+
+            Crash when closing tab with debugger paused
+            https://bugs.webkit.org/show_bug.cgi?id=161746
+            <rdar://problem/15607819>
+
+            Reviewed by Brian Burg and Brent Fulgham.
+
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::DeferredPageDestructor::createDeferredPageDestructor):
+            (WebKit::DeferredPageDestructor::DeferredPageDestructor):
+            (WebKit::DeferredPageDestructor::tryDestruction):
+            (WebKit::WebPage::close):
+            Defer destruction of the Page and WebPage if we are in a nested runloop.
+            Also, proactively close all inspector frontends, including remote frontends.
+
+            * WebProcess/WebPage/ios/WebPageIOS.mm:
+            (WebKit::WebPage::handleSyntheticClick):
+            (WebKit::WebPage::completeSyntheticClick):
+            Return early in some cases where a nested run loop may have closed
+            the WebPage on us while handling _javascript_ events.
+
 2017-01-13  Matthew Hanson  <matthew_han...@apple.com>
 
         Rollout r210726. rdar://problem/29428877

Modified: branches/safari-603-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (210855 => 210856)


--- branches/safari-603-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2017-01-18 19:09:13 UTC (rev 210856)
@@ -144,6 +144,7 @@
 #include <WebCore/HistoryController.h>
 #include <WebCore/HistoryItem.h>
 #include <WebCore/HitTestResult.h>
+#include <WebCore/InspectorController.h>
 #include <WebCore/JSDOMWindow.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/MIMETypeRegistry.h>
@@ -278,6 +279,37 @@
     WebPage* m_page;
 };
 
+class DeferredPageDestructor {
+public:
+    static void createDeferredPageDestructor(std::unique_ptr<Page> page, WebPage* webPage)
+    {
+        new DeferredPageDestructor(WTFMove(page), webPage);
+    }
+
+private:
+    DeferredPageDestructor(std::unique_ptr<Page> page, WebPage* webPage)
+        : m_page(WTFMove(page))
+        , m_webPage(webPage)
+    {
+        tryDestruction();
+    }
+
+    void tryDestruction()
+    {
+        if (m_page->insideNestedRunLoop()) {
+            m_page->whenUnnested([this] { tryDestruction(); });
+            return;
+        }
+
+        m_page = nullptr;
+        m_webPage = nullptr;
+        delete this;
+    }
+
+    std::unique_ptr<Page> m_page;
+    RefPtr<WebPage> m_webPage;
+};
+
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webPageCounter, ("WebPage"));
 
 Ref<WebPage> WebPage::create(uint64_t pageID, const WebPageCreationParameters& parameters)
@@ -1023,6 +1055,8 @@
         m_inspector = nullptr;
     }
 
+    m_page->inspectorController().disconnectAllFrontends();
+
 #if ENABLE(FULLSCREEN_API)
     m_fullScreenManager = nullptr;
 #endif
@@ -1080,9 +1114,10 @@
 
     m_printContext = nullptr;
     m_mainFrame->coreFrame()->loader().detachFromParent();
-    m_page = nullptr;
     m_drawingArea = nullptr;
 
+    DeferredPageDestructor::createDeferredPageDestructor(WTFMove(m_page), this);
+
     bool isRunningModal = m_isRunningModal;
     m_isRunningModal = false;
 
@@ -2398,7 +2433,6 @@
     bool handled = handleGestureEvent(gestureEvent, m_page.get());
     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(gestureEvent.type()), handled));
 }
-
 #endif
 
 bool WebPage::scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)

Modified: branches/safari-603-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (210855 => 210856)


--- branches/safari-603-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2017-01-18 18:45:59 UTC (rev 210855)
+++ branches/safari-603-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2017-01-18 19:09:13 UTC (rev 210856)
@@ -535,6 +535,9 @@
     m_pendingSyntheticClickNode = nullptr;
     m_pendingSyntheticClickLocation = FloatPoint();
 
+    if (m_isClosed)
+        return;
+
     switch (WKObservedContentChange()) {
     case WKContentVisibilityChange:
         // The move event caused new contents to appear. Don't send the click event.
@@ -570,12 +573,19 @@
 
     RefPtr<Frame> oldFocusedFrame = m_page->focusController().focusedFrame();
     RefPtr<Element> oldFocusedElement = oldFocusedFrame ? oldFocusedFrame->document()->focusedElement() : nullptr;
-    m_userIsInteracting = true;
 
+    SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true };
+
     bool tapWasHandled = false;
     m_lastInteractionLocation = roundedAdjustedPoint;
+
     tapWasHandled |= mainframe.eventHandler().handleMousePressEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MousePressed, 1, false, false, false, false, currentTime(), WebCore::ForceAtClick, syntheticClickType));
+    if (m_isClosed)
+        return;
+
     tapWasHandled |= mainframe.eventHandler().handleMouseReleaseEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MouseReleased, 1, false, false, false, false, currentTime(), WebCore::ForceAtClick, syntheticClickType));
+    if (m_isClosed)
+        return;
 
     RefPtr<Frame> newFocusedFrame = m_page->focusController().focusedFrame();
     RefPtr<Element> newFocusedElement = newFocusedFrame ? newFocusedFrame->document()->focusedElement() : nullptr;
@@ -587,8 +597,6 @@
     if (newFocusedElement && newFocusedElement == oldFocusedElement)
         elementDidFocus(newFocusedElement.get());
 
-    m_userIsInteracting = false;
-
     if (!tapWasHandled || !nodeRespondingToClick || !nodeRespondingToClick->isElementNode())
         send(Messages::WebPageProxy::DidNotHandleTapAsClick(roundedIntPoint(location)));
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to