VirtualBox

Changeset 100412 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Jul 6, 2023 2:08:30 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158152
Message:

Shared Clipboard: Windows host service now uses the same way as the Linux host service wrt transfer handling. ​​​bugref:9437

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp

    r100394 r100412  
    301301static DECLCALLBACK(void) shClSvcWinTransferOnInitializedCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx)
    302302{
     303    LogFlowFuncEnter();
     304
    303305    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    304306    AssertPtr(pCtx);
     
    317319            {
    318320                SharedClipboardWinDataObject *pObj = pCtx->Win.pDataObjInFlight;
    319                 AssertPtrReturnVoid(pObj);
    320                 rc = pObj->SetTransfer(pTransfer);
    321 
    322                 pCtx->Win.pDataObjInFlight = NULL; /* Hand off to Windows. */
     321                if (pObj)
     322                {
     323                    rc = pObj->SetTransfer(pTransfer);
     324                    if (RT_SUCCESS(rc))
     325                        rc = pObj->SetStatus(SharedClipboardWinDataObject::Running);
     326
     327                    pCtx->Win.pDataObjInFlight = NULL; /* Hand off to Windows. */
     328                }
     329                else
     330                    AssertMsgFailed(("No data object in flight!\n"));
    323331
    324332                int rc2 = RTCritSectLeave(&pCtx->Win.CritSect);
     
    350358static DECLCALLBACK(void) shClSvcWinTransferOnDestroyCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx)
    351359{
     360    LogFlowFuncEnter();
     361
    352362    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    353363    AssertPtr(pCtx);
     
    360370
    361371/**
    362  * @copydoc SHCLTRANSFERCALLBACKS::pfnOnStarted
     372 * @copydoc SharedClipboardWinDataObject::CALLBACKS::pfnTransferStart
     373 *
     374 * Called by SharedClipboardWinDataObject::GetData() when the user wants to paste data.
     375 * This then creates and initializes a new transfer on the host + lets the guest know about that new transfer.
    363376 *
    364377 * @thread  Service main thread.
    365378 */
    366 static DECLCALLBACK(void) shClSvcWinTransferOnStartedCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx)
    367 {
     379static DECLCALLBACK(int) shClSvcWinDataObjectTransferStartCallback(SharedClipboardWinDataObject::PCALLBACKCTX pCbCtx)
     380{
     381    LogFlowFuncEnter();
     382
    368383    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    369384    AssertPtr(pCtx);
    370385
    371     PSHCLTRANSFER pTransfer = pCbCtx->pTransfer;
    372     AssertPtr(pTransfer);
    373 
    374     if (ShClTransferGetDir(pTransfer) ==  SHCLTRANSFERDIR_FROM_REMOTE) /* G->H */
    375     {
    376         /* Report to the guest that we now entered the STARTED state. */
    377         ShClSvcTransferStart(pCtx->pClient, pTransfer);
    378     }
     386    PSHCLTRANSFER pTransfer;
     387    int rc = ShClSvcTransferCreate(pCtx->pClient, SHCLTRANSFERDIR_FROM_REMOTE, SHCLSOURCE_REMOTE,
     388                                   NIL_SHCLTRANSFERID /* Creates a new transfer ID */, &pTransfer);
     389    if (RT_SUCCESS(rc))
     390    {
     391        /* Initialize the transfer on the host side. */
     392        rc = ShClSvcTransferInit(pCtx->pClient, pTransfer);
     393        if (RT_FAILURE(rc))
     394             ShClSvcTransferDestroy(pCtx->pClient, pTransfer);
     395    }
     396
     397    LogFlowFuncLeaveRC(rc);
     398    return rc;
    379399}
    380400#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
     
    545565
    546566            int rc = SharedClipboardWinClearAndAnnounceFormats(pWinCtx, fFormats, hWnd);
    547             if (RT_FAILURE(rc))
    548                 LogRel(("Shared Clipboard: Reporting clipboard formats %#x to Windows host failed with %Rrc\n", fFormats, rc));
    549 
     567#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     568            if (   RT_SUCCESS(rc)
     569                && fFormats & VBOX_SHCL_FMT_URI_LIST)
     570            {
     571                /*
     572                 * Create our IDataObject implementation and push it to the Windows clibpoard.
     573                 * That way Windows will recognize that there is a data transfer available.
     574                 */
     575                SharedClipboardWinDataObject::CALLBACKS Callbacks;
     576                RT_ZERO(Callbacks);
     577                Callbacks.pfnTransferStart = shClSvcWinDataObjectTransferStartCallback;
     578
     579                rc = SharedClipboardWinTransferCreateAndSetDataObject(pWinCtx, pCtx, &Callbacks);
     580            }
     581#else
     582            RT_NOREF(rc);
     583#endif
    550584            LogFunc(("SHCL_WIN_WM_REPORT_FORMATS: lastErr=%ld\n", GetLastError()));
    551585            break;
     
    828862        pClient->Transfers.Callbacks.pfnOnCreated     = shClSvcWinTransferOnCreatedCallback;
    829863        pClient->Transfers.Callbacks.pfnOnInitialized = shClSvcWinTransferOnInitializedCallback;
    830         pClient->Transfers.Callbacks.pfnOnStarted     = shClSvcWinTransferOnStartedCallback;
    831864        pClient->Transfers.Callbacks.pfnOnDestroy     = shClSvcWinTransferOnDestroyCallback;
    832865#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
Note: See TracChangeset for help on using the changeset viewer.

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