Title: [217865] trunk
Revision
217865
Author
[email protected]
Date
2017-06-06 16:04:48 -0700 (Tue, 06 Jun 2017)

Log Message

REGRESSION (r199558): WKWebView upload file which name contains Chinese character results in garbled code
https://bugs.webkit.org/show_bug.cgi?id=172849
<rdar://problem/32567454>

Reviewed by Darin Adler.

Source/WebKit2:

This is the Mac equivalent of what was fixed in r208295. This time we use -[NSURL path] to
construct a WTF::String instead of calling String::fromUTF8() on -[NSURL fileSystemRepresentation].

* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::runOpenPanel):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/RunOpenPanel.mm: Added.
(-[RunOpenPanelUIDelegate webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:]):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (217864 => 217865)


--- trunk/Source/WebKit2/ChangeLog	2017-06-06 22:38:27 UTC (rev 217864)
+++ trunk/Source/WebKit2/ChangeLog	2017-06-06 23:04:48 UTC (rev 217865)
@@ -1,3 +1,17 @@
+2017-06-06  Andy Estes  <[email protected]>
+
+        REGRESSION (r199558): WKWebView upload file which name contains Chinese character results in garbled code
+        https://bugs.webkit.org/show_bug.cgi?id=172849
+        <rdar://problem/32567454>
+
+        Reviewed by Darin Adler.
+
+        This is the Mac equivalent of what was fixed in r208295. This time we use -[NSURL path] to
+        construct a WTF::String instead of calling String::fromUTF8() on -[NSURL fileSystemRepresentation].
+
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::UIClient::runOpenPanel):
+
 2017-06-06  Yoav Weiss  <[email protected]>
 
         [preload] Conditional support for media preloading and align media `as` values.

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm (217864 => 217865)


--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm	2017-06-06 22:38:27 UTC (rev 217864)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm	2017-06-06 23:04:48 UTC (rev 217865)
@@ -395,7 +395,7 @@
 
         Vector<String> filenames;
         for (NSURL *url in URLs)
-            filenames.append(url.fileSystemRepresentation);
+            filenames.append(url.path);
 
         resultListener->chooseFiles(filenames);
     }];

Modified: trunk/Tools/ChangeLog (217864 => 217865)


--- trunk/Tools/ChangeLog	2017-06-06 22:38:27 UTC (rev 217864)
+++ trunk/Tools/ChangeLog	2017-06-06 23:04:48 UTC (rev 217865)
@@ -1,3 +1,16 @@
+2017-06-06  Andy Estes  <[email protected]>
+
+        REGRESSION (r199558): WKWebView upload file which name contains Chinese character results in garbled code
+        https://bugs.webkit.org/show_bug.cgi?id=172849
+        <rdar://problem/32567454>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RunOpenPanel.mm: Added.
+        (-[RunOpenPanelUIDelegate webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:]):
+        (TestWebKitAPI::TEST):
+
 2017-06-06  Yoav Weiss  <[email protected]>
 
         [preload] Conditional support for media preloading and align media `as` values.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (217864 => 217865)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-06-06 22:38:27 UTC (rev 217864)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-06-06 23:04:48 UTC (rev 217865)
@@ -529,6 +529,7 @@
 		A16F66BA1C40EB4F00BD4D24 /* ContentFiltering.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A16F66B91C40EA2000BD4D24 /* ContentFiltering.html */; };
 		A17991881E1C994E00A505ED /* SharedBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = A17991861E1C994E00A505ED /* SharedBuffer.mm */; };
 		A179918B1E1CA24100A505ED /* SharedBufferTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17991891E1CA24100A505ED /* SharedBufferTest.cpp */; };
+		A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */; };
 		A1C4FB731BACD1CA003742D0 /* pages.pages in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1C4FB721BACD1B7003742D0 /* pages.pages */; };
 		A1DF74321C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */; };
 		A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */; };
@@ -1363,6 +1364,7 @@
 		A17991861E1C994E00A505ED /* SharedBuffer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedBuffer.mm; sourceTree = "<group>"; };
 		A17991891E1CA24100A505ED /* SharedBufferTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBufferTest.cpp; sourceTree = "<group>"; };
 		A179918A1E1CA24100A505ED /* SharedBufferTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedBufferTest.h; sourceTree = "<group>"; };
+		A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RunOpenPanel.mm; sourceTree = "<group>"; };
 		A18AA8CC1C3FA218009B2B97 /* ContentFiltering.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFiltering.h; sourceTree = "<group>"; };
 		A1A4FE5D18DD3DB700B5EA8A /* Download.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Download.mm; sourceTree = "<group>"; };
 		A1C4FB6C1BACCE50003742D0 /* QuickLook.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QuickLook.mm; sourceTree = "<group>"; };
@@ -1783,6 +1785,7 @@
 				A12DDBFC1E836FF100CF6CAE /* RenderedImageWithOptionsPlugIn.mm */,
 				A12DDC011E8374F500CF6CAE /* RenderedImageWithOptionsProtocol.h */,
 				CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
+				A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */,
 				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
 				2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
@@ -3087,6 +3090,7 @@
 				CE3524F91B1441C40028A7C5 /* TextFieldDidBeginAndEndEditing.cpp in Sources */,
 				7CCE7EDD1A411A9200447C4C /* TimeRanges.cpp in Sources */,
 				0F4FFA9E1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm in Sources */,
+				A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */,
 				7CCE7ED31A411A7E00447C4C /* TypingStyleCrash.mm in Sources */,
 				7CCE7EDE1A411A9200447C4C /* URL.cpp in Sources */,
 				7CCE7EB01A411A4400447C4C /* URLExtras.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RunOpenPanel.mm (0 => 217865)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RunOpenPanel.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RunOpenPanel.mm	2017-06-06 23:04:48 UTC (rev 217865)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 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"
+
+#if WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+
+#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
+#import "Utilities.h"
+#import <AppKit/AppKit.h>
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+static bool fileSelected;
+static NSString * const expectedFileName = @"这是中文";
+
+@interface RunOpenPanelUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation RunOpenPanelUIDelegate
+
+- (void)webView:(WKWebView *)webView runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSArray<NSURL *> * _Nullable))completionHandler
+{
+    completionHandler(@[ [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:expectedFileName]] ]);
+    fileSelected = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit2, RunOpenPanelNonLatin1)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+    auto uiDelegate = adoptNS([[RunOpenPanelUIDelegate alloc] init]);
+    [webView setUIDelegate:uiDelegate.get()];
+    [webView loadHTMLString:@"<!DOCTYPE html><input style='width: 100vw; height: 100vh;' type='file'>" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+    
+    NSPoint clickPoint = NSMakePoint(50, 50);
+    NSInteger windowNumber = [webView window].windowNumber;
+    [webView mouseDown:[NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [webView mouseUp:[NSEvent mouseEventWithType:NSEventTypeLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:1]];
+    Util::run(&fileSelected);
+    
+    __block bool testFinished = false;
+    [webView evaluateJavaScript:@"document.getElementsByTagName('input')[0].files[0].name" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
+        EXPECT_TRUE([result isKindOfClass:[NSString class]]);
+        EXPECT_WK_STREQ(expectedFileName, result);
+        testFinished = true;
+    }];
+    Util::run(&testFinished);
+}
+    
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to