Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 "nsClipboard.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 | #define LOG_TAG "Clipboard" |
michael@0 | 16 | #define LOGI(args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, ## args) |
michael@0 | 17 | #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args) |
michael@0 | 18 | |
michael@0 | 19 | NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard) |
michael@0 | 20 | |
michael@0 | 21 | nsClipboard::nsClipboard() |
michael@0 | 22 | { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | NS_IMETHODIMP |
michael@0 | 26 | nsClipboard::SetData(nsITransferable *aTransferable, |
michael@0 | 27 | nsIClipboardOwner *anOwner, int32_t aWhichClipboard) |
michael@0 | 28 | { |
michael@0 | 29 | if (aWhichClipboard != kGlobalClipboard) { |
michael@0 | 30 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | nsCOMPtr<nsISupports> tmp; |
michael@0 | 34 | uint32_t len; |
michael@0 | 35 | nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), |
michael@0 | 36 | &len); |
michael@0 | 37 | if (NS_WARN_IF(NS_FAILED(rv))) { |
michael@0 | 38 | return rv; |
michael@0 | 39 | } |
michael@0 | 40 | nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp); |
michael@0 | 41 | // No support for non-text data |
michael@0 | 42 | if (NS_WARN_IF(!supportsString)) { |
michael@0 | 43 | LOGE("No support for non-text data. See bug 952456."); |
michael@0 | 44 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 45 | } |
michael@0 | 46 | nsAutoString buffer; |
michael@0 | 47 | supportsString->GetData(buffer); |
michael@0 | 48 | |
michael@0 | 49 | if (XRE_GetProcessType() == GeckoProcessType_Default) { |
michael@0 | 50 | mClipboard = buffer; |
michael@0 | 51 | } else { |
michael@0 | 52 | bool isPrivateData = false; |
michael@0 | 53 | aTransferable->GetIsPrivateData(&isPrivateData); |
michael@0 | 54 | ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData, |
michael@0 | 55 | aWhichClipboard); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | return NS_OK; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | NS_IMETHODIMP |
michael@0 | 62 | nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) |
michael@0 | 63 | { |
michael@0 | 64 | if (aWhichClipboard != kGlobalClipboard) { |
michael@0 | 65 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | nsAutoString buffer; |
michael@0 | 69 | if (XRE_GetProcessType() == GeckoProcessType_Default) { |
michael@0 | 70 | buffer = mClipboard; |
michael@0 | 71 | } else { |
michael@0 | 72 | ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | nsresult rv; |
michael@0 | 76 | nsCOMPtr<nsISupportsString> dataWrapper = |
michael@0 | 77 | do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); |
michael@0 | 78 | if (NS_WARN_IF(NS_FAILED(rv))) { |
michael@0 | 79 | return rv; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | rv = dataWrapper->SetData(buffer); |
michael@0 | 83 | if (NS_WARN_IF(NS_FAILED(rv))) { |
michael@0 | 84 | return rv; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | // If our data flavor has already been added, this will fail. But we don't care |
michael@0 | 88 | aTransferable->AddDataFlavor(kUnicodeMime); |
michael@0 | 89 | |
michael@0 | 90 | nsCOMPtr<nsISupports> nsisupportsDataWrapper = |
michael@0 | 91 | do_QueryInterface(dataWrapper); |
michael@0 | 92 | rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper, |
michael@0 | 93 | buffer.Length() * sizeof(PRUnichar)); |
michael@0 | 94 | if (NS_WARN_IF(NS_FAILED(rv))) { |
michael@0 | 95 | return rv; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | return NS_OK; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | NS_IMETHODIMP |
michael@0 | 102 | nsClipboard::EmptyClipboard(int32_t aWhichClipboard) |
michael@0 | 103 | { |
michael@0 | 104 | if (aWhichClipboard != kGlobalClipboard) { |
michael@0 | 105 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 106 | } |
michael@0 | 107 | if (XRE_GetProcessType() == GeckoProcessType_Default) { |
michael@0 | 108 | mClipboard.Truncate(0); |
michael@0 | 109 | } else { |
michael@0 | 110 | ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | return NS_OK; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | NS_IMETHODIMP |
michael@0 | 117 | nsClipboard::HasDataMatchingFlavors(const char **aFlavorList, |
michael@0 | 118 | uint32_t aLength, int32_t aWhichClipboard, |
michael@0 | 119 | bool *aHasText) |
michael@0 | 120 | { |
michael@0 | 121 | *aHasText = false; |
michael@0 | 122 | if (aWhichClipboard != kGlobalClipboard) { |
michael@0 | 123 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 124 | } |
michael@0 | 125 | if (XRE_GetProcessType() == GeckoProcessType_Default) { |
michael@0 | 126 | *aHasText = !mClipboard.IsEmpty(); |
michael@0 | 127 | } else { |
michael@0 | 128 | ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText); |
michael@0 | 129 | } |
michael@0 | 130 | return NS_OK; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | NS_IMETHODIMP |
michael@0 | 134 | nsClipboard::SupportsSelectionClipboard(bool *aIsSupported) |
michael@0 | 135 | { |
michael@0 | 136 | *aIsSupported = false; |
michael@0 | 137 | return NS_OK; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | NS_IMETHODIMP |
michael@0 | 141 | nsClipboard::SupportsFindClipboard(bool* _retval) |
michael@0 | 142 | { |
michael@0 | 143 | NS_ENSURE_ARG_POINTER(_retval); |
michael@0 | 144 | |
michael@0 | 145 | *_retval = false; |
michael@0 | 146 | return NS_OK; |
michael@0 | 147 | } |
michael@0 | 148 |