1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/xpwidgets/nsClipboardProxy.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "mozilla/dom/ContentChild.h" 1.9 +#include "nsClipboardProxy.h" 1.10 +#include "nsISupportsPrimitives.h" 1.11 +#include "nsCOMPtr.h" 1.12 +#include "nsComponentManagerUtils.h" 1.13 +#include "nsXULAppAPI.h" 1.14 + 1.15 +using namespace mozilla; 1.16 +using mozilla::dom::ContentChild; 1.17 + 1.18 +NS_IMPL_ISUPPORTS(nsClipboardProxy, nsIClipboard) 1.19 + 1.20 +nsClipboardProxy::nsClipboardProxy() 1.21 +{ 1.22 +} 1.23 + 1.24 +NS_IMETHODIMP 1.25 +nsClipboardProxy::SetData(nsITransferable *aTransferable, 1.26 + nsIClipboardOwner *anOwner, int32_t aWhichClipboard) 1.27 +{ 1.28 + nsCOMPtr<nsISupports> tmp; 1.29 + uint32_t len; 1.30 + nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), 1.31 + &len); 1.32 + NS_ENSURE_SUCCESS(rv, rv); 1.33 + nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp); 1.34 + // No support for non-text data 1.35 + NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED); 1.36 + nsAutoString buffer; 1.37 + supportsString->GetData(buffer); 1.38 + 1.39 + bool isPrivateData = false; 1.40 + aTransferable->GetIsPrivateData(&isPrivateData); 1.41 + ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData, 1.42 + aWhichClipboard); 1.43 + 1.44 + return NS_OK; 1.45 +} 1.46 + 1.47 +NS_IMETHODIMP 1.48 +nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) 1.49 +{ 1.50 + nsAutoString buffer; 1.51 + ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer); 1.52 + 1.53 + nsresult rv; 1.54 + nsCOMPtr<nsISupportsString> dataWrapper = 1.55 + do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); 1.56 + NS_ENSURE_SUCCESS(rv, rv); 1.57 + 1.58 + rv = dataWrapper->SetData(buffer); 1.59 + NS_ENSURE_SUCCESS(rv, rv); 1.60 + 1.61 + // If our data flavor has already been added, this will fail. But we don't care 1.62 + aTransferable->AddDataFlavor(kUnicodeMime); 1.63 + 1.64 + nsCOMPtr<nsISupports> nsisupportsDataWrapper = 1.65 + do_QueryInterface(dataWrapper); 1.66 + rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper, 1.67 + buffer.Length() * sizeof(char16_t)); 1.68 + NS_ENSURE_SUCCESS(rv, rv); 1.69 + 1.70 + return NS_OK; 1.71 +} 1.72 + 1.73 +NS_IMETHODIMP 1.74 +nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard) 1.75 +{ 1.76 + ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard); 1.77 + return NS_OK; 1.78 +} 1.79 + 1.80 +NS_IMETHODIMP 1.81 +nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList, 1.82 + uint32_t aLength, int32_t aWhichClipboard, 1.83 + bool *aHasText) 1.84 +{ 1.85 + *aHasText = false; 1.86 + ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText); 1.87 + return NS_OK; 1.88 +} 1.89 + 1.90 +NS_IMETHODIMP 1.91 +nsClipboardProxy::SupportsSelectionClipboard(bool *aIsSupported) 1.92 +{ 1.93 + *aIsSupported = false; 1.94 + return NS_OK; 1.95 +} 1.96 + 1.97 + 1.98 +NS_IMETHODIMP 1.99 +nsClipboardProxy::SupportsFindClipboard(bool *aIsSupported) 1.100 +{ 1.101 + *aIsSupported = false; 1.102 + return NS_OK; 1.103 +}