| 1 | /* |
| 2 | * Copyright (C) 2014 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. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "MessageReceiver.h" |
| 29 | #include "SandboxExtension.h" |
| 30 | #include "SharedMemory.h" |
| 31 | #include <wtf/Forward.h> |
| 32 | #include <wtf/HashSet.h> |
| 33 | |
| 34 | namespace WebCore { |
| 35 | class Color; |
| 36 | struct PasteboardCustomData; |
| 37 | struct PasteboardImage; |
| 38 | struct PasteboardItemInfo; |
| 39 | struct PasteboardURL; |
| 40 | struct PasteboardWebContent; |
| 41 | } |
| 42 | |
| 43 | namespace WebKit { |
| 44 | |
| 45 | class WebFrameProxy; |
| 46 | class WebProcessProxy; |
| 47 | struct WebSelectionData; |
| 48 | |
| 49 | class WebPasteboardProxy : public IPC::MessageReceiver { |
| 50 | WTF_MAKE_NONCOPYABLE(WebPasteboardProxy); |
| 51 | friend LazyNeverDestroyed<WebPasteboardProxy>; |
| 52 | public: |
| 53 | static WebPasteboardProxy& singleton(); |
| 54 | |
| 55 | void addWebProcessProxy(WebProcessProxy&); |
| 56 | void removeWebProcessProxy(WebProcessProxy&); |
| 57 | |
| 58 | #if PLATFORM(GTK) |
| 59 | void setPrimarySelectionOwner(WebFrameProxy*); |
| 60 | void didDestroyFrame(WebFrameProxy*); |
| 61 | #endif |
| 62 | |
| 63 | private: |
| 64 | WebPasteboardProxy(); |
| 65 | |
| 66 | typedef HashSet<WebProcessProxy*> WebProcessProxyList; |
| 67 | |
| 68 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
| 69 | void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override; |
| 70 | |
| 71 | #if PLATFORM(IOS_FAMILY) |
| 72 | void writeURLToPasteboard(const WebCore::PasteboardURL&, const String& pasteboardName); |
| 73 | void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&, const String& pasteboardName); |
| 74 | void writeImageToPasteboard(const WebCore::PasteboardImage&, const String& pasteboardName); |
| 75 | void writeStringToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName); |
| 76 | void readStringFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&&); |
| 77 | void readURLFromPasteboard(uint64_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&); |
| 78 | void readBufferFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&&); |
| 79 | void getPasteboardItemsCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&&); |
| 80 | void allPasteboardItemInfo(const String& pasteboardName, CompletionHandler<void(Vector<WebCore::PasteboardItemInfo>&&)>&&); |
| 81 | void informationForItemAtIndex(int index, const String& pasteboardName, CompletionHandler<void(WebCore::PasteboardItemInfo&&)>&&); |
| 82 | void updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName); |
| 83 | #endif |
| 84 | #if PLATFORM(COCOA) |
| 85 | void getNumberOfFiles(const String& pasteboardName, CompletionHandler<void(uint64_t)>&&); |
| 86 | void getPasteboardTypes(const String& pasteboardName, CompletionHandler<void(Vector<String>&&)>&&); |
| 87 | void getPasteboardPathnamesForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&& pathnames, SandboxExtension::HandleArray&&)>&&); |
| 88 | void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(String&&)>&&); |
| 89 | void getPasteboardStringsForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&&)>&&); |
| 90 | void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&&); |
| 91 | void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard, CompletionHandler<void(uint64_t)>&&); |
| 92 | void getPasteboardChangeCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&&); |
| 93 | void getPasteboardUniqueName(CompletionHandler<void(String&&)>&&); |
| 94 | void getPasteboardColor(const String& pasteboardName, CompletionHandler<void(WebCore::Color&&)>&&); |
| 95 | void getPasteboardURL(const String& pasteboardName, CompletionHandler<void(const String&)>&&); |
| 96 | void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(uint64_t)>&&); |
| 97 | void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, CompletionHandler<void(uint64_t)>&&); |
| 98 | void setPasteboardURL(IPC::Connection&, const WebCore::PasteboardURL&, const String& pasteboardName, CompletionHandler<void(uint64_t)>&&); |
| 99 | void setPasteboardColor(const String&, const WebCore::Color&, CompletionHandler<void(uint64_t)>&&); |
| 100 | void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, CompletionHandler<void(uint64_t)>&&); |
| 101 | void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, CompletionHandler<void(uint64_t)>&&); |
| 102 | #endif |
| 103 | |
| 104 | void writeCustomData(const WebCore::PasteboardCustomData&, const String& pasteboardName, CompletionHandler<void(uint64_t)>&&); |
| 105 | void typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin, CompletionHandler<void(Vector<String>&&)>&&); |
| 106 | |
| 107 | #if PLATFORM(GTK) |
| 108 | void writeToClipboard(const String& pasteboardName, const WebSelectionData&); |
| 109 | void readFromClipboard(const String& pasteboardName, CompletionHandler<void(WebSelectionData&&)>&&); |
| 110 | |
| 111 | WebFrameProxy* m_primarySelectionOwner { nullptr }; |
| 112 | WebFrameProxy* m_frameWritingToClipboard { nullptr }; |
| 113 | #endif // PLATFORM(GTK) |
| 114 | |
| 115 | #if USE(LIBWPE) |
| 116 | void getPasteboardTypes(CompletionHandler<void(Vector<String>&&)>&&); |
| 117 | void readStringFromPasteboard(uint64_t index, const String& pasteboardType, CompletionHandler<void(String&&)>&&); |
| 118 | void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&); |
| 119 | void writeStringToPasteboard(const String& pasteboardType, const String&); |
| 120 | #endif |
| 121 | |
| 122 | WebProcessProxyList m_webProcessProxyList; |
| 123 | }; |
| 124 | |
| 125 | } // namespace WebKit |
| 126 | |