Changeset 107844 in webkit


Ignore:
Timestamp:
Feb 15, 2012, 3:08:25 PM (13 years ago)
Author:
enrica@apple.com
Message:

Refactor ClipboardMac class to use PlatformStrategies.
https://bugs.webkit.org/show_bug.cgi?id=78554

Reviewed by Anders Carlsson.

Source/WebCore:

No new tests. No change in behavior.

  • WebCore.exp.in: Added new exported methods of the PlatformPasteboard class
  • editing/mac/EditorMac.mm:

(WebCore::Editor::newGeneralClipboard): Use name based pasteboard references.

  • page/DragClient.h:

(WebCore::DragClient::declareAndWriteDragImage): Ditto.

  • page/mac/EventHandlerMac.mm:

(WebCore::EventHandler::createDraggingClipboard): Ditto.

  • platform/PasteboardStrategy.h: Added new methods to get a unique pasteboard name

and the pasteboard change count.

  • platform/PlatformPasteboard.h: Ditto.
  • platform/mac/ClipboardMac.h:

(WebCore::ClipboardMac::create): Using name based pasteboard.
(WebCore::ClipboardMac::pasteboardName): Replacing the old pasteboard() method.

  • platform/mac/ClipboardMac.mm: All the methods below have been modified to avoid

using Objective-C types and direct access to NSPasteboard object.
(WebCore::Clipboard::create):
(WebCore::ClipboardMac::ClipboardMac):
(WebCore::ClipboardMac::hasData):
(WebCore::cocoaTypeFromHTMLClipboardType):
(WebCore::utiTypeFromCocoaType):
(WebCore::addHTMLClipboardTypesForCocoaType):
(WebCore::ClipboardMac::clearData):
(WebCore::ClipboardMac::clearAllData):
(WebCore::absoluteURLsFromPasteboardFilenames):
(WebCore::absoluteURLsFromPasteboard):
(WebCore::ClipboardMac::getData):
(WebCore::ClipboardMac::setData):
(WebCore::ClipboardMac::types):
(WebCore::ClipboardMac::files):
(WebCore::ClipboardMac::setDragImage):
(WebCore::ClipboardMac::writeRange):
(WebCore::ClipboardMac::writePlainText):
(WebCore::ClipboardMac::writeURL):
(WebCore::ClipboardMac::declareAndWriteDragImage):

  • platform/mac/PasteboardMac.mm:

(WebCore::Pasteboard::writeClipboard): Using name based pasteboard reference.

  • platform/mac/PlatformPasteboardMac.mm:

(WebCore::PlatformPasteboard::getPathnamesForType): Fixed to support NSArray and NString content.
(WebCore::PlatformPasteboard::changeCount): Added.
(WebCore::PlatformPasteboard::uniqueName): Added.

Source/WebKit/mac:

  • WebCoreSupport/WebDragClient.h: Changed methods signature to use name based pasteboard.
  • WebCoreSupport/WebDragClient.mm: Ditto.

(WebDragClient::willPerformDragSourceAction):
(WebDragClient::startDrag):
(WebDragClient::declareAndWriteDragImage):

  • WebCoreSupport/WebPlatformStrategies.h: Added new methods.
  • WebCoreSupport/WebPlatformStrategies.mm:

(WebPlatformStrategies::changeCount):
(WebPlatformStrategies::uniqueName):

Source/WebKit2:

  • WebProcess/WebCoreSupport/WebDragClient.h: Changed method signature to reference

the pasteboard by name.

  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: Added new methods.

(WebKit::WebPlatformStrategies::changeCount):
(WebKit::WebPlatformStrategies::uniqueName):

  • WebProcess/WebCoreSupport/WebPlatformStrategies.h: Ditto.
  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::WebDragClient::declareAndWriteDragImage): Changed method signature to reference
the pasteboard by name.

Location:
trunk/Source
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r107843 r107844  
     12012-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
    1512012-02-15  Anders Carlsson  <andersca@apple.com>
    252
  • TabularUnified trunk/Source/WebCore/WebCore.exp.in

    r107793 r107844  
    560560__ZN7WebCore18PlatformPasteboard16setBufferForTypeEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS1_6StringE
    561561__ZN7WebCore18PlatformPasteboard16setStringForTypeERKN3WTF6StringES4_
     562__ZN7WebCore18PlatformPasteboard10uniqueNameEv
     563__ZNK7WebCore18PlatformPasteboard11changeCountEv
    562564__ZN7WebCore18SearchPopupMenuMacC1EPNS_15PopupMenuClientE
    563565__ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE
  • TabularUnified trunk/Source/WebCore/editing/mac/EditorMac.mm

    r107606 r107844  
    3838#import "HTMLNames.h"
    3939#import "Pasteboard.h"
     40#import "PasteboardStrategy.h"
     41#import "PlatformStrategies.h"
    4042#import "RenderBlock.h"
    4143#import "RuntimeApplicationChecks.h"
     
    5052{
    5153    return ClipboardMac::create(Clipboard::CopyAndPaste,
    52         policy == ClipboardWritable ? [NSPasteboard pasteboardWithUniqueName] : [NSPasteboard generalPasteboard], policy, frame);
     54        policy == ClipboardWritable ? platformStrategies()->pasteboardStrategy()->uniqueName() : String(NSGeneralPboard), policy, frame);
    5355}
    5456
  • TabularUnified trunk/Source/WebCore/page/DragClient.h

    r105203 r107844  
    6262        // Mac-specific helper function to allow access to web archives and NSPasteboard extras in WebKit.
    6363        // 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*) { }
    6565#endif
    6666       
  • TabularUnified trunk/Source/WebCore/page/mac/EventHandlerMac.mm

    r104773 r107844  
    4242#include "NotImplemented.h"
    4343#include "Page.h"
     44#include "Pasteboard.h"
    4445#include "PlatformEventFactoryMac.h"
    4546#include "RenderWidget.h"
     
    669670PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const
    670671{
    671     NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
    672672    // Must be done before ondragstart adds types and data to the pboard,
    673673    // 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);
    676677}
    677678
  • TabularUnified trunk/Source/WebCore/platform/PasteboardStrategy.h

    r107606 r107844  
    4343    virtual void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) = 0;
    4444    virtual String stringForType(const String& pasteboardType, const String& pasteboardName) = 0;
     45    virtual int changeCount(const String& pasteboardName) = 0;
     46    virtual String uniqueName() = 0;
    4547   
    4648    virtual void copy(const String& fromPasteboard, const String& toPasteboard) = 0;
  • TabularUnified trunk/Source/WebCore/platform/PlatformPasteboard.h

    r107629 r107844  
    4141public:
    4242    PlatformPasteboard(const String& pasteboardName);
     43    static String uniqueName();
    4344   
    4445    void getTypes(Vector<String>& types);
     
    4647    void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType);
    4748    String stringForType(const String& pasteboardType);
     49    int changeCount() const;
    4850   
    4951    void copy(const String& fromPasteboard);
  • TabularUnified trunk/Source/WebCore/platform/mac/ClipboardMac.h

    r105203 r107844  
    4242    WTF_MAKE_FAST_ALLOCATED;
    4343public:
    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)
    4545    {
    46         return adoptRef(new ClipboardMac(clipboardType, pasteboard, policy, frame));
     46        return adoptRef(new ClipboardMac(clipboardType, pasteboardName, policy, frame));
    4747    }
    4848
     
    7373    // Methods for getting info in Cocoa's type system
    7474    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; }
    7676
    7777private:
    78     ClipboardMac(ClipboardType, NSPasteboard *, ClipboardAccessPolicy, Frame*);
     78    ClipboardMac(ClipboardType, const String& pasteboardName, ClipboardAccessPolicy, Frame*);
    7979
    8080    void setDragImage(CachedImage*, Node*, const IntPoint&);
    8181
    82     RetainPtr<NSPasteboard> m_pasteboard;
     82    String m_pasteboardName;
    8383    int m_changeCount;
    8484    Frame* m_frame; // used on the source side to generate dragging images
  • TabularUnified trunk/Source/WebCore/platform/mac/ClipboardMac.mm

    r106872 r107844  
    3737#import "Page.h"
    3838#import "Pasteboard.h"
     39#import "PasteboardStrategy.h"
     40#import "PlatformStrategies.h"
    3941#import "RenderImage.h"
    4042#import "ScriptExecutionContext.h"
     
    4749PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData* dragData, Frame* frame)
    4850{
    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
     54ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame *frame)
    5355    : Clipboard(policy, clipboardType)
    54     , m_pasteboard(pasteboard)
     56    , m_pasteboardName(pasteboardName)
    5557    , m_frame(frame)
    5658{
    57     m_changeCount = [m_pasteboard.get() changeCount];
     59    m_changeCount = platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName);
    5860}
    5961
     
    6466bool ClipboardMac::hasData()
    6567{
    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();
    6771}
    6872   
    69 static RetainPtr<NSString> cocoaTypeFromHTMLClipboardType(const String& type)
     73static String cocoaTypeFromHTMLClipboardType(const String& type)
    7074{
    7175    // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dom-datatransfer-setdata
     
    7983    // Ignore any trailing charset - JS strings are Unicode, which encapsulates the charset issue
    8084    if (qType == "text/plain" || qType.startsWith("text/plain;"))
    81         return NSStringPboardType;
     85        return String(NSStringPboardType);
    8286    if (qType == "text/uri-list")
    8387        // special case because UTI doesn't work with Cocoa's URL type
    84         return NSURLPboardType; // note special case in getData to read NSFilenamesType
     88        return String(NSURLPboardType); // note special case in getData to read NSFilenamesType
    8589
    8690    // 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));
    8993    if (utiType) {
    9094        CFStringRef pbType = UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassNSPboardType);
    9195        if (pbType)
    92             return (NSString *)pbType;
     96            return pbType;
    9397    }
    9498
    9599    // 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
     103static String utiTypeFromCocoaType(const String& type)
     104{
     105    RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, type.createCFString(), NULL));
    102106    if (utiType) {
    103107        RetainPtr<CFStringRef> mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType));
     
    108112}
    109113
    110 static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, NSString *cocoaType, NSPasteboard *pasteboard)
     114static void addHTMLClipboardTypesForCocoaType(HashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName)
    111115{
    112116    // 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)) {
    114118        resultTypes.add("text/plain");
    115119        return;
    116120    }
    117     if ([cocoaType isEqualToString:NSURLPboardType]) {
     121    if (cocoaType == String(NSURLPboardType)) {
    118122        resultTypes.add("text/uri-list");
    119123        return;
    120124    }
    121     if ([cocoaType isEqualToString:NSFilenamesPboardType]) {
     125    if (cocoaType == String(NSFilenamesPboardType)) {
    122126        // If file list is empty, add nothing.
    123127        // Note that there is a chance that the file list count could have changed since we grabbed the types array.
    124128        // 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()) {
    127132            // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
    128133            // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
     
    148153    // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
    149154
    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);
    152158}
    153159
     
    159165    // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
    160166
    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
     171static 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]));
    184184    }
    185185    return urls;
    186186}
    187187
    188 static NSArray *absoluteURLsFromPasteboard(NSPasteboard* pasteboard, bool onlyFirstURL = false)
     188static Vector<String> absoluteURLsFromPasteboard(const String& pasteboardName, bool onlyFirstURL = false)
    189189{
    190190    // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data
    191191    // 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);
    193195
    194196    // 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())
    197200            return absoluteURLs;
    198201    }
    199202
    200203    // 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;
    204208    }
    205209
    206210    // No file paths on the pasteboard, return nil
    207     return nil;
     211    return Vector<String>();
    208212}
    209213
     
    214218        return String();
    215219
    216     RetainPtr<NSString> cocoaType = cocoaTypeFromHTMLClipboardType(type);
    217     NSString *cocoaValue = nil;
     220    const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
     221    String cocoaValue;
    218222
    219223    // Grab the value off the pasteboard corresponding to the cocoaType
    220     if ([cocoaType.get() isEqualToString:NSURLPboardType]) {
     224    if (cocoaType == String(NSURLPboardType)) {
    221225        // "url" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "url" only wants the first URL
    222226        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);
    229234
    230235    // Enforce changeCount ourselves for security.  We check after reading instead of before to be
    231236    // 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)) {
    233238        success = true;
    234239        return cocoaValue;
     
    244249    // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
    245250
    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);
    251260        NSURL *url = [[NSURL alloc] initWithString:cocoaData];
    252         [url writeToPasteboard:m_pasteboard.get()];
    253261
    254262        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);
    258268        }
    259269
     
    262272    }
    263273
    264     if (cocoaType) {
     274    if (!cocoaType.isEmpty()) {
    265275        // 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;
    268281    }
    269282
     
    276289        return HashSet<String>();
    277290
    278     NSArray *types = [m_pasteboard.get() types];
     291    Vector<String> types;
     292    platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName);
    279293
    280294    // Enforce changeCount ourselves for security.  We check after reading instead of before to be
    281295    // 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))
    283297        return HashSet<String>();
    284298
    285299    HashSet<String> result;
    286     NSUInteger count = [types count];
    287300    // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types
    288301    // 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")
    292304            continue;   // skip this ancient type that gets auto-supplied by some system conversion
    293305
    294         addHTMLClipboardTypesForCocoaType(result, pbType, m_pasteboard.get());
     306        addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName);
    295307    }
    296308
     
    306318        return FileList::create();
    307319
    308     NSArray *absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboard.get());
    309     NSUInteger count = [absoluteURLs count];
     320    Vector<String> absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName);
    310321
    311322    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]];
    314325        ASSERT([absoluteURL isFileURL]);
    315326        fileList->append(File::create([absoluteURL path]));
     
    342353        m_dragImageElement = node;
    343354       
    344         if (dragStarted() && m_changeCount == [m_pasteboard.get() changeCount]) {
     355        if (dragStarted() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) {
    345356            NSPoint cocoaLoc;
    346357            NSImage* cocoaImage = dragNSImage(cocoaLoc);
     
    368379    ASSERT(range);
    369380    ASSERT(frame);
    370     Pasteboard pasteboard([m_pasteboard.get() name]);
     381    Pasteboard pasteboard(m_pasteboardName);
    371382    pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame);
    372383}
     
    374385void ClipboardMac::writePlainText(const String& text)
    375386{
    376     Pasteboard pasteboard([m_pasteboard.get() name]);
     387    Pasteboard pasteboard(m_pasteboardName);
    377388    pasteboard.writePlainText(text);
    378389}
     
    381392{   
    382393    ASSERT(frame);
    383     ASSERT(m_pasteboard);
    384     Pasteboard pasteboard([m_pasteboard.get() name]);
     394    ASSERT(m_pasteboardName);
     395    Pasteboard pasteboard(m_pasteboardName);
    385396    pasteboard.writeURL(url, title, frame);
    386397}
     
    391402    ASSERT(frame);
    392403    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);
    394405}
    395406#endif // ENABLE(DRAG_SUPPORT)
  • TabularUnified trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r107770 r107844  
    298298void Pasteboard::writeClipboard(Clipboard* clipboard)
    299299{
    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);
    304301}
    305302
  • TabularUnified trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm

    r107753 r107844  
    5151{
    5252    NSArray* paths = [m_pasteboard.get() propertyListForType:pasteboardType];
     53    if ([paths isKindOfClass:[NSString class]]) {
     54        pathnames.append((NSString *)paths);
     55        return;       
     56    }
    5357    for (NSUInteger i = 0; i < [paths count]; i++)
    5458        pathnames.append([paths objectAtIndex:i]);
     
    5862{
    5963    return [m_pasteboard.get() stringForType:pasteboardType];
     64}
     65
     66int PlatformPasteboard::changeCount() const
     67{
     68    return [m_pasteboard.get() changeCount];
     69}
     70
     71String PlatformPasteboard::uniqueName()
     72{
     73    return [[NSPasteboard pasteboardWithUniqueName] name];
    6074}
    6175
  • TabularUnified trunk/Source/WebKit/mac/ChangeLog

    r107832 r107844  
     12012-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
    1182012-02-15  Sadrul Habib Chowdhury  <sadrul@chromium.org>
    219
  • TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h

    r95847 r107844  
    3737    virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) OVERRIDE;
    3838    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;
    4040private:
    4141    WebView* m_webView;
  • TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm

    r101414 r107844  
    8484{
    8585    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()]];
    8787}
    8888
     
    101101   
    102102    [topHTMLView _stopAutoscrollTimer];
    103     NSPasteboard *pasteboard = static_cast<ClipboardMac*>(clipboard)->pasteboard();
     103    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:static_cast<ClipboardMac*>(clipboard)->pasteboardName()];
    104104
    105105    NSImage *dragNSImage = dragImage.get();
     
    121121}
    122122
    123 void WebDragClient::declareAndWriteDragImage(NSPasteboard* pasteboard, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame)
     123void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame)
    124124{
    125     ASSERT(pasteboard);
     125    ASSERT(pasteboardName);
    126126    ASSERT(element);
    127127    WebHTMLView *source = getTopHTMLView(frame);     
    128128    WebArchive *archive = [element webArchive];
    129129   
    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];
    131131}
    132132
  • TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h

    r107606 r107844  
    6262    virtual void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) OVERRIDE;
    6363    virtual String stringForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE;
     64    virtual int changeCount(const String& pasteboardName) OVERRIDE;
     65    virtual String uniqueName() OVERRIDE;
    6466   
    6567    virtual void copy(const String& fromPasteboard, const String& toPasteboard) OVERRIDE;
  • TabularUnified trunk/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm

    r107606 r107844  
    128128}
    129129
     130int WebPlatformStrategies::changeCount(const String &pasteboardName)
     131{
     132    PlatformPasteboard pasteboard(pasteboardName);
     133    return pasteboard.changeCount();
     134}
     135
     136String WebPlatformStrategies::uniqueName()
     137{
     138    return PlatformPasteboard::uniqueName();
     139}
     140
    130141void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
    131142{
  • TabularUnified trunk/Source/WebKit2/ChangeLog

    r107832 r107844  
     12012-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
    1182012-02-15  Sadrul Habib Chowdhury  <sadrul@chromium.org>
    219
  • TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h

    r105203 r107844  
    5454
    5555#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;
    5757#endif
    5858
  • TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r107606 r107844  
    165165}
    166166
     167int WebPlatformStrategies::changeCount(const WTF::String &pasteboardName)
     168{
     169    PlatformPasteboard pasteboard(pasteboardName);
     170    return pasteboard.changeCount();
     171}
     172
     173String WebPlatformStrategies::uniqueName()
     174{
     175    return PlatformPasteboard::uniqueName();
     176}
     177
    167178void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
    168179{
  • TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h

    r107606 r107844  
    6868    virtual void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) OVERRIDE;
    6969    virtual String stringForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE;
     70    virtual int changeCount(const String& pasteboardName) OVERRIDE;
     71    virtual String uniqueName() OVERRIDE;
    7072   
    7173    virtual void copy(const String& fromPasteboard, const String& toPasteboard) OVERRIDE;
  • TabularUnified trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r107267 r107844  
    126126}
    127127
    128 void WebDragClient::declareAndWriteDragImage(NSPasteboard *pasteboard, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*)
     128void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*)
    129129{
    130130    ASSERT(element);
    131     ASSERT(pasteboard && pasteboard == [NSPasteboard pasteboardWithName:NSDragPboard]);
     131    ASSERT(pasteboardName == String(NSDragPboard));
    132132
    133133    Element* coreElement = core(element);
     
    156156    m_filePromiseOwner.adoptNS([(WKPasteboardFilePromiseOwner *)[WKPasteboardFilePromiseOwner alloc] initWithSource:m_pasteboardOwner.get()]);
    157157
     158    NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
    158159    [pasteboard declareTypes:types.get() owner:m_pasteboardOwner.leakRef()];   
    159160
Note: See TracChangeset for help on using the changeset viewer.