michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/ContentChild.h" michael@0: #include "nsClipboardProxy.h" michael@0: #include "nsISupportsPrimitives.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsXULAppAPI.h" michael@0: michael@0: using namespace mozilla; michael@0: using mozilla::dom::ContentChild; michael@0: michael@0: NS_IMPL_ISUPPORTS(nsClipboardProxy, nsIClipboard) michael@0: michael@0: nsClipboardProxy::nsClipboardProxy() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboardProxy::SetData(nsITransferable *aTransferable, michael@0: nsIClipboardOwner *anOwner, int32_t aWhichClipboard) michael@0: { michael@0: nsCOMPtr tmp; michael@0: uint32_t len; michael@0: nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), michael@0: &len); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: nsCOMPtr supportsString = do_QueryInterface(tmp); michael@0: // No support for non-text data michael@0: NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED); michael@0: nsAutoString buffer; michael@0: supportsString->GetData(buffer); michael@0: michael@0: bool isPrivateData = false; michael@0: aTransferable->GetIsPrivateData(&isPrivateData); michael@0: ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData, michael@0: aWhichClipboard); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) michael@0: { michael@0: nsAutoString buffer; michael@0: ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer); michael@0: michael@0: nsresult rv; michael@0: nsCOMPtr dataWrapper = michael@0: do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: rv = dataWrapper->SetData(buffer); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: // If our data flavor has already been added, this will fail. But we don't care michael@0: aTransferable->AddDataFlavor(kUnicodeMime); michael@0: michael@0: nsCOMPtr nsisupportsDataWrapper = michael@0: do_QueryInterface(dataWrapper); michael@0: rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper, michael@0: buffer.Length() * sizeof(char16_t)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard) michael@0: { michael@0: ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList, michael@0: uint32_t aLength, int32_t aWhichClipboard, michael@0: bool *aHasText) michael@0: { michael@0: *aHasText = false; michael@0: ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboardProxy::SupportsSelectionClipboard(bool *aIsSupported) michael@0: { michael@0: *aIsSupported = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsClipboardProxy::SupportsFindClipboard(bool *aIsSupported) michael@0: { michael@0: *aIsSupported = false; michael@0: return NS_OK; michael@0: }