Changeset 106872 in webkit
- Timestamp:
- Feb 6, 2012, 4:34:18 PM (15 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
platform/Pasteboard.h (modified) (3 diffs)
-
platform/mac/ClipboardMac.mm (modified) (2 diffs)
-
platform/mac/DragDataMac.mm (modified) (3 diffs)
-
platform/mac/PasteboardMac.mm (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r106870 r106872 1 2012-02-06 Enrica Casucci <enrica@apple.com> 2 3 Refactor Mac platform implementation of the Pasteboard class. 4 https://bugs.webkit.org/show_bug.cgi?id=77567 5 6 The goal of this change is to remove the majority of the methods in 7 the class interface that are Mac specific. 8 writeSelectionForTypes has been left to support OS X services. 9 Some of the methods have been turned into static functions. 10 The method asURL was being used only by the DragData class and its 11 implementation has been moved there. 12 This is a first step in the direction of removing NSPasteboard access from 13 the WebProcess for WebKit2 (https://bugs.webkit.org/show_bug.cgi?id=77259) 14 leaving the WebKit1 behavior unchanged. 15 16 Reviewed by Alexey Proskuryakov. 17 18 No new tests. No changes in behavior. 19 20 * platform/Pasteboard.h: Removed most of the Mac specific methods. 21 * platform/mac/ClipboardMac.mm: 22 (WebCore::ClipboardMac::writeRange): 23 (WebCore::ClipboardMac::writeURL): 24 * platform/mac/DragDataMac.mm: 25 (WebCore::DragData::asURL): Moved code from PasteboardMac.mm. Removed FIXME 26 because we only want to handle the case of single file, otherwise the user 27 doesn't know which of the files has been chosen. 28 * platform/mac/PasteboardMac.mm: 29 (WebCore::writeURLForTypes): 30 (WebCore::Pasteboard::writeURL): 31 (WebCore::writeFileWrapperAsRTFDAttachment): Now a static function. 32 (WebCore::Pasteboard::writeImage): 33 (WebCore::documentFragmentWithImageResource): Ditto. 34 (WebCore::documentFragmentWithRTF): Ditto. 35 (WebCore::Pasteboard::documentFragment): 36 1 37 2012-02-06 James Robinson <jamesr@chromium.org> 2 38 -
trunk/Source/WebCore/platform/Pasteboard.h
r106248 r106872 81 81 public: 82 82 #if PLATFORM(MAC) 83 // This is required to support OS X services. 83 84 void writeSelectionForTypes(NSArray* pasteboardTypes, Range* selectedRange, bool canSmartCopyOrDelete, Frame*); 84 void writeURLForTypes(NSArray* types, const KURL&, const String& titleStr, Frame*);85 86 85 Pasteboard(const String& pasteboardName); 87 86 #endif … … 92 91 void writeURL(const KURL&, const String&, Frame* = 0); 93 92 void writeImage(Node*, const KURL&, const String& title); 94 #if PLATFORM(MAC)95 void writeFileWrapperAsRTFDAttachment(NSFileWrapper*);96 String asURL(Frame*);97 #endif98 93 void writeClipboard(Clipboard*); 99 94 void clear(); … … 116 111 #if PLATFORM(MAC) 117 112 RetainPtr<NSPasteboard> m_pasteboard; 118 PassRefPtr<DocumentFragment> documentFragmentWithImageResource(Frame* frame, PassRefPtr<ArchiveResource> resource);119 PassRefPtr<DocumentFragment> documentFragmentWithRtf(Frame* frame, NSString* pboardType);120 NSURL *getBestURL(Frame *);121 113 #endif 122 114 -
trunk/Source/WebCore/platform/mac/ClipboardMac.mm
r106248 r106872 369 369 ASSERT(frame); 370 370 Pasteboard pasteboard([m_pasteboard.get() name]); 371 pasteboard.writeSelection ForTypes(nil,range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame);371 pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame); 372 372 } 373 373 … … 383 383 ASSERT(m_pasteboard); 384 384 Pasteboard pasteboard([m_pasteboard.get() name]); 385 pasteboard.writeURL ForTypes(nil,url, title, frame);385 pasteboard.writeURL(url, title, frame); 386 386 } 387 387 -
trunk/Source/WebCore/platform/mac/DragDataMac.mm
r106248 r106872 32 32 #import "DOMDocumentFragment.h" 33 33 #import "DOMDocumentFragmentInternal.h" 34 #import "Editor.h" 35 #import "EditorClient.h" 36 #import "Frame.h" 34 37 #import "MIMETypeRegistry.h" 35 38 #import "Pasteboard.h" … … 148 151 return !asURL(frame, filenamePolicy).isEmpty(); 149 152 } 150 153 151 154 String DragData::asURL(Frame* frame, FilenameConversionPolicy filenamePolicy, String* title) const 152 155 { … … 158 161 *title = URLTitleString; 159 162 } 163 164 NSArray *types = [m_pasteboard.get() types]; 165 166 // FIXME: using the editorClient to call into WebKit, for now, since 167 // calling webkit_canonicalize from WebCore involves migrating a sizable amount of 168 // helper code that should either be done in a separate patch or figured out in another way. 169 170 if ([types containsObject:NSURLPboardType]) { 171 NSURL *URLFromPasteboard = [NSURL URLFromPasteboard:m_pasteboard.get()]; 172 NSString *scheme = [URLFromPasteboard scheme]; 173 if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]) { 174 return [frame->editor()->client()->canonicalizeURL(URLFromPasteboard) absoluteString]; 175 } 176 } 177 178 if ([types containsObject:NSStringPboardType]) { 179 NSString *URLString = [m_pasteboard.get() stringForType:NSStringPboardType]; 180 NSURL *URL = frame->editor()->client()->canonicalizeURLString(URLString); 181 if (URL) 182 return [URL absoluteString]; 183 } 184 185 if ([types containsObject:NSFilenamesPboardType]) { 186 NSArray *files = [m_pasteboard.get() propertyListForType:NSFilenamesPboardType]; 187 if ([files count] == 1) { 188 NSString *file = [files objectAtIndex:0]; 189 BOOL isDirectory; 190 if ([[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDirectory] && isDirectory) 191 return String(); 192 return [frame->editor()->client()->canonicalizeURL([NSURL fileURLWithPath:file]) absoluteString]; 193 } 194 } 195 196 return String(); 197 } 198 199 PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range> range, bool allowPlainText, bool& chosePlainText) const 200 { 160 201 Pasteboard pasteboard([m_pasteboard.get() name]); 161 return pasteboard.asURL(frame);162 }163 164 PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range> range, bool allowPlainText, bool& chosePlainText) const165 {166 Pasteboard pasteboard([m_pasteboard.get() name]);167 202 168 203 return pasteboard.documentFragment(frame, range, allowPlainText, chosePlainText); -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r106248 r106872 211 211 } 212 212 213 void Pasteboard::writeURLForTypes(NSArray* types, const KURL& url, const String& titleStr, Frame* frame) 214 { 215 if (!WebArchivePboardType) 216 Pasteboard::generalPasteboard(); // Initializes pasteboard types. 217 218 if (!types) { 219 types = writableTypesForURL(); 220 [m_pasteboard.get() declareTypes:types owner:nil]; 221 } 213 static void writeURLForTypes(NSArray* types, NSPasteboard* pasteboard, const KURL& url, const String& titleStr, Frame* frame) 214 { 215 [pasteboard declareTypes:types owner:nil]; 222 216 223 217 ASSERT(!url.isEmpty()); … … 234 228 235 229 if ([types containsObject:WebURLsWithTitlesPboardType]) 236 [ m_pasteboard.get()setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:userVisibleString],230 [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:userVisibleString], 237 231 [NSArray arrayWithObject:(NSString*)titleStr.stripWhiteSpace()], 238 232 nil] 239 233 forType:WebURLsWithTitlesPboardType]; 240 234 if ([types containsObject:NSURLPboardType]) 241 [cocoaURL writeToPasteboard: m_pasteboard.get()];235 [cocoaURL writeToPasteboard:pasteboard]; 242 236 if ([types containsObject:WebURLPboardType]) 243 [ m_pasteboard.get()setString:userVisibleString forType:WebURLPboardType];237 [pasteboard setString:userVisibleString forType:WebURLPboardType]; 244 238 if ([types containsObject:WebURLNamePboardType]) 245 [ m_pasteboard.get()setString:title forType:WebURLNamePboardType];239 [pasteboard setString:title forType:WebURLNamePboardType]; 246 240 if ([types containsObject:NSStringPboardType]) 247 [ m_pasteboard.get()setString:userVisibleString forType:NSStringPboardType];241 [pasteboard setString:userVisibleString forType:NSStringPboardType]; 248 242 } 249 243 250 244 void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) 251 245 { 252 writeURLForTypes( nil, url, titleStr, frame);246 writeURLForTypes(writableTypesForURL(), m_pasteboard.get(), url, titleStr, frame); 253 247 } 254 248 … … 266 260 } 267 261 268 void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper)262 static void writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper, NSPasteboard* pasteboard) 269 263 { 270 264 NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrapper]; … … 274 268 275 269 NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:nil]; 276 [ m_pasteboard.get()setData:RTFDData forType:NSRTFDPboardType];270 [pasteboard setData:RTFDData forType:NSRTFDPboardType]; 277 271 } 278 272 … … 294 288 return; 295 289 296 NSArray* types = writableTypesForImage(); 297 [m_pasteboard.get() declareTypes:types owner:nil]; 298 writeURLForTypes(types, cocoaURL, nsStringNilIfEmpty(title), frame); 290 writeURLForTypes(writableTypesForImage(), m_pasteboard.get(), cocoaURL, nsStringNilIfEmpty(title), frame); 299 291 300 292 Image* image = cachedImage->imageForRenderer(renderer); … … 306 298 ASSERT(MIMETypeRegistry::isSupportedImageResourceMIMEType(MIMEType)); 307 299 308 writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, cocoaURL) );300 writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, cocoaURL), m_pasteboard.get()); 309 301 } 310 302 … … 366 358 } 367 359 368 PassRefPtr<DocumentFragment> Pasteboard::documentFragmentWithImageResource(Frame* frame, PassRefPtr<ArchiveResource> resource)360 static PassRefPtr<DocumentFragment> documentFragmentWithImageResource(Frame* frame, PassRefPtr<ArchiveResource> resource) 369 361 { 370 362 if (DocumentLoader* loader = frame->loader()->documentLoader()) … … 386 378 } 387 379 388 PassRefPtr<DocumentFragment> Pasteboard::documentFragmentWithRtf(Frame* frame, NSString* pboardType)380 static PassRefPtr<DocumentFragment> documentFragmentWithRTF(Frame* frame, NSString *pasteboardType, NSPasteboard *pasteboard) 389 381 { 390 382 if (!frame || !frame->document() || !frame->document()->isHTMLDocument()) … … 392 384 393 385 NSAttributedString *string = nil; 394 if (p boardType == NSRTFDPboardType)395 string = [[NSAttributedString alloc] initWithRTFD:[ m_pasteboard.get()dataForType:NSRTFDPboardType] documentAttributes:NULL];386 if (pasteboardType == NSRTFDPboardType) 387 string = [[NSAttributedString alloc] initWithRTFD:[pasteboard dataForType:NSRTFDPboardType] documentAttributes:NULL]; 396 388 if (string == nil) 397 string = [[NSAttributedString alloc] initWithRTF:[ m_pasteboard.get()dataForType:NSRTFPboardType] documentAttributes:NULL];389 string = [[NSAttributedString alloc] initWithRTF:[pasteboard dataForType:NSRTFPboardType] documentAttributes:NULL]; 398 390 if (string == nil) 399 391 return nil; … … 431 423 432 424 return URL; 433 }434 435 NSURL *Pasteboard::getBestURL(Frame* frame)436 {437 NSArray *types = [m_pasteboard.get() types];438 439 // FIXME: using the editorClient to call into webkit, for now, since440 // calling webkit_canonicalize from WebCore involves migrating a sizable amount of441 // helper code that should either be done in a separate patch or figured out in another way.442 443 if ([types containsObject:NSURLPboardType]) {444 NSURL *URLFromPasteboard = [NSURL URLFromPasteboard:m_pasteboard.get()];445 NSString *scheme = [URLFromPasteboard scheme];446 if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]) {447 return frame->editor()->client()->canonicalizeURL(URLFromPasteboard);448 }449 }450 451 if ([types containsObject:NSStringPboardType]) {452 NSString *URLString = [m_pasteboard.get() stringForType:NSStringPboardType];453 NSURL *URL = frame->editor()->client()->canonicalizeURLString(URLString);454 if (URL)455 return URL;456 }457 458 if ([types containsObject:NSFilenamesPboardType]) {459 NSArray *files = [m_pasteboard.get() propertyListForType:NSFilenamesPboardType];460 // FIXME: Maybe it makes more sense to allow multiple files and only use the first one?461 if ([files count] == 1) {462 NSString *file = [files objectAtIndex:0];463 BOOL isDirectory;464 if ([[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDirectory] && isDirectory)465 return nil;466 return frame->editor()->client()->canonicalizeURL([NSURL fileURLWithPath:file]);467 }468 }469 470 return nil;471 }472 473 String Pasteboard::asURL(Frame* frame)474 {475 return [getBestURL(frame) absoluteString];476 425 } 477 426 … … 541 490 542 491 if ([types containsObject:NSRTFDPboardType] && 543 (fragment = documentFragmentWithR tf(frame, NSRTFDPboardType)))492 (fragment = documentFragmentWithRTF(frame, NSRTFDPboardType, m_pasteboard.get()))) 544 493 return fragment.release(); 545 494 546 495 if ([types containsObject:NSRTFPboardType] && 547 (fragment = documentFragmentWithR tf(frame, NSRTFPboardType)))496 (fragment = documentFragmentWithRTF(frame, NSRTFPboardType, m_pasteboard.get()))) 548 497 return fragment.release(); 549 498
Note:
See TracChangeset
for help on using the changeset viewer.