Web Inspector: Include a NetworkAgent in ServiceWorkers for network debugging
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2017 23:15:57 +0000 (23:15 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2017 23:15:57 +0000 (23:15 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224788 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/inspector/InspectorAllInOne.cpp
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebCore/inspector/WorkerInspectorController.h
Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Source/WebCore/inspector/agents/InspectorNetworkAgent.h
Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp [new file with mode: 0644]
Source/WebCore/inspector/agents/page/PageNetworkAgent.h [new file with mode: 0644]
Source/WebCore/inspector/agents/worker/WorkerConsoleAgent.cpp
Source/WebCore/inspector/agents/worker/WorkerDebuggerAgent.cpp
Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp [new file with mode: 0644]
Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h [new file with mode: 0644]
Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.h
Source/WebCore/workers/WorkerDebuggerProxy.h
Source/WebCore/workers/WorkerGlobalScope.h
Source/WebCore/workers/WorkerMessagingProxy.cpp
Source/WebCore/workers/WorkerMessagingProxy.h
Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp
Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h

index acec808..3a77049 100644 (file)
@@ -1,3 +1,163 @@
+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.
+
 2017-11-08  Keith Miller  <keith_miller@apple.com>
 
         Async iteration should only fetch the next method once and add feature flag
index 239d699..b916926 100644 (file)
@@ -1150,10 +1150,12 @@ inspector/agents/WebHeapAgent.cpp
 inspector/agents/page/PageConsoleAgent.cpp
 inspector/agents/page/PageDebuggerAgent.cpp
 inspector/agents/page/PageHeapAgent.cpp
+inspector/agents/page/PageNetworkAgent.cpp
 inspector/agents/page/PageRuntimeAgent.cpp
 
 inspector/agents/worker/WorkerConsoleAgent.cpp
 inspector/agents/worker/WorkerDebuggerAgent.cpp
+inspector/agents/worker/WorkerNetworkAgent.cpp
 inspector/agents/worker/WorkerRuntimeAgent.cpp
 
 loader/ContentFilter.cpp
index bdeb040..a4f8c04 100644 (file)
                A5B81CCD1FAA44DE0037D1E6 /* WorkerConsoleAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5B81CCA1FAA44DA0037D1E6 /* WorkerConsoleAgent.h */; };
                A5B81CCE1FAA44DE0037D1E6 /* WorkerDebuggerAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5B81CCC1FAA44DA0037D1E6 /* WorkerDebuggerAgent.h */; };
                A5B81CCF1FAA44DE0037D1E6 /* WorkerRuntimeAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5B81CC91FAA44DA0037D1E6 /* WorkerRuntimeAgent.h */; };
+               A5CB05241FB51F3300089B97 /* PageNetworkAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CB05211FB51F1700089B97 /* PageNetworkAgent.h */; };
+               A5CB05251FB51F3A00089B97 /* WorkerNetworkAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CB05231FB51F2400089B97 /* WorkerNetworkAgent.h */; };
                A5CE9F3F1E4C4174001BBE7C /* ResourceTiming.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE9F3C1E4BC586001BBE7C /* ResourceTiming.h */; };
                A5DEBDA416FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A5DEBDA016FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.h */; };
                A5F36D3B18F758720054C024 /* PageScriptDebugServer.h in Headers */ = {isa = PBXBuildFile; fileRef = A5F36D3918F758720054C024 /* PageScriptDebugServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A5B81CCC1FAA44DA0037D1E6 /* WorkerDebuggerAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerDebuggerAgent.h; sourceTree = "<group>"; };
                A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyEventCocoa.h; sourceTree = "<group>"; };
                A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyEventCocoa.mm; sourceTree = "<group>"; };
+               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>"; };
                A5CE9F3C1E4BC586001BBE7C /* ResourceTiming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceTiming.h; sourceTree = "<group>"; };
                A5CE9F3E1E4C416B001BBE7C /* ResourceTiming.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceTiming.cpp; sourceTree = "<group>"; };
                A5DEBD9F16FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitPlaybackTargetAvailabilityEvent.cpp; sourceTree = "<group>"; };
                                A5B81CBE1FAA44B70037D1E6 /* PageDebuggerAgent.h */,
                                A5B81CBA1FAA44B70037D1E6 /* PageHeapAgent.cpp */,
                                A5B81CBC1FAA44B70037D1E6 /* PageHeapAgent.h */,
+                               A5CB051F1FB51F1600089B97 /* PageNetworkAgent.cpp */,
+                               A5CB05211FB51F1700089B97 /* PageNetworkAgent.h */,
                                A5B81CC11FAA44B70037D1E6 /* PageRuntimeAgent.cpp */,
                                A5B81CBF1FAA44B70037D1E6 /* PageRuntimeAgent.h */,
                        );
                                A5B81CCA1FAA44DA0037D1E6 /* WorkerConsoleAgent.h */,
                                A5B81CC81FAA44DA0037D1E6 /* WorkerDebuggerAgent.cpp */,
                                A5B81CCC1FAA44DA0037D1E6 /* WorkerDebuggerAgent.h */,
+                               A5CB05221FB51F2300089B97 /* WorkerNetworkAgent.cpp */,
+                               A5CB05231FB51F2400089B97 /* WorkerNetworkAgent.h */,
                                A5B81CC71FAA44DA0037D1E6 /* WorkerRuntimeAgent.cpp */,
                                A5B81CC91FAA44DA0037D1E6 /* WorkerRuntimeAgent.h */,
                        );
                                9302B0BF0D79F82C00C7EE83 /* PageGroup.h in Headers */,
                                7A674BDC0F9EBF4E006CF099 /* PageGroupLoadDeferrer.h in Headers */,
                                A5B81CC41FAA44BC0037D1E6 /* PageHeapAgent.h in Headers */,
+                               A5CB05241FB51F3300089B97 /* PageNetworkAgent.h in Headers */,
                                2D5C9D0019C7B52E00B3C5C1 /* PageOverlay.h in Headers */,
                                2D5C9D0219C7B52E00B3C5C1 /* PageOverlayController.h in Headers */,
                                FBDB61A116D6037E00BB3394 /* PageRuleCollector.h in Headers */,
                                2E4346500F546A8200B0F1BA /* WorkerMessagingProxy.h in Headers */,
                                E1271A0B0EEEC77A00F61213 /* WorkerNavigator.h in Headers */,
                                1ABC7109170E5E1B00F9A9D6 /* WorkerNavigatorStorageQuota.h in Headers */,
+                               A5CB05251FB51F3A00089B97 /* WorkerNetworkAgent.h in Headers */,
                                2E4346510F546A8200B0F1BA /* WorkerObjectProxy.h in Headers */,
                                416E29A6102FA962007FC14E /* WorkerReportingProxy.h in Headers */,
                                2E4346530F546A8200B0F1BA /* WorkerRunLoop.h in Headers */,
index e89e669..939651a 100644 (file)
@@ -57,6 +57,7 @@
 #include "PageConsoleAgent.cpp"
 #include "PageDebuggerAgent.cpp"
 #include "PageHeapAgent.cpp"
+#include "PageNetworkAgent.cpp"
 #include "PageRuntimeAgent.cpp"
 #include "PageScriptDebugServer.cpp"
 #include "TimelineRecordFactory.cpp"
@@ -68,5 +69,6 @@
 #include "WorkerConsoleAgent.cpp"
 #include "WorkerDebuggerAgent.cpp"
 #include "WorkerInspectorController.cpp"
+#include "WorkerNetworkAgent.cpp"
 #include "WorkerRuntimeAgent.cpp"
 #include "WorkerScriptDebugServer.cpp"
index a523ccd..ab3bdfc 100644 (file)
@@ -50,7 +50,6 @@
 #include "InspectorInstrumentation.h"
 #include "InspectorLayerTreeAgent.h"
 #include "InspectorMemoryAgent.h"
-#include "InspectorNetworkAgent.h"
 #include "InspectorPageAgent.h"
 #include "InspectorTimelineAgent.h"
 #include "InspectorWorkerAgent.h"
@@ -64,6 +63,7 @@
 #include "PageConsoleAgent.h"
 #include "PageDebuggerAgent.h"
 #include "PageHeapAgent.h"
+#include "PageNetworkAgent.h"
 #include "PageRuntimeAgent.h"
 #include "PageScriptDebugServer.h"
 #include "Settings.h"
@@ -149,15 +149,8 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     m_agents.append(WTFMove(canvasAgentPtr));
 
     ASSERT(m_injectedScriptManager->commandLineAPIHost());
-    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost()) {
-        commandLineAPIHost->init(
-              m_inspectorAgent
-            , consoleAgent
-            , m_domAgent
-            , domStorageAgent
-            , databaseAgent
-        );
-    }
+    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
+        commandLineAPIHost->init(m_inspectorAgent, consoleAgent, m_domAgent, domStorageAgent, databaseAgent);
 }
 
 InspectorController::~InspectorController()
@@ -201,7 +194,7 @@ void InspectorController::createLazyAgents()
     auto debuggerAgentPtr = debuggerAgent.get();
 
     m_agents.append(WTFMove(debuggerAgent));
-    m_agents.append(std::make_unique<InspectorNetworkAgent>(pageContext, m_pageAgent));
+    m_agents.append(std::make_unique<PageNetworkAgent>(pageContext, m_pageAgent));
     m_agents.append(std::make_unique<InspectorCSSAgent>(pageContext, m_domAgent));
     m_agents.append(std::make_unique<InspectorDOMDebuggerAgent>(pageContext, m_domAgent, debuggerAgentPtr));
     m_agents.append(std::make_unique<InspectorApplicationCacheAgent>(pageContext, m_pageAgent));
index a04e3be..487ac04 100644 (file)
@@ -560,20 +560,14 @@ void InspectorInstrumentation::applyEmulatedMediaImpl(InstrumentingAgents& instr
 
 void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
 {
-    if (!loader)
-        return;
-
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->willSendRequest(identifier, *loader, request, redirectResponse);
+        networkAgent->willSendRequest(identifier, loader, request, redirectResponse);
 }
 
 void InspectorInstrumentation::willSendRequestOfTypeImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, LoadType loadType)
 {
-    if (!loader)
-        return;
-
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->willSendRequestOfType(identifier, *loader, request, loadType);
+        networkAgent->willSendRequestOfType(identifier, loader, request, loadType);
 }
 
 void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingAgents& instrumentingAgents, DocumentLoader* loader, CachedResource* cachedResource)
@@ -585,16 +579,13 @@ void InspectorInstrumentation::didLoadResourceFromMemoryCacheImpl(InstrumentingA
         return;
 
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->didLoadResourceFromMemoryCache(*loader, *cachedResource);
+        networkAgent->didLoadResourceFromMemoryCache(loader, *cachedResource);
 }
 
 void InspectorInstrumentation::didReceiveResourceResponseImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
 {
-    if (!loader)
-        return;
-
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->didReceiveResponse(identifier, *loader, response, resourceLoader);
+        networkAgent->didReceiveResponse(identifier, loader, response, resourceLoader);
     if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
         consoleAgent->didReceiveResponse(identifier, response); // This should come AFTER resource notification, front-end relies on this.
 }
@@ -613,20 +604,14 @@ void InspectorInstrumentation::didReceiveDataImpl(InstrumentingAgents& instrumen
 
 void InspectorInstrumentation::didFinishLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
 {
-    if (!loader)
-        return;
-
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->didFinishLoading(identifier, *loader, networkLoadMetrics, resourceLoader);
+        networkAgent->didFinishLoading(identifier, loader, networkLoadMetrics, resourceLoader);
 }
 
 void InspectorInstrumentation::didFailLoadingImpl(InstrumentingAgents& instrumentingAgents, unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
 {
-    if (!loader)
-        return;
-
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
-        networkAgent->didFailLoading(identifier, *loader, error);
+        networkAgent->didFailLoading(identifier, loader, error);
     if (WebConsoleAgent* consoleAgent = instrumentingAgents.webConsoleAgent())
         consoleAgent->didFailLoading(identifier, error); // This should come AFTER resource notification, front-end relies on this.
 }
@@ -697,7 +682,6 @@ void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents&
 {
     if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
         pageAgent->frameDetached(frame);
-
 }
 
 void InspectorInstrumentation::didCommitLoadImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, DocumentLoader* loader)
index fc40e01..f846b0a 100644 (file)
@@ -177,9 +177,12 @@ public:
     static void didReceiveData(Frame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
     static void didFinishLoading(Frame*, DocumentLoader*, unsigned long identifier, const NetworkLoadMetrics&, ResourceLoader*);
     static void didFailLoading(Frame*, DocumentLoader*, unsigned long identifier, const ResourceError&);
-    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&);
+
+    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&);
 
     // Some network requests do not go through the normal network loading path.
     // These network requests have to issue their own willSendRequest / didReceiveResponse / didFinishLoading / didFailLoading
@@ -187,6 +190,9 @@ public:
     enum class LoadType { Ping, Beacon };
     static void willSendRequestOfType(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, LoadType);
 
+    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&);
     static void didFinishXHRLoading(ScriptExecutionContext*, unsigned long identifier, std::optional<String> decodedText);
     static void willLoadXHRSynchronously(ScriptExecutionContext*);
     static void didLoadXHRSynchronously(ScriptExecutionContext*);
@@ -907,6 +913,12 @@ inline void InspectorInstrumentation::willSendRequest(Frame* frame, unsigned lon
         willSendRequestImpl(*instrumentingAgents, identifier, loader, request, redirectResponse);
 }
 
+inline void InspectorInstrumentation::willSendRequest(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, ResourceRequest& request)
+{
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    willSendRequestImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, request, ResourceResponse { });
+}
+
 inline void InspectorInstrumentation::willSendRequestOfType(Frame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, LoadType loadType)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
@@ -926,6 +938,11 @@ inline void InspectorInstrumentation::didReceiveResourceResponse(Frame& frame, u
         didReceiveResourceResponseImpl(*instrumentingAgents, identifier, loader, response, resourceLoader);
 }
 
+inline void InspectorInstrumentation::didReceiveResourceResponse(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const ResourceResponse& response)
+{
+    didReceiveResourceResponseImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, response, nullptr);
+}
+
 inline void InspectorInstrumentation::didReceiveThreadableLoaderResponse(DocumentThreadableLoader& documentThreadableLoader, unsigned long identifier)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
@@ -940,18 +957,36 @@ inline void InspectorInstrumentation::didReceiveData(Frame* frame, unsigned long
         didReceiveDataImpl(*instrumentingAgents, identifier, data, dataLength, encodedDataLength);
 }
 
+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);
+}
+
 inline void InspectorInstrumentation::didFinishLoading(Frame* frame, DocumentLoader* loader, unsigned long identifier, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
 {
+    FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
         didFinishLoadingImpl(*instrumentingAgents, identifier, loader, networkLoadMetrics, resourceLoader);
 }
 
+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);
+}
+
 inline void InspectorInstrumentation::didFailLoading(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
 {
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
         didFailLoadingImpl(*instrumentingAgents, identifier, loader, error);
 }
 
+inline void InspectorInstrumentation::didFailLoading(WorkerGlobalScope& workerGlobalScope, unsigned long identifier, const ResourceError& error)
+{
+    didFailLoadingImpl(instrumentingAgentsForWorkerGlobalScope(workerGlobalScope), identifier, nullptr, error);
+}
+
 inline void InspectorInstrumentation::continueAfterXFrameOptionsDenied(Frame& frame, unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response)
 {
     // Treat the same as didReceiveResponse.
index 5f4313a..642c49d 100644 (file)
@@ -35,6 +35,7 @@
 #include "WorkerConsoleAgent.h"
 #include "WorkerDebuggerAgent.h"
 #include "WorkerGlobalScope.h"
+#include "WorkerNetworkAgent.h"
 #include "WorkerRuntimeAgent.h"
 #include "WorkerThread.h"
 #include "WorkerToPageFrontendChannel.h"
 #include <inspector/InspectorFrontendChannel.h>
 #include <inspector/InspectorFrontendDispatchers.h>
 #include <inspector/InspectorFrontendRouter.h>
+#include <inspector/agents/InspectorAgent.h>
 
+#if ENABLE(SERVICE_WORKER)
+#include "ServiceWorkerGlobalScope.h"
+#endif
 
 namespace WebCore {
+
 using namespace JSC;
 using namespace Inspector;
 
@@ -58,43 +64,25 @@ WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope& workerGl
     , m_scriptDebugServer(workerGlobalScope)
     , m_workerGlobalScope(workerGlobalScope)
 {
-    AgentContext baseContext = {
-        *this,
-        *m_injectedScriptManager,
-        m_frontendRouter.get(),
-        m_backendDispatcher.get(),
-    };
+    ASSERT(workerGlobalScope.isContextThread());
 
-    WebAgentContext webContext = {
-        baseContext,
-        m_instrumentingAgents.get(),
-    };
-
-    WorkerAgentContext workerContext = {
-        webContext,
-        workerGlobalScope,
-    };
+    auto workerContext = workerAgentContext();
 
+    auto inspectorAgent = std::make_unique<InspectorAgent>(workerContext);
     auto heapAgent = std::make_unique<WebHeapAgent>(workerContext);
+    auto consoleAgent = std::make_unique<WorkerConsoleAgent>(workerContext, heapAgent.get());
 
+    m_instrumentingAgents->setInspectorAgent(inspectorAgent.get());
+    m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
+
+    m_agents.append(WTFMove(inspectorAgent));
     m_agents.append(std::make_unique<WorkerRuntimeAgent>(workerContext));
     m_agents.append(std::make_unique<WorkerDebuggerAgent>(workerContext));
-
-    auto consoleAgent = std::make_unique<WorkerConsoleAgent>(workerContext, heapAgent.get());
-    m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
     m_agents.append(WTFMove(consoleAgent));
-
     m_agents.append(WTFMove(heapAgent));
 
-    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost()) {
-        commandLineAPIHost->init(
-              nullptr // InspectorAgent
-            , m_instrumentingAgents->webConsoleAgent()
-            , nullptr // InspectorDOMAgent
-            , nullptr // InspectorDOMStorageAgent
-            , nullptr // InspectorDatabaseAgent
-        );
-    }
+    if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
+        commandLineAPIHost->init(m_instrumentingAgents->inspectorAgent(), m_instrumentingAgents->webConsoleAgent(), nullptr, nullptr, nullptr);
 }
 
 WorkerInspectorController::~WorkerInspectorController()
@@ -119,6 +107,13 @@ void WorkerInspectorController::connectFrontend()
     ASSERT(!m_frontendRouter->hasFrontends());
     ASSERT(!m_forwardingChannel);
 
+    createLazyAgents();
+
+    InspectorInstrumentation::frontendCreated();
+
+    m_executionStopwatch->reset();
+    m_executionStopwatch->start();
+
     m_forwardingChannel = std::make_unique<WorkerToPageFrontendChannel>(m_workerGlobalScope);
     m_frontendRouter->connectFrontend(m_forwardingChannel.get());
     m_agents.didCreateFrontendAndBackend(&m_frontendRouter.get(), &m_backendDispatcher.get());
@@ -131,6 +126,8 @@ void WorkerInspectorController::disconnectFrontend(Inspector::DisconnectReason r
 
     ASSERT(m_forwardingChannel);
 
+    InspectorInstrumentation::frontendDeleted();
+
     m_agents.willDestroyFrontendAndBackend(reason);
     m_frontendRouter->disconnectFrontend(m_forwardingChannel.get());
     m_forwardingChannel = nullptr;
@@ -141,6 +138,42 @@ void WorkerInspectorController::dispatchMessageFromFrontend(const String& messag
     m_backendDispatcher->dispatch(message);
 }
 
+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
+}
+
 InspectorFunctionCallHandler WorkerInspectorController::functionCallHandler() const
 {
     return WebCore::functionCallHandlerFromAnyThread;
index f92d5ef..0b4c247 100644 (file)
@@ -42,6 +42,7 @@ namespace WebCore {
 class InstrumentingAgents;
 class WebInjectedScriptManager;
 class WorkerGlobalScope;
+struct WorkerAgentContext;
 
 class WorkerInspectorController final : public Inspector::InspectorEnvironment {
     WTF_MAKE_NONCOPYABLE(WorkerInspectorController);
@@ -70,6 +71,9 @@ public:
 private:
     friend class InspectorInstrumentation;
 
+    WorkerAgentContext workerAgentContext();
+    void createLazyAgents();
+
     Ref<InstrumentingAgents> m_instrumentingAgents;
     std::unique_ptr<WebInjectedScriptManager> m_injectedScriptManager;
     Ref<Inspector::FrontendRouter> m_frontendRouter;
@@ -79,6 +83,7 @@ private:
     Inspector::AgentRegistry m_agents;
     WorkerGlobalScope& m_workerGlobalScope;
     std::unique_ptr<Inspector::FrontendChannel> m_forwardingChannel;
+    bool m_didCreateLazyAgents { false };
 };
 
 } // namespace WebCore
index d75c90a..ee21bea 100644 (file)
 #include <wtf/Stopwatch.h>
 #include <wtf/text/StringBuilder.h>
 
-
 typedef Inspector::NetworkBackendDispatcherHandler::LoadResourceCallback LoadResourceCallback;
 
 namespace WebCore {
+
 using namespace Inspector;
 
 namespace {
@@ -89,7 +89,9 @@ class InspectorThreadableLoaderClient final : public ThreadableLoaderClient {
     WTF_MAKE_NONCOPYABLE(InspectorThreadableLoaderClient);
 public:
     InspectorThreadableLoaderClient(RefPtr<LoadResourceCallback>&& callback)
-        : m_callback(WTFMove(callback)) { }
+        : m_callback(WTFMove(callback))
+    {
+    }
 
     virtual ~InspectorThreadableLoaderClient() = default;
 
@@ -157,12 +159,11 @@ private:
 
 } // namespace
 
-InspectorNetworkAgent::InspectorNetworkAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
+InspectorNetworkAgent::InspectorNetworkAgent(WebAgentContext& context)
     : InspectorAgentBase(ASCIILiteral("Network"), context)
     , m_frontendDispatcher(std::make_unique<Inspector::NetworkFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::NetworkBackendDispatcher::create(context.backendDispatcher, this))
     , m_injectedScriptManager(context.injectedScriptManager)
-    , m_pageAgent(pageAgent)
     , m_resourcesData(std::make_unique<NetworkResourcesData>())
 {
 }
@@ -336,7 +337,7 @@ double InspectorNetworkAgent::timestamp()
     return m_environment.executionStopwatch()->elapsedTime();
 }
 
-void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader& loader, ResourceRequest& request, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType type)
+void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType type)
 {
     if (request.hiddenFromInspector()) {
         m_hiddenRequestIdentifiers.add(identifier);
@@ -347,15 +348,17 @@ void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLo
     double walltime = currentTime();
 
     String requestId = IdentifiersFactory::requestId(identifier);
-    String loaderId = m_pageAgent->loaderId(&loader);
+    String frameId = frameIdentifier(loader);
+    String loaderId = loaderIdentifier(loader);
+    String targetId = request.initiatorIdentifier();
 
     if (type == InspectorPageAgent::OtherResource) {
         if (m_loadingXHRSynchronously)
             type = InspectorPageAgent::XHRResource;
-        else if (equalIgnoringFragmentIdentifier(request.url(), loader.url()) && !loader.isCommitted())
+        else if (loader && equalIgnoringFragmentIdentifier(request.url(), loader->url()) && !loader->isCommitted())
             type = InspectorPageAgent::DocumentResource;
-        else {
-            for (auto& linkIcon : loader.linkIcons()) {
+        else if (loader) {
+            for (auto& linkIcon : loader->linkIcons()) {
                 if (equalIgnoringFragmentIdentifier(request.url(), linkIcon.url)) {
                     type = InspectorPageAgent::ImageResource;
                     break;
@@ -371,10 +374,11 @@ void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLo
 
     auto protocolResourceType = InspectorPageAgent::resourceTypeJSON(type);
 
-    RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader.frame() ? loader.frame()->document() : nullptr);
-    String targetId = request.initiatorIdentifier();
+    Document* document = loader && loader->frame() ? loader->frame()->document() : nullptr;
+    auto initiatorObject = buildInitiatorObject(document);
 
-    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);
+    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);
 }
 
 static InspectorPageAgent::ResourceType resourceTypeForCachedResource(CachedResource* resource)
@@ -397,18 +401,18 @@ static InspectorPageAgent::ResourceType resourceTypeForLoadType(InspectorInstrum
     return InspectorPageAgent::OtherResource;
 }
 
-void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader& loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
+void InspectorNetworkAgent::willSendRequest(unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
 {
-    auto* cachedResource = InspectorPageAgent::cachedResource(loader.frame(), request.url());
+    auto* cachedResource = loader ? InspectorPageAgent::cachedResource(loader->frame(), request.url()) : nullptr;
     willSendRequest(identifier, loader, request, redirectResponse, resourceTypeForCachedResource(cachedResource));
 }
 
-void InspectorNetworkAgent::willSendRequestOfType(unsigned long identifier, DocumentLoader& loader, ResourceRequest& request, InspectorInstrumentation::LoadType loadType)
+void InspectorNetworkAgent::willSendRequestOfType(unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, InspectorInstrumentation::LoadType loadType)
 {
     willSendRequest(identifier, loader, request, ResourceResponse(), resourceTypeForLoadType(loadType));
 }
 
-void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, DocumentLoader& loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
+void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader)
 {
     if (m_hiddenRequestIdentifiers.contains(identifier))
         return;
@@ -421,8 +425,8 @@ void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, Documen
     CachedResource* cachedResource = nullptr;
     if (resourceLoader && resourceLoader->isSubresourceLoader() && !isNotModified)
         cachedResource = static_cast<SubresourceLoader*>(resourceLoader)->cachedResource();
-    if (!cachedResource)
-        cachedResource = InspectorPageAgent::cachedResource(loader.frame(), response.url());
+    if (!cachedResource && loader)
+        cachedResource = InspectorPageAgent::cachedResource(loader->frame(), response.url());
 
     if (cachedResource) {
         // Use mime type from cached resource in case the one in response is empty.
@@ -439,8 +443,8 @@ void InspectorNetworkAgent::didReceiveResponse(unsigned long identifier, Documen
     if (type != newType && newType != InspectorPageAgent::XHRResource && newType != InspectorPageAgent::OtherResource)
         type = newType;
 
-    String frameId = m_pageAgent->frameId(loader.frame());
-    String loaderId = m_pageAgent->loaderId(&loader);
+    String frameId = frameIdentifier(loader);
+    String loaderId = loaderIdentifier(loader);
 
     m_resourcesData->responseReceived(requestId, frameId, response, type);
 
@@ -473,7 +477,7 @@ void InspectorNetworkAgent::didReceiveData(unsigned long identifier, const char*
     m_frontendDispatcher->dataReceived(requestId, timestamp(), dataLength, encodedDataLength);
 }
 
-void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentLoader& loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
+void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentLoader* loader, const NetworkLoadMetrics& networkLoadMetrics, ResourceLoader* resourceLoader)
 {
     if (m_hiddenRequestIdentifiers.remove(identifier))
         return;
@@ -487,8 +491,8 @@ void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentL
         elapsedFinishTime = timestamp();
 
     String requestId = IdentifiersFactory::requestId(identifier);
-    if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource)
-        m_resourcesData->addResourceSharedBuffer(requestId, loader.frameLoader()->documentLoader()->mainResourceData(), loader.frame()->document()->encoding());
+    if (loader && m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource)
+        m_resourcesData->addResourceSharedBuffer(requestId, loader->frameLoader()->documentLoader()->mainResourceData(), loader->frame()->document()->encoding());
 
     m_resourcesData->maybeDecodeDataToContent(requestId);
 
@@ -502,15 +506,15 @@ void InspectorNetworkAgent::didFinishLoading(unsigned long identifier, DocumentL
     m_frontendDispatcher->loadingFinished(requestId, elapsedFinishTime, !sourceMappingURL.isEmpty() ? &sourceMappingURL : nullptr, metrics);
 }
 
-void InspectorNetworkAgent::didFailLoading(unsigned long identifier, DocumentLoader& loader, const ResourceError& error)
+void InspectorNetworkAgent::didFailLoading(unsigned long identifier, DocumentLoader* loader, const ResourceError& error)
 {
     if (m_hiddenRequestIdentifiers.remove(identifier))
         return;
 
     String requestId = IdentifiersFactory::requestId(identifier);
 
-    if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
-        Frame* frame = loader.frame();
+    if (loader && m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
+        Frame* frame = loader->frame();
         if (frame && frame->loader().documentLoader() && frame->document()) {
             m_resourcesData->addResourceSharedBuffer(requestId,
                 frame->loader().documentLoader()->mainResourceData(),
@@ -522,22 +526,26 @@ void InspectorNetworkAgent::didFailLoading(unsigned long identifier, DocumentLoa
     m_frontendDispatcher->loadingFailed(requestId, timestamp(), error.localizedDescription(), canceled ? &canceled : nullptr);
 }
 
-void InspectorNetworkAgent::didLoadResourceFromMemoryCache(DocumentLoader& loader, CachedResource& resource)
+void InspectorNetworkAgent::didLoadResourceFromMemoryCache(DocumentLoader* loader, CachedResource& resource)
 {
-    unsigned long identifier = loader.frame()->page()->progress().createUniqueIdentifier();
+    ASSERT(loader);
+    if (!loader)
+        return;
+
+    unsigned long identifier = loader->frame()->page()->progress().createUniqueIdentifier();
     String requestId = IdentifiersFactory::requestId(identifier);
-    String loaderId = m_pageAgent->loaderId(&loader);
-    String frameId = m_pageAgent->frameId(loader.frame());
+    String loaderId = loaderIdentifier(loader);
+    String frameId = frameIdentifier(loader);
 
     m_resourcesData->resourceCreated(requestId, loaderId, resource);
 
-    RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader.frame() ? loader.frame()->document() : nullptr);
+    RefPtr<Inspector::Protocol::Network::Initiator> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : nullptr);
 
     // FIXME: It would be ideal to generate the Network.Response with the MemoryCache source
     // instead of whatever ResourceResponse::Source the CachedResources's response has.
     // The frontend already knows for certain that this was served from the memory cache.
 
-    m_frontendDispatcher->requestServedFromMemoryCache(requestId, frameId, loaderId, loader.url().string(), timestamp(), initiatorObject, buildObjectForCachedResource(&resource));
+    m_frontendDispatcher->requestServedFromMemoryCache(requestId, frameId, loaderId, loader->url().string(), timestamp(), initiatorObject, buildObjectForCachedResource(&resource));
 }
 
 void InspectorNetworkAgent::setInitialScriptContent(unsigned long identifier, const String& sourceString)
@@ -607,6 +615,13 @@ void InspectorNetworkAgent::didScheduleStyleRecalculation(Document& document)
 
 RefPtr<Inspector::Protocol::Network::Initiator> InspectorNetworkAgent::buildInitiatorObject(Document* document)
 {
+    // FIXME: Worker support.
+    if (!isMainThread()) {
+        return Inspector::Protocol::Network::Initiator::create()
+            .setType(Inspector::Protocol::Network::Initiator::Type::Other)
+            .release();
+    }
+
     Ref<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState());
     if (stackTrace->size() > 0) {
         auto initiatorObject = Inspector::Protocol::Network::Initiator::create()
@@ -698,29 +713,23 @@ void InspectorNetworkAgent::enable()
     m_enabled = true;
     m_instrumentingAgents.setInspectorNetworkAgent(this);
 
-    LockHolder lock(WebSocket::allActiveWebSocketsMutex());
-
-    for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
-        if (!is<Document>(webSocket->scriptExecutionContext()) || !is<WebSocketChannel>(webSocket->channel().get()))
-            continue;
-
-        Document* document = downcast<Document>(webSocket->scriptExecutionContext());
-        if (document->page() != &m_pageAgent->page())
-            continue;
+    {
+        LockHolder lock(WebSocket::allActiveWebSocketsMutex());
 
-        WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
-        if (!channel)
-            continue;
+        for (WebSocket* webSocket : activeWebSockets(lock)) {
+            ASSERT(is<WebSocketChannel>(webSocket->channel().get()));
+            WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
 
-        unsigned identifier = channel->identifier();
-        didCreateWebSocket(identifier, webSocket->url());
-        willSendWebSocketHandshakeRequest(identifier, channel->clientHandshakeRequest());
+            unsigned identifier = channel->identifier();
+            didCreateWebSocket(identifier, webSocket->url());
+            willSendWebSocketHandshakeRequest(identifier, channel->clientHandshakeRequest());
 
-        if (channel->handshakeMode() == WebSocketHandshake::Connected)
-            didReceiveWebSocketHandshakeResponse(identifier, channel->serverHandshakeResponse());
+            if (channel->handshakeMode() == WebSocketHandshake::Connected)
+                didReceiveWebSocketHandshakeResponse(identifier, channel->serverHandshakeResponse());
 
-        if (webSocket->readyState() == WebSocket::CLOSED)
-            didCloseWebSocket(identifier);
+            if (webSocket->readyState() == WebSocket::CLOSED)
+                didCloseWebSocket(identifier);
+        }
     }
 }
 
@@ -731,7 +740,7 @@ void InspectorNetworkAgent::disable(ErrorString&)
     m_resourcesData->clear();
     m_extraRequestHeaders.clear();
 
-    m_pageAgent->page().setResourceCachingDisabledOverride(false);
+    setResourceCachingDisabled(false);
 }
 
 void InspectorNetworkAgent::setExtraHTTPHeaders(ErrorString&, const InspectorObject& headers)
@@ -778,22 +787,16 @@ void InspectorNetworkAgent::getResponseBody(ErrorString& errorString, const Stri
 
 void InspectorNetworkAgent::setResourceCachingDisabled(ErrorString&, bool disabled)
 {
-    m_pageAgent->page().setResourceCachingDisabledOverride(disabled);
+    setResourceCachingDisabled(disabled);
 }
 
 void InspectorNetworkAgent::loadResource(ErrorString& errorString, const String& frameId, const String& urlString, Ref<LoadResourceCallback>&& callback)
 {
-    Frame* frame = m_pageAgent->assertFrame(errorString, frameId);
-    if (!frame)
+    auto* context = scriptExecutionContext(errorString, frameId);
+    if (!context)
         return;
 
-    Document* document = frame->document();
-    if (!document) {
-        errorString = ASCIILiteral("No Document instance for the specified frame");
-        return;
-    }
-
-    URL url = document->completeURL(urlString);
+    URL url = context->completeURL(urlString);
     ResourceRequest request(url);
     request.setHTTPMethod(ASCIILiteral("GET"));
     request.setHiddenFromInspector(true);
@@ -807,7 +810,7 @@ void InspectorNetworkAgent::loadResource(ErrorString& errorString, const String&
 
     // InspectorThreadableLoaderClient deletes itself when the load completes or fails.
     InspectorThreadableLoaderClient* inspectorThreadableLoaderClient = new InspectorThreadableLoaderClient(callback.copyRef());
-    auto loader = DocumentThreadableLoader::create(*document, *inspectorThreadableLoaderClient, WTFMove(request), options);
+    auto loader = ThreadableLoader::create(*context, *inspectorThreadableLoaderClient, WTFMove(request), options);
     if (!loader)
         return;
 
@@ -822,26 +825,11 @@ WebSocket* InspectorNetworkAgent::webSocketForRequestId(const String& requestId)
 {
     LockHolder lock(WebSocket::allActiveWebSocketsMutex());
 
-    for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
-        if (!is<WebSocketChannel>(webSocket->channel().get()))
-            continue;
-
+    for (WebSocket* webSocket : activeWebSockets(lock)) {
+        ASSERT(is<WebSocketChannel>(webSocket->channel().get()));
         WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
-        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;
+        if (IdentifiersFactory::requestId(channel->identifier()) == requestId)
+            return webSocket;
     }
 
     return nullptr;
@@ -861,9 +849,12 @@ void InspectorNetworkAgent::resolveWebSocket(ErrorString& errorString, const Str
         return;
     }
 
-    // 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();
+    // 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();
     if (!frame) {
         errorString = ASCIILiteral("WebSocket belongs to document without a frame");
         return;
@@ -918,7 +909,7 @@ void InspectorNetworkAgent::searchInRequest(ErrorString& errorString, const Stri
 
 void InspectorNetworkAgent::mainFrameNavigated(DocumentLoader& loader)
 {
-    m_resourcesData->clear(m_pageAgent->loaderId(&loader));
+    m_resourcesData->clear(loaderIdentifier(&loader));
 }
 
 } // namespace WebCore
index a785f37..862de5d 100644 (file)
@@ -64,10 +64,10 @@ struct WebSocketFrame;
 
 typedef String ErrorString;
 
-class InspectorNetworkAgent final : public InspectorAgentBase, public Inspector::NetworkBackendDispatcherHandler {
+class InspectorNetworkAgent : public InspectorAgentBase, public Inspector::NetworkBackendDispatcherHandler {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InspectorNetworkAgent(WebAgentContext&, InspectorPageAgent*);
+    explicit InspectorNetworkAgent(WebAgentContext&);
     virtual ~InspectorNetworkAgent();
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
@@ -76,13 +76,13 @@ public:
     // InspectorInstrumentation
     void willRecalculateStyle();
     void didRecalculateStyle();
-    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*);
+    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*);
     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
-    void didFinishLoading(unsigned long identifier, DocumentLoader&, const NetworkLoadMetrics&, ResourceLoader*);
-    void didFailLoading(unsigned long identifier, DocumentLoader&, const ResourceError&);
-    void didLoadResourceFromMemoryCache(DocumentLoader&, CachedResource&);
+    void didFinishLoading(unsigned long identifier, DocumentLoader*, const NetworkLoadMetrics&, ResourceLoader*);
+    void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
+    void didLoadResourceFromMemoryCache(DocumentLoader*, CachedResource&);
     void didReceiveThreadableLoaderResponse(unsigned long identifier, DocumentThreadableLoader&);
     void didFinishXHRLoading(unsigned long identifier, const String& decodedText);
     void willLoadXHRSynchronously();
@@ -106,18 +106,24 @@ public:
     RefPtr<Inspector::Protocol::Network::Initiator> buildInitiatorObject(Document*);
 
     // Called from frontend.
-    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;
+    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;
+
+    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;
 
 private:
     void enable();
 
-    void willSendRequest(unsigned long identifier, DocumentLoader&, ResourceRequest&, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType);
+    void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, InspectorPageAgent::ResourceType);
 
     WebSocket* webSocketForRequestId(const String& requestId);
 
@@ -131,7 +137,6 @@ private:
     std::unique_ptr<Inspector::NetworkFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::NetworkBackendDispatcher> m_backendDispatcher;
     Inspector::InjectedScriptManager& m_injectedScriptManager;
-    InspectorPageAgent* m_pageAgent { nullptr };
 
     // FIXME: InspectorNetworkAgent should not be aware of style recalculation.
     RefPtr<Inspector::Protocol::Network::Initiator> m_styleRecalculationInitiator;
diff --git a/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp b/Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp
new file mode 100644 (file)
index 0000000..44bc121
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * 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
diff --git a/Source/WebCore/inspector/agents/page/PageNetworkAgent.h b/Source/WebCore/inspector/agents/page/PageNetworkAgent.h
new file mode 100644 (file)
index 0000000..19174e3
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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
index efcb6d4..0ad29ac 100644 (file)
 #include "config.h"
 #include "WorkerConsoleAgent.h"
 
+#include "WorkerGlobalScope.h"
 
 namespace WebCore {
+
 using namespace Inspector;
 
 WorkerConsoleAgent::WorkerConsoleAgent(WorkerAgentContext& context, InspectorHeapAgent* heapAgent)
     : WebConsoleAgent(context, heapAgent)
 {
+    ASSERT(context.workerGlobalScope.isContextThread());
 }
 
 } // namespace WebCore
index d9cf06b..795829f 100644 (file)
@@ -34,8 +34,8 @@
 #include <inspector/ScriptCallStack.h>
 #include <inspector/ScriptCallStackFactory.h>
 
-
 namespace WebCore {
+
 using namespace JSC;
 using namespace Inspector;
 
@@ -43,6 +43,7 @@ WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerAgentContext& context)
     : WebDebuggerAgent(context)
     , m_workerGlobalScope(context.workerGlobalScope)
 {
+    ASSERT(context.workerGlobalScope.isContextThread());
 }
 
 WorkerDebuggerAgent::~WorkerDebuggerAgent() = default;
diff --git a/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp b/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp
new file mode 100644 (file)
index 0000000..cfc5cd2
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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
diff --git a/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h b/Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.h
new file mode 100644 (file)
index 0000000..297b0eb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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
index b423f56..db9a98a 100644 (file)
@@ -37,8 +37,8 @@
 #include <inspector/InjectedScript.h>
 #include <inspector/InjectedScriptManager.h>
 
-
 namespace WebCore {
+
 using namespace Inspector;
 
 WorkerRuntimeAgent::WorkerRuntimeAgent(WorkerAgentContext& context)
@@ -46,6 +46,7 @@ WorkerRuntimeAgent::WorkerRuntimeAgent(WorkerAgentContext& context)
     , m_backendDispatcher(RuntimeBackendDispatcher::create(context.backendDispatcher, this))
     , m_workerGlobalScope(context.workerGlobalScope)
 {
+    ASSERT(context.workerGlobalScope.isContextThread());
 }
 
 void WorkerRuntimeAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
index 92cd6d5..aed7b14 100644 (file)
@@ -102,7 +102,7 @@ ThreadableLoaderOptions ThreadableLoaderOptions::isolatedCopy() const
 RefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext& context, ThreadableLoaderClient& client, ResourceRequest&& request, const ThreadableLoaderOptions& options, String&& referrer)
 {
     if (is<WorkerGlobalScope>(context))
-        return WorkerThreadableLoader::create(downcast<WorkerGlobalScope>(context), client, WorkerRunLoop::defaultMode(), WTFMove(request), options, referrer);
+        return WorkerThreadableLoader::create(downcast<WorkerGlobalScope>(context), client, WorkerRunLoop::defaultMode(), WTFMove(request), options, WTFMove(referrer));
 
     return DocumentThreadableLoader::create(downcast<Document>(context), client, WTFMove(request), options, WTFMove(referrer));
 }
index dcf5eb4..b29ee32 100644 (file)
@@ -35,6 +35,7 @@
 #include "ContentSecurityPolicy.h"
 #include "Document.h"
 #include "DocumentThreadableLoader.h"
+#include "InspectorInstrumentation.h"
 #include "Performance.h"
 #include "ResourceError.h"
 #include "ResourceRequest.h"
@@ -106,8 +107,8 @@ WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(ThreadableLoaderClien
     : m_workerClientWrapper(&workerClientWrapper)
     , m_loaderProxy(loaderProxy)
     , m_taskMode(taskMode.isolatedCopy())
+    , m_workerRequestIdentifier(globalScope.createUniqueIdentifier())
 {
-
     auto* securityOrigin = globalScope.securityOrigin();
     auto* contentSecurityPolicy = globalScope.contentSecurityPolicy();
 
@@ -131,6 +132,8 @@ WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(ThreadableLoaderClien
         optionsCopy->options.serviceWorkerIdentifier = activeServiceWorker->identifier();
 #endif
 
+    InspectorInstrumentation::willSendRequest(globalScope, m_workerRequestIdentifier, request);
+
     // Can we benefit from request being an r-value to create more efficiently its isolated copy?
     m_loaderProxy.postTaskToLoader([this, request = request.isolatedCopy(), options = WTFMove(optionsCopy), contentSecurityPolicyCopy = WTFMove(contentSecurityPolicyCopy)](ScriptExecutionContext& context) mutable {
         ASSERT(isMainThread());
@@ -195,45 +198,49 @@ void WorkerThreadableLoader::MainThreadBridge::didSendData(unsigned long long by
 
 void WorkerThreadableLoader::MainThreadBridge::didReceiveResponse(unsigned long identifier, const ResourceResponse& response)
 {
-    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)));
+    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);
     }, m_taskMode);
 }
 
 void WorkerThreadableLoader::MainThreadBridge::didReceiveData(const char* data, int dataLength)
 {
-    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());
+    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());
     }, m_taskMode);
 }
 
 void WorkerThreadableLoader::MainThreadBridge::didFinishLoading(unsigned long identifier)
 {
     m_loadingFinished = true;
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), identifier] (ScriptExecutionContext& context) mutable {
-        ASSERT_UNUSED(context, context.isWorkerGlobalScope());
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), workerRequestIdentifier = m_workerRequestIdentifier, networkLoadMetrics = m_networkLoadMetrics.isolatedCopy(), identifier] (ScriptExecutionContext& context) mutable {
+        ASSERT(context.isWorkerGlobalScope());
         protectedWorkerClientWrapper->didFinishLoading(identifier);
+        InspectorInstrumentation::didFinishLoading(downcast<WorkerGlobalScope>(context), workerRequestIdentifier, networkLoadMetrics);
     }, m_taskMode);
 }
 
 void WorkerThreadableLoader::MainThreadBridge::didFail(const ResourceError& error)
 {
     m_loadingFinished = true;
-    m_loaderProxy.postTaskForModeToWorkerGlobalScope([workerClientWrapper = Ref<ThreadableLoaderClientWrapper>(*m_workerClientWrapper), error = error.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+    m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), workerRequestIdentifier = m_workerRequestIdentifier, error = error.isolatedCopy()] (ScriptExecutionContext& context) mutable {
         ASSERT(context.isWorkerGlobalScope());
-
-        ThreadableLoader::logError(context, error, workerClientWrapper->initiator());
-
-        workerClientWrapper->didFail(error);
+        ThreadableLoader::logError(context, error, protectedWorkerClientWrapper->initiator());
+        protectedWorkerClientWrapper->didFail(error);
+        InspectorInstrumentation::didFailLoading(downcast<WorkerGlobalScope>(context), workerRequestIdentifier, error);
     }, m_taskMode);
 }
 
 void WorkerThreadableLoader::MainThreadBridge::didFinishTiming(const ResourceTiming& resourceTiming)
 {
+    m_networkLoadMetrics = resourceTiming.networkLoadMetrics();
     m_loaderProxy.postTaskForModeToWorkerGlobalScope([protectedWorkerClientWrapper = makeRef(*m_workerClientWrapper), resourceTiming = resourceTiming.isolatedCopy()] (ScriptExecutionContext& context) mutable {
         ASSERT(context.isWorkerGlobalScope());
         ASSERT(!resourceTiming.initiator().isEmpty());
index 22ab149..a146963 100644 (file)
@@ -117,6 +117,8 @@ namespace WebCore {
 
             // For use on the main thread.
             String m_taskMode;
+            unsigned long m_workerRequestIdentifier { 0 };
+            NetworkLoadMetrics m_networkLoadMetrics;
         };
 
         WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient&, const String& taskMode, ResourceRequest&&, const ThreadableLoaderOptions&, const String& referrer);
index 76ad87f..b1e118a 100644 (file)
@@ -36,6 +36,7 @@ class WorkerDebuggerProxy {
 public:
     virtual ~WorkerDebuggerProxy() = default;
     virtual void postMessageToDebugger(const String&) = 0;
+    virtual void setResourceCachingDisabled(bool) = 0;
 };
 
 } // namespace WebCore
index 3e8cde9..6e3fac2 100644 (file)
@@ -64,6 +64,7 @@ public:
 
     const URL& url() const final { return m_url; }
     String origin() const final;
+    const String& identifier() const { return m_identifier; }
 
 #if ENABLE(INDEXED_DATABASE)
     IDBClient::IDBConnectionProxy* idbConnectionProxy() final;
@@ -118,6 +119,8 @@ public:
     void createImageBitmap(ImageBitmap::Source&&, ImageBitmapOptions&&, ImageBitmap::Promise&&);
     void createImageBitmap(ImageBitmap::Source&&, int sx, int sy, int sw, int sh, ImageBitmapOptions&&, ImageBitmap::Promise&&);
 
+    unsigned long createUniqueIdentifier() { return m_uniqueIdentifier++; }
+
 protected:
     WorkerGlobalScope(const URL&, const String& identifier, const String& userAgent, bool isOnline, WorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, PAL::SessionID);
 
@@ -196,6 +199,8 @@ private:
 
     PAL::SessionID m_sessionID;
     RefPtr<WorkerCacheStorageConnection> m_cacheStorageConnection;
+
+    unsigned long m_uniqueIdentifier { 1 };
 };
 
 } // namespace WebCore
index a5ab1b0..a2146cd 100644 (file)
@@ -177,6 +177,15 @@ void WorkerMessagingProxy::postMessageToDebugger(const String& message)
     });
 }
 
+void WorkerMessagingProxy::setResourceCachingDisabled(bool disabled)
+{
+    postTaskToLoader([disabled] (ScriptExecutionContext& context) {
+        ASSERT(isMainThread());
+        if (auto* page = downcast<Document>(context).page())
+            page->setResourceCachingDisabled(disabled);
+    });
+}
+
 void WorkerMessagingProxy::workerThreadCreated(DedicatedWorkerThread& workerThread)
 {
     m_workerThread = &workerThread;
index fef92e5..e9fa148 100644 (file)
@@ -65,6 +65,7 @@ private:
     // Implementation of WorkerDebuggerProxy.
     // (Only use these functions in the worker context thread.)
     void postMessageToDebugger(const String&) final;
+    void setResourceCachingDisabled(bool) final;
 
     // Implementation of WorkerLoaderProxy.
     // These functions are called on different threads to schedule loading
index 1570cf0..821dcea 100644 (file)
@@ -89,6 +89,14 @@ void ServiceWorkerThreadProxy::postMessageToDebugger(const String& message)
     });
 }
 
+void ServiceWorkerThreadProxy::setResourceCachingDisabled(bool disabled)
+{
+    postTaskToLoader([this, protectedThis = makeRef(*this), disabled] (ScriptExecutionContext&) {
+        ASSERT(isMainThread());
+        m_page->setResourceCachingDisabled(disabled);
+    });   
+}
+
 Ref<CacheStorageConnection> ServiceWorkerThreadProxy::createCacheStorageConnection()
 {
     ASSERT(isMainThread());
index 410b0ea..b998856 100644 (file)
@@ -63,6 +63,7 @@ private:
 
     // WorkerDebuggerProxy
     void postMessageToDebugger(const String&) final;
+    void setResourceCachingDisabled(bool) final;
 
     UniqueRef<Page> m_page;
     Ref<Document> m_document;