Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "mozilla/dom/ContentChild.h" |
michael@0 | 6 | #include "nsClipboardProxy.h" |
michael@0 | 7 | #include "nsISupportsPrimitives.h" |
michael@0 | 8 | #include "nsCOMPtr.h" |
michael@0 | 9 | #include "nsComponentManagerUtils.h" |
michael@0 | 10 | #include "nsXULAppAPI.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace mozilla; |
michael@0 | 13 | using mozilla::dom::ContentChild; |
michael@0 | 14 | |
michael@0 | 15 | NS_IMPL_ISUPPORTS(nsClipboardProxy, nsIClipboard) |
michael@0 | 16 | |
michael@0 | 17 | nsClipboardProxy::nsClipboardProxy() |
michael@0 | 18 | { |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | NS_IMETHODIMP |
michael@0 | 22 | nsClipboardProxy::SetData(nsITransferable *aTransferable, |
michael@0 | 23 | nsIClipboardOwner *anOwner, int32_t aWhichClipboard) |
michael@0 | 24 | { |
michael@0 | 25 | nsCOMPtr<nsISupports> tmp; |
michael@0 | 26 | uint32_t len; |
michael@0 | 27 | nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), |
michael@0 | 28 | &len); |
michael@0 | 29 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 30 | nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp); |
michael@0 | 31 | // No support for non-text data |
michael@0 | 32 | NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED); |
michael@0 | 33 | nsAutoString buffer; |
michael@0 | 34 | supportsString->GetData(buffer); |
michael@0 | 35 | |
michael@0 | 36 | bool isPrivateData = false; |
michael@0 | 37 | aTransferable->GetIsPrivateData(&isPrivateData); |
michael@0 | 38 | ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData, |
michael@0 | 39 | aWhichClipboard); |
michael@0 | 40 | |
michael@0 | 41 | return NS_OK; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | NS_IMETHODIMP |
michael@0 | 45 | nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) |
michael@0 | 46 | { |
michael@0 | 47 | nsAutoString buffer; |
michael@0 | 48 | ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer); |
michael@0 | 49 | |
michael@0 | 50 | nsresult rv; |
michael@0 | 51 | nsCOMPtr<nsISupportsString> dataWrapper = |
michael@0 | 52 | do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); |
michael@0 | 53 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 54 | |
michael@0 | 55 | rv = dataWrapper->SetData(buffer); |
michael@0 | 56 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 57 | |
michael@0 | 58 | // If our data flavor has already been added, this will fail. But we don't care |
michael@0 | 59 | aTransferable->AddDataFlavor(kUnicodeMime); |
michael@0 | 60 | |
michael@0 | 61 | nsCOMPtr<nsISupports> nsisupportsDataWrapper = |
michael@0 | 62 | do_QueryInterface(dataWrapper); |
michael@0 | 63 | rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper, |
michael@0 | 64 | buffer.Length() * sizeof(char16_t)); |
michael@0 | 65 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 66 | |
michael@0 | 67 | return NS_OK; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | NS_IMETHODIMP |
michael@0 | 71 | nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard) |
michael@0 | 72 | { |
michael@0 | 73 | ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard); |
michael@0 | 74 | return NS_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP |
michael@0 | 78 | nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList, |
michael@0 | 79 | uint32_t aLength, int32_t aWhichClipboard, |
michael@0 | 80 | bool *aHasText) |
michael@0 | 81 | { |
michael@0 | 82 | *aHasText = false; |
michael@0 | 83 | ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText); |
michael@0 | 84 | return NS_OK; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | NS_IMETHODIMP |
michael@0 | 88 | nsClipboardProxy::SupportsSelectionClipboard(bool *aIsSupported) |
michael@0 | 89 | { |
michael@0 | 90 | *aIsSupported = false; |
michael@0 | 91 | return NS_OK; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | |
michael@0 | 95 | NS_IMETHODIMP |
michael@0 | 96 | nsClipboardProxy::SupportsFindClipboard(bool *aIsSupported) |
michael@0 | 97 | { |
michael@0 | 98 | *aIsSupported = false; |
michael@0 | 99 | return NS_OK; |
michael@0 | 100 | } |