diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-05 14:34:32 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-05 14:34:32 -0800 |
commit | 635860845790a19bf50bbc51ba8fb66a96dde068 (patch) | |
tree | ef6ad9ff73a5b57f65249d4232a202fa77e6a140 /WebKit/mac/Misc/WebNSPasteboardExtras.mm | |
parent | 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 (diff) | |
download | external_webkit-635860845790a19bf50bbc51ba8fb66a96dde068.zip external_webkit-635860845790a19bf50bbc51ba8fb66a96dde068.tar.gz external_webkit-635860845790a19bf50bbc51ba8fb66a96dde068.tar.bz2 |
auto import from //depot/cupcake/@136594
Diffstat (limited to 'WebKit/mac/Misc/WebNSPasteboardExtras.mm')
-rw-r--r-- | WebKit/mac/Misc/WebNSPasteboardExtras.mm | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/WebKit/mac/Misc/WebNSPasteboardExtras.mm b/WebKit/mac/Misc/WebNSPasteboardExtras.mm index b84542a..34c39dd 100644 --- a/WebKit/mac/Misc/WebNSPasteboardExtras.mm +++ b/WebKit/mac/Misc/WebNSPasteboardExtras.mm @@ -41,6 +41,7 @@ #import <WebKit/DOMExtensions.h> #import <WebKit/DOMPrivate.h> #import <wtf/Assertions.h> +#import <wtf/StdLibExtras.h> #import <wtf/RetainPtr.h> #import <WebKitSystemInterface.h> @@ -58,37 +59,40 @@ NSString *WebURLNamePboardType = @"public.url-name"; + (NSArray *)_web_writableTypesForURL { - static RetainPtr<NSArray> types; - if (!types) { - types = [[NSArray alloc] initWithObjects: - WebURLsWithTitlesPboardType, - NSURLPboardType, - WebURLPboardType, - WebURLNamePboardType, - NSStringPboardType, - nil]; - } + DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, types, ([[NSArray alloc] initWithObjects: + WebURLsWithTitlesPboardType, + NSURLPboardType, + WebURLPboardType, + WebURLNamePboardType, + NSStringPboardType, + nil])); return types.get(); } +static inline NSArray *_createWritableTypesForImageWithoutArchive() +{ + NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSTIFFPboardType, nil]; + [types addObjectsFromArray:[NSPasteboard _web_writableTypesForURL]]; + return types; +} + static NSArray *_writableTypesForImageWithoutArchive (void) { - static RetainPtr<NSMutableArray> types; - if (types == nil) { - types = [[NSMutableArray alloc] initWithObjects:NSTIFFPboardType, nil]; - [types.get() addObjectsFromArray:[NSPasteboard _web_writableTypesForURL]]; - } + DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, types, (_createWritableTypesForImageWithoutArchive())); return types.get(); } +static inline NSArray *_createWritableTypesForImageWithArchive() +{ + NSMutableArray *types = [_writableTypesForImageWithoutArchive() mutableCopy]; + [types addObject:NSRTFDPboardType]; + [types addObject:WebArchivePboardType]; + return types; +} + static NSArray *_writableTypesForImageWithArchive (void) { - static RetainPtr<NSMutableArray> types; - if (types == nil) { - types = [_writableTypesForImageWithoutArchive() mutableCopy]; - [types.get() addObject:NSRTFDPboardType]; - [types.get() addObject:WebArchivePboardType]; - } + DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, types, (_createWritableTypesForImageWithArchive())); return types.get(); } @@ -207,7 +211,7 @@ static NSArray *_writableTypesForImageWithArchive (void) } -CachedImage* imageFromElement(DOMElement *domElement) { +static CachedImage* imageFromElement(DOMElement *domElement) { Element* element = core(domElement); if (!element) return 0; @@ -259,18 +263,23 @@ CachedImage* imageFromElement(DOMElement *domElement) { { ASSERT(self == [NSPasteboard pasteboardWithName:NSDragPboard]); + NSString *extension = @""; + if (RenderObject* renderer = core(element)->renderer()) { + if (renderer->isImage()) { + if (CachedImage* image = static_cast<RenderImage*>(renderer)->cachedImage()) { + extension = image->image()->filenameExtension(); + if (![extension length]) + return 0; + } + } + } + NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]; [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImageIncludingArchive:(archive != nil)]]; [self declareTypes:types owner:source]; [self _web_writeImage:nil element:element URL:URL title:title archive:archive types:types source:source]; [types release]; - NSString *extension = @""; - if (RenderObject* renderer = core(element)->renderer()) - if (renderer->isImage()) - if (CachedImage* image = static_cast<RenderImage*>(renderer)->cachedImage()) - extension = WKGetPreferredExtensionForMIMEType(image->response().mimeType()); - NSArray *extensions = [[NSArray alloc] initWithObjects:extension, nil]; [self setPropertyList:extensions forType:NSFilesPromisePboardType]; [extensions release]; |