Take UnboundedNetworking assertion when a file upload is in progress.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 17:57:57 +0000 (17:57 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 17:57:57 +0000 (17:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195497

Reviewed by Geoff Garen.

Source/WebCore:

* platform/network/ResourceRequestBase.cpp:
(WebCore::ResourceRequestBase::hasUpload const):
* platform/network/ResourceRequestBase.h:

Source/WebKit:

This patch implements whole bunch of bookkeeping in both the Networking and UI processes.

The TLDR of that bookkeeping is:
- Whenever any uploads are in progress, take an assertion for both Networking and UI processes.
- Whenever a particular WebProcess has an upload in progress, take an assertion for it.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::setProcessIdentifier):
(WebKit::NetworkConnectionToWebProcess::setConnectionHasUploads):
(WebKit::NetworkConnectionToWebProcess::clearConnectionHasUploads):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:

* NetworkProcess/NetworkResourceLoadMap.cpp: Added.
(WebKit::NetworkResourceLoadMap::add):
(WebKit::NetworkResourceLoadMap::remove):
(WebKit::NetworkResourceLoadMap::get const):
* NetworkProcess/NetworkResourceLoadMap.h: Added.
(WebKit::NetworkResourceLoadMap::NetworkResourceLoadMap):
(WebKit::NetworkResourceLoadMap::isEmpty const):
(WebKit::NetworkResourceLoadMap::contains const):
(WebKit::NetworkResourceLoadMap::begin):
(WebKit::NetworkResourceLoadMap::values):

* NetworkProcess/NetworkSession.cpp:

       * Scripts/webkit/messages.py:

* Sources.txt:

* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::takeUploadAssertion):
(WebKit::NetworkProcessProxy::clearUploadAssertion):
* UIProcess/Network/NetworkProcessProxy.h:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::setWebProcessHasUploads):
(WebKit::WebProcessPool::clearWebProcessHasUploads):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessPool.messages.in:

       * WebKit.xcodeproj/project.pbxproj:

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::ensureNetworkProcessConnection):

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

19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/ResourceRequestBase.cpp
Source/WebCore/platform/network/ResourceRequestBase.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
Source/WebKit/NetworkProcess/NetworkResourceLoadMap.cpp [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkResourceLoadMap.h [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkSession.cpp
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/Sources.txt
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebProcessPool.messages.in
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebProcess.cpp

index fcee991..6227c2e 100644 (file)
@@ -1,3 +1,14 @@
+2019-03-12  Brady Eidson  <beidson@apple.com>
+
+        Take UnboundedNetworking assertion when a file upload is in progress.
+        https://bugs.webkit.org/show_bug.cgi?id=195497
+
+        Reviewed by Geoff Garen.
+
+        * platform/network/ResourceRequestBase.cpp:
+        (WebCore::ResourceRequestBase::hasUpload const):
+        * platform/network/ResourceRequestBase.h:
+
 2019-03-13  Youenn Fablet  <youenn@apple.com>
 
         Enable libwebrtc logging control through WebCore
index d540f44..4dbc37e 100644 (file)
@@ -488,6 +488,18 @@ FormData* ResourceRequestBase::httpBody() const
     return m_httpBody.get();
 }
 
+bool ResourceRequestBase::hasUpload() const
+{
+    if (auto* body = httpBody()) {
+        for (auto& element : body->elements()) {
+            if (WTF::holds_alternative<WebCore::FormDataElement::EncodedFileData>(element.data) || WTF::holds_alternative<WebCore::FormDataElement::EncodedBlobData>(element.data))
+                return true;
+        }
+    }
+    
+    return false;
+}
+
 void ResourceRequestBase::setHTTPBody(RefPtr<FormData>&& httpBody)
 {
     updateResourceRequest();
index 927f43a..255768d 100644 (file)
@@ -144,6 +144,7 @@ public:
     WEBCORE_EXPORT void setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2 = String(), const String& encoding3 = String());
 
     WEBCORE_EXPORT FormData* httpBody() const;
+    WEBCORE_EXPORT bool hasUpload() const;
     WEBCORE_EXPORT void setHTTPBody(RefPtr<FormData>&&);
 
     bool allowCookies() const;
index 6c7197e..c1bfc8a 100644 (file)
@@ -1,3 +1,57 @@
+2019-03-12  Brady Eidson  <beidson@apple.com>
+
+        Take UnboundedNetworking assertion when a file upload is in progress.
+        https://bugs.webkit.org/show_bug.cgi?id=195497
+
+        Reviewed by Geoff Garen.
+
+        This patch implements whole bunch of bookkeeping in both the Networking and UI processes.
+
+        The TLDR of that bookkeeping is:
+        - Whenever any uploads are in progress, take an assertion for both Networking and UI processes.
+        - Whenever a particular WebProcess has an upload in progress, take an assertion for it.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
+        (WebKit::NetworkConnectionToWebProcess::setProcessIdentifier):
+        (WebKit::NetworkConnectionToWebProcess::setConnectionHasUploads):
+        (WebKit::NetworkConnectionToWebProcess::clearConnectionHasUploads):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+
+        * NetworkProcess/NetworkResourceLoadMap.cpp: Added.
+        (WebKit::NetworkResourceLoadMap::add):
+        (WebKit::NetworkResourceLoadMap::remove):
+        (WebKit::NetworkResourceLoadMap::get const):
+        * NetworkProcess/NetworkResourceLoadMap.h: Added.
+        (WebKit::NetworkResourceLoadMap::NetworkResourceLoadMap):
+        (WebKit::NetworkResourceLoadMap::isEmpty const):
+        (WebKit::NetworkResourceLoadMap::contains const):
+        (WebKit::NetworkResourceLoadMap::begin):
+        (WebKit::NetworkResourceLoadMap::values):
+
+        * NetworkProcess/NetworkSession.cpp:
+       * Scripts/webkit/messages.py:
+
+        * Sources.txt:
+
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::takeUploadAssertion):
+        (WebKit::NetworkProcessProxy::clearUploadAssertion):
+        * UIProcess/Network/NetworkProcessProxy.h:
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::setWebProcessHasUploads):
+        (WebKit::WebProcessPool::clearWebProcessHasUploads):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessPool.messages.in:
+       * WebKit.xcodeproj/project.pbxproj:
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::ensureNetworkProcessConnection):
+
 2019-03-13  Chris Dumez  <cdumez@apple.com>
 
         Use new RegistrableDomain type in PSON code
index bd1093e..8d90a09 100644 (file)
@@ -50,6 +50,7 @@
 #include "WebErrors.h"
 #include "WebIDBConnectionToClient.h"
 #include "WebIDBConnectionToClientMessages.h"
+#include "WebProcessPoolMessages.h"
 #include "WebResourceLoadStatisticsStore.h"
 #include "WebSWServerConnection.h"
 #include "WebSWServerConnectionMessages.h"
@@ -77,6 +78,7 @@ Ref<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(Network
 NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(NetworkProcess& networkProcess, IPC::Connection::Identifier connectionIdentifier)
     : m_connection(IPC::Connection::createServerConnection(connectionIdentifier, *this))
     , m_networkProcess(networkProcess)
+    , m_networkResourceLoaders(*this)
 #if ENABLE(WEB_RTC)
     , m_mdnsRegister(*this)
 #endif
@@ -821,4 +823,23 @@ void NetworkConnectionToWebProcess::establishSWServerConnection(PAL::SessionID s
 }
 #endif
 
+void NetworkConnectionToWebProcess::setWebProcessIdentifier(ProcessIdentifier webProcessIdentifier)
+{
+    m_webProcessIdentifier = webProcessIdentifier;
+}
+
+void NetworkConnectionToWebProcess::setConnectionHasUploads()
+{
+    ASSERT(!m_connectionHasUploads);
+    m_connectionHasUploads = true;
+    m_networkProcess->parentProcessConnection()->send(Messages::WebProcessPool::SetWebProcessHasUploads(m_webProcessIdentifier), 0);
+}
+
+void NetworkConnectionToWebProcess::clearConnectionHasUploads()
+{
+    ASSERT(m_connectionHasUploads);
+    m_connectionHasUploads = false;
+    m_networkProcess->parentProcessConnection()->send(Messages::WebProcessPool::ClearWebProcessHasUploads(m_webProcessIdentifier), 0);
+}
+
 } // namespace WebKit
index 398430e..48e9753 100644 (file)
 #include "NetworkConnectionToWebProcessMessages.h"
 #include "NetworkMDNSRegister.h"
 #include "NetworkRTCProvider.h"
+#include "NetworkResourceLoadMap.h"
 #include "WebPaymentCoordinatorProxy.h"
 #include <WebCore/NetworkLoadInformation.h>
+#include <WebCore/ProcessIdentifier.h>
 #include <WebCore/RegistrableDomain.h>
 #include <wtf/RefCounted.h>
 
@@ -135,6 +137,10 @@ public:
     Vector<RefPtr<WebCore::BlobDataFileReference>> filesInBlob(const URL&);
     Vector<RefPtr<WebCore::BlobDataFileReference>> resolveBlobReferences(const NetworkResourceLoadParameters&);
 
+    void setWebProcessIdentifier(WebCore::ProcessIdentifier);
+    void setConnectionHasUploads();
+    void clearConnectionHasUploads();
+
 private:
     NetworkConnectionToWebProcess(NetworkProcess&, IPC::Connection::Identifier);
 
@@ -268,7 +274,7 @@ private:
     Ref<NetworkProcess> m_networkProcess;
 
     HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
-    HashMap<ResourceLoadIdentifier, Ref<NetworkResourceLoader>> m_networkResourceLoaders;
+    NetworkResourceLoadMap m_networkResourceLoaders;
     HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
     Vector<ResourceNetworkActivityTracker> m_networkActivityTrackers;
 
@@ -297,6 +303,9 @@ private:
 #if ENABLE(APPLE_PAY_REMOTE_UI)
     std::unique_ptr<WebPaymentCoordinatorProxy> m_paymentCoordinator;
 #endif
+
+    WebCore::ProcessIdentifier m_webProcessIdentifier;
+    bool m_connectionHasUploads { false };
 };
 
 } // namespace WebKit
index afe420f..d129946 100644 (file)
@@ -83,4 +83,6 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
 #if ENABLE(SERVICE_WORKER)
     EstablishSWServerConnection(PAL::SessionID sessionID) -> (WebCore::SWServerConnectionIdentifier serverConnectionIdentifier) LegacySync
 #endif
+
+    SetWebProcessIdentifier(WebCore::ProcessIdentifier processIdentifier)
 }
diff --git a/Source/WebKit/NetworkProcess/NetworkResourceLoadMap.cpp b/Source/WebKit/NetworkProcess/NetworkResourceLoadMap.cpp
new file mode 100644 (file)
index 0000000..c20fb8a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 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 "NetworkResourceLoadMap.h"
+
+namespace WebKit {
+
+NetworkResourceLoadMap::MapType::AddResult NetworkResourceLoadMap::add(ResourceLoadIdentifier identifier, Ref<NetworkResourceLoader>&& loader)
+{
+    auto result = m_loaders.add(identifier, WTFMove(loader));
+    ASSERT(result.isNewEntry);
+        
+    if (result.iterator->value->originalRequest().hasUpload()) {
+        if (m_loadersWithUploads.isEmpty())
+            m_connectionToWebProcess.setConnectionHasUploads();
+        m_loadersWithUploads.add(result.iterator->value.ptr());
+    }
+
+    return result;
+}
+
+bool NetworkResourceLoadMap::remove(ResourceLoadIdentifier identifier)
+{
+    auto loader = m_loaders.take(identifier);
+    if (!loader)
+        return false;
+
+    if ((*loader)->originalRequest().hasUpload()) {
+        m_loadersWithUploads.remove(loader->ptr());
+        if (m_loadersWithUploads.isEmpty())
+            m_connectionToWebProcess.clearConnectionHasUploads();
+    }
+
+    return true;
+}
+
+NetworkResourceLoader* NetworkResourceLoadMap::get(ResourceLoadIdentifier identifier) const
+{
+    return m_loaders.get(identifier);
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/NetworkResourceLoadMap.h b/Source/WebKit/NetworkProcess/NetworkResourceLoadMap.h
new file mode 100644 (file)
index 0000000..7ef45b5
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 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 "NetworkConnectionToWebProcess.h"
+#include "NetworkResourceLoader.h"
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+
+#if ENABLE(TAKE_UNBOUNDED_NETWORKING_ASSERTION)
+#include "ProcessAssertion.h"
+#endif
+
+namespace WebKit {
+
+typedef uint64_t ResourceLoadIdentifier;
+
+class NetworkResourceLoadMap {
+public:
+    typedef HashMap<ResourceLoadIdentifier, Ref<NetworkResourceLoader>> MapType;
+
+    NetworkResourceLoadMap(NetworkConnectionToWebProcess& connection)
+        : m_connectionToWebProcess(connection)
+    {
+    }
+
+    bool isEmpty() const { return m_loaders.isEmpty(); }
+    bool contains(ResourceLoadIdentifier identifier) const { return m_loaders.contains(identifier); }
+    MapType::iterator begin() { return m_loaders.begin(); }
+    MapType::ValuesIteratorRange values() { return m_loaders.values(); }
+
+    MapType::AddResult add(ResourceLoadIdentifier, Ref<NetworkResourceLoader>&&);
+    NetworkResourceLoader* get(ResourceLoadIdentifier) const;
+    bool remove(ResourceLoadIdentifier);
+
+private:
+    NetworkConnectionToWebProcess& m_connectionToWebProcess;
+    MapType m_loaders;
+    HashSet<NetworkResourceLoader*> m_loadersWithUploads;
+};
+
+} // namespace WebKit
index a0b065c..3c8c938 100644 (file)
@@ -29,6 +29,8 @@
 #include "NetworkAdClickAttribution.h"
 #include "NetworkProcess.h"
 #include "NetworkProcessProxyMessages.h"
+#include "WebPageProxy.h"
+#include "WebPageProxyMessages.h"
 #include "WebProcessProxy.h"
 #include <WebCore/AdClickAttribution.h>
 #include <WebCore/CookieJar.h>
index 8def845..8c867a8 100644 (file)
@@ -198,6 +198,7 @@ def forward_declarations_and_headers(receiver):
         'WebCore::DocumentIdentifier',
         'WebCore::FetchIdentifier',
         'WebCore::PointerID',
+        'WebCore::ProcessIdentifier',
         'WebCore::ServiceWorkerIdentifier',
         'WebCore::ServiceWorkerJobIdentifier',
         'WebCore::ServiceWorkerOrClientData',
@@ -424,6 +425,7 @@ def headers_for_type(type):
         'WebCore::PluginInfo': ['<WebCore/PluginData.h>'],
         'WebCore::PolicyAction': ['<WebCore/FrameLoaderTypes.h>'],
         'WebCore::PolicyCheckIdentifier': ['<WebCore/FrameLoaderTypes.h>'],
+        'WebCore::ProcessIdentifier': ['<WebCore/ProcessIdentifier.h>'],
         'WebCore::RecentSearch': ['<WebCore/SearchPopupMenu.h>'],
         'WebCore::RouteSharingPolicy': ['<WebCore/AudioSession.h>'],
         'WebCore::SWServerConnectionIdentifier': ['<WebCore/ServiceWorkerTypes.h>'],
index 1c646bd..1c9ee2c 100644 (file)
@@ -35,6 +35,7 @@ NetworkProcess/NetworkProcess.cpp
 NetworkProcess/NetworkProcessCreationParameters.cpp
 NetworkProcess/NetworkProcessPlatformStrategies.cpp
 NetworkProcess/NetworkResourceLoadParameters.cpp
+NetworkProcess/NetworkResourceLoadMap.cpp
 NetworkProcess/NetworkResourceLoader.cpp
 NetworkProcess/NetworkSession.cpp
 NetworkProcess/NetworkSessionCreationParameters.cpp
index a56d10f..d60d8ee 100644 (file)
@@ -1201,6 +1201,18 @@ void NetworkProcessProxy::requestStorageSpace(PAL::SessionID sessionID, const We
     store->client().requestStorageSpace(origin.topOrigin, origin.clientOrigin, quota, currentSize, spaceRequired, WTFMove(completionHandler));
 }
 
+void NetworkProcessProxy::takeUploadAssertion()
+{
+    ASSERT(!m_uploadAssertion);
+    m_uploadAssertion = std::make_unique<ProcessAssertion>(processIdentifier(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);
+}
+
+void NetworkProcessProxy::clearUploadAssertion()
+{
+    ASSERT(m_uploadAssertion);
+    m_uploadAssertion = nullptr;
+}
+
 } // namespace WebKit
 
 #undef MESSAGE_CHECK
index 1ee3069..b2fbca5 100644 (file)
@@ -173,6 +173,9 @@ public:
 
     void addSession(Ref<WebsiteDataStore>&&);
     void removeSession(PAL::SessionID);
+    
+    void takeUploadAssertion();
+    void clearUploadAssertion();
 
 private:
     // AuxiliaryProcessProxy
@@ -261,6 +264,8 @@ private:
 #endif
 
     HashMap<PAL::SessionID, RefPtr<WebsiteDataStore>> m_websiteDataStores;
+    
+    std::unique_ptr<ProcessAssertion> m_uploadAssertion;
 };
 
 } // namespace WebKit
index 4b27830..8a28536 100644 (file)
@@ -2511,4 +2511,47 @@ void WebProcessPool::committedCrossSiteLoadWithLinkDecoration(PAL::SessionID ses
 #endif
 }
 
+void WebProcessPool::setWebProcessHasUploads(ProcessIdentifier processID)
+{
+    auto* process = WebProcessProxy::processForIdentifier(processID);
+    ASSERT(process);
+
+    RELEASE_LOG(ProcessSuspension, "Web process pid %u now has uploads in progress", (unsigned)process->processIdentifier());
+
+    if (m_processesWithUploads.isEmpty()) {
+        RELEASE_LOG(ProcessSuspension, "The number of uploads in progress is now one. Taking Networking and UI process assertions.");
+
+        ASSERT(m_networkProcess);
+        m_networkProcess->takeUploadAssertion();
+        
+        ASSERT(!m_uiProcessUploadAssertion);
+        m_uiProcessUploadAssertion = std::make_unique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);
+    }
+    
+    auto result = m_processesWithUploads.add(processID, nullptr);
+    ASSERT(result.isNewEntry);
+    result.iterator->value = std::make_unique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);
+}
+
+void WebProcessPool::clearWebProcessHasUploads(ProcessIdentifier processID)
+{
+    auto result = m_processesWithUploads.take(processID);
+    ASSERT_UNUSED(result, result);
+
+    auto* process = WebProcessProxy::processForIdentifier(processID);
+    ASSERT(process);
+    RELEASE_LOG(ProcessSuspension, "Web process pid %u no longer has uploads in progress", (unsigned)process->processIdentifier());
+
+    if (m_processesWithUploads.isEmpty()) {
+        RELEASE_LOG(ProcessSuspension, "The number of uploads in progress is now zero. Releasing Networking and UI process assertions.");
+
+        if (m_networkProcess)
+            m_networkProcess->clearUploadAssertion();
+        
+        ASSERT(m_uiProcessUploadAssertion);
+        m_uiProcessUploadAssertion = nullptr;
+    }
+    
+}
+
 } // namespace WebKit
index f109c2c..ec34718 100644 (file)
@@ -44,6 +44,7 @@
 #include "WebContextClient.h"
 #include "WebContextConnectionClient.h"
 #include "WebProcessProxy.h"
+#include <WebCore/ProcessIdentifier.h>
 #include <WebCore/RegistrableDomain.h>
 #include <WebCore/SecurityOriginHash.h>
 #include <WebCore/SharedStringHash.h>
@@ -52,7 +53,6 @@
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/MemoryPressureHandler.h>
-#include <wtf/ProcessID.h>
 #include <wtf/RefCounter.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/StringHash.h>
@@ -495,6 +495,9 @@ public:
     const HashMap<CString, SandboxPermission>& sandboxPaths() const { return m_extraSandboxPaths; };
     bool sandboxEnabled() const { return m_sandboxEnabled; };
 #endif
+    
+    void setWebProcessHasUploads(WebCore::ProcessIdentifier);
+    void clearWebProcessHasUploads(WebCore::ProcessIdentifier);
 
 private:
     void platformInitialize();
@@ -768,6 +771,9 @@ private:
     bool m_sandboxEnabled { false };
     HashMap<CString, SandboxPermission> m_extraSandboxPaths;
 #endif
+
+    HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> m_processesWithUploads;
+    std::unique_ptr<ProcessAssertion> m_uiProcessUploadAssertion;
 };
 
 template<typename T>
index f32d19d..ebf2c3b 100644 (file)
@@ -37,6 +37,9 @@ messages -> WebProcessPool {
 
     ReportWebContentCPUTime(Seconds cpuTime, uint64_t activityState)
 
+    SetWebProcessHasUploads(WebCore::ProcessIdentifier processID)
+    ClearWebProcessHasUploads(WebCore::ProcessIdentifier processID)
+
 #if ENABLE(SERVICE_WORKER)
     PostMessageToServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerIdentifier sourceIdentifier, String sourceOrigin)
     PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientIdentifier source, WebCore::SWServerConnectionIdentifier connectionIdentifier)
index b77ecf1..33945f2 100644 (file)
                51217461164C20E30037A5C1 /* ShareableResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 5121745F164C20E30037A5C1 /* ShareableResource.h */; };
                5123CF1C133D260A0056F800 /* WKIconDatabaseCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 5123CF1A133D260A0056F800 /* WKIconDatabaseCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51240EBA220A08D2005CFC63 /* DownloadMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 51240EB8220A08CA005CFC63 /* DownloadMap.h */; };
+               51240EC0220B694C005CFC63 /* NetworkResourceLoadMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 51240EBE220B6947005CFC63 /* NetworkResourceLoadMap.h */; };
                512935D81288D19400A4B695 /* WebContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 512935D61288D19400A4B695 /* WebContextMenuItem.h */; };
                512935E41288D97800A4B695 /* InjectedBundlePageContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 512935E21288D97800A4B695 /* InjectedBundlePageContextMenuClient.h */; };
                512E34E5130B4D0500ABD19A /* WKApplicationCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A33B4130B308C00F80CB5 /* WKApplicationCacheManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5123CF1A133D260A0056F800 /* WKIconDatabaseCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKIconDatabaseCG.h; path = cg/WKIconDatabaseCG.h; sourceTree = "<group>"; };
                51240EB8220A08CA005CFC63 /* DownloadMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadMap.h; sourceTree = "<group>"; };
                51240EB9220A08CA005CFC63 /* DownloadMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DownloadMap.cpp; sourceTree = "<group>"; };
+               51240EBE220B6947005CFC63 /* NetworkResourceLoadMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkResourceLoadMap.h; sourceTree = "<group>"; };
+               51240EBF220B6948005CFC63 /* NetworkResourceLoadMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkResourceLoadMap.cpp; sourceTree = "<group>"; };
                512935D51288D19400A4B695 /* WebContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenuItem.cpp; sourceTree = "<group>"; };
                512935D61288D19400A4B695 /* WebContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuItem.h; sourceTree = "<group>"; };
                512935E11288D97800A4B695 /* InjectedBundlePageContextMenuClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageContextMenuClient.cpp; sourceTree = "<group>"; };
                                51FD18B31651FBAD00DBE1CE /* NetworkResourceLoader.cpp */,
                                51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */,
                                E1525517170109FB003D7ADB /* NetworkResourceLoader.messages.in */,
+                               51240EBF220B6948005CFC63 /* NetworkResourceLoadMap.cpp */,
+                               51240EBE220B6947005CFC63 /* NetworkResourceLoadMap.h */,
                                5C1426E51C23F80500D41183 /* NetworkResourceLoadParameters.cpp */,
                                5C1426E61C23F80500D41183 /* NetworkResourceLoadParameters.h */,
                                532159521DBAE6FC0054AA3C /* NetworkSession.cpp */,
                                A11455B0211FD25200CA935B /* NetworkProximityManager.h in Headers */,
                                51FD18B61651FBAD00DBE1CE /* NetworkResourceLoader.h in Headers */,
                                E152551B17011819003D7ADB /* NetworkResourceLoaderMessages.h in Headers */,
+                               51240EC0220B694C005CFC63 /* NetworkResourceLoadMap.h in Headers */,
                                5C1426F01C23F80900D41183 /* NetworkResourceLoadParameters.h in Headers */,
                                413075AC1DE85F370039EC69 /* NetworkRTCMonitor.h in Headers */,
                                41DC45961E3D6E2200B11F51 /* NetworkRTCProvider.h in Headers */,
index 69cb9e4..d40ea81 100644 (file)
@@ -1230,6 +1230,7 @@ NetworkProcessConnection& WebProcess::ensureNetworkProcessConnection()
             CRASH();
 
         m_networkProcessConnection = NetworkProcessConnection::create(connectionIdentifier);
+        m_networkProcessConnection->connection().send(Messages::NetworkConnectionToWebProcess::SetWebProcessIdentifier(Process::identifier()), 0);
     }
     
     return *m_networkProcessConnection;