widget/android/nsClipboard.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "mozilla/dom/ContentChild.h"
     6 #include "nsClipboard.h"
     7 #include "nsISupportsPrimitives.h"
     8 #include "AndroidBridge.h"
     9 #include "nsCOMPtr.h"
    10 #include "nsComponentManagerUtils.h"
    11 #include "nsXULAppAPI.h"
    13 using namespace mozilla;
    14 using mozilla::dom::ContentChild;
    16 NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
    18 /* The Android clipboard only supports text and doesn't support mime types
    19  * so we assume all clipboard data is text/unicode for now. Documentation
    20  * indicates that support for other data types is planned for future
    21  * releases.
    22  */
    24 nsClipboard::nsClipboard()
    25 {
    26 }
    28 NS_IMETHODIMP
    29 nsClipboard::SetData(nsITransferable *aTransferable,
    30                      nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
    31 {
    32   if (aWhichClipboard != kGlobalClipboard)
    33     return NS_ERROR_NOT_IMPLEMENTED;
    35   nsCOMPtr<nsISupports> tmp;
    36   uint32_t len;
    37   nsresult rv  = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
    38                                                 &len);
    39   NS_ENSURE_SUCCESS(rv, rv);
    40   nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
    41   // No support for non-text data
    42   NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED);
    43   nsAutoString buffer;
    44   supportsString->GetData(buffer);
    46   mozilla::widget::android::Clipboard::SetClipboardText(buffer);
    47   return NS_OK;
    48 }
    50 NS_IMETHODIMP
    51 nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
    52 {
    53   if (aWhichClipboard != kGlobalClipboard)
    54     return NS_ERROR_NOT_IMPLEMENTED;
    56   nsAutoString buffer;
    57   if (!AndroidBridge::Bridge())
    58     return NS_ERROR_NOT_IMPLEMENTED;
    59   if (!AndroidBridge::Bridge()->GetClipboardText(buffer))
    60     return NS_ERROR_UNEXPECTED;
    62   nsresult rv;
    63   nsCOMPtr<nsISupportsString> dataWrapper =
    64     do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
    65   NS_ENSURE_SUCCESS(rv, rv);
    67   rv = dataWrapper->SetData(buffer);
    68   NS_ENSURE_SUCCESS(rv, rv);
    70   // If our data flavor has already been added, this will fail. But we don't care
    71   aTransferable->AddDataFlavor(kUnicodeMime);
    73   nsCOMPtr<nsISupports> nsisupportsDataWrapper =
    74     do_QueryInterface(dataWrapper);
    75   rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
    76                                       buffer.Length() * sizeof(char16_t));
    77   NS_ENSURE_SUCCESS(rv, rv);
    79   return NS_OK;
    80 }
    82 NS_IMETHODIMP
    83 nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
    84 {
    85   if (aWhichClipboard != kGlobalClipboard)
    86     return NS_ERROR_NOT_IMPLEMENTED;
    87   mozilla::widget::android::Clipboard::ClearText();
    89   return NS_OK;
    90 }
    92 NS_IMETHODIMP
    93 nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
    94                                     uint32_t aLength, int32_t aWhichClipboard,
    95                                     bool *aHasText)
    96 {
    97   *aHasText = false;
    98   if (aWhichClipboard != kGlobalClipboard)
    99     return NS_ERROR_NOT_IMPLEMENTED;
   100   *aHasText = mozilla::widget::android::Clipboard::HasText();
   101   return NS_OK;
   102 }
   104 NS_IMETHODIMP
   105 nsClipboard::SupportsSelectionClipboard(bool *aIsSupported)
   106 {
   107   *aIsSupported = false;
   108   return NS_OK;
   109 }
   111 NS_IMETHODIMP
   112 nsClipboard::SupportsFindClipboard(bool* _retval)
   113 {
   114   *_retval = false;
   115   return NS_OK;
   116 }

mercurial