toolkit/obsolete/content/nsClipboard.js

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: Java; tab-width: 4; 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 /** 
     7  * nsClipboard - wrapper around nsIClipboard and nsITransferable
     8  *               that simplifies access to the clipboard. 
     9  **/ 
    10 var nsClipboard = {
    11   _CB: null,
    12   get mClipboard()
    13     {
    14       if (!this._CB) 
    15         {
    16           const kCBContractID = "@mozilla.org/widget/clipboard;1";
    17           const kCBIID = Components.interfaces.nsIClipboard;
    18           this._CB = Components.classes[kCBContractID].getService(kCBIID);
    19         }
    20       return this._CB;
    21     },
    23   currentClipboard: null,
    24   /** 
    25    * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ;
    26    *
    27    * returns the data in the clipboard
    28    * 
    29    * @param FlavourSet aFlavourSet
    30    *        formatted list of desired flavours
    31    * @param long aClipboard
    32    *        the clipboard to read data from (kSelectionClipboard/kGlobalClipboard)
    33    * @param Bool aAnyFlag
    34    *        should be false.
    35    **/
    36   read: function (aFlavourList, aClipboard, aAnyFlag)
    37     {
    38       this.currentClipboard = aClipboard;
    39       var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag);
    40       return data.first.first;  // only support one item
    41     },
    43   /**
    44    * nsISupportsArray getClipboardTransferable (Object aFlavourList) ;
    45    * 
    46    * returns a nsISupportsArray of the item on the clipboard
    47    *
    48    * @param Object aFlavourList
    49    *        formatted list of desired flavours.
    50    **/
    51   getClipboardTransferable: function (aFlavourList)
    52     {
    53       const supportsContractID = "@mozilla.org/supports-array;1";
    54       const supportsIID = Components.interfaces.nsISupportsArray;
    55       var supportsArray = Components.classes[supportsContractID].createInstance(supportsIID);
    56       var trans = nsTransferable.createTransferable();
    57       for (var flavour in aFlavourList) 
    58         trans.addDataFlavor(flavour);
    59       nsClipboard.mClipboard.getData(trans, nsClipboard.currentClipboard)
    60       supportsArray.AppendElement(trans);
    61       return supportsArray;
    62     }
    63 };

mercurial