widget/xpwidgets/nsClipboardProxy.cpp

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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 "nsClipboardProxy.h"
     7 #include "nsISupportsPrimitives.h"
     8 #include "nsCOMPtr.h"
     9 #include "nsComponentManagerUtils.h"
    10 #include "nsXULAppAPI.h"
    12 using namespace mozilla;
    13 using mozilla::dom::ContentChild;
    15 NS_IMPL_ISUPPORTS(nsClipboardProxy, nsIClipboard)
    17 nsClipboardProxy::nsClipboardProxy()
    18 {
    19 }
    21 NS_IMETHODIMP
    22 nsClipboardProxy::SetData(nsITransferable *aTransferable,
    23 			  nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
    24 {
    25   nsCOMPtr<nsISupports> tmp;
    26   uint32_t len;
    27   nsresult rv  = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
    28                                                 &len);
    29   NS_ENSURE_SUCCESS(rv, rv);
    30   nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
    31   // No support for non-text data
    32   NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED);
    33   nsAutoString buffer;
    34   supportsString->GetData(buffer);
    36   bool isPrivateData = false;
    37   aTransferable->GetIsPrivateData(&isPrivateData);
    38   ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData,
    39 						     aWhichClipboard);
    41   return NS_OK;
    42 }
    44 NS_IMETHODIMP
    45 nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
    46 {
    47   nsAutoString buffer;
    48   ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer);
    50   nsresult rv;
    51   nsCOMPtr<nsISupportsString> dataWrapper =
    52     do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
    53   NS_ENSURE_SUCCESS(rv, rv);
    55   rv = dataWrapper->SetData(buffer);
    56   NS_ENSURE_SUCCESS(rv, rv);
    58   // If our data flavor has already been added, this will fail. But we don't care
    59   aTransferable->AddDataFlavor(kUnicodeMime);
    61   nsCOMPtr<nsISupports> nsisupportsDataWrapper =
    62     do_QueryInterface(dataWrapper);
    63   rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
    64                                       buffer.Length() * sizeof(char16_t));
    65   NS_ENSURE_SUCCESS(rv, rv);
    67   return NS_OK;
    68 }
    70 NS_IMETHODIMP
    71 nsClipboardProxy::EmptyClipboard(int32_t aWhichClipboard)
    72 {
    73   ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard);
    74   return NS_OK;
    75 }
    77 NS_IMETHODIMP
    78 nsClipboardProxy::HasDataMatchingFlavors(const char **aFlavorList,
    79                                     uint32_t aLength, int32_t aWhichClipboard,
    80                                     bool *aHasText)
    81 {
    82   *aHasText = false;
    83   ContentChild::GetSingleton()->SendClipboardHasText(aWhichClipboard, aHasText);
    84   return NS_OK;
    85 }
    87 NS_IMETHODIMP
    88 nsClipboardProxy::SupportsSelectionClipboard(bool *aIsSupported)
    89 {
    90   *aIsSupported = false;
    91   return NS_OK;
    92 }
    95 NS_IMETHODIMP
    96 nsClipboardProxy::SupportsFindClipboard(bool *aIsSupported)
    97 {
    98   *aIsSupported = false;
    99   return NS_OK;
   100 }

mercurial