VirtualBox

Changeset 55520 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Apr 29, 2015 12:51:40 PM (10 years ago)
Author:
vboxsync
Message:

DnD: Don't allow simultaneous drop operations for now.

Location:
trunk/src/VBox/Main/src-client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp

    r55514 r55520  
    7878        , mpCtx(pCtx) { }
    7979
    80     virtual ~RecvDataTask(void)
    81     {
    82         if (mpCtx)
    83         {
    84             delete mpCtx;
    85             mpCtx = NULL;
    86         }
    87     }
     80    virtual ~RecvDataTask(void) { }
    8881
    8982    PRECVDATACTX getCtx(void) { return mpCtx; }
     
    10699    /* Note: Never ever rely on information from the guest; the host dictates what and
    107100     *       how to do something, so try to negogiate a sensible value here later. */
    108     m_cbBlockSize = _64K; /** @todo Make this configurable. */
     101    mData.mcbBlockSize    = _64K; /** @todo Make this configurable. */
     102    mData.mfDropIsPending = false;
    109103
    110104    LogFlowThisFunc(("\n"));
     
    247241
    248242    /* Determine guest DnD protocol to use. */
    249     GuestDnDBase::getProtocolVersion(&mData.mProtocolVersion);
     243    GuestDnDBase::getProtocolVersion(&mDataBase.mProtocolVersion);
    250244
    251245    /* Default is ignoring the action. */
     
    254248    HRESULT hr = S_OK;
    255249
    256     VBOXHGCMSVCPARM paParms[1];
    257     int i = 0;
    258     paParms[i++].setUInt32(uScreenId);
    259 
    260     int rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_GH_REQ_PENDING, i, paParms);
     250    GuestDnDMsg Msg;
     251    Msg.setType(DragAndDropSvc::HOST_DND_GH_REQ_PENDING);
     252    Msg.setNextUInt32(uScreenId);
     253
     254    int rc = GuestDnDInst()->hostCall(Msg.getType(), Msg.getCount(), Msg.getParms());
    261255    if (RT_SUCCESS(rc))
    262256    {
     
    313307        return S_OK;
    314308
     309    if (ASMAtomicReadBool(&mData.mfDropIsPending))
     310        return setError(E_INVALIDARG, tr("Another drop operation already is in progress"));
     311
     312    ASMAtomicWriteBool(&mData.mfDropIsPending, true);
     313
    315314    HRESULT hr = S_OK;
    316315
     
    325324        try
    326325        {
    327             PRECVDATACTX pRecvCtx = new RECVDATACTX;
    328             RT_BZERO(pRecvCtx, sizeof(RECVDATACTX));
    329 
    330             pRecvCtx->mpSource = this;
    331             pRecvCtx->mpResp   = pResp;
    332             pRecvCtx->mFormat  = aFormat;
    333 
    334             RecvDataTask *pTask = new RecvDataTask(this, pRecvCtx);
     326            mData.mRecvCtx.mpSource = this;
     327            mData.mRecvCtx.mpResp   = pResp;
     328            mData.mRecvCtx.mFormat  = aFormat;
     329
     330            RecvDataTask *pTask = new RecvDataTask(this, &mData.mRecvCtx);
    335331            AssertReturn(pTask->isOk(), pTask->getRC());
    336332
     
    344340                /* Note: pTask is now owned by the worker thread. */
    345341            }
    346             else if (pRecvCtx)
    347                 delete pRecvCtx;
    348342        }
    349343        catch(std::bad_alloc &)
     
    355349    }
    356350    /** @todo SetError(...) */
     351
     352    ASMAtomicWriteBool(&mData.mfDropIsPending, false);
    357353
    358354    LogFlowFunc(("Returning hr=%Rhrc\n", hr));
     
    372368    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    373369
     370    if (ASMAtomicReadBool(&mData.mfDropIsPending))
     371        return setError(E_INVALIDARG, tr("Current drop operation still running"));
     372
     373    PRECVDATACTX pCtx = &mData.mRecvCtx;
     374
     375    if (pCtx->mData.vecData.empty())
     376    {
     377        aData.resize(0);
     378        return S_OK;
     379    }
     380
    374381    HRESULT hr = S_OK;
    375 
    376 #if 0
    377     GuestDnDResponse *pResp = GuestDnDInst()->response();
    378     if (pResp)
    379     {
    380         size_t cbData = pResp->size();
    381         if (cbData)
    382         {
    383             const void *pvData = pResp->data();
    384             AssertPtr(pvData);
    385 
    386             Utf8Str strFormat = pResp->format();
    387             LogFlowFunc(("strFormat=%s, cbData=%zu, pvData=0x%p\n", strFormat.c_str(), cbData, pvData));
    388 
    389             try
    390             {
    391                 if (DnDMIMEHasFileURLs(strFormat.c_str(), strFormat.length()))
    392                 {
    393                     LogFlowFunc(("strDropDir=%s\n", pResp->dropDir().c_str()));
    394 
    395                     DnDURIList lstURI;
    396                     int rc2 = lstURI.RootFromURIData(pvData, cbData, 0 /* fFlags */);
    397                     if (RT_SUCCESS(rc2))
    398                     {
    399                         Utf8Str strURIs = lstURI.RootToString(pResp->dropDir());
    400                         size_t cbURIs = strURIs.length();
    401 
    402                         LogFlowFunc(("Found %zu root URIs (%zu bytes)\n", lstURI.RootCount(), cbURIs));
    403 
    404                         aData.resize(cbURIs + 1 /* Include termination */);
    405                         memcpy(&aData.front(), strURIs.c_str(), cbURIs);
    406                     }
    407                     else
    408                         hr = VBOX_E_IPRT_ERROR;
    409                 }
    410                 else
    411                 {
    412                     /* Copy the data into a safe array of bytes. */
    413                     aData.resize(cbData);
    414                     memcpy(&aData.front(), pvData, cbData);
    415                 }
    416             }
    417             catch (std::bad_alloc &)
    418             {
    419                 hr = E_OUTOFMEMORY;
    420             }
    421         }
    422 
    423         /* Delete the data. */
    424         pResp->reset();
    425     }
    426     else
    427         hr = VBOX_E_INVALID_OBJECT_STATE;
    428 #endif
    429 
    430     LogFlowFunc(("Returning hr=%Rhrc\n", hr));
     382    size_t cbData;
     383
     384    try
     385    {
     386        bool fHasURIList = DnDMIMENeedsDropDir(pCtx->mFormat.c_str(), pCtx->mFormat.length());
     387        if (fHasURIList)
     388        {
     389            Utf8Str strURIs = pCtx->mURI.lstURI.RootToString(pCtx->mURI.strDropDir);
     390            cbData = strURIs.length();
     391
     392            LogFlowFunc(("Found %zu root URIs (%zu bytes)\n", pCtx->mURI.lstURI.RootCount(), cbData));
     393
     394            aData.resize(cbData + 1 /* Include termination */);
     395            memcpy(&aData.front(), strURIs.c_str(), cbData);
     396        }
     397        else
     398        {
     399            cbData = pCtx->mData.vecData.size();
     400
     401            /* Copy the data into a safe array of bytes. */
     402            aData.resize(cbData);
     403            memcpy(&aData.front(), &pCtx->mData.vecData[0], cbData);
     404        }
     405    }
     406    catch (std::bad_alloc &)
     407    {
     408        hr = E_OUTOFMEMORY;
     409    }
     410
     411    LogFlowFunc(("Returning cbData=%zu, hr=%Rhrc\n", cbData, hr));
    431412    return hr;
    432413#endif /* VBOX_WITH_DRAG_AND_DROP */
     
    451432    {
    452433        if (   cbData > cbTotalSize
    453             || cbData > m_cbBlockSize)
     434            || cbData > mData.mcbBlockSize)
    454435        {
    455436            LogFlowFunc(("Data sizes invalid: cbData=%RU32, cbTotalSize=%RU64\n", cbData, cbTotalSize));
     
    586567
    587568            /* Note: Protocol v1 does not send any file sizes, so always 0. */
    588             if (mData.mProtocolVersion >= 2)
     569            if (mDataBase.mProtocolVersion >= 2)
    589570                rc = pCtx->mURI.objURI.SetSize(cbSize);
    590571        }
     
    645626            if (pCtx->mURI.objURI.IsComplete())
    646627            {
    647                 /* Prepare URI object for next use. */
    648                 pCtx->mURI.objURI.Reset();
    649 
    650628                /** @todo Sanitize path. */
    651629                LogRel2(("DnD: File transfer to host complete: %s\n", pCtx->mURI.objURI.GetDestPath().c_str()));
    652630                rc = VINF_EOF;
     631
     632                /* Prepare URI object for next use. */
     633                pCtx->mURI.objURI.Reset();
    653634            }
    654635        }
     
    839820    REGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_DATA);
    840821    REGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_DIR);
    841     if (mData.mProtocolVersion >= 2)
     822    if (mDataBase.mProtocolVersion >= 2)
    842823        REGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_FILE_HDR);
    843824    REGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_FILE_DATA);
     
    884865    UNREGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_DATA);
    885866    UNREGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_DIR);
    886     if (mData.mProtocolVersion >= 2)
     867    if (mDataBase.mProtocolVersion >= 2)
    887868        UNREGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_FILE_HDR);
    888869    UNREGISTER_CALLBACK(DragAndDropSvc::GUEST_DND_GH_SND_FILE_DATA);
     
    10241005            AssertReturn(DragAndDropSvc::CB_MAGIC_DND_GH_SND_FILE_DATA == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
    10251006
    1026             if (pThis->mData.mProtocolVersion <= 1)
     1007            if (pThis->mDataBase.mProtocolVersion <= 1)
    10271008            {
    10281009                /**
  • trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp

    r55514 r55520  
    111111    /* Note: Never ever rely on information from the guest; the host dictates what and
    112112     *       how to do something, so try to negogiate a sensible value here later. */
    113     m_cbBlockSize = _64K; /** @todo Make this configurable. */
     113    mData.mcbBlockSize = _64K; /** @todo Make this configurable. */
    114114
    115115    LogFlowThisFunc(("\n"));
     
    261261
    262262    /* Determine guest DnD protocol to use. */
    263     GuestDnDBase::getProtocolVersion(&mData.mProtocolVersion);
     263    GuestDnDBase::getProtocolVersion(&mDataBase.mProtocolVersion);
    264264
    265265    /* Default action is ignoring. */
     
    287287    if (RT_SUCCESS(rc))
    288288    {
    289         VBOXHGCMSVCPARM paParms[8];
    290         int i = 0;
    291         paParms[i++].setUInt32(aScreenId);
    292         paParms[i++].setUInt32(aX);
    293         paParms[i++].setUInt32(aY);
    294         paParms[i++].setUInt32(uDefAction);
    295         paParms[i++].setUInt32(uAllowedActions);
    296         paParms[i++].setPointer((void*)strFormats.c_str(), strFormats.length() + 1);
    297         paParms[i++].setUInt32(strFormats.length() + 1);
    298 
    299         rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_ENTER,
    300                                       i, paParms);
     289        GuestDnDMsg Msg;
     290        Msg.setType(DragAndDropSvc::HOST_DND_HG_EVT_ENTER);
     291        Msg.setNextUInt32(aScreenId);
     292        Msg.setNextUInt32(aX);
     293        Msg.setNextUInt32(aY);
     294        Msg.setNextUInt32(uDefAction);
     295        Msg.setNextUInt32(uAllowedActions);
     296        Msg.setNextPointer((void*)strFormats.c_str(), strFormats.length() + 1);
     297        Msg.setNextUInt32(strFormats.length() + 1);
     298
     299        rc = GuestDnDInst()->hostCall(Msg.getType(), Msg.getCount(), Msg.getParms());
    301300        if (RT_SUCCESS(rc))
    302301        {
     
    353352    if (RT_SUCCESS(rc))
    354353    {
    355         VBOXHGCMSVCPARM paParms[8];
    356         int i = 0;
    357         paParms[i++].setUInt32(aScreenId);
    358         paParms[i++].setUInt32(aX);
    359         paParms[i++].setUInt32(aY);
    360         paParms[i++].setUInt32(uDefAction);
    361         paParms[i++].setUInt32(uAllowedActions);
    362         paParms[i++].setPointer((void*)strFormats.c_str(), strFormats.length() + 1);
    363         paParms[i++].setUInt32(strFormats.length() + 1);
    364 
    365         rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_MOVE,
    366                                       i, paParms);
     354        GuestDnDMsg Msg;
     355        Msg.setType(DragAndDropSvc::HOST_DND_HG_EVT_MOVE);
     356        Msg.setNextUInt32(aScreenId);
     357        Msg.setNextUInt32(aX);
     358        Msg.setNextUInt32(aY);
     359        Msg.setNextUInt32(uDefAction);
     360        Msg.setNextUInt32(uAllowedActions);
     361        Msg.setNextPointer((void*)strFormats.c_str(), strFormats.length() + 1);
     362        Msg.setNextUInt32(strFormats.length() + 1);
     363
     364        rc = GuestDnDInst()->hostCall(Msg.getType(), Msg.getCount(), Msg.getParms());
    367365        if (RT_SUCCESS(rc))
    368366        {
     
    446444    if (RT_SUCCESS(rc))
    447445    {
    448         VBOXHGCMSVCPARM paParms[8];
    449         int i = 0;
    450         paParms[i++].setUInt32(aScreenId);
    451         paParms[i++].setUInt32(aX);
    452         paParms[i++].setUInt32(aY);
    453         paParms[i++].setUInt32(uDefAction);
    454         paParms[i++].setUInt32(uAllowedActions);
    455         paParms[i++].setPointer((void*)strFormats.c_str(), strFormats.length() + 1);
    456         paParms[i++].setUInt32(strFormats.length() + 1);
    457 
    458         rc = GuestDnDInst()->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_DROPPED,
    459                                       i, paParms);
     446        GuestDnDMsg Msg;
     447        Msg.setType(DragAndDropSvc::HOST_DND_HG_EVT_DROPPED);
     448        Msg.setNextUInt32(aScreenId);
     449        Msg.setNextUInt32(aX);
     450        Msg.setNextUInt32(aY);
     451        Msg.setNextUInt32(uDefAction);
     452        Msg.setNextUInt32(uAllowedActions);
     453        Msg.setNextPointer((void*)strFormats.c_str(), strFormats.length() + 1);
     454        Msg.setNextUInt32(strFormats.length() + 1);
     455
     456        rc = GuestDnDInst()->hostCall(Msg.getType(), Msg.getCount(), Msg.getParms());
    460457        if (RT_SUCCESS(rc))
    461458        {
     
    669666        return VERR_BUFFER_OVERFLOW;
    670667
    671     LogFlowFunc(("Sending directory \"%s\" using protocol v%RU32 ...\n", strPath.c_str(), mData.mProtocolVersion));
     668    LogFlowFunc(("Sending directory \"%s\" using protocol v%RU32 ...\n", strPath.c_str(), mDataBase.mProtocolVersion));
    672669
    673670    pMsg->setType(DragAndDropSvc::HOST_DND_HG_SND_DIR);
     
    690687
    691688    LogFlowFunc(("Sending \"%s\" (%RU32 bytes buffer) using protocol v%RU32 ...\n",
    692                  strPathSrc.c_str(), m_cbBlockSize, mData.mProtocolVersion));
     689                 strPathSrc.c_str(), mData.mcbBlockSize, mDataBase.mProtocolVersion));
    693690
    694691    bool fOpen = aFile.IsOpen();
     
    703700    if (RT_SUCCESS(rc))
    704701    {
    705         if (mData.mProtocolVersion >= 2)
     702        if (mDataBase.mProtocolVersion >= 2)
    706703        {
    707704            if (!fOpen)
     
    772769    /* Protocol version 1 sends the file path *every* time with a new file chunk.
    773770     * In protocol version 2 we only do this once with HOST_DND_HG_SND_FILE_HDR. */
    774     if (mData.mProtocolVersion <= 1)
     771    if (mDataBase.mProtocolVersion <= 1)
    775772    {
    776773        pMsg->setNextString(aFile.GetSourcePath().c_str());                  /* pvName */
     
    790787        pCtx->mData.cbProcessed += cbRead;
    791788
    792         if (mData.mProtocolVersion <= 1)
     789        if (mDataBase.mProtocolVersion <= 1)
    793790        {
    794791            pMsg->setNextPointer(pCtx->mURI.pvScratchBuf, cbRead);  /* pvData */
     
    944941    }
    945942
    946     void *pvBuf = RTMemAlloc(m_cbBlockSize);
     943    void *pvBuf = RTMemAlloc(mData.mcbBlockSize);
    947944    if (!pvBuf)
    948945        return VERR_NO_MEMORY;
     
    971968    /* Host callbacks. */
    972969    REGISTER_CALLBACK(DragAndDropSvc::HOST_DND_HG_SND_DIR);
    973     if (mData.mProtocolVersion >= 2)
     970    if (mDataBase.mProtocolVersion >= 2)
    974971        REGISTER_CALLBACK(DragAndDropSvc::HOST_DND_HG_SND_FILE_HDR);
    975972    REGISTER_CALLBACK(DragAndDropSvc::HOST_DND_HG_SND_FILE_DATA);
     
    981978         */
    982979        pCtx->mURI.pvScratchBuf = pvBuf;
    983         pCtx->mURI.cbScratchBuf = m_cbBlockSize;
     980        pCtx->mURI.cbScratchBuf = mData.mcbBlockSize;
    984981
    985982        /*
     
    10471044    /* Host callbacks. */
    10481045    UNREGISTER_CALLBACK(DragAndDropSvc::HOST_DND_HG_SND_DIR);
    1049     if (mData.mProtocolVersion >= 2)
     1046    if (mDataBase.mProtocolVersion >= 2)
    10501047        UNREGISTER_CALLBACK(DragAndDropSvc::HOST_DND_HG_SND_FILE_HDR);
    10511048    UNREGISTER_CALLBACK(DragAndDropSvc::HOST_DND_HG_SND_FILE_DATA);
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