From: enrica@apple.com Date: Wed, 15 Feb 2012 23:08:25 +0000 (+0000) Subject: Refactor ClipboardMac class to use PlatformStrategies. X-Git-Tag: 070512121124~12772 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d9962f673fe6c0032d656846b350f0075371f73;p=profile%2Fivi%2Fwebkit-efl.git 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. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107844 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 5c18cbb..73f53bb 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,53 @@ +2012-02-15 Enrica Casucci + + Refactor ClipboardMac class to use PlatformStrategies. + https://bugs.webkit.org/show_bug.cgi?id=78554 + + Reviewed by Anders Carlsson. + + 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. + 2012-02-15 Anders Carlsson TileCache needs to support setting the contents scale diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in index 7246c04..65b8c56 100644 --- a/Source/WebCore/WebCore.exp.in +++ b/Source/WebCore/WebCore.exp.in @@ -559,6 +559,8 @@ __ZN7WebCore18PlatformPasteboard8getTypesERN3WTF6VectorINS1_6StringELm0EEE __ZN7WebCore18PlatformPasteboard4copyERKN3WTF6StringE __ZN7WebCore18PlatformPasteboard16setBufferForTypeEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS1_6StringE __ZN7WebCore18PlatformPasteboard16setStringForTypeERKN3WTF6StringES4_ +__ZN7WebCore18PlatformPasteboard10uniqueNameEv +__ZNK7WebCore18PlatformPasteboard11changeCountEv __ZN7WebCore18SearchPopupMenuMacC1EPNS_15PopupMenuClientE __ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE __ZN7WebCore18pluginScriptObjectEPN3JSC9ExecStateEPNS_13JSHTMLElementE diff --git a/Source/WebCore/editing/mac/EditorMac.mm b/Source/WebCore/editing/mac/EditorMac.mm index b172592..2f58336 100644 --- a/Source/WebCore/editing/mac/EditorMac.mm +++ b/Source/WebCore/editing/mac/EditorMac.mm @@ -37,6 +37,8 @@ #import "FrameView.h" #import "HTMLNames.h" #import "Pasteboard.h" +#import "PasteboardStrategy.h" +#import "PlatformStrategies.h" #import "RenderBlock.h" #import "RuntimeApplicationChecks.h" #import "Sound.h" @@ -49,7 +51,7 @@ using namespace HTMLNames; PassRefPtr Editor::newGeneralClipboard(ClipboardAccessPolicy policy, Frame* frame) { return ClipboardMac::create(Clipboard::CopyAndPaste, - policy == ClipboardWritable ? [NSPasteboard pasteboardWithUniqueName] : [NSPasteboard generalPasteboard], policy, frame); + policy == ClipboardWritable ? platformStrategies()->pasteboardStrategy()->uniqueName() : String(NSGeneralPboard), policy, frame); } void Editor::showFontPanel() diff --git a/Source/WebCore/page/DragClient.h b/Source/WebCore/page/DragClient.h index 090c29d..1d9b25b 100644 --- a/Source/WebCore/page/DragClient.h +++ b/Source/WebCore/page/DragClient.h @@ -61,7 +61,7 @@ namespace WebCore { #if PLATFORM(MAC) // Mac-specific helper function to allow access to web archives and NSPasteboard extras in WebKit. // This is not abstract as that would require another #if PLATFORM(MAC) for the SVGImage client empty implentation. - virtual void declareAndWriteDragImage(NSPasteboard *, DOMElement*, NSURL *, NSString *, Frame*) { } + virtual void declareAndWriteDragImage(const String&, DOMElement*, NSURL *, NSString *, Frame*) { } #endif virtual void dragEnded() { } diff --git a/Source/WebCore/page/mac/EventHandlerMac.mm b/Source/WebCore/page/mac/EventHandlerMac.mm index 2630dbb..55dd816 100644 --- a/Source/WebCore/page/mac/EventHandlerMac.mm +++ b/Source/WebCore/page/mac/EventHandlerMac.mm @@ -41,6 +41,7 @@ #include "MouseEventWithHitTestResults.h" #include "NotImplemented.h" #include "Page.h" +#include "Pasteboard.h" #include "PlatformEventFactoryMac.h" #include "RenderWidget.h" #include "RuntimeApplicationChecks.h" @@ -668,11 +669,11 @@ bool EventHandler::eventActivatedView(const PlatformMouseEvent& event) const PassRefPtr EventHandler::createDraggingClipboard() const { - NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; // Must be done before ondragstart adds types and data to the pboard, // also done for security, as it erases data from the last drag - [pasteboard declareTypes:[NSArray array] owner:nil]; - return ClipboardMac::create(Clipboard::DragAndDrop, pasteboard, ClipboardWritable, m_frame); + Pasteboard pasteboard(NSDragPboard); + pasteboard.clear(); + return ClipboardMac::create(Clipboard::DragAndDrop, String(NSDragPboard), ClipboardWritable, m_frame); } #endif diff --git a/Source/WebCore/platform/PasteboardStrategy.h b/Source/WebCore/platform/PasteboardStrategy.h index 052f8aa..c2d357a 100644 --- a/Source/WebCore/platform/PasteboardStrategy.h +++ b/Source/WebCore/platform/PasteboardStrategy.h @@ -42,6 +42,8 @@ public: virtual PassRefPtr bufferForType(const String& pasteboardType, const String& pasteboardName) = 0; virtual void getPathnamesForType(Vector& pathnames, const String& pasteboardType, const String& pasteboardName) = 0; virtual String stringForType(const String& pasteboardType, const String& pasteboardName) = 0; + virtual int changeCount(const String& pasteboardName) = 0; + virtual String uniqueName() = 0; virtual void copy(const String& fromPasteboard, const String& toPasteboard) = 0; virtual void setTypes(const Vector& pasteboardTypes, const String& pasteboardName) = 0; diff --git a/Source/WebCore/platform/PlatformPasteboard.h b/Source/WebCore/platform/PlatformPasteboard.h index f0439dd..e04ba3b 100644 --- a/Source/WebCore/platform/PlatformPasteboard.h +++ b/Source/WebCore/platform/PlatformPasteboard.h @@ -40,11 +40,13 @@ namespace WebCore { class PlatformPasteboard { public: PlatformPasteboard(const String& pasteboardName); + static String uniqueName(); void getTypes(Vector& types); PassRefPtr bufferForType(const String& pasteboardType); void getPathnamesForType(Vector& pathnames, const String& pasteboardType); String stringForType(const String& pasteboardType); + int changeCount() const; void copy(const String& fromPasteboard); void setTypes(const Vector& pasteboardTypes); diff --git a/Source/WebCore/platform/mac/ClipboardMac.h b/Source/WebCore/platform/mac/ClipboardMac.h index 24e9b80..a4b6796 100644 --- a/Source/WebCore/platform/mac/ClipboardMac.h +++ b/Source/WebCore/platform/mac/ClipboardMac.h @@ -41,9 +41,9 @@ class FileList; class ClipboardMac : public Clipboard, public CachedImageClient { WTF_MAKE_FAST_ALLOCATED; public: - static PassRefPtr create(ClipboardType clipboardType, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame* frame) + static PassRefPtr create(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame* frame) { - return adoptRef(new ClipboardMac(clipboardType, pasteboard, policy, frame)); + return adoptRef(new ClipboardMac(clipboardType, pasteboardName, policy, frame)); } virtual ~ClipboardMac(); @@ -72,14 +72,14 @@ public: // Methods for getting info in Cocoa's type system NSImage *dragNSImage(NSPoint&) const; // loc converted from dragLoc, based on whole image size - NSPasteboard *pasteboard() { return m_pasteboard.get(); } + const String& pasteboardName() { return m_pasteboardName; } private: - ClipboardMac(ClipboardType, NSPasteboard *, ClipboardAccessPolicy, Frame*); + ClipboardMac(ClipboardType, const String& pasteboardName, ClipboardAccessPolicy, Frame*); void setDragImage(CachedImage*, Node*, const IntPoint&); - RetainPtr m_pasteboard; + String m_pasteboardName; int m_changeCount; Frame* m_frame; // used on the source side to generate dragging images }; diff --git a/Source/WebCore/platform/mac/ClipboardMac.mm b/Source/WebCore/platform/mac/ClipboardMac.mm index d37c5f3..c48aa49 100644 --- a/Source/WebCore/platform/mac/ClipboardMac.mm +++ b/Source/WebCore/platform/mac/ClipboardMac.mm @@ -36,6 +36,8 @@ #import "Image.h" #import "Page.h" #import "Pasteboard.h" +#import "PasteboardStrategy.h" +#import "PlatformStrategies.h" #import "RenderImage.h" #import "ScriptExecutionContext.h" #import "SecurityOrigin.h" @@ -46,15 +48,15 @@ namespace WebCore { PassRefPtr Clipboard::create(ClipboardAccessPolicy policy, DragData* dragData, Frame* frame) { - return ClipboardMac::create(DragAndDrop, dragData->pasteboard(), policy, frame); + return ClipboardMac::create(DragAndDrop, [dragData->pasteboard() name], policy, frame); } -ClipboardMac::ClipboardMac(ClipboardType clipboardType, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame *frame) +ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame *frame) : Clipboard(policy, clipboardType) - , m_pasteboard(pasteboard) + , m_pasteboardName(pasteboardName) , m_frame(frame) { - m_changeCount = [m_pasteboard.get() changeCount]; + m_changeCount = platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName); } ClipboardMac::~ClipboardMac() @@ -63,10 +65,12 @@ ClipboardMac::~ClipboardMac() bool ClipboardMac::hasData() { - return m_pasteboard && [m_pasteboard.get() types] && [[m_pasteboard.get() types] count] > 0; + Vector types; + platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); + return !types.isEmpty(); } -static RetainPtr cocoaTypeFromHTMLClipboardType(const String& type) +static String cocoaTypeFromHTMLClipboardType(const String& type) { // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dom-datatransfer-setdata String qType = type.lower(); @@ -78,27 +82,27 @@ static RetainPtr cocoaTypeFromHTMLClipboardType(const String& type) // Ignore any trailing charset - JS strings are Unicode, which encapsulates the charset issue if (qType == "text/plain" || qType.startsWith("text/plain;")) - return NSStringPboardType; + return String(NSStringPboardType); if (qType == "text/uri-list") // special case because UTI doesn't work with Cocoa's URL type - return NSURLPboardType; // note special case in getData to read NSFilenamesType + return String(NSURLPboardType); // note special case in getData to read NSFilenamesType // Try UTI now - NSString *mimeType = qType; - RetainPtr utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL)); + String mimeType = qType; + RetainPtr utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType.createCFString(), NULL)); if (utiType) { CFStringRef pbType = UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassNSPboardType); if (pbType) - return (NSString *)pbType; + return pbType; } // No mapping, just pass the whole string though - return (NSString *)qType; + return qType; } -static String utiTypeFromCocoaType(NSString *type) +static String utiTypeFromCocoaType(const String& type) { - RetainPtr utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL)); + RetainPtr utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, type.createCFString(), NULL)); if (utiType) { RetainPtr mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType)); if (mimeType) @@ -107,23 +111,24 @@ static String utiTypeFromCocoaType(NSString *type) return String(); } -static void addHTMLClipboardTypesForCocoaType(HashSet& resultTypes, NSString *cocoaType, NSPasteboard *pasteboard) +static void addHTMLClipboardTypesForCocoaType(HashSet& resultTypes, const String& cocoaType, const String& pasteboardName) { // UTI may not do these right, so make sure we get the right, predictable result - if ([cocoaType isEqualToString:NSStringPboardType]) { + if (cocoaType == String(NSStringPboardType)) { resultTypes.add("text/plain"); return; } - if ([cocoaType isEqualToString:NSURLPboardType]) { + if (cocoaType == String(NSURLPboardType)) { resultTypes.add("text/uri-list"); return; } - if ([cocoaType isEqualToString:NSFilenamesPboardType]) { + if (cocoaType == String(NSFilenamesPboardType)) { // If file list is empty, add nothing. // Note that there is a chance that the file list count could have changed since we grabbed the types array. // However, this is not really an issue for us doing a sanity check here. - NSArray *fileList = [pasteboard propertyListForType:NSFilenamesPboardType]; - if ([fileList count]) { + Vector fileList; + platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName); + if (!fileList.isEmpty()) { // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa, // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files' resultTypes.add("text/uri-list"); @@ -147,8 +152,9 @@ void ClipboardMac::clearData(const String& type) // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner - if (RetainPtr cocoaType = cocoaTypeFromHTMLClipboardType(type)) - [m_pasteboard.get() setString:@"" forType:cocoaType.get()]; + String cocoaType = cocoaTypeFromHTMLClipboardType(type); + if (!cocoaType.isEmpty()) + platformStrategies()->pasteboardStrategy()->setStringForType("", cocoaType, m_pasteboardName); } void ClipboardMac::clearAllData() @@ -158,53 +164,51 @@ void ClipboardMac::clearAllData() // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner - [m_pasteboard.get() declareTypes:[NSArray array] owner:nil]; + Pasteboard pasteboard(m_pasteboardName); + pasteboard.clear(); } -static NSArray *absoluteURLsFromPasteboardFilenames(NSPasteboard* pasteboard, bool onlyFirstURL = false) +static Vector absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool onlyFirstURL = false) { - NSArray *fileList = [pasteboard propertyListForType:NSFilenamesPboardType]; + Vector fileList; + platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName); - // FIXME: Why does this code need to guard against bad values on the pasteboard? - ASSERT(!fileList || [fileList isKindOfClass:[NSArray class]]); - if (!fileList || ![fileList isKindOfClass:[NSArray class]] || ![fileList count]) - return nil; + if (fileList.isEmpty()) + return fileList; - NSUInteger count = onlyFirstURL ? 1 : [fileList count]; - NSMutableArray *urls = [NSMutableArray array]; - for (NSUInteger i = 0; i < count; i++) { - NSString *string = [fileList objectAtIndex:i]; - - ASSERT([string isKindOfClass:[NSString class]]); // Added to understand why this if code is here - if (![string isKindOfClass:[NSString class]]) - return nil; // Non-string object in the list, bail out! FIXME: When can this happen? - - NSURL *url = [NSURL fileURLWithPath:string]; - [urls addObject:[url absoluteString]]; + size_t count = onlyFirstURL ? 1 : fileList.size(); + Vector urls; + for (size_t i = 0; i < count; i++) { + NSURL *url = [NSURL fileURLWithPath:fileList[i]]; + urls.append(String([url absoluteString])); } return urls; } -static NSArray *absoluteURLsFromPasteboard(NSPasteboard* pasteboard, bool onlyFirstURL = false) +static Vector absoluteURLsFromPasteboard(const String& pasteboardName, bool onlyFirstURL = false) { // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data // or CoreFoundation will printf when there is not data of the corresponding type. - NSArray *availableTypes = [pasteboard types]; + Vector availableTypes; + Vector absoluteURLs; + platformStrategies()->pasteboardStrategy()->getTypes(availableTypes, pasteboardName); // Try NSFilenamesPboardType because it contains a list - if ([availableTypes containsObject:NSFilenamesPboardType]) { - if (NSArray* absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboard, onlyFirstURL)) + if (availableTypes.contains(String(NSFilenamesPboardType))) { + absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL); + if (!absoluteURLs.isEmpty()) return absoluteURLs; } // Fallback to NSURLPboardType (which is a single URL) - if ([availableTypes containsObject:NSURLPboardType]) { - if (NSURL *url = [NSURL URLFromPasteboard:pasteboard]) - return [NSArray arrayWithObject:[url absoluteString]]; + if (availableTypes.contains(String(NSURLPboardType))) { + platformStrategies()->pasteboardStrategy()->getPathnamesForType(absoluteURLs, String(NSURLPboardType), pasteboardName); + if (!absoluteURLs.isEmpty()) + return absoluteURLs; } // No file paths on the pasteboard, return nil - return nil; + return Vector(); } String ClipboardMac::getData(const String& type, bool& success) const @@ -213,23 +217,24 @@ String ClipboardMac::getData(const String& type, bool& success) const if (policy() != ClipboardReadable) return String(); - RetainPtr cocoaType = cocoaTypeFromHTMLClipboardType(type); - NSString *cocoaValue = nil; + const String& cocoaType = cocoaTypeFromHTMLClipboardType(type); + String cocoaValue; // Grab the value off the pasteboard corresponding to the cocoaType - if ([cocoaType.get() isEqualToString:NSURLPboardType]) { + if (cocoaType == String(NSURLPboardType)) { // "url" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "url" only wants the first URL bool onlyFirstURL = (equalIgnoringCase(type, "url")); - NSArray *absoluteURLs = absoluteURLsFromPasteboard(m_pasteboard.get(), onlyFirstURL); - cocoaValue = [absoluteURLs componentsJoinedByString:@"\n"]; - } else if ([cocoaType.get() isEqualToString:NSStringPboardType]) { - cocoaValue = [[m_pasteboard.get() stringForType:cocoaType.get()] precomposedStringWithCanonicalMapping]; - } else if (cocoaType) - cocoaValue = [m_pasteboard.get() stringForType:cocoaType.get()]; + Vector absoluteURLs = absoluteURLsFromPasteboard(m_pasteboardName, onlyFirstURL); + for (size_t i = 0; i < absoluteURLs.size(); i++) + cocoaValue = i ? "\n" + absoluteURLs[i]: absoluteURLs[i]; + } else if (cocoaType == String(NSStringPboardType)) + cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName) precomposedStringWithCanonicalMapping]; + else if (!cocoaType.isEmpty()) + cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName); // Enforce changeCount ourselves for security. We check after reading instead of before to be // sure it doesn't change between our testing the change count and accessing the data. - if (cocoaValue && m_changeCount == [m_pasteboard.get() changeCount]) { + if (!cocoaValue.isEmpty() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) { success = true; return cocoaValue; } @@ -243,28 +248,36 @@ bool ClipboardMac::setData(const String &type, const String &data) return false; // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner - RetainPtr cocoaType = cocoaTypeFromHTMLClipboardType(type); - NSString *cocoaData = data; + const String& cocoaType = cocoaTypeFromHTMLClipboardType(type); + String cocoaData = data; - if ([cocoaType.get() isEqualToString:NSURLPboardType]) { - [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil]; + if (cocoaType == String(NSURLPboardType)) { + Vector types; + types.append(String(NSURLPboardType)); + + platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); + platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, String(NSURLPboardType), m_pasteboardName); NSURL *url = [[NSURL alloc] initWithString:cocoaData]; - [url writeToPasteboard:m_pasteboard.get()]; if ([url isFileURL] && m_frame->document()->securityOrigin()->canLoadLocalResources()) { - [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; - NSArray *fileList = [NSArray arrayWithObject:[url path]]; - [m_pasteboard.get() setPropertyList:fileList forType:NSFilenamesPboardType]; + types.append(String(NSFilenamesPboardType)); + platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); + Vector fileList; + fileList.append(String([url path])); + platformStrategies()->pasteboardStrategy()->setPathnamesForType(fileList, String(NSFilenamesPboardType), m_pasteboardName); } [url release]; return true; } - if (cocoaType) { + if (!cocoaType.isEmpty()) { // everything else we know of goes on the pboard as a string - [m_pasteboard.get() addTypes:[NSArray arrayWithObject:cocoaType.get()] owner:nil]; - return [m_pasteboard.get() setString:cocoaData forType:cocoaType.get()]; + Vector types; + types.append(cocoaType); + platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); + platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, cocoaType, m_pasteboardName); + return true; } return false; @@ -275,23 +288,22 @@ HashSet ClipboardMac::types() const if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable) return HashSet(); - NSArray *types = [m_pasteboard.get() types]; + Vector types; + platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); // Enforce changeCount ourselves for security. We check after reading instead of before to be // sure it doesn't change between our testing the change count and accessing the data. - if (m_changeCount != [m_pasteboard.get() changeCount]) + if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) return HashSet(); HashSet result; - NSUInteger count = [types count]; // FIXME: This loop could be split into two stages. One which adds all the HTML5 specified types // and a second which adds all the extra types from the cocoa clipboard (which is Mac-only behavior). - for (NSUInteger i = 0; i < count; i++) { - NSString *pbType = [types objectAtIndex:i]; - if ([pbType isEqualToString:@"NeXT plain ascii pasteboard type"]) + for (size_t i = 0; i < types.size(); i++) { + if (types[i] == "NeXT plain ascii pasteboard type") continue; // skip this ancient type that gets auto-supplied by some system conversion - addHTMLClipboardTypesForCocoaType(result, pbType, m_pasteboard.get()); + addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName); } return result; @@ -305,12 +317,11 @@ PassRefPtr ClipboardMac::files() const if (policy() != ClipboardReadable) return FileList::create(); - NSArray *absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboard.get()); - NSUInteger count = [absoluteURLs count]; + Vector absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName); RefPtr fileList = FileList::create(); - for (NSUInteger x = 0; x < count; x++) { - NSURL *absoluteURL = [NSURL URLWithString:[absoluteURLs objectAtIndex:x]]; + for (size_t i = 0; i < absoluteURLs.size(); i++) { + NSURL *absoluteURL = [NSURL URLWithString:absoluteURLs[i]]; ASSERT([absoluteURL isFileURL]); fileList->append(File::create([absoluteURL path])); } @@ -341,7 +352,7 @@ void ClipboardMac::setDragImage(CachedImage* image, Node *node, const IntPoint & m_dragLoc = loc; m_dragImageElement = node; - if (dragStarted() && m_changeCount == [m_pasteboard.get() changeCount]) { + if (dragStarted() && m_changeCount == platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) { NSPoint cocoaLoc; NSImage* cocoaImage = dragNSImage(cocoaLoc); if (cocoaImage) { @@ -367,21 +378,21 @@ void ClipboardMac::writeRange(Range* range, Frame* frame) { ASSERT(range); ASSERT(frame); - Pasteboard pasteboard([m_pasteboard.get() name]); + Pasteboard pasteboard(m_pasteboardName); pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame); } void ClipboardMac::writePlainText(const String& text) { - Pasteboard pasteboard([m_pasteboard.get() name]); + Pasteboard pasteboard(m_pasteboardName); pasteboard.writePlainText(text); } void ClipboardMac::writeURL(const KURL& url, const String& title, Frame* frame) { ASSERT(frame); - ASSERT(m_pasteboard); - Pasteboard pasteboard([m_pasteboard.get() name]); + ASSERT(m_pasteboardName); + Pasteboard pasteboard(m_pasteboardName); pasteboard.writeURL(url, title, frame); } @@ -390,7 +401,7 @@ void ClipboardMac::declareAndWriteDragImage(Element* element, const KURL& url, c { ASSERT(frame); if (Page* page = frame->page()) - page->dragController()->client()->declareAndWriteDragImage(m_pasteboard.get(), kit(element), url, title, frame); + page->dragController()->client()->declareAndWriteDragImage(m_pasteboardName, kit(element), url, title, frame); } #endif // ENABLE(DRAG_SUPPORT) diff --git a/Source/WebCore/platform/mac/PasteboardMac.mm b/Source/WebCore/platform/mac/PasteboardMac.mm index 6c32214..c952760 100644 --- a/Source/WebCore/platform/mac/PasteboardMac.mm +++ b/Source/WebCore/platform/mac/PasteboardMac.mm @@ -297,10 +297,7 @@ void Pasteboard::writeImage(Node* node, const KURL& url, const String& title) void Pasteboard::writeClipboard(Clipboard* clipboard) { - // FIXME: this is the last access to NSPasteboard. It will removed when the ClipboardMac - // class is refactored. - NSPasteboard* pasteboard = static_cast(clipboard)->pasteboard(); - platformStrategies()->pasteboardStrategy()->copy([pasteboard name], m_pasteboardName); + platformStrategies()->pasteboardStrategy()->copy(static_cast(clipboard)->pasteboardName(), m_pasteboardName); } bool Pasteboard::canSmartReplace() diff --git a/Source/WebCore/platform/mac/PlatformPasteboardMac.mm b/Source/WebCore/platform/mac/PlatformPasteboardMac.mm index 059e435..267e86c 100644 --- a/Source/WebCore/platform/mac/PlatformPasteboardMac.mm +++ b/Source/WebCore/platform/mac/PlatformPasteboardMac.mm @@ -50,6 +50,10 @@ PassRefPtr PlatformPasteboard::bufferForType(const String& pastebo void PlatformPasteboard::getPathnamesForType(Vector& pathnames, const String& pasteboardType) { NSArray* paths = [m_pasteboard.get() propertyListForType:pasteboardType]; + if ([paths isKindOfClass:[NSString class]]) { + pathnames.append((NSString *)paths); + return; + } for (NSUInteger i = 0; i < [paths count]; i++) pathnames.append([paths objectAtIndex:i]); } @@ -59,6 +63,16 @@ String PlatformPasteboard::stringForType(const String& pasteboardType) return [m_pasteboard.get() stringForType:pasteboardType]; } +int PlatformPasteboard::changeCount() const +{ + return [m_pasteboard.get() changeCount]; +} + +String PlatformPasteboard::uniqueName() +{ + return [[NSPasteboard pasteboardWithUniqueName] name]; +} + void PlatformPasteboard::copy(const String& fromPasteboard) { NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:fromPasteboard]; diff --git a/Source/WebKit/mac/ChangeLog b/Source/WebKit/mac/ChangeLog index 8803156..8f5d827 100644 --- a/Source/WebKit/mac/ChangeLog +++ b/Source/WebKit/mac/ChangeLog @@ -1,3 +1,20 @@ +2012-02-15 Enrica Casucci + + Refactor ClipboardMac class to use PlatformStrategies. + https://bugs.webkit.org/show_bug.cgi?id=78554 + + Reviewed by Anders Carlsson. + + * 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): + 2012-02-15 Sadrul Habib Chowdhury Notify ChromeClient when touch-event handlers are installed/removed. diff --git a/Source/WebKit/mac/WebCoreSupport/WebDragClient.h b/Source/WebKit/mac/WebCoreSupport/WebDragClient.h index e472fb7..9d96b82 100644 --- a/Source/WebKit/mac/WebCoreSupport/WebDragClient.h +++ b/Source/WebKit/mac/WebCoreSupport/WebDragClient.h @@ -36,7 +36,7 @@ public: virtual void dragControllerDestroyed() OVERRIDE; virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) OVERRIDE; virtual void startDrag(WebCore::DragImageRef, const WebCore::IntPoint& dragPos, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag) OVERRIDE; - virtual void declareAndWriteDragImage(NSPasteboard*, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE; + virtual void declareAndWriteDragImage(const String& pasteboardName, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE; private: WebView* m_webView; }; diff --git a/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm b/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm index 9ba4b05..aff7ec2 100644 --- a/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm +++ b/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm @@ -83,7 +83,7 @@ WebCore::DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntP void WebDragClient::willPerformDragSourceAction(WebCore::DragSourceAction action, const WebCore::IntPoint& mouseDownPoint, WebCore::Clipboard* clipboard) { ASSERT(clipboard); - [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:mouseDownPoint withPasteboard:static_cast(clipboard)->pasteboard()]; + [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:mouseDownPoint withPasteboard:[NSPasteboard pasteboardWithName:static_cast(clipboard)->pasteboardName()]]; } void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& at, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool linkDrag) @@ -100,7 +100,7 @@ void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& at, const RetainPtr topViewProtector = topHTMLView; [topHTMLView _stopAutoscrollTimer]; - NSPasteboard *pasteboard = static_cast(clipboard)->pasteboard(); + NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:static_cast(clipboard)->pasteboardName()]; NSImage *dragNSImage = dragImage.get(); WebHTMLView *sourceHTMLView = htmlView.get(); @@ -120,14 +120,14 @@ void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& at, const [topHTMLView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES]; } -void WebDragClient::declareAndWriteDragImage(NSPasteboard* pasteboard, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame) +void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame) { - ASSERT(pasteboard); + ASSERT(pasteboardName); ASSERT(element); WebHTMLView *source = getTopHTMLView(frame); WebArchive *archive = [element webArchive]; - [pasteboard _web_declareAndWriteDragImageForElement:element URL:URL title:title archive:archive source:source]; + [[NSPasteboard pasteboardWithName:pasteboardName] _web_declareAndWriteDragImageForElement:element URL:URL title:title archive:archive source:source]; } void WebDragClient::dragControllerDestroyed() diff --git a/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h b/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h index 0d86c08..6506528 100644 --- a/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h +++ b/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.h @@ -61,6 +61,8 @@ private: virtual PassRefPtr bufferForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE; virtual void getPathnamesForType(Vector& pathnames, const String& pasteboardType, const String& pasteboardName) OVERRIDE; virtual String stringForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE; + virtual int changeCount(const String& pasteboardName) OVERRIDE; + virtual String uniqueName() OVERRIDE; virtual void copy(const String& fromPasteboard, const String& toPasteboard) OVERRIDE; virtual void setTypes(const Vector& pasteboardTypes, const String& pasteboardName) OVERRIDE; diff --git a/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm b/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm index 491078d..dd82394 100644 --- a/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm +++ b/Source/WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm @@ -127,6 +127,17 @@ void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toP return pasteboard.copy(fromPasteboard); } +int WebPlatformStrategies::changeCount(const String &pasteboardName) +{ + PlatformPasteboard pasteboard(pasteboardName); + return pasteboard.changeCount(); +} + +String WebPlatformStrategies::uniqueName() +{ + return PlatformPasteboard::uniqueName(); +} + void WebPlatformStrategies::setTypes(const Vector& pasteboardTypes, const String& pasteboardName) { PlatformPasteboard pasteboard(pasteboardName); diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index 3e5cc08..07def97 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,20 @@ +2012-02-15 Enrica Casucci + + Refactor ClipboardMac class to use PlatformStrategies. + https://bugs.webkit.org/show_bug.cgi?id=78554 + + Reviewed by Anders Carlsson. + + * 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. + 2012-02-15 Sadrul Habib Chowdhury Notify ChromeClient when touch-event handlers are installed/removed. diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h b/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h index 913eb6e..a9411ac 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h @@ -53,7 +53,7 @@ private: virtual void startDrag(WebCore::DragImageRef, const WebCore::IntPoint& dragImageOrigin, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag = false) OVERRIDE; #if PLATFORM(MAC) - virtual void declareAndWriteDragImage(NSPasteboard*, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE; + virtual void declareAndWriteDragImage(const String& pasteboardName, DOMElement*, NSURL*, NSString*, WebCore::Frame*) OVERRIDE; #endif virtual void dragEnded() OVERRIDE; diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp index 4c177bf..cd72610 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp @@ -164,6 +164,17 @@ void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toP return pasteboard.copy(fromPasteboard); } +int WebPlatformStrategies::changeCount(const WTF::String &pasteboardName) +{ + PlatformPasteboard pasteboard(pasteboardName); + return pasteboard.changeCount(); +} + +String WebPlatformStrategies::uniqueName() +{ + return PlatformPasteboard::uniqueName(); +} + void WebPlatformStrategies::setTypes(const Vector& pasteboardTypes, const String& pasteboardName) { PlatformPasteboard pasteboard(pasteboardName); diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h b/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h index 457753b..28c91bb 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h @@ -67,6 +67,8 @@ private: virtual PassRefPtr bufferForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE; virtual void getPathnamesForType(Vector& pathnames, const String& pasteboardType, const String& pasteboardName) OVERRIDE; virtual String stringForType(const String& pasteboardType, const String& pasteboardName) OVERRIDE; + virtual int changeCount(const String& pasteboardName) OVERRIDE; + virtual String uniqueName() OVERRIDE; virtual void copy(const String& fromPasteboard, const String& toPasteboard) OVERRIDE; virtual void setTypes(const Vector& pasteboardTypes, const String& pasteboardName) OVERRIDE; diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm b/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm index 1102735..da608dd 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm +++ b/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm @@ -125,10 +125,10 @@ static NSArray *arrayForURLsWithTitles(NSURL *URL, NSString *title) [NSArray arrayWithObject:[title _webkit_stringByTrimmingWhitespace]], nil]; } -void WebDragClient::declareAndWriteDragImage(NSPasteboard *pasteboard, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*) +void WebDragClient::declareAndWriteDragImage(const String& pasteboardName, DOMElement *element, NSURL *URL, NSString *title, WebCore::Frame*) { ASSERT(element); - ASSERT(pasteboard && pasteboard == [NSPasteboard pasteboardWithName:NSDragPboard]); + ASSERT(pasteboardName == String(NSDragPboard)); Element* coreElement = core(element); @@ -155,6 +155,7 @@ void WebDragClient::declareAndWriteDragImage(NSPasteboard *pasteboard, DOMElemen m_pasteboardOwner.adoptNS([[WKPasteboardOwner alloc] initWithImage:image]); m_filePromiseOwner.adoptNS([(WKPasteboardFilePromiseOwner *)[WKPasteboardFilePromiseOwner alloc] initWithSource:m_pasteboardOwner.get()]); + NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:pasteboardName]; [pasteboard declareTypes:types.get() owner:m_pasteboardOwner.leakRef()]; [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];