Title: [234968] trunk/Source
Revision
234968
Author
[email protected]
Date
2018-08-16 16:20:56 -0700 (Thu, 16 Aug 2018)

Log Message

[watchOS] Upstream Proximity Networking (nee Wi-Fi Assertions)
https://bugs.webkit.org/show_bug.cgi?id=188664

Reviewed by Tim Horton.

Source/WebKit:

Proximity Networking provides two features for speeding up page loads on watchOS:

1. Binding requests to the Apple Watch's Wi-Fi interface even when the iPhone is in proximity.
2. When Wi-Fi isn't available, preemptively upgrading the Bluetooth link to its fastest data
rate prior to starting page loads.

* Configurations/WebKit.xcconfig:

Added LDFLAGS for Proximity Networking.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::NetworkProcess):
(WebKit::NetworkProcess::proximityManager):
* NetworkProcess/NetworkProcess.h:

Added NetworkProximityManager as a supplement.

* NetworkProcess/NetworkProcessCreationParameters.cpp:
(WebKit::NetworkProcessCreationParameters::encode const):
(WebKit::NetworkProcessCreationParameters::decode):
* NetworkProcess/NetworkProcessCreationParameters.h:

Renamed ENABLE(WIFI_ASSERTIONS) to ENABLE(PROXIMITY_NETWORKING).

* NetworkProcess/cocoa/NetworkDataTaskCocoa.h:

Renamed m_wiFiAssertionHolder to m_proximityAssertionToken and changed its type from an
optional WiFiAssertionHolder to an optional NetworkProximityAssertion::Token.

* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
(WebKit::NetworkProcess::platformPrepareToSuspend):
(WebKit::NetworkProcess::platformProcessDidResume):
(WebKit::NetworkProcess::platformProcessDidTransitionToBackground):
(WebKit::NetworkProcess::platformProcessDidTransitionToForeground):

Changed to use NetworkProximityManager.

* NetworkProcess/cocoa/WiFiAssertionHolder.h: Removed.
* NetworkProcess/cocoa/WiFiAssertionHolder.mm: Removed.
* NetworkProcess/watchos/NetworkProximityAssertion.h: Added.
(WebKit::NetworkProximityAssertion::Token::Token):
(WebKit::NetworkProximityAssertion::Token::~Token):

Added. NetworkDataTasks hold these tokens to keep Bluetooth or Wi-Fi assertions active
during loading. When the last token is destroyed, its associated assertion will be
deactivated.

* NetworkProcess/watchos/NetworkProximityAssertion.mm: Added.
(WebKit::NetworkProximityAssertion::NetworkProximityAssertion):
(WebKit::NetworkProximityAssertion::hold):
(WebKit::NetworkProximityAssertion::release):
(WebKit::NetworkProximityAssertion::resume):
(WebKit::NetworkProximityAssertion::suspend):
(WebKit::NetworkProximityAssertion::suspendNow):
(WebKit::NetworkProximityAssertion::releaseTimerFired):
(WebKit::NetworkProximityAssertion::suspendAfterBackgroundingTimerFired):

Added. NetworkProximityAssertion is the base class for Bluetooth and Wi-Fi assertions. It
manages the logic for holding and releasing assertions as well as responding to network
process backgrounding and suspension.

(WebKit::BluetoothProximityAssertion::BluetoothProximityAssertion):
(WebKit::BluetoothProximityAssertion::suspend):
(WebKit::BluetoothProximityAssertion::holdNow):
(WebKit::BluetoothProximityAssertion::releaseNow):

Added. Holds a Bluetooth assertion by calling -[IDSService setLinkPreferences:].

(WebKit::WiFiProximityAssertion::WiFiProximityAssertion):
(WebKit::WiFiProximityAssertion::holdNow):
(WebKit::WiFiProximityAssertion::releaseNow):

Added. Holds a Wi-Fi assertion by using WiFiManagerClient.

* NetworkProcess/watchos/NetworkProximityManager.h: Added.
* NetworkProcess/watchos/NetworkProximityManager.mm: Added.
(-[WKProximityServiceDelegate setClient:]):
(-[WKProximityServiceDelegate service:devicesChanged:]):
(-[WKProximityServiceDelegate service:nearbyDevicesChanged:]):
(WebKit::NetworkProximityManager::NetworkProximityManager):
(WebKit::NetworkProximityManager::~NetworkProximityManager):
(WebKit::NetworkProximityManager::supplementName):
(WebKit::bindRequestToWiFi):
(WebKit::NetworkProximityManager::applyProperties):
(WebKit::NetworkProximityManager::resume):
(WebKit::NetworkProximityManager::suspend):
(WebKit::NetworkProximityManager::recommendation const):
(WebKit::NetworkProximityManager::processRecommendations):
(WebKit::toProcessID):
(WebKit::NetworkProximityManager::resumeRecommendations):
(WebKit::NetworkProximityManager::suspendRecommendations):
(WebKit::NetworkProximityManager::updateCompanionProximity):
(WebKit::NetworkProximityManager::updateRecommendation):
(WebKit::NetworkProximityManager::initialize):
(WebKit::NetworkProximityManager::devicesChanged):

Added. NetworkProximityManager is a network process supplement that can bind
NetworkDataTasks to Wi-Fi, associate assertions with NetworkDataTasks, check for companion
proximity, ask for proximity network recommendations, and respond to network process
backgrounding and suspending.

* Platform/Logging.h:

Renamed the WiFiAssertions log channel to ProximityNetworking.

* Platform/spi/ios/MobileWiFiSPI.h:
* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeNetworkProcess):

Renamed ENABLE(WIFI_ASSERTIONS) to ENABLE(PROXIMITY_NETWORKING).

* WebKit.xcodeproj/project.pbxproj:
* config.h:

Removed unused definition of HAVE_MOBILE_WIFI.

Source/WTF:

* wtf/FeatureDefines.h: Defined ENABLE_PROXIMITY_NETWORKING to 1 on watchOS.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (234967 => 234968)


--- trunk/Source/WTF/ChangeLog	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WTF/ChangeLog	2018-08-16 23:20:56 UTC (rev 234968)
@@ -1,3 +1,12 @@
+2018-08-16  Andy Estes  <[email protected]>
+
+        [watchOS] Upstream Proximity Networking (nee Wi-Fi Assertions)
+        https://bugs.webkit.org/show_bug.cgi?id=188664
+
+        Reviewed by Tim Horton.
+
+        * wtf/FeatureDefines.h: Defined ENABLE_PROXIMITY_NETWORKING to 1 on watchOS.
+
 2018-08-16  Alex Christensen  <[email protected]>
 
         Re-introduce assertion removed in r234890

Modified: trunk/Source/WTF/wtf/FeatureDefines.h (234967 => 234968)


--- trunk/Source/WTF/wtf/FeatureDefines.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WTF/wtf/FeatureDefines.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -180,6 +180,17 @@
 
 #endif /* PLATFORM(IOS) */
 
+/* --------- Apple WATCHOS port --------- */
+#if PLATFORM(WATCHOS)
+
+#if !defined(ENABLE_PROXIMITY_NETWORKING)
+#if !TARGET_OS_SIMULATOR
+#define ENABLE_PROXIMITY_NETWORKING 1
+#endif
+#endif
+
+#endif /* PLATFORM(WATCHOS) */
+
 /* --------- Apple MAC port (not IOS) --------- */
 #if PLATFORM(MAC)
 

Modified: trunk/Source/WebKit/CMakeLists.txt (234967 => 234968)


--- trunk/Source/WebKit/CMakeLists.txt	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/CMakeLists.txt	2018-08-16 23:20:56 UTC (rev 234968)
@@ -11,6 +11,7 @@
     "${WEBKIT_DIR}/NetworkProcess/FileAPI"
     "${WEBKIT_DIR}/NetworkProcess/cache"
     "${WEBKIT_DIR}/NetworkProcess/capture"
+    "${WEBKIT_DIR}/NetworkProcess/watchos"
     "${WEBKIT_DIR}/NetworkProcess/webrtc"
     "${WEBKIT_DIR}/Platform"
     "${WEBKIT_DIR}/Platform/IPC"

Modified: trunk/Source/WebKit/ChangeLog (234967 => 234968)


--- trunk/Source/WebKit/ChangeLog	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/ChangeLog	2018-08-16 23:20:56 UTC (rev 234968)
@@ -1,3 +1,133 @@
+2018-08-16  Andy Estes  <[email protected]>
+
+        [watchOS] Upstream Proximity Networking (nee Wi-Fi Assertions)
+        https://bugs.webkit.org/show_bug.cgi?id=188664
+
+        Reviewed by Tim Horton.
+
+        Proximity Networking provides two features for speeding up page loads on watchOS:
+
+        1. Binding requests to the Apple Watch's Wi-Fi interface even when the iPhone is in proximity.
+        2. When Wi-Fi isn't available, preemptively upgrading the Bluetooth link to its fastest data
+        rate prior to starting page loads.
+
+        * Configurations/WebKit.xcconfig:
+
+        Added LDFLAGS for Proximity Networking.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::NetworkProcess):
+        (WebKit::NetworkProcess::proximityManager):
+        * NetworkProcess/NetworkProcess.h:
+
+        Added NetworkProximityManager as a supplement.
+
+        * NetworkProcess/NetworkProcessCreationParameters.cpp:
+        (WebKit::NetworkProcessCreationParameters::encode const):
+        (WebKit::NetworkProcessCreationParameters::decode):
+        * NetworkProcess/NetworkProcessCreationParameters.h:
+
+        Renamed ENABLE(WIFI_ASSERTIONS) to ENABLE(PROXIMITY_NETWORKING).
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
+
+        Renamed m_wiFiAssertionHolder to m_proximityAssertionToken and changed its type from an
+        optional WiFiAssertionHolder to an optional NetworkProximityAssertion::Token.
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
+        (WebKit::NetworkProcess::platformPrepareToSuspend):
+        (WebKit::NetworkProcess::platformProcessDidResume):
+        (WebKit::NetworkProcess::platformProcessDidTransitionToBackground):
+        (WebKit::NetworkProcess::platformProcessDidTransitionToForeground):
+
+        Changed to use NetworkProximityManager.
+
+        * NetworkProcess/cocoa/WiFiAssertionHolder.h: Removed.
+        * NetworkProcess/cocoa/WiFiAssertionHolder.mm: Removed.
+        * NetworkProcess/watchos/NetworkProximityAssertion.h: Added.
+        (WebKit::NetworkProximityAssertion::Token::Token):
+        (WebKit::NetworkProximityAssertion::Token::~Token):
+
+        Added. NetworkDataTasks hold these tokens to keep Bluetooth or Wi-Fi assertions active
+        during loading. When the last token is destroyed, its associated assertion will be
+        deactivated.
+
+        * NetworkProcess/watchos/NetworkProximityAssertion.mm: Added.
+        (WebKit::NetworkProximityAssertion::NetworkProximityAssertion):
+        (WebKit::NetworkProximityAssertion::hold):
+        (WebKit::NetworkProximityAssertion::release):
+        (WebKit::NetworkProximityAssertion::resume):
+        (WebKit::NetworkProximityAssertion::suspend):
+        (WebKit::NetworkProximityAssertion::suspendNow):
+        (WebKit::NetworkProximityAssertion::releaseTimerFired):
+        (WebKit::NetworkProximityAssertion::suspendAfterBackgroundingTimerFired):
+
+        Added. NetworkProximityAssertion is the base class for Bluetooth and Wi-Fi assertions. It
+        manages the logic for holding and releasing assertions as well as responding to network
+        process backgrounding and suspension.
+
+        (WebKit::BluetoothProximityAssertion::BluetoothProximityAssertion):
+        (WebKit::BluetoothProximityAssertion::suspend):
+        (WebKit::BluetoothProximityAssertion::holdNow):
+        (WebKit::BluetoothProximityAssertion::releaseNow):
+
+        Added. Holds a Bluetooth assertion by calling -[IDSService setLinkPreferences:].
+
+        (WebKit::WiFiProximityAssertion::WiFiProximityAssertion):
+        (WebKit::WiFiProximityAssertion::holdNow):
+        (WebKit::WiFiProximityAssertion::releaseNow):
+
+        Added. Holds a Wi-Fi assertion by using WiFiManagerClient.
+
+        * NetworkProcess/watchos/NetworkProximityManager.h: Added.
+        * NetworkProcess/watchos/NetworkProximityManager.mm: Added.
+        (-[WKProximityServiceDelegate setClient:]):
+        (-[WKProximityServiceDelegate service:devicesChanged:]):
+        (-[WKProximityServiceDelegate service:nearbyDevicesChanged:]):
+        (WebKit::NetworkProximityManager::NetworkProximityManager):
+        (WebKit::NetworkProximityManager::~NetworkProximityManager):
+        (WebKit::NetworkProximityManager::supplementName):
+        (WebKit::bindRequestToWiFi):
+        (WebKit::NetworkProximityManager::applyProperties):
+        (WebKit::NetworkProximityManager::resume):
+        (WebKit::NetworkProximityManager::suspend):
+        (WebKit::NetworkProximityManager::recommendation const):
+        (WebKit::NetworkProximityManager::processRecommendations):
+        (WebKit::toProcessID):
+        (WebKit::NetworkProximityManager::resumeRecommendations):
+        (WebKit::NetworkProximityManager::suspendRecommendations):
+        (WebKit::NetworkProximityManager::updateCompanionProximity):
+        (WebKit::NetworkProximityManager::updateRecommendation):
+        (WebKit::NetworkProximityManager::initialize):
+        (WebKit::NetworkProximityManager::devicesChanged):
+
+        Added. NetworkProximityManager is a network process supplement that can bind
+        NetworkDataTasks to Wi-Fi, associate assertions with NetworkDataTasks, check for companion
+        proximity, ask for proximity network recommendations, and respond to network process
+        backgrounding and suspending.
+
+        * Platform/Logging.h:
+
+        Renamed the WiFiAssertions log channel to ProximityNetworking.
+
+        * Platform/spi/ios/MobileWiFiSPI.h:
+        * UIProcess/API/APIProcessPoolConfiguration.cpp:
+        (API::ProcessPoolConfiguration::copy):
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeNetworkProcess):
+
+        Renamed ENABLE(WIFI_ASSERTIONS) to ENABLE(PROXIMITY_NETWORKING).
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * config.h:
+
+        Removed unused definition of HAVE_MOBILE_WIFI.
+
 2018-08-16  Alex Christensen  <[email protected]>
 
         Remove unused and deprecated _WKProcessPoolConfiguration.allowsCellularAccess

Modified: trunk/Source/WebKit/Configurations/WebKit.xcconfig (234967 => 234968)


--- trunk/Source/WebKit/Configurations/WebKit.xcconfig	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/Configurations/WebKit.xcconfig	2018-08-16 23:20:56 UTC (rev 234968)
@@ -101,6 +101,9 @@
 WK_PDFKIT_LDFLAGS_iphoneos[sdk=iphone*11.*] = ;
 WK_PDFKIT_LDFLAGS_iphonesimulator[sdk=iphone*11.*] = ;
 
+WK_PROXIMITY_NETWORKING_LDFLAGS = $(WK_PROXIMITY_NETWORKING_LDFLAGS_$(WK_PLATFORM_NAME));
+WK_PROXIMITY_NETWORKING_LDFLAGS_watchos = -framework IDS -framework MobileWiFi -framework SystemConfiguration -framework WirelessCoexManager;
+
 WK_SAFE_BROWSING_LDFLAGS = $(WK_SAFE_BROWSING_LDFLAGS_$(WK_PLATFORM_NAME));
 WK_SAFE_BROWSING_LDFLAGS_iphoneos = -framework SafariSafeBrowsing;
 WK_SAFE_BROWSING_LDFLAGS_iphonesimulator = -framework SafariSafeBrowsing;
@@ -115,7 +118,7 @@
 WK_URL_FORMATTING_LDFLAGS = $(WK_URL_FORMATTING_LDFLAGS_$(WK_HAVE_URL_FORMATTING));
 WK_URL_FORMATTING_LDFLAGS_YES = -framework URLFormatting;
 
-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_LIBSANDBOX_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) $(WK_URL_FORMATTING_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_LIBSANDBOX_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_PROXIMITY_NETWORKING_LDFLAGS) $(WK_SAFE_BROWSING_LDFLAGS) $(WK_UIKIT_LDFLAGS) $(WK_URL_FORMATTING_LDFLAGS);
 
 // Prevent C++ standard library basic_stringstream, 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__18functionIFvN7WebCore12PolicyActionEE
 ED1Ev -Wl,-unexported_symbol -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEED2Ev -Wl,-unexported_symbol -Wl,__ZNSt3__18functionIFvN7WebCore12PolicyActionEEEaSERKS4_ -Wl,-unexported_symbol -Wl,__ZTVNSt3__117bad_function_callE -Wl,-unexported_symbol -Wl,__ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_13basic_istreamIcS2_EE -Wl,-unexported_symbol -Wl,__ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE -Wl,-unexported_symbol -Wl,__ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE16_NS_13basic_ostreamIcS2_EE -Wl,-unexported_symbol -Wl,__ZTTNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE -Wl,-unexported_symbol -Wl,__ZTVNSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEEE -Wl,-unexported_symbol -Wl,__ZTVNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE -Wl,-unexported_symbol -Wl,__ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEE
 NS_9allocatorIcEEEE8_NS_13basic_ostreamIcS2_EE;

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2018-08-16 23:20:56 UTC (rev 234968)
@@ -43,6 +43,7 @@
 #include "NetworkProcessCreationParameters.h"
 #include "NetworkProcessPlatformStrategies.h"
 #include "NetworkProcessProxyMessages.h"
+#include "NetworkProximityManager.h"
 #include "NetworkResourceLoader.h"
 #include "NetworkSession.h"
 #include "PreconnectTask.h"
@@ -121,6 +122,9 @@
 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
     addSupplement<LegacyCustomProtocolManager>();
 #endif
+#if ENABLE(PROXIMITY_NETWORKING)
+    addSupplement<NetworkProximityManager>();
+#endif
 
     NetworkStateNotifier::singleton().addListener([this](bool isOnLine) {
         auto webProcessConnections = m_webProcessConnections;
@@ -148,6 +152,13 @@
     return downloadManager;
 }
 
+#if ENABLE(PROXIMITY_NETWORKING)
+NetworkProximityManager& NetworkProcess::proximityManager()
+{
+    return *supplement<NetworkProximityManager>();
+}
+#endif
+
 void NetworkProcess::removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess* connection)
 {
     size_t vectorIndex = m_webProcessConnections.find(connection);

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -46,25 +46,25 @@
 }
 
 namespace WebCore {
+class CertificateInfo;
 class DownloadID;
-class CertificateInfo;
 class NetworkStorageSession;
 class ProtectionSpace;
 class SecurityOrigin;
+class URL;
+enum class StoredCredentialsPolicy;
 struct SecurityOriginData;
 struct SoupNetworkProxySettings;
-enum class StoredCredentialsPolicy;
-class URL;
 }
 
 namespace WebKit {
+
 class AuthenticationManager;
-#if ENABLE(SERVER_PRECONNECT)
-class PreconnectTask;
-#endif
 class NetworkConnectionToWebProcess;
 class NetworkProcessSupplement;
+class NetworkProximityManager;
 class NetworkResourceLoader;
+class PreconnectTask;
 enum class WebsiteDataFetchOption;
 enum class WebsiteDataType;
 struct NetworkProcessCreationParameters;
@@ -98,6 +98,9 @@
 
     AuthenticationManager& authenticationManager();
     DownloadManager& downloadManager();
+#if ENABLE(PROXIMITY_NETWORKING)
+    NetworkProximityManager& proximityManager();
+#endif
 
     NetworkCache::Cache* cache() { return m_cache.get(); }
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp	2018-08-16 23:20:56 UTC (rev 234968)
@@ -107,7 +107,7 @@
     encoder << urlSchemesRegisteredAsCORSEnabled;
     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     encoder << wirelessContextIdentifier;
 #endif
 }
@@ -251,7 +251,7 @@
     if (!decoder.decode(result.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
         return false;
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     if (!decoder.decode(result.wirelessContextIdentifier))
         return false;
 #endif

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -123,7 +123,7 @@
     Vector<String> urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
     Vector<String> urlSchemesRegisteredAsCORSEnabled;
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     unsigned wirelessContextIdentifier { 0 };
 #endif
 };

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -28,7 +28,7 @@
 #include "NetworkActivityTracker.h"
 #include "NetworkDataTask.h"
 #include "NetworkLoadParameters.h"
-#include "WiFiAssertionHolder.h"
+#include "NetworkProximityAssertion.h"
 #include <WebCore/NetworkLoadMetrics.h>
 #include <wtf/RetainPtr.h>
 
@@ -73,11 +73,11 @@
     uint64_t frameID() const { return m_frameID; };
     uint64_t pageID() const { return m_pageID; };
 
-#if ENABLE(WIFI_ASSERTIONS)
-    void maybeHoldWiFiAssertion(bool shouldHoldWiFiAssertion)
+#if ENABLE(PROXIMITY_NETWORKING)
+    void holdProximityAssertion(NetworkProximityAssertion& assertion)
     {
-        ASSERT(!m_wiFiAssertionHolder);
-        m_wiFiAssertionHolder.emplace(shouldHoldWiFiAssertion);
+        ASSERT(!m_proximityAssertionToken);
+        m_proximityAssertionToken.emplace(assertion);
     }
 #endif
 
@@ -106,8 +106,8 @@
     bool m_hasBeenSetToUseStatelessCookieStorage { false };
 #endif
 
-#if ENABLE(WIFI_ASSERTIONS)
-    std::optional<WiFiAssertionHolder> m_wiFiAssertionHolder;
+#if ENABLE(PROXIMITY_NETWORKING)
+    std::optional<NetworkProximityAssertion::Token> m_proximityAssertionToken;
 #endif
 };
 

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -31,6 +31,7 @@
 #import "DownloadProxyMessages.h"
 #import "Logging.h"
 #import "NetworkProcess.h"
+#import "NetworkProximityManager.h"
 #import "NetworkSessionCocoa.h"
 #import "SessionTracker.h"
 #import "WebCoreArgumentCoders.h"
@@ -44,10 +45,6 @@
 #import <wtf/ProcessPrivilege.h>
 #import <wtf/text/Base64.h>
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/NetworkDataTaskCocoaAdditions.mm>
-#endif
-
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
 @interface NSURLSessionTask (Staging)
 @property (nullable, readwrite, retain) NSURL *_siteForCookies;
@@ -213,8 +210,8 @@
 
     NSURLRequest *nsRequest = request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
     applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(nsRequest, shouldContentSniff == WebCore::ContentSniffingPolicy::SniffContent && !url.isLocalFile(), shouldContentEncodingSniff == WebCore::ContentEncodingSniffingPolicy::Sniff);
-#if ENABLE(WIFI_ASSERTIONS)
-    applyAdditionalProperties(request, *this, nsRequest);
+#if ENABLE(PROXIMITY_NETWORKING)
+    NetworkProcess::singleton().proximityManager().applyProperties(request, *this, nsRequest);
 #endif
 
     auto& cocoaSession = static_cast<NetworkSessionCocoa&>(m_session.get());

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -30,6 +30,7 @@
 #import "Logging.h"
 #import "NetworkCache.h"
 #import "NetworkProcessCreationParameters.h"
+#import "NetworkProximityManager.h"
 #import "NetworkResourceLoader.h"
 #import "NetworkSessionCocoa.h"
 #import "SandboxExtension.h"
@@ -45,10 +46,6 @@
 #import <wtf/CallbackAggregator.h>
 #import <wtf/ProcessPrivilege.h>
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/NetworkProcessCocoaAdditions.mm>
-#endif
-
 namespace WebKit {
 
 static void initializeNetworkSettings()
@@ -110,10 +107,6 @@
 
     ASSERT(!m_diskCacheIsDisabledForTesting);
 
-#if ENABLE(WIFI_ASSERTIONS)
-    initializeWiFiAssertions(parameters);
-#endif
-
     if (m_diskCacheDirectory.isNull())
         return;
 
@@ -245,8 +238,8 @@
 
 void NetworkProcess::platformPrepareToSuspend(CompletionHandler<void()>&& completionHandler)
 {
-#if ENABLE(WIFI_ASSERTIONS)
-    suspendWiFiAssertions(SuspensionReason::ProcessSuspending, WTFMove(completionHandler));
+#if ENABLE(PROXIMITY_NETWORKING)
+    proximityManager().suspend(SuspensionReason::ProcessSuspending, WTFMove(completionHandler));
 #else
     completionHandler();
 #endif
@@ -254,23 +247,23 @@
 
 void NetworkProcess::platformProcessDidResume()
 {
-#if ENABLE(WIFI_ASSERTIONS)
-    resumeWiFiAssertions(ResumptionReason::ProcessResuming);
+#if ENABLE(PROXIMITY_NETWORKING)
+    proximityManager().resume(ResumptionReason::ProcessResuming);
 #endif
 }
 
 void NetworkProcess::platformProcessDidTransitionToBackground()
 {
-#if ENABLE(WIFI_ASSERTIONS)
-    suspendWiFiAssertions(SuspensionReason::ProcessBackgrounding, [] { });
+#if ENABLE(PROXIMITY_NETWORKING)
+    proximityManager().suspend(SuspensionReason::ProcessBackgrounding, [] { });
 #endif
 }
 
 void NetworkProcess::platformProcessDidTransitionToForeground()
 {
-#if ENABLE(WIFI_ASSERTIONS)
-    resumeWiFiAssertions(ResumptionReason::ProcessForegrounding);
+#if ENABLE(PROXIMITY_NETWORKING)
+    proximityManager().resume(ResumptionReason::ProcessForegrounding);
 #endif
 }
 
-}
+} // namespace WebKit

Deleted: trunk/Source/WebKit/NetworkProcess/cocoa/WiFiAssertionHolder.h (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/cocoa/WiFiAssertionHolder.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/WiFiAssertionHolder.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -1,48 +0,0 @@
-/*
- * 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 HAVE(MOBILE_WIFI)
-
-#include <wtf/Noncopyable.h>
-
-namespace WebKit {
-
-class WiFiAssertionHolder {
-    WTF_MAKE_NONCOPYABLE(WiFiAssertionHolder);
-public:
-    explicit WiFiAssertionHolder(bool shouldHoldWiFiAssertion);
-    ~WiFiAssertionHolder();
-
-    bool shouldHoldWiFiAssertion() const { return m_shouldHoldWiFiAssertion; }
-
-private:
-    bool m_shouldHoldWiFiAssertion;
-};
-
-} // namespace WebKit
-
-#endif // HAVE(MOBILE_WIFI)

Deleted: trunk/Source/WebKit/NetworkProcess/cocoa/WiFiAssertionHolder.mm (234967 => 234968)


--- trunk/Source/WebKit/NetworkProcess/cocoa/WiFiAssertionHolder.mm	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/WiFiAssertionHolder.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -1,58 +0,0 @@
-/*
- * 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.
- */
-
-#import "config.h"
-#import "WiFiAssertionHolder.h"
-
-#if HAVE(MOBILE_WIFI)
-
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WiFiAssertionHolderAdditions.mm>
-#else
-static void holdWiFiAssertion(const WiFiAssertionHolder&)
-{
-}
-
-static void releaseWiFiAssertion(const WiFiAssertionHolder&)
-{
-}
-#endif
-
-namespace WebKit {
-
-WiFiAssertionHolder::WiFiAssertionHolder(bool shouldHoldWiFiAssertion)
-    : m_shouldHoldWiFiAssertion { shouldHoldWiFiAssertion }
-{
-    holdWiFiAssertion(*this);
-}
-
-WiFiAssertionHolder::~WiFiAssertionHolder()
-{
-    releaseWiFiAssertion(*this);
-}
-
-} // namespace WebKit
-
-#endif // HAVE(MOBILE_WIFI)

Added: trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.h (0 => 234968)


--- trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.h	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -0,0 +1,120 @@
+/*
+ * 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 ENABLE(PROXIMITY_NETWORKING)
+
+#include "MobileWiFiSPI.h"
+#include <WebCore/Timer.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS IDSService;
+
+namespace WebKit {
+
+enum class ResumptionReason : uint8_t;
+enum class SuspensionReason : uint8_t;
+
+class NetworkProximityAssertion {
+    WTF_MAKE_NONCOPYABLE(NetworkProximityAssertion);
+public:
+    class Token {
+        WTF_MAKE_NONCOPYABLE(Token);
+    public:
+        explicit Token(NetworkProximityAssertion& assertion)
+            : m_assertion { assertion }
+        {
+            m_assertion.hold();
+        }
+
+        ~Token()
+        {
+            m_assertion.release();
+        }
+
+    private:
+        NetworkProximityAssertion& m_assertion;
+    };
+
+    void resume(ResumptionReason);
+    void suspend(SuspensionReason, CompletionHandler<void()>&&);
+
+protected:
+    NetworkProximityAssertion();
+    virtual ~NetworkProximityAssertion() = default;
+
+    bool m_isHoldingAssertion { false };
+
+private:
+    enum class State {
+        Backgrounded, // Can hold assertions until m_suspendAfterBackgroundingTimer fires.
+        Resumed, // Can hold assertions at any time.
+        Suspended, // Can not hold assertions.
+    };
+
+    virtual void holdNow() = 0;
+    virtual void releaseNow() = 0;
+
+    void hold();
+    void release();
+    void releaseTimerFired();
+    void suspendAfterBackgroundingTimerFired();
+    void suspendNow();
+
+    uint64_t m_assertionCount { 0 };
+    State m_state { State::Suspended };
+    WebCore::DeferrableOneShotTimer m_releaseTimer;
+    WebCore::DeferrableOneShotTimer m_suspendAfterBackgroundingTimer;
+};
+
+class BluetoothProximityAssertion final : public NetworkProximityAssertion {
+public:
+    explicit BluetoothProximityAssertion(IDSService *);
+
+    void suspend(SuspensionReason, CompletionHandler<void()>&&);
+
+private:
+    void holdNow() override;
+    void releaseNow() override;
+
+    RetainPtr<IDSService> m_idsService;
+};
+
+class WiFiProximityAssertion final : public NetworkProximityAssertion {
+public:
+    WiFiProximityAssertion();
+
+private:
+    void holdNow() override;
+    void releaseNow() override;
+
+    RetainPtr<WiFiManagerClientRef> m_wiFiManagerClient;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(PROXIMITY_NETWORKING)

Added: trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.mm (0 => 234968)


--- trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.mm	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -0,0 +1,230 @@
+/*
+ * 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.
+ */
+
+#import "config.h"
+#import "NetworkProximityAssertion.h"
+
+#if ENABLE(PROXIMITY_NETWORKING)
+
+#import "Logging.h"
+#import "NetworkProcess.h"
+#import "NetworkProximityManager.h"
+#import <IDS/IDS_Private.h>
+#import <wtf/BlockPtr.h>
+
+namespace WebKit {
+
+static auto assertionReleaseDelayAfterBackgrounding = 10_s;
+static auto assertionReleaseDelayForHysteresis = 10_s;
+
+NetworkProximityAssertion::NetworkProximityAssertion()
+    : m_releaseTimer { *this, &NetworkProximityAssertion::releaseTimerFired, assertionReleaseDelayForHysteresis }
+    , m_suspendAfterBackgroundingTimer { *this, &NetworkProximityAssertion::suspendAfterBackgroundingTimerFired, assertionReleaseDelayAfterBackgrounding }
+{
+}
+
+void NetworkProximityAssertion::hold()
+{
+    ++m_assertionCount;
+
+    if (m_state == State::Suspended) {
+        ASSERT(!m_isHoldingAssertion);
+        ASSERT(!m_releaseTimer.isActive());
+        ASSERT(!m_suspendAfterBackgroundingTimer.isActive());
+        return;
+    }
+
+    if (m_releaseTimer.isActive()) {
+        m_releaseTimer.stop();
+        return;
+    }
+
+    if (m_assertionCount == 1)
+        holdNow();
+}
+
+void NetworkProximityAssertion::release()
+{
+    ASSERT(m_assertionCount);
+    if (!m_assertionCount || --m_assertionCount)
+        return;
+
+    if (m_state == State::Suspended) {
+        ASSERT(!m_isHoldingAssertion);
+        ASSERT(!m_releaseTimer.isActive());
+        ASSERT(!m_suspendAfterBackgroundingTimer.isActive());
+        return;
+    }
+
+    m_releaseTimer.restart();
+}
+
+void NetworkProximityAssertion::resume(ResumptionReason)
+{
+    switch (m_state) {
+    case State::Backgrounded:
+        m_suspendAfterBackgroundingTimer.stop();
+        break;
+    case State::Resumed:
+        ASSERT(!m_suspendAfterBackgroundingTimer.isActive());
+        break;
+    case State::Suspended:
+        ASSERT(!m_isHoldingAssertion);
+        ASSERT(!m_releaseTimer.isActive());
+        ASSERT(!m_suspendAfterBackgroundingTimer.isActive());
+        holdNow();
+        if (!m_assertionCount)
+            m_releaseTimer.restart();
+        break;
+    }
+
+    m_state = State::Resumed;
+}
+
+void NetworkProximityAssertion::suspend(SuspensionReason reason, CompletionHandler<void()>&& completionHandler)
+{
+    switch (reason) {
+    case SuspensionReason::ProcessBackgrounding:
+        // The Networking process is being backgrounded. We should drop our assertions
+        // soon, in case the system suspends the process before we receive ProcessSuspending.
+        m_state = State::Backgrounded;
+        m_suspendAfterBackgroundingTimer.restart();
+        break;
+    case SuspensionReason::ProcessSuspending:
+        // The Networking process is being suspended, so we need to drop our assertions
+        // immediately before that happens.
+        suspendNow();
+        break;
+    }
+
+    completionHandler();
+}
+
+void NetworkProximityAssertion::suspendNow()
+{
+    if (m_state == State::Suspended)
+        return;
+
+    m_state = State::Suspended;
+    m_releaseTimer.stop();
+    m_suspendAfterBackgroundingTimer.stop();
+    releaseNow();
+}
+
+void NetworkProximityAssertion::releaseTimerFired()
+{
+    ASSERT(!m_releaseTimer.isActive());
+    ASSERT(!m_assertionCount);
+    ASSERT(m_state != State::Suspended);
+    releaseNow();
+}
+
+void NetworkProximityAssertion::suspendAfterBackgroundingTimerFired()
+{
+    ASSERT(!m_suspendAfterBackgroundingTimer.isActive());
+    ASSERT(m_state != State::Suspended);
+    suspendNow();
+}
+
+BluetoothProximityAssertion::BluetoothProximityAssertion(IDSService *idsService)
+    : m_idsService { idsService }
+{
+}
+
+void BluetoothProximityAssertion::suspend(SuspensionReason reason, CompletionHandler<void()>&& completionHandler)
+{
+    auto wasHoldingAssertion = m_isHoldingAssertion;
+    NetworkProximityAssertion::suspend(reason, [] { });
+
+    switch (reason) {
+    case SuspensionReason::ProcessBackgrounding:
+        completionHandler();
+        break;
+    case SuspensionReason::ProcessSuspending:
+        ASSERT(!m_isHoldingAssertion);
+        if (!wasHoldingAssertion) {
+            completionHandler();
+            break;
+        }
+
+        // IDS processes -setLinkPreferences: on a background dispatch queue and provides no
+        // completion handler. If we suspend before IDS finishes setting link preferences, the
+        // Bluetooth radio might stay in a high power mode, harming battery life. Delay suspension
+        // by 30 seconds to ensure -setLinkPreferences: always finishes its work.
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC), dispatch_get_main_queue(), BlockPtr<void()>::fromCallable(WTFMove(completionHandler)).get());
+        break;
+    }
+}
+
+void BluetoothProximityAssertion::holdNow()
+{
+    if (m_isHoldingAssertion)
+        return;
+
+    RELEASE_LOG(ProximityNetworking, "Holding Bluetooth Classic assertion.");
+    [m_idsService setLinkPreferences:@{ IDSLinkPreferenceOptionPacketsPerSecondKey : @(200) }];
+    m_isHoldingAssertion = true;
+}
+
+void BluetoothProximityAssertion::releaseNow()
+{
+    if (!m_isHoldingAssertion)
+        return;
+
+    RELEASE_LOG(ProximityNetworking, "Releasing Bluetooth Classic assertion.");
+    [m_idsService setLinkPreferences:@{ IDSLinkPreferenceOptionPacketsPerSecondKey : @(0) }];
+    m_isHoldingAssertion = false;
+}
+
+WiFiProximityAssertion::WiFiProximityAssertion()
+    : m_wiFiManagerClient { adoptCF(WiFiManagerClientCreate(kCFAllocatorDefault, kWiFiClientTypeNormal)) }
+{
+}
+
+void WiFiProximityAssertion::holdNow()
+{
+    if (m_isHoldingAssertion)
+        return;
+
+    RELEASE_LOG(ProximityNetworking, "Holding Wi-Fi assertion.");
+    ASSERT(WiFiManagerClientGetType(m_wiFiManagerClient.get()) == kWiFiClientTypeNormal);
+    WiFiManagerClientSetType(m_wiFiManagerClient.get(), kWiFiClientTypeDirectToCloud);
+    m_isHoldingAssertion = true;
+}
+
+void WiFiProximityAssertion::releaseNow()
+{
+    if (!m_isHoldingAssertion)
+        return;
+
+    RELEASE_LOG(ProximityNetworking, "Releasing Wi-Fi assertion.");
+    ASSERT(WiFiManagerClientGetType(m_wiFiManagerClient.get()) == kWiFiClientTypeDirectToCloud);
+    WiFiManagerClientSetType(m_wiFiManagerClient.get(), kWiFiClientTypeNormal);
+    m_isHoldingAssertion = false;
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PROXIMITY_NETWORKING)

Added: trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.h (0 => 234968)


--- trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.h	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -0,0 +1,120 @@
+/*
+ * 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 ENABLE(PROXIMITY_NETWORKING)
+
+#include "NetworkProcessSupplement.h"
+#include "NetworkProximityAssertion.h"
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/OSObjectPtr.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS IDSService;
+OBJC_CLASS NSArray;
+OBJC_CLASS NSURLRequest;
+OBJC_CLASS WKProximityServiceDelegate;
+OBJC_CLASS WRM_iRATInterface;
+
+namespace WebCore {
+class ResourceRequest;
+}
+
+namespace WebKit {
+
+class ChildProcess;
+class NetworkDataTaskCocoa;
+enum class NetworkProximityRecommendation : uint8_t;
+
+enum class ResumptionReason : uint8_t {
+    ProcessForegrounding,
+    ProcessResuming,
+};
+
+enum class SuspensionReason : uint8_t {
+    ProcessBackgrounding,
+    ProcessSuspending
+};
+
+class NetworkProximityServiceClient {
+public:
+    virtual ~NetworkProximityServiceClient() = default;
+    virtual void devicesChanged(NSArray *devices) = 0;
+};
+
+class NetworkProximityManager final : public NetworkProcessSupplement, private NetworkProximityServiceClient {
+    WTF_MAKE_NONCOPYABLE(NetworkProximityManager);
+public:
+    explicit NetworkProximityManager(ChildProcess&);
+    ~NetworkProximityManager();
+
+    static const char* supplementName();
+
+    void applyProperties(const WebCore::ResourceRequest&, NetworkDataTaskCocoa&, NSURLRequest *&);
+    void resume(ResumptionReason);
+    void suspend(SuspensionReason, CompletionHandler<void()>&&);
+
+private:
+    enum class State : uint8_t {
+        Backgrounded,
+        Foregrounded,
+        Initialized,
+        Resumed,
+        Suspended,
+    };
+
+    bool isCompanionInProximity() const { return m_isCompanionInProximity; }
+    NetworkProximityRecommendation recommendation() const;
+    bool shouldUseDirectWiFiInProximity() const { return m_shouldUseDirectWiFiInProximity; }
+
+    void processRecommendations(NSArray *recommendations);
+    void resumeRecommendations();
+    void suspendRecommendations(State oldState);
+    void updateCompanionProximity();
+    void updateRecommendation();
+
+    // NetworkProcessSupplement
+    void initialize(const NetworkProcessCreationParameters&) override;
+
+    // NetworkProximityServiceClient
+    void devicesChanged(NSArray *devices) override;
+
+    unsigned m_contextIdentifier { 0 };
+    bool m_isCompanionInProximity { false };
+    bool m_shouldUseDirectWiFiInProximity { false };
+    State m_state { State::Initialized };
+    RetainPtr<WRM_iRATInterface> m_iRATInterface;
+    RetainPtr<IDSService> m_idsService;
+    RetainPtr<WKProximityServiceDelegate> m_idsServiceDelegate;
+    OSObjectPtr<dispatch_queue_t> m_recommendationQueue;
+    BluetoothProximityAssertion m_bluetoothProximityAssertion;
+    WiFiProximityAssertion m_wiFiProximityAssertion;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(PROXIMITY_NETWORKING)

Added: trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.mm (0 => 234968)


--- trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.mm	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityManager.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -0,0 +1,323 @@
+/*
+ * 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.
+ */
+
+#import "config.h"
+#import "NetworkProximityManager.h"
+
+#if ENABLE(PROXIMITY_NETWORKING)
+
+#import "Logging.h"
+#import "NetworkDataTaskCocoa.h"
+#import "NetworkProcessCreationParameters.h"
+#import <IDS/IDS.h>
+#import <WirelessCoexManager/WRM_iRATInterface.h>
+#import <pal/spi/cf/CFNetworkSPI.h>
+#import <wtf/BlockPtr.h>
+#import <wtf/CompletionHandler.h>
+#import <wtf/cf/TypeCastsCF.h>
+
+WTF_DECLARE_CF_TYPE_TRAIT(SCNetworkInterface);
+
+@interface WKProximityServiceDelegate : NSObject <IDSServiceDelegate>
+- (void)setClient:(WebKit::NetworkProximityServiceClient*)client;
+@end
+
+@implementation WKProximityServiceDelegate {
+    WebKit::NetworkProximityServiceClient* _client;
+}
+
+- (void)setClient:(WebKit::NetworkProximityServiceClient*)client
+{
+    _client = client;
+}
+
+- (void)service:(IDSService *)service devicesChanged:(NSArray *)devices
+{
+    if (_client)
+        _client->devicesChanged(devices);
+}
+
+- (void)service:(IDSService *)service nearbyDevicesChanged:(NSArray *)devices
+{
+    if (_client)
+        _client->devicesChanged(devices);
+}
+
+@end
+
+namespace WebKit {
+
+enum class NetworkProximityRecommendation : uint8_t {
+    Bluetooth,
+    None,
+    WiFi,
+};
+
+NetworkProximityManager::NetworkProximityManager(ChildProcess&)
+    : m_idsService { adoptNS([[IDSService alloc] initWithService:@"com.apple.private.alloy.webkitnetworking"]) }
+    , m_idsServiceDelegate { adoptNS([[WKProximityServiceDelegate alloc] init]) }
+    , m_recommendationQueue { adoptOSObject(dispatch_queue_create("WebKit Network Proximity Recommendation Queue", DISPATCH_QUEUE_SERIAL)) }
+    , m_bluetoothProximityAssertion { m_idsService.get() }
+{
+    [m_idsServiceDelegate setClient:this];
+    [m_idsService addDelegate:m_idsServiceDelegate.get() queue:dispatch_get_main_queue()];
+}
+
+NetworkProximityManager::~NetworkProximityManager()
+{
+    [m_idsServiceDelegate setClient:nullptr];
+}
+
+const char* NetworkProximityManager::supplementName()
+{
+    return "NetworkProximityManager";
+}
+
+static void bindRequestToWiFi(NSURLRequest *& request)
+{
+    static NSString *wiFiInterfaceIdentifier = []() -> NSString * {
+        auto interfaces = adoptCF(SCNetworkInterfaceCopyAll());
+        for (CFIndex i = 0, count = CFArrayGetCount(interfaces.get()); i < count; ++i) {
+            auto interface = checked_cf_cast<SCNetworkInterfaceRef>(CFArrayGetValueAtIndex(interfaces.get(), i));
+            if (!CFEqual(SCNetworkInterfaceGetInterfaceType(interface), kSCNetworkInterfaceTypeIEEE80211))
+                continue;
+
+            auto identifier = retainPtr(SCNetworkInterfaceGetBSDName(interface));
+            RELEASE_LOG(ProximityNetworking, "Determined Wi-Fi interface identifier is %@.", identifier.get());
+            return (NSString *)identifier.leakRef();
+        }
+
+        RELEASE_LOG(ProximityNetworking, "Failed to determine Wi-Fi interface identifier.");
+        return nil;
+    }();
+
+    if (!wiFiInterfaceIdentifier)
+        return;
+
+    auto mutableRequest = adoptNS([request mutableCopy]);
+    [mutableRequest setBoundInterfaceIdentifier:wiFiInterfaceIdentifier];
+    request = mutableRequest.autorelease();
+}
+
+void NetworkProximityManager::applyProperties(const WebCore::ResourceRequest& request, WebKit::NetworkDataTaskCocoa& dataTask, NSURLRequest *& nsRequest)
+{
+    // If the client has already bound the request to an identifier, don't override it.
+    if (nsRequest.boundInterfaceIdentifier.length)
+        return;
+
+    if (dataTask.isTopLevelNavigation())
+        updateRecommendation();
+
+    switch (recommendation()) {
+    case NetworkProximityRecommendation::Bluetooth:
+        dataTask.holdProximityAssertion(m_bluetoothProximityAssertion);
+        break;
+    case NetworkProximityRecommendation::None:
+        break;
+    case NetworkProximityRecommendation::WiFi:
+        dataTask.holdProximityAssertion(m_wiFiProximityAssertion);
+        bindRequestToWiFi(nsRequest);
+        break;
+    }
+}
+
+void NetworkProximityManager::resume(ResumptionReason reason)
+{
+    switch (reason) {
+    case ResumptionReason::ProcessForegrounding:
+        m_state = State::Foregrounded;
+        break;
+    case ResumptionReason::ProcessResuming:
+        m_state = State::Resumed;
+        break;
+    }
+
+    resumeRecommendations();
+
+    switch (recommendation()) {
+    case NetworkProximityRecommendation::Bluetooth:
+        m_bluetoothProximityAssertion.resume(reason);
+        break;
+    case NetworkProximityRecommendation::None:
+        break;
+    case NetworkProximityRecommendation::WiFi:
+        m_wiFiProximityAssertion.resume(reason);
+        break;
+    }
+}
+
+void NetworkProximityManager::suspend(SuspensionReason reason, CompletionHandler<void()>&& completionHandler)
+{
+    auto oldState = m_state;
+    switch (reason) {
+    case SuspensionReason::ProcessBackgrounding:
+        m_state = State::Backgrounded;
+        break;
+    case SuspensionReason::ProcessSuspending:
+        m_state = State::Suspended;
+        break;
+    }
+
+    suspendRecommendations(oldState);
+
+    auto wrappedCompletionHandler = [this, completionHandler = WTFMove(completionHandler)]() mutable {
+        completionHandler();
+        RELEASE_LOG(ProximityNetworking, "Finished suspending NetworkProximityManager (state: %hhu).", m_state);
+    };
+
+    RELEASE_LOG(ProximityNetworking, "Suspending NetworkProximityManager (state: %hhu).", m_state);
+    m_bluetoothProximityAssertion.suspend(reason, WTFMove(wrappedCompletionHandler));
+    m_wiFiProximityAssertion.suspend(reason, [] { });
+}
+
+NetworkProximityRecommendation NetworkProximityManager::recommendation() const
+{
+    if (!isCompanionInProximity())
+        return NetworkProximityRecommendation::None;
+
+    if (shouldUseDirectWiFiInProximity())
+        return NetworkProximityRecommendation::WiFi;
+
+    return NetworkProximityRecommendation::Bluetooth;
+}
+
+void NetworkProximityManager::processRecommendations(NSArray *recommendations)
+{
+    m_shouldUseDirectWiFiInProximity = false;
+    bool didSeeDirectWiFiRecommendation = false;
+    for (WRM_iRATProximityRecommendation *recommendation in recommendations) {
+        switch (recommendation.RecommendationType) {
+        case WRMRecommendationLinkTypeBT:
+        case WRMRecommendationLinkTypeCompanionWifi:
+            break;
+        case WRMRecommendationLinkTypeDirectWifi:
+            ASSERT(!didSeeDirectWiFiRecommendation);
+            didSeeDirectWiFiRecommendation = true;
+            m_shouldUseDirectWiFiInProximity = recommendation.linkRecommendationIsValid && recommendation.linkIsRecommended;
+            break;
+        }
+    }
+
+    RELEASE_LOG(ProximityNetworking, "Processed iRATManager recommendations (shouldUseDirectWiFiInProximity: %d).\n", m_shouldUseDirectWiFiInProximity);
+}
+
+static WCMProcessId toProcessID(unsigned contextIdentifier)
+{
+    switch (contextIdentifier) {
+    case WRMWebkit:
+        return WRMWebkit;
+    case WRMWebkitMail:
+        return WRMWebkitMail;
+    case WRMWebkitNotification:
+        return WRMWebkitNotification;
+    default:
+        return WCMUnknown;
+    }
+}
+
+void NetworkProximityManager::resumeRecommendations()
+{
+    if (m_iRATInterface)
+        return;
+
+    updateCompanionProximity();
+
+    auto processID = toProcessID(m_contextIdentifier);
+    if (processID == WCMUnknown) {
+        RELEASE_LOG(ProximityNetworking, "Invalid WCM process ID (%d).", m_contextIdentifier);
+        return;
+    }
+
+    RELEASE_LOG(ProximityNetworking, "Registering with iRATManager (WCM process ID: %d, state: %hhu).", processID, m_state);
+    m_iRATInterface = adoptNS([[WRM_iRATInterface alloc] init]);
+    [m_iRATInterface registerClient:processID queue:m_recommendationQueue.get()];
+    updateRecommendation();
+}
+
+void NetworkProximityManager::suspendRecommendations(State oldState)
+{
+    // If this is not a foreground-to-background transition, avoid unregistering. Page loads can
+    // often cause the network process to resume, transition to the background, then transition to
+    // the foreground in rapid succession, causing unnecessary iRATManager registration churn and
+    // exposing bugs such as <rdar://problem/42560320>.
+    if (m_state == State::Backgrounded && oldState != State::Foregrounded)
+        return;
+
+    if (!m_iRATInterface)
+        return;
+
+    RELEASE_LOG(ProximityNetworking, "Unregistering with iRATManager (WCM process ID: %d, state: %hhu).", m_contextIdentifier, m_state);
+    [m_iRATInterface unregisterClient];
+    m_iRATInterface = nil;
+    m_isCompanionInProximity = false;
+    m_shouldUseDirectWiFiInProximity = false;
+}
+
+void NetworkProximityManager::updateCompanionProximity()
+{
+    m_isCompanionInProximity = false;
+    for (IDSDevice *device in [m_idsService devices]) {
+        if (device.isDefaultPairedDevice && device.isNearby) {
+            m_isCompanionInProximity = true;
+            break;
+        }
+    }
+
+    RELEASE_LOG(ProximityNetworking, "Determined companion proximity (isCompanionInProximity: %d).", m_isCompanionInProximity);
+}
+
+void NetworkProximityManager::updateRecommendation()
+{
+    if (!isCompanionInProximity())
+        return;
+
+    if (!m_iRATInterface)
+        return;
+
+    RELEASE_LOG(ProximityNetworking, "Requesting an immediate recommendation from iRATManager.");
+
+    auto semaphore = adoptOSObject(dispatch_semaphore_create(0));
+    [m_iRATInterface getProximityLinkRecommendation:NO recommendation:[this, semaphore](NSArray<WRM_iRATProximityRecommendation *> *recommendations) {
+        processRecommendations(recommendations);
+        dispatch_semaphore_signal(semaphore.get());
+    }];
+
+    dispatch_semaphore_wait(semaphore.get(), dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC));
+}
+
+void NetworkProximityManager::initialize(const NetworkProcessCreationParameters& parameters)
+{
+    m_contextIdentifier = parameters.wirelessContextIdentifier;
+    resume(ResumptionReason::ProcessResuming);
+}
+
+void NetworkProximityManager::devicesChanged(NSArray *)
+{
+    updateCompanionProximity();
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(PROXIMITY_NETWORKING)

Modified: trunk/Source/WebKit/Platform/Logging.h (234967 => 234968)


--- trunk/Source/WebKit/Platform/Logging.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/Platform/Logging.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -67,6 +67,7 @@
     M(Process) \
     M(ProcessSuspension) \
     M(ProcessSwapping) \
+    M(ProximityNetworking) \
     M(RemoteLayerTree) \
     M(Resize) \
     M(ResourceLoadStatistics) \
@@ -81,7 +82,6 @@
     M(VirtualMemory) \
     M(VisibleRects) \
     M(WebRTC) \
-    M(WiFiAssertions) \
 
 WEBKIT2_LOG_CHANNELS(DECLARE_LOG_CHANNEL)
 

Modified: trunk/Source/WebKit/Platform/spi/ios/MobileWiFiSPI.h (234967 => 234968)


--- trunk/Source/WebKit/Platform/spi/ios/MobileWiFiSPI.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/Platform/spi/ios/MobileWiFiSPI.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -27,7 +27,7 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 
-#include <MobileWiFi/WiFiManagerClient.h>
+#include <MobileWiFi/MobileWiFi.h>
 
 #else
 

Modified: trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp (234967 => 234968)


--- trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp	2018-08-16 23:20:56 UTC (rev 234968)
@@ -132,7 +132,7 @@
     copy->m_processSwapsOnNavigation = this->m_processSwapsOnNavigation;
     copy->m_alwaysKeepAndReuseSwappedProcesses = this->m_alwaysKeepAndReuseSwappedProcesses;
     copy->m_processSwapsOnWindowOpenWithOpener = this->m_processSwapsOnWindowOpenWithOpener;
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     copy->m_wirelessContextIdentifier = this->m_wirelessContextIdentifier;
 #endif
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h (234967 => 234968)


--- trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -153,7 +153,7 @@
     const WTF::String& customWebContentServiceBundleIdentifier() const { return m_customWebContentServiceBundleIdentifier; }
     void setCustomWebContentServiceBundleIdentifier(const WTF::String& customWebContentServiceBundleIdentifier) { m_customWebContentServiceBundleIdentifier = customWebContentServiceBundleIdentifier; }
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     unsigned wirelessContextIdentifier() const { return m_wirelessContextIdentifier; }
     void setWirelessContextIdentifier(unsigned wirelessContextIdentifier) { m_wirelessContextIdentifier = wirelessContextIdentifier; }
 #endif
@@ -205,7 +205,7 @@
     WTF::String m_ctDataConnectionServiceType;
 #endif
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     unsigned m_wirelessContextIdentifier { 0 };
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm (234967 => 234968)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -139,7 +139,7 @@
     _processPoolConfiguration->setAdditionalReadAccessAllowedPaths(WTFMove(paths));
 }
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
 - (NSUInteger)wirelessContextIdentifier
 {
     return _processPoolConfiguration->wirelessContextIdentifier();

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (234967 => 234968)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2018-08-16 23:20:56 UTC (rev 234968)
@@ -333,7 +333,7 @@
         parameters.recordReplayCacheLocation = parameters.diskCacheDirectory;
 #endif
 
-#if ENABLE(WIFI_ASSERTIONS)
+#if ENABLE(PROXIMITY_NETWORKING)
     parameters.wirelessContextIdentifier = m_configuration->wirelessContextIdentifier();
 #endif
 }

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (234967 => 234968)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-08-16 23:20:56 UTC (rev 234968)
@@ -1593,6 +1593,10 @@
 		A102A7081EC0EEE900D81D82 /* com.macromedia.Flash Player ESR.plugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 7A5E39491D5BD8A700B4B7CE /* com.macromedia.Flash Player ESR.plugin.sb */; };
 		A1046EA12079263100F0C5D8 /* WKPDFView.h in Headers */ = {isa = PBXBuildFile; fileRef = A1046E9F2079263100F0C5D8 /* WKPDFView.h */; };
 		A1046EA22079263100F0C5D8 /* WKPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1046EA02079263100F0C5D8 /* WKPDFView.mm */; };
+		A11455AC211FCFCA00CA935B /* NetworkProximityAssertion.h in Headers */ = {isa = PBXBuildFile; fileRef = A11455AA211FCFCA00CA935B /* NetworkProximityAssertion.h */; };
+		A11455AD211FCFCA00CA935B /* NetworkProximityAssertion.mm in Sources */ = {isa = PBXBuildFile; fileRef = A11455AB211FCFCA00CA935B /* NetworkProximityAssertion.mm */; };
+		A11455B0211FD25200CA935B /* NetworkProximityManager.h in Headers */ = {isa = PBXBuildFile; fileRef = A11455AE211FD25200CA935B /* NetworkProximityManager.h */; };
+		A11455B1211FD25200CA935B /* NetworkProximityManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = A11455AF211FD25200CA935B /* NetworkProximityManager.mm */; };
 		A115DC71191D82D700DA8072 /* _WKWebViewPrintFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A115DC6D191D82AB00DA8072 /* _WKWebViewPrintFormatter.mm */; };
 		A115DC72191D82DA00DA8072 /* _WKWebViewPrintFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = A115DC6E191D82AB00DA8072 /* _WKWebViewPrintFormatter.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A118A9EE1907AD6F00F7C92B /* QuickLookDocumentData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */; };
@@ -1614,8 +1618,6 @@
 		A1C512C8190656E500448914 /* WebPreviewLoaderClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1C512C6190656E500448914 /* WebPreviewLoaderClient.cpp */; };
 		A1C512C9190656E500448914 /* WebPreviewLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A1C512C7190656E500448914 /* WebPreviewLoaderClient.h */; };
 		A1D420471DB5578500BB6B0D /* WKContextMenuListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1EA02351DABFF7E0096021F /* WKContextMenuListener.cpp */; };
-		A1DAFDDF207E9B16005E8A52 /* WiFiAssertionHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DAFDDD207E9B16005E8A52 /* WiFiAssertionHolder.h */; };
-		A1DAFDE0207E9B16005E8A52 /* WiFiAssertionHolder.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DAFDDE207E9B16005E8A52 /* WiFiAssertionHolder.mm */; };
 		A1DF631218E0B7C8003A3E2A /* DownloadClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DF631018E0B7C8003A3E2A /* DownloadClient.mm */; };
 		A1DF631318E0B7C8003A3E2A /* DownloadClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF631118E0B7C8003A3E2A /* DownloadClient.h */; };
 		A1E688701F6E2BAB007006A6 /* QuarantineSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E6886F1F6E2BAB007006A6 /* QuarantineSPI.h */; };
@@ -4198,6 +4200,10 @@
 		9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKContextPrivateMac.h; path = mac/WKContextPrivateMac.h; sourceTree = "<group>"; };
 		A1046E9F2079263100F0C5D8 /* WKPDFView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKPDFView.h; path = ios/WKPDFView.h; sourceTree = "<group>"; };
 		A1046EA02079263100F0C5D8 /* WKPDFView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPDFView.mm; path = ios/WKPDFView.mm; sourceTree = "<group>"; };
+		A11455AA211FCFCA00CA935B /* NetworkProximityAssertion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetworkProximityAssertion.h; sourceTree = "<group>"; };
+		A11455AB211FCFCA00CA935B /* NetworkProximityAssertion.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProximityAssertion.mm; sourceTree = "<group>"; };
+		A11455AE211FD25200CA935B /* NetworkProximityManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetworkProximityManager.h; sourceTree = "<group>"; };
+		A11455AF211FD25200CA935B /* NetworkProximityManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProximityManager.mm; sourceTree = "<group>"; };
 		A115DC6D191D82AB00DA8072 /* _WKWebViewPrintFormatter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKWebViewPrintFormatter.mm; sourceTree = "<group>"; };
 		A115DC6E191D82AB00DA8072 /* _WKWebViewPrintFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebViewPrintFormatter.h; sourceTree = "<group>"; };
 		A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = QuickLookDocumentData.cpp; path = ios/QuickLookDocumentData.cpp; sourceTree = "<group>"; };
@@ -4218,8 +4224,6 @@
 		A1A4FE6018DD54A400B5EA8A /* _WKDownloadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKDownloadDelegate.h; sourceTree = "<group>"; };
 		A1C512C6190656E500448914 /* WebPreviewLoaderClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebPreviewLoaderClient.cpp; path = ios/WebPreviewLoaderClient.cpp; sourceTree = "<group>"; };
 		A1C512C7190656E500448914 /* WebPreviewLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebPreviewLoaderClient.h; path = ios/WebPreviewLoaderClient.h; sourceTree = "<group>"; };
-		A1DAFDDD207E9B16005E8A52 /* WiFiAssertionHolder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WiFiAssertionHolder.h; path = NetworkProcess/cocoa/WiFiAssertionHolder.h; sourceTree = "<group>"; };
-		A1DAFDDE207E9B16005E8A52 /* WiFiAssertionHolder.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WiFiAssertionHolder.mm; path = NetworkProcess/cocoa/WiFiAssertionHolder.mm; sourceTree = "<group>"; };
 		A1DF631018E0B7C8003A3E2A /* DownloadClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadClient.mm; sourceTree = "<group>"; };
 		A1DF631118E0B7C8003A3E2A /* DownloadClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadClient.h; sourceTree = "<group>"; };
 		A1E6886F1F6E2BAB007006A6 /* QuarantineSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QuarantineSPI.h; sourceTree = "<group>"; };
@@ -6554,6 +6558,7 @@
 				E1798C7616E6815500240139 /* FileAPI */,
 				2DA944BB188511DD00ED86DB /* ios */,
 				510CC7DC16138E2900D03ED3 /* mac */,
+				A11455A1211FCE7F00CA935B /* watchos */,
 				413075971DE84ED70039EC69 /* webrtc */,
 				53F3CAA5206C443E0086490E /* NetworkActivityTracker.cpp */,
 				535BCB902069C49C00CCCE02 /* NetworkActivityTracker.h */,
@@ -7118,8 +7123,6 @@
 				7EC4F0F918E4A945008056AF /* NetworkProcessCocoa.mm */,
 				532159501DBAE6D70054AA3C /* NetworkSessionCocoa.h */,
 				5C20CB9B1BB0DCD200895BB1 /* NetworkSessionCocoa.mm */,
-				A1DAFDDD207E9B16005E8A52 /* WiFiAssertionHolder.h */,
-				A1DAFDDE207E9B16005E8A52 /* WiFiAssertionHolder.mm */,
 			);
 			name = cocoa;
 			sourceTree = "<group>";
@@ -7190,6 +7193,18 @@
 			path = cocoa;
 			sourceTree = "<group>";
 		};
+		A11455A1211FCE7F00CA935B /* watchos */ = {
+			isa = PBXGroup;
+			children = (
+				A11455AA211FCFCA00CA935B /* NetworkProximityAssertion.h */,
+				A11455AB211FCFCA00CA935B /* NetworkProximityAssertion.mm */,
+				A11455AE211FD25200CA935B /* NetworkProximityManager.h */,
+				A11455AF211FD25200CA935B /* NetworkProximityManager.mm */,
+			);
+			name = watchos;
+			path = NetworkProcess/watchos;
+			sourceTree = "<group>";
+		};
 		A182D5B11BE6BCF40087A7CC /* ios */ = {
 			isa = PBXGroup;
 			children = (
@@ -9258,6 +9273,8 @@
 				5179556E162877B300FA43B6 /* NetworkProcessProxy.h in Headers */,
 				513A163D163088F6005D7D22 /* NetworkProcessProxyMessages.h in Headers */,
 				5C1426EE1C23F80900D41183 /* NetworkProcessSupplement.h in Headers */,
+				A11455AC211FCFCA00CA935B /* NetworkProximityAssertion.h in Headers */,
+				A11455B0211FD25200CA935B /* NetworkProximityManager.h in Headers */,
 				51FD18B61651FBAD00DBE1CE /* NetworkResourceLoader.h in Headers */,
 				E152551B17011819003D7ADB /* NetworkResourceLoaderMessages.h in Headers */,
 				5C1426F01C23F80900D41183 /* NetworkResourceLoadParameters.h in Headers */,
@@ -9646,7 +9663,6 @@
 				15739BBD1B42042D00D258C1 /* WebUserMediaClient.h in Headers */,
 				83EE575C1DB7D61100C74C50 /* WebValidationMessageClient.h in Headers */,
 				2DFC7DBB1BCCC19500C1548C /* WebViewImpl.h in Headers */,
-				A1DAFDDF207E9B16005E8A52 /* WiFiAssertionHolder.h in Headers */,
 				29CD55AA128E294F00133C85 /* WKAccessibilityWebPageObjectBase.h in Headers */,
 				29232DF418B29D6800D0596F /* WKAccessibilityWebPageObjectMac.h in Headers */,
 				934B724419F5B9BE00AE96D6 /* WKActionMenuItemTypes.h in Headers */,
@@ -11124,6 +11140,8 @@
 				E14A954916E016A40068DE82 /* NetworkProcessPlatformStrategies.cpp in Sources */,
 				5179556D162877B100FA43B6 /* NetworkProcessProxy.cpp in Sources */,
 				513A163C163088F6005D7D22 /* NetworkProcessProxyMessageReceiver.cpp in Sources */,
+				A11455AD211FCFCA00CA935B /* NetworkProximityAssertion.mm in Sources */,
+				A11455B1211FD25200CA935B /* NetworkProximityManager.mm in Sources */,
 				51FD18B51651FBAD00DBE1CE /* NetworkResourceLoader.cpp in Sources */,
 				E152551A17011819003D7ADB /* NetworkResourceLoaderMessageReceiver.cpp in Sources */,
 				5C1426EF1C23F80900D41183 /* NetworkResourceLoadParameters.cpp in Sources */,
@@ -11612,7 +11630,6 @@
 				83EE575B1DB7D61100C74C50 /* WebValidationMessageClient.cpp in Sources */,
 				2DFC7DBC1BCCC19500C1548C /* WebViewImpl.mm in Sources */,
 				C0337DD1127A2980008FF4F4 /* WebWheelEvent.cpp in Sources */,
-				A1DAFDE0207E9B16005E8A52 /* WiFiAssertionHolder.mm in Sources */,
 				868160D0187645570021E79D /* WindowServerConnection.mm in Sources */,
 				29CD55AB128E294F00133C85 /* WKAccessibilityWebPageObjectBase.mm in Sources */,
 				29232DF818B2A9AE00D0596F /* WKAccessibilityWebPageObjectIOS.mm in Sources */,

Modified: trunk/Source/WebKit/config.h (234967 => 234968)


--- trunk/Source/WebKit/config.h	2018-08-16 23:05:54 UTC (rev 234967)
+++ trunk/Source/WebKit/config.h	2018-08-16 23:20:56 UTC (rev 234968)
@@ -119,14 +119,6 @@
 #endif
 #endif
 
-#ifndef HAVE_MOBILE_WIFI
-#if PLATFORM(IOS) && !TARGET_OS_SIMULATOR && !PLATFORM(IOSMAC) && USE(APPLE_INTERNAL_SDK)
-#define HAVE_MOBILE_WIFI 1
-#else
-#define HAVE_MOBILE_WIFI 0
-#endif
-#endif
-
 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)) && !defined(__i386__) && !PLATFORM(IOSMAC)
 #define HAVE_SAFE_BROWSING 1
 #else
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to