⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 106872 in webkit


Ignore:
Timestamp:
Feb 6, 2012, 4:34:18 PM (15 years ago)
Author:
enrica@apple.com
Message:

Refactor Mac platform implementation of the Pasteboard class.
https://bugs.webkit.org/show_bug.cgi?id=77567

The goal of this change is to remove the majority of the methods in
the class interface that are Mac specific.
writeSelectionForTypes has been left to support OS X services.
Some of the methods have been turned into static functions.
The method asURL was being used only by the DragData class and its
implementation has been moved there.
This is a first step in the direction of removing NSPasteboard access from
the WebProcess for WebKit2 (https://bugs.webkit.org/show_bug.cgi?id=77259)
leaving the WebKit1 behavior unchanged.

Reviewed by Alexey Proskuryakov.

No new tests. No changes in behavior.

  • platform/Pasteboard.h: Removed most of the Mac specific methods.
  • platform/mac/ClipboardMac.mm:

(WebCore::ClipboardMac::writeRange):
(WebCore::ClipboardMac::writeURL):

  • platform/mac/DragDataMac.mm:

(WebCore::DragData::asURL): Moved code from PasteboardMac.mm. Removed FIXME
because we only want to handle the case of single file, otherwise the user
doesn't know which of the files has been chosen.

  • platform/mac/PasteboardMac.mm:

(WebCore::writeURLForTypes):
(WebCore::Pasteboard::writeURL):
(WebCore::writeFileWrapperAsRTFDAttachment): Now a static function.
(WebCore::Pasteboard::writeImage):
(WebCore::documentFragmentWithImageResource): Ditto.
(WebCore::documentFragmentWithRTF): Ditto.
(WebCore::Pasteboard::documentFragment):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106870 r106872  
     12012-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
    1372012-02-06  James Robinson  <jamesr@chromium.org>
    238
  • trunk/Source/WebCore/platform/Pasteboard.h

    r106248 r106872  
    8181public:
    8282#if PLATFORM(MAC)
     83    // This is required to support OS X services.
    8384    void writeSelectionForTypes(NSArray* pasteboardTypes, Range* selectedRange, bool canSmartCopyOrDelete, Frame*);
    84     void writeURLForTypes(NSArray* types, const KURL&, const String& titleStr, Frame*);
    85 
    8685    Pasteboard(const String& pasteboardName);
    8786#endif
     
    9291    void writeURL(const KURL&, const String&, Frame* = 0);
    9392    void writeImage(Node*, const KURL&, const String& title);
    94 #if PLATFORM(MAC)
    95     void writeFileWrapperAsRTFDAttachment(NSFileWrapper*);
    96     String asURL(Frame*);
    97 #endif
    9893    void writeClipboard(Clipboard*);
    9994    void clear();
     
    116111#if PLATFORM(MAC)
    117112    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 *);
    121113#endif
    122114
  • trunk/Source/WebCore/platform/mac/ClipboardMac.mm

    r106248 r106872  
    369369    ASSERT(frame);
    370370    Pasteboard pasteboard([m_pasteboard.get() name]);
    371     pasteboard.writeSelectionForTypes(nil, range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame);
     371    pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame);
    372372}
    373373
     
    383383    ASSERT(m_pasteboard);
    384384    Pasteboard pasteboard([m_pasteboard.get() name]);
    385     pasteboard.writeURLForTypes(nil, url, title, frame);
     385    pasteboard.writeURL(url, title, frame);
    386386}
    387387   
  • trunk/Source/WebCore/platform/mac/DragDataMac.mm

    r106248 r106872  
    3232#import "DOMDocumentFragment.h"
    3333#import "DOMDocumentFragmentInternal.h"
     34#import "Editor.h"
     35#import "EditorClient.h"
     36#import "Frame.h"
    3437#import "MIMETypeRegistry.h"
    3538#import "Pasteboard.h"
     
    148151    return !asURL(frame, filenamePolicy).isEmpty();
    149152}
    150    
     153
    151154String DragData::asURL(Frame* frame, FilenameConversionPolicy filenamePolicy, String* title) const
    152155{
     
    158161            *title = URLTitleString;
    159162    }
     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
     199PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range> range, bool allowPlainText, bool& chosePlainText) const
     200{
    160201    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) const
    165 {
    166     Pasteboard pasteboard([m_pasteboard.get() name]);
    167202   
    168203    return pasteboard.documentFragment(frame, range, allowPlainText, chosePlainText);
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r106248 r106872  
    211211}
    212212
    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     }
     213static void writeURLForTypes(NSArray* types, NSPasteboard* pasteboard, const KURL& url, const String& titleStr, Frame* frame)
     214{
     215    [pasteboard declareTypes:types owner:nil];
    222216   
    223217    ASSERT(!url.isEmpty());
     
    234228       
    235229    if ([types containsObject:WebURLsWithTitlesPboardType])
    236         [m_pasteboard.get() setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:userVisibleString],
     230        [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:userVisibleString],
    237231                                     [NSArray arrayWithObject:(NSString*)titleStr.stripWhiteSpace()],
    238232                                     nil]
    239233                            forType:WebURLsWithTitlesPboardType];
    240234    if ([types containsObject:NSURLPboardType])
    241         [cocoaURL writeToPasteboard:m_pasteboard.get()];
     235        [cocoaURL writeToPasteboard:pasteboard];
    242236    if ([types containsObject:WebURLPboardType])
    243         [m_pasteboard.get() setString:userVisibleString forType:WebURLPboardType];
     237        [pasteboard setString:userVisibleString forType:WebURLPboardType];
    244238    if ([types containsObject:WebURLNamePboardType])
    245         [m_pasteboard.get() setString:title forType:WebURLNamePboardType];
     239        [pasteboard setString:title forType:WebURLNamePboardType];
    246240    if ([types containsObject:NSStringPboardType])
    247         [m_pasteboard.get() setString:userVisibleString forType:NSStringPboardType];
     241        [pasteboard setString:userVisibleString forType:NSStringPboardType];
    248242}
    249243   
    250244void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame)
    251245{
    252     writeURLForTypes(nil, url, titleStr, frame);
     246    writeURLForTypes(writableTypesForURL(), m_pasteboard.get(), url, titleStr, frame);
    253247}
    254248
     
    266260}
    267261
    268 void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper)
     262static void writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper, NSPasteboard* pasteboard)
    269263{
    270264    NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrapper];
     
    274268   
    275269    NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:nil];
    276     [m_pasteboard.get() setData:RTFDData forType:NSRTFDPboardType];
     270    [pasteboard setData:RTFDData forType:NSRTFDPboardType];
    277271}
    278272
     
    294288        return;
    295289
    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);
    299291   
    300292    Image* image = cachedImage->imageForRenderer(renderer);
     
    306298    ASSERT(MIMETypeRegistry::isSupportedImageResourceMIMEType(MIMEType));
    307299
    308     writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, cocoaURL));
     300    writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, cocoaURL), m_pasteboard.get());
    309301}
    310302
     
    366358}
    367359   
    368 PassRefPtr<DocumentFragment> Pasteboard::documentFragmentWithImageResource(Frame* frame, PassRefPtr<ArchiveResource> resource)
     360static PassRefPtr<DocumentFragment> documentFragmentWithImageResource(Frame* frame, PassRefPtr<ArchiveResource> resource)
    369361{
    370362    if (DocumentLoader* loader = frame->loader()->documentLoader())
     
    386378}
    387379
    388 PassRefPtr<DocumentFragment> Pasteboard::documentFragmentWithRtf(Frame* frame, NSString* pboardType)
     380static PassRefPtr<DocumentFragment> documentFragmentWithRTF(Frame* frame, NSString *pasteboardType, NSPasteboard *pasteboard)
    389381{
    390382    if (!frame || !frame->document() || !frame->document()->isHTMLDocument())
     
    392384
    393385    NSAttributedString *string = nil;
    394     if (pboardType == 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];
    396388    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];
    398390    if (string == nil)
    399391        return nil;
     
    431423
    432424    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, since
    440     // calling webkit_canonicalize from WebCore involves migrating a sizable amount of
    441     // 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];
    476425}
    477426
     
    541490
    542491    if ([types containsObject:NSRTFDPboardType] &&
    543         (fragment = documentFragmentWithRtf(frame, NSRTFDPboardType)))
     492        (fragment = documentFragmentWithRTF(frame, NSRTFDPboardType, m_pasteboard.get())))
    544493       return fragment.release();
    545494
    546495    if ([types containsObject:NSRTFPboardType] &&
    547         (fragment = documentFragmentWithRtf(frame, NSRTFPboardType)))
     496        (fragment = documentFragmentWithRTF(frame, NSRTFPboardType, m_pasteboard.get())))
    548497        return fragment.release();
    549498
Note: See TracChangeset for help on using the changeset viewer.