2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #import "WebArchive.h"
27 #import "WebHTMLViewInternal.h"
28 #import "WebNSPasteboardExtras.h"
29 #import "WebNSURLExtras.h"
30 #import "WebPasteboardHelper.h"
32 #import <WebCore/DOMDocument.h>
33 #import <WebCore/DOMDocumentFragment.h>
34 #import <WebCore/PlatformString.h>
35 #import <wtf/RetainPtr.h>
37 using namespace WebCore;
39 String WebPasteboardHelper::urlFromPasteboard(const NSPasteboard* pasteboard, String* title) const
41 NSURL *URL = [pasteboard _web_bestURL];
43 if (NSString *URLTitleString = [pasteboard stringForType:WebURLNamePboardType])
44 *title = URLTitleString;
47 return [URL _web_originalDataAsString];
50 String WebPasteboardHelper::plainTextFromPasteboard(const NSPasteboard *pasteboard) const
52 NSArray *types = [pasteboard types];
54 if ([types containsObject:NSStringPboardType])
55 return [pasteboard stringForType:NSStringPboardType];
57 NSAttributedString *attributedString = nil;
60 if ([types containsObject:NSRTFDPboardType])
61 attributedString = [[NSAttributedString alloc] initWithRTFD:[pasteboard dataForType:NSRTFDPboardType] documentAttributes:nil];
62 if (!attributedString && [types containsObject:NSRTFPboardType])
63 attributedString = [[NSAttributedString alloc] initWithRTF:[pasteboard dataForType:NSRTFPboardType] documentAttributes:nil];
64 if (attributedString) {
65 string = [[attributedString string] copy];
66 [attributedString release];
67 return [string autorelease];
70 if ([types containsObject:NSFilenamesPboardType]) {
71 string = [[pasteboard propertyListForType:NSFilenamesPboardType] componentsJoinedByString:@"\n"];
78 if ((URL = [NSURL URLFromPasteboard:pasteboard])) {
79 string = [URL _web_userVisibleString];
80 if ([string length] > 0)
87 DOMDocumentFragment *WebPasteboardHelper::fragmentFromPasteboard(const NSPasteboard *pasteboard) const
89 return [m_view _documentFragmentFromPasteboard:pasteboard];
92 NSArray *WebPasteboardHelper::insertablePasteboardTypes() const
94 static RetainPtr<NSArray> types = [[NSArray alloc] initWithObjects:WebArchivePboardType, NSHTMLPboardType,
95 NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSURLPboardType,
96 NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, NSColorPboardType, nil];