<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189970] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189970">189970</a></dd>
<dt>Author</dt> <dd>bburg@apple.com</dd>
<dt>Date</dt> <dd>2015-09-18 10:16:24 -0700 (Fri, 18 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
https://bugs.webkit.org/show_bug.cgi?id=149006
Source/JavaScriptCore:

Reviewed by Joseph Pecoraro.

Prior to disconnecting, we need to know how many frontends remain connected.

* inspector/InspectorFrontendRouter.h: Add frontendCount().

Source/WebCore:

Reviewed by Joseph Pecoraro.

The patch fixes two defects:

    (1) the stub inspector frontend is not closed reliably when a test times out
    (2) frontend clients and channels are sometimes connected to the wrong controllers

When an inspector test times out, the test runner requests (via the inspected page's controller)
that the inspector close. But, the stub frontend works independently of InspectorClient,
so the inspected page's InspectorController cannot close the stub frontend. The assertion
failed because the stub frontend's channel was still connected to the inspected page's controller.

The fix is to route requests for the inspector window to close through the FrontendClient's
closeWindow() method rather than InspectorClient, so that the stub frontend can react.
The other code paths (i.e., through close() and closeLocalFrontend()) have been removed.

Now that the stub frontend eagerly closes its channel before the Page gets GC'd, several
methods invoked during test teardown must be reordered to avoid using dangling pointers.

The stub frontend in Internals has been rewritten to properly disconnect itself
from both the frontend and inspected page's inspector controllers.

While fixing this bug, I noticed that we are inconsistent about which inspector controller
(the inspected page's or the frontend page's) receives the FrontendClient and which takes
FrontendChannels. It is now the case for all configurations that the FrontendClient is
connected to the frontend page's inspector controller, and FrontendChannels are connected
to the inspected page's inspector controller. In the WK2 case, the Inspector Process
has an attached frontend client, and its inspected Web Process has frontend channels.

No new tests, covered by existing tests.

* inspector/InspectorClient.h:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::~InspectorController):
(WebCore::InspectorController::inspectedPageDestroyed):

    This method is called from Page::~Page, so we should disconnect all frontends now
    before subframes are detached from the page, making InspectorController inaccessible.

(WebCore::InspectorController::disconnectFrontend):

    The teardown branch was never being run before, because we never disconnected the
    frontend's channel correctly. Some agents use the overlay during teardown, so notify
    agents before releasing the overlay page.

(WebCore::InspectorController::disconnectAllFrontends):

    The actions from close() are inlined and rearranged here, similar to disconnectFrontend.
    We have to notify agents before removing InspectorClient as some agents make use of it.

(WebCore::InspectorController::close): Deleted.
(WebCore::InspectorController::show): This assertion is vacuously true now.
* inspector/InspectorFrontendClientLocal.cpp:
(WebCore::InspectorFrontendClientLocal::inspectedPage): Added. Used by stub frontend.
* inspector/InspectorFrontendClientLocal.h:
(WebCore::InspectorFrontendClientLocal::frontendPage): Added.
* loader/EmptyClients.h:
* page/Page.cpp:
(WebCore::Page::~Page):

    Notify inspector before detaching frames, otherwise it will not be possible to
    cleanly disconnect the stub frontend's channel.

* testing/Internals.cpp:

    Rewrite the stub frontend to better encapsulate its setup and teardown logic.

(WebCore::InspectorStubFrontend::frontendPage): Added.
(WebCore::InspectorStubFrontend::InspectorStubFrontend): Added.
(WebCore::InspectorStubFrontend::~InspectorStubFrontend): Added.
(WebCore::InspectorStubFrontend::closeWindow): Added.
(WebCore::InspectorStubFrontend::sendMessageToFrontend): Added.
(WebCore::Internals::openDummyInspectorFrontend):
(WebCore::Internals::closeDummyInspectorFrontend):
(WebCore::InspectorFrontendClientDummy::~InspectorFrontendClientDummy): Deleted.
(WebCore::InspectorFrontendClientDummy::InspectorFrontendClientDummy): Deleted.
(WebCore::InspectorFrontendChannelDummy::~InspectorFrontendChannelDummy): Deleted.
(WebCore::InspectorFrontendChannelDummy::InspectorFrontendChannelDummy): Deleted.
(WebCore::InspectorFrontendChannelDummy::sendMessageToFrontend): Deleted.
* testing/Internals.h:

Source/WebKit/ios:

Reviewed by Joseph Pecoraro.

* WebCoreSupport/WebInspectorClientIOS.mm:
(WebInspectorClient::closeLocalFrontend): Deleted.
(WebInspectorFrontendClient::disconnectFromBackend): Deleted.

Source/WebKit/mac:

Reviewed by Joseph Pecoraro.

WK1 WebInspectorClient was connecting to the wrong controllers. Fix this, and
remove extra code paths for closing the frontend.

* WebCoreSupport/WebInspectorClient.h:
* WebCoreSupport/WebInspectorClient.mm:
(-[WebInspectorWindowController destroyInspectorView]):

    Disconnect the FrontendClient from the frontend page's inspector controller.
    Do this teardown before releasing the frontend, otherwise we can't use it.

(WebInspectorClient::inspectedPageDestroyed): Deleted.
(WebInspectorClient::closeLocalFrontend): Deleted.
(WebInspectorFrontendClient::disconnectFromBackend): Deleted.
* WebInspector/WebInspector.mm:
(-[WebInspector inspectedWebViewClosed]):

    Make sure to close ourself if the inspected page closes.

(-[WebInspector close:]):

    Go through the frontend instead of InspectorController.

* WebInspector/WebInspectorFrontend.h:
* WebInspector/WebInspectorFrontend.mm:
(-[WebInspectorFrontend close]):

Source/WebKit/win:

Reviewed by Joseph Pecoraro.

* WebCoreSupport/WebInspectorClient.cpp:
(WebInspectorFrontendClient::destroyInspectorView):

    Disconnect the FrontendClient from the frontend page's inspector controller.
    Do this teardown before releasing the frontend, otherwise we can't use it.

(WebInspectorFrontendClient::onClose):
(WebInspectorClient::inspectedPageDestroyed): Deleted.
(WebInspectorClient::closeLocalFrontend): Deleted.
* WebCoreSupport/WebInspectorClient.h: Drive-by cleanup for class declarations.
* WebInspector.cpp:
(WebInspector::close):

    Go through the frontend instead of InspectorController.

Source/WebKit2:

&lt;rdar://problem/22654257&gt;
&lt;rdar://problem/22631369&gt;

Reviewed by Joseph Pecoraro.

Stop using InspectorController to close the frontend page. Go through
the FrontendClient instead. Reduce redundant code paths.

This change seems to fix some recent crashes that were seen when
closing Safari with Web Inspector open. These were caused by the frontend
channel not being disconnected at the right time.

* WebProcess/WebCoreSupport/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::inspectedPageDestroyed):
(WebKit::WebInspectorClient::closeLocalFrontend): Deleted.
* WebProcess/WebCoreSupport/WebInspectorClient.h:
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::close):
* WebProcess/WebPage/WebInspectorUI.cpp:
(WebKit::WebInspectorUI::establishConnection):

    Save a pointer to the frontend's InspectorController since we may
    need to use it while the page is being destructed and its getter
    is no longer accessible.

(WebKit::WebInspectorUI::closeWindow):

    Explicitly remove the frontend client when closing the frontend.

* WebProcess/WebPage/WebInspectorUI.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::inspector):

    Allow clients to specify whether an inspector should be eagerly created.
    Without this, we may accidentally create an instance during teardown.

* WebProcess/WebPage/WebPage.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInspectorFrontendRouterh">trunk/Source/JavaScriptCore/inspector/InspectorFrontendRouter.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorClienth">trunk/Source/WebCore/inspector/InspectorClient.h</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorControllercpp">trunk/Source/WebCore/inspector/InspectorController.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorControllerh">trunk/Source/WebCore/inspector/InspectorController.h</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorFrontendClientLocalcpp">trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorFrontendClientLocalh">trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h</a></li>
<li><a href="#trunkSourceWebCoreloaderEmptyClientsh">trunk/Source/WebCore/loader/EmptyClients.h</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebKitiosChangeLog">trunk/Source/WebKit/ios/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitiosWebCoreSupportWebInspectorClientIOSmm">trunk/Source/WebKit/ios/WebCoreSupport/WebInspectorClientIOS.mm</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebInspectorClienth">trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebInspectorClientmm">trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebInspectorWebInspectormm">trunk/Source/WebKit/mac/WebInspector/WebInspector.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebInspectorWebInspectorFrontendh">trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.h</a></li>
<li><a href="#trunkSourceWebKitmacWebInspectorWebInspectorFrontendmm">trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.mm</a></li>
<li><a href="#trunkSourceWebKitwinChangeLog">trunk/Source/WebKit/win/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitwinWebCoreSupportWebInspectorClientcpp">trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.cpp</a></li>
<li><a href="#trunkSourceWebKitwinWebCoreSupportWebInspectorClienth">trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.h</a></li>
<li><a href="#trunkSourceWebKitwinWebInspectorcpp">trunk/Source/WebKit/win/WebInspector.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebInspectorClientcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebInspectorClienth">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebInspectorcpp">trunk/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebInspectorUIcpp">trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebInspectorUIh">trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-09-17  Brian Burg  &lt;bburg@apple.com&gt;
+
+        ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
+        https://bugs.webkit.org/show_bug.cgi?id=149006
+
+        Reviewed by Joseph Pecoraro.
+
+        Prior to disconnecting, we need to know how many frontends remain connected.
+
+        * inspector/InspectorFrontendRouter.h: Add frontendCount().
+
</ins><span class="cx"> 2015-09-18  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Explicitly specify builtin JS files dependency
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInspectorFrontendRouterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InspectorFrontendRouter.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InspectorFrontendRouter.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/JavaScriptCore/inspector/InspectorFrontendRouter.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -41,6 +41,8 @@
</span><span class="cx">     bool hasLocalFrontend() const;
</span><span class="cx">     bool hasRemoteFrontend() const;
</span><span class="cx"> 
</span><ins>+    unsigned frontendCount() const { return m_connections.size(); }
+
</ins><span class="cx">     void connectFrontend(FrontendChannel*);
</span><span class="cx">     void disconnectFrontend(FrontendChannel*);
</span><span class="cx">     void disconnectAllFrontends();
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/ChangeLog        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,3 +1,89 @@
</span><ins>+2015-09-17  Brian Burg  &lt;bburg@apple.com&gt;
+
+        ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
+        https://bugs.webkit.org/show_bug.cgi?id=149006
+
+        Reviewed by Joseph Pecoraro.
+
+        The patch fixes two defects:
+
+            (1) the stub inspector frontend is not closed reliably when a test times out
+            (2) frontend clients and channels are sometimes connected to the wrong controllers
+
+        When an inspector test times out, the test runner requests (via the inspected page's controller)
+        that the inspector close. But, the stub frontend works independently of InspectorClient,
+        so the inspected page's InspectorController cannot close the stub frontend. The assertion
+        failed because the stub frontend's channel was still connected to the inspected page's controller.
+
+        The fix is to route requests for the inspector window to close through the FrontendClient's
+        closeWindow() method rather than InspectorClient, so that the stub frontend can react.
+        The other code paths (i.e., through close() and closeLocalFrontend()) have been removed.
+
+        Now that the stub frontend eagerly closes its channel before the Page gets GC'd, several
+        methods invoked during test teardown must be reordered to avoid using dangling pointers.
+
+        The stub frontend in Internals has been rewritten to properly disconnect itself
+        from both the frontend and inspected page's inspector controllers.
+
+        While fixing this bug, I noticed that we are inconsistent about which inspector controller
+        (the inspected page's or the frontend page's) receives the FrontendClient and which takes
+        FrontendChannels. It is now the case for all configurations that the FrontendClient is
+        connected to the frontend page's inspector controller, and FrontendChannels are connected
+        to the inspected page's inspector controller. In the WK2 case, the Inspector Process
+        has an attached frontend client, and its inspected Web Process has frontend channels.
+
+        No new tests, covered by existing tests.
+
+        * inspector/InspectorClient.h:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::~InspectorController):
+        (WebCore::InspectorController::inspectedPageDestroyed):
+
+            This method is called from Page::~Page, so we should disconnect all frontends now
+            before subframes are detached from the page, making InspectorController inaccessible.
+
+        (WebCore::InspectorController::disconnectFrontend):
+
+            The teardown branch was never being run before, because we never disconnected the
+            frontend's channel correctly. Some agents use the overlay during teardown, so notify
+            agents before releasing the overlay page.
+
+        (WebCore::InspectorController::disconnectAllFrontends):
+
+            The actions from close() are inlined and rearranged here, similar to disconnectFrontend.
+            We have to notify agents before removing InspectorClient as some agents make use of it.
+
+        (WebCore::InspectorController::close): Deleted.
+        (WebCore::InspectorController::show): This assertion is vacuously true now.
+        * inspector/InspectorFrontendClientLocal.cpp:
+        (WebCore::InspectorFrontendClientLocal::inspectedPage): Added. Used by stub frontend.
+        * inspector/InspectorFrontendClientLocal.h:
+        (WebCore::InspectorFrontendClientLocal::frontendPage): Added.
+        * loader/EmptyClients.h:
+        * page/Page.cpp:
+        (WebCore::Page::~Page):
+
+            Notify inspector before detaching frames, otherwise it will not be possible to
+            cleanly disconnect the stub frontend's channel.
+
+        * testing/Internals.cpp:
+
+            Rewrite the stub frontend to better encapsulate its setup and teardown logic.
+
+        (WebCore::InspectorStubFrontend::frontendPage): Added.
+        (WebCore::InspectorStubFrontend::InspectorStubFrontend): Added.
+        (WebCore::InspectorStubFrontend::~InspectorStubFrontend): Added.
+        (WebCore::InspectorStubFrontend::closeWindow): Added.
+        (WebCore::InspectorStubFrontend::sendMessageToFrontend): Added.
+        (WebCore::Internals::openDummyInspectorFrontend):
+        (WebCore::Internals::closeDummyInspectorFrontend):
+        (WebCore::InspectorFrontendClientDummy::~InspectorFrontendClientDummy): Deleted.
+        (WebCore::InspectorFrontendClientDummy::InspectorFrontendClientDummy): Deleted.
+        (WebCore::InspectorFrontendChannelDummy::~InspectorFrontendChannelDummy): Deleted.
+        (WebCore::InspectorFrontendChannelDummy::InspectorFrontendChannelDummy): Deleted.
+        (WebCore::InspectorFrontendChannelDummy::sendMessageToFrontend): Deleted.
+        * testing/Internals.h:
+
</ins><span class="cx"> 2015-09-18  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         classList.toggle(name, force) treats undefined `force` argument as false
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorClient.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorClient.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/inspector/InspectorClient.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2007 Apple Inc.  All rights reserved.
</del><ins>+ * Copyright (C) 2007, 2015 Apple Inc.  All rights reserved.
</ins><span class="cx">  * Copyright (C) 2011 Google Inc.  All rights reserved.
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -49,7 +49,6 @@
</span><span class="cx">     virtual void inspectedPageDestroyed() = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual Inspector::FrontendChannel* openLocalFrontend(InspectorController*) = 0;
</span><del>-    virtual void closeLocalFrontend() = 0;
</del><span class="cx">     virtual void bringFrontendToFront() = 0;
</span><span class="cx">     virtual void didResizeMainFrame(Frame*) { }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorController.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -196,11 +196,17 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorController::inspectedPageDestroyed()
</span><span class="cx"> {
</span><ins>+    m_injectedScriptManager-&gt;disconnect();
+
+    // If the local frontend page was destroyed, close the window.
+    if (m_inspectorFrontendClient)
+        m_inspectorFrontendClient-&gt;closeWindow();
+
+    // The frontend should call setInspectorFrontendClient(nullptr) under closeWindow().
+    ASSERT(!m_inspectorFrontendClient);
+
+    // Clean up resources and disconnect local and remote frontends.
</ins><span class="cx">     disconnectAllFrontends();
</span><del>-
-    m_injectedScriptManager-&gt;disconnect();
-    m_inspectorClient-&gt;inspectedPageDestroyed();
-    m_inspectorClient = nullptr;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorController::setInspectorFrontendClient(InspectorFrontendClient* inspectorFrontendClient)
</span><span class="lines">@@ -262,9 +268,6 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorController::disconnectFrontend(FrontendChannel* frontendChannel)
</span><span class="cx"> {
</span><del>-    // The local frontend client should be disconnected first so it stops sending messages.
-    ASSERT(!m_frontendRouter-&gt;hasLocalFrontend() || !m_inspectorFrontendClient);
-
</del><span class="cx">     m_frontendRouter-&gt;disconnectFrontend(frontendChannel);
</span><span class="cx">     m_isAutomaticInspection = false;
</span><span class="cx"> 
</span><span class="lines">@@ -272,9 +275,13 @@
</span><span class="cx"> 
</span><span class="cx">     bool disconnectedLastFrontend = !m_frontendRouter-&gt;hasFrontends();
</span><span class="cx">     if (disconnectedLastFrontend) {
</span><del>-        // Release overlay page resources.
</del><ins>+        // Notify agents first.
+        m_agents.willDestroyFrontendAndBackend(DisconnectReason::InspectorDestroyed);
+
+        // Destroy the inspector overlay's page.
</ins><span class="cx">         m_overlay-&gt;freePage();
</span><del>-        m_agents.willDestroyFrontendAndBackend(DisconnectReason::InspectorDestroyed);
</del><ins>+
+        // Unplug all instrumentations since they aren't needed now.
</ins><span class="cx">         InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgents.get());
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -286,22 +293,29 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorController::disconnectAllFrontends()
</span><span class="cx"> {
</span><del>-    // The local frontend client should be disconnected first so it stops sending messages.
-    ASSERT(!m_frontendRouter-&gt;hasLocalFrontend() || !m_inspectorFrontendClient);
</del><ins>+    // The local frontend client should be disconnected already.
+    ASSERT(!m_inspectorFrontendClient);
</ins><span class="cx"> 
</span><ins>+    for (unsigned i = 0; i &lt; m_frontendRouter-&gt;frontendCount(); ++i)
+        InspectorInstrumentation::frontendDeleted();
+
+    // Unplug all instrumentations to prevent further agent callbacks.
+    InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgents.get());
+
+    // Notify agents first, since they may need to use InspectorClient.
</ins><span class="cx">     m_agents.willDestroyFrontendAndBackend(DisconnectReason::InspectedTargetDestroyed);
</span><span class="cx"> 
</span><ins>+    // Destroy the inspector overlay's page.
+    m_overlay-&gt;freePage();
+
+    // Disconnect local WK2 frontend and destroy the client.
+    m_inspectorClient-&gt;inspectedPageDestroyed();
+    m_inspectorClient = nullptr;
+
+    // Disconnect any remaining remote frontends.
</ins><span class="cx">     m_frontendRouter-&gt;disconnectAllFrontends();
</span><span class="cx">     m_isAutomaticInspection = false;
</span><span class="cx"> 
</span><del>-    // Release overlay page resources.
-    m_overlay-&gt;freePage();
-
-    while (InspectorInstrumentation::hasFrontends())
-        InspectorInstrumentation::frontendDeleted();
-
-    InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgents.get());
-    
</del><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="cx">     m_page.remoteInspectorInformationDidChange();
</span><span class="cx"> #endif
</span><span class="lines">@@ -311,9 +325,6 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!m_frontendRouter-&gt;hasRemoteFrontend());
</span><span class="cx"> 
</span><del>-    // The local frontend client should be disconnected if there's no local frontend.
-    ASSERT(m_frontendRouter-&gt;hasLocalFrontend() || !m_inspectorFrontendClient);
-
</del><span class="cx">     if (!enabled())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -323,14 +334,6 @@
</span><span class="cx">         connectFrontend(frontendChannel);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorController::close()
-{
-    if (m_frontendRouter-&gt;hasLocalFrontend())
-        m_inspectorClient-&gt;closeLocalFrontend();
-
-    ASSERT(!m_frontendRouter-&gt;hasLocalFrontend());
-}
-
</del><span class="cx"> void InspectorController::setProcessId(long processId)
</span><span class="cx"> {
</span><span class="cx">     IdentifiersFactory::setProcessId(processId);
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorController.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorController.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/inspector/InspectorController.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -88,7 +88,6 @@
</span><span class="cx">     Page&amp; inspectedPage() const;
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void show();
</span><del>-    WEBCORE_EXPORT void close();
</del><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void setInspectorFrontendClient(InspectorFrontendClient*);
</span><span class="cx">     bool hasInspectorFrontendClient() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorFrontendClientLocalcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2010 Google Inc. All rights reserved.
</span><ins>+ * Copyright (C) 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -370,4 +371,12 @@
</span><span class="cx">         m_evaluateOnLoad.append(expression);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Page* InspectorFrontendClientLocal::inspectedPage() const
+{
+    if (!m_inspectedPageController)
+        return nullptr;
+
+    return &amp;m_inspectedPageController-&gt;inspectedPage();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorFrontendClientLocalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2010 Google Inc. All rights reserved.
</span><ins>+ * Copyright (C) 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -104,6 +105,8 @@
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void setAttachedWindow(DockSide);
</span><span class="cx"> 
</span><ins>+    WEBCORE_EXPORT Page* inspectedPage() const;
+    Page* frontendPage() const { return m_frontendPage; }
</ins><span class="cx"> protected:
</span><span class="cx">     virtual void setAttachedWindowHeight(unsigned) = 0;
</span><span class="cx">     virtual void setAttachedWindowWidth(unsigned) = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderEmptyClientsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/EmptyClients.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/EmptyClients.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/loader/EmptyClients.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2006 Eric Seidel (eric@webkit.org)
</span><del>- * Copyright (C) 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2008-2012, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
</span><span class="cx">  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
</span><span class="cx">  *
</span><span class="lines">@@ -596,7 +596,6 @@
</span><span class="cx">     virtual void inspectedPageDestroyed() override { }
</span><span class="cx">     
</span><span class="cx">     virtual Inspector::FrontendChannel* openLocalFrontend(InspectorController*) override { return 0; }
</span><del>-    virtual void closeLocalFrontend() override { }
</del><span class="cx">     virtual void bringFrontendToFront() override { }
</span><span class="cx"> 
</span><span class="cx">     virtual void highlight() override { }
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/page/Page.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -253,6 +253,8 @@
</span><span class="cx">     
</span><span class="cx">     m_settings-&gt;pageDestroyed();
</span><span class="cx"> 
</span><ins>+    m_inspectorController-&gt;inspectedPageDestroyed();
+
</ins><span class="cx">     for (Frame* frame = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext()) {
</span><span class="cx">         frame-&gt;willDetachPage();
</span><span class="cx">         frame-&gt;detachFromPage();
</span><span class="lines">@@ -264,8 +266,6 @@
</span><span class="cx">     if (m_alternativeTextClient)
</span><span class="cx">         m_alternativeTextClient-&gt;pageDestroyed();
</span><span class="cx"> 
</span><del>-    m_inspectorController-&gt;inspectedPageDestroyed();
-
</del><span class="cx">     if (m_scrollingCoordinator)
</span><span class="cx">         m_scrollingCoordinator-&gt;pageDestroyed();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/testing/Internals.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -208,52 +208,77 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace HTMLNames;
</span><span class="cx"> 
</span><del>-class InspectorFrontendClientDummy : public InspectorFrontendClientLocal {
</del><ins>+class InspectorStubFrontend : public InspectorFrontendClientLocal, public FrontendChannel {
</ins><span class="cx"> public:
</span><del>-    InspectorFrontendClientDummy(InspectorController*, Page*);
-    virtual ~InspectorFrontendClientDummy() { }
</del><ins>+    InspectorStubFrontend(Page* inspectedPage, RefPtr&lt;DOMWindow&gt;&amp;&amp; frontendWindow);
+    virtual ~InspectorStubFrontend();
+
+    // InspectorFrontendClient API
</ins><span class="cx">     virtual void attachWindow(DockSide) override { }
</span><span class="cx">     virtual void detachWindow() override { }
</span><del>-
-    virtual String localizedStringsURL() override { return String(); }
-
</del><ins>+    virtual void closeWindow() override;
</ins><span class="cx">     virtual void bringToFront() override { }
</span><del>-    virtual void closeWindow() override { }
-
</del><ins>+    virtual String localizedStringsURL() override { return String(); }
</ins><span class="cx">     virtual void inspectedURLChanged(const String&amp;) override { }
</span><del>-
</del><span class="cx"> protected:
</span><span class="cx">     virtual void setAttachedWindowHeight(unsigned) override { }
</span><span class="cx">     virtual void setAttachedWindowWidth(unsigned) override { }
</span><span class="cx">     virtual void setToolbarHeight(unsigned) override { }
</span><del>-};
</del><span class="cx"> 
</span><del>-InspectorFrontendClientDummy::InspectorFrontendClientDummy(InspectorController* controller, Page* page)
-    : InspectorFrontendClientLocal(controller, page, std::make_unique&lt;InspectorFrontendClientLocal::Settings&gt;())
-{
-}
-
-class InspectorFrontendChannelDummy : public FrontendChannel {
</del><span class="cx"> public:
</span><del>-    explicit InspectorFrontendChannelDummy(Page*);
-    virtual ~InspectorFrontendChannelDummy() { }
</del><ins>+    // Inspector::FrontendChannel API
</ins><span class="cx">     virtual bool sendMessageToFrontend(const String&amp; message) override;
</span><span class="cx">     virtual ConnectionType connectionType() const override { return ConnectionType::Local; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    Page* m_frontendPage;
</del><ins>+    Page* frontendPage() const
+    {
+        if (!m_frontendWindow || !m_frontendWindow-&gt;document())
+            return nullptr;
+
+        return m_frontendWindow-&gt;document()-&gt;page();
+    }
+
+    RefPtr&lt;DOMWindow&gt; m_frontendWindow;
+    InspectorController&amp; m_frontendController;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><del>-InspectorFrontendChannelDummy::InspectorFrontendChannelDummy(Page* page)
-    : m_frontendPage(page)
</del><ins>+InspectorStubFrontend::InspectorStubFrontend(Page* inspectedPage, RefPtr&lt;DOMWindow&gt;&amp;&amp; frontendWindow)
+    : InspectorFrontendClientLocal(&amp;inspectedPage-&gt;inspectorController(), frontendWindow-&gt;document()-&gt;page(), std::make_unique&lt;InspectorFrontendClientLocal::Settings&gt;())
+    , m_frontendWindow(frontendWindow.copyRef())
+    , m_frontendController(frontendPage()-&gt;inspectorController())
</ins><span class="cx"> {
</span><ins>+    ASSERT_ARG(inspectedPage, inspectedPage);
+    ASSERT_ARG(frontendWindow, frontendWindow);
+
+    m_frontendController.setInspectorFrontendClient(this);
+    inspectedPage-&gt;inspectorController().connectFrontend(this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool InspectorFrontendChannelDummy::sendMessageToFrontend(const String&amp; message)
</del><ins>+InspectorStubFrontend::~InspectorStubFrontend()
</ins><span class="cx"> {
</span><del>-    return InspectorClient::doDispatchMessageOnFrontendPage(m_frontendPage, message);
</del><ins>+    closeWindow();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void InspectorStubFrontend::closeWindow()
+{
+    if (!m_frontendWindow)
+        return;
+
+    m_frontendController.setInspectorFrontendClient(nullptr);
+    inspectedPage()-&gt;inspectorController().disconnectFrontend(this);
+
+    m_frontendWindow-&gt;close(m_frontendWindow-&gt;scriptExecutionContext());
+    m_frontendWindow = nullptr;
+}
+
+bool InspectorStubFrontend::sendMessageToFrontend(const String&amp; message)
+{
+    ASSERT_ARG(message, !message.isEmpty());
+
+    return InspectorClient::doDispatchMessageOnFrontendPage(frontendPage(), message);
+}
+
</ins><span class="cx"> static bool markerTypesFrom(const String&amp; markerType, DocumentMarker::MarkerTypes&amp; result)
</span><span class="cx"> {
</span><span class="cx">     if (markerType.isEmpty() || equalIgnoringCase(markerType, &quot;all&quot;))
</span><span class="lines">@@ -1724,46 +1749,19 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;DOMWindow&gt; Internals::openDummyInspectorFrontend(const String&amp; url)
</del><ins>+RefPtr&lt;DOMWindow&gt; Internals::openDummyInspectorFrontend(const String&amp; url)
</ins><span class="cx"> {
</span><del>-    Page* page = contextDocument()-&gt;frame()-&gt;page();
-    ASSERT(page);
</del><ins>+    Page* inspectedPage = contextDocument()-&gt;frame()-&gt;page();
+    RefPtr&lt;DOMWindow&gt; window = inspectedPage-&gt;mainFrame().document()-&gt;domWindow();
+    RefPtr&lt;DOMWindow&gt; frontendWindow = window-&gt;open(url, &quot;&quot;, &quot;&quot;, *window, *window);
+    m_inspectorFrontend = std::make_unique&lt;InspectorStubFrontend&gt;(inspectedPage, frontendWindow.copyRef());
</ins><span class="cx"> 
</span><del>-    DOMWindow* window = page-&gt;mainFrame().document()-&gt;domWindow();
-    ASSERT(window);
-
-    m_frontendWindow = window-&gt;open(url, &quot;&quot;, &quot;&quot;, *window, *window);
-    ASSERT(m_frontendWindow);
-
-    Page* frontendPage = m_frontendWindow-&gt;document()-&gt;page();
-    ASSERT(frontendPage);
-
-    m_frontendClient = std::make_unique&lt;InspectorFrontendClientDummy&gt;(&amp;page-&gt;inspectorController(), frontendPage);
-    frontendPage-&gt;inspectorController().setInspectorFrontendClient(m_frontendClient.get());
-
-    m_frontendChannel = std::make_unique&lt;InspectorFrontendChannelDummy&gt;(frontendPage);
-    page-&gt;inspectorController().connectFrontend(m_frontendChannel.get());
-
-    return m_frontendWindow;
</del><ins>+    return WTF::move(frontendWindow);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Internals::closeDummyInspectorFrontend()
</span><span class="cx"> {
</span><del>-    Page* page = contextDocument()-&gt;frame()-&gt;page();
-    ASSERT(page);
-    ASSERT(m_frontendWindow);
-
-    Page* frontendPage = m_frontendWindow-&gt;document()-&gt;page();
-    ASSERT(frontendPage);
-
-    frontendPage-&gt;inspectorController().setInspectorFrontendClient(nullptr);
-    m_frontendClient = nullptr;
-
-    page-&gt;inspectorController().disconnectFrontend(m_frontendChannel.get());
-    m_frontendChannel = nullptr;
-
-    m_frontendWindow-&gt;close(m_frontendWindow-&gt;scriptExecutionContext());
-    m_frontendWindow = nullptr;
</del><ins>+    m_inspectorFrontend = nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Internals::setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&amp; ec)
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebCore/testing/Internals.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2012 Google Inc. All rights reserved.
</span><del>- * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -53,8 +53,7 @@
</span><span class="cx"> class File;
</span><span class="cx"> class Frame;
</span><span class="cx"> class HTMLMediaElement;
</span><del>-class InspectorFrontendChannelDummy;
-class InspectorFrontendClientDummy;
</del><ins>+class InspectorStubFrontend;
</ins><span class="cx"> class InternalSettings;
</span><span class="cx"> class MallocStatistics;
</span><span class="cx"> class MediaSession;
</span><span class="lines">@@ -265,7 +264,7 @@
</span><span class="cx">     unsigned numberOfLiveDocuments() const;
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;String&gt; consoleMessageArgumentCounts() const;
</span><del>-    PassRefPtr&lt;DOMWindow&gt; openDummyInspectorFrontend(const String&amp; url);
</del><ins>+    RefPtr&lt;DOMWindow&gt; openDummyInspectorFrontend(const String&amp; url);
</ins><span class="cx">     void closeDummyInspectorFrontend();
</span><span class="cx">     void setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&amp;);
</span><span class="cx">     void setInspectorIsUnderTest(bool isUnderTest, ExceptionCode&amp;);
</span><span class="lines">@@ -445,9 +444,7 @@
</span><span class="cx"> 
</span><span class="cx">     RenderedDocumentMarker* markerAt(Node*, const String&amp; markerType, unsigned index, ExceptionCode&amp;);
</span><span class="cx"> 
</span><del>-    RefPtr&lt;DOMWindow&gt; m_frontendWindow;
-    std::unique_ptr&lt;InspectorFrontendClientDummy&gt; m_frontendClient;
-    std::unique_ptr&lt;InspectorFrontendChannelDummy&gt; m_frontendChannel;
</del><ins>+    std::unique_ptr&lt;InspectorStubFrontend&gt; m_inspectorFrontend;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebKitiosChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ios/ChangeLog (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ios/ChangeLog        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/ios/ChangeLog        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-09-17  Brian Burg  &lt;bburg@apple.com&gt;
+
+        ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
+        https://bugs.webkit.org/show_bug.cgi?id=149006
+
+        Reviewed by Joseph Pecoraro.
+
+        * WebCoreSupport/WebInspectorClientIOS.mm:
+        (WebInspectorClient::closeLocalFrontend): Deleted.
+        (WebInspectorFrontendClient::disconnectFromBackend): Deleted.
+
</ins><span class="cx"> 2015-09-12  Brian Burg  &lt;bburg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: disambiguate inspected/frontend controllers and pages in backend code
</span></span></pre></div>
<a id="trunkSourceWebKitiosWebCoreSupportWebInspectorClientIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ios/WebCoreSupport/WebInspectorClientIOS.mm (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ios/WebCoreSupport/WebInspectorClientIOS.mm        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/ios/WebCoreSupport/WebInspectorClientIOS.mm        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc.  All rights reserved.
</del><ins>+ * Copyright (C) 2006-2008, 2010, 2015 Apple Inc.  All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -42,9 +42,9 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><del>-WebInspectorClient::WebInspectorClient(WebView* inpectedWebView)
-    : m_inspectedWebView(inpectedWebView)
-    , m_highlighter(adoptNS([[WebNodeHighlighter alloc] initWithInspectedWebView:inpectedWebView]))
</del><ins>+WebInspectorClient::WebInspectorClient(WebView* inspectedWebView)
+    : m_inspectedWebView(inspectedWebView)
+    , m_highlighter(adoptNS([[WebNodeHighlighter alloc] initWithInspectedWebView:inspectedWebView]))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -65,11 +65,6 @@
</span><span class="cx">     // iOS does not have a local inspector, nothing to do here.
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebInspectorClient::closeLocalFrontend()
-{
-    // iOS does not have a local inspector, nothing to do here.
-}
-
</del><span class="cx"> void WebInspectorClient::didResizeMainFrame(Frame*)
</span><span class="cx"> {
</span><span class="cx">     // iOS does not have a local inspector, nothing to do here.
</span><span class="lines">@@ -129,7 +124,6 @@
</span><span class="cx"> String WebInspectorFrontendClient::localizedStringsURL() { return String(); }
</span><span class="cx"> void WebInspectorFrontendClient::bringToFront() { }
</span><span class="cx"> void WebInspectorFrontendClient::closeWindow() { }
</span><del>-void WebInspectorFrontendClient::disconnectFromBackend() { }
</del><span class="cx"> void WebInspectorFrontendClient::attachWindow(DockSide) { }
</span><span class="cx"> void WebInspectorFrontendClient::detachWindow() { }
</span><span class="cx"> void WebInspectorFrontendClient::setAttachedWindowHeight(unsigned) { }
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/mac/ChangeLog        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2015-09-17  Brian Burg  &lt;bburg@apple.com&gt;
+
+        ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
+        https://bugs.webkit.org/show_bug.cgi?id=149006
+
+        Reviewed by Joseph Pecoraro.
+
+        WK1 WebInspectorClient was connecting to the wrong controllers. Fix this, and
+        remove extra code paths for closing the frontend.
+
+        * WebCoreSupport/WebInspectorClient.h:
+        * WebCoreSupport/WebInspectorClient.mm:
+        (-[WebInspectorWindowController destroyInspectorView]):
+
+            Disconnect the FrontendClient from the frontend page's inspector controller.
+            Do this teardown before releasing the frontend, otherwise we can't use it.
+
+        (WebInspectorClient::inspectedPageDestroyed): Deleted.
+        (WebInspectorClient::closeLocalFrontend): Deleted.
+        (WebInspectorFrontendClient::disconnectFromBackend): Deleted.
+        * WebInspector/WebInspector.mm:
+        (-[WebInspector inspectedWebViewClosed]):
+
+            Make sure to close ourself if the inspected page closes.
+
+        (-[WebInspector close:]):
+
+            Go through the frontend instead of InspectorController.
+
+        * WebInspector/WebInspectorFrontend.h:
+        * WebInspector/WebInspectorFrontend.mm:
+        (-[WebInspectorFrontend close]):
+
</ins><span class="cx"> 2015-09-16  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         printing does not use minimum page zoom factor
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebInspectorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -51,12 +51,11 @@
</span><span class="cx"> 
</span><span class="cx"> class WebInspectorClient : public WebCore::InspectorClient, public Inspector::FrontendChannel {
</span><span class="cx"> public:
</span><del>-    explicit WebInspectorClient(WebView* inspectedWebView);
</del><ins>+    explicit WebInspectorClient(WebView *inspectedWebView);
</ins><span class="cx"> 
</span><span class="cx">     virtual void inspectedPageDestroyed() override;
</span><span class="cx"> 
</span><span class="cx">     virtual Inspector::FrontendChannel* openLocalFrontend(WebCore::InspectorController*) override;
</span><del>-    virtual void closeLocalFrontend() override;
</del><span class="cx">     virtual void bringFrontendToFront() override;
</span><span class="cx">     virtual void didResizeMainFrame(WebCore::Frame*) override;
</span><span class="cx"> 
</span><span class="lines">@@ -114,7 +113,6 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void bringToFront() override;
</span><span class="cx">     virtual void closeWindow() override;
</span><del>-    void disconnectFromBackend();
</del><span class="cx"> 
</span><span class="cx">     virtual void attachWindow(DockSide) override;
</span><span class="cx">     virtual void detachWindow() override;
</span><span class="lines">@@ -133,7 +131,7 @@
</span><span class="cx">     virtual void append(const String&amp; url, const String&amp; content) override;
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    WebView* m_inspectedWebView;
</del><ins>+    WebView *m_inspectedWebView;
</ins><span class="cx">     RetainPtr&lt;WebInspectorWindowController&gt; m_frontendWindowController;
</span><span class="cx">     String m_inspectedURL;
</span><span class="cx">     HashMap&lt;String, RetainPtr&lt;NSURL&gt;&gt; m_suggestedToActualURLMap;
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebInspectorClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -102,7 +102,6 @@
</span><span class="cx"> 
</span><span class="cx"> void WebInspectorClient::inspectedPageDestroyed()
</span><span class="cx"> {
</span><del>-    closeLocalFrontend();
</del><span class="cx">     delete this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -122,12 +121,6 @@
</span><span class="cx">     return this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebInspectorClient::closeLocalFrontend()
-{
-    if (m_frontendClient)
-        m_frontendClient-&gt;disconnectFromBackend();
-}
-
</del><span class="cx"> void WebInspectorClient::bringFrontendToFront()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_frontendClient);
</span><span class="lines">@@ -256,11 +249,6 @@
</span><span class="cx">     [m_frontendWindowController.get() destroyInspectorView];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebInspectorFrontendClient::disconnectFromBackend()
-{
-    [m_frontendWindowController.get() destroyInspectorView];
-}
-
</del><span class="cx"> void WebInspectorFrontendClient::attachWindow(DockSide)
</span><span class="cx"> {
</span><span class="cx">     if ([m_frontendWindowController.get() attached])
</span><span class="lines">@@ -681,6 +669,11 @@
</span><span class="cx"> {
</span><span class="cx">     RetainPtr&lt;WebInspectorWindowController&gt; protect(self);
</span><span class="cx"> 
</span><ins>+    if (Page* frontendPage = _frontendClient-&gt;frontendPage())
+        frontendPage-&gt;inspectorController().setInspectorFrontendClient(nullptr);
+    if (Page* inspectedPage = [_inspectedWebView.get() page])
+        inspectedPage-&gt;inspectorController().disconnectFrontend(_inspectorClient);
+
</ins><span class="cx">     [[_inspectedWebView.get() inspector] releaseFrontend];
</span><span class="cx">     _inspectorClient-&gt;releaseFrontend();
</span><span class="cx"> 
</span><span class="lines">@@ -693,11 +686,6 @@
</span><span class="cx"> 
</span><span class="cx">     _visible = NO;
</span><span class="cx"> 
</span><del>-    if (Page* inspectedPage = [_inspectedWebView.get() page]) {
-        inspectedPage-&gt;inspectorController().setInspectorFrontendClient(nullptr);
-        inspectedPage-&gt;inspectorController().disconnectFrontend(_inspectorClient);
-    }
-
</del><span class="cx">     [_frontendWebView close];
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebInspectorWebInspectormm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebInspector/WebInspector.mm (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebInspector/WebInspector.mm        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/mac/WebInspector/WebInspector.mm        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2007 Apple Inc.  All rights reserved.
</del><ins>+ * Copyright (C) 2007, 2015 Apple Inc.  All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)inspectedWebViewClosed
</span><span class="cx"> {
</span><ins>+    [self close:nil];
</ins><span class="cx">     _inspectedWebView = nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -157,8 +158,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)close:(id)sender 
</span><span class="cx"> {
</span><del>-    if (Page* inspectedPage = core(_inspectedWebView))
-        inspectedPage-&gt;inspectorController().close();
</del><ins>+    [_frontend close];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)attach:(id)sender
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebInspectorWebInspectorFrontendh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2010, 2015 Apple Inc. All Rights Reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> - (id)initWithFrontendClient:(WebInspectorFrontendClient *)frontendClient;
</span><span class="cx"> - (void)attach;
</span><span class="cx"> - (void)detach;
</span><ins>+- (void)close;
</ins><span class="cx"> 
</span><span class="cx"> - (BOOL)isDebuggingEnabled;
</span><span class="cx"> - (void)setDebuggingEnabled:(BOOL)enabled;
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebInspectorWebInspectorFrontendmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.mm (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.mm        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/mac/WebInspector/WebInspectorFrontend.mm        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2010, 2015 Apple Inc. All Rights Reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -51,6 +51,11 @@
</span><span class="cx">     m_frontendClient-&gt;detachWindow();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)close
+{
+    m_frontendClient-&gt;closeWindow();
+}
+
</ins><span class="cx"> - (BOOL)isDebuggingEnabled
</span><span class="cx"> {
</span><span class="cx">     return m_frontendClient-&gt;isDebuggingEnabled();
</span></span></pre></div>
<a id="trunkSourceWebKitwinChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/ChangeLog (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/ChangeLog        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/win/ChangeLog        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2015-09-17  Brian Burg  &lt;bburg@apple.com&gt;
+
+        ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
+        https://bugs.webkit.org/show_bug.cgi?id=149006
+
+        Reviewed by Joseph Pecoraro.
+
+        * WebCoreSupport/WebInspectorClient.cpp:
+        (WebInspectorFrontendClient::destroyInspectorView):
+
+            Disconnect the FrontendClient from the frontend page's inspector controller.
+            Do this teardown before releasing the frontend, otherwise we can't use it.
+
+        (WebInspectorFrontendClient::onClose):
+        (WebInspectorClient::inspectedPageDestroyed): Deleted.
+        (WebInspectorClient::closeLocalFrontend): Deleted.
+        * WebCoreSupport/WebInspectorClient.h: Drive-by cleanup for class declarations.
+        * WebInspector.cpp:
+        (WebInspector::close):
+
+            Go through the frontend instead of InspectorController.
+
</ins><span class="cx"> 2015-09-17  Per Arne Vollan  &lt;peavo@outlook.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win][HighDPI] Windowed plugins have incorrect placement.
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebCoreSupportWebInspectorClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2014 Apple Inc.  All rights reserved.
</del><ins>+ * Copyright (C) 2006-2010, 2014, 2015 Apple Inc.  All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -74,7 +74,6 @@
</span><span class="cx"> 
</span><span class="cx"> void WebInspectorClient::inspectedPageDestroyed()
</span><span class="cx"> {
</span><del>-    closeLocalFrontend();
</del><span class="cx">     delete this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -171,12 +170,6 @@
</span><span class="cx">     return this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebInspectorClient::closeLocalFrontend()
-{
-    if (m_frontendClient)
-        m_frontendClient-&gt;destroyInspectorView();
-}
-
</del><span class="cx"> void WebInspectorClient::bringFrontendToFront()
</span><span class="cx"> {
</span><span class="cx">     m_frontendClient-&gt;bringToFront();
</span><span class="lines">@@ -423,16 +416,19 @@
</span><span class="cx"> 
</span><span class="cx"> void WebInspectorFrontendClient::destroyInspectorView()
</span><span class="cx"> {
</span><del>-    m_inspectorClient-&gt;releaseFrontend();
-
</del><span class="cx">     if (m_destroyingInspectorView)
</span><span class="cx">         return;
</span><span class="cx">     m_destroyingInspectorView = true;
</span><span class="cx"> 
</span><ins>+    if (Page* frontendPage = this-&gt;frontendPage())
+        frontendPage-&gt;inspectorController().setInspectorFrontendClient(nullptr);
+    if (Page* inspectedPage = m_inspectedWebView-&gt;page())
+        inspectedPage-&gt;inspectorController().disconnectFrontend(m_inspectorClient);
+
+    m_inspectorClient-&gt;releaseFrontend();
+
</ins><span class="cx">     closeWindowWithoutNotifications();
</span><span class="cx"> 
</span><del>-    m_inspectedWebView-&gt;page()-&gt;inspectorController().setInspectorFrontendClient(nullptr);
-    m_inspectedWebView-&gt;page()-&gt;inspectorController().disconnectFrontend(m_inspectorClient);
</del><span class="cx">     m_inspectorClient-&gt;updateHighlight();
</span><span class="cx"> 
</span><span class="cx">     ::DestroyWindow(m_frontendHwnd);
</span><span class="lines">@@ -466,7 +462,7 @@
</span><span class="cx"> LRESULT WebInspectorFrontendClient::onClose(WPARAM, LPARAM)
</span><span class="cx"> {
</span><span class="cx">     ::ShowWindow(m_frontendHwnd, SW_HIDE);
</span><del>-    m_inspectedWebView-&gt;page()-&gt;inspectorController().close();
</del><ins>+    closeWindow();
</ins><span class="cx"> 
</span><span class="cx">     return 0;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebCoreSupportWebInspectorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebInspectorClient.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -48,22 +48,22 @@
</span><span class="cx"> class WebNodeHighlight;
</span><span class="cx"> class WebView;
</span><span class="cx"> 
</span><del>-class WebInspectorClient : public WebCore::InspectorClient, public Inspector::FrontendChannel {
</del><ins>+class WebInspectorClient final : public WebCore::InspectorClient, public Inspector::FrontendChannel {
</ins><span class="cx"> public:
</span><span class="cx">     explicit WebInspectorClient(WebView*);
</span><span class="cx"> 
</span><del>-    // InspectorClient
-    virtual void inspectedPageDestroyed();
</del><ins>+    // InspectorClient API.
+    virtual void inspectedPageDestroyed() override;
</ins><span class="cx"> 
</span><del>-    virtual Inspector::FrontendChannel* openLocalFrontend(WebCore::InspectorController*);
-    virtual void closeLocalFrontend();
-    virtual void bringFrontendToFront();
</del><ins>+    virtual Inspector::FrontendChannel* openLocalFrontend(WebCore::InspectorController*) override;
+    virtual void bringFrontendToFront() override;
</ins><span class="cx"> 
</span><del>-    virtual void highlight();
-    virtual void hideHighlight();
</del><ins>+    virtual void highlight() override;
+    virtual void hideHighlight() override;
</ins><span class="cx"> 
</span><ins>+    // FrontendChannel API.
+    virtual ConnectionType connectionType() const override { return ConnectionType::Local; }
</ins><span class="cx">     virtual bool sendMessageToFrontend(const WTF::String&amp;) override;
</span><del>-    virtual ConnectionType connectionType() const override { return ConnectionType::Local; }
</del><span class="cx"> 
</span><span class="cx">     bool inspectorStartsAttached();
</span><span class="cx">     void setInspectorStartsAttached(bool);
</span><span class="lines">@@ -90,27 +90,29 @@
</span><span class="cx">     std::unique_ptr&lt;WebNodeHighlight&gt; m_highlight;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-class WebInspectorFrontendClient : public WebCore::InspectorFrontendClientLocal, WebCore::WindowMessageListener {
</del><ins>+class WebInspectorFrontendClient final : public WebCore::InspectorFrontendClientLocal, WebCore::WindowMessageListener {
</ins><span class="cx"> public:
</span><span class="cx">     WebInspectorFrontendClient(WebView* inspectedWebView, HWND inspectedWebViewHwnd, HWND frontendHwnd, const COMPtr&lt;WebView&gt;&amp; frotnendWebView, HWND frontendWebViewHwnd, WebInspectorClient*, std::unique_ptr&lt;Settings&gt;);
</span><span class="cx">     virtual ~WebInspectorFrontendClient();
</span><span class="cx"> 
</span><del>-    virtual void frontendLoaded();
</del><ins>+    // InspectorFrontendClient API.
+    virtual void frontendLoaded() override;
</ins><span class="cx"> 
</span><del>-    virtual WTF::String localizedStringsURL();
</del><ins>+    virtual WTF::String localizedStringsURL() override;
</ins><span class="cx"> 
</span><del>-    virtual void bringToFront();
-    virtual void closeWindow();
</del><ins>+    virtual void bringToFront() override;
+    virtual void closeWindow() override;
</ins><span class="cx"> 
</span><del>-    virtual void attachWindow(DockSide);
-    virtual void detachWindow();
-
-    virtual void setAttachedWindowHeight(unsigned height);
-    virtual void setAttachedWindowWidth(unsigned);
</del><ins>+    virtual void setAttachedWindowHeight(unsigned) override;
+    virtual void setAttachedWindowWidth(unsigned) override;
</ins><span class="cx">     virtual void setToolbarHeight(unsigned) override;
</span><span class="cx"> 
</span><del>-    virtual void inspectedURLChanged(const WTF::String&amp; newURL);
</del><ins>+    virtual void inspectedURLChanged(const WTF::String&amp; newURL) override;
</ins><span class="cx"> 
</span><ins>+    // InspectorFrontendClientLocal API.
+    virtual void attachWindow(DockSide) override;
+    virtual void detachWindow() override;
+
</ins><span class="cx">     void destroyInspectorView();
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebInspectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebInspector.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebInspector.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit/win/WebInspector.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -127,9 +127,8 @@
</span><span class="cx"> 
</span><span class="cx"> HRESULT WebInspector::close()
</span><span class="cx"> {
</span><del>-    if (m_inspectedWebView)
-        if (Page* page = m_inspectedWebView-&gt;page())
-            page-&gt;inspectorController().close();
</del><ins>+    if (frontendClient())
+        frontendClient()-&gt;closeWindow();
</ins><span class="cx"> 
</span><span class="cx">     return S_OK;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/ChangeLog        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,3 +1,45 @@
</span><ins>+2015-09-17  Brian Burg  &lt;bburg@apple.com&gt;
+
+        ASSERT(!m_frontendRouter-&gt;hasLocalFrontend()) when running Web Inspector tests
+        https://bugs.webkit.org/show_bug.cgi?id=149006
+        &lt;rdar://problem/22654257&gt;
+        &lt;rdar://problem/22631369&gt;
+
+        Reviewed by Joseph Pecoraro.
+
+        Stop using InspectorController to close the frontend page. Go through
+        the FrontendClient instead. Reduce redundant code paths.
+
+        This change seems to fix some recent crashes that were seen when
+        closing Safari with Web Inspector open. These were caused by the frontend
+        channel not being disconnected at the right time.
+
+        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
+        (WebKit::WebInspectorClient::inspectedPageDestroyed):
+        (WebKit::WebInspectorClient::closeLocalFrontend): Deleted.
+        * WebProcess/WebCoreSupport/WebInspectorClient.h:
+        * WebProcess/WebPage/WebInspector.cpp:
+        (WebKit::WebInspector::close):
+        * WebProcess/WebPage/WebInspectorUI.cpp:
+        (WebKit::WebInspectorUI::establishConnection):
+
+            Save a pointer to the frontend's InspectorController since we may
+            need to use it while the page is being destructed and its getter
+            is no longer accessible.
+
+        (WebKit::WebInspectorUI::closeWindow):
+
+            Explicitly remove the frontend client when closing the frontend.
+
+        * WebProcess/WebPage/WebInspectorUI.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::inspector):
+
+            Allow clients to specify whether an inspector should be eagerly created.
+            Without this, we may accidentally create an instance during teardown.
+
+        * WebProcess/WebPage/WebPage.h:
+
</ins><span class="cx"> 2015-09-18  Emanuele Aina  &lt;emanuele.aina@collabora.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix build with --no-indexed-database after r189831
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebInspectorClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2014, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -78,7 +78,9 @@
</span><span class="cx"> 
</span><span class="cx"> void WebInspectorClient::inspectedPageDestroyed()
</span><span class="cx"> {
</span><del>-    closeLocalFrontend();
</del><ins>+    if (WebInspector* inspector = m_page-&gt;inspector(WebPage::LazyCreationPolicy::UseExistingOnly))
+        inspector-&gt;close();
+
</ins><span class="cx">     delete this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -89,14 +91,6 @@
</span><span class="cx">     return m_page-&gt;inspector();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebInspectorClient::closeLocalFrontend()
-{
-    if (m_page-&gt;inspector()) {
-        m_page-&gt;corePage()-&gt;inspectorController().disconnectFrontend(m_page-&gt;inspector());
-        m_page-&gt;inspector()-&gt;closeFrontendConnection();
-    }
-}
-
</del><span class="cx"> void WebInspectorClient::bringFrontendToFront()
</span><span class="cx"> {
</span><span class="cx">     if (m_page-&gt;inspector())
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebInspectorClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -53,7 +53,6 @@
</span><span class="cx">     void inspectedPageDestroyed() override;
</span><span class="cx"> 
</span><span class="cx">     Inspector::FrontendChannel* openLocalFrontend(WebCore::InspectorController*) override;
</span><del>-    void closeLocalFrontend() override;
</del><span class="cx">     void bringFrontendToFront() override;
</span><span class="cx">     void didResizeMainFrame(WebCore::Frame*) override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebInspectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2014, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -126,7 +126,12 @@
</span><span class="cx">     if (!m_page-&gt;corePage())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_page-&gt;corePage()-&gt;inspectorController().close();
</del><ins>+    // Close could be called multiple times during teardown.
+    if (!m_frontendConnection)
+        return;
+
+    m_page-&gt;corePage()-&gt;inspectorController().disconnectFrontend(this);
+    closeFrontendConnection();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebInspector::openInNewTab(const String&amp; urlString)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebInspectorUIcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -70,7 +70,8 @@
</span><span class="cx">     m_frontendAPIDispatcher.reset();
</span><span class="cx">     m_underTest = underTest;
</span><span class="cx"> 
</span><del>-    m_page.corePage()-&gt;inspectorController().setInspectorFrontendClient(this);
</del><ins>+    m_frontendController = &amp;m_page.corePage()-&gt;inspectorController();
+    m_frontendController-&gt;setInspectorFrontendClient(this);
</ins><span class="cx"> 
</span><span class="cx">     m_backendConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
</span><span class="cx">     m_backendConnection-&gt;open();
</span><span class="lines">@@ -117,6 +118,10 @@
</span><span class="cx">         m_backendConnection-&gt;invalidate();
</span><span class="cx">     m_backendConnection = nullptr;
</span><span class="cx"> 
</span><ins>+    if (m_frontendController)
+        m_frontendController-&gt;setInspectorFrontendClient(nullptr);
+    m_frontendController = nullptr;
+
</ins><span class="cx">     m_inspectedPageIdentifier = 0;
</span><span class="cx">     m_underTest = false;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebInspectorUIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -31,6 +31,10 @@
</span><span class="cx"> #include &lt;WebCore/InspectorFrontendClient.h&gt;
</span><span class="cx"> #include &lt;WebCore/InspectorFrontendHost.h&gt;
</span><span class="cx"> 
</span><ins>+namespace WebCore {
+class InspectorController;
+}
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> class WebPage;
</span><span class="lines">@@ -109,6 +113,10 @@
</span><span class="cx">     RefPtr&lt;WebCore::InspectorFrontendHost&gt; m_frontendHost;
</span><span class="cx">     RefPtr&lt;IPC::Connection&gt; m_backendConnection;
</span><span class="cx"> 
</span><ins>+    // Keep a pointer to the frontend's inspector controller rather than going through
+    // corePage(), since we may need it after the frontend's page has started destruction.
+    WebCore::InspectorController* m_frontendController { nullptr };
+
</ins><span class="cx">     uint64_t m_inspectedPageIdentifier { 0 };
</span><span class="cx">     bool m_underTest { false };
</span><span class="cx">     DockSide m_dockSide { DockSide::Undocked };
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -2942,11 +2942,11 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-WebInspector* WebPage::inspector()
</del><ins>+WebInspector* WebPage::inspector(LazyCreationPolicy behavior)
</ins><span class="cx"> {
</span><span class="cx">     if (m_isClosed)
</span><span class="cx">         return nullptr;
</span><del>-    if (!m_inspector)
</del><ins>+    if (!m_inspector &amp;&amp; behavior == LazyCreationPolicy::CreateIfNeeded)
</ins><span class="cx">         m_inspector = WebInspector::create(this);
</span><span class="cx">     return m_inspector.get();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (189969 => 189970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2015-09-18 16:53:10 UTC (rev 189969)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2015-09-18 17:16:24 UTC (rev 189970)
</span><span class="lines">@@ -236,7 +236,9 @@
</span><span class="cx">     void didFlushLayerTreeAtTime(std::chrono::milliseconds);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    WebInspector* inspector();
</del><ins>+    enum class LazyCreationPolicy { UseExistingOnly, CreateIfNeeded };
+
+    WebInspector* inspector(LazyCreationPolicy = LazyCreationPolicy::CreateIfNeeded);
</ins><span class="cx">     WebInspectorUI* inspectorUI();
</span><span class="cx">     bool isInspectorPage() { return !!m_inspectorUI; }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>