Title: [291511] trunk/Source/WebKit
Revision
291511
Author
[email protected]
Date
2022-03-18 17:31:59 -0700 (Fri, 18 Mar 2022)

Log Message

Update preference location used for CaptivePortal testing.
https://bugs.webkit.org/show_bug.cgi?id=237970
<rdar://problem/88897735>

Patch by Gavin Phillips <[email protected]> on 2022-03-18
Reviewed by Brent Fulgham.

Update the location of the setting used to determine whether we should ignore CaptivePortal requests for testing
as well as group the various iterations of preference checking into a single location.

* UIProcess/API/Cocoa/_WKSystemPreferences.mm:
(+[_WKSystemPreferences isCaptivePortalModeEnabled]):
(+[_WKSystemPreferences setCaptivePortalModeEnabled:]):
(+[_WKSystemPreferences isCaptivePortalModeIgnored:]):
(+[_WKSystemPreferences setCaptivePortalModeIgnored:ignore:]):
* UIProcess/API/Cocoa/_WKSystemPreferencesInternal.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::isCaptivePortalModeEnabledBySystemIgnoringCaching):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291510 => 291511)


--- trunk/Source/WebKit/ChangeLog	2022-03-19 00:30:28 UTC (rev 291510)
+++ trunk/Source/WebKit/ChangeLog	2022-03-19 00:31:59 UTC (rev 291511)
@@ -1,3 +1,23 @@
+2022-03-18  Gavin Phillips  <[email protected]>
+
+        Update preference location used for CaptivePortal testing. 
+        https://bugs.webkit.org/show_bug.cgi?id=237970
+        <rdar://problem/88897735>
+
+        Reviewed by Brent Fulgham.
+
+        Update the location of the setting used to determine whether we should ignore CaptivePortal requests for testing 
+        as well as group the various iterations of preference checking into a single location. 
+
+        * UIProcess/API/Cocoa/_WKSystemPreferences.mm:
+        (+[_WKSystemPreferences isCaptivePortalModeEnabled]):
+        (+[_WKSystemPreferences setCaptivePortalModeEnabled:]):
+        (+[_WKSystemPreferences isCaptivePortalModeIgnored:]):
+        (+[_WKSystemPreferences setCaptivePortalModeIgnored:ignore:]):
+        * UIProcess/API/Cocoa/_WKSystemPreferencesInternal.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::isCaptivePortalModeEnabledBySystemIgnoringCaching):
+
 2022-03-18  Jonathan Bedard  <[email protected]>
 
         [iOS 15.4] Fix unused variables

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSystemPreferences.mm (291510 => 291511)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSystemPreferences.mm	2022-03-19 00:30:28 UTC (rev 291510)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSystemPreferences.mm	2022-03-19 00:31:59 UTC (rev 291511)
@@ -35,15 +35,23 @@
 
 + (BOOL)isCaptivePortalModeEnabled
 {
-    auto changedNotificationKey = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, WKCaptivePortalModeEnabledKey, kCFStringEncodingUTF8));
-    auto preferenceValue = adoptCF(CFPreferencesCopyValue(changedNotificationKey.get(), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
+    auto key = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, WKCaptivePortalModeEnabledKey, kCFStringEncodingUTF8));
+    auto preferenceValue = adoptCF(CFPreferencesCopyValue(key.get(), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
+    if (preferenceValue.get() == kCFBooleanTrue)
+        return true;
+
+    if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithUTF8String:WebKitCaptivePortalModeChangedNotification_Legacy]])
+        return true;
+
+    key = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, LDMEnabledKey, kCFStringEncodingUTF8));
+    preferenceValue = adoptCF(CFPreferencesCopyValue(key.get(), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
     return preferenceValue.get() == kCFBooleanTrue;
 }
 
 + (void)setCaptivePortalModeEnabled:(BOOL)enabled
 {
-    auto changedNotificationKey = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, WKCaptivePortalModeEnabledKey, kCFStringEncodingUTF8));
-    CFPreferencesSetValue(changedNotificationKey.get(), enabled ? kCFBooleanTrue : kCFBooleanFalse, kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+    auto key = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, WKCaptivePortalModeEnabledKey, kCFStringEncodingUTF8));
+    CFPreferencesSetValue(key.get(), enabled ? kCFBooleanTrue : kCFBooleanFalse, kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
     CFPreferencesSynchronize(kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
     CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge CFStringRef)WKCaptivePortalModeContainerConfigurationChangedNotification, nullptr, nullptr, true);
 }
@@ -51,7 +59,7 @@
 + (BOOL)isCaptivePortalModeIgnored:(NSString *)containerPath
 {
 #if PLATFORM(IOS_FAMILY)
-    NSString *cpmconfigIgnoreFilePath = [NSString pathWithComponents:@[containerPath, @"Library/Preferences/", CaptivePortalConfigurationIgnoreFileName]];
+    NSString *cpmconfigIgnoreFilePath = [NSString pathWithComponents:@[containerPath, @"System/Preferences/", CaptivePortalConfigurationIgnoreFileName]];
     return [[NSFileManager defaultManager] fileExistsAtPath:cpmconfigIgnoreFilePath];
 #endif
     return false;
@@ -60,10 +68,20 @@
 + (void)setCaptivePortalModeIgnored:(NSString *)containerPath ignore:(BOOL)ignore
 {
 #if PLATFORM(IOS_FAMILY)
-    NSString *cpmconfigIgnoreFilePath = [NSString pathWithComponents:@[containerPath, @"Library/Preferences/", CaptivePortalConfigurationIgnoreFileName]];
+    NSString *cpmconfigDirectoryPath = [NSString pathWithComponents:@[containerPath, @"System/Preferences/"]];
+    NSString *cpmconfigIgnoreFilePath = [NSString pathWithComponents:@[cpmconfigDirectoryPath, CaptivePortalConfigurationIgnoreFileName]];
     if ([[NSFileManager defaultManager] fileExistsAtPath:cpmconfigIgnoreFilePath] == ignore)
         return;
-    
+
+    BOOL cpmconfigDirectoryisDir;
+    BOOL cpmconfigDirectoryPathExists = [[NSFileManager defaultManager] fileExistsAtPath:cpmconfigDirectoryPath isDirectory:&cpmconfigDirectoryisDir];
+
+    if (!cpmconfigDirectoryisDir)
+        [[NSFileManager defaultManager] removeItemAtPath:cpmconfigDirectoryPath error:NULL];
+
+    if (!cpmconfigDirectoryPathExists || !cpmconfigDirectoryisDir)
+        [[NSFileManager defaultManager] createDirectoryAtPath:cpmconfigDirectoryPath withIntermediateDirectories:YES attributes:NULL error:NULL];
+
     if (ignore)
         [[NSFileManager defaultManager] createFileAtPath:cpmconfigIgnoreFilePath contents:NULL attributes:NULL];
     else

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSystemPreferencesInternal.h (291510 => 291511)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSystemPreferencesInternal.h	2022-03-19 00:30:28 UTC (rev 291510)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSystemPreferencesInternal.h	2022-03-19 00:31:59 UTC (rev 291511)
@@ -25,5 +25,7 @@
 
 #import "_WKSystemPreferences.h"
 
+constexpr auto LDMEnabledKey = "LDMGlobalEnabled";
 constexpr auto WKCaptivePortalModeEnabledKey = "WKCaptivePortalModeEnabled";
+constexpr auto WebKitCaptivePortalModeChangedNotification_Legacy = "WebKitCaptivePortalModeEnabled";
 constexpr auto WKCaptivePortalModeContainerConfigurationChangedNotification = @"WKCaptivePortalModeContainerConfigurationChanged";

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (291510 => 291511)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2022-03-19 00:30:28 UTC (rev 291510)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2022-03-19 00:31:59 UTC (rev 291511)
@@ -130,7 +130,6 @@
 static NSString *WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification = @"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
 static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");
 #endif
-static const char* const WebKitCaptivePortalModeChangedNotification_Legacy = "WebKitCaptivePortalModeEnabled";
 
 static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
 
@@ -952,9 +951,6 @@
     if (auto& enabledForTesting = isCaptivePortalModeEnabledGloballyForTesting())
         return *enabledForTesting;
 
-    if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithUTF8String:WebKitCaptivePortalModeChangedNotification_Legacy]])
-        return true;
-
     if (![_WKSystemPreferences isCaptivePortalModeEnabled])
         return false;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to