VirtualBox

Ignore:
Timestamp:
Sep 26, 2019 4:13:25 PM (5 years ago)
Author:
vboxsync
Message:

Shared Clipboard/Transfers: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp

    r80966 r81025  
    181181    if (!pWinCtx)
    182182        return;
     183
     184    LogFlowFuncEnter();
    183185
    184186    if (RTCritSectIsInitialized(&pWinCtx->CritSect))
     
    894896    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
    895897
    896     LogFlowFuncEnter();
    897 
    898     int rc;
     898    LogFlowFunc(("pWinCtx=%p\n", pWinCtx));
    899899
    900900    AssertReturn(pTransfer->pvUser == NULL, VERR_WRONG_ORDER);
    901901
    902     SharedClipboardWinTransferCtx *pWinURITransferCtx = new SharedClipboardWinTransferCtx();
    903     if (pWinURITransferCtx)
    904     {
    905         pTransfer->pvUser = pWinURITransferCtx;
    906         pTransfer->cbUser = sizeof(SharedClipboardWinTransferCtx);
    907 
    908         pWinURITransferCtx->pDataObj = new SharedClipboardWinDataObject(pTransfer);
    909         if (pWinURITransferCtx->pDataObj)
    910         {
    911             rc = pWinURITransferCtx->pDataObj->Init();
    912             if (RT_SUCCESS(rc))
     902    /* Make sure to enter the critical section before setting the clipboard data, as otherwise WM_CLIPBOARDUPDATE
     903     * might get called *before* we had the opportunity to set pWinCtx->hWndClipboardOwnerUs below. */
     904    int rc = RTCritSectEnter(&pWinCtx->CritSect);
     905    if (RT_SUCCESS(rc))
     906    {
     907        SharedClipboardWinTransferCtx *pWinURITransferCtx = new SharedClipboardWinTransferCtx();
     908        if (pWinURITransferCtx)
     909        {
     910            pTransfer->pvUser = pWinURITransferCtx;
     911            pTransfer->cbUser = sizeof(SharedClipboardWinTransferCtx);
     912
     913            pWinURITransferCtx->pDataObj = new SharedClipboardWinDataObject(pTransfer);
     914            if (pWinURITransferCtx->pDataObj)
    913915            {
    914                 SharedClipboardWinClose();
    915                 /* Note: Clipboard must be closed first before calling OleSetClipboard(). */
    916 
    917                 /** @todo There is a potential race between SharedClipboardWinClose() and OleSetClipboard(),
    918                  *        where another application could own the clipboard (open), and thus the call to
    919                  *        OleSetClipboard() will fail. Needs (better) fixing. */
    920                 HRESULT hr = S_OK;
    921 
    922                 for (unsigned uTries = 0; uTries < 3; uTries++)
     916                rc = pWinURITransferCtx->pDataObj->Init();
     917                if (RT_SUCCESS(rc))
    923918                {
    924                     /* Make sure to enter the critical section before setting the clipboard data, as otherwise WM_CLIPBOARDUPDATE
    925                      * might get called *before* we had the opportunity to set pWinCtx->hWndClipboardOwnerUs below. */
    926                     rc = RTCritSectEnter(&pWinCtx->CritSect);
    927                     if (RT_SUCCESS(rc))
     919                    SharedClipboardWinClose();
     920                    /* Note: Clipboard must be closed first before calling OleSetClipboard(). */
     921
     922                    /** @todo There is a potential race between SharedClipboardWinClose() and OleSetClipboard(),
     923                     *        where another application could own the clipboard (open), and thus the call to
     924                     *        OleSetClipboard() will fail. Needs (better) fixing. */
     925                    HRESULT hr = S_OK;
     926
     927                    for (unsigned uTries = 0; uTries < 3; uTries++)
    928928                    {
    929929                        hr = OleSetClipboard(pWinURITransferCtx->pDataObj);
     
    939939                            pWinCtx->hWndClipboardOwnerUs = GetClipboardOwner();
    940940
    941                             rc = RTCritSectLeave(&pWinCtx->CritSect);
    942                             AssertRC(rc);
     941                            LogFlowFunc(("hWndClipboardOwnerUs=%p\n", pWinCtx->hWndClipboardOwnerUs));
    943942                            break;
    944943                        }
     944
     945                        LogFlowFunc(("Failed with %Rhrc (try %u/3)\n", hr, uTries + 1));
     946                        RTThreadSleep(500); /* Wait a bit. */
    945947                    }
    946948
    947                     rc = RTCritSectLeave(&pWinCtx->CritSect);
    948                     AssertRCBreak(rc);
    949 
    950                     LogFlowFunc(("Failed with %Rhrc (try %u/3)\n", hr, uTries + 1));
    951                     RTThreadSleep(500); /* Wait a bit. */
    952                 }
    953 
    954                 if (FAILED(hr))
    955                 {
    956                     rc = VERR_ACCESS_DENIED; /** @todo Fudge; fix this. */
    957                     LogRel(("Shared Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr));
     949                    if (FAILED(hr))
     950                    {
     951                        rc = VERR_ACCESS_DENIED; /** @todo Fudge; fix this. */
     952                        LogRel(("Shared Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr));
     953                    }
    958954                }
    959955            }
     956            else
     957                rc = VERR_NO_MEMORY;
    960958        }
    961959        else
    962960            rc = VERR_NO_MEMORY;
    963     }
    964     else
    965         rc = VERR_NO_MEMORY;
     961
     962        int rc2 = RTCritSectLeave(&pWinCtx->CritSect);
     963        AssertRC(rc2);
     964    }
    966965
    967966    LogFlowFuncLeaveRC(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