Add facility for tracking times and results of page and resource loading
authorkrollin@apple.com <krollin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2018 00:31:50 +0000 (00:31 +0000)
committerkrollin@apple.com <krollin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2018 00:31:50 +0000 (00:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184838
<rdar://problem/36548974>

Reviewed by Brent Fulgham.

Source/WebCore:

Update FrameProgressTracker to send the necessary page load start/stop
signals so that we can track the entire page load at a network level.
Add an empty override of the pure virtual
LoaderStrategy::pageLoadCompleted method.

No new tests. There is no testable effect from these changes. On
Cocoa, measurable changes take place in another (non-WebKit) process.
On non-Cocoa systems, this facility is currently disabled.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::FrameProgressTracker::progressCompleted):
* loader/LoaderStrategy.h:

Source/WebKit:

Add NetworkActivityTracker. The idea behind this facility is to create
and destroy them around networking activity that we want to track for
the purpose of measuring overall network health. They can be created
around the loading of pages or individual resources, and can be
arranged in a parent/child hierarchy to indicate what pages the
resources are part of. The NetworkActivity tracker tracks load times
and results. On Cocoa, it can be integrated with CFNetwork in order to
associate WebKit activity with low-level networking activity.

* CMakeLists.txt:
* Configurations/WebKit.xcconfig:
* NetworkProcess/NetworkActivityTracker.cpp: Copied from Source/WebKit/NetworkProcess/NetworkLoadParameters.h.
(WebKit::NetworkActivityTracker::NetworkActivityTracker):
(WebKit::NetworkActivityTracker::~NetworkActivityTracker):
(WebKit::NetworkActivityTracker::setParent):
(WebKit::NetworkActivityTracker::start):
(WebKit::NetworkActivityTracker::complete):
* NetworkProcess/NetworkActivityTracker.h: Added.
(WebKit::NetworkActivityTracker::getPlatformObject):
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::didClose):
(WebKit::NetworkConnectionToWebProcess::pageLoadCompleted):
(WebKit::networkActivityTrackingEnabled):
(WebKit::NetworkConnectionToWebProcess::startTrackingResourceLoad):
(WebKit::NetworkConnectionToWebProcess::stopTrackingResourceLoad):
(WebKit::NetworkConnectionToWebProcess::stopAllNetworkActivityTracking):
(WebKit::NetworkConnectionToWebProcess::stopAllNetworkActivityTrackingForPage):
(WebKit::NetworkConnectionToWebProcess::findRootNetworkActivity):
(WebKit::NetworkConnectionToWebProcess::findNetworkActivityTracker):
* NetworkProcess/NetworkConnectionToWebProcess.h:
(WebKit::NetworkConnectionToWebProcess::ResourceNetworkActivityTracker::ResourceNetworkActivityTracker):
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* NetworkProcess/NetworkDataTask.cpp:
(WebKit::NetworkDataTask::create):
* NetworkProcess/NetworkLoadParameters.h:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
* NetworkProcess/NetworkProcess.h:
(WebKit::NetworkProcess::trackNetworkActivity const):
* NetworkProcess/NetworkProcessCreationParameters.cpp:
(WebKit::NetworkProcessCreationParameters::encode const):
(WebKit::NetworkProcessCreationParameters::decode):
* NetworkProcess/NetworkProcessCreationParameters.h:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::start):
(WebKit::NetworkResourceLoader::cleanup):
(WebKit::NetworkResourceLoader::abort):
(WebKit::NetworkResourceLoader::didFinishLoading):
(WebKit::NetworkResourceLoader::didFailLoading):
(WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
(WebKit::NetworkResourceLoader::continueProcessingCachedEntryAfterDidReceiveResponse):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/cocoa/NetworkActivityTrackerCocoa.mm: Added.
(WebKit::NetworkActivityTracker::NetworkActivityTracker):
(WebKit::NetworkActivityTracker::~NetworkActivityTracker):
(WebKit::NetworkActivityTracker::setParent):
(WebKit::NetworkActivityTracker::start):
(WebKit::NetworkActivityTracker::complete):
* NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/C/WKContextConfigurationRef.cpp:
(WKContextConfigurationTrackNetworkActivity):
(WKContextConfigurationSetTrackNetworkActivity):
* UIProcess/API/C/WKContextConfigurationRef.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration trackNetworkActivity]):
(-[_WKProcessPoolConfiguration setTrackNetworkActivity:]):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::ensureNetworkProcess):
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::pageLoadCompleted):
* WebProcess/Network/WebLoaderStrategy.h:

Source/WebKitLegacy:

Add an empty override of the pure virtual
LoaderStrategy::pageLoadCompleted method.

* WebCoreSupport/WebResourceLoadScheduler.cpp:
(WebResourceLoadScheduler::pageLoadCompleted):
* WebCoreSupport/WebResourceLoadScheduler.h:

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

35 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/LoaderStrategy.h
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/Configurations/WebKit.xcconfig
Source/WebKit/NetworkProcess/NetworkActivityTracker.cpp [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkActivityTracker.h [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
Source/WebKit/NetworkProcess/NetworkDataTask.cpp
Source/WebKit/NetworkProcess/NetworkLoadParameters.h
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp
Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/NetworkResourceLoader.h
Source/WebKit/NetworkProcess/cocoa/NetworkActivityTrackerCocoa.mm [new file with mode: 0644]
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp
Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h
Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.cpp
Source/WebKit/UIProcess/API/C/WKContextConfigurationRef.h
Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
Source/WebKit/WebProcess/Network/WebLoaderStrategy.h
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.cpp
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.h

index 6c61636..1260753 100644 (file)
@@ -1,3 +1,24 @@
+2018-05-02  Keith Rollin  <krollin@apple.com>
+
+        Add facility for tracking times and results of page and resource loading
+        https://bugs.webkit.org/show_bug.cgi?id=184838
+        <rdar://problem/36548974>
+
+        Reviewed by Brent Fulgham.
+
+        Update FrameProgressTracker to send the necessary page load start/stop
+        signals so that we can track the entire page load at a network level.
+        Add an empty override of the pure virtual
+        LoaderStrategy::pageLoadCompleted method.
+
+        No new tests. There is no testable effect from these changes. On
+        Cocoa, measurable changes take place in another (non-WebKit) process.
+        On non-Cocoa systems, this facility is currently disabled.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::FrameProgressTracker::progressCompleted):
+        * loader/LoaderStrategy.h:
+
 2018-05-02  Aditya Keerthi  <akeerthi@apple.com>
 
         Can't copy and paste URLs that have no title into Mail (macOS)
index 97cf0b6..e3eee58 100644 (file)
@@ -252,6 +252,9 @@ public:
         ASSERT(m_frame.page());
         m_inProgress = false;
         m_frame.page()->progress().progressCompleted(m_frame);
+
+        if (auto pageID = m_frame.loader().client().pageID())
+            platformStrategies()->loaderStrategy()->pageLoadCompleted(pageID.value());
     }
 
 private:
index 67d30cf..2f5efeb 100644 (file)
@@ -58,6 +58,7 @@ class WEBCORE_EXPORT LoaderStrategy {
 public:
     virtual void loadResource(Frame&, CachedResource&, ResourceRequest&&, const ResourceLoaderOptions&, CompletionHandler<void(RefPtr<SubresourceLoader>&&)>&&) = 0;
     virtual void loadResourceSynchronously(FrameLoader&, unsigned long identifier, const ResourceRequest&, ClientCredentialPolicy, const FetchOptions&, const HTTPHeaderMap&, ResourceError&, ResourceResponse&, Vector<char>& data) = 0;
+    virtual void pageLoadCompleted(uint64_t webPageID) = 0;
 
     virtual void remove(ResourceLoader*) = 0;
     virtual void setDefersLoading(ResourceLoader*, bool) = 0;
index b939820..f1d03e4 100644 (file)
@@ -97,14 +97,7 @@ set(WebKit_SYSTEM_INCLUDE_DIRECTORIES
 )
 
 set(WebKit_SOURCES
-    NetworkProcess/Cookies/WebCookieManager.cpp
-
-    NetworkProcess/Downloads/Download.cpp
-    NetworkProcess/Downloads/DownloadManager.cpp
-    NetworkProcess/Downloads/PendingDownload.cpp
-
-    NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
-
+    NetworkProcess/NetworkActivityTracker.cpp
     NetworkProcess/NetworkCORSPreflightChecker.cpp
     NetworkProcess/NetworkConnectionToWebProcess.cpp
     NetworkProcess/NetworkContentRuleListManager.cpp
@@ -122,6 +115,14 @@ set(WebKit_SOURCES
     NetworkProcess/PingLoad.cpp
     NetworkProcess/PreconnectTask.cpp
 
+    NetworkProcess/Cookies/WebCookieManager.cpp
+
+    NetworkProcess/Downloads/Download.cpp
+    NetworkProcess/Downloads/DownloadManager.cpp
+    NetworkProcess/Downloads/PendingDownload.cpp
+
+    NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
+
     NetworkProcess/cache/CacheStorageEngine.cpp
     NetworkProcess/cache/CacheStorageEngineCache.cpp
     NetworkProcess/cache/CacheStorageEngineCaches.cpp
index 6ee4814..f85b020 100644 (file)
@@ -1,3 +1,90 @@
+2018-05-02  Keith Rollin  <krollin@apple.com>
+
+        Add facility for tracking times and results of page and resource loading
+        https://bugs.webkit.org/show_bug.cgi?id=184838
+        <rdar://problem/36548974>
+
+        Reviewed by Brent Fulgham.
+
+        Add NetworkActivityTracker. The idea behind this facility is to create
+        and destroy them around networking activity that we want to track for
+        the purpose of measuring overall network health. They can be created
+        around the loading of pages or individual resources, and can be
+        arranged in a parent/child hierarchy to indicate what pages the
+        resources are part of. The NetworkActivity tracker tracks load times
+        and results. On Cocoa, it can be integrated with CFNetwork in order to
+        associate WebKit activity with low-level networking activity.
+
+        * CMakeLists.txt:
+        * Configurations/WebKit.xcconfig:
+        * NetworkProcess/NetworkActivityTracker.cpp: Copied from Source/WebKit/NetworkProcess/NetworkLoadParameters.h.
+        (WebKit::NetworkActivityTracker::NetworkActivityTracker):
+        (WebKit::NetworkActivityTracker::~NetworkActivityTracker):
+        (WebKit::NetworkActivityTracker::setParent):
+        (WebKit::NetworkActivityTracker::start):
+        (WebKit::NetworkActivityTracker::complete):
+        * NetworkProcess/NetworkActivityTracker.h: Added.
+        (WebKit::NetworkActivityTracker::getPlatformObject):
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::didClose):
+        (WebKit::NetworkConnectionToWebProcess::pageLoadCompleted):
+        (WebKit::networkActivityTrackingEnabled):
+        (WebKit::NetworkConnectionToWebProcess::startTrackingResourceLoad):
+        (WebKit::NetworkConnectionToWebProcess::stopTrackingResourceLoad):
+        (WebKit::NetworkConnectionToWebProcess::stopAllNetworkActivityTracking):
+        (WebKit::NetworkConnectionToWebProcess::stopAllNetworkActivityTrackingForPage):
+        (WebKit::NetworkConnectionToWebProcess::findRootNetworkActivity):
+        (WebKit::NetworkConnectionToWebProcess::findNetworkActivityTracker):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        (WebKit::NetworkConnectionToWebProcess::ResourceNetworkActivityTracker::ResourceNetworkActivityTracker):
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+        * NetworkProcess/NetworkDataTask.cpp:
+        (WebKit::NetworkDataTask::create):
+        * NetworkProcess/NetworkLoadParameters.h:
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        * NetworkProcess/NetworkProcess.h:
+        (WebKit::NetworkProcess::trackNetworkActivity const):
+        * NetworkProcess/NetworkProcessCreationParameters.cpp:
+        (WebKit::NetworkProcessCreationParameters::encode const):
+        (WebKit::NetworkProcessCreationParameters::decode):
+        * NetworkProcess/NetworkProcessCreationParameters.h:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::start):
+        (WebKit::NetworkResourceLoader::cleanup):
+        (WebKit::NetworkResourceLoader::abort):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+        (WebKit::NetworkResourceLoader::didFailLoading):
+        (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
+        (WebKit::NetworkResourceLoader::continueProcessingCachedEntryAfterDidReceiveResponse):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/cocoa/NetworkActivityTrackerCocoa.mm: Added.
+        (WebKit::NetworkActivityTracker::NetworkActivityTracker):
+        (WebKit::NetworkActivityTracker::~NetworkActivityTracker):
+        (WebKit::NetworkActivityTracker::setParent):
+        (WebKit::NetworkActivityTracker::start):
+        (WebKit::NetworkActivityTracker::complete):
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        * UIProcess/API/APIProcessPoolConfiguration.cpp:
+        (API::ProcessPoolConfiguration::copy):
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/API/C/WKContextConfigurationRef.cpp:
+        (WKContextConfigurationTrackNetworkActivity):
+        (WKContextConfigurationSetTrackNetworkActivity):
+        * UIProcess/API/C/WKContextConfigurationRef.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        (-[_WKProcessPoolConfiguration trackNetworkActivity]):
+        (-[_WKProcessPoolConfiguration setTrackNetworkActivity:]):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::ensureNetworkProcess):
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::WebLoaderStrategy::pageLoadCompleted):
+        * WebProcess/Network/WebLoaderStrategy.h:
+
 2018-05-02  Jer Noble  <jer.noble@apple.com>
 
         Open audio/video sandbox services for minimal simulator
index 66348a4..5d7ae92 100644 (file)
@@ -109,7 +109,7 @@ WK_SAFE_BROWSING_LDFLAGS_MACOS_SINCE_1013 = -weak_framework SafariSafeBrowsing;
 WK_UIKIT_LDFLAGS = $(WK_UIKIT_LDFLAGS_$(WK_COCOA_TOUCH));
 WK_UIKIT_LDFLAGS_cocoatouch = -framework UIKit;
 
-FRAMEWORK_AND_LIBRARY_LDFLAGS = -lobjc -framework CFNetwork -framework CoreAudio -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework ImageIO -framework IOKit -framework WebKitLegacy $(WK_ACCESSIBILITY_LDFLAGS) $(WK_APPKIT_LDFLAGS) $(WK_ASSERTION_SERVICES_LDFLAGS) $(WK_CARBON_LDFLAGS) $(WK_CORE_PDF_LDFLAGS) $(WK_CORE_PREDICTION_LDFLAGS) $(WK_CORE_SERVICES_LDFLAGS) $(WK_GRAPHICS_SERVICES_LDFLAGS) $(WK_IOSURFACE_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SAFE_BROWSING_LDFLAGS) $(WK_UIKIT_LDFLAGS);
+FRAMEWORK_AND_LIBRARY_LDFLAGS = -lobjc -framework CFNetwork -framework CoreAudio -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework Foundation -framework ImageIO -framework IOKit -framework WebKitLegacy -lnetwork $(WK_ACCESSIBILITY_LDFLAGS) $(WK_APPKIT_LDFLAGS) $(WK_ASSERTION_SERVICES_LDFLAGS) $(WK_CARBON_LDFLAGS) $(WK_CORE_PDF_LDFLAGS) $(WK_CORE_PREDICTION_LDFLAGS) $(WK_CORE_SERVICES_LDFLAGS) $(WK_GRAPHICS_SERVICES_LDFLAGS) $(WK_IOSURFACE_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SAFE_BROWSING_LDFLAGS) $(WK_UIKIT_LDFLAGS);
 
 // Prevent C++ standard library operator new, delete and their related exception types from being exported as weak symbols.
 UNEXPORTED_SYMBOL_LDFLAGS = -Wl,-unexported_symbol -Wl,__ZTISt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTISt9exception -Wl,-unexported_symbol -Wl,__ZTSSt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTSSt9exception -Wl,-unexported_symbol -Wl,__ZdlPvS_ -Wl,-unexported_symbol -Wl,__ZnwmPv -Wl,-unexported_symbol -Wl,__Znwm -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC2EOS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC1EOS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEaSEDn -Wl,-unexported_symbol, -Wl,__ZNKSt3__18functionIFvN7WebCore12PolicyActionEEEclES2_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEE4swapERS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC1ERKS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEC2ERKS4_ -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEED1Ev -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEED2Ev -Wl,-unexported_symbol, -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEaSERKS4_ -Wl,-unexported_symbol, -Wl,__ZTVNSt3__117bad_function_callE;
diff --git a/Source/WebKit/NetworkProcess/NetworkActivityTracker.cpp b/Source/WebKit/NetworkProcess/NetworkActivityTracker.cpp
new file mode 100644 (file)
index 0000000..ab367e9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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 "NetworkActivityTracker.h"
+
+#if !HAVE(NW_ACTIVITY)
+
+namespace WebKit {
+
+NetworkActivityTracker::NetworkActivityTracker(Label, Domain)
+{
+}
+
+NetworkActivityTracker::~NetworkActivityTracker()
+{
+}
+
+void NetworkActivityTracker::setParent(NetworkActivityTracker&)
+{
+}
+
+void NetworkActivityTracker::start()
+{
+}
+
+void NetworkActivityTracker::complete(CompletionCode)
+{
+}
+
+} // namespace WebKit
+
+#endif // !HAVE(NW_ACTIVITY)
diff --git a/Source/WebKit/NetworkProcess/NetworkActivityTracker.h b/Source/WebKit/NetworkProcess/NetworkActivityTracker.h
new file mode 100644 (file)
index 0000000..60e1718
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2018 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
+
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<nw/activity.h>)
+#define HAVE_NW_ACTIVITY 1
+#endif
+
+#if HAVE(NW_ACTIVITY)
+#include <nw/private.h>
+#include <wtf/RetainPtr.h>
+#endif
+
+namespace WebKit {
+
+class NetworkActivityTracker {
+public:
+    enum class Domain {
+        // These are defined to match analogous values used in the Darwin implementation.
+        // If they are renumbered, platform-specific code will need to be added to map
+        // them to the Darwin-specific values.
+
+        Invalid = 0,
+        WebKit = 16,
+    };
+
+    enum class Label {
+        // These are ours to define, but once defined, they shouldn't change. They can
+        // be obsolesced and replaced with other codes, but previously-defined codes
+        // should not be renumbered. Previously assigned values should not be re-used.
+
+        Invalid = 0,
+        LoadPage = 1,
+        LoadResource = 2,
+    };
+
+    enum class CompletionCode {
+        Undefined,
+        None,
+        Success,
+        Failure,
+    };
+
+    NetworkActivityTracker(Label, Domain = Domain::WebKit);
+    ~NetworkActivityTracker();
+
+    void setParent(NetworkActivityTracker&);
+    void start();
+    void complete(CompletionCode);
+
+#if HAVE(NW_ACTIVITY)
+    nw_activity_t getPlatformObject() { return m_networkActivity.get(); }
+#endif
+
+private:
+#if HAVE(NW_ACTIVITY)
+    Domain m_domain;
+    Label m_label;
+    bool m_isCompleted { false };
+    RetainPtr<nw_activity_t> m_networkActivity;
+#endif
+};
+
+} // namespace WebKit
index c13903d..94d8623 100644 (file)
@@ -29,6 +29,7 @@
 #include "BlobDataFileReferenceWithSandboxExtension.h"
 #include "CacheStorageEngineConnectionMessages.h"
 #include "DataReference.h"
+#include "Logging.h"
 #include "NetworkBlobRegistry.h"
 #include "NetworkCache.h"
 #include "NetworkConnectionToWebProcessMessages.h"
@@ -61,6 +62,9 @@
 
 using namespace WebCore;
 
+#define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(true, Network, "%p - NetworkConnectionToWebProcess::" fmt, this, ##__VA_ARGS__)
+#define RELEASE_LOG_ERROR_IF_ALLOWED(fmt, ...) RELEASE_LOG_ERROR_IF(true, Network, "%p - NetworkConnectionToWebProcess::" fmt, this, ##__VA_ARGS__)
+
 namespace WebKit {
 
 Ref<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(IPC::Connection::Identifier connectionIdentifier)
@@ -180,6 +184,11 @@ void NetworkConnectionToWebProcess::didClose(IPC::Connection&)
         loader->abort();
     ASSERT(m_networkResourceLoaders.isEmpty());
 
+    // All trackers of resources that were in the middle of being loaded were
+    // stopped with the abort() calls above, but we still need to sweep up the
+    // root activity trackers.
+    stopAllNetworkActivityTracking();
+
     NetworkBlobRegistry::singleton().connectionToWebProcessDidClose(this);
     NetworkProcess::singleton().removeNetworkConnectionToWebProcess(this);
 
@@ -287,6 +296,11 @@ void NetworkConnectionToWebProcess::removeLoadIdentifier(ResourceLoadIdentifier
     ASSERT(!m_networkResourceLoaders.contains(identifier));
 }
 
+void NetworkConnectionToWebProcess::pageLoadCompleted(uint64_t webPageID)
+{
+    stopAllNetworkActivityTrackingForPage(webPageID);
+}
+
 void NetworkConnectionToWebProcess::setDefersLoading(ResourceLoadIdentifier identifier, bool defers)
 {
     RefPtr<NetworkResourceLoader> loader = m_networkResourceLoaders.get(identifier);
@@ -532,4 +546,115 @@ void NetworkConnectionToWebProcess::resetOriginAccessWhitelists()
     SecurityPolicy::resetOriginAccessWhitelists();
 }
 
+static bool networkActivityTrackingEnabled()
+{
+    return NetworkProcess::singleton().trackNetworkActivity();
+}
+
+std::optional<NetworkActivityTracker> NetworkConnectionToWebProcess::startTrackingResourceLoad(uint64_t pageID, ResourceLoadIdentifier resourceID, bool isMainResource)
+{
+    if (!networkActivityTrackingEnabled())
+        return std::nullopt;
+
+    // Either get the existing root activity tracker for this page or create a
+    // new one if this is the main resource.
+
+    size_t rootActivityIndex;
+    if (isMainResource) {
+        // If we're loading a page from the top, make sure any tracking of
+        // previous activity for this page is stopped.
+
+        stopAllNetworkActivityTrackingForPage(pageID);
+
+        rootActivityIndex = m_networkActivityTrackers.size();
+        m_networkActivityTrackers.constructAndAppend(pageID);
+        m_networkActivityTrackers[rootActivityIndex].networkActivity.start();
+
+#if HAVE(NW_ACTIVITY)
+        ASSERT(m_networkActivityTrackers[rootActivityIndex].networkActivity.getPlatformObject());
+#endif
+    } else {
+        rootActivityIndex = findRootNetworkActivity(pageID);
+
+        // This could happen if the Networking process crashes, taking its
+        // previous state with it.
+        if (rootActivityIndex == notFound)
+            return std::nullopt;
+
+#if HAVE(NW_ACTIVITY)
+        ASSERT(m_networkActivityTrackers[rootActivityIndex].networkActivity.getPlatformObject());
+#endif
+    }
+
+    // Create a tracker for the loading of the new resource, setting the root
+    // activity tracker as its parent.
+
+    size_t newActivityIndex = m_networkActivityTrackers.size();
+    m_networkActivityTrackers.constructAndAppend(pageID, resourceID);
+#if HAVE(NW_ACTIVITY)
+    ASSERT(m_networkActivityTrackers[newActivityIndex].networkActivity.getPlatformObject());
+#endif
+
+    auto& newActivityTracker = m_networkActivityTrackers[newActivityIndex];
+    newActivityTracker.networkActivity.setParent(m_networkActivityTrackers[rootActivityIndex].networkActivity);
+    newActivityTracker.networkActivity.start();
+
+    return newActivityTracker.networkActivity;
+}
+
+void NetworkConnectionToWebProcess::stopTrackingResourceLoad(ResourceLoadIdentifier resourceID, NetworkActivityTracker::CompletionCode code)
+{
+    if (!networkActivityTrackingEnabled())
+        return;
+
+    auto itemIndex = findNetworkActivityTracker(resourceID);
+    if (itemIndex == notFound) {
+        RELEASE_LOG_ERROR(Network, "stopTrackingResourceLoad: Unable to find network activity for resource: %d", static_cast<int>(resourceID));
+        return;
+    }
+
+    m_networkActivityTrackers[itemIndex].networkActivity.complete(code);
+    m_networkActivityTrackers.remove(itemIndex);
+}
+
+void NetworkConnectionToWebProcess::stopAllNetworkActivityTracking()
+{
+    if (!networkActivityTrackingEnabled())
+        return;
+
+    for (auto& activityTracker : m_networkActivityTrackers)
+        activityTracker.networkActivity.complete(NetworkActivityTracker::CompletionCode::None);
+
+    m_networkActivityTrackers.clear();
+}
+
+void NetworkConnectionToWebProcess::stopAllNetworkActivityTrackingForPage(uint64_t pageID)
+{
+    if (!networkActivityTrackingEnabled())
+        return;
+
+    for (auto& activityTracker : m_networkActivityTrackers) {
+        if (activityTracker.pageID == pageID)
+            activityTracker.networkActivity.complete(NetworkActivityTracker::CompletionCode::None);
+    }
+
+    m_networkActivityTrackers.removeAllMatching([&](const auto& activityTracker) {
+        return activityTracker.pageID == pageID;
+    });
+}
+
+size_t NetworkConnectionToWebProcess::findRootNetworkActivity(uint64_t pageID)
+{
+    return m_networkActivityTrackers.findMatching([&](const auto& item) {
+        return item.isRootActivity && item.pageID == pageID;
+    });
+}
+
+size_t NetworkConnectionToWebProcess::findNetworkActivityTracker(ResourceLoadIdentifier resourceID)
+{
+    return m_networkActivityTrackers.findMatching([&](const auto& item) {
+        return item.resourceID == resourceID;
+    });
+}
+
 } // namespace WebKit
index d71dc3c..41cb823 100644 (file)
@@ -29,6 +29,7 @@
 #include "CacheStorageEngineConnection.h"
 #include "Connection.h"
 #include "DownloadID.h"
+#include "NetworkActivityTracker.h"
 #include "NetworkConnectionToWebProcessMessages.h"
 #include "NetworkMDNSRegister.h"
 #include "NetworkRTCProvider.h"
@@ -111,6 +112,9 @@ public:
         m_networkLoadInformationByID.remove(identifier);
     }
 
+    std::optional<NetworkActivityTracker> startTrackingResourceLoad(uint64_t pageID, ResourceLoadIdentifier resourceID, bool isMainResource);
+    void stopTrackingResourceLoad(ResourceLoadIdentifier resourceID, NetworkActivityTracker::CompletionCode);
+
 private:
     NetworkConnectionToWebProcess(IPC::Connection::Identifier);
 
@@ -133,6 +137,7 @@ private:
     void preconnectTo(uint64_t preconnectionIdentifier, NetworkResourceLoadParameters&&);
 
     void removeLoadIdentifier(ResourceLoadIdentifier);
+    void pageLoadCompleted(uint64_t webPageID);
     void setDefersLoading(ResourceLoadIdentifier, bool);
     void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::URL& redirectURL);
     void startDownload(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedName = { });
@@ -180,11 +185,41 @@ private:
     void removeOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains);
     void resetOriginAccessWhitelists();
 
+    struct ResourceNetworkActivityTracker {
+        ResourceNetworkActivityTracker() = default;
+        ResourceNetworkActivityTracker(const ResourceNetworkActivityTracker&) = default;
+        ResourceNetworkActivityTracker(ResourceNetworkActivityTracker&&) = default;
+        ResourceNetworkActivityTracker(uint64_t pageID)
+            : pageID { pageID }
+            , isRootActivity { true }
+            , networkActivity { NetworkActivityTracker::Label::LoadPage }
+        {
+        }
+
+        ResourceNetworkActivityTracker(uint64_t pageID, ResourceLoadIdentifier resourceID)
+            : pageID { pageID }
+            , resourceID { resourceID }
+            , networkActivity { NetworkActivityTracker::Label::LoadResource }
+        {
+        }
+
+        uint64_t pageID { 0 };
+        ResourceLoadIdentifier resourceID { 0 };
+        bool isRootActivity { false };
+        NetworkActivityTracker networkActivity;
+    };
+
+    void stopAllNetworkActivityTracking();
+    void stopAllNetworkActivityTrackingForPage(uint64_t pageID);
+    size_t findRootNetworkActivity(uint64_t pageID);
+    size_t findNetworkActivityTracker(ResourceLoadIdentifier resourceID);
+
     Ref<IPC::Connection> m_connection;
 
     HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
     HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
     HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
+    Vector<ResourceNetworkActivityTracker> m_networkActivityTrackers;
 
     HashMap<ResourceLoadIdentifier, NetworkLoadInformation> m_networkLoadInformationByID;
 
index 9a5a4f2..f4ec633 100644 (file)
@@ -26,6 +26,7 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
     PerformSynchronousLoad(WebKit::NetworkResourceLoadParameters resourceLoadParameters) -> (WebCore::ResourceError error, WebCore::ResourceResponse response, Vector<char> data) Delayed
     LoadPing(WebKit::NetworkResourceLoadParameters resourceLoadParameters)
     RemoveLoadIdentifier(uint64_t resourceLoadIdentifier)
+    PageLoadCompleted(uint64_t webPageID)
     SetDefersLoading(uint64_t resourceLoadIdentifier, bool defers)
     PrefetchDNS(String hostname)
     PreconnectTo(uint64_t preconnectionIdentifier, WebKit::NetworkResourceLoadParameters loadParameters);
index 5a1f749..1524d3c 100644 (file)
@@ -54,7 +54,7 @@ Ref<NetworkDataTask> NetworkDataTask::create(NetworkSession& session, NetworkDat
         return NetworkDataTaskBlob::create(session, client, parameters.request, parameters.contentSniffingPolicy, parameters.blobFileReferences);
 
 #if PLATFORM(COCOA)
-    return NetworkDataTaskCocoa::create(session, client, parameters.request, parameters.webFrameID, parameters.webPageID, parameters.storedCredentialsPolicy, parameters.contentSniffingPolicy, parameters.contentEncodingSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect, parameters.shouldPreconnectOnly, parameters.isMainFrameNavigation);
+    return NetworkDataTaskCocoa::create(session, client, parameters.request, parameters.webFrameID, parameters.webPageID, parameters.storedCredentialsPolicy, parameters.contentSniffingPolicy, parameters.contentEncodingSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect, parameters.shouldPreconnectOnly, parameters.isMainFrameNavigation, parameters.networkActivityTracker);
 #endif
 #if USE(SOUP)
     return NetworkDataTaskSoup::create(session, client, parameters.request, parameters.storedCredentialsPolicy, parameters.contentSniffingPolicy, parameters.contentEncodingSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect, parameters.isMainFrameNavigation);
index 555122b..9c8c845 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "NetworkActivityTracker.h"
 #include <WebCore/BlobDataFileReference.h>
 #include <WebCore/ResourceLoaderOptions.h>
 #include <WebCore/ResourceRequest.h>
@@ -51,6 +52,7 @@ public:
     bool isMainFrameNavigation { false };
     Vector<RefPtr<WebCore::BlobDataFileReference>> blobFileReferences;
     PreconnectOnly shouldPreconnectOnly { PreconnectOnly::No };
+    std::optional<NetworkActivityTracker> networkActivityTracker;
 };
 
 } // namespace WebKit
index 3b0ff20..077bd73 100644 (file)
@@ -298,6 +298,8 @@ void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&&
     for (auto& scheme : parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest)
         registerURLSchemeAsCanDisplayOnlyIfCanRequest(scheme);
 
+    m_trackNetworkActivity = parameters.trackNetworkActivity;
+
     RELEASE_LOG(Process, "%p - NetworkProcess::initializeNetworkProcess: Presenting process = %d", this, WebCore::presentingApplicationPID());
 }
 
index ce412b4..b961abc 100644 (file)
@@ -162,6 +162,8 @@ public:
     NetworkContentRuleListManager& networkContentRuleListManager() { return m_NetworkContentRuleListManager; }
 #endif
 
+    bool trackNetworkActivity() const { return m_trackNetworkActivity; }
+
 private:
     NetworkProcess();
     ~NetworkProcess();
@@ -300,6 +302,8 @@ private:
 #if ENABLE(CONTENT_EXTENSIONS)
     NetworkContentRuleListManager m_NetworkContentRuleListManager;
 #endif
+
+    bool m_trackNetworkActivity { false };
 };
 
 } // namespace WebKit
index a84e498..3d24d23 100644 (file)
@@ -115,6 +115,8 @@ void NetworkProcessCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << urlSchemesRegisteredAsDisplayIsolated;
     encoder << urlSchemesRegisteredAsCORSEnabled;
     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
+
+    encoder << trackNetworkActivity;
 }
 
 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
@@ -275,6 +277,9 @@ bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProc
     if (!decoder.decode(result.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
         return false;
 
+    if (!decoder.decode(result.trackNetworkActivity))
+        return false;
+
     return true;
 }
 
index c2b680b..d147533 100644 (file)
@@ -132,6 +132,8 @@ struct NetworkProcessCreationParameters {
     Vector<String> urlSchemesRegisteredAsDisplayIsolated;
     Vector<String> urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
     Vector<String> urlSchemesRegisteredAsCORSEnabled;
+
+    bool trackNetworkActivity { false };
 };
 
 } // namespace WebKit
index 5088209..9d78a44 100644 (file)
@@ -165,6 +165,8 @@ void NetworkResourceLoader::start()
 {
     ASSERT(RunLoop::isMain());
 
+    m_networkActivityTracker = m_connection->startTrackingResourceLoad(m_parameters.webPageID, m_parameters.identifier, isMainResource());
+
     if (m_defersLoading) {
         RELEASE_LOG_IF_ALLOWED("start: Loading is deferred (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", isMainResource = %d, isSynchronous = %d)", m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier, isMainResource(), isSynchronous());
         return;
@@ -254,6 +256,7 @@ void NetworkResourceLoader::startNetworkLoad(ResourceRequest&& request, FirstLoa
 
     NetworkLoadParameters parameters = m_parameters;
     parameters.defersLoading = m_defersLoading;
+    parameters.networkActivityTracker = m_networkActivityTracker;
     if (m_networkLoadChecker)
         parameters.storedCredentialsPolicy = m_networkLoadChecker->storedCredentialsPolicy();
 
@@ -306,10 +309,15 @@ void NetworkResourceLoader::setDefersLoading(bool defers)
         RELEASE_LOG_IF_ALLOWED("setDefersLoading: defers = %d, but nothing to do (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ")", m_defersLoading, m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier);
 }
 
-void NetworkResourceLoader::cleanup()
+void NetworkResourceLoader::cleanup(LoadResult result)
 {
     ASSERT(RunLoop::isMain());
 
+    m_connection->stopTrackingResourceLoad(m_parameters.identifier,
+        result == LoadResult::Success ? NetworkActivityTracker::CompletionCode::Success :
+        result == LoadResult::Failure ? NetworkActivityTracker::CompletionCode::Failure :
+        NetworkActivityTracker::CompletionCode::None);
+
     m_bufferingTimer.stop();
 
     invalidateSandboxExtensions();
@@ -342,7 +350,7 @@ void NetworkResourceLoader::abort()
         m_networkLoad->cancel();
     }
 
-    cleanup();
+    cleanup(LoadResult::Cancel);
 }
 
 static bool areFrameAncestorsSameSite(const ResourceResponse& response, const Vector<RefPtr<SecurityOrigin>>& frameAncestorOrigins)
@@ -507,7 +515,7 @@ void NetworkResourceLoader::didFinishLoading(const NetworkLoadMetrics& networkLo
 
     tryStoreAsCacheEntry();
 
-    cleanup();
+    cleanup(LoadResult::Success);
 }
 
 void NetworkResourceLoader::didFailLoading(const ResourceError& error)
@@ -527,7 +535,7 @@ void NetworkResourceLoader::didFailLoading(const ResourceError& error)
     } else if (auto* connection = messageSenderConnection())
         connection->send(Messages::WebResourceLoader::DidFailResourceLoad(error), messageSenderDestinationID());
 
-    cleanup();
+    cleanup(LoadResult::Failure);
 }
 
 void NetworkResourceLoader::didBlockAuthenticationChallenge()
@@ -731,7 +739,7 @@ void NetworkResourceLoader::didRetrieveCacheEntry(std::unique_ptr<NetworkCache::
     if (isSynchronous()) {
         m_synchronousLoadData->response = WTFMove(response);
         sendReplyToSynchronousRequest(*m_synchronousLoadData, entry->buffer());
-        cleanup();
+        cleanup(LoadResult::Success);
         return;
     }
 
@@ -765,7 +773,7 @@ void NetworkResourceLoader::continueProcessingCachedEntryAfterDidReceiveResponse
                 }
                 if (retrievedAll) {
                     loader->sendResultForCacheEntry(WTFMove(entry));
-                    loader->cleanup();
+                    loader->cleanup(LoadResult::Success);
                 }
             });
         }
@@ -774,7 +782,7 @@ void NetworkResourceLoader::continueProcessingCachedEntryAfterDidReceiveResponse
 
     sendResultForCacheEntry(WTFMove(entry));
 
-    cleanup();
+    cleanup(LoadResult::Success);
 }
 
 void NetworkResourceLoader::sendResultForCacheEntry(std::unique_ptr<NetworkCache::Entry> entry)
index 8769708..57c540d 100644 (file)
@@ -134,7 +134,13 @@ private:
     void startNetworkLoad(WebCore::ResourceRequest&&, FirstLoad);
     void continueDidReceiveResponse();
 
-    void cleanup();
+    enum class LoadResult {
+        Unknown,
+        Success,
+        Failure,
+        Cancel
+    };
+    void cleanup(LoadResult);
     
     void platformDidReceiveResponse(const WebCore::ResourceResponse&);
 
@@ -184,6 +190,8 @@ private:
     bool m_isWaitingContinueWillSendRequestForCachedRedirect { false };
     std::unique_ptr<NetworkCache::Entry> m_cacheEntryWaitingForContinueDidReceiveResponse;
     RefPtr<NetworkLoadChecker> m_networkLoadChecker;
+
+    std::optional<NetworkActivityTracker> m_networkActivityTracker;
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/cocoa/NetworkActivityTrackerCocoa.mm b/Source/WebKit/NetworkProcess/cocoa/NetworkActivityTrackerCocoa.mm
new file mode 100644 (file)
index 0000000..d3705a5
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2018 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 "NetworkActivityTracker.h"
+
+#if HAVE(NW_ACTIVITY)
+
+namespace WebKit {
+
+NetworkActivityTracker::NetworkActivityTracker(Label label, Domain domain)
+    : m_domain(domain)
+    , m_label(label)
+    , m_networkActivity(adoptNS(nw_activity_create(static_cast<uint32_t>(m_domain), static_cast<uint32_t>(m_label))))
+{
+}
+
+NetworkActivityTracker::~NetworkActivityTracker()
+{
+}
+
+void NetworkActivityTracker::setParent(NetworkActivityTracker& parent)
+{
+    ASSERT(m_networkActivity.get());
+    ASSERT(parent.m_networkActivity.get());
+    nw_activity_set_parent_activity(m_networkActivity.get(), parent.m_networkActivity.get());
+}
+
+void NetworkActivityTracker::start()
+{
+    ASSERT(m_networkActivity.get());
+    nw_activity_activate(m_networkActivity.get());
+}
+
+void NetworkActivityTracker::complete(CompletionCode code)
+{
+    if (m_isCompleted)
+        return;
+
+    m_isCompleted = true;
+
+    ASSERT(m_networkActivity.get());
+    auto reason =
+        code == CompletionCode::None ? nw_activity_completion_reason_none :
+        code == CompletionCode::Success ? nw_activity_completion_reason_success :
+        code == CompletionCode::Failure ? nw_activity_completion_reason_failure :
+        nw_activity_completion_reason_invalid;
+    nw_activity_complete_with_reason(m_networkActivity.get(), reason);
+    m_networkActivity.clear();
+}
+
+} // namespace WebKit
+
+#endif // HAVE(NW_ACTIVITY)
index a8280b5..53b4921 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "NetworkActivityTracker.h"
 #include "NetworkDataTask.h"
 #include "NetworkLoadParameters.h"
 #include "WiFiAssertionHolder.h"
@@ -41,9 +42,9 @@ class NetworkSessionCocoa;
 class NetworkDataTaskCocoa final : public NetworkDataTask {
     friend class NetworkSessionCocoa;
 public:
-    static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WebCore::ContentSniffingPolicy shouldContentSniff, WebCore::ContentEncodingSniffingPolicy shouldContentEncodingSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly shouldPreconnectOnly, bool dataTaskIsForMainFrameNavigation)
+    static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WebCore::ContentSniffingPolicy shouldContentSniff, WebCore::ContentEncodingSniffingPolicy shouldContentEncodingSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly shouldPreconnectOnly, bool dataTaskIsForMainFrameNavigation, std::optional<NetworkActivityTracker> networkActivityTracker)
     {
-        return adoptRef(*new NetworkDataTaskCocoa(session, client, request, frameID, pageID, storedCredentialsPolicy, shouldContentSniff, shouldContentEncodingSniff, shouldClearReferrerOnHTTPSToHTTPRedirect, shouldPreconnectOnly, dataTaskIsForMainFrameNavigation));
+        return adoptRef(*new NetworkDataTaskCocoa(session, client, request, frameID, pageID, storedCredentialsPolicy, shouldContentSniff, shouldContentEncodingSniff, shouldClearReferrerOnHTTPSToHTTPRedirect, shouldPreconnectOnly, dataTaskIsForMainFrameNavigation, networkActivityTracker));
     }
 
     ~NetworkDataTaskCocoa();
@@ -83,7 +84,7 @@ public:
     String description() const override;
 
 private:
-    NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy, WebCore::ContentSniffingPolicy, WebCore::ContentEncodingSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly, bool dataTaskIsForMainFrameNavigation);
+    NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy, WebCore::ContentSniffingPolicy, WebCore::ContentEncodingSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly, bool dataTaskIsForMainFrameNavigation, std::optional<NetworkActivityTracker>);
 
     bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&);
     void applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(NSURLRequest*&, bool shouldContentSniff, bool shouldContentEncodingSniff);
index f98749a..45d6049 100644 (file)
 @end
 #endif
 
+#if HAVE(NW_ACTIVITY)
+#import <CFNetwork/CFNSURLConnection.h>
+#endif
+
 namespace WebKit {
 
 #if USE(CREDENTIAL_STORAGE_WITH_NETWORK_SESSION)
@@ -181,7 +185,7 @@ static void updateTaskWithFirstPartyForSameSiteCookies(NSURLSessionDataTask* tas
 #endif
 }
 
-NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& requestWithCredentials, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WebCore::ContentSniffingPolicy shouldContentSniff, WebCore::ContentEncodingSniffingPolicy shouldContentEncodingSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly shouldPreconnectOnly, bool dataTaskIsForMainFrameNavigation)
+NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& requestWithCredentials, uint64_t frameID, uint64_t pageID, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WebCore::ContentSniffingPolicy shouldContentSniff, WebCore::ContentEncodingSniffingPolicy shouldContentEncodingSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect, PreconnectOnly shouldPreconnectOnly, bool dataTaskIsForMainFrameNavigation, std::optional<NetworkActivityTracker> networkActivityTracker)
     : NetworkDataTask(session, client, requestWithCredentials, storedCredentialsPolicy, shouldClearReferrerOnHTTPSToHTTPRedirect, dataTaskIsForMainFrameNavigation)
     , m_frameID(frameID)
     , m_pageID(pageID)
@@ -273,6 +277,11 @@ NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataT
         m_task.get().priority = toNSURLSessionTaskPriority(request.priority());
 
     updateTaskWithFirstPartyForSameSiteCookies(m_task.get(), request);
+
+#if HAVE(NW_ACTIVITY)
+    if (networkActivityTracker)
+        m_task.get()._nw_activity = networkActivityTracker.value().getPlatformObject();
+#endif
 }
 
 NetworkDataTaskCocoa::~NetworkDataTaskCocoa()
index fe1e9c9..a69db07 100644 (file)
@@ -130,6 +130,7 @@ Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::copy()
     copy->m_processSwapsOnNavigation = this->m_processSwapsOnNavigation;
     copy->m_alwaysKeepAndReuseSwappedProcesses = this->m_alwaysKeepAndReuseSwappedProcesses;
     copy->m_processSwapsOnWindowOpenWithOpener = this->m_processSwapsOnWindowOpenWithOpener;
+    copy->m_trackNetworkActivity = this->m_trackNetworkActivity;
 
     return copy;
 }
index e3b7d49..edbd09e 100644 (file)
@@ -144,6 +144,9 @@ public:
     bool processSwapsOnWindowOpenWithOpener() const { return m_processSwapsOnWindowOpenWithOpener; }
     void setProcessSwapsOnWindowOpenWithOpener(bool swaps) { m_processSwapsOnWindowOpenWithOpener = swaps; }
 
+    bool trackNetworkActivity() const { return m_trackNetworkActivity; }
+    void setTrackNetworkActivity(bool track) { m_trackNetworkActivity = track; }
+
 private:
     bool m_shouldHaveLegacyDataStore { false };
 
@@ -178,6 +181,7 @@ private:
     bool m_processSwapsOnNavigation { false };
     bool m_alwaysKeepAndReuseSwappedProcesses { false };
     bool m_processSwapsOnWindowOpenWithOpener { false };
+    bool m_trackNetworkActivity { false };
 
 #if PLATFORM(IOS)
     WTF::String m_ctDataConnectionServiceType;
index a3d4a58..c56e7d5 100644 (file)
@@ -187,3 +187,13 @@ void WKContextConfigurationSetProcessSwapsOnWindowOpenWithOpener(WKContextConfig
 {
     toImpl(configuration)->setProcessSwapsOnWindowOpenWithOpener(swaps);
 }
+
+bool WKContextConfigurationTrackNetworkActivity(WKContextConfigurationRef configuration)
+{
+    return toImpl(configuration)->trackNetworkActivity();
+}
+
+void WKContextConfigurationSetTrackNetworkActivity(WKContextConfigurationRef configuration, bool track)
+{
+    toImpl(configuration)->setTrackNetworkActivity(track);
+}
index a759342..d79535c 100644 (file)
@@ -77,6 +77,9 @@ WK_EXPORT void WKContextConfigurationSetAlwaysKeepAndReuseSwappedProcesses(WKCon
 WK_EXPORT bool WKContextConfigurationProcessSwapsOnWindowOpenWithOpener(WKContextConfigurationRef configuration);
 WK_EXPORT void WKContextConfigurationSetProcessSwapsOnWindowOpenWithOpener(WKContextConfigurationRef configuration, bool swaps);
 
+WK_EXPORT bool WKContextConfigurationTrackNetworkActivity(WKContextConfigurationRef configuration);
+WK_EXPORT void WKContextConfigurationSetTrackNetworkActivity(WKContextConfigurationRef configuration, bool track);
+
 #ifdef __cplusplus
 }
 #endif
index 60295fe..424e4f4 100644 (file)
@@ -60,6 +60,7 @@ WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0))
 @property (nonatomic) BOOL processSwapsOnNavigation WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic) BOOL alwaysKeepAndReuseSwappedProcesses WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic) BOOL processSwapsOnWindowOpenWithOpener WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic) BOOL trackNetworkActivity WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
 
index 547ec89..5b69b61 100644 (file)
     return _processPoolConfiguration->processSwapsOnWindowOpenWithOpener();
 }
 
+- (BOOL)trackNetworkActivity
+{
+    return _processPoolConfiguration->trackNetworkActivity();
+}
+
+- (void)setTrackNetworkActivity:(BOOL)track
+{
+    _processPoolConfiguration->setTrackNetworkActivity(track);
+}
+
 #if PLATFORM(IOS)
 - (NSString *)CTDataConnectionServiceType
 {
index 6b12175..f7c8d84 100644 (file)
@@ -494,6 +494,8 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* with
     parameters.urlSchemesRegisteredAsCORSEnabled = copyToVector(m_schemesToRegisterAsCORSEnabled);
     parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest = copyToVector(m_schemesToRegisterAsCanDisplayOnlyIfCanRequest);
 
+    parameters.trackNetworkActivity = m_configuration->trackNetworkActivity();
+
     // Add any platform specific parameters
     platformInitializeNetworkProcess(parameters);
 
index 76f0ddd..c1be545 100644 (file)
                530258451DCBBD2200DA89C2 /* NetworkCaptureReplayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 530258381DCBBD1D00DA89C2 /* NetworkCaptureReplayer.h */; };
                530258461DCBBD2200DA89C2 /* NetworkDataTaskReplay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 530258391DCBBD1D00DA89C2 /* NetworkDataTaskReplay.cpp */; };
                530258471DCBBD2200DA89C2 /* NetworkDataTaskReplay.h in Headers */ = {isa = PBXBuildFile; fileRef = 5302583A1DCBBD1D00DA89C2 /* NetworkDataTaskReplay.h */; };
+               5315876C2076B762004BF9F3 /* NetworkActivityTrackerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5315876B2076B713004BF9F3 /* NetworkActivityTrackerCocoa.mm */; };
                532159531DBAE7180054AA3C /* NetworkSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 532159521DBAE6FC0054AA3C /* NetworkSession.cpp */; };
                532159541DBAE71D0054AA3C /* NetworkDataTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 532159511DBAE6FC0054AA3C /* NetworkDataTask.cpp */; };
                532159551DBAE7290054AA3C /* NetworkSessionCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 532159501DBAE6D70054AA3C /* NetworkSessionCocoa.h */; };
                532159561DBAE72D0054AA3C /* NetworkDataTaskCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */; };
+               535BCB922069C49C00CCCE02 /* NetworkActivityTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 535BCB902069C49C00CCCE02 /* NetworkActivityTracker.h */; };
+               5379DB72207E9470007D8C33 /* NetworkActivityTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F3CAA5206C443E0086490E /* NetworkActivityTracker.cpp */; };
                53BA47D01DC2EF5E004DF4AD /* NetworkDataTaskBlob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB5461DC2EE40009D48CF /* NetworkDataTaskBlob.cpp */; };
                53BA47D11DC2EF5E004DF4AD /* NetworkDataTaskBlob.h in Headers */ = {isa = PBXBuildFile; fileRef = 539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */; };
                53DEA3661DDE423100E82648 /* json.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 53DEA3651DDE422E00E82648 /* json.hpp */; };
                530258381DCBBD1D00DA89C2 /* NetworkCaptureReplayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkCaptureReplayer.h; path = NetworkProcess/capture/NetworkCaptureReplayer.h; sourceTree = "<group>"; };
                530258391DCBBD1D00DA89C2 /* NetworkDataTaskReplay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkDataTaskReplay.cpp; path = NetworkProcess/capture/NetworkDataTaskReplay.cpp; sourceTree = "<group>"; };
                5302583A1DCBBD1D00DA89C2 /* NetworkDataTaskReplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTaskReplay.h; path = NetworkProcess/capture/NetworkDataTaskReplay.h; sourceTree = "<group>"; };
+               5315876B2076B713004BF9F3 /* NetworkActivityTrackerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkActivityTrackerCocoa.mm; path = NetworkProcess/cocoa/NetworkActivityTrackerCocoa.mm; sourceTree = "<group>"; };
                5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTaskCocoa.h; path = NetworkProcess/cocoa/NetworkDataTaskCocoa.h; sourceTree = "<group>"; };
                532159501DBAE6D70054AA3C /* NetworkSessionCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkSessionCocoa.h; path = NetworkProcess/cocoa/NetworkSessionCocoa.h; sourceTree = "<group>"; };
                532159511DBAE6FC0054AA3C /* NetworkDataTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkDataTask.cpp; path = NetworkProcess/NetworkDataTask.cpp; sourceTree = "<group>"; };
                532159521DBAE6FC0054AA3C /* NetworkSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkSession.cpp; path = NetworkProcess/NetworkSession.cpp; sourceTree = "<group>"; };
+               535BCB902069C49C00CCCE02 /* NetworkActivityTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NetworkActivityTracker.h; path = NetworkProcess/NetworkActivityTracker.h; sourceTree = "<group>"; };
                539EB5461DC2EE40009D48CF /* NetworkDataTaskBlob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkDataTaskBlob.cpp; path = NetworkProcess/NetworkDataTaskBlob.cpp; sourceTree = "<group>"; };
                539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTaskBlob.h; path = NetworkProcess/NetworkDataTaskBlob.h; sourceTree = "<group>"; };
                53DEA3651DDE422E00E82648 /* json.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = json.hpp; path = NetworkProcess/capture/json.hpp; sourceTree = "<group>"; };
+               53F3CAA5206C443E0086490E /* NetworkActivityTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkActivityTracker.cpp; path = NetworkProcess/NetworkActivityTracker.cpp; sourceTree = "<group>"; };
                5750F32A2032D4E500389347 /* LocalAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LocalAuthentication.framework; path = System/Library/Frameworks/LocalAuthentication.framework; sourceTree = SDKROOT; };
                5760828B2029854200116678 /* WebCredentialsMessenger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCredentialsMessenger.h; sourceTree = "<group>"; };
                5760828C2029854200116678 /* WebCredentialsMessenger.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebCredentialsMessenger.cpp; sourceTree = "<group>"; };
                                2DA944BB188511DD00ED86DB /* ios */,
                                510CC7DC16138E2900D03ED3 /* mac */,
                                413075971DE84ED70039EC69 /* webrtc */,
+                               53F3CAA5206C443E0086490E /* NetworkActivityTracker.cpp */,
+                               535BCB902069C49C00CCCE02 /* NetworkActivityTracker.h */,
                                513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */,
                                513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */,
                                513A164B1630A9BF005D7D22 /* NetworkConnectionToWebProcess.messages.in */,
                7EC4F0F818E4A922008056AF /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               5315876B2076B713004BF9F3 /* NetworkActivityTrackerCocoa.mm */,
                                5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */,
                                5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */,
                                7EC4F0F918E4A945008056AF /* NetworkProcessCocoa.mm */,
                                1A6FBD2811E69BC200DB1371 /* NetscapePlugin.h in Headers */,
                                1A4A9C5612B816CF008FE984 /* NetscapePluginModule.h in Headers */,
                                1AA5889211EE70400061B882 /* NetscapePluginStream.h in Headers */,
+                               535BCB922069C49C00CCCE02 /* NetworkActivityTracker.h in Headers */,
                                E1798C7A16E6818800240139 /* NetworkBlobRegistry.h in Headers */,
                                E4436ECC1A0D040B00EAD204 /* NetworkCache.h in Headers */,
                                E49D40D71AD3FB170066B7B9 /* NetworkCacheBlobStorage.h in Headers */,
                                2D50365E1BCC793F00E20BB3 /* NativeWebGestureEventMac.mm in Sources */,
                                2DA9449E1884E4F000ED86DB /* NativeWebKeyboardEventIOS.mm in Sources */,
                                C02BFF1E1251502E009CCBEA /* NativeWebKeyboardEventMac.mm in Sources */,
+                               1C9EBA5C2087E74F00054429 /* NativeWebMouseEventIOS.mm in Sources */,
                                31EA25D2134F78C0005B1452 /* NativeWebMouseEventMac.mm in Sources */,
                                2DA9449F1884E4F000ED86DB /* NativeWebTouchEventIOS.mm in Sources */,
                                DF58C6361371ACA000F9A37C /* NativeWebWheelEventMac.mm in Sources */,
                                1A4A9C5512B816CF008FE984 /* NetscapePluginModule.cpp in Sources */,
                                1A4A9C9A12B821CD008FE984 /* NetscapePluginModuleMac.mm in Sources */,
                                1AA5889311EE70400061B882 /* NetscapePluginStream.cpp in Sources */,
+                               5379DB72207E9470007D8C33 /* NetworkActivityTracker.cpp in Sources */,
+                               5315876C2076B762004BF9F3 /* NetworkActivityTrackerCocoa.mm in Sources */,
                                E1798C7916E6818800240139 /* NetworkBlobRegistry.cpp in Sources */,
                                E4436ECA1A0D03FA00EAD204 /* NetworkCache.cpp in Sources */,
                                E49D40D91AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp in Sources */,
                                832AE2531BE2E8CD00FAAE10 /* NetworkCacheSpeculativeLoadManager.cpp in Sources */,
                                83BDCCB91AC5FDB6003F6441 /* NetworkCacheStatistics.cpp in Sources */,
                                E4436ED01A0D040B00EAD204 /* NetworkCacheStorage.cpp in Sources */,
-                               1C9EBA5C2087E74F00054429 /* NativeWebMouseEventIOS.mm in Sources */,
                                8310428C1BD6B66F00A715E4 /* NetworkCacheSubresourcesEntry.cpp in Sources */,
                                5302583D1DCBBD2200DA89C2 /* NetworkCaptureEvent.cpp in Sources */,
                                530258401DCBBD2200DA89C2 /* NetworkCaptureManager.cpp in Sources */,
index 50026ec..b691fee 100644 (file)
@@ -521,6 +521,11 @@ void WebLoaderStrategy::loadResourceSynchronously(FrameLoader& frameLoader, unsi
     }
 }
 
+void WebLoaderStrategy::pageLoadCompleted(uint64_t webPageID)
+{
+    WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::PageLoadCompleted(webPageID), 0);
+}
+
 static uint64_t generateLoadIdentifier()
 {
     static uint64_t identifier = 0;
index 14814a9..507216b 100644 (file)
@@ -49,6 +49,7 @@ public:
     
     void loadResource(WebCore::Frame&, WebCore::CachedResource&, WebCore::ResourceRequest&&, const WebCore::ResourceLoaderOptions&, CompletionHandler<void(RefPtr<WebCore::SubresourceLoader>&&)>&&) final;
     void loadResourceSynchronously(WebCore::FrameLoader&, unsigned long resourceLoadIdentifier, const WebCore::ResourceRequest&, WebCore::ClientCredentialPolicy, const WebCore::FetchOptions&, const WebCore::HTTPHeaderMap&, WebCore::ResourceError&, WebCore::ResourceResponse&, Vector<char>& data) final;
+    void pageLoadCompleted(uint64_t webPageID) final;
 
     void remove(WebCore::ResourceLoader*) final;
     void setDefersLoading(WebCore::ResourceLoader*, bool) final;
index 3c6dc52..2279487 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-02  Keith Rollin  <krollin@apple.com>
+
+        Add facility for tracking times and results of page and resource loading
+        https://bugs.webkit.org/show_bug.cgi?id=184838
+        <rdar://problem/36548974>
+
+        Reviewed by Brent Fulgham.
+
+        Add an empty override of the pure virtual
+        LoaderStrategy::pageLoadCompleted method.
+
+        * WebCoreSupport/WebResourceLoadScheduler.cpp:
+        (WebResourceLoadScheduler::pageLoadCompleted):
+        * WebCoreSupport/WebResourceLoadScheduler.h:
+
 2018-05-01  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] remove WK1 support
index c60b2e4..641e67c 100644 (file)
@@ -111,6 +111,10 @@ void WebResourceLoadScheduler::loadResourceSynchronously(FrameLoader& frameLoade
     ResourceHandle::loadResourceSynchronously(frameLoader.networkingContext(), request, options.credentials == FetchOptions::Credentials::Omit ? StoredCredentialsPolicy::DoNotUse : StoredCredentialsPolicy::Use, error, response, data);
 }
 
+void WebResourceLoadScheduler::pageLoadCompleted(uint64_t /*webPageID*/)
+{
+}
+
 void WebResourceLoadScheduler::schedulePluginStreamLoad(Frame& frame, NetscapePlugInStreamLoaderClient& client, ResourceRequest&& request, CompletionHandler<void(RefPtr<WebCore::NetscapePlugInStreamLoader>&&)>&& completionHandler)
 {
     NetscapePlugInStreamLoader::create(frame, client, WTFMove(request), [this, completionHandler = WTFMove(completionHandler)] (RefPtr<WebCore::NetscapePlugInStreamLoader>&& loader) mutable {
index 8828b54..770d63e 100644 (file)
@@ -51,6 +51,8 @@ public:
 
     void loadResource(WebCore::Frame&, WebCore::CachedResource&, WebCore::ResourceRequest&&, const WebCore::ResourceLoaderOptions&, CompletionHandler<void(RefPtr<WebCore::SubresourceLoader>&&)>&&) final;
     void loadResourceSynchronously(WebCore::FrameLoader&, unsigned long, const WebCore::ResourceRequest&, WebCore::ClientCredentialPolicy, const WebCore::FetchOptions&, const WebCore::HTTPHeaderMap&, WebCore::ResourceError&, WebCore::ResourceResponse&, Vector<char>&) final;
+    void pageLoadCompleted(uint64_t webPageID) final;
+
     void remove(WebCore::ResourceLoader*) final;
     void setDefersLoading(WebCore::ResourceLoader*, bool) final;
     void crossOriginRedirectReceived(WebCore::ResourceLoader*, const WebCore::URL& redirectURL) final;