Changeset 229503 in webkit
- Timestamp:
- Mar 10, 2018 3:33:20 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r229502 r229503 1 2018-03-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails 4 https://bugs.webkit.org/show_bug.cgi?id=183485 5 <rdar://problem/38041984> 6 7 Reviewed by Ryosuke Niwa. 8 9 Rebaseline some pasteboard-related layout tests, in which we now expose text/plain alongside files that were 10 written to the DataTransfer by the page itself. 11 12 * editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt: 13 * editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt: 14 * editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt: 15 1 16 2018-03-09 Chris Dumez <cdumez@apple.com> 2 17 -
trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt
r228340 r229503 11 11 "data": { 12 12 "Files": "", 13 "text/plain": "plain text string", 13 14 "text/uri-list": "https://webkit.org" 14 15 }, … … 89 90 "data": { 90 91 "Files": "", 92 "text/plain": "plain text string", 91 93 "text/uri-list": "https://webkit.org" 92 94 }, … … 154 156 "data": { 155 157 "Files": "", 158 "text/plain": "plain text string", 156 159 "text/uri-list": "https://webkit.org" 157 160 }, … … 205 208 "data": { 206 209 "Files": "", 210 "text/plain": "plain text string", 207 211 "text/uri-list": "https://webkit.org" 208 212 }, … … 249 253 "data": { 250 254 "Files": "", 251 "text/html": "<strong>some styled text</strong>" 255 "text/html": "<strong>some styled text</strong>", 256 "text/plain": "some plain text" 252 257 }, 253 258 "items": [ -
trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt
r228340 r229503 25 25 { 26 26 "data": { 27 "Files": "" 27 "Files": "", 28 "text/plain": "hello world" 28 29 }, 29 30 "items": [ … … 55 56 { 56 57 "data": { 57 "Files": "" 58 "Files": "", 59 "text/plain": "hello world" 58 60 }, 59 61 "items": [ … … 99 101 { 100 102 "data": { 101 "Files": "" 103 "Files": "", 104 "text/plain": "hello world" 102 105 }, 103 106 "items": [ … … 131 134 "data": { 132 135 "Files": "", 136 "text/plain": "hello world", 133 137 "text/html": "<a>goodbye world</a>" 134 138 }, … … 167 171 "data": { 168 172 "Files": "", 173 "text/plain": "hello world", 169 174 "text/html": "<a>goodbye world</a>" 170 175 }, … … 217 222 "data": { 218 223 "Files": "", 224 "text/plain": "hello world", 219 225 "text/html": "<a>goodbye world</a>" 220 226 }, … … 253 259 { 254 260 "data": { 255 "Files": "" 261 "Files": "", 262 "text/plain": "hello world" 256 263 }, 257 264 "items": [ -
trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt
r228340 r229503 25 25 { 26 26 "data": { 27 "Files": "" 27 "Files": "", 28 "text/plain": "hello world" 28 29 }, 29 30 "items": [ … … 55 56 { 56 57 "data": { 57 "Files": "" 58 "Files": "", 59 "text/plain": "hello world" 58 60 }, 59 61 "items": [ … … 99 101 { 100 102 "data": { 101 "Files": "" 103 "Files": "", 104 "text/plain": "hello world" 102 105 }, 103 106 "items": [ … … 131 134 "data": { 132 135 "Files": "", 136 "text/plain": "hello world", 133 137 "text/html": "<a>goodbye world</a>" 134 138 }, … … 167 171 "data": { 168 172 "Files": "", 173 "text/plain": "hello world", 169 174 "text/html": "<a>goodbye world</a>" 170 175 }, … … 217 222 "data": { 218 223 "Files": "", 224 "text/plain": "hello world", 219 225 "text/html": "<a>goodbye world</a>" 220 226 }, … … 253 259 { 254 260 "data": { 255 "Files": "" 261 "Files": "", 262 "text/plain": "hello world" 256 263 }, 257 264 "items": [ -
trunk/Source/WebCore/ChangeLog
r229500 r229503 1 2018-03-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails 4 https://bugs.webkit.org/show_bug.cgi?id=183485 5 <rdar://problem/38041984> 6 7 Reviewed by Ryosuke Niwa. 8 9 After r222656, WebKit now treats raw image data on the pasteboard as files for the purposes of computing 10 DataTransfer.files and DataTransfer.types. However, this is combined with existing policies that suppress 11 DataTransfer.getData and DataTransfer.setData when the pasteboard contains files (generalized to copy/paste in 12 r222688). This means we now don't allow web pages to access "text/plain" in the case where the user copies part 13 of a table from the native Numbers app since Numbers additionally writes a snapshot of the table to the platform 14 pasteboard. 15 16 This restriction on getData/setData was intended to prevent web pages from extracting users' file paths when 17 pasting or dropping, so it doesn't make sense to enforce this restriction even when there is only in-memory 18 image data on the pasteboard. To fix this bug, we make Pasteboard::fileContentState() differentiate between 19 cases where there are (real) files on the pasteboard, and cases where we've fallen back to treating image data 20 as files. 21 22 Rebaselined existing LayoutTests to match new behavior. 23 Also covered by 4 new API tests: 24 - PasteMixedContent.ImageDataAndPlainText 25 - PasteMixedContent.ImageDataAndPlainTextAndURL 26 - PasteMixedContent.ImageDataAndPlainTextAndURLAndHTML 27 - UIPasteboardTests.DataTransferGetDataWhenPastingImageAndText 28 29 * dom/DataTransfer.cpp: 30 (WebCore::DataTransfer::shouldSuppressGetAndSetDataToAvoidExposingFilePaths const): 31 32 If custom pasteboard data is enabled, suppress getData and setData if and only if we might actually expose file 33 paths (see Pasteboard::fileContentState). 34 35 (WebCore::DataTransfer::types const): 36 37 Only allow "text/html" or "text/uri-list" in the case where there are actual files in the pasteboard. If there's 38 only image data, add all of the DOM-safe types back into the list of types. 39 40 * platform/Pasteboard.h: 41 * platform/StaticPasteboard.h: 42 43 Add an enum type to represent the result of Pasteboard::fileContentState. 44 - NoFileOrImageData indicates that there was nothing on the pasteboard that could be considered a file 45 from the point of view of the page. 46 - InMemoryImage indicates that there are no files on the pasteboard, but there is image data that we consider 47 to be files, exposed via DataTransfer API. 48 - MayContainFilePaths indicates that there might be file paths on the pasteboard. This means that the source 49 has either written file paths to the pasteboard (for example, through NSFilenamesPboardType) or the source 50 has written image data along with a URL type of some sort that does not match one of the allowed URL schemes 51 that are safe to expose (currently, these are http-family, data, or blob). 52 53 * platform/cocoa/PasteboardCocoa.mm: 54 (WebCore::Pasteboard::fileContentState): 55 56 Refactor to return one of the three enum types described above. 57 58 (WebCore::Pasteboard::containsFiles): Deleted. 59 * platform/gtk/PasteboardGtk.cpp: 60 (WebCore::Pasteboard::fileContentState): 61 (WebCore::Pasteboard::containsFiles): Deleted. 62 * platform/win/PasteboardWin.cpp: 63 (WebCore::Pasteboard::fileContentState): 64 (WebCore::Pasteboard::containsFiles): Deleted. 65 * platform/wpe/PasteboardWPE.cpp: 66 (WebCore::Pasteboard::fileContentState): 67 (WebCore::Pasteboard::containsFiles): Deleted. 68 69 Adjust for Pasteboard::fileContentState() tweaks. 70 1 71 2018-03-09 Chris Fleizach <cfleizach@apple.com> 2 72 -
trunk/Source/WebCore/dom/DataTransfer.cpp
r228340 r229503 205 205 if (!forFileDrag() && !RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled()) 206 206 return false; 207 return m_pasteboard-> containsFiles();207 return m_pasteboard->fileContentState() == Pasteboard::FileContentState::MayContainFilePaths; 208 208 } 209 209 … … 292 292 auto types = m_pasteboard->typesForLegacyUnsafeBindings(); 293 293 ASSERT(!types.contains("Files")); 294 if (m_pasteboard-> containsFiles()&& addFilesType == AddFilesType::Yes)294 if (m_pasteboard->fileContentState() != Pasteboard::FileContentState::NoFileOrImageData && addFilesType == AddFilesType::Yes) 295 295 types.append("Files"); 296 296 return types; … … 302 302 }); 303 303 304 if (hasFileBackedItem || m_pasteboard->containsFiles()) { 304 auto fileContentState = m_pasteboard->fileContentState(); 305 if (hasFileBackedItem || fileContentState != Pasteboard::FileContentState::NoFileOrImageData) { 305 306 Vector<String> types; 306 307 if (addFilesType == AddFilesType::Yes) 307 308 types.append(ASCIILiteral("Files")); 309 310 if (fileContentState != Pasteboard::FileContentState::MayContainFilePaths) { 311 types.appendVector(WTFMove(safeTypes)); 312 return types; 313 } 314 308 315 if (safeTypes.contains("text/uri-list")) 309 316 types.append(ASCIILiteral("text/uri-list")); -
trunk/Source/WebCore/platform/Pasteboard.h
r229297 r229503 221 221 virtual WEBCORE_EXPORT void writeCustomData(const PasteboardCustomData&); 222 222 223 virtual WEBCORE_EXPORT bool containsFiles(); 223 enum class FileContentState { NoFileOrImageData, InMemoryImage, MayContainFilePaths }; 224 virtual WEBCORE_EXPORT FileContentState fileContentState(); 224 225 virtual WEBCORE_EXPORT bool canSmartReplace(); 225 226 -
trunk/Source/WebCore/platform/StaticPasteboard.h
r228340 r229503 62 62 void writeCustomData(const PasteboardCustomData&) final { } 63 63 64 bool containsFiles() final { return false; }64 Pasteboard::FileContentState fileContentState() final { return FileContentState::NoFileOrImageData; } 65 65 bool canSmartReplace() final { return false; } 66 66 -
trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm
r227552 r229503 135 135 } 136 136 137 bool Pasteboard::containsFiles() 138 { 139 if (!platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName)) { 137 Pasteboard::FileContentState Pasteboard::fileContentState() 138 { 139 bool mayContainFilePaths = platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName); 140 if (!mayContainFilePaths) { 140 141 Vector<String> cocoaTypes; 141 142 platformStrategies()->pasteboardStrategy()->getTypes(cocoaTypes, m_pasteboardName); 142 143 if (cocoaTypes.findMatching([](const String& cocoaType) { return shouldTreatCocoaTypeAsFile(cocoaType); }) == notFound) 143 return false; 144 } 145 146 // Enforce changeCount ourselves for security. We check after reading instead of before to be 147 // sure it doesn't change between our testing the change count and accessing the data. 148 if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) 149 return false; 150 151 return true; 144 return FileContentState::NoFileOrImageData; 145 146 bool containsURL = notFound != cocoaTypes.findMatching([] (auto& cocoaType) { 147 #if PLATFORM(MAC) 148 if (cocoaType == String(legacyURLPasteboardType())) 149 return true; 150 #endif 151 return cocoaType == String(kUTTypeURL); 152 }); 153 mayContainFilePaths = containsURL && !Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(readString(ASCIILiteral("text/uri-list"))); 154 } 155 156 // Enforce changeCount ourselves for security. We check after reading instead of before to be 157 // sure it doesn't change between our testing the change count and accessing the data. 158 if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) 159 return FileContentState::NoFileOrImageData; 160 161 // Even when there's only image data in the pasteboard and no file representations, we still run the risk of exposing file paths 162 // to the page if the app has written image data to the pasteboard with a corresponding file path as plain text. An example of 163 // this is copying an image with a local `src` in Safari. To mitigate this, we additionally require that the app has not also 164 // written URLs to the pasteboard, as this would suggest that the plain text data might contain file paths. 165 return mayContainFilePaths ? FileContentState::MayContainFilePaths : FileContentState::InMemoryImage; 152 166 } 153 167 -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r228340 r229503 319 319 } 320 320 321 bool Pasteboard::containsFiles()322 { 323 readFromClipboard(); 324 return !m_selectionData->filenames().isEmpty();321 Pasteboard::FileContentState Pasteboard::fileContentState() 322 { 323 readFromClipboard(); 324 return m_selectionData->filenames().isEmpty() ? FileContentState::NoFileOrImageData : FileContentState::MayContainFilePaths; 325 325 } 326 326 -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r228340 r229503 316 316 }; 317 317 318 bool Pasteboard::containsFiles()318 Pasteboard::FileContentState Pasteboard::fileContentState() 319 319 { 320 320 // FIXME: This implementation can be slightly more efficient by avoiding calls to DragQueryFileW. 321 321 PasteboardFileCounter reader; 322 322 read(reader); 323 return reader.count ;323 return reader.count ? FileContentState::MayContainFilePaths : FileContentState::NoFileOrImageData; 324 324 } 325 325 -
trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp
r228340 r229503 126 126 } 127 127 128 bool Pasteboard::containsFiles()128 Pasteboard::FileContentState Pasteboard::fileContentState() 129 129 { 130 130 notImplemented(); 131 return false;131 return FileContentState::NoFileOrImageData; 132 132 } 133 133 -
trunk/Tools/ChangeLog
r229473 r229503 1 2018-03-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails 4 https://bugs.webkit.org/show_bug.cgi?id=183485 5 <rdar://problem/38041984> 6 7 Reviewed by Ryosuke Niwa. 8 9 Add new API tests to cover scenarios in which we paste image data alongside text data. 10 11 * TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm: 12 (TestWebKitAPI::TEST): 13 * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm: 14 (TestWebKitAPI::TEST): 15 1 16 2018-03-09 Zalan Bujtas <zalan@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm
r228340 r229503 195 195 } 196 196 197 TEST(PasteMixedContent, ImageDataAndPlainText) 198 { 199 auto webView = setUpWebView(); 200 writeTypesAndDataToPasteboard(NSPasteboardTypeString, @"Hello world", NSPasteboardTypePNG, [NSData dataWithContentsOfFile:imagePath()], nil); 201 [webView paste:nil]; 202 203 EXPECT_WK_STREQ("Files, text/plain", [webView stringByEvaluatingJavaScript:@"types.textContent"]); 204 EXPECT_WK_STREQ("(STRING, text/plain), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]); 205 EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]); 206 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]); 207 EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"textData.textContent"]); 208 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]); 209 } 210 211 TEST(PasteMixedContent, ImageDataAndPlainTextAndURL) 212 { 213 auto webView = setUpWebView(); 214 writeTypesAndDataToPasteboard(NSPasteboardTypeString, imagePath(), NSURLPboardType, imagePath(), NSPasteboardTypePNG, [NSData dataWithContentsOfFile:imagePath()], nil); 215 [webView paste:nil]; 216 217 EXPECT_WK_STREQ("Files", [webView stringByEvaluatingJavaScript:@"types.textContent"]); 218 EXPECT_WK_STREQ("(FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]); 219 EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]); 220 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]); 221 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"textData.textContent"]); 222 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]); 223 } 224 225 TEST(PasteMixedContent, ImageDataAndPlainTextAndURLAndHTML) 226 { 227 auto webView = setUpWebView(); 228 writeTypesAndDataToPasteboard(NSPasteboardTypeString, imagePath(), NSURLPboardType, imagePath(), NSPasteboardTypeHTML, markupString(), NSPasteboardTypePNG, [NSData dataWithContentsOfFile:imagePath()], nil); 229 [webView paste:nil]; 230 231 EXPECT_WK_STREQ("Files, text/html", [webView stringByEvaluatingJavaScript:@"types.textContent"]); 232 EXPECT_WK_STREQ("(STRING, text/html), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]); 233 EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]); 234 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]); 235 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"textData.textContent"]); 236 EXPECT_WK_STREQ("HELLO WORLD", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]); 237 EXPECT_FALSE([[webView stringByEvaluatingJavaScript:@"rawHTMLData.textContent"] containsString:@"script"]); 238 } 239 197 240 } // namespace TestWebKitAPI 198 241 -
trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm
r227859 r229503 195 195 } 196 196 197 TEST(UIPasteboardTests, DataTransferGetDataWhenPastingImageAndText) 198 { 199 auto webView = setUpWebViewForPasteboardTests(@"DataTransfer"); 200 auto copiedText = retainPtr(@"Apple Inc."); 201 auto itemProvider = adoptNS([[NSItemProvider alloc] init]); 202 [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { 203 completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); 204 return nil; 205 }]; 206 [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeUTF8PlainText visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[copiedText] (DataLoadCompletionBlock completionHandler) -> NSProgress * { 207 completionHandler([copiedText dataUsingEncoding:NSUTF8StringEncoding], nil); 208 return nil; 209 }]; 210 [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; 211 [webView paste:nil]; 212 213 EXPECT_WK_STREQ("Files, text/plain", [webView stringByEvaluatingJavaScript:@"types.textContent"]); 214 EXPECT_WK_STREQ("(STRING, text/plain), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]); 215 EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]); 216 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]); 217 EXPECT_WK_STREQ("Apple Inc.", [webView stringByEvaluatingJavaScript:@"textData.textContent"]); 218 EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]); 219 } 220 197 221 TEST(UIPasteboardTests, DataTransferSetDataCannotWritePlatformTypes) 198 222 {
Note: See TracChangeset
for help on using the changeset viewer.