1 | /* |
2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
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. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE 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 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. |
24 | */ |
25 | |
26 | #ifndef PlatformPasteboard_h |
27 | #define PlatformPasteboard_h |
28 | |
29 | #include <wtf/Forward.h> |
30 | #include <wtf/Function.h> |
31 | #include <wtf/RetainPtr.h> |
32 | #include <wtf/Vector.h> |
33 | |
34 | #if PLATFORM(MAC) |
35 | OBJC_CLASS NSPasteboard; |
36 | #endif |
37 | |
38 | #if PLATFORM(IOS_FAMILY) |
39 | OBJC_CLASS UIPasteboard; |
40 | #endif |
41 | |
42 | #if USE(LIBWPE) |
43 | struct wpe_pasteboard; |
44 | #endif |
45 | |
46 | namespace WebCore { |
47 | |
48 | class Color; |
49 | class SelectionData; |
50 | class SharedBuffer; |
51 | struct PasteboardCustomData; |
52 | struct PasteboardImage; |
53 | struct PasteboardItemInfo; |
54 | struct PasteboardURL; |
55 | struct PasteboardWebContent; |
56 | |
57 | class PlatformPasteboard { |
58 | public: |
59 | WEBCORE_EXPORT explicit PlatformPasteboard(const String& pasteboardName); |
60 | #if PLATFORM(IOS_FAMILY) || USE(LIBWPE) |
61 | WEBCORE_EXPORT PlatformPasteboard(); |
62 | WEBCORE_EXPORT Vector<PasteboardItemInfo> allPasteboardItemInfo(); |
63 | WEBCORE_EXPORT PasteboardItemInfo informationForItemAtIndex(int index); |
64 | WEBCORE_EXPORT void updateSupportedTypeIdentifiers(const Vector<String>& types); |
65 | #endif |
66 | WEBCORE_EXPORT static String uniqueName(); |
67 | |
68 | WEBCORE_EXPORT static String platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType); |
69 | |
70 | WEBCORE_EXPORT void getTypes(Vector<String>& types); |
71 | WEBCORE_EXPORT RefPtr<SharedBuffer> bufferForType(const String& pasteboardType); |
72 | WEBCORE_EXPORT void getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType) const; |
73 | WEBCORE_EXPORT String stringForType(const String& pasteboardType) const; |
74 | WEBCORE_EXPORT Vector<String> allStringsForType(const String& pasteboardType) const; |
75 | WEBCORE_EXPORT long changeCount() const; |
76 | WEBCORE_EXPORT Color color(); |
77 | WEBCORE_EXPORT URL url(); |
78 | |
79 | // Take ownership of the pasteboard, and return new change count. |
80 | WEBCORE_EXPORT long addTypes(const Vector<String>& pasteboardTypes); |
81 | WEBCORE_EXPORT long setTypes(const Vector<String>& pasteboardTypes); |
82 | |
83 | // These methods will return 0 if pasteboard ownership has been taken from us. |
84 | WEBCORE_EXPORT long copy(const String& fromPasteboard); |
85 | WEBCORE_EXPORT long setBufferForType(SharedBuffer*, const String& pasteboardType); |
86 | WEBCORE_EXPORT long setURL(const PasteboardURL&); |
87 | WEBCORE_EXPORT long setColor(const Color&); |
88 | WEBCORE_EXPORT long setStringForType(const String&, const String& pasteboardType); |
89 | WEBCORE_EXPORT void write(const PasteboardWebContent&); |
90 | WEBCORE_EXPORT void write(const PasteboardImage&); |
91 | WEBCORE_EXPORT void write(const String& pasteboardType, const String&); |
92 | WEBCORE_EXPORT void write(const PasteboardURL&); |
93 | WEBCORE_EXPORT RefPtr<SharedBuffer> readBuffer(int index, const String& pasteboardType) const; |
94 | WEBCORE_EXPORT String readString(int index, const String& pasteboardType) const; |
95 | WEBCORE_EXPORT URL readURL(int index, String& title) const; |
96 | WEBCORE_EXPORT int count() const; |
97 | WEBCORE_EXPORT int numberOfFiles() const; |
98 | |
99 | WEBCORE_EXPORT long write(const PasteboardCustomData&); |
100 | WEBCORE_EXPORT Vector<String> typesSafeForDOMToReadAndWrite(const String& origin) const; |
101 | |
102 | #if PLATFORM(GTK) |
103 | WEBCORE_EXPORT void writeToClipboard(const SelectionData&, WTF::Function<void()>&& primarySelectionCleared); |
104 | WEBCORE_EXPORT Ref<SelectionData> readFromClipboard(); |
105 | #endif |
106 | |
107 | private: |
108 | #if PLATFORM(IOS_FAMILY) |
109 | bool allowReadingURLAtIndex(const URL&, int index) const; |
110 | #endif |
111 | |
112 | #if PLATFORM(MAC) |
113 | RetainPtr<NSPasteboard> m_pasteboard; |
114 | #endif |
115 | #if PLATFORM(IOS_FAMILY) |
116 | RetainPtr<id> m_pasteboard; |
117 | #endif |
118 | #if PLATFORM(GTK) |
119 | GtkClipboard* m_clipboard; |
120 | #endif |
121 | #if USE(LIBWPE) |
122 | struct wpe_pasteboard* m_pasteboard; |
123 | #endif |
124 | }; |
125 | |
126 | } |
127 | |
128 | #endif // !PlatformPasteboard_h |
129 | |