widget/xpwidgets/nsBaseClipboard.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsBaseClipboard.h"
     8 #include "nsIClipboardOwner.h"
     9 #include "nsCOMPtr.h"
    10 #include "nsXPCOM.h"
    11 #include "nsISupportsPrimitives.h"
    13 nsBaseClipboard::nsBaseClipboard()
    14 {
    15   mClipboardOwner          = nullptr;
    16   mTransferable            = nullptr;
    17   mIgnoreEmptyNotification = false;
    18   mEmptyingForSetData      = false;
    19 }
    21 nsBaseClipboard::~nsBaseClipboard()
    22 {
    23   EmptyClipboard(kSelectionClipboard);
    24   EmptyClipboard(kGlobalClipboard);
    25   EmptyClipboard(kFindClipboard);
    26 }
    28 NS_IMPL_ISUPPORTS(nsBaseClipboard, nsIClipboard)
    30 /**
    31   * Sets the transferable object
    32   *
    33   */
    34 NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipboardOwner * anOwner,
    35                                         int32_t aWhichClipboard)
    36 {
    37   NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
    39   if (aTransferable == mTransferable && anOwner == mClipboardOwner)
    40     return NS_OK;
    41   bool selectClipPresent;
    42   SupportsSelectionClipboard(&selectClipPresent);
    43   bool findClipPresent;
    44   SupportsFindClipboard(&findClipPresent);
    45   if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
    46     return NS_ERROR_FAILURE;
    48   mEmptyingForSetData = true;
    49   EmptyClipboard(aWhichClipboard);
    50   mEmptyingForSetData = false;
    52   mClipboardOwner = anOwner;
    53   if ( anOwner )
    54     NS_ADDREF(mClipboardOwner);
    56   mTransferable = aTransferable;
    58   nsresult rv = NS_ERROR_FAILURE;
    60   if ( mTransferable ) {
    61     NS_ADDREF(mTransferable);
    62     if (!mPrivacyHandler) {
    63       rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler));
    64       NS_ENSURE_SUCCESS(rv, rv);
    65     }
    66     rv = mPrivacyHandler->PrepareDataForClipboard(mTransferable);
    67     NS_ENSURE_SUCCESS(rv, rv);
    68     rv = SetNativeClipboardData(aWhichClipboard);
    69   }
    71   return rv;
    72 }
    74 /**
    75   * Gets the transferable object
    76   *
    77   */
    78 NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable * aTransferable, int32_t aWhichClipboard)
    79 {
    80   NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
    82   bool selectClipPresent;
    83   SupportsSelectionClipboard(&selectClipPresent);
    84   bool findClipPresent;
    85   SupportsFindClipboard(&findClipPresent);
    86   if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
    87     return NS_ERROR_FAILURE;
    89   if ( aTransferable )
    90     return GetNativeClipboardData(aTransferable, aWhichClipboard);
    92   return NS_ERROR_FAILURE;
    93 }
    95 NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard)
    96 {
    97   bool selectClipPresent;
    98   SupportsSelectionClipboard(&selectClipPresent);
    99   bool findClipPresent;
   100   SupportsFindClipboard(&findClipPresent);
   101   if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
   102     return NS_ERROR_FAILURE;
   104   if (mIgnoreEmptyNotification)
   105     return NS_OK;
   107   if ( mClipboardOwner ) {
   108     mClipboardOwner->LosingOwnership(mTransferable);
   109     NS_RELEASE(mClipboardOwner);
   110   }
   112   NS_IF_RELEASE(mTransferable);
   114   return NS_OK;
   115 }
   117 NS_IMETHODIMP
   118 nsBaseClipboard::HasDataMatchingFlavors(const char** aFlavorList,
   119                                         uint32_t aLength,
   120                                         int32_t aWhichClipboard,
   121                                         bool* outResult) 
   122 {
   123   *outResult = true;  // say we always do.
   124   return NS_OK;
   125 }
   127 NS_IMETHODIMP
   128 nsBaseClipboard::SupportsSelectionClipboard(bool* _retval)
   129 {
   130   *_retval = false;   // we don't support the selection clipboard by default.
   131   return NS_OK;
   132 }
   134 NS_IMETHODIMP
   135 nsBaseClipboard::SupportsFindClipboard(bool* _retval)
   136 {
   137   *_retval = false;   // we don't support the find clipboard by default.
   138   return NS_OK;
   139 }

mercurial