Changeset 47852 in webkit
- Timestamp:
- Aug 27, 2009 6:38:08 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r47850 r47852 1 2009-08-27 Noel Gordon <noel.gordon@gmail.com> 2 3 Reviewed by Eric Seidel. 4 5 dataTransfer.types() should include type "Files" when files are present in the clipboard. 6 https://bugs.webkit.org/show_bug.cgi?id=28780 7 8 Test dataTransfer.types "Files" access for all ports. 9 10 * http/tests/security/clipboard/clipboard-file-access-expected.txt: 11 * http/tests/security/clipboard/resources/clipboard-file-access.js: 12 1 13 2009-08-27 Oliver Hunt <oliver@apple.com> 2 14 -
trunk/LayoutTests/http/tests/security/clipboard/clipboard-file-access-expected.txt
r47832 r47852 1 Tests access to event.dataTransfer.files 1 Tests access to event.dataTransfer.files and .types 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". … … 6 6 Dragging no files should return an empty file list (arbitrary implementation detail): 7 7 On dragenter: 8 PASS event.dataTransfer.types contains Files. 8 9 PASS event.dataTransfer.files.length is 0 9 10 On dragover: 11 PASS event.dataTransfer.types contains Files. 10 12 PASS event.dataTransfer.files.length is 0 11 13 On drop: 14 PASS event.dataTransfer.types contains Files. 12 15 PASS event.dataTransfer.files.length is 0 13 16 Drag drop a single (non-existant) file onto an element: 14 17 On dragenter: 18 PASS event.dataTransfer.types contains Files. 15 19 PASS event.dataTransfer.files.length is 0 16 20 On dragover: 21 PASS event.dataTransfer.types contains Files. 17 22 PASS event.dataTransfer.files.length is 0 18 23 On dragover: 24 PASS event.dataTransfer.types contains Files. 19 25 PASS event.dataTransfer.files.length is 0 20 26 On drop: 27 PASS event.dataTransfer.types contains Files. 21 28 PASS event.dataTransfer.files.length is 1 22 29 PASS event.dataTransfer.files[0].fileName is "DRTFakeFile" … … 25 32 Drag files over an element, leave that element and release the mouse: 26 33 On dragenter: 34 PASS event.dataTransfer.types contains Files. 27 35 PASS event.dataTransfer.files.length is 0 28 36 On dragover: 37 PASS event.dataTransfer.types contains Files. 29 38 PASS event.dataTransfer.files.length is 0 30 39 On dragleave: 40 PASS event.dataTransfer.types contains Files. 31 41 PASS event.dataTransfer.files.length is 0 32 42 Drag drop a real file onto an element: 33 43 On dragenter: 44 PASS event.dataTransfer.types contains Files. 34 45 PASS event.dataTransfer.files.length is 0 35 46 On dragover: 47 PASS event.dataTransfer.types contains Files. 36 48 PASS event.dataTransfer.files.length is 0 37 49 On drop: 50 PASS event.dataTransfer.types contains Files. 38 51 PASS event.dataTransfer.files.length is 1 39 52 PASS event.dataTransfer.files[0].fileName is "apple.gif" … … 41 54 Drag drop two files onto an element: 42 55 On dragenter: 56 PASS event.dataTransfer.types contains Files. 43 57 PASS event.dataTransfer.files.length is 0 44 58 On dragover: 59 PASS event.dataTransfer.types contains Files. 45 60 PASS event.dataTransfer.files.length is 0 46 61 On dragover: 62 PASS event.dataTransfer.types contains Files. 47 63 PASS event.dataTransfer.files.length is 0 48 64 On drop: 65 PASS event.dataTransfer.types contains Files. 49 66 PASS event.dataTransfer.files.length is 2 50 67 PASS event.dataTransfer.files[0].fileName is "apple.gif" … … 54 71 Drag drop two files in reverse alphabetical order onto an element: 55 72 On dragenter: 73 PASS event.dataTransfer.types contains Files. 56 74 PASS event.dataTransfer.files.length is 0 57 75 On dragover: 76 PASS event.dataTransfer.types contains Files. 58 77 PASS event.dataTransfer.files.length is 0 59 78 On dragover: 79 PASS event.dataTransfer.types contains Files. 60 80 PASS event.dataTransfer.files.length is 0 61 81 On drop: 82 PASS event.dataTransfer.types contains Files. 62 83 PASS event.dataTransfer.files.length is 2 63 84 PASS event.dataTransfer.files[0].fileName is "mozilla.gif" … … 68 89 Drag drop a directory onto an element: 69 90 On dragenter: 91 PASS event.dataTransfer.types contains Files. 70 92 PASS event.dataTransfer.files.length is 0 71 93 On dragover: 94 PASS event.dataTransfer.types contains Files. 72 95 PASS event.dataTransfer.files.length is 0 73 96 On dragover: 97 PASS event.dataTransfer.types contains Files. 74 98 PASS event.dataTransfer.files.length is 0 75 99 On drop: 100 PASS event.dataTransfer.types contains Files. 76 101 FAIL event.dataTransfer.files.length should be 0. Was 1. 77 102 Drag drop a file and a directory onto an element: 78 103 On dragenter: 104 PASS event.dataTransfer.types contains Files. 79 105 PASS event.dataTransfer.files.length is 0 80 106 On dragover: 107 PASS event.dataTransfer.types contains Files. 81 108 PASS event.dataTransfer.files.length is 0 82 109 On dragover: 110 PASS event.dataTransfer.types contains Files. 83 111 PASS event.dataTransfer.files.length is 0 84 112 On drop: 113 PASS event.dataTransfer.types contains Files. 85 114 FAIL event.dataTransfer.files.length should be 0. Was 2. 86 115 Drag drop a directory and a file onto an element: 87 116 On dragenter: 117 PASS event.dataTransfer.types contains Files. 88 118 PASS event.dataTransfer.files.length is 0 89 119 On dragover: 120 PASS event.dataTransfer.types contains Files. 90 121 PASS event.dataTransfer.files.length is 0 91 122 On dragover: 123 PASS event.dataTransfer.types contains Files. 92 124 PASS event.dataTransfer.files.length is 0 93 125 On drop: 126 PASS event.dataTransfer.types contains Files. 94 127 FAIL event.dataTransfer.files.length should be 0. Was 2. 95 128 PASS successfullyParsed is true -
trunk/LayoutTests/http/tests/security/clipboard/resources/clipboard-file-access.js
r47832 r47852 1 description("Tests access to event.dataTransfer.files ");1 description("Tests access to event.dataTransfer.files and .types"); 2 2 3 3 var dragTarget = document.createElement("div"); … … 12 12 debug("On dragenter:") 13 13 event.dataTransfer.dropEffect = "copy"; 14 eventShouldContainTransferType(event, "Files"); 14 15 fileListShouldBe("event.dataTransfer.files", []); 15 16 event.preventDefault(); … … 19 20 debug("On dragover:") 20 21 event.dataTransfer.dropEffect = "copy"; 22 eventShouldContainTransferType(event, "Files"); 21 23 fileListShouldBe("event.dataTransfer.files", []); 22 24 event.preventDefault(); … … 25 27 dragTarget.addEventListener("dragleave", function() { 26 28 debug("On dragleave:") 29 eventShouldContainTransferType(event, "Files"); 27 30 fileListShouldBe("event.dataTransfer.files", []); 28 31 }, false); … … 31 34 dragTarget.addEventListener("drop", function() { 32 35 debug("On drop:") 36 eventShouldContainTransferType(event, "Files"); 33 37 fileListShouldBe("event.dataTransfer.files", expectedFilesOnDrop); 34 38 event.preventDefault(); … … 51 55 moveMouseToCenterOfElement(dragTarget); 52 56 if (leave && leave === true) 53 moveMouseToOutsideOfElement(dragTarget);57 moveMouseToOutsideOfElement(dragTarget); 54 58 eventSender.mouseUp(); 59 } 60 61 function eventShouldContainTransferType(event, typeString) 62 { 63 if (event.dataTransfer.types.indexOf(typeString) == -1) 64 testFailed("event.dataTransfer.types " + typeString + " expected."); 65 else 66 testPassed("event.dataTransfer.types contains " + typeString + "."); 55 67 } 56 68 -
trunk/WebCore/ChangeLog
r47851 r47852 1 2009-08-27 Noel Gordon <noel.gordon@gmail.com> 2 3 Reviewed by Eric Seidel. 4 5 dataTransfer.types() should include type "Files" when files are present in the clipboard. 6 https://bugs.webkit.org/show_bug.cgi?id=28780 7 8 Add dataTransfer type "Files" to the chromium port. Add eseidel's 9 patch for same for the mac port. 10 11 * platform/chromium/ClipboardChromium.cpp: 12 1 13 2009-08-27 Chris Marrin <cmarrin@apple.com> 2 14 -
trunk/WebCore/platform/chromium/ClipboardChromium.cpp
r47833 r47852 166 166 return results; 167 167 168 if (!m_dataObject->filenames.isEmpty()) 169 results.add("Files"); 170 168 171 if (m_dataObject->url.isValid()) { 169 172 results.add("URL"); -
trunk/WebCore/platform/mac/ClipboardMac.mm
r47829 r47852 64 64 } 65 65 66 static NSString *cocoaTypeFrom MIMEType(const String& type)66 static NSString *cocoaTypeFromHTMLClipboardType(const String& type) 67 67 { 68 68 String qType = type.stripWhiteSpace(); … … 94 94 } 95 95 96 static String MIMETypeFromCocoaType(NSString *type) 97 { 98 // UTI may not do these right, so make sure we get the right, predictable result 99 if ([type isEqualToString:NSStringPboardType]) 100 return "text/plain"; 101 if ([type isEqualToString:NSURLPboardType] || [type isEqualToString:NSFilenamesPboardType]) 102 return "text/uri-list"; 103 104 // Now try the general UTI mechanism 96 static String utiTypeFromCocoaType(NSString *type) 97 { 105 98 RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL)); 106 99 if (utiType) { … … 109 102 return String(mimeType.get()); 110 103 } 111 112 // No mapping, just pass the whole string though 113 return type; 104 return String(); 105 } 106 107 static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, NSString *cocoaType) 108 { 109 // UTI may not do these right, so make sure we get the right, predictable result 110 if ([cocoaType isEqualToString:NSStringPboardType]) 111 resultTypes.add("text/plain"); 112 else if ([cocoaType isEqualToString:NSURLPboardType]) 113 resultTypes.add("text/uri-list"); 114 else if ([cocoaType isEqualToString:NSFilenamesPboardType]) { 115 // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa, 116 // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files' 117 resultTypes.add("text/uri-list"); 118 resultTypes.add("Files"); 119 } else if (String utiType = utiTypeFromCocoaType(cocoaType)) 120 resultTypes.add(utiType); 121 else { 122 // No mapping, just pass the whole string though 123 resultTypes.add(cocoaType); 124 } 114 125 } 115 126 … … 121 132 // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner 122 133 123 NSString *cocoaType = cocoaTypeFrom MIMEType(type);134 NSString *cocoaType = cocoaTypeFromHTMLClipboardType(type); 124 135 if (cocoaType) 125 136 [m_pasteboard.get() setString:@"" forType:cocoaType]; … … 188 199 return String(); 189 200 190 NSString *cocoaType = cocoaTypeFrom MIMEType(type);201 NSString *cocoaType = cocoaTypeFromHTMLClipboardType(type); 191 202 NSString *cocoaValue = nil; 192 203 193 204 // Grab the value off the pasteboard corresponding to the cocoaType 194 205 if ([cocoaType isEqualToString:NSURLPboardType]) { 195 // "URL" and "text/url-list" both map to NSURLPboardType in cocoaTypeFrom MIMEType(), "URL" only wants the first URL206 // "URL" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "URL" only wants the first URL 196 207 bool onlyFirstURL = (type == "URL"); 197 208 NSArray *absoluteURLs = absoluteURLsFromPasteboard(m_pasteboard.get(), onlyFirstURL); … … 218 229 // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner 219 230 220 NSString *cocoaType = cocoaTypeFrom MIMEType(type);231 NSString *cocoaType = cocoaTypeFromHTMLClipboardType(type); 221 232 NSString *cocoaData = data; 222 233 … … 259 270 HashSet<String> result; 260 271 NSUInteger count = [types count]; 272 // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types 273 // and a second which adds all the extra types from the cocoa clipboard (which is Mac-only behavior). 261 274 for (NSUInteger i = 0; i < count; i++) { 262 275 NSString *pbType = [types objectAtIndex:i]; … … 264 277 continue; // skip this ancient type that gets auto-supplied by some system conversion 265 278 266 String str = MIMETypeFromCocoaType(pbType); 267 if (!result.contains(str)) 268 result.add(str); 269 } 279 addHTMLClipboardTypesForCocoaType(result, pbType); 280 } 281 270 282 return result; 271 283 }
Note: See TracChangeset
for help on using the changeset viewer.