<!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>[224788] trunk/Source/WebCore</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/224788">224788</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2017-11-13 15:15:57 -0800 (Mon, 13 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Include a NetworkAgent in ServiceWorkers for network debugging
https://bugs.webkit.org/show_bug.cgi?id=179513
<rdar://problem/35456402>

Reviewed by Brian Burg.

In order to show Network requests for a ServiceWorker, we need to add
inspector networking hooks for Worker loads. While we show Network
requests for DedicatedWorkers, we do that through the Page during Page
inspection. In ServiceWorker inspection, the remote connection is
connected to the ServiceWorkerThreadProxy, and interacts with the
WorkerGlobalScope without making any assumptions about a Page existing.
We don't want to make any assumptions about a Page/Document being needed
for Network hooks, so we should add new hooks that will work in the
WorkerGlobalScope's context.

This patch adds InspectorInstrumentation networking hooks for workers inside
of the WorkerThreadableLoader bridge. This is where the majority of Worker
initiated network requests happen (Fetch/XHR, but not WebSockets). The hooks
are simpler versions of the existing network hooks for a Page, and allow for
complete inspector networking information (will send, did receive response,
did receive data, success, failure, and timing metrics).

This patch generalizes InspectorNetworkAgent to work for a Page and Worker.
Some of the existing functionality was specific to a Page (frameId/loaderId)
but did not make sense for a Worker. In order to handle these cases, all
of the unique logic was extracted out into virtual methods that subclasses
PageNetworkAgent and WorkerNetworkAgent provide as appropriate. The majority
of NetworkAgent remains unchanged and algorithms are shared.

We needed to change the existing InspectorInstrumentation networking hooks
to allow for an optional DocumentLoader. This way we can keep all of the
same hooks leading inside of NetworkAgent, but loads for a Page will have a
DocumentLoader, and loads for a ServiceWorker will not.

While the WorkerNetworkAgent would work for a DedicatedWorker, we still
only create it for a ServiceWorker. The existing behavior of showing Network
loads for a DedicatedWorker will continue to go through the Page inspector
so we can avoid creating a NetworkAgent for DedicatedWorkers. If we created
a way to directly inspect a DedicatedWorker we could look at making this
always available, but it would require extra work to function perfectly.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* inspector/InspectorAllInOne.cpp:
Add new files.

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::createLazyAgents):
Switch from InspectorNetworkAgent to PageNetworkAgent.

* inspector/WorkerInspectorController.h:
* inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::WorkerInspectorController):
(WebCore::WorkerInspectorController::workerAgentContext):
(WebCore::WorkerInspectorController::createLazyAgents):
Create a WorkerNetworkAgent when inside of a ServiceWorker.
Also start the lazy agent pattern for agents that can defer
creation until a frontend attached.

(WebCore::WorkerInspectorController::connectFrontend):
(WebCore::WorkerInspectorController::disconnectFrontend):
When frontends connect/disconnect toggle the necessary states.
Also start the execution stopwatch, otherwise it will always be at 0.

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willSendRequestImpl):
(WebCore::InspectorInstrumentation::willSendRequestOfTypeImpl):
(WebCore::InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl):
(WebCore::InspectorInstrumentation::didReceiveResourceResponseImpl):
(WebCore::InspectorInstrumentation::didFinishLoadingImpl):
(WebCore::InspectorInstrumentation::didFailLoadingImpl):
(WebCore::InspectorInstrumentation::frameDetachedFromParentImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::willSendRequest):
(WebCore::InspectorInstrumentation::didReceiveResourceResponse):
(WebCore::InspectorInstrumentation::didReceiveData):
(WebCore::InspectorInstrumentation::didFinishLoading):
(WebCore::InspectorInstrumentation::didFailLoading):
Add Worker networking hooks that pass through to the same general hooks.

* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):
(WebCore::WorkerThreadableLoader::MainThreadBridge::didReceiveResponse):
(WebCore::WorkerThreadableLoader::MainThreadBridge::didReceiveData):
(WebCore::WorkerThreadableLoader::MainThreadBridge::didFinishLoading):
(WebCore::WorkerThreadableLoader::MainThreadBridge::didFail):
(WebCore::WorkerThreadableLoader::MainThreadBridge::didFinishTiming):
* loader/WorkerThreadableLoader.h:
Use the new worker networking instrumentation hooks.

* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create):
Drive-by: use a move.

* inspector/agents/InspectorNetworkAgent.h:
* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::InspectorNetworkAgent):
(WebCore::InspectorNetworkAgent::willSendRequest):
(WebCore::InspectorNetworkAgent::willSendRequestOfType):
(WebCore::InspectorNetworkAgent::didReceiveResponse):
(WebCore::InspectorNetworkAgent::didFinishLoading):
(WebCore::InspectorNetworkAgent::didFailLoading):
(WebCore::InspectorNetworkAgent::didLoadResourceFromMemoryCache):
(WebCore::InspectorNetworkAgent::buildInitiatorObject):
(WebCore::InspectorNetworkAgent::enable):
(WebCore::InspectorNetworkAgent::disable):
(WebCore::InspectorNetworkAgent::setResourceCachingDisabled):
(WebCore::InspectorNetworkAgent::loadResource):
(WebCore::InspectorNetworkAgent::webSocketForRequestId):
(WebCore::InspectorNetworkAgent::resolveWebSocket):
(WebCore::InspectorNetworkAgent::mainFrameNavigated):
Extract logic for subclasses. Transition to DocumentLoader being null.

* inspector/agents/page/PageNetworkAgent.h:
* inspector/agents/page/PageNetworkAgent.cpp: Added.
(WebCore::PageNetworkAgent::PageNetworkAgent):
(WebCore::PageNetworkAgent::loaderIdentifier):
(WebCore::PageNetworkAgent::frameIdentifier):
(WebCore::PageNetworkAgent::setResourceCachingDisabled):
(WebCore::PageNetworkAgent::scriptExecutionContext):
Extracted Page implementation. This is just moving from the original.

* inspector/agents/worker/WorkerNetworkAgent.h:
* inspector/agents/worker/WorkerNetworkAgent.cpp:
(WebCore::WorkerNetworkAgent::WorkerNetworkAgent):
(WebCore::WorkerNetworkAgent::loaderIdentifier):
(WebCore::WorkerNetworkAgent::frameIdentifier):
(WebCore::WorkerNetworkAgent::setResourceCachingDisabled):
(WebCore::WorkerNetworkAgent::scriptExecutionContext):
Implement for a worker.

* inspector/agents/worker/WorkerDebuggerAgent.cpp:
(WebCore::WorkerDebuggerAgent::WorkerDebuggerAgent):
* inspector/agents/worker/WorkerConsoleAgent.cpp:
(WebCore::WorkerConsoleAgent::WorkerConsoleAgent):
* inspector/agents/worker/WorkerRuntimeAgent.cpp:
(WebCore::WorkerRuntimeAgent::WorkerRuntimeAgent):
Add some assertions for all Worker agents for clarify.

* workers/WorkerDebuggerProxy.h:
* workers/WorkerGlobalScope.h:
(WebCore::WorkerGlobalScope::identifier const):
(WebCore::WorkerGlobalScope::createUniqueIdentifier):
Provide a way to get unique identifiers in a worker. For the Page
this is done through the Page's ProgressTracker. For a Worker we just
put this on the WorkerGlobalScope. This is used for request ids.

* workers/WorkerMessagingProxy.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::setResourceCachingDisabled):
* workers/service/context/ServiceWorkerThreadProxy.h:
* workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::setResourceCachingDisabled):
Add a debug method for disabling the resource cache from a worker.
In service workers this sets the override flag on the hidden page.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreSourcestxt">trunk/Source/WebCore/Sources.txt</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorAllInOnecpp">trunk/Source/WebCore/inspector/InspectorAllInOne.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorControllercpp">trunk/Source/WebCore/inspector/InspectorController.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorInstrumentationcpp">trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorInstrumentationh">trunk/Source/WebCore/inspector/InspectorInstrumentation.h</a></li>
<li><a href="#trunkSourceWebCoreinspectorWorkerInspectorControllercpp">trunk/Source/WebCore/inspector/WorkerInspectorController.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorWorkerInspectorControllerh">trunk/Source/WebCore/inspector/WorkerInspectorController.h</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsInspectorNetworkAgentcpp">trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsInspectorNetworkAgenth">trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsworkerWorkerConsoleAgentcpp">trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsworkerWorkerDebuggerAgentcpp">trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsworkerWorkerRuntimeAgentcpp">trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderThreadableLoadercpp">trunk/Source/WebCore/loader/ThreadableLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderWorkerThreadableLoadercpp">trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderWorkerThreadableLoaderh">trunk/Source/WebCore/loader/WorkerThreadableLoader.h</a></li>
<li><a href="#trunkSourceWebCoreworkersWorkerDebuggerProxyh">trunk/Source/WebCore/workers/WorkerDebuggerProxy.h</a></li>
<li><a href="#trunkSourceWebCoreworkersWorkerGlobalScopeh">trunk/Source/WebCore/workers/WorkerGlobalScope.h</a></li>
<li><a href="#trunkSourceWebCoreworkersWorkerMessagingProxycpp">trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersWorkerMessagingProxyh">trunk/Source/WebCore/workers/WorkerMessagingProxy.h</a></li>
<li><a href="#trunkSourceWebCoreworkersservicecontextServiceWorkerThreadProxycpp">trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersservicecontextServiceWorkerThreadProxyh">trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreinspectoragentspagePageNetworkAgentcpp">trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentspagePageNetworkAgenth">trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.h</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsworkerWorkerNetworkAgentcpp">trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectoragentsworkerWorkerNetworkAgenth">trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/ChangeLog      2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -1,3 +1,163 @@
</span><ins>+2017-11-13  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Include a NetworkAgent in ServiceWorkers for network debugging
+        https://bugs.webkit.org/show_bug.cgi?id=179513
+        <rdar://problem/35456402>
+
+        Reviewed by Brian Burg.
+
+        In order to show Network requests for a ServiceWorker, we need to add
+        inspector networking hooks for Worker loads. While we show Network
+        requests for DedicatedWorkers, we do that through the Page during Page
+        inspection. In ServiceWorker inspection, the remote connection is
+        connected to the ServiceWorkerThreadProxy, and interacts with the
+        WorkerGlobalScope without making any assumptions about a Page existing.
+        We don't want to make any assumptions about a Page/Document being needed
+        for Network hooks, so we should add new hooks that will work in the
+        WorkerGlobalScope's context.
+
+        This patch adds InspectorInstrumentation networking hooks for workers inside
+        of the WorkerThreadableLoader bridge. This is where the majority of Worker
+        initiated network requests happen (Fetch/XHR, but not WebSockets). The hooks
+        are simpler versions of the existing network hooks for a Page, and allow for
+        complete inspector networking information (will send, did receive response,
+        did receive data, success, failure, and timing metrics).
+
+        This patch generalizes InspectorNetworkAgent to work for a Page and Worker.
+        Some of the existing functionality was specific to a Page (frameId/loaderId)
+        but did not make sense for a Worker. In order to handle these cases, all
+        of the unique logic was extracted out into virtual methods that subclasses
+        PageNetworkAgent and WorkerNetworkAgent provide as appropriate. The majority
+        of NetworkAgent remains unchanged and algorithms are shared.
+
+        We needed to change the existing InspectorInstrumentation networking hooks
+        to allow for an optional DocumentLoader. This way we can keep all of the
+        same hooks leading inside of NetworkAgent, but loads for a Page will have a
+        DocumentLoader, and loads for a ServiceWorker will not.
+
+        While the WorkerNetworkAgent would work for a DedicatedWorker, we still
+        only create it for a ServiceWorker. The existing behavior of showing Network
+        loads for a DedicatedWorker will continue to go through the Page inspector
+        so we can avoid creating a NetworkAgent for DedicatedWorkers. If we created
+        a way to directly inspect a DedicatedWorker we could look at making this
+        always available, but it would require extra work to function perfectly.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * inspector/InspectorAllInOne.cpp:
+        Add new files.
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::createLazyAgents):
+        Switch from InspectorNetworkAgent to PageNetworkAgent.
+
+        * inspector/WorkerInspectorController.h:
+        * inspector/WorkerInspectorController.cpp:
+        (WebCore::WorkerInspectorController::WorkerInspectorController):
+        (WebCore::WorkerInspectorController::workerAgentContext):
+        (WebCore::WorkerInspectorController::createLazyAgents):
+        Create a WorkerNetworkAgent when inside of a ServiceWorker.
+        Also start the lazy agent pattern for agents that can defer
+        creation until a frontend attached.
+
+        (WebCore::WorkerInspectorController::connectFrontend):
+        (WebCore::WorkerInspectorController::disconnectFrontend):
+        When frontends connect/disconnect toggle the necessary states.
+        Also start the execution stopwatch, otherwise it will always be at 0.
+
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willSendRequestImpl):
+        (WebCore::InspectorInstrumentation::willSendRequestOfTypeImpl):
+        (WebCore::InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl):
+        (WebCore::InspectorInstrumentation::didReceiveResourceResponseImpl):
+        (WebCore::InspectorInstrumentation::didFinishLoadingImpl):
+        (WebCore::InspectorInstrumentation::didFailLoadingImpl):
+        (WebCore::InspectorInstrumentation::frameDetachedFromParentImpl):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::willSendRequest):
+        (WebCore::InspectorInstrumentation::didReceiveResourceResponse):
+        (WebCore::InspectorInstrumentation::didReceiveData):
+        (WebCore::InspectorInstrumentation::didFinishLoading):
+        (WebCore::InspectorInstrumentation::didFailLoading):
+        Add Worker networking hooks that pass through to the same general hooks.
+
+        * loader/WorkerThreadableLoader.cpp:
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge):
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didReceiveResponse):
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didReceiveData):
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didFinishLoading):
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didFail):
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::didFinishTiming):
+        * loader/WorkerThreadableLoader.h:
+        Use the new worker networking instrumentation hooks.
+
+        * loader/ThreadableLoader.cpp:
+        (WebCore::ThreadableLoader::create):
+        Drive-by: use a move.
+
+        * inspector/agents/InspectorNetworkAgent.h:
+        * inspector/agents/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::InspectorNetworkAgent):
+        (WebCore::InspectorNetworkAgent::willSendRequest):
+        (WebCore::InspectorNetworkAgent::willSendRequestOfType):
+        (WebCore::InspectorNetworkAgent::didReceiveResponse):
+        (WebCore::InspectorNetworkAgent::didFinishLoading):
+        (WebCore::InspectorNetworkAgent::didFailLoading):
+        (WebCore::InspectorNetworkAgent::didLoadResourceFromMemoryCache):
+        (WebCore::InspectorNetworkAgent::buildInitiatorObject):
+        (WebCore::InspectorNetworkAgent::enable):
+        (WebCore::InspectorNetworkAgent::disable):
+        (WebCore::InspectorNetworkAgent::setResourceCachingDisabled):
+        (WebCore::InspectorNetworkAgent::loadResource):
+        (WebCore::InspectorNetworkAgent::webSocketForRequestId):
+        (WebCore::InspectorNetworkAgent::resolveWebSocket):
+        (WebCore::InspectorNetworkAgent::mainFrameNavigated):
+        Extract logic for subclasses. Transition to DocumentLoader being null.
+
+        * inspector/agents/page/PageNetworkAgent.h:
+        * inspector/agents/page/PageNetworkAgent.cpp: Added.
+        (WebCore::PageNetworkAgent::PageNetworkAgent):
+        (WebCore::PageNetworkAgent::loaderIdentifier):
+        (WebCore::PageNetworkAgent::frameIdentifier):
+        (WebCore::PageNetworkAgent::setResourceCachingDisabled):
+        (WebCore::PageNetworkAgent::scriptExecutionContext):
+        Extracted Page implementation. This is just moving from the original.
+
+        * inspector/agents/worker/WorkerNetworkAgent.h:
+        * inspector/agents/worker/WorkerNetworkAgent.cpp:
+        (WebCore::WorkerNetworkAgent::WorkerNetworkAgent):
+        (WebCore::WorkerNetworkAgent::loaderIdentifier):
+        (WebCore::WorkerNetworkAgent::frameIdentifier):
+        (WebCore::WorkerNetworkAgent::setResourceCachingDisabled):
+        (WebCore::WorkerNetworkAgent::scriptExecutionContext):
+        Implement for a worker.
+        
+        * inspector/agents/worker/WorkerDebuggerAgent.cpp:
+        (WebCore::WorkerDebuggerAgent::WorkerDebuggerAgent):
+        * inspector/agents/worker/WorkerConsoleAgent.cpp:
+        (WebCore::WorkerConsoleAgent::WorkerConsoleAgent):
+        * inspector/agents/worker/WorkerRuntimeAgent.cpp:
+        (WebCore::WorkerRuntimeAgent::WorkerRuntimeAgent):
+        Add some assertions for all Worker agents for clarify.
+
+        * workers/WorkerDebuggerProxy.h:
+        * workers/WorkerGlobalScope.h:
+        (WebCore::WorkerGlobalScope::identifier const):
+        (WebCore::WorkerGlobalScope::createUniqueIdentifier):
+        Provide a way to get unique identifiers in a worker. For the Page
+        this is done through the Page's ProgressTracker. For a Worker we just
+        put this on the WorkerGlobalScope. This is used for request ids.
+
+        * workers/WorkerMessagingProxy.h:
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::setResourceCachingDisabled):
+        * workers/service/context/ServiceWorkerThreadProxy.h:
+        * workers/service/context/ServiceWorkerThreadProxy.cpp:
+        (WebCore::ServiceWorkerThreadProxy::setResourceCachingDisabled):
+        Add a debug method for disabling the resource cache from a worker.
+        In service workers this sets the override flag on the hidden page.
+
</ins><span class="cx"> 2017-11-08  Keith Miller  <keith_miller@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Async iteration should only fetch the next method once and add feature flag
</span></span></pre></div>
<a id="trunkSourceWebCoreSourcestxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Sources.txt (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Sources.txt 2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/Sources.txt    2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -1150,10 +1150,12 @@
</span><span class="cx"> inspector/agents/page/PageConsoleAgent.cpp
</span><span class="cx"> inspector/agents/page/PageDebuggerAgent.cpp
</span><span class="cx"> inspector/agents/page/PageHeapAgent.cpp
</span><ins>+inspector/agents/page/PageNetworkAgent.cpp
</ins><span class="cx"> inspector/agents/page/PageRuntimeAgent.cpp
</span><span class="cx"> 
</span><span class="cx"> inspector/agents/worker/WorkerConsoleAgent.cpp
</span><span class="cx"> inspector/agents/worker/WorkerDebuggerAgent.cpp
</span><ins>+inspector/agents/worker/WorkerNetworkAgent.cpp
</ins><span class="cx"> inspector/agents/worker/WorkerRuntimeAgent.cpp
</span><span class="cx"> 
</span><span class="cx"> loader/ContentFilter.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -2878,6 +2878,8 @@
</span><span class="cx">          A5B81CCD1FAA44DE0037D1E6 /* WorkerConsoleAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5B81CCA1FAA44DA0037D1E6 /* WorkerConsoleAgent.h */; };
</span><span class="cx">          A5B81CCE1FAA44DE0037D1E6 /* WorkerDebuggerAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5B81CCC1FAA44DA0037D1E6 /* WorkerDebuggerAgent.h */; };
</span><span class="cx">          A5B81CCF1FAA44DE0037D1E6 /* WorkerRuntimeAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5B81CC91FAA44DA0037D1E6 /* WorkerRuntimeAgent.h */; };
</span><ins>+               A5CB05241FB51F3300089B97 /* PageNetworkAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CB05211FB51F1700089B97 /* PageNetworkAgent.h */; };
+               A5CB05251FB51F3A00089B97 /* WorkerNetworkAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CB05231FB51F2400089B97 /* WorkerNetworkAgent.h */; };
</ins><span class="cx">           A5CE9F3F1E4C4174001BBE7C /* ResourceTiming.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE9F3C1E4BC586001BBE7C /* ResourceTiming.h */; };
</span><span class="cx">          A5DEBDA416FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5DEBDA016FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.h */; };
</span><span class="cx">          A5F36D3B18F758720054C024 /* PageScriptDebugServer.h in Headers */ = {isa = PBXBuildFile; fileRef = A5F36D3918F758720054C024 /* PageScriptDebugServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -10810,6 +10812,10 @@
</span><span class="cx">          A5B81CCC1FAA44DA0037D1E6 /* WorkerDebuggerAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerDebuggerAgent.h; sourceTree = "<group>"; };
</span><span class="cx">          A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyEventCocoa.h; sourceTree = "<group>"; };
</span><span class="cx">          A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyEventCocoa.mm; sourceTree = "<group>"; };
</span><ins>+               A5CB051F1FB51F1600089B97 /* PageNetworkAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageNetworkAgent.cpp; sourceTree = "<group>"; };
+               A5CB05211FB51F1700089B97 /* PageNetworkAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageNetworkAgent.h; sourceTree = "<group>"; };
+               A5CB05221FB51F2300089B97 /* WorkerNetworkAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerNetworkAgent.cpp; sourceTree = "<group>"; };
+               A5CB05231FB51F2400089B97 /* WorkerNetworkAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerNetworkAgent.h; sourceTree = "<group>"; };
</ins><span class="cx">           A5CE9F3C1E4BC586001BBE7C /* ResourceTiming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceTiming.h; sourceTree = "<group>"; };
</span><span class="cx">          A5CE9F3E1E4C416B001BBE7C /* ResourceTiming.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceTiming.cpp; sourceTree = "<group>"; };
</span><span class="cx">          A5DEBD9F16FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitPlaybackTargetAvailabilityEvent.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -20594,6 +20600,8 @@
</span><span class="cx">                          A5B81CBE1FAA44B70037D1E6 /* PageDebuggerAgent.h */,
</span><span class="cx">                          A5B81CBA1FAA44B70037D1E6 /* PageHeapAgent.cpp */,
</span><span class="cx">                          A5B81CBC1FAA44B70037D1E6 /* PageHeapAgent.h */,
</span><ins>+                               A5CB051F1FB51F1600089B97 /* PageNetworkAgent.cpp */,
+                               A5CB05211FB51F1700089B97 /* PageNetworkAgent.h */,
</ins><span class="cx">                           A5B81CC11FAA44B70037D1E6 /* PageRuntimeAgent.cpp */,
</span><span class="cx">                          A5B81CBF1FAA44B70037D1E6 /* PageRuntimeAgent.h */,
</span><span class="cx">                  );
</span><span class="lines">@@ -20607,6 +20615,8 @@
</span><span class="cx">                          A5B81CCA1FAA44DA0037D1E6 /* WorkerConsoleAgent.h */,
</span><span class="cx">                          A5B81CC81FAA44DA0037D1E6 /* WorkerDebuggerAgent.cpp */,
</span><span class="cx">                          A5B81CCC1FAA44DA0037D1E6 /* WorkerDebuggerAgent.h */,
</span><ins>+                               A5CB05221FB51F2300089B97 /* WorkerNetworkAgent.cpp */,
+                               A5CB05231FB51F2400089B97 /* WorkerNetworkAgent.h */,
</ins><span class="cx">                           A5B81CC71FAA44DA0037D1E6 /* WorkerRuntimeAgent.cpp */,
</span><span class="cx">                          A5B81CC91FAA44DA0037D1E6 /* WorkerRuntimeAgent.h */,
</span><span class="cx">                  );
</span><span class="lines">@@ -28412,6 +28422,7 @@
</span><span class="cx">                          9302B0BF0D79F82C00C7EE83 /* PageGroup.h in Headers */,
</span><span class="cx">                          7A674BDC0F9EBF4E006CF099 /* PageGroupLoadDeferrer.h in Headers */,
</span><span class="cx">                          A5B81CC41FAA44BC0037D1E6 /* PageHeapAgent.h in Headers */,
</span><ins>+                               A5CB05241FB51F3300089B97 /* PageNetworkAgent.h in Headers */,
</ins><span class="cx">                           2D5C9D0019C7B52E00B3C5C1 /* PageOverlay.h in Headers */,
</span><span class="cx">                          2D5C9D0219C7B52E00B3C5C1 /* PageOverlayController.h in Headers */,
</span><span class="cx">                          FBDB61A116D6037E00BB3394 /* PageRuleCollector.h in Headers */,
</span><span class="lines">@@ -29774,6 +29785,7 @@
</span><span class="cx">                          2E4346500F546A8200B0F1BA /* WorkerMessagingProxy.h in Headers */,
</span><span class="cx">                          E1271A0B0EEEC77A00F61213 /* WorkerNavigator.h in Headers */,
</span><span class="cx">                          1ABC7109170E5E1B00F9A9D6 /* WorkerNavigatorStorageQuota.h in Headers */,
</span><ins>+                               A5CB05251FB51F3A00089B97 /* WorkerNetworkAgent.h in Headers */,
</ins><span class="cx">                           2E4346510F546A8200B0F1BA /* WorkerObjectProxy.h in Headers */,
</span><span class="cx">                          416E29A6102FA962007FC14E /* WorkerReportingProxy.h in Headers */,
</span><span class="cx">                          2E4346530F546A8200B0F1BA /* WorkerRunLoop.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorAllInOnecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorAllInOne.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorAllInOne.cpp     2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/InspectorAllInOne.cpp        2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx"> #include "PageConsoleAgent.cpp"
</span><span class="cx"> #include "PageDebuggerAgent.cpp"
</span><span class="cx"> #include "PageHeapAgent.cpp"
</span><ins>+#include "PageNetworkAgent.cpp"
</ins><span class="cx"> #include "PageRuntimeAgent.cpp"
</span><span class="cx"> #include "PageScriptDebugServer.cpp"
</span><span class="cx"> #include "TimelineRecordFactory.cpp"
</span><span class="lines">@@ -68,5 +69,6 @@
</span><span class="cx"> #include "WorkerConsoleAgent.cpp"
</span><span class="cx"> #include "WorkerDebuggerAgent.cpp"
</span><span class="cx"> #include "WorkerInspectorController.cpp"
</span><ins>+#include "WorkerNetworkAgent.cpp"
</ins><span class="cx"> #include "WorkerRuntimeAgent.cpp"
</span><span class="cx"> #include "WorkerScriptDebugServer.cpp"
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorController.cpp   2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp      2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -50,7 +50,6 @@
</span><span class="cx"> #include "InspectorInstrumentation.h"
</span><span class="cx"> #include "InspectorLayerTreeAgent.h"
</span><span class="cx"> #include "InspectorMemoryAgent.h"
</span><del>-#include "InspectorNetworkAgent.h"
</del><span class="cx"> #include "InspectorPageAgent.h"
</span><span class="cx"> #include "InspectorTimelineAgent.h"
</span><span class="cx"> #include "InspectorWorkerAgent.h"
</span><span class="lines">@@ -64,6 +63,7 @@
</span><span class="cx"> #include "PageConsoleAgent.h"
</span><span class="cx"> #include "PageDebuggerAgent.h"
</span><span class="cx"> #include "PageHeapAgent.h"
</span><ins>+#include "PageNetworkAgent.h"
</ins><span class="cx"> #include "PageRuntimeAgent.h"
</span><span class="cx"> #include "PageScriptDebugServer.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="lines">@@ -149,15 +149,8 @@
</span><span class="cx">     m_agents.append(WTFMove(canvasAgentPtr));
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_injectedScriptManager->commandLineAPIHost());
</span><del>-    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost()) {
-        commandLineAPIHost->init(
-              m_inspectorAgent
-            , consoleAgent
-            , m_domAgent
-            , domStorageAgent
-            , databaseAgent
-        );
-    }
</del><ins>+    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
+        commandLineAPIHost->init(m_inspectorAgent, consoleAgent, m_domAgent, domStorageAgent, databaseAgent);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> InspectorController::~InspectorController()
</span><span class="lines">@@ -201,7 +194,7 @@
</span><span class="cx">     auto debuggerAgentPtr = debuggerAgent.get();
</span><span class="cx"> 
</span><span class="cx">     m_agents.append(WTFMove(debuggerAgent));
</span><del>-    m_agents.append(std::make_unique<InspectorNetworkAgent>(pageContext, m_pageAgent));
</del><ins>+    m_agents.append(std::make_unique<PageNetworkAgent>(pageContext, m_pageAgent));
</ins><span class="cx">     m_agents.append(std::make_unique<InspectorCSSAgent>(pageContext, m_domAgent));
</span><span class="cx">     m_agents.append(std::make_unique<InspectorDOMDebuggerAgent>(pageContext, m_domAgent, debuggerAgentPtr));
</span><span class="cx">     m_agents.append(std::make_unique<InspectorApplicationCacheAgent>(pageContext, m_pageAgent));
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorInstrumentationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp      2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -560,20 +560,14 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
</span><span class="cx"> {
</span><del>-    if (!loader)
-        return;
-
</del><span class="cx">     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
</span><del>-        networkAgent->willSendRequest(identifier, *loader, request, redirectResponse);
</del><ins>+        networkAgent->willSendRequest(identifier, loader, request, redirectResponse);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::willSendRequestOfTypeImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, LoadType loadType)
</span><span class="cx"> {
</span><del>-    if (!loader)
-        return;
-
</del><span class="cx">     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
</span><del>-        networkAgent->willSendRequestOfType(identifier, *loader, request, loadType);
</del><ins>+        networkAgent->willSendRequestOfType(identifier, loader, request, loadType);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents& instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
</span><span class="lines">@@ -585,16 +579,13 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
</span><del>-        networkAgent->didLoadResourceFromMemoryCache(*loader, *cachedResource);
</del><ins>+        networkAgent->didLoadResourceFromMemoryCache(loader, *cachedResource);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::didReceiveResourceResponseImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
</span><span class="cx"> {
</span><del>-    if (!loader)
-        return;
-
</del><span class="cx">     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
</span><del>-        networkAgent->didReceiveResponse(identifier, *loader, response, resourceLoader);
</del><ins>+        networkAgent->didReceiveResponse(identifier, loader, response, resourceLoader);
</ins><span class="cx">     if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
</span><span class="cx">         consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
</span><span class="cx"> }
</span><span class="lines">@@ -613,20 +604,14 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
</span><span class="cx"> {
</span><del>-    if (!loader)
-        return;
-
</del><span class="cx">     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
</span><del>-        networkAgent->didFinishLoading(identifier, *loader, networkLoadMetrics, resourceLoader);
</del><ins>+        networkAgent->didFinishLoading(identifier, loader, networkLoadMetrics, resourceLoader);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
</span><span class="cx"> {
</span><del>-    if (!loader)
-        return;
-
</del><span class="cx">     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
</span><del>-        networkAgent->didFailLoading(identifier, *loader, error);
</del><ins>+        networkAgent->didFailLoading(identifier, loader, error);
</ins><span class="cx">     if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
</span><span class="cx">         consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
</span><span class="cx"> }
</span><span class="lines">@@ -697,7 +682,6 @@
</span><span class="cx"> {
</span><span class="cx">     if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
</span><span class="cx">         pageAgent->frameDetached(frame);
</span><del>-
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, DocumentLoader* loader)
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorInstrumentationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h        2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h   2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -177,10 +177,13 @@
</span><span class="cx">     static void didReceiveData(Frame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
</span><span class="cx">     static void didFinishLoading(Frame*, DocumentLoader*, unsigned long identifier, const NetworkLoadMetrics&, ResourceLoader*);
</span><span class="cx">     static void didFailLoading(Frame*, DocumentLoader*, unsigned long identifier, const ResourceError&);
</span><del>-    static void continueAfterXFrameOptionsDenied(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
-    static void continueWithPolicyDownload(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
-    static void continueWithPolicyIgnore(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
</del><span class="cx"> 
</span><ins>+    static void willSendRequest(WorkerGlobalScope&, unsigned long identifier, ResourceRequest&);
+    static void didReceiveResourceResponse(WorkerGlobalScope&, unsigned long identifier, const ResourceResponse&);
+    static void didReceiveData(WorkerGlobalScope&, unsigned long identifier, const char* data, int dataLength);
+    static void didFinishLoading(WorkerGlobalScope&, unsigned long identifier, const NetworkLoadMetrics&);
+    static void didFailLoading(WorkerGlobalScope&, unsigned long identifier, const ResourceError&);
+
</ins><span class="cx">     // Some network requests do not go through the normal network loading path.
</span><span class="cx">     // These network requests have to issue their own willSendRequest / didReceiveResponse / didFinishLoading / didFailLoading
</span><span class="cx">     // instrumentation calls. Some of these loads are for resources that lack a CachedResource::Type.
</span><span class="lines">@@ -187,6 +190,9 @@
</span><span class="cx">     enum class LoadType { Ping, Beacon };
</span><span class="cx">     static void willSendRequestOfType(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, LoadType);
</span><span class="cx"> 
</span><ins>+    static void continueAfterXFrameOptionsDenied(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
+    static void continueWithPolicyDownload(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
+    static void continueWithPolicyIgnore(Frame&, unsigned long identifier, DocumentLoader&, const ResourceResponse&);
</ins><span class="cx">     static void didFinishXHRLoading(ScriptExecutionContext*, unsigned long identifier, std::optional<String> decodedText);
</span><span class="cx">     static void willLoadXHRSynchronously(ScriptExecutionContext*);
</span><span class="cx">     static void didLoadXHRSynchronously(ScriptExecutionContext*);
</span><span class="lines">@@ -907,6 +913,12 @@
</span><span class="cx">         willSendRequestImpl(*instrumentingAgents, identifier, loader, request, redirectResponse);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline void InspectorInstrumentation::willSendRequest(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, ResourceRequest& request)
+{
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    willSendRequestImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, request, ResourceResponse { });
+}
+
</ins><span class="cx"> inline void InspectorInstrumentation::willSendRequestOfType(Frame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, LoadType loadType)
</span><span class="cx"> {
</span><span class="cx">     FAST_RETURN_IF_NO_FRONTENDS(void());
</span><span class="lines">@@ -926,6 +938,11 @@
</span><span class="cx">         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, loader, response, resourceLoader);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline void InspectorInstrumentation::didReceiveResourceResponse(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const ResourceResponse& response)
+{
+    didReceiveResourceResponseImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, response, nullptr);
+}
+
</ins><span class="cx"> inline void InspectorInstrumentation::didReceiveThreadableLoaderResponse(DocumentThreadableLoader& documentThreadableLoader, unsigned long identifier)
</span><span class="cx"> {
</span><span class="cx">     FAST_RETURN_IF_NO_FRONTENDS(void());
</span><span class="lines">@@ -940,12 +957,25 @@
</span><span class="cx">         didReceiveDataImpl(*instrumentingAgents, identifier, data, dataLength, encodedDataLength);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline void InspectorInstrumentation::didReceiveData(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const char* data, int dataLength)
+{
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    didReceiveDataImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, data, dataLength, dataLength);
+}
+
</ins><span class="cx"> inline void InspectorInstrumentation::didFinishLoading(Frame* frame, DocumentLoader* loader, unsigned long identifier, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
</span><span class="cx"> {
</span><ins>+    FAST_RETURN_IF_NO_FRONTENDS(void());
</ins><span class="cx">     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
</span><span class="cx">         didFinishLoadingImpl(*instrumentingAgents, identifier, loader, networkLoadMetrics, resourceLoader);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline void InspectorInstrumentation::didFinishLoading(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const NetworkLoadMetrics& networkLoadMetrics)
+{
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    didFinishLoadingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, networkLoadMetrics, nullptr);
+}
+
</ins><span class="cx"> inline void InspectorInstrumentation::didFailLoading(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
</span><span class="cx"> {
</span><span class="cx">     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
</span><span class="lines">@@ -952,6 +982,11 @@
</span><span class="cx">         didFailLoadingImpl(*instrumentingAgents, identifier, loader, error);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline void InspectorInstrumentation::didFailLoading(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const ResourceError& error)
+{
+    didFailLoadingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, error);
+}
+
</ins><span class="cx"> inline void InspectorInstrumentation::continueAfterXFrameOptionsDenied(Frame& frame, unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response)
</span><span class="cx"> {
</span><span class="cx">     // Treat the same as didReceiveResponse.
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorWorkerInspectorControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/WorkerInspectorController.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/WorkerInspectorController.cpp     2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/WorkerInspectorController.cpp        2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include "WorkerConsoleAgent.h"
</span><span class="cx"> #include "WorkerDebuggerAgent.h"
</span><span class="cx"> #include "WorkerGlobalScope.h"
</span><ins>+#include "WorkerNetworkAgent.h"
</ins><span class="cx"> #include "WorkerRuntimeAgent.h"
</span><span class="cx"> #include "WorkerThread.h"
</span><span class="cx"> #include "WorkerToPageFrontendChannel.h"
</span><span class="lines">@@ -43,9 +44,14 @@
</span><span class="cx"> #include <inspector/InspectorFrontendChannel.h>
</span><span class="cx"> #include <inspector/InspectorFrontendDispatchers.h>
</span><span class="cx"> #include <inspector/InspectorFrontendRouter.h>
</span><ins>+#include <inspector/agents/InspectorAgent.h>
</ins><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_WORKER)
+#include "ServiceWorkerGlobalScope.h"
+#endif
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><ins>+
</ins><span class="cx"> using namespace JSC;
</span><span class="cx"> using namespace Inspector;
</span><span class="cx"> 
</span><span class="lines">@@ -58,43 +64,25 @@
</span><span class="cx">     , m_scriptDebugServer(workerGlobalScope)
</span><span class="cx">     , m_workerGlobalScope(workerGlobalScope)
</span><span class="cx"> {
</span><del>-    AgentContext baseContext = {
-        *this,
-        *m_injectedScriptManager,
-        m_frontendRouter.get(),
-        m_backendDispatcher.get(),
-    };
</del><ins>+    ASSERT(workerGlobalScope.isContextThread());
</ins><span class="cx"> 
</span><del>-    WebAgentContext webContext = {
-        baseContext,
-        m_instrumentingAgents.get(),
-    };
</del><ins>+    auto workerContext = workerAgentContext();
</ins><span class="cx"> 
</span><del>-    WorkerAgentContext workerContext = {
-        webContext,
-        workerGlobalScope,
-    };
-
</del><ins>+    auto inspectorAgent = std::make_unique<InspectorAgent>(workerContext);
</ins><span class="cx">     auto heapAgent = std::make_unique<WebHeapAgent>(workerContext);
</span><ins>+    auto consoleAgent = std::make_unique<WorkerConsoleAgent>(workerContext, heapAgent.get());
</ins><span class="cx"> 
</span><ins>+    m_instrumentingAgents->setInspectorAgent(inspectorAgent.get());
+    m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
+
+    m_agents.append(WTFMove(inspectorAgent));
</ins><span class="cx">     m_agents.append(std::make_unique<WorkerRuntimeAgent>(workerContext));
</span><span class="cx">     m_agents.append(std::make_unique<WorkerDebuggerAgent>(workerContext));
</span><del>-
-    auto consoleAgent = std::make_unique<WorkerConsoleAgent>(workerContext, heapAgent.get());
-    m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
</del><span class="cx">     m_agents.append(WTFMove(consoleAgent));
</span><del>-
</del><span class="cx">     m_agents.append(WTFMove(heapAgent));
</span><span class="cx"> 
</span><del>-    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost()) {
-        commandLineAPIHost->init(
-              nullptr // InspectorAgent
-            , m_instrumentingAgents->webConsoleAgent()
-            , nullptr // InspectorDOMAgent
-            , nullptr // InspectorDOMStorageAgent
-            , nullptr // InspectorDatabaseAgent
-        );
-    }
</del><ins>+    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
+        commandLineAPIHost->init(m_instrumentingAgents->inspectorAgent(), m_instrumentingAgents->webConsoleAgent(), nullptr, nullptr, nullptr);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WorkerInspectorController::~WorkerInspectorController()
</span><span class="lines">@@ -119,6 +107,13 @@
</span><span class="cx">     ASSERT(!m_frontendRouter->hasFrontends());
</span><span class="cx">     ASSERT(!m_forwardingChannel);
</span><span class="cx"> 
</span><ins>+    createLazyAgents();
+
+    InspectorInstrumentation::frontendCreated();
+
+    m_executionStopwatch->reset();
+    m_executionStopwatch->start();
+
</ins><span class="cx">     m_forwardingChannel = std::make_unique<WorkerToPageFrontendChannel>(m_workerGlobalScope);
</span><span class="cx">     m_frontendRouter->connectFrontend(m_forwardingChannel.get());
</span><span class="cx">     m_agents.didCreateFrontendAndBackend(&m_frontendRouter.get(), &m_backendDispatcher.get());
</span><span class="lines">@@ -131,6 +126,8 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_forwardingChannel);
</span><span class="cx"> 
</span><ins>+    InspectorInstrumentation::frontendDeleted();
+
</ins><span class="cx">     m_agents.willDestroyFrontendAndBackend(reason);
</span><span class="cx">     m_frontendRouter->disconnectFrontend(m_forwardingChannel.get());
</span><span class="cx">     m_forwardingChannel = nullptr;
</span><span class="lines">@@ -141,6 +138,42 @@
</span><span class="cx">     m_backendDispatcher->dispatch(message);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+WorkerAgentContext WorkerInspectorController::workerAgentContext()
+{
+    AgentContext baseContext = {
+        *this,
+        *m_injectedScriptManager,
+        m_frontendRouter.get(),
+        m_backendDispatcher.get(),
+    };
+
+    WebAgentContext webContext = {
+        baseContext,
+        m_instrumentingAgents.get(),
+    };
+
+    WorkerAgentContext workerContext = {
+        webContext,
+        m_workerGlobalScope,
+    };
+
+    return workerContext;
+}
+
+void WorkerInspectorController::createLazyAgents()
+{
+    if (m_didCreateLazyAgents)
+        return;
+
+    m_didCreateLazyAgents = true;
+
+#if ENABLE(SERVICE_WORKER)
+    auto workerContext = workerAgentContext();
+    if (is<ServiceWorkerGlobalScope>(m_workerGlobalScope))
+        m_agents.append(std::make_unique<WorkerNetworkAgent>(workerContext));
+#endif
+}
+
</ins><span class="cx"> InspectorFunctionCallHandler WorkerInspectorController::functionCallHandler() const
</span><span class="cx"> {
</span><span class="cx">     return WebCore::functionCallHandlerFromAnyThread;
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorWorkerInspectorControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/WorkerInspectorController.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/WorkerInspectorController.h       2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/WorkerInspectorController.h  2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> class InstrumentingAgents;
</span><span class="cx"> class WebInjectedScriptManager;
</span><span class="cx"> class WorkerGlobalScope;
</span><ins>+struct WorkerAgentContext;
</ins><span class="cx"> 
</span><span class="cx"> class WorkerInspectorController final : public Inspector::InspectorEnvironment {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(WorkerInspectorController);
</span><span class="lines">@@ -70,6 +71,9 @@
</span><span class="cx"> private:
</span><span class="cx">     friend class InspectorInstrumentation;
</span><span class="cx"> 
</span><ins>+    WorkerAgentContext workerAgentContext();
+    void createLazyAgents();
+
</ins><span class="cx">     Ref<InstrumentingAgents> m_instrumentingAgents;
</span><span class="cx">     std::unique_ptr<WebInjectedScriptManager> m_injectedScriptManager;
</span><span class="cx">     Ref<Inspector::FrontendRouter> m_frontendRouter;
</span><span class="lines">@@ -79,6 +83,7 @@
</span><span class="cx">     Inspector::AgentRegistry m_agents;
</span><span class="cx">     WorkerGlobalScope& m_workerGlobalScope;
</span><span class="cx">     std::unique_ptr<Inspector::FrontendChannel> m_forwardingChannel;
</span><ins>+    bool m_didCreateLazyAgents { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsInspectorNetworkAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp  2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp     2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -77,10 +77,10 @@
</span><span class="cx"> #include <wtf/Stopwatch.h>
</span><span class="cx"> #include <wtf/text/StringBuilder.h>
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> typedef Inspector::NetworkBackendDispatcherHandler::LoadResourceCallback LoadResourceCallback;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><ins>+
</ins><span class="cx"> using namespace Inspector;
</span><span class="cx"> 
</span><span class="cx"> namespace {
</span><span class="lines">@@ -89,7 +89,9 @@
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(InspectorThreadableLoaderClient);
</span><span class="cx"> public:
</span><span class="cx">     InspectorThreadableLoaderClient(RefPtr<LoadResourceCallback>&& callback)
</span><del>-        : m_callback(WTFMove(callback)) { }
</del><ins>+        : m_callback(WTFMove(callback))
+    {
+    }
</ins><span class="cx"> 
</span><span class="cx">     virtual ~InspectorThreadableLoaderClient() = default;
</span><span class="cx"> 
</span><span class="lines">@@ -157,12 +159,11 @@
</span><span class="cx"> 
</span><span class="cx"> } // namespace
</span><span class="cx"> 
</span><del>-InspectorNetworkAgent::InspectorNetworkAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
</del><ins>+InspectorNetworkAgent::InspectorNetworkAgent(WebAgentContext& context)
</ins><span class="cx">     : InspectorAgentBase(ASCIILiteral("Network"), context)
</span><span class="cx">     , m_frontendDispatcher(std::make_unique<Inspector::NetworkFrontendDispatcher>(context.frontendRouter))
</span><span class="cx">     , m_backendDispatcher(Inspector::NetworkBackendDispatcher::create(context.backendDispatcher, this))
</span><span class="cx">     , m_injectedScriptManager(context.injectedScriptManager)
</span><del>-    , m_pageAgent(pageAgent)
</del><span class="cx">     , m_resourcesData(std::make_unique<NetworkResourcesData>())
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -336,7 +337,7 @@
</span><span class="cx">     return m_environment.executionStopwatch()->elapsedTime();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader& loader, ResourceRequest& request, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType type)
</del><ins>+void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType type)
</ins><span class="cx"> {
</span><span class="cx">     if (request.hiddenFromInspector()) {
</span><span class="cx">         m_hiddenRequestIdentifiers.add(identifier);
</span><span class="lines">@@ -347,15 +348,17 @@
</span><span class="cx">     double walltime = currentTime();
</span><span class="cx"> 
</span><span class="cx">     String requestId = IdentifiersFactory::requestId(identifier);
</span><del>-    String loaderId = m_pageAgent->loaderId(&loader);
</del><ins>+    String frameId = frameIdentifier(loader);
+    String loaderId = loaderIdentifier(loader);
+    String targetId = request.initiatorIdentifier();
</ins><span class="cx"> 
</span><span class="cx">     if (type == InspectorPageAgent::OtherResource) {
</span><span class="cx">         if (m_loadingXHRSynchronously)
</span><span class="cx">             type = InspectorPageAgent::XHRResource;
</span><del>-        else if (equalIgnoringFragmentIdentifier(request.url(), loader.url()) && !loader.isCommitted())
</del><ins>+        else if (loader && equalIgnoringFragmentIdentifier(request.url(), loader->url()) && !loader->isCommitted())
</ins><span class="cx">             type = InspectorPageAgent::DocumentResource;
</span><del>-        else {
-            for (auto& linkIcon : loader.linkIcons()) {
</del><ins>+        else if (loader) {
+            for (auto& linkIcon : loader->linkIcons()) {
</ins><span class="cx">                 if (equalIgnoringFragmentIdentifier(request.url(), linkIcon.url)) {
</span><span class="cx">                     type = InspectorPageAgent::ImageResource;
</span><span class="cx">                     break;
</span><span class="lines">@@ -371,10 +374,11 @@
</span><span class="cx"> 
</span><span class="cx">     auto protocolResourceType = InspectorPageAgent::resourceTypeJSON(type);
</span><span class="cx"> 
</span><del>-    RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader.frame() ? loader.frame()->document() : nullptr);
-    String targetId = request.initiatorIdentifier();
</del><ins>+    Document* document = loader && loader->frame() ? loader->frame()->document() : nullptr;
+    auto initiatorObject = buildInitiatorObject(document);
</ins><span class="cx"> 
</span><del>-    m_frontendDispatcher->requestWillBeSent(requestId, m_pageAgent->frameId(loader.frame()), m_pageAgent->loaderId(&loader), loader.url().string(), buildObjectForResourceRequest(request), sendTimestamp, walltime, initiatorObject, buildObjectForResourceResponse(redirectResponse, nullptr), type != InspectorPageAgent::OtherResource ? &protocolResourceType : nullptr, targetId.isEmpty() ? nullptr : &targetId);
</del><ins>+    String url = loader ? loader->url().string() : request.url();
+    m_frontendDispatcher->requestWillBeSent(requestId, frameId, loaderId, url, buildObjectForResourceRequest(request), sendTimestamp, walltime, initiatorObject, buildObjectForResourceResponse(redirectResponse, nullptr), type != InspectorPageAgent::OtherResource ? &protocolResourceType : nullptr, targetId.isEmpty() ? nullptr : &targetId);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static InspectorPageAgent::ResourceType resourceTypeForCachedResource(CachedResource* resource)
</span><span class="lines">@@ -397,18 +401,18 @@
</span><span class="cx">     return InspectorPageAgent::OtherResource;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader& loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
</del><ins>+void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
</ins><span class="cx"> {
</span><del>-    auto* cachedResource = InspectorPageAgent::cachedResource(loader.frame(), request.url());
</del><ins>+    auto* cachedResource = loader ? InspectorPageAgent::cachedResource(loader->frame(), request.url()) : nullptr;
</ins><span class="cx">     willSendRequest(identifier, loader, request, redirectResponse, resourceTypeForCachedResource(cachedResource));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::willSendRequestOfType(unsigned long identifier, DocumentLoader& loader, ResourceRequest& request, InspectorInstrumentation::LoadType loadType)
</del><ins>+void InspectorNetworkAgent::willSendRequestOfType(unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, InspectorInstrumentation::LoadType loadType)
</ins><span class="cx"> {
</span><span class="cx">     willSendRequest(identifier, loader, request, ResourceResponse(), resourceTypeForLoadType(loadType));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
</del><ins>+void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
</ins><span class="cx"> {
</span><span class="cx">     if (m_hiddenRequestIdentifiers.contains(identifier))
</span><span class="cx">         return;
</span><span class="lines">@@ -421,8 +425,8 @@
</span><span class="cx">     CachedResource* cachedResource = nullptr;
</span><span class="cx">     if (resourceLoader && resourceLoader->isSubresourceLoader() && !isNotModified)
</span><span class="cx">         cachedResource = static_cast<SubresourceLoader*>(resourceLoader)->cachedResource();
</span><del>-    if (!cachedResource)
-        cachedResource = InspectorPageAgent::cachedResource(loader.frame(), response.url());
</del><ins>+    if (!cachedResource && loader)
+        cachedResource = InspectorPageAgent::cachedResource(loader->frame(), response.url());
</ins><span class="cx"> 
</span><span class="cx">     if (cachedResource) {
</span><span class="cx">         // Use mime type from cached resource in case the one in response is empty.
</span><span class="lines">@@ -439,8 +443,8 @@
</span><span class="cx">     if (type != newType && newType != InspectorPageAgent::XHRResource && newType != InspectorPageAgent::OtherResource)
</span><span class="cx">         type = newType;
</span><span class="cx"> 
</span><del>-    String frameId = m_pageAgent->frameId(loader.frame());
-    String loaderId = m_pageAgent->loaderId(&loader);
</del><ins>+    String frameId = frameIdentifier(loader);
+    String loaderId = loaderIdentifier(loader);
</ins><span class="cx"> 
</span><span class="cx">     m_resourcesData->responseReceived(requestId, frameId, response, type);
</span><span class="cx"> 
</span><span class="lines">@@ -473,7 +477,7 @@
</span><span class="cx">     m_frontendDispatcher->dataReceived(requestId, timestamp(), dataLength, encodedDataLength);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentLoader& loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
</del><ins>+void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentLoader* loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
</ins><span class="cx"> {
</span><span class="cx">     if (m_hiddenRequestIdentifiers.remove(identifier))
</span><span class="cx">         return;
</span><span class="lines">@@ -487,8 +491,8 @@
</span><span class="cx">         elapsedFinishTime = timestamp();
</span><span class="cx"> 
</span><span class="cx">     String requestId = IdentifiersFactory::requestId(identifier);
</span><del>-    if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource)
-        m_resourcesData->addResourceSharedBuffer(requestId, loader.frameLoader()->documentLoader()->mainResourceData(), loader.frame()->document()->encoding());
</del><ins>+    if (loader && m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource)
+        m_resourcesData->addResourceSharedBuffer(requestId, loader->frameLoader()->documentLoader()->mainResourceData(), loader->frame()->document()->encoding());
</ins><span class="cx"> 
</span><span class="cx">     m_resourcesData->maybeDecodeDataToContent(requestId);
</span><span class="cx"> 
</span><span class="lines">@@ -502,7 +506,7 @@
</span><span class="cx">     m_frontendDispatcher->loadingFinished(requestId, elapsedFinishTime, !sourceMappingURL.isEmpty() ? &sourceMappingURL : nullptr, metrics);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::didFailLoading(unsigned long identifier, DocumentLoader& loader, const ResourceError& error)
</del><ins>+void InspectorNetworkAgent::didFailLoading(unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
</ins><span class="cx"> {
</span><span class="cx">     if (m_hiddenRequestIdentifiers.remove(identifier))
</span><span class="cx">         return;
</span><span class="lines">@@ -509,8 +513,8 @@
</span><span class="cx"> 
</span><span class="cx">     String requestId = IdentifiersFactory::requestId(identifier);
</span><span class="cx"> 
</span><del>-    if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
-        Frame* frame = loader.frame();
</del><ins>+    if (loader && m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
+        Frame* frame = loader->frame();
</ins><span class="cx">         if (frame && frame->loader().documentLoader() && frame->document()) {
</span><span class="cx">             m_resourcesData->addResourceSharedBuffer(requestId,
</span><span class="cx">                 frame->loader().documentLoader()->mainResourceData(),
</span><span class="lines">@@ -522,22 +526,26 @@
</span><span class="cx">     m_frontendDispatcher->loadingFailed(requestId, timestamp(), error.localizedDescription(), canceled ? &canceled : nullptr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorNetworkAgent::didLoadResourceFromMemoryCache(DocumentLoader& loader, CachedResource& resource)
</del><ins>+void InspectorNetworkAgent::didLoadResourceFromMemoryCache(DocumentLoader* loader, CachedResource& resource)
</ins><span class="cx"> {
</span><del>-    unsigned long identifier = loader.frame()->page()->progress().createUniqueIdentifier();
</del><ins>+    ASSERT(loader);
+    if (!loader)
+        return;
+
+    unsigned long identifier = loader->frame()->page()->progress().createUniqueIdentifier();
</ins><span class="cx">     String requestId = IdentifiersFactory::requestId(identifier);
</span><del>-    String loaderId = m_pageAgent->loaderId(&loader);
-    String frameId = m_pageAgent->frameId(loader.frame());
</del><ins>+    String loaderId = loaderIdentifier(loader);
+    String frameId = frameIdentifier(loader);
</ins><span class="cx"> 
</span><span class="cx">     m_resourcesData->resourceCreated(requestId, loaderId, resource);
</span><span class="cx"> 
</span><del>-    RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader.frame() ? loader.frame()->document() : nullptr);
</del><ins>+    RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : nullptr);
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: It would be ideal to generate the Network.Response with the MemoryCache source
</span><span class="cx">     // instead of whatever ResourceResponse::Source the CachedResources's response has.
</span><span class="cx">     // The frontend already knows for certain that this was served from the memory cache.
</span><span class="cx"> 
</span><del>-    m_frontendDispatcher->requestServedFromMemoryCache(requestId, frameId, loaderId, loader.url().string(), timestamp(), initiatorObject, buildObjectForCachedResource(&resource));
</del><ins>+    m_frontendDispatcher->requestServedFromMemoryCache(requestId, frameId, loaderId, loader->url().string(), timestamp(), initiatorObject, buildObjectForCachedResource(&resource));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorNetworkAgent::setInitialScriptContent(unsigned long identifier, const String& sourceString)
</span><span class="lines">@@ -607,6 +615,13 @@
</span><span class="cx"> 
</span><span class="cx"> RefPtr<Inspector::Protocol::Network::Initiator> InspectorNetworkAgent::buildInitiatorObject(Document* document)
</span><span class="cx"> {
</span><ins>+    // FIXME: Worker support.
+    if (!isMainThread()) {
+        return Inspector::Protocol::Network::Initiator::create()
+            .setType(Inspector::Protocol::Network::Initiator::Type::Other)
+            .release();
+    }
+
</ins><span class="cx">     Ref<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState());
</span><span class="cx">     if (stackTrace->size() > 0) {
</span><span class="cx">         auto initiatorObject = Inspector::Protocol::Network::Initiator::create()
</span><span class="lines">@@ -698,29 +713,23 @@
</span><span class="cx">     m_enabled = true;
</span><span class="cx">     m_instrumentingAgents.setInspectorNetworkAgent(this);
</span><span class="cx"> 
</span><del>-    LockHolder lock(WebSocket::allActiveWebSocketsMutex());
</del><ins>+    {
+        LockHolder lock(WebSocket::allActiveWebSocketsMutex());
</ins><span class="cx"> 
</span><del>-    for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
-        if (!is<Document>(webSocket->scriptExecutionContext()) || !is<WebSocketChannel>(webSocket->channel().get()))
-            continue;
</del><ins>+        for (WebSocket* webSocket : activeWebSockets(lock)) {
+            ASSERT(is<WebSocketChannel>(webSocket->channel().get()));
+            WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
</ins><span class="cx"> 
</span><del>-        Document* document = downcast<Document>(webSocket->scriptExecutionContext());
-        if (document->page() != &m_pageAgent->page())
-            continue;
</del><ins>+            unsigned identifier = channel->identifier();
+            didCreateWebSocket(identifier, webSocket->url());
+            willSendWebSocketHandshakeRequest(identifier, channel->clientHandshakeRequest());
</ins><span class="cx"> 
</span><del>-        WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
-        if (!channel)
-            continue;
</del><ins>+            if (channel->handshakeMode() == WebSocketHandshake::Connected)
+                didReceiveWebSocketHandshakeResponse(identifier, channel->serverHandshakeResponse());
</ins><span class="cx"> 
</span><del>-        unsigned identifier = channel->identifier();
-        didCreateWebSocket(identifier, webSocket->url());
-        willSendWebSocketHandshakeRequest(identifier, channel->clientHandshakeRequest());
-
-        if (channel->handshakeMode() == WebSocketHandshake::Connected)
-            didReceiveWebSocketHandshakeResponse(identifier, channel->serverHandshakeResponse());
-
-        if (webSocket->readyState() == WebSocket::CLOSED)
-            didCloseWebSocket(identifier);
</del><ins>+            if (webSocket->readyState() == WebSocket::CLOSED)
+                didCloseWebSocket(identifier);
+        }
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -731,7 +740,7 @@
</span><span class="cx">     m_resourcesData->clear();
</span><span class="cx">     m_extraRequestHeaders.clear();
</span><span class="cx"> 
</span><del>-    m_pageAgent->page().setResourceCachingDisabledOverride(false);
</del><ins>+    setResourceCachingDisabled(false);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorNetworkAgent::setExtraHTTPHeaders(ErrorString&, const InspectorObject& headers)
</span><span class="lines">@@ -778,22 +787,16 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorNetworkAgent::setResourceCachingDisabled(ErrorString&, bool disabled)
</span><span class="cx"> {
</span><del>-    m_pageAgent->page().setResourceCachingDisabledOverride(disabled);
</del><ins>+    setResourceCachingDisabled(disabled);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InspectorNetworkAgent::loadResource(ErrorString& errorString, const String& frameId, const String& urlString, Ref<LoadResourceCallback>&& callback)
</span><span class="cx"> {
</span><del>-    Frame* frame = m_pageAgent->assertFrame(errorString, frameId);
-    if (!frame)
</del><ins>+    auto* context = scriptExecutionContext(errorString, frameId);
+    if (!context)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    Document* document = frame->document();
-    if (!document) {
-        errorString = ASCIILiteral("No Document instance for the specified frame");
-        return;
-    }
-
-    URL url = document->completeURL(urlString);
</del><ins>+    URL url = context->completeURL(urlString);
</ins><span class="cx">     ResourceRequest request(url);
</span><span class="cx">     request.setHTTPMethod(ASCIILiteral("GET"));
</span><span class="cx">     request.setHiddenFromInspector(true);
</span><span class="lines">@@ -807,7 +810,7 @@
</span><span class="cx"> 
</span><span class="cx">     // InspectorThreadableLoaderClient deletes itself when the load completes or fails.
</span><span class="cx">     InspectorThreadableLoaderClient* inspectorThreadableLoaderClient = new InspectorThreadableLoaderClient(callback.copyRef());
</span><del>-    auto loader = DocumentThreadableLoader::create(*document, *inspectorThreadableLoaderClient, WTFMove(request), options);
</del><ins>+    auto loader = ThreadableLoader::create(*context, *inspectorThreadableLoaderClient, WTFMove(request), options);
</ins><span class="cx">     if (!loader)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -822,26 +825,11 @@
</span><span class="cx"> {
</span><span class="cx">     LockHolder lock(WebSocket::allActiveWebSocketsMutex());
</span><span class="cx"> 
</span><del>-    for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
-        if (!is<WebSocketChannel>(webSocket->channel().get()))
-            continue;
-
</del><ins>+    for (WebSocket* webSocket : activeWebSockets(lock)) {
+        ASSERT(is<WebSocketChannel>(webSocket->channel().get()));
</ins><span class="cx">         WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
</span><del>-        if (!channel)
-            continue;
-
-        if (IdentifiersFactory::requestId(channel->identifier()) != requestId)
-            continue;
-
-        // FIXME: <webkit.org/b/168475> Web Inspector: Correctly display iframe's and worker's WebSockets
-        if (!is<Document>(webSocket->scriptExecutionContext()))
-            continue;
-
-        Document* document = downcast<Document>(webSocket->scriptExecutionContext());
-        if (document->page() != &m_pageAgent->page())
-            continue;
-
-        return webSocket;
</del><ins>+        if (IdentifiersFactory::requestId(channel->identifier()) == requestId)
+            return webSocket;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return nullptr;
</span><span class="lines">@@ -861,9 +849,12 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // FIXME: <webkit.org/b/168475> Web Inspector: Correctly display iframe's and worker's WebSockets
-    Document* document = downcast<Document>(webSocket->scriptExecutionContext());
-    Frame* frame = document->frame();
</del><ins>+    // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's and worker's WebSockets
+    if (!is<Document>(webSocket->scriptExecutionContext()))
+        return;
+
+    auto* document = downcast<Document>(webSocket->scriptExecutionContext());
+    auto* frame = document->frame();
</ins><span class="cx">     if (!frame) {
</span><span class="cx">         errorString = ASCIILiteral("WebSocket belongs to document without a frame");
</span><span class="cx">         return;
</span><span class="lines">@@ -918,7 +909,7 @@
</span><span class="cx"> 
</span><span class="cx"> void InspectorNetworkAgent::mainFrameNavigated(DocumentLoader& loader)
</span><span class="cx"> {
</span><del>-    m_resourcesData->clear(m_pageAgent->loaderId(&loader));
</del><ins>+    m_resourcesData->clear(loaderIdentifier(&loader));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsInspectorNetworkAgenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h    2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.h       2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -64,10 +64,10 @@
</span><span class="cx"> 
</span><span class="cx"> typedef String ErrorString;
</span><span class="cx"> 
</span><del>-class InspectorNetworkAgent final : public InspectorAgentBase, public Inspector::NetworkBackendDispatcherHandler {
</del><ins>+class InspectorNetworkAgent : public InspectorAgentBase, public Inspector::NetworkBackendDispatcherHandler {
</ins><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    InspectorNetworkAgent(WebAgentContext&, InspectorPageAgent*);
</del><ins>+    explicit InspectorNetworkAgent(WebAgentContext&);
</ins><span class="cx">     virtual ~InspectorNetworkAgent();
</span><span class="cx"> 
</span><span class="cx">     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
</span><span class="lines">@@ -76,13 +76,13 @@
</span><span class="cx">     // InspectorInstrumentation
</span><span class="cx">     void willRecalculateStyle();
</span><span class="cx">     void didRecalculateStyle();
</span><del>-    void willSendRequest(unsigned long identifier, DocumentLoader&, ResourceRequest&, const ResourceResponse& redirectResponse);
-    void willSendRequestOfType(unsigned long identifier, DocumentLoader&, ResourceRequest&, InspectorInstrumentation::LoadType);
-    void didReceiveResponse(unsigned long identifier, DocumentLoader&, const ResourceResponse&, ResourceLoader*);
</del><ins>+    void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
+    void willSendRequestOfType(unsigned long identifier, DocumentLoader*, ResourceRequest&, InspectorInstrumentation::LoadType);
+    void didReceiveResponse(unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
</ins><span class="cx">     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
</span><del>-    void didFinishLoading(unsigned long identifier, DocumentLoader&, const NetworkLoadMetrics&, ResourceLoader*);
-    void didFailLoading(unsigned long identifier, DocumentLoader&, const ResourceError&);
-    void didLoadResourceFromMemoryCache(DocumentLoader&, CachedResource&);
</del><ins>+    void didFinishLoading(unsigned long identifier, DocumentLoader*, const NetworkLoadMetrics&, ResourceLoader*);
+    void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
+    void didLoadResourceFromMemoryCache(DocumentLoader*, CachedResource&);
</ins><span class="cx">     void didReceiveThreadableLoaderResponse(unsigned long identifier, DocumentThreadableLoader&);
</span><span class="cx">     void didFinishXHRLoading(unsigned long identifier, const String& decodedText);
</span><span class="cx">     void willLoadXHRSynchronously();
</span><span class="lines">@@ -106,18 +106,24 @@
</span><span class="cx">     RefPtr<Inspector::Protocol::Network::Initiator> buildInitiatorObject(Document*);
</span><span class="cx"> 
</span><span class="cx">     // Called from frontend.
</span><del>-    void enable(ErrorString&) override;
-    void disable(ErrorString&) override;
-    void setExtraHTTPHeaders(ErrorString&, const Inspector::InspectorObject& headers) override;
-    void getResponseBody(ErrorString&, const String& requestId, String* content, bool* base64Encoded) override;
-    void setResourceCachingDisabled(ErrorString&, bool disabled) override;
-    void loadResource(ErrorString&, const String& frameId, const String& url, Ref<LoadResourceCallback>&&) override;
-    void resolveWebSocket(ErrorString&, const String& requestId, const String* const objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>&) override;
</del><ins>+    void enable(ErrorString&) final;
+    void disable(ErrorString&) final;
+    void setExtraHTTPHeaders(ErrorString&, const Inspector::InspectorObject& headers) final;
+    void getResponseBody(ErrorString&, const String& requestId, String* content, bool* base64Encoded) final;
+    void setResourceCachingDisabled(ErrorString&, bool disabled) final;
+    void loadResource(ErrorString&, const String& frameId, const String& url, Ref<LoadResourceCallback>&&) final;
+    void resolveWebSocket(ErrorString&, const String& requestId, const String* const objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>&) final;
</ins><span class="cx"> 
</span><ins>+    virtual String loaderIdentifier(DocumentLoader*) = 0;
+    virtual String frameIdentifier(DocumentLoader*) = 0;
+    virtual Vector<WebSocket*> activeWebSockets(const LockHolder&) = 0;
+    virtual void setResourceCachingDisabled(bool) = 0;
+    virtual ScriptExecutionContext* scriptExecutionContext(ErrorString&, const String& frameId) = 0;
+
</ins><span class="cx"> private:
</span><span class="cx">     void enable();
</span><span class="cx"> 
</span><del>-    void willSendRequest(unsigned long identifier, DocumentLoader&, ResourceRequest&, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType);
</del><ins>+    void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType);
</ins><span class="cx"> 
</span><span class="cx">     WebSocket* webSocketForRequestId(const String& requestId);
</span><span class="cx"> 
</span><span class="lines">@@ -131,7 +137,6 @@
</span><span class="cx">     std::unique_ptr<Inspector::NetworkFrontendDispatcher> m_frontendDispatcher;
</span><span class="cx">     RefPtr<Inspector::NetworkBackendDispatcher> m_backendDispatcher;
</span><span class="cx">     Inspector::InjectedScriptManager& m_injectedScriptManager;
</span><del>-    InspectorPageAgent* m_pageAgent { nullptr };
</del><span class="cx"> 
</span><span class="cx">     // FIXME: InspectorNetworkAgent should not be aware of style recalculation.
</span><span class="cx">     RefPtr<Inspector::Protocol::Network::Initiator> m_styleRecalculationInitiator;
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentspagePageNetworkAgentcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp (0 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp                          (rev 0)
+++ trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp     2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -0,0 +1,106 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PageNetworkAgent.h"
+
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "Frame.h"
+#include "Page.h"
+#include "ScriptState.h"
+#include "WebSocket.h"
+#include "WebSocketChannel.h"
+
+namespace WebCore {
+
+using namespace Inspector;
+
+PageNetworkAgent::PageNetworkAgent(PageAgentContext& context, InspectorPageAgent* pageAgent)
+    : InspectorNetworkAgent(context)
+    , m_pageAgent(pageAgent)
+{
+    ASSERT(m_pageAgent);
+}
+
+String PageNetworkAgent::loaderIdentifier(DocumentLoader* loader)
+{
+    return m_pageAgent->loaderId(loader);
+}
+
+String PageNetworkAgent::frameIdentifier(DocumentLoader* loader)
+{
+    if (!loader)
+        return { };
+    return m_pageAgent->frameId(loader->frame());
+}
+
+Vector<WebSocket*> PageNetworkAgent::activeWebSockets(const LockHolder& lock)
+{
+    Vector<WebSocket*> webSockets;
+
+    for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
+        if (!is<WebSocketChannel>(webSocket->channel().get()))
+            continue;
+
+        auto* channel = downcast<WebSocketChannel>(webSocket->channel().get());
+        if (!channel)
+            continue;
+
+        if (!is<Document>(webSocket->scriptExecutionContext()))
+            continue;
+
+        // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's WebSockets
+        auto* document = downcast<Document>(webSocket->scriptExecutionContext());
+        if (document->page() != &m_pageAgent->page())
+            continue;
+
+        webSockets.append(webSocket);
+    }
+
+    return webSockets;
+}
+
+void PageNetworkAgent::setResourceCachingDisabled(bool disabled)
+{
+    m_pageAgent->page().setResourceCachingDisabledOverride(disabled);
+}
+
+ScriptExecutionContext* PageNetworkAgent::scriptExecutionContext(ErrorString& errorString, const String& frameId)
+{
+    auto* frame = m_pageAgent->assertFrame(errorString, frameId);
+    if (!frame)
+        return nullptr;
+
+    auto* document = frame->document();
+    if (!document) {
+        errorString = ASCIILiteral("No Document instance for the specified frame");
+        return nullptr;
+    }
+
+    return document;
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentspagePageNetworkAgenthfromrev224787trunkSourceWebCoreinspectoragentsworkerWorkerConsoleAgentcpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.h (from rev 224787, trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp) (0 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.h                            (rev 0)
+++ trunk/Source/WebCore/inspector/agents/page/PageNetworkAgent.h       2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "InspectorNetworkAgent.h"
+
+namespace WebCore {
+
+class PageNetworkAgent final : public InspectorNetworkAgent {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    PageNetworkAgent(PageAgentContext&, InspectorPageAgent*);
+    virtual ~PageNetworkAgent() = default;
+
+private:
+    String loaderIdentifier(DocumentLoader*) final;
+    String frameIdentifier(DocumentLoader*) final;
+    Vector<WebSocket*> activeWebSockets(const LockHolder&) final;
+    void setResourceCachingDisabled(bool) final;
+    ScriptExecutionContext* scriptExecutionContext(ErrorString&, const String& frameId) final;
+
+    InspectorPageAgent* m_pageAgent { nullptr };
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsworkerWorkerConsoleAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp      2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp 2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -26,13 +26,16 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "WorkerConsoleAgent.h"
</span><span class="cx"> 
</span><ins>+#include "WorkerGlobalScope.h"
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><ins>+
</ins><span class="cx"> using namespace Inspector;
</span><span class="cx"> 
</span><span class="cx"> WorkerConsoleAgent::WorkerConsoleAgent(WorkerAgentContext& context, InspectorHeapAgent* heapAgent)
</span><span class="cx">     : WebConsoleAgent(context, heapAgent)
</span><span class="cx"> {
</span><ins>+    ASSERT(context.workerGlobalScope.isContextThread());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsworkerWorkerDebuggerAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp     2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp        2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -34,8 +34,8 @@
</span><span class="cx"> #include <inspector/ScriptCallStack.h>
</span><span class="cx"> #include <inspector/ScriptCallStackFactory.h>
</span><span class="cx"> 
</span><ins>+namespace WebCore {
</ins><span class="cx"> 
</span><del>-namespace WebCore {
</del><span class="cx"> using namespace JSC;
</span><span class="cx"> using namespace Inspector;
</span><span class="cx"> 
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx">     : WebDebuggerAgent(context)
</span><span class="cx">     , m_workerGlobalScope(context.workerGlobalScope)
</span><span class="cx"> {
</span><ins>+    ASSERT(context.workerGlobalScope.isContextThread());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WorkerDebuggerAgent::~WorkerDebuggerAgent() = default;
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsworkerWorkerNetworkAgentcppfromrev224787trunkSourceWebCoreinspectoragentsworkerWorkerConsoleAgentcpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp (from rev 224787, trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp) (0 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp                              (rev 0)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp 2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -0,0 +1,70 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WorkerNetworkAgent.h"
+
+#include "WorkerDebuggerProxy.h"
+#include "WorkerGlobalScope.h"
+#include "WorkerThread.h"
+
+namespace WebCore {
+
+using namespace Inspector;
+
+WorkerNetworkAgent::WorkerNetworkAgent(WorkerAgentContext& context)
+    : InspectorNetworkAgent(context)
+    , m_workerGlobalScope(context.workerGlobalScope)
+{
+    ASSERT(context.workerGlobalScope.isContextThread());
+}
+
+String WorkerNetworkAgent::loaderIdentifier(DocumentLoader*)
+{
+    return { };
+}
+
+String WorkerNetworkAgent::frameIdentifier(DocumentLoader*)
+{
+    return { };
+}
+
+Vector<WebSocket*> WorkerNetworkAgent::activeWebSockets(const LockHolder&)
+{
+    // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display worker's WebSockets
+    return { };
+}
+
+void WorkerNetworkAgent::setResourceCachingDisabled(bool disabled)
+{
+    m_workerGlobalScope.thread().workerDebuggerProxy().setResourceCachingDisabled(disabled);
+}
+
+ScriptExecutionContext* WorkerNetworkAgent::scriptExecutionContext(ErrorString&, const String&)
+{
+    return &m_workerGlobalScope;
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsworkerWorkerNetworkAgenthfromrev224787trunkSourceWebCoreinspectoragentsworkerWorkerConsoleAgentcpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h (from rev 224787, trunk/Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp) (0 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h                                (rev 0)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h   2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "InspectorNetworkAgent.h"
+
+namespace WebCore {
+
+class WorkerNetworkAgent final : public InspectorNetworkAgent {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit WorkerNetworkAgent(WorkerAgentContext&);
+    virtual ~WorkerNetworkAgent() = default;
+
+private:
+    String loaderIdentifier(DocumentLoader*) final;
+    String frameIdentifier(DocumentLoader*) final;
+    Vector<WebSocket*> activeWebSockets(const LockHolder&) final;
+    void setResourceCachingDisabled(bool) final;
+    ScriptExecutionContext* scriptExecutionContext(ErrorString&, const String& frameId) final;
+
+    WorkerGlobalScope& m_workerGlobalScope;
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreinspectoragentsworkerWorkerRuntimeAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp      2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp 2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -37,8 +37,8 @@
</span><span class="cx"> #include <inspector/InjectedScript.h>
</span><span class="cx"> #include <inspector/InjectedScriptManager.h>
</span><span class="cx"> 
</span><ins>+namespace WebCore {
</ins><span class="cx"> 
</span><del>-namespace WebCore {
</del><span class="cx"> using namespace Inspector;
</span><span class="cx"> 
</span><span class="cx"> WorkerRuntimeAgent::WorkerRuntimeAgent(WorkerAgentContext& context)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx">     , m_backendDispatcher(RuntimeBackendDispatcher::create(context.backendDispatcher, this))
</span><span class="cx">     , m_workerGlobalScope(context.workerGlobalScope)
</span><span class="cx"> {
</span><ins>+    ASSERT(context.workerGlobalScope.isContextThread());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WorkerRuntimeAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderThreadableLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ThreadableLoader.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ThreadableLoader.cpp 2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/loader/ThreadableLoader.cpp    2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -102,7 +102,7 @@
</span><span class="cx"> RefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext& context, ThreadableLoaderClient& client, ResourceRequest&& request, const ThreadableLoaderOptions& options, String&& referrer)
</span><span class="cx"> {
</span><span class="cx">     if (is<WorkerGlobalScope>(context))
</span><del>-        return WorkerThreadableLoader::create(downcast<WorkerGlobalScope>(context), client, WorkerRunLoop::defaultMode(), WTFMove(request), options, referrer);
</del><ins>+        return WorkerThreadableLoader::create(downcast<WorkerGlobalScope>(context), client, WorkerRunLoop::defaultMode(), WTFMove(request), options, WTFMove(referrer));
</ins><span class="cx"> 
</span><span class="cx">     return DocumentThreadableLoader::create(downcast<Document>(context), client, WTFMove(request), options, WTFMove(referrer));
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderWorkerThreadableLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp   2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp      2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include "ContentSecurityPolicy.h"
</span><span class="cx"> #include "Document.h"
</span><span class="cx"> #include "DocumentThreadableLoader.h"
</span><ins>+#include "InspectorInstrumentation.h"
</ins><span class="cx"> #include "Performance.h"
</span><span class="cx"> #include "ResourceError.h"
</span><span class="cx"> #include "ResourceRequest.h"
</span><span class="lines">@@ -106,8 +107,8 @@
</span><span class="cx">     : m_workerClientWrapper(&workerClientWrapper)
</span><span class="cx">     , m_loaderProxy(loaderProxy)
</span><span class="cx">     , m_taskMode(taskMode.isolatedCopy())
</span><ins>+    , m_workerRequestIdentifier(globalScope.createUniqueIdentifier())
</ins><span class="cx"> {
</span><del>-
</del><span class="cx">     auto* securityOrigin = globalScope.securityOrigin();
</span><span class="cx">     auto* contentSecurityPolicy = globalScope.contentSecurityPolicy();
</span><span class="cx"> 
</span><span class="lines">@@ -131,6 +132,8 @@
</span><span class="cx">         optionsCopy->options.serviceWorkerIdentifier = activeServiceWorker->identifier();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    InspectorInstrumentation::willSendRequest(globalScope, m_workerRequestIdentifier, request);
+
</ins><span class="cx">     // Can we benefit from request being an r-value to create more efficiently its isolated copy?
</span><span class="cx">     m_loaderProxy.postTaskToLoader([this, request = request.isolatedCopy(), options = WTFMove(optionsCopy), contentSecurityPolicyCopy = WTFMove(contentSecurityPolicyCopy)](ScriptExecutionContext& context) mutable {
</span><span class="cx">         ASSERT(isMainThread());
</span><span class="lines">@@ -195,19 +198,22 @@
</span><span class="cx"> 
</span><span class="cx"> void WorkerThreadableLoader::MainThreadBridge::didReceiveResponse(unsigned long identifier, const ResourceResponse& response)
</span><span class="cx"> {
</span><del>-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), identifier, responseData = response.crossThreadData()] (ScriptExecutionContext& context) mutable {
-        ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-        protectedWorkerClientWrapper->didReceiveResponse(identifier, ResourceResponse::fromCrossThreadData(WTFMove(responseData)));
</del><ins>+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), workerRequestIdentifier = m_workerRequestIdentifier, identifier, responseData = response.crossThreadData()] (ScriptExecutionContext& context) mutable {
+        ASSERT(context.isWorkerGlobalScope());
+        auto response = ResourceResponse::fromCrossThreadData(WTFMove(responseData));
+        protectedWorkerClientWrapper->didReceiveResponse(identifier, response);
+        InspectorInstrumentation::didReceiveResourceResponse(downcast<WorkerGlobalScope>(context), workerRequestIdentifier, response);
</ins><span class="cx">     }, m_taskMode);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WorkerThreadableLoader::MainThreadBridge::didReceiveData(const char* data, int dataLength)
</span><span class="cx"> {
</span><del>-    Vector<char> vector(dataLength);
-    memcpy(vector.data(), data, dataLength);
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), vector = WTFMove(vector)] (ScriptExecutionContext& context) mutable {
-        ASSERT_UNUSED(context, context.isWorkerGlobalScope());
-        protectedWorkerClientWrapper->didReceiveData(vector.data(), vector.size());
</del><ins>+    Vector<char> buffer(dataLength);
+    memcpy(buffer.data(), data, dataLength);
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), workerRequestIdentifier = m_workerRequestIdentifier, buffer = WTFMove(buffer)] (ScriptExecutionContext& context) mutable {
+        ASSERT(context.isWorkerGlobalScope());
+        protectedWorkerClientWrapper->didReceiveData(buffer.data(), buffer.size());
+        InspectorInstrumentation::didReceiveData(downcast<WorkerGlobalScope>(context), workerRequestIdentifier, buffer.data(), buffer.size());
</ins><span class="cx">     }, m_taskMode);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -214,9 +220,10 @@
</span><span class="cx"> void WorkerThreadableLoader::MainThreadBridge::didFinishLoading(unsigned long identifier)
</span><span class="cx"> {
</span><span class="cx">     m_loadingFinished = true;
</span><del>-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), identifier] (ScriptExecutionContext& context) mutable {
-        ASSERT_UNUSED(context, context.isWorkerGlobalScope());
</del><ins>+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), workerRequestIdentifier = m_workerRequestIdentifier, networkLoadMetrics = m_networkLoadMetrics.isolatedCopy(), identifier] (ScriptExecutionContext& context) mutable {
+        ASSERT(context.isWorkerGlobalScope());
</ins><span class="cx">         protectedWorkerClientWrapper->didFinishLoading(identifier);
</span><ins>+        InspectorInstrumentation::didFinishLoading(downcast<WorkerGlobalScope>(context), workerRequestIdentifier, networkLoadMetrics);
</ins><span class="cx">     }, m_taskMode);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -223,17 +230,17 @@
</span><span class="cx"> void WorkerThreadableLoader::MainThreadBridge::didFail(const ResourceError& error)
</span><span class="cx"> {
</span><span class="cx">     m_loadingFinished = true;
</span><del>-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper = Ref<ThreadableLoaderClientWrapper>(*m_workerClientWrapper), error = error.isolatedCopy()] (ScriptExecutionContext& context) mutable {
</del><ins>+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), workerRequestIdentifier = m_workerRequestIdentifier, error = error.isolatedCopy()] (ScriptExecutionContext& context) mutable {
</ins><span class="cx">         ASSERT(context.isWorkerGlobalScope());
</span><del>-
-        ThreadableLoader::logError(context, error, workerClientWrapper->initiator());
-
-        workerClientWrapper->didFail(error);
</del><ins>+        ThreadableLoader::logError(context, error, protectedWorkerClientWrapper->initiator());
+        protectedWorkerClientWrapper->didFail(error);
+        InspectorInstrumentation::didFailLoading(downcast<WorkerGlobalScope>(context), workerRequestIdentifier, error);
</ins><span class="cx">     }, m_taskMode);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WorkerThreadableLoader::MainThreadBridge::didFinishTiming(const ResourceTiming& resourceTiming)
</span><span class="cx"> {
</span><ins>+    m_networkLoadMetrics = resourceTiming.networkLoadMetrics();
</ins><span class="cx">     m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), resourceTiming = resourceTiming.isolatedCopy()] (ScriptExecutionContext& context) mutable {
</span><span class="cx">         ASSERT(context.isWorkerGlobalScope());
</span><span class="cx">         ASSERT(!resourceTiming.initiator().isEmpty());
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderWorkerThreadableLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/WorkerThreadableLoader.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/WorkerThreadableLoader.h     2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/loader/WorkerThreadableLoader.h        2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -117,6 +117,8 @@
</span><span class="cx"> 
</span><span class="cx">             // For use on the main thread.
</span><span class="cx">             String m_taskMode;
</span><ins>+            unsigned long m_workerRequestIdentifier { 0 };
+            NetworkLoadMetrics m_networkLoadMetrics;
</ins><span class="cx">         };
</span><span class="cx"> 
</span><span class="cx">         WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient&, const String& taskMode, ResourceRequest&&, const ThreadableLoaderOptions&, const String& referrer);
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersWorkerDebuggerProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/WorkerDebuggerProxy.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/WorkerDebuggerProxy.h       2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/workers/WorkerDebuggerProxy.h  2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> public:
</span><span class="cx">     virtual ~WorkerDebuggerProxy() = default;
</span><span class="cx">     virtual void postMessageToDebugger(const String&) = 0;
</span><ins>+    virtual void setResourceCachingDisabled(bool) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersWorkerGlobalScopeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/WorkerGlobalScope.h 2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h    2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -64,6 +64,7 @@
</span><span class="cx"> 
</span><span class="cx">     const URL& url() const final { return m_url; }
</span><span class="cx">     String origin() const final;
</span><ins>+    const String& identifier() const { return m_identifier; }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">     IDBClient::IDBConnectionProxy* idbConnectionProxy() final;
</span><span class="lines">@@ -118,6 +119,8 @@
</span><span class="cx">     void createImageBitmap(ImageBitmap::Source&&, ImageBitmapOptions&&, ImageBitmap::Promise&&);
</span><span class="cx">     void createImageBitmap(ImageBitmap::Source&&, int sx, int sy, int sw, int sh, ImageBitmapOptions&&, ImageBitmap::Promise&&);
</span><span class="cx"> 
</span><ins>+    unsigned long createUniqueIdentifier() { return m_uniqueIdentifier++; }
+
</ins><span class="cx"> protected:
</span><span class="cx">     WorkerGlobalScope(const URL&, const String& identifier, const String& userAgent, bool isOnline, WorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, PAL::SessionID);
</span><span class="cx"> 
</span><span class="lines">@@ -196,6 +199,8 @@
</span><span class="cx"> 
</span><span class="cx">     PAL::SessionID m_sessionID;
</span><span class="cx">     RefPtr<WorkerCacheStorageConnection> m_cacheStorageConnection;
</span><ins>+
+    unsigned long m_uniqueIdentifier { 1 };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersWorkerMessagingProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp    2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp       2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -177,6 +177,15 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WorkerMessagingProxy::setResourceCachingDisabled(bool disabled)
+{
+    postTaskToLoader([disabled] (ScriptExecutionContext& context) {
+        ASSERT(isMainThread());
+        if (auto* page = downcast<Document>(context).page())
+            page->setResourceCachingDisabled(disabled);
+    });
+}
+
</ins><span class="cx"> void WorkerMessagingProxy::workerThreadCreated(DedicatedWorkerThread& workerThread)
</span><span class="cx"> {
</span><span class="cx">     m_workerThread = &workerThread;
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersWorkerMessagingProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/WorkerMessagingProxy.h      2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.h 2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx">     // Implementation of WorkerDebuggerProxy.
</span><span class="cx">     // (Only use these functions in the worker context thread.)
</span><span class="cx">     void postMessageToDebugger(const String&) final;
</span><ins>+    void setResourceCachingDisabled(bool) final;
</ins><span class="cx"> 
</span><span class="cx">     // Implementation of WorkerLoaderProxy.
</span><span class="cx">     // These functions are called on different threads to schedule loading
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersservicecontextServiceWorkerThreadProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp        2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp   2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -89,6 +89,14 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ServiceWorkerThreadProxy::setResourceCachingDisabled(bool disabled)
+{
+    postTaskToLoader([this, protectedThis = makeRef(*this), disabled] (ScriptExecutionContext&) {
+        ASSERT(isMainThread());
+        m_page->setResourceCachingDisabled(disabled);
+    });   
+}
+
</ins><span class="cx"> Ref<CacheStorageConnection> ServiceWorkerThreadProxy::createCacheStorageConnection()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersservicecontextServiceWorkerThreadProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h (224787 => 224788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h  2017-11-13 23:10:03 UTC (rev 224787)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h     2017-11-13 23:15:57 UTC (rev 224788)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx"> 
</span><span class="cx">     // WorkerDebuggerProxy
</span><span class="cx">     void postMessageToDebugger(const String&) final;
</span><ins>+    void setResourceCachingDisabled(bool) final;
</ins><span class="cx"> 
</span><span class="cx">     UniqueRef<Page> m_page;
</span><span class="cx">     Ref<Document> m_document;
</span></span></pre>
</div>
</div>

</body>
</html>