Title: [232079] trunk
Revision
232079
Author
sihui_...@apple.com
Date
2018-05-22 14:13:59 -0700 (Tue, 22 May 2018)

Log Message

Conversion between SecurityOriginData and DatabaseIdentifier is asymmetric when port is null
https://bugs.webkit.org/show_bug.cgi?id=185715

Reviewed by Geoffrey Garen.

Source/WebCore:

Fixed the issue of null port when converting between SecurityOriginData and DatabaseIdentifier.

Test: WKWebView.LocalStorageFetchDataRecords.

* page/SecurityOriginData.cpp:
(WebCore::SecurityOriginData::fromDatabaseIdentifier):

Source/WebKit:

Add getter for origins in WKWebsiteDataRecord for testing.

* UIProcess/API/Cocoa/WKWebsiteDataRecord.mm:
(-[WKWebsiteDataRecord _originsString]):
* UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h:

Tools:

Add API test coverage.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/LocalStorageDatabaseTracker.mm: Added.
(-[LocalStorageUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (232078 => 232079)


--- trunk/Source/WebCore/ChangeLog	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Source/WebCore/ChangeLog	2018-05-22 21:13:59 UTC (rev 232079)
@@ -1,3 +1,17 @@
+2018-05-22  Sihui Liu  <sihui_...@apple.com>
+
+        Conversion between SecurityOriginData and DatabaseIdentifier is asymmetric when port is null
+        https://bugs.webkit.org/show_bug.cgi?id=185715
+
+        Reviewed by Geoffrey Garen.
+
+        Fixed the issue of null port when converting between SecurityOriginData and DatabaseIdentifier.
+
+        Test: WKWebView.LocalStorageFetchDataRecords.
+
+        * page/SecurityOriginData.cpp:
+        (WebCore::SecurityOriginData::fromDatabaseIdentifier):
+
 2018-05-22  Keith Miller  <keith_mil...@apple.com>
 
         We should have a CoW storage for NewArrayBuffer arrays.

Modified: trunk/Source/WebCore/page/SecurityOriginData.cpp (232078 => 232079)


--- trunk/Source/WebCore/page/SecurityOriginData.cpp	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Source/WebCore/page/SecurityOriginData.cpp	2018-05-22 21:13:59 UTC (rev 232079)
@@ -114,7 +114,12 @@
     if (port < 0 || port > std::numeric_limits<uint16_t>::max())
         return std::nullopt;
     
-    return SecurityOriginData {databaseIdentifier.substring(0, separator1), databaseIdentifier.substring(separator1 + 1, separator2 - separator1 - 1), static_cast<uint16_t>(port)};
+    auto protocol = databaseIdentifier.substring(0, separator1);
+    auto host = databaseIdentifier.substring(separator1 + 1, separator2 - separator1 - 1);
+    if (!port)
+        return SecurityOriginData { protocol, host, std::nullopt };
+
+    return SecurityOriginData { protocol, host, static_cast<uint16_t>(port) };
 }
 
 SecurityOriginData SecurityOriginData::isolatedCopy() const

Modified: trunk/Source/WebKit/ChangeLog (232078 => 232079)


--- trunk/Source/WebKit/ChangeLog	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Source/WebKit/ChangeLog	2018-05-22 21:13:59 UTC (rev 232079)
@@ -1,3 +1,17 @@
+2018-05-22  Sihui Liu  <sihui_...@apple.com>
+
+        Conversion between SecurityOriginData and DatabaseIdentifier is asymmetric when port is null
+        https://bugs.webkit.org/show_bug.cgi?id=185715
+
+        Reviewed by Geoffrey Garen.
+
+        Add getter for origins in WKWebsiteDataRecord for testing.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataRecord.mm:
+        (-[WKWebsiteDataRecord _originsString]):
+        * UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h:
+
+
 2018-05-22  Brady Eidson  <beid...@apple.com>
 
         Rename the "Web content is visible" process assertion.

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm (232078 => 232079)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm	2018-05-22 21:13:59 UTC (rev 232079)
@@ -29,6 +29,8 @@
 #if WK_API_ENABLED
 
 #import "_WKWebsiteDataSizeInternal.h"
+#import <WebCore/SecurityOriginData.h>
+#import <wtf/HashSet.h>
 
 NSString * const WKWebsiteDataTypeFetchCache = @"WKWebsiteDataTypeFetchCache";
 NSString * const WKWebsiteDataTypeDiskCache = @"WKWebsiteDataTypeDiskCache";
@@ -146,6 +148,15 @@
     return [[[_WKWebsiteDataSize alloc] initWithSize:*size] autorelease];
 }
 
+- (NSArray<NSString *> *)_originsStrings
+{
+    auto origins = _websiteDataRecord->websiteDataRecord().origins;
+    NSMutableArray<NSString *> *array = [[NSMutableArray alloc] initWithCapacity:origins.size()];
+    for (auto& origin : origins)
+        [array addObject:(NSString *)origin.toString()];
+    return [array autorelease];
+}
+
 @end
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h (232078 => 232079)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h	2018-05-22 21:13:59 UTC (rev 232079)
@@ -46,6 +46,8 @@
 
 @property (nullable, nonatomic, readonly) _WKWebsiteDataSize *_dataSize;
 
+- (NSArray<NSString *> *)_originsStrings WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/Tools/ChangeLog (232078 => 232079)


--- trunk/Tools/ChangeLog	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Tools/ChangeLog	2018-05-22 21:13:59 UTC (rev 232079)
@@ -1,5 +1,19 @@
 2018-05-22  Sihui Liu  <sihui_...@apple.com>
 
+        Conversion between SecurityOriginData and DatabaseIdentifier is asymmetric when port is null
+        https://bugs.webkit.org/show_bug.cgi?id=185715
+
+        Reviewed by Geoffrey Garen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/LocalStorageDatabaseTracker.mm: Added.
+        (-[LocalStorageUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (TEST):
+
+2018-05-22  Sihui Liu  <sihui_...@apple.com>
+
         Unreviewed, added myself as a WebKit committer.
 
         * Scripts/webkitpy/common/config/contributors.json:

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (232078 => 232079)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-05-22 20:52:08 UTC (rev 232078)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-05-22 21:13:59 UTC (rev 232079)
@@ -698,6 +698,7 @@
 		C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */; };
 		C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */; };
 		C9E6DD351EA97D0800DD78AA /* FirstResponderSuppression.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */; };
+		CA38459620AE17A900990D3B /* LocalStorageDatabaseTracker.mm in Sources */ = {isa = PBXBuildFile; fileRef = CA38459520AE012E00990D3B /* LocalStorageDatabaseTracker.mm */; };
 		CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */; };
 		CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */; };
 		CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
@@ -1843,6 +1844,7 @@
 		C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-frame.html"; sourceTree = "<group>"; };
 		C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-in-iframe.html"; sourceTree = "<group>"; };
 		C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderSuppression.mm; sourceTree = "<group>"; };
+		CA38459520AE012E00990D3B /* LocalStorageDatabaseTracker.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageDatabaseTracker.mm; sourceTree = "<group>"; };
 		CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuImgWithVideo.mm; sourceTree = "<group>"; };
 		CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = ContextMenuImgWithVideo.html; sourceTree = "<group>"; };
 		CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
@@ -2213,6 +2215,7 @@
 				A125478D1DB18B9400358564 /* LoadDataWithNilMIMEType.mm */,
 				57901FAC1CAF12C200ED64F9 /* LoadInvalidURLRequest.mm */,
 				51E6A8921D2F1BEC00C004B6 /* LocalStorageClear.mm */,
+				CA38459520AE012E00990D3B /* LocalStorageDatabaseTracker.mm */,
 				46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */,
 				8C10AF96206467770018FD90 /* LocalStoragePersistence.mm */,
 				7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */,
@@ -3649,6 +3652,7 @@
 				7CCE7F001A411AE600447C4C /* LoadPageOnCrash.cpp in Sources */,
 				574F55CF204D37C5002948C6 /* LocalAuthenticator.mm in Sources */,
 				51E6A8941D2F1C0A00C004B6 /* LocalStorageClear.mm in Sources */,
+				CA38459620AE17A900990D3B /* LocalStorageDatabaseTracker.mm in Sources */,
 				46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */,
 				8C10AF99206467A90018FD90 /* LocalStoragePersistence.mm in Sources */,
 				7A6A2C701DCCFA8C00C0D085 /* LocalStorageQuirkTest.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStorageDatabaseTracker.mm (0 => 232079)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStorageDatabaseTracker.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStorageDatabaseTracker.mm	2018-05-22 21:13:59 UTC (rev 232079)
@@ -0,0 +1,80 @@
+/*
+ * 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 "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WKWebsiteDataRecordPrivate.h>
+#import <WebKit/WebKit.h>
+#import <wtf/text/WTFString.h>
+
+#if WK_API_ENABLED
+
+static bool readyToContinue;
+
+@interface LocalStorageUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation LocalStorageUIDelegate
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+    EXPECT_STREQ("testValue", message.UTF8String);
+    readyToContinue = true;
+    completionHandler();
+}
+@end
+
+TEST(WKWebView, LocalStorageFetchDataRecords)
+{
+    readyToContinue = false;
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+
+    readyToContinue = false;
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    webView.get().UIDelegate = [[[LocalStorageUIDelegate alloc] init] autorelease];
+    [webView loadHTMLString:@"<script>localStorage.setItem('testKey', 'testValue');alert(localStorage.getItem('testKey'));</script>" baseURL:[NSURL URLWithString:@"http://localhost"]];
+    TestWebKitAPI::Util::run(&readyToContinue);
+
+    // Local storage database update interval is 1 second.
+    TestWebKitAPI::Util::sleep(1);
+
+    readyToContinue = false;
+    [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {
+        readyToContinue = true;
+        ASSERT_EQ(1u, dataRecords.count);
+        auto origins = [[dataRecords objectAtIndex:0] _originsStrings];
+        ASSERT_EQ(1u, origins.count);
+        EXPECT_STREQ("http://localhost", [origins objectAtIndex:0].UTF8String);
+    }];
+    TestWebKitAPI::Util::run(&readyToContinue);
+}
+
+#endif
+
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to