Changeset 107844 in webkit
- Timestamp:
- Feb 15, 2012, 3:08:25 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/Source/WebCore/ChangeLog ¶
r107843 r107844 1 2012-02-15 Enrica Casucci <enrica@apple.com> 2 3 Refactor ClipboardMac class to use PlatformStrategies. 4 https://bugs.webkit.org/show_bug.cgi?id=78554 5 6 Reviewed by Anders Carlsson. 7 8 No new tests. No change in behavior. 9 10 * WebCore.exp.in: Added new exported methods of the PlatformPasteboard class 11 * editing/mac/EditorMac.mm: 12 (WebCore::Editor::newGeneralClipboard): Use name based pasteboard references. 13 * page/DragClient.h: 14 (WebCore::DragClient::declareAndWriteDragImage): Ditto. 15 * page/mac/EventHandlerMac.mm: 16 (WebCore::EventHandler::createDraggingClipboard): Ditto. 17 * platform/PasteboardStrategy.h: Added new methods to get a unique pasteboard name 18 and the pasteboard change count. 19 * platform/PlatformPasteboard.h: Ditto. 20 * platform/mac/ClipboardMac.h: 21 (WebCore::ClipboardMac::create): Using name based pasteboard. 22 (WebCore::ClipboardMac::pasteboardName): Replacing the old pasteboard() method. 23 * platform/mac/ClipboardMac.mm: All the methods below have been modified to avoid 24 using Objective-C types and direct access to NSPasteboard object. 25 (WebCore::Clipboard::create): 26 (WebCore::ClipboardMac::ClipboardMac): 27 (WebCore::ClipboardMac::hasData): 28 (WebCore::cocoaTypeFromHTMLClipboardType): 29 (WebCore::utiTypeFromCocoaType): 30 (WebCore::addHTMLClipboardTypesForCocoaType): 31 (WebCore::ClipboardMac::clearData): 32 (WebCore::ClipboardMac::clearAllData): 33 (WebCore::absoluteURLsFromPasteboardFilenames): 34 (WebCore::absoluteURLsFromPasteboard): 35 (WebCore::ClipboardMac::getData): 36 (WebCore::ClipboardMac::setData): 37 (WebCore::ClipboardMac::types): 38 (WebCore::ClipboardMac::files): 39 (WebCore::ClipboardMac::setDragImage): 40 (WebCore::ClipboardMac::writeRange): 41 (WebCore::ClipboardMac::writePlainText): 42 (WebCore::ClipboardMac::writeURL): 43 (WebCore::ClipboardMac::declareAndWriteDragImage): 44 * platform/mac/PasteboardMac.mm: 45 (WebCore::Pasteboard::writeClipboard): Using name based pasteboard reference. 46 * platform/mac/PlatformPasteboardMac.mm: 47 (WebCore::PlatformPasteboard::getPathnamesForType): Fixed to support NSArray and NString content. 48 (WebCore::PlatformPasteboard::changeCount): Added. 49 (WebCore::PlatformPasteboard::uniqueName): Added. 50 1 51 2012-02-15 Anders Carlsson <andersca@apple.com> 2 52 -
TabularUnified trunk/Source/WebCore/WebCore.exp.in ¶
r107793 r107844 560 560 __ZN7WebCore18PlatformPasteboard16setBufferForTypeEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS1_6StringE 561 561 __ZN7WebCore18PlatformPasteboard16setStringForTypeERKN3WTF6StringES4_ 562 __ZN7WebCore18PlatformPasteboard10uniqueNameEv 563 __ZNK7WebCore18PlatformPasteboard11changeCountEv 562 564 __ZN7WebCore18SearchPopupMenuMacC1EPNS_15PopupMenuClientE 563 565 __ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE -
TabularUnified trunk/Source/WebCore/editing/mac/EditorMac.mm ¶
r107606 r107844 38 38 #import "HTMLNames.h" 39 39 #import "Pasteboard.h" 40 #import "PasteboardStrategy.h" 41 #import "PlatformStrategies.h" 40 42 #import "RenderBlock.h" 41 43 #import "RuntimeApplicationChecks.h" … … 50 52 { 51 53 return ClipboardMac::create(Clipboard::CopyAndPaste, 52 policy == ClipboardWritable ? [NSPasteboard pasteboardWithUniqueName] : [NSPasteboard generalPasteboard], policy, frame);54 policy == ClipboardWritable ? platformStrategies()->pasteboardStrategy()->uniqueName() : String(NSGeneralPboard), policy, frame); 53 55 } 54 56 -
TabularUnified trunk/Source/WebCore/page/DragClient.h ¶
r105203 r107844 62 62 // Mac-specific helper function to allow access to web archives and NSPasteboard extras in WebKit. 63 63 // This is not abstract as that would require another #if PLATFORM(MAC) for the SVGImage client empty implentation. 64 virtual void declareAndWriteDragImage( NSPasteboard *, DOMElement*, NSURL *, NSString *, Frame*) { }64 virtual void declareAndWriteDragImage(const String&, DOMElement*, NSURL *, NSString *, Frame*) { } 65 65 #endif 66 66 -
TabularUnified trunk/Source/WebCore/page/mac/EventHandlerMac.mm ¶
r104773 r107844 42 42 #include "NotImplemented.h" 43 43 #include "Page.h" 44 #include "Pasteboard.h" 44 45 #include "PlatformEventFactoryMac.h" 45 46 #include "RenderWidget.h" … … 669 670 PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const 670 671 { 671 NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];672 672 // Must be done before ondragstart adds types and data to the pboard, 673 673 // also done for security, as it erases data from the last drag 674 [pasteboard declareTypes:[NSArray array] owner:nil]; 675 return ClipboardMac::create(Clipboard::DragAndDrop, pasteboard, ClipboardWritable, m_frame); 674 Pasteboard pasteboard(NSDragPboard); 675 pasteboard.clear(); 676 return ClipboardMac::create(Clipboard::DragAndDrop, String(NSDragPboard), ClipboardWritable, m_frame); 676 677 } 677 678 -
TabularUnified trunk/Source/WebCore/platform/PasteboardStrategy.h ¶
r107606 r107844 43 43 virtual void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) = 0; 44 44 virtual String stringForType(const String& pasteboardType, const String& pasteboardName) = 0; 45 virtual int changeCount(const String& pasteboardName) = 0; 46 virtual String uniqueName() = 0; 45 47 46 48 virtual void copy(const String& fromPasteboard, const String& toPasteboard) = 0; -
TabularUnified trunk/Source/WebCore/platform/PlatformPasteboard.h ¶
r107629 r107844 41 41 public: 42 42 PlatformPasteboard(const String& pasteboardName); 43 static String uniqueName(); 43 44 44 45 void getTypes(Vector<String>& types); … … 46 47 void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType); 47 48 String stringForType(const String& pasteboardType); 49 int changeCount() const; 48 50 49 51 void copy(const String& fromPasteboard); -
TabularUnified trunk/Source/WebCore/platform/mac/ClipboardMac.h ¶
r105203 r107844 42 42 WTF_MAKE_FAST_ALLOCATED; 43 43 public: 44 static PassRefPtr<ClipboardMac> create(ClipboardType clipboardType, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame* frame)44 static PassRefPtr<ClipboardMac> create(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame* frame) 45 45 { 46 return adoptRef(new ClipboardMac(clipboardType, pasteboard , policy, frame));46 return adoptRef(new ClipboardMac(clipboardType, pasteboardName, policy, frame)); 47 47 } 48 48 … … 73 73 // Methods for getting info in Cocoa's type system 74 74 NSImage *dragNSImage(NSPoint&) const; // loc converted from dragLoc, based on whole image size 75 NSPasteboard *pasteboard() { return m_pasteboard.get(); }75 const String& pasteboardName() { return m_pasteboardName; } 76 76 77 77 private: 78 ClipboardMac(ClipboardType, NSPasteboard *, ClipboardAccessPolicy, Frame*);78 ClipboardMac(ClipboardType, const String& pasteboardName, ClipboardAccessPolicy, Frame*); 79 79 80 80 void setDragImage(CachedImage*, Node*, const IntPoint&); 81 81 82 RetainPtr<NSPasteboard> m_pasteboard;82 String m_pasteboardName; 83 83 int m_changeCount; 84 84 Frame* m_frame; // used on the source side to generate dragging images -
TabularUnified trunk/Source/WebCore/platform/mac/ClipboardMac.mm ¶
r106872 r107844 37 37 #import "Page.h" 38 38 #import "Pasteboard.h" 39 #import "PasteboardStrategy.h" 40 #import "PlatformStrategies.h" 39 41 #import "RenderImage.h" 40 42 #import "ScriptExecutionContext.h" … … 47 49 PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData* dragData, Frame* frame) 48 50 { 49 return ClipboardMac::create(DragAndDrop, dragData->pasteboard(), policy, frame);50 } 51 52 ClipboardMac::ClipboardMac(ClipboardType clipboardType, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame *frame)51 return ClipboardMac::create(DragAndDrop, [dragData->pasteboard() name], policy, frame); 52 } 53 54 ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame *frame) 53 55 : Clipboard(policy, clipboardType) 54 , m_pasteboard (pasteboard)56 , m_pasteboardName(pasteboardName) 55 57 , m_frame(frame) 56 58 { 57 m_changeCount = [m_pasteboard.get() changeCount];59 m_changeCount = platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName); 58 60 } 59 61 … … 64 66 bool ClipboardMac::hasData() 65 67 { 66 return m_pasteboard && [m_pasteboard.get() types] && [[m_pasteboard.get() types] count] > 0; 68 Vector<String> types; 69 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); 70 return !types.isEmpty(); 67 71 } 68 72 69 static RetainPtr<NSString>cocoaTypeFromHTMLClipboardType(const String& type)73 static String cocoaTypeFromHTMLClipboardType(const String& type) 70 74 { 71 75 // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dom-datatransfer-setdata … … 79 83 // Ignore any trailing charset - JS strings are Unicode, which encapsulates the charset issue 80 84 if (qType == "text/plain" || qType.startsWith("text/plain;")) 81 return NSStringPboardType;85 return String(NSStringPboardType); 82 86 if (qType == "text/uri-list") 83 87 // special case because UTI doesn't work with Cocoa's URL type 84 return NSURLPboardType; // note special case in getData to read NSFilenamesType88 return String(NSURLPboardType); // note special case in getData to read NSFilenamesType 85 89 86 90 // Try UTI now 87 NSString *mimeType = qType;88 RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL));91 String mimeType = qType; 92 RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType.createCFString(), NULL)); 89 93 if (utiType) { 90 94 CFStringRef pbType = UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassNSPboardType); 91 95 if (pbType) 92 return (NSString *)pbType;96 return pbType; 93 97 } 94 98 95 99 // No mapping, just pass the whole string though 96 return (NSString *)qType;97 } 98 99 static String utiTypeFromCocoaType( NSString *type)100 { 101 RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL));100 return qType; 101 } 102 103 static String utiTypeFromCocoaType(const String& type) 104 { 105 RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, type.createCFString(), NULL)); 102 106 if (utiType) { 103 107 RetainPtr<CFStringRef> mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType)); … … 108 112 } 109 113 110 static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, NSString *cocoaType, NSPasteboard *pasteboard)114 static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName) 111 115 { 112 116 // UTI may not do these right, so make sure we get the right, predictable result 113 if ( [cocoaType isEqualToString:NSStringPboardType]) {117 if (cocoaType == String(NSStringPboardType)) { 114 118 resultTypes.add("text/plain"); 115 119 return; 116 120 } 117 if ( [cocoaType isEqualToString:NSURLPboardType]) {121 if (cocoaType == String(NSURLPboardType)) { 118 122 resultTypes.add("text/uri-list"); 119 123 return; 120 124 } 121 if ( [cocoaType isEqualToString:NSFilenamesPboardType]) {125 if (cocoaType == String(NSFilenamesPboardType)) { 122 126 // If file list is empty, add nothing. 123 127 // Note that there is a chance that the file list count could have changed since we grabbed the types array. 124 128 // However, this is not really an issue for us doing a sanity check here. 125 NSArray *fileList = [pasteboard propertyListForType:NSFilenamesPboardType]; 126 if ([fileList count]) { 129 Vector<String> fileList; 130 platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName); 131 if (!fileList.isEmpty()) { 127 132 // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa, 128 133 // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files' … … 148 153 // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner 149 154 150 if (RetainPtr<NSString> cocoaType = cocoaTypeFromHTMLClipboardType(type)) 151 [m_pasteboard.get() setString:@"" forType:cocoaType.get()]; 155 String cocoaType = cocoaTypeFromHTMLClipboardType(type); 156 if (!cocoaType.isEmpty()) 157 platformStrategies()->pasteboardStrategy()->setStringForType("", cocoaType, m_pasteboardName); 152 158 } 153 159 … … 159 165 // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner 160 166 161 [m_pasteboard.get() declareTypes:[NSArray array] owner:nil]; 162 } 163 164 static NSArray *absoluteURLsFromPasteboardFilenames(NSPasteboard* pasteboard, bool onlyFirstURL = false) 165 { 166 NSArray *fileList = [pasteboard propertyListForType:NSFilenamesPboardType]; 167 168 // FIXME: Why does this code need to guard against bad values on the pasteboard? 169 ASSERT(!fileList || [fileList isKindOfClass:[NSArray class]]); 170 if (!fileList || ![fileList isKindOfClass:[NSArray class]] || ![fileList count]) 171 return nil; 172 173 NSUInteger count = onlyFirstURL ? 1 : [fileList count]; 174 NSMutableArray *urls = [NSMutableArray array]; 175 for (NSUInteger i = 0; i < count; i++) { 176 NSString *string = [fileList objectAtIndex:i]; 177 178 ASSERT([string isKindOfClass:[NSString class]]); // Added to understand why this if code is here 179 if (![string isKindOfClass:[NSString class]]) 180 return nil; // Non-string object in the list, bail out! FIXME: When can this happen? 181 182 NSURL *url = [NSURL fileURLWithPath:string]; 183 [urls addObject:[url absoluteString]]; 167 Pasteboard pasteboard(m_pasteboardName); 168 pasteboard.clear(); 169 } 170 171 static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool onlyFirstURL = false) 172 { 173 Vector<String> fileList; 174 platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName); 175 176 if (fileList.isEmpty()) 177 return fileList; 178 179 size_t count = onlyFirstURL ? 1 : fileList.size(); 180 Vector<String> urls; 181 for (size_t i = 0; i < count; i++) { 182 NSURL *url = [NSURL fileURLWithPath:fileList[i]]; 183 urls.append(String([url absoluteString])); 184 184 } 185 185 return urls; 186 186 } 187 187 188 static NSArray *absoluteURLsFromPasteboard(NSPasteboard* pasteboard, bool onlyFirstURL = false)188 static Vector<String> absoluteURLsFromPasteboard(const String& pasteboardName, bool onlyFirstURL = false) 189 189 { 190 190 // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data 191 191 // or CoreFoundation will printf when there is not data of the corresponding type. 192 NSArray *availableTypes = [pasteboard types]; 192 Vector<String> availableTypes; 193 Vector<String> absoluteURLs; 194 platformStrategies()->pasteboardStrategy()->getTypes(availableTypes, pasteboardName); 193 195 194 196 // Try NSFilenamesPboardType because it contains a list 195 if ([availableTypes containsObject:NSFilenamesPboardType]) { 196 if (NSArray* absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboard, onlyFirstURL)) 197 if (availableTypes.contains(String(NSFilenamesPboardType))) { 198 absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL); 199 if (!absoluteURLs.isEmpty()) 197 200 return absoluteURLs; 198 201 } 199 202 200 203 // Fallback to NSURLPboardType (which is a single URL) 201 if ([availableTypes containsObject:NSURLPboardType]) { 202 if (NSURL *url = [NSURL URLFromPasteboard:pasteboard]) 203 return [NSArray arrayWithObject:[url absoluteString]]; 204 if (availableTypes.contains(String(NSURLPboardType))) { 205 platformStrategies()->pasteboardStrategy()->getPathnamesForType(absoluteURLs, String(NSURLPboardType), pasteboardName); 206 if (!absoluteURLs.isEmpty()) 207 return absoluteURLs; 204 208 } 205 209 206 210 // No file paths on the pasteboard, return nil 207 return nil;211 return Vector<String>(); 208 212 } 209 213 … … 214 218 return String(); 215 219 216 RetainPtr<NSString>cocoaType = cocoaTypeFromHTMLClipboardType(type);217 NSString *cocoaValue = nil;220 const String& cocoaType = cocoaTypeFromHTMLClipboardType(type); 221 String cocoaValue; 218 222 219 223 // Grab the value off the pasteboard corresponding to the cocoaType 220 if ( [cocoaType.get() isEqualToString:NSURLPboardType]) {224 if (cocoaType == String(NSURLPboardType)) { 221 225 // "url" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "url" only wants the first URL 222 226 bool onlyFirstURL = (equalIgnoringCase(type, "url")); 223 NSArray *absoluteURLs = absoluteURLsFromPasteboard(m_pasteboard.get(), onlyFirstURL); 224 cocoaValue = [absoluteURLs componentsJoinedByString:@"\n"]; 225 } else if ([cocoaType.get() isEqualToString:NSStringPboardType]) { 226 cocoaValue = [[m_pasteboard.get() stringForType:cocoaType.get()] precomposedStringWithCanonicalMapping]; 227 } else if (cocoaType) 228 cocoaValue = [m_pasteboard.get() stringForType:cocoaType.get()]; 227 Vector<String> absoluteURLs = absoluteURLsFromPasteboard(m_pasteboardName, onlyFirstURL); 228 for (size_t i = 0; i < absoluteURLs.size(); i++) 229 cocoaValue = i ? "\n" + absoluteURLs[i]: absoluteURLs[i]; 230 } else if (cocoaType == String(NSStringPboardType)) 231 cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName) precomposedStringWithCanonicalMapping]; 232 else if (!cocoaType.isEmpty()) 233 cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName); 229 234 230 235 // Enforce changeCount ourselves for security. We check after reading instead of before to be 231 236 // sure it doesn't change between our testing the change count and accessing the data. 232 if ( cocoaValue && m_changeCount == [m_pasteboard.get() changeCount]) {237 if (!cocoaValue.isEmpty() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) { 233 238 success = true; 234 239 return cocoaValue; … … 244 249 // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner 245 250 246 RetainPtr<NSString> cocoaType = cocoaTypeFromHTMLClipboardType(type); 247 NSString *cocoaData = data; 248 249 if ([cocoaType.get() isEqualToString:NSURLPboardType]) { 250 [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil]; 251 const String& cocoaType = cocoaTypeFromHTMLClipboardType(type); 252 String cocoaData = data; 253 254 if (cocoaType == String(NSURLPboardType)) { 255 Vector<String> types; 256 types.append(String(NSURLPboardType)); 257 258 platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); 259 platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, String(NSURLPboardType), m_pasteboardName); 251 260 NSURL *url = [[NSURL alloc] initWithString:cocoaData]; 252 [url writeToPasteboard:m_pasteboard.get()];253 261 254 262 if ([url isFileURL] && m_frame->document()->securityOrigin()->canLoadLocalResources()) { 255 [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; 256 NSArray *fileList = [NSArray arrayWithObject:[url path]]; 257 [m_pasteboard.get() setPropertyList:fileList forType:NSFilenamesPboardType]; 263 types.append(String(NSFilenamesPboardType)); 264 platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); 265 Vector<String> fileList; 266 fileList.append(String([url path])); 267 platformStrategies()->pasteboardStrategy()->setPathnamesForType(fileList, String(NSFilenamesPboardType), m_pasteboardName); 258 268 } 259 269 … … 262 272 } 263 273 264 if ( cocoaType) {274 if (!cocoaType.isEmpty()) { 265 275 // everything else we know of goes on the pboard as a string 266 [m_pasteboard.get() addTypes:[NSArray arrayWithObject:cocoaType.get()] owner:nil]; 267 return [m_pasteboard.get() setString:cocoaData forType:cocoaType.get()]; 276 Vector<String> types; 277 types.append(cocoaType); 278 platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); 279 platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, cocoaType, m_pasteboardName); 280 return true; 268 281 } 269 282 … … 276 289 return HashSet<String>(); 277 290 278 NSArray *types = [m_pasteboard.get() types]; 291 Vector<String> types; 292 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); 279 293 280 294 // Enforce changeCount ourselves for security. We check after reading instead of before to be 281 295 // sure it doesn't change between our testing the change count and accessing the data. 282 if (m_changeCount != [m_pasteboard.get() changeCount])296 if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) 283 297 return HashSet<String>(); 284 298 285 299 HashSet<String> result; 286 NSUInteger count = [types count];287 300 // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types 288 301 // and a second which adds all the extra types from the cocoa clipboard (which is Mac-only behavior). 289 for (NSUInteger i = 0; i < count; i++) { 290 NSString *pbType = [types objectAtIndex:i]; 291 if ([pbType isEqualToString:@"NeXT plain ascii pasteboard type"]) 302 for (size_t i = 0; i < types.size(); i++) { 303 if (types[i] == "NeXT plain ascii pasteboard type") 292 304 continue; // skip this ancient type that gets auto-supplied by some system conversion 293 305 294 addHTMLClipboardTypesForCocoaType(result, pbType, m_pasteboard.get());306 addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName); 295 307 } 296 308 … … 306 318 return FileList::create(); 307 319 308 NSArray *absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboard.get()); 309 NSUInteger count = [absoluteURLs count]; 320 Vector<String> absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName); 310 321 311 322 RefPtr<FileList> fileList = FileList::create(); 312 for ( NSUInteger x = 0; x < count; x++) {313 NSURL *absoluteURL = [NSURL URLWithString: [absoluteURLs objectAtIndex:x]];323 for (size_t i = 0; i < absoluteURLs.size(); i++) { 324 NSURL *absoluteURL = [NSURL URLWithString:absoluteURLs[i]]; 314 325 ASSERT([absoluteURL isFileURL]); 315 326 fileList->append(File::create([absoluteURL path])); … … 342 353 m_dragImageElement = node; 343 354 344 if (dragStarted() && m_changeCount == [m_pasteboard.get() changeCount]) {355 if (dragStarted() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) { 345 356 NSPoint cocoaLoc; 346 357 NSImage* cocoaImage = dragNSImage(cocoaLoc); … … 368 379 ASSERT(range); 369 380 ASSERT(frame); 370 Pasteboard pasteboard( [m_pasteboard.get() name]);381 Pasteboard pasteboard(m_pasteboardName); 371 382 pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame); 372 383 } … … 374 385 void ClipboardMac::writePlainText(const String& text) 375 386 { 376 Pasteboard pasteboard( [m_pasteboard.get() name]);387 Pasteboard pasteboard(m_pasteboardName); 377 388 pasteboard.writePlainText(text); 378 389 } … … 381 392 { 382 393 ASSERT(frame); 383 ASSERT(m_pasteboard );384 Pasteboard pasteboard( [m_pasteboard.get() name]);394 ASSERT(m_pasteboardName); 395 Pasteboard pasteboard(m_pasteboardName); 385 396 pasteboard.writeURL(url, title, frame); 386 397 } … … 391 402 ASSERT(frame); 392 403 if (Page* page = frame->page()) 393 page->dragController()->client()->declareAndWriteDragImage(m_pasteboard .get(), kit(element), url, title, frame);404 page->dragController()->client()->declareAndWriteDragImage(m_pasteboardName, kit(element), url, title, frame); 394 405 } 395 406 #endif // ENABLE(DRAG_SUPPORT) -
TabularUnified trunk/Source/WebCore/platform/mac/PasteboardMac.mm ¶
r107770 r107844 298 298 void Pasteboard::writeClipboard(Clipboard* clipboard) 299 299 { 300 // FIXME: this is the last access to NSPasteboard. It will removed when the ClipboardMac 301 // class is refactored. 302 NSPasteboard* pasteboard = static_cast<ClipboardMac*>(clipboard)->pasteboard(); 303 platformStrategies()->pasteboardStrategy()->copy([pasteboard name], m_pasteboardName); 300 platformStrategies()->pasteboardStrategy()->copy(static_cast<ClipboardMac*>(clipboard)->pasteboardName(), m_pasteboardName); 304 301 } 305 302 -
TabularUnified trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm ¶
r107753 r107844 51 51 { 52 52 NSArray* paths = [m_pasteboard.get() propertyListForType:pasteboardType]; 53 if ([paths isKindOfClass:[NSString class]]) { 54 pathnames.append((NSString *)paths); 55 return; 56 } 53 57 for (NSUInteger i = 0; i < [paths count]; i++) 54 58 pathnames.append([paths objectAtIndex:i]); … … 58 62 { 59 63 return [m_pasteboard.get() stringForType:pasteboardType]; 64 } 65 66 int PlatformPasteboard::changeCount() const 67 { 68 return [m_pasteboard.get() changeCount]; 69 } 70 71 String PlatformPasteboard::uniqueName() 72 { 73 return [[NSPasteboard pasteboardWithUniqueName] name]; 60 74 } 61 75 -
TabularUnified trunk/Source/WebKit/mac/ChangeLog ¶
r107832 r107844 1 2012-02-15 Enrica Casucci <enrica@apple.com> 2 3 Refactor ClipboardMac class to use PlatformStrategies. 4 https://bugs.webkit.org/show_bug.cgi?id=78554 5 6 Reviewed by Anders Carlsson. 7 8 * WebCoreSupport/WebDragClient.h: Changed methods signature to use name based pasteboard. 9 * WebCoreSupport/WebDragClient.mm: Ditto. 10 (WebDragClient::willPerformDragSourceAction): 11 (WebDragClient::startDrag): 12 (WebDragClient::declareAndWriteDragImage): 13 * WebCoreSupport/WebPlatformStrategies.h: Added new methods. 14 * WebCoreSupport/WebPlatformStrategies.mm: 15 (WebPlatformStrategies::changeCount): 16 (WebPlatformStrategies::uniqueName): 17 1 18 2012-02-15 Sadrul Habib Chowdhury <sadrul@chromium.org> 2 19 -
TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h ¶
r95847 r107844 37 37 virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) OVERRIDE; 38 38 virtual void startDrag(WebCore::DragImageRef, const WebCore::IntPoint& dragPos, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag) OVERRIDE; 39 virtual void declareAndWriteDragImage( NSPasteboard*, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE;39 virtual void declareAndWriteDragImage(const String& pasteboardName, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE; 40 40 private: 41 41 WebView* m_webView; -
TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm ¶
r101414 r107844 84 84 { 85 85 ASSERT(clipboard); 86 [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:mouseDownPoint withPasteboard: static_cast<WebCore::ClipboardMac*>(clipboard)->pasteboard()];86 [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:mouseDownPoint withPasteboard:[NSPasteboard pasteboardWithName:static_cast<WebCore::ClipboardMac*>(clipboard)->pasteboardName()]]; 87 87 } 88 88 … … 101 101 102 102 [topHTMLView _stopAutoscrollTimer]; 103 NSPasteboard *pasteboard = static_cast<ClipboardMac*>(clipboard)->pasteboard();103 NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:static_cast<ClipboardMac*>(clipboard)->pasteboardName()]; 104 104 105 105 NSImage *dragNSImage = dragImage.get(); … … 121 121 } 122 122 123 void WebDragClient::declareAndWriteDragImage( NSPasteboard* pasteboard, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame)123 void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame) 124 124 { 125 ASSERT(pasteboard );125 ASSERT(pasteboardName); 126 126 ASSERT(element); 127 127 WebHTMLView *source = getTopHTMLView(frame); 128 128 WebArchive *archive = [element webArchive]; 129 129 130 [ pasteboard_web_declareAndWriteDragImageForElement:element URL:URL title:title archive:archive source:source];130 [[NSPasteboard pasteboardWithName:pasteboardName] _web_declareAndWriteDragImageForElement:element URL:URL title:title archive:archive source:source]; 131 131 } 132 132 -
TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h ¶
r107606 r107844 62 62 virtual void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) OVERRIDE; 63 63 virtual String stringForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE; 64 virtual int changeCount(const String& pasteboardName) OVERRIDE; 65 virtual String uniqueName() OVERRIDE; 64 66 65 67 virtual void copy(const String& fromPasteboard, const String& toPasteboard) OVERRIDE; -
TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm ¶
r107606 r107844 128 128 } 129 129 130 int WebPlatformStrategies::changeCount(const String &pasteboardName) 131 { 132 PlatformPasteboard pasteboard(pasteboardName); 133 return pasteboard.changeCount(); 134 } 135 136 String WebPlatformStrategies::uniqueName() 137 { 138 return PlatformPasteboard::uniqueName(); 139 } 140 130 141 void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) 131 142 { -
TabularUnified trunk/Source/WebKit2/ChangeLog ¶
r107832 r107844 1 2012-02-15 Enrica Casucci <enrica@apple.com> 2 3 Refactor ClipboardMac class to use PlatformStrategies. 4 https://bugs.webkit.org/show_bug.cgi?id=78554 5 6 Reviewed by Anders Carlsson. 7 8 * WebProcess/WebCoreSupport/WebDragClient.h: Changed method signature to reference 9 the pasteboard by name. 10 * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: Added new methods. 11 (WebKit::WebPlatformStrategies::changeCount): 12 (WebKit::WebPlatformStrategies::uniqueName): 13 * WebProcess/WebCoreSupport/WebPlatformStrategies.h: Ditto. 14 * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm: 15 (WebKit::WebDragClient::declareAndWriteDragImage): Changed method signature to reference 16 the pasteboard by name. 17 1 18 2012-02-15 Sadrul Habib Chowdhury <sadrul@chromium.org> 2 19 -
TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h ¶
r105203 r107844 54 54 55 55 #if PLATFORM(MAC) 56 virtual void declareAndWriteDragImage( NSPasteboard*, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE;56 virtual void declareAndWriteDragImage(const String& pasteboardName, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE; 57 57 #endif 58 58 -
TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp ¶
r107606 r107844 165 165 } 166 166 167 int WebPlatformStrategies::changeCount(const WTF::String &pasteboardName) 168 { 169 PlatformPasteboard pasteboard(pasteboardName); 170 return pasteboard.changeCount(); 171 } 172 173 String WebPlatformStrategies::uniqueName() 174 { 175 return PlatformPasteboard::uniqueName(); 176 } 177 167 178 void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) 168 179 { -
TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h ¶
r107606 r107844 68 68 virtual void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) OVERRIDE; 69 69 virtual String stringForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE; 70 virtual int changeCount(const String& pasteboardName) OVERRIDE; 71 virtual String uniqueName() OVERRIDE; 70 72 71 73 virtual void copy(const String& fromPasteboard, const String& toPasteboard) OVERRIDE; -
TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm ¶
r107267 r107844 126 126 } 127 127 128 void WebDragClient::declareAndWriteDragImage( NSPasteboard *pasteboard, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*)128 void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*) 129 129 { 130 130 ASSERT(element); 131 ASSERT(pasteboard && pasteboard == [NSPasteboard pasteboardWithName:NSDragPboard]);131 ASSERT(pasteboardName == String(NSDragPboard)); 132 132 133 133 Element* coreElement = core(element); … … 156 156 m_filePromiseOwner.adoptNS([(WKPasteboardFilePromiseOwner *)[WKPasteboardFilePromiseOwner alloc] initWithSource:m_pasteboardOwner.get()]); 157 157 158 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:pasteboardName]; 158 159 [pasteboard declareTypes:types.get() owner:m_pasteboardOwner.leakRef()]; 159 160
Note:
See TracChangeset
for help on using the changeset viewer.