VirtualBox

Changeset 80918 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Sep 20, 2019 10:27:30 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133495
Message:

Shared Clipboard/Transfers: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp

    r80907 r80918  
    101101
    102102#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    103 #if 0
    104 static DECLCALLBACK(int) vboxClipboardTransferWriteThread(RTTHREAD ThreadSelf, void *pvUser)
    105 {
    106     RT_NOREF(ThreadSelf);
    107 
    108     LogFlowFuncEnter();
    109 
    110     PSHCLWRITETHREADCTX pCtx = (PSHCLWRITETHREADCTX)pvUser;
    111     AssertPtr(pCtx);
    112 
    113     PSHCLTRANSFER pTransfer = pCtx->pTransfer;
    114     AssertPtr(pTransfer);
    115 
    116     pTransfer->Thread.fStarted = true;
    117 
    118     RTThreadUserSignal(RTThreadSelf());
    119 
    120     VBGLR3SHCLCMDCTX cmdCtx;
    121     int rc = VbglR3ClipboardConnectEx(&cmdCtx);
    122     if (RT_SUCCESS(rc))
    123     {
    124         rc = VbglR3ClipboardTransferSendStatus(&cmdCtx, pTransfer, SHCLTRANSFERSTATUS_RUNNING);
    125         if (RT_SUCCESS(rc))
    126         {
    127             bool     fTerminate = false;
    128             unsigned cErrors    = 0;
    129 
    130             for (;;)
    131             {
    132                 PVBGLR3CLIPBOARDEVENT pEvent = NULL;
    133                 rc = VbglR3ClipboardEventGetNext(&cmdCtx, &pEvent);
    134                 if (RT_SUCCESS(rc))
    135                 {
    136                     /* Nothing to do in here right now. */
    137 
    138                     VbglR3ClipboardEventFree(pEvent);
    139                 }
    140 
    141                 if (fTerminate)
    142                     break;
    143 
    144                 if (RT_FAILURE(rc))
    145                 {
    146                     if (cErrors++ >= 3)
    147                         break;
    148                     RTThreadSleep(1000);
    149                 }
    150             }
    151         }
    152 
    153         VbglR3ClipboardDisconnectEx(&cmdCtx);
    154     }
    155 
    156     RTMemFree(pCtx);
    157 
    158     LogFlowFuncLeaveRC(rc);
    159     return rc;
    160 }
    161 #endif
    162 
    163103/**
    164104 * Cleanup helper function for transfer callbacks.
     
    196136    LogFlowFunc(("pCtx=%p\n", pCtx));
    197137
    198     int rc = SharedClipboardWinOpen(pCtx->Win.hWnd);
    199     if (RT_SUCCESS(rc))
    200     {
    201         /* The data data in CF_HDROP format, as the files are locally present and don't need to be
    202          * presented as a IDataObject or IStream. */
    203         HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
    204         if (hClip)
     138    PSHCLTRANSFER pTransfer = pData->pTransfer;
     139    AssertPtr(pTransfer);
     140
     141    int rc;
     142
     143    /* The guest wants to write local data to the host? */
     144    if (SharedClipboardTransferGetDir(pTransfer) == SHCLTRANSFERDIR_WRITE)
     145    {
     146        Assert(SharedClipboardTransferGetSource(pTransfer) == SHCLSOURCE_LOCAL); /* Sanity. */
     147
     148        rc = SharedClipboardWinOpen(pCtx->Win.hWnd);
     149        if (RT_SUCCESS(rc))
    205150        {
    206             HDROP hDrop = (HDROP)GlobalLock(hClip);
    207             if (hDrop)
     151            /* The data data in CF_HDROP format, as the files are locally present and don't need to be
     152             * presented as a IDataObject or IStream. */
     153            HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
     154            if (hClip)
    208155            {
    209                 char    *papszList = NULL;
    210                 uint32_t cbList;
    211                 rc = SharedClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
    212 
    213                 GlobalUnlock(hClip);
    214 
    215                 if (RT_SUCCESS(rc))
     156                HDROP hDrop = (HDROP)GlobalLock(hClip);
     157                if (hDrop)
    216158                {
    217                     rc = SharedClipboardTransferRootsSet(pData->pTransfer,
    218                                                          papszList, cbList + 1 /* Include termination */);
    219                     RTStrFree(papszList);
     159                    char    *papszList = NULL;
     160                    uint32_t cbList;
     161                    rc = SharedClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
     162
     163                    GlobalUnlock(hClip);
     164
     165                    if (RT_SUCCESS(rc))
     166                    {
     167                        rc = SharedClipboardTransferRootsSet(pTransfer,
     168                                                             papszList, cbList + 1 /* Include termination */);
     169                        RTStrFree(papszList);
     170                    }
    220171                }
     172                else
     173                    LogRel(("Shared Clipboard: Unable to lock clipboard data, last error: %ld\n", GetLastError()));
    221174            }
    222175            else
    223             {
    224                 hClip = NULL;
    225             }
     176                LogRel(("Shared Clipboard: Unable to retrieve clipboard data from clipboard (CF_HDROP), last error: %ld\n",
     177                        GetLastError()));
     178
     179            SharedClipboardWinClose();
    226180        }
    227 
    228         SharedClipboardWinClose();
    229     }
     181    }
     182    /* The guest wants to read data from a remote source. */
     183    else if (SharedClipboardTransferGetDir(pTransfer) == SHCLTRANSFERDIR_READ)
     184    {
     185        Assert(SharedClipboardTransferGetSource(pTransfer) == SHCLSOURCE_REMOTE); /* Sanity. */
     186
     187        rc = SharedClipboardWinTransferCreate(&pCtx->Win, pTransfer);
     188    }
     189    else
     190        AssertFailedStmt(rc = VERR_NOT_SUPPORTED);
    230191
    231192    LogFlowFuncLeaveRC(rc);
     
    475436       {
    476437           const HWND hWndClipboardOwner = GetClipboardOwner();
     438
     439           LogFunc(("WM_CLIPBOARDUPDATE: hWndOldClipboardOwner=%p, hWndNewClipboardOwner=%p\n",
     440                    pWinCtx->hWndClipboardOwnerUs, hWndClipboardOwner));
     441
    477442           if (pWinCtx->hWndClipboardOwnerUs != hWndClipboardOwner)
    478443           {
    479                LogFunc(("WM_CLIPBOARDUPDATE: hWndOldClipboardOwner=%p, hWndNewClipboardOwner=%p\n",
    480                         pWinCtx->hWndClipboardOwnerUs, hWndClipboardOwner));
    481 
    482444               /* Clipboard was updated by another application.
    483445                * Report available formats to the host. */
     
    716678                        LogFunc(("VBOX_SHCL_FMT_URI_LIST\n"));
    717679
    718                         PSHCLTRANSFER pTransfer = SharedClipboardTransferCtxGetTransfer(&pCtx->TransferCtx, 0); /** @todo FIX !!! */
    719                         if (pTransfer)
    720                         {
    721                             rc = SharedClipboardWinTransferCreate(pWinCtx, pTransfer);
    722 
    723                             /* Note: The actual requesting + retrieving of data will be done in the IDataObject implementation
    724                                      (ClipboardDataObjectImpl::GetData()). */
    725                         }
    726                         else
    727                             AssertFailedStmt(rc = VERR_NOT_FOUND);
    728 
    729                         /* Note: SharedClipboardWinTransferCreate() takes care of closing the clipboard. */
     680                        /*
     681                         * Creating and starting the actual transfer will be done in vbglR3ClipboardTransferStart() as soon
     682                         * as the host announces the start of the transfer via a VBOX_SHCL_HOST_MSG_TRANSFER_STATUS message.
     683                         * Transfers always are controlled and initiated on the host side!
     684                         *
     685                         * So don't announce the transfer to the OS here yet.
     686                         */
    730687                    }
    731688                    else
     
    733690#endif
    734691                        rc = SharedClipboardWinAnnounceFormats(pWinCtx, fFormats);
    735 
    736                         SharedClipboardWinClose();
    737692#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    738693                    }
    739694#endif
     695                    SharedClipboardWinClose();
    740696               }
    741697           }
     
    826782                   }
    827783               }
    828 #if 0
    829                else if (uFormat == VBOX_SHCL_FMT_URI_LIST)
    830                {
    831                    LogFunc(("cTransfersRunning=%RU32\n", SharedClipboardTransferCtxGetRunningTransfers(&pCtx->TransferCtx)));
    832 
    833                    int rc = SharedClipboardWinOpen(hwnd);
    834                    if (RT_SUCCESS(rc))
    835                    {
    836                        PSHCLTRANSFER pTransfer;
    837                        rc = SharedClipboardTransferCreate(&pTransfer);
    838                        if (RT_SUCCESS(rc))
    839                            rc = SharedClipboardTransferInit(pTransfer, 0 /* uID */,
    840                                                             SHCLTRANSFERDIR_WRITE, SHCLSOURCE_LOCAL);
    841                        if (RT_SUCCESS(rc))
    842                        {
    843                            /* The data data in CF_HDROP format, as the files are locally present and don't need to be
    844                             * presented as a IDataObject or IStream. */
    845                            HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
    846                            if (hClip)
    847                            {
    848                                HDROP hDrop = (HDROP)GlobalLock(hClip);
    849                                if (hDrop)
    850                                {
    851                                    char    *papszList;
    852                                    uint32_t cbList;
    853                                    rc = SharedClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
    854 
    855                                    GlobalUnlock(hClip);
    856 
    857                                    if (RT_SUCCESS(rc))
    858                                    {
    859                                        rc = SharedClipboardTransferSetRoots(pTransfer,
    860                                                                             papszList, cbList + 1 /* Include termination */);
    861                                        if (RT_SUCCESS(rc))
    862                                        {
    863                                            PSHCLWRITETHREADCTX pThreadCtx
    864                                                = (PSHCLWRITETHREADCTX)RTMemAllocZ(sizeof(SHCLWRITETHREADCTX));
    865                                            if (pThreadCtx)
    866                                            {
    867                                                pThreadCtx->pClipboardCtx = pCtx;
    868                                                pThreadCtx->pTransfer     = pTransfer;
    869 
    870                                                rc = SharedClipboardTransferPrepare(pTransfer);
    871                                                if (RT_SUCCESS(rc))
    872                                                {
    873                                                    rc = SharedClipboardTransferCtxTransferRegister(&pCtx->TransferCtx, pTransfer,
    874                                                                                                    NULL /* puTransferID */);
    875                                             #if 0
    876                                                    if (RT_SUCCESS(rc))
    877                                                    {
    878                                                        rc = SharedClipboardTransferRun(pTransfer, vboxClipboardTransferWriteThread,
    879                                                                                        pThreadCtx /* pvUser */);
    880                                                        /* pThreadCtx now is owned by vboxClipboardTransferWriteThread(). */
    881                                                    }
    882                                             #endif
    883                                                }
    884                                            }
    885                                            else
    886                                                rc = VERR_NO_MEMORY;
    887                                        }
    888 
    889                                        if (papszList)
    890                                            RTStrFree(papszList);
    891                                    }
    892                                }
    893                                else
    894                                {
    895                                    hClip = NULL;
    896                                }
    897                            }
    898                        }
    899 
    900                        SharedClipboardWinClose();
    901                    }
    902 
    903                    if (RT_FAILURE(rc))
    904                        LogFunc(("SHCL_WIN_WM_READ_DATA: Failed with rc=%Rrc\n", rc));
    905                }
    906 #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
    907 
    908784               if (hClip == NULL)
    909785               {
     
    932808
    933809#if 0
    934        /* The host wants to read transfer data. */
    935        case VBOX_CLIPBOARD_WM_URI_START_READ:
    936        {
    937            LogFunc(("VBOX_CLIPBOARD_WM_URI_START_READ: cTransfersRunning=%RU32\n",
    938                     SharedClipboardTransferCtxGetRunningTransfers(&pCtx->URI)));
    939 
    940            int rc = SharedClipboardWinOpen(hwnd);
    941            if (RT_SUCCESS(rc))
    942            {
    943                PSHCLTRANSFER pTransfer;
    944                rc = SharedClipboardTransferCreate(SHCLTRANSFERDIR_WRITE,
    945                                                   SHCLSOURCE_LOCAL,
    946                                                   &pTransfer);
    947                if (RT_SUCCESS(rc))
    948                {
    949                    rc = SharedClipboardTransferCtxTransferAdd(&pCtx->URI, pTransfer);
    950                    if (RT_SUCCESS(rc))
    951                    {
    952                        /* The data data in CF_HDROP format, as the files are locally present and don't need to be
    953                        * presented as a IDataObject or IStream. */
    954                        HANDLE hClip = hClip = GetClipboardData(CF_HDROP);
    955                        if (hClip)
    956                        {
    957                            HDROP hDrop = (HDROP)GlobalLock(hClip);
    958                            if (hDrop)
    959                            {
    960                                char    *papszList;
    961                                uint32_t cbList;
    962                                rc = SharedClipboardWinDropFilesToStringList((DROPFILES *)hDrop, &papszList, &cbList);
    963 
    964                                GlobalUnlock(hClip);
    965 
    966                                if (RT_SUCCESS(rc))
    967                                {
    968                                    rc = SharedClipboardTransferSetRoots(pTransfer,
    969                                                                         papszList, cbList + 1 /* Include termination */);
    970                                    if (RT_SUCCESS(rc))
    971                                    {
    972                                        PSHCLWRITETHREADCTX pThreadCtx
    973                                            = (PSHCLWRITETHREADCTX)RTMemAllocZ(sizeof(SHCLWRITETHREADCTX));
    974                                        if (pThreadCtx)
    975                                        {
    976                                            pThreadCtx->pClipboardCtx = pCtx;
    977                                            pThreadCtx->pTransfer     = pTransfer;
    978 
    979                                            rc = SharedClipboardTransferPrepare(pTransfer);
    980                                            if (RT_SUCCESS(rc))
    981                                            {
    982                                                rc = SharedClipboardTransferRun(pTransfer, vboxClipboardTransferWriteThread,
    983                                                                                pThreadCtx /* pvUser */);
    984                                                /* pThreadCtx now is owned by vboxClipboardTransferWriteThread(). */
    985                                            }
    986                                        }
    987                                        else
    988                                            rc = VERR_NO_MEMORY;
    989                                    }
    990 
    991                                    if (papszList)
    992                                        RTStrFree(papszList);
    993                                }
    994                            }
    995                            else
    996                            {
    997                                hClip = NULL;
    998                            }
    999                        }
    1000                    }
    1001                }
    1002 
    1003                SharedClipboardWinClose();
    1004            }
    1005 
    1006            if (RT_FAILURE(rc))
    1007                LogFunc(("VBOX_CLIPBOARD_WM_URI_START_READ: Failed with rc=%Rrc\n", rc));
    1008            break;
    1009        }
    1010 
    1011810       /* The host wants to write transfer data. */
    1012811       case VBOX_CLIPBOARD_WM_URI_START_WRITE:
     
    12031002    if (FAILED(hr))
    12041003    {
    1205         LogRel(("Shared Clipboard: Initializing OLE failed (%Rhrc) -- file transfers unavailable\n"));
     1004        LogRel(("Shared Clipboard: Initializing OLE failed (%Rhrc) -- file transfers unavailable\n", hr));
    12061005        /* Not critical, the rest of the clipboard might work. */
    12071006    }
     
    12531052    AssertPtr(pInstance);
    12541053    LogFlowFunc(("pInstance=%p\n", pInstance));
     1054
     1055    HRESULT hr = OleInitialize(NULL);
     1056    if (FAILED(hr))
     1057    {
     1058        LogRel(("Shared Clipboard: Initializing OLE in worker thread failed (%Rhrc) -- file transfers unavailable\n", hr));
     1059        /* Not critical, the rest of the clipboard might work. */
     1060    }
    12551061
    12561062    /*
     
    14031209    }
    14041210
     1211#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     1212    OleSetClipboard(NULL); /* Make sure to flush the clipboard on destruction. */
     1213    OleUninitialize();
     1214#endif
     1215
    14051216    LogFlowFuncLeaveRC(rc);
    14061217    return rc;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette