xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #1312: clipboard-loops.patch

File clipboard-loops.patch, 6.6 KB (added by Antoine Martin, 5 years ago)

work in progress patch

  • xpra/client/gtk2/client.py

     
    55# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
    66# later version. See the file COPYING for details.
    77
     8import os
    89import gobject
    910try:
    1011    #we *have to* do this as early as possible on win32..
     
    220221            Try the various clipboard classes until we find one
    221222            that loads ok. (some platforms have more options than others)
    222223        """
     224        #first, verify that we're not creating a loop:
     225        if self.server_clipboard_uuid and os.name=="posix":
     226            try:
     227                from xpra.x11.gtk_x11.prop import prop_get
     228            except ImportError:
     229                pass
     230            else:
     231                root = gtk.gdk.get_default_root_window()
     232                v = prop_get(root, "XPRA_CLIPBOARD_UUID", "latin1")
     233                if v:
     234                    if self.server_clipboard_uuid in v.split(","):
     235                        clipboardlog.warn("Warning: the xpra server you connected to seems to be using the same display as this client")
     236                        clipboardlog.warn(" this would create a clipboard forwarding loop, clipboard sharing has been disabled")
     237                        return None
     238                    elif v:
     239                        clipboardlog.info("found an xpra clipboard token on this display - is xpra nested?")
    223240        clipboard_options = self.get_clipboard_helper_classes()
    224241        clipboardlog("make_clipboard_helper() options=%s", clipboard_options)
    225242        for helperclass in clipboard_options:
  • xpra/client/ui_client_base.py

     
    251251        self.server_encodings_with_lossless_mode = ()
    252252        self.server_auto_video_encoding = False
    253253        self.server_clipboard_direction = "both"
     254        self.server_clipboard_uuid = None
    254255        self.readonly = False
    255256        self.windows_enabled = True
    256257        self.pings = False
     
    17271728        self.bell_enabled = self.server_supports_bell and self.client_supports_bell
    17281729        self.server_supports_clipboard = c.boolget("clipboard")
    17291730        self.server_clipboard_direction = c.strget("clipboard-direction", "both")
     1731        self.server_clipboard_uuid = c.strget("clipboard-uuid")
    17301732        if self.server_clipboard_direction!=self.client_clipboard_direction and self.server_clipboard_direction!="both":
    17311733            if self.client_clipboard_direction=="disabled":
    17321734                pass
  • xpra/clipboard/clipboard_base.py

     
    2424from xpra.gtk_common.nested_main import NestedMainLoop
    2525from xpra.net.compression import Compressible
    2626from xpra.util import csv, envint, envbool
     27from xpra.os_util import get_hex_uuid
    2728
    2829
    2930MIN_CLIPBOARD_COMPRESSION_SIZE = 512
     
    6162
    6263class ClipboardProtocolHelperBase(object):
    6364    def __init__(self, send_packet_cb, progress_cb=None, **kwargs):
     65        self.uuid = get_hex_uuid()
    6466        self.send = send_packet_cb
    6567        self.progress_cb = progress_cb
    6668        self.can_send = kwargs.get("can-send", True)
     
    8082        self.init_packet_handlers()
    8183        self.init_proxies(kwargs.get("clipboards.local", CLIPBOARDS))
    8284        self.remote_clipboards = kwargs.get("clipboards.remote", CLIPBOARDS)
     85        self.expose_uuid()
    8386
    8487    def __repr__(self):
    8588        return "ClipboardProtocolHelperBase"
     
    8689
    8790    def get_info(self):
    8891        info = {
     92                "uuid"      : self.uuid,
    8993                "type"      : str(self),
    9094                "max_size"  : self.max_clipboard_packet_size,
    9195                "filters"   : [x.pattern for x in self.filter_res],
     
    106110        for x in self._clipboard_proxies.values():
    107111            x.cleanup()
    108112        self._clipboard_proxies = {}
     113        self.cleanup_uuid()
    109114
     115    def expose_uuid(self):
     116        pass
     117
     118    def cleanup_uuid(self):
     119        pass
     120
    110121    def set_direction(self, can_send, can_receive):
    111122        self.can_send = can_send
    112123        self.can_receive = can_receive
  • xpra/clipboard/gdk_clipboard.py

     
    2323        return "GDKClipboardProtocolHelper"
    2424
    2525
     26    def expose_uuid(self):
     27        #for X11 only:
     28        try:
     29            from xpra.x11.gtk_x11.prop import prop_set
     30            from xpra.gtk_common.gtk_util import get_default_root_window
     31        except ImportError:
     32            pass
     33        else:
     34            root = get_default_root_window()
     35            prop_set(root, "XPRA_CLIPBOARD_UUID", "latin1", self._clipboard_helper.uuid.decode("latin1"))
     36
     37    def cleanup_uuid(self):
     38        #for X11 only:
     39        try:
     40            from xpra.gtk_common.error import xswallow
     41            from xpra.x11.gtk_x11.prop import prop_del
     42            from xpra.gtk_common.gtk_util import get_default_root_window
     43        except ImportError:
     44            pass
     45        else:
     46            root = get_default_root_window()
     47            with xswallow:
     48                prop_del(root, "XPRA_CLIPBOARD_UUID")
     49
     50
    2651    def _do_munge_raw_selection_to_wire(self, target, datatype, dataformat, data):
    2752        if dataformat == 32 and datatype in ("ATOM", "ATOM_PAIR"):
    2853            log("_do_munge_raw_selection_to_wire(%s, %s, %s, %s:%s:%s) using gdk atom code", target, datatype, dataformat, type(data), len(data), list(data))
  • xpra/server/server_base.py

     
    13921392        if server_source.wants_features:
    13931393            clipboard = self._clipboard_helper is not None and self._clipboard_client == server_source
    13941394            capabilities["clipboard"] = clipboard
     1395            if self._clipboard_helper:
     1396                capabilities["clipboard-uuid"] = self._clipboard_helper.uuid
    13951397            clipboardlog("clipboard_helper=%s, clipboard_client=%s, source=%s, clipboard=%s", self._clipboard_helper, self._clipboard_client, server_source, clipboard)
    13961398            capabilities["remote-logging"] = self.remote_logging
    13971399        if self._reverse_aliases and server_source.wants_aliases: