[51476] | 1 | /* $Id: GuestDnDPrivate.h 98286 2023-01-24 13:15:30Z vboxsync $ */
|
---|
[42261] | 2 | /** @file
|
---|
[51476] | 3 | * Private guest drag and drop code, used by GuestDnDTarget +
|
---|
| 4 | * GuestDnDSource.
|
---|
[42261] | 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[98103] | 8 | * Copyright (C) 2011-2023 Oracle and/or its affiliates.
|
---|
[42261] | 9 | *
|
---|
[96407] | 10 | * This file is part of VirtualBox base platform packages, as
|
---|
| 11 | * available from https://www.virtualbox.org.
|
---|
| 12 | *
|
---|
| 13 | * This program is free software; you can redistribute it and/or
|
---|
| 14 | * modify it under the terms of the GNU General Public License
|
---|
| 15 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 16 | * License.
|
---|
| 17 | *
|
---|
| 18 | * This program is distributed in the hope that it will be useful, but
|
---|
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 21 | * General Public License for more details.
|
---|
| 22 | *
|
---|
| 23 | * You should have received a copy of the GNU General Public License
|
---|
| 24 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 25 | *
|
---|
| 26 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[42261] | 27 | */
|
---|
| 28 |
|
---|
[76562] | 29 | #ifndef MAIN_INCLUDED_GuestDnDPrivate_h
|
---|
| 30 | #define MAIN_INCLUDED_GuestDnDPrivate_h
|
---|
[76487] | 31 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 32 | # pragma once
|
---|
| 33 | #endif
|
---|
[42261] | 34 |
|
---|
[55556] | 35 | #include <iprt/dir.h>
|
---|
| 36 | #include <iprt/file.h>
|
---|
[58212] | 37 | #include <iprt/path.h>
|
---|
[55556] | 38 |
|
---|
[58212] | 39 | #include <VBox/hgcmsvc.h> /* For PVBOXHGCMSVCPARM. */
|
---|
| 40 | #include <VBox/GuestHost/DragAndDrop.h>
|
---|
[74439] | 41 | #include <VBox/GuestHost/DragAndDropDefs.h>
|
---|
[58212] | 42 | #include <VBox/HostServices/DragAndDropSvc.h>
|
---|
[42261] | 43 |
|
---|
[55422] | 44 | /**
|
---|
| 45 | * Forward prototype declarations.
|
---|
| 46 | */
|
---|
[51476] | 47 | class Guest;
|
---|
[55422] | 48 | class GuestDnDBase;
|
---|
[85744] | 49 | class GuestDnDState;
|
---|
[55422] | 50 | class GuestDnDSource;
|
---|
| 51 | class GuestDnDTarget;
|
---|
[51476] | 52 | class Progress;
|
---|
| 53 |
|
---|
[58212] | 54 | /**
|
---|
| 55 | * Type definitions.
|
---|
| 56 | */
|
---|
| 57 |
|
---|
| 58 | /** List (vector) of MIME types. */
|
---|
| 59 | typedef std::vector<com::Utf8Str> GuestDnDMIMEList;
|
---|
| 60 |
|
---|
[85553] | 61 | /**
|
---|
| 62 | * Class to handle a guest DnD callback event.
|
---|
[58329] | 63 | */
|
---|
[55512] | 64 | class GuestDnDCallbackEvent
|
---|
| 65 | {
|
---|
| 66 | public:
|
---|
[55422] | 67 |
|
---|
[55512] | 68 | GuestDnDCallbackEvent(void)
|
---|
[85402] | 69 | : m_SemEvent(NIL_RTSEMEVENT)
|
---|
[98273] | 70 | , m_vrc(VINF_SUCCESS) { }
|
---|
[55512] | 71 |
|
---|
| 72 | virtual ~GuestDnDCallbackEvent(void);
|
---|
| 73 |
|
---|
| 74 | public:
|
---|
| 75 |
|
---|
| 76 | int Reset(void);
|
---|
| 77 |
|
---|
[98273] | 78 | int Notify(int vrc = VINF_SUCCESS);
|
---|
[55512] | 79 |
|
---|
[98273] | 80 | int Result(void) const { return m_vrc; }
|
---|
[55512] | 81 |
|
---|
| 82 | int Wait(RTMSINTERVAL msTimeout);
|
---|
| 83 |
|
---|
| 84 | protected:
|
---|
| 85 |
|
---|
| 86 | /** Event semaphore to notify on error/completion. */
|
---|
[85402] | 87 | RTSEMEVENT m_SemEvent;
|
---|
[55512] | 88 | /** Callback result. */
|
---|
[98273] | 89 | int m_vrc;
|
---|
[55512] | 90 | };
|
---|
| 91 |
|
---|
[51476] | 92 | /**
|
---|
[85371] | 93 | * Struct for handling the (raw) meta data.
|
---|
[55512] | 94 | */
|
---|
[85371] | 95 | struct GuestDnDMetaData
|
---|
[55512] | 96 | {
|
---|
[58212] | 97 | GuestDnDMetaData(void)
|
---|
| 98 | : pvData(NULL)
|
---|
| 99 | , cbData(0)
|
---|
[85537] | 100 | , cbAllocated(0)
|
---|
| 101 | , cbAnnounced(0) { }
|
---|
[58212] | 102 |
|
---|
| 103 | virtual ~GuestDnDMetaData(void)
|
---|
| 104 | {
|
---|
| 105 | reset();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[85553] | 108 | /**
|
---|
| 109 | * Adds new meta data.
|
---|
| 110 | *
|
---|
| 111 | * @returns New (total) meta data size in bytes.
|
---|
| 112 | * @param pvDataAdd Pointer of data to add.
|
---|
| 113 | * @param cbDataAdd Size (in bytes) of data to add.
|
---|
| 114 | */
|
---|
[85402] | 115 | size_t add(const void *pvDataAdd, size_t cbDataAdd)
|
---|
[58212] | 116 | {
|
---|
[85537] | 117 | LogFlowThisFunc(("cbAllocated=%zu, cbAnnounced=%zu, pvDataAdd=%p, cbDataAdd=%zu\n",
|
---|
| 118 | cbAllocated, cbAnnounced, pvDataAdd, cbDataAdd));
|
---|
[58212] | 119 | if (!cbDataAdd)
|
---|
| 120 | return 0;
|
---|
| 121 | AssertPtrReturn(pvDataAdd, 0);
|
---|
| 122 |
|
---|
[85537] | 123 | const size_t cbAllocatedTmp = cbData + cbDataAdd;
|
---|
| 124 | if (cbAllocatedTmp > cbAllocated)
|
---|
| 125 | {
|
---|
[98273] | 126 | int vrc = resize(cbAllocatedTmp);
|
---|
| 127 | if (RT_FAILURE(vrc))
|
---|
[85537] | 128 | return 0;
|
---|
| 129 | }
|
---|
[58212] | 130 |
|
---|
[85371] | 131 | Assert(cbAllocated >= cbData + cbDataAdd);
|
---|
| 132 | memcpy((uint8_t *)pvData + cbData, pvDataAdd, cbDataAdd);
|
---|
[58212] | 133 |
|
---|
[85583] | 134 | cbData += cbDataAdd;
|
---|
| 135 | cbAnnounced = cbData;
|
---|
[58212] | 136 |
|
---|
[85371] | 137 | return cbData;
|
---|
[58212] | 138 | }
|
---|
| 139 |
|
---|
[85553] | 140 | /**
|
---|
| 141 | * Adds new meta data.
|
---|
| 142 | *
|
---|
| 143 | * @returns New (total) meta data size in bytes.
|
---|
| 144 | * @param vecAdd Meta data to add.
|
---|
| 145 | */
|
---|
[85402] | 146 | size_t add(const std::vector<BYTE> &vecAdd)
|
---|
[58212] | 147 | {
|
---|
| 148 | if (!vecAdd.size())
|
---|
| 149 | return 0;
|
---|
| 150 |
|
---|
[58370] | 151 | if (vecAdd.size() > UINT32_MAX) /* Paranoia. */
|
---|
| 152 | return 0;
|
---|
| 153 |
|
---|
| 154 | return add(&vecAdd.front(), (uint32_t)vecAdd.size());
|
---|
[58212] | 155 | }
|
---|
| 156 |
|
---|
[85553] | 157 | /**
|
---|
| 158 | * Resets (clears) all data.
|
---|
| 159 | */
|
---|
[58212] | 160 | void reset(void)
|
---|
| 161 | {
|
---|
[85371] | 162 | strFmt = "";
|
---|
| 163 |
|
---|
[58212] | 164 | if (pvData)
|
---|
| 165 | {
|
---|
[85371] | 166 | Assert(cbAllocated);
|
---|
[58212] | 167 | RTMemFree(pvData);
|
---|
| 168 | pvData = NULL;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[85537] | 171 | cbData = 0;
|
---|
[85371] | 172 | cbAllocated = 0;
|
---|
[85537] | 173 | cbAnnounced = 0;
|
---|
[58212] | 174 | }
|
---|
| 175 |
|
---|
[85553] | 176 | /**
|
---|
| 177 | * Resizes the allocation size.
|
---|
| 178 | *
|
---|
| 179 | * @returns VBox status code.
|
---|
| 180 | * @param cbSize New allocation size (in bytes).
|
---|
| 181 | */
|
---|
[85402] | 182 | int resize(size_t cbSize)
|
---|
[58212] | 183 | {
|
---|
| 184 | if (!cbSize)
|
---|
| 185 | {
|
---|
| 186 | reset();
|
---|
| 187 | return VINF_SUCCESS;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[85371] | 190 | if (cbSize == cbAllocated)
|
---|
[58212] | 191 | return VINF_SUCCESS;
|
---|
| 192 |
|
---|
[85549] | 193 | cbSize = RT_ALIGN_Z(cbSize, PAGE_SIZE);
|
---|
| 194 |
|
---|
[78653] | 195 | if (cbSize > _32M) /* Meta data can be up to 32MB. */
|
---|
[85537] | 196 | return VERR_BUFFER_OVERFLOW;
|
---|
[78653] | 197 |
|
---|
[58212] | 198 | void *pvTmp = NULL;
|
---|
[85371] | 199 | if (!cbAllocated)
|
---|
[58212] | 200 | {
|
---|
[85371] | 201 | Assert(cbData == 0);
|
---|
[85549] | 202 | pvTmp = RTMemAllocZ(cbSize);
|
---|
[58212] | 203 | }
|
---|
| 204 | else
|
---|
| 205 | {
|
---|
| 206 | AssertPtr(pvData);
|
---|
[85549] | 207 | pvTmp = RTMemRealloc(pvData, cbSize);
|
---|
[58212] | 208 | }
|
---|
| 209 |
|
---|
| 210 | if (pvTmp)
|
---|
| 211 | {
|
---|
[85371] | 212 | pvData = pvTmp;
|
---|
| 213 | cbAllocated = cbSize;
|
---|
[58212] | 214 | return VINF_SUCCESS;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | return VERR_NO_MEMORY;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[85371] | 220 | /** Format string of this meta data. */
|
---|
| 221 | com::Utf8Str strFmt;
|
---|
| 222 | /** Pointer to allocated meta data. */
|
---|
| 223 | void *pvData;
|
---|
| 224 | /** Used bytes of meta data. Must not exceed cbAllocated. */
|
---|
[85402] | 225 | size_t cbData;
|
---|
[85371] | 226 | /** Size (in bytes) of allocated meta data. */
|
---|
[85402] | 227 | size_t cbAllocated;
|
---|
[85537] | 228 | /** Size (in bytes) of announced meta data. */
|
---|
| 229 | size_t cbAnnounced;
|
---|
[58212] | 230 | };
|
---|
| 231 |
|
---|
| 232 | /**
|
---|
[85371] | 233 | * Struct for accounting shared DnD data to be sent/received.
|
---|
[58212] | 234 | */
|
---|
[85371] | 235 | struct GuestDnDData
|
---|
[58212] | 236 | {
|
---|
[55556] | 237 | GuestDnDData(void)
|
---|
[85371] | 238 | : cbExtra(0)
|
---|
| 239 | , cbProcessed(0) { }
|
---|
[55556] | 240 |
|
---|
[58212] | 241 | virtual ~GuestDnDData(void)
|
---|
[55556] | 242 | {
|
---|
[58212] | 243 | reset();
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[85553] | 246 | /**
|
---|
| 247 | * Adds processed data to the internal accounting.
|
---|
| 248 | *
|
---|
| 249 | * @returns New processed data size.
|
---|
| 250 | * @param cbDataAdd Bytes to add as done processing.
|
---|
| 251 | */
|
---|
[85402] | 252 | size_t addProcessed(size_t cbDataAdd)
|
---|
[58212] | 253 | {
|
---|
[85537] | 254 | const size_t cbTotal = getTotalAnnounced(); RT_NOREF(cbTotal);
|
---|
[85423] | 255 | AssertReturn(cbProcessed + cbDataAdd <= cbTotal, 0);
|
---|
[58212] | 256 | cbProcessed += cbDataAdd;
|
---|
| 257 | return cbProcessed;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
[85553] | 260 | /**
|
---|
| 261 | * Returns whether all data has been processed or not.
|
---|
| 262 | *
|
---|
| 263 | * @returns \c true if all data has been processed, \c false if not.
|
---|
| 264 | */
|
---|
[58212] | 265 | bool isComplete(void) const
|
---|
| 266 | {
|
---|
[85537] | 267 | const size_t cbTotal = getTotalAnnounced();
|
---|
[85402] | 268 | LogFlowFunc(("cbProcessed=%zu, cbTotal=%zu\n", cbProcessed, cbTotal));
|
---|
[85423] | 269 | AssertReturn(cbProcessed <= cbTotal, true);
|
---|
[58212] | 270 | return (cbProcessed == cbTotal);
|
---|
| 271 | }
|
---|
| 272 |
|
---|
[85553] | 273 | /**
|
---|
| 274 | * Returns the percentage (0-100) of the already processed data.
|
---|
| 275 | *
|
---|
| 276 | * @returns Percentage (0-100) of the already processed data.
|
---|
| 277 | */
|
---|
[58212] | 278 | uint8_t getPercentComplete(void) const
|
---|
| 279 | {
|
---|
[85537] | 280 | const size_t cbTotal = getTotalAnnounced();
|
---|
[85371] | 281 | return (uint8_t)(cbProcessed * 100 / RT_MAX(cbTotal, 1));
|
---|
[58212] | 282 | }
|
---|
| 283 |
|
---|
[85553] | 284 | /**
|
---|
| 285 | * Returns the remaining (outstanding) data left for processing.
|
---|
| 286 | *
|
---|
| 287 | * @returns Remaining (outstanding) data (in bytes) left for processing.
|
---|
| 288 | */
|
---|
[85402] | 289 | size_t getRemaining(void) const
|
---|
[58212] | 290 | {
|
---|
[85537] | 291 | const size_t cbTotal = getTotalAnnounced();
|
---|
[85371] | 292 | AssertReturn(cbProcessed <= cbTotal, 0);
|
---|
[58212] | 293 | return cbTotal - cbProcessed;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[85553] | 296 | /**
|
---|
| 297 | * Returns the total data size (in bytes) announced.
|
---|
| 298 | *
|
---|
| 299 | * @returns Total data size (in bytes) announced.
|
---|
| 300 | */
|
---|
[85537] | 301 | size_t getTotalAnnounced(void) const
|
---|
[85371] | 302 | {
|
---|
[85537] | 303 | return Meta.cbAnnounced + cbExtra;
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[85553] | 306 | /**
|
---|
| 307 | * Returns the total data size (in bytes) available.
|
---|
| 308 | * For receiving data, this represents the already received data.
|
---|
| 309 | * For sending data, this represents the data left to send.
|
---|
| 310 | *
|
---|
| 311 | * @returns Total data size (in bytes) available.
|
---|
| 312 | */
|
---|
[85537] | 313 | size_t getTotalAvailable(void) const
|
---|
| 314 | {
|
---|
[85371] | 315 | return Meta.cbData + cbExtra;
|
---|
| 316 | }
|
---|
[58212] | 317 |
|
---|
[85553] | 318 | /**
|
---|
| 319 | * Resets all data.
|
---|
| 320 | */
|
---|
[58212] | 321 | void reset(void)
|
---|
| 322 | {
|
---|
[85371] | 323 | Meta.reset();
|
---|
[58212] | 324 |
|
---|
[85371] | 325 | cbExtra = 0;
|
---|
[55556] | 326 | cbProcessed = 0;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[58212] | 329 | /** For storing the actual meta data.
|
---|
| 330 | * This might be an URI list or just plain raw data,
|
---|
| 331 | * according to the format being sent. */
|
---|
[85402] | 332 | GuestDnDMetaData Meta;
|
---|
[85371] | 333 | /** Extra data to send/receive (in bytes). Can be 0 for raw data.
|
---|
| 334 | * For (file) transfers this is the total size for all files. */
|
---|
[85402] | 335 | size_t cbExtra;
|
---|
[58212] | 336 | /** Overall size (in bytes) of processed data. */
|
---|
[85402] | 337 | size_t cbProcessed;
|
---|
[58212] | 338 | };
|
---|
| 339 |
|
---|
[78095] | 340 | /** Initial object context state / no state set. */
|
---|
[85371] | 341 | #define DND_OBJ_STATE_NONE 0
|
---|
[78095] | 342 | /** The header was received / sent. */
|
---|
[85371] | 343 | #define DND_OBJ_STATE_HAS_HDR RT_BIT(0)
|
---|
[78095] | 344 | /** Validation mask for object context state. */
|
---|
[85371] | 345 | #define DND_OBJ_STATE_VALID_MASK UINT32_C(0x00000001)
|
---|
[58329] | 346 |
|
---|
[55512] | 347 | /**
|
---|
[85553] | 348 | * Base class for keeping around DnD (file) transfer data.
|
---|
| 349 | * Used for sending / receiving transfer data.
|
---|
[57500] | 350 | */
|
---|
[85371] | 351 | struct GuestDnDTransferData
|
---|
[57500] | 352 | {
|
---|
[58212] | 353 |
|
---|
[57500] | 354 | public:
|
---|
| 355 |
|
---|
[85371] | 356 | GuestDnDTransferData(void)
|
---|
[58212] | 357 | : cObjToProcess(0)
|
---|
| 358 | , cObjProcessed(0)
|
---|
| 359 | , pvScratchBuf(NULL)
|
---|
[57654] | 360 | , cbScratchBuf(0) { }
|
---|
[55556] | 361 |
|
---|
[85371] | 362 | virtual ~GuestDnDTransferData(void)
|
---|
[55556] | 363 | {
|
---|
[85371] | 364 | destroy();
|
---|
[55556] | 365 | }
|
---|
| 366 |
|
---|
[85553] | 367 | /**
|
---|
| 368 | * Initializes a transfer data object.
|
---|
| 369 | *
|
---|
| 370 | * @param cbBuf Scratch buffer size (in bytes) to use.
|
---|
[85557] | 371 | * If not specified, DND_DEFAULT_CHUNK_SIZE will be used.
|
---|
[85553] | 372 | */
|
---|
[85557] | 373 | int init(size_t cbBuf = DND_DEFAULT_CHUNK_SIZE)
|
---|
[57469] | 374 | {
|
---|
[58212] | 375 | reset();
|
---|
[57469] | 376 |
|
---|
| 377 | pvScratchBuf = RTMemAlloc(cbBuf);
|
---|
| 378 | if (!pvScratchBuf)
|
---|
| 379 | return VERR_NO_MEMORY;
|
---|
| 380 |
|
---|
| 381 | cbScratchBuf = cbBuf;
|
---|
| 382 | return VINF_SUCCESS;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[85553] | 385 | /**
|
---|
| 386 | * Destroys a transfer data object.
|
---|
| 387 | */
|
---|
[85371] | 388 | void destroy(void)
|
---|
[58212] | 389 | {
|
---|
[85371] | 390 | reset();
|
---|
[58329] | 391 |
|
---|
[85371] | 392 | if (pvScratchBuf)
|
---|
[58212] | 393 | {
|
---|
[85371] | 394 | Assert(cbScratchBuf);
|
---|
| 395 | RTMemFree(pvScratchBuf);
|
---|
| 396 | pvScratchBuf = NULL;
|
---|
[58212] | 397 | }
|
---|
[85371] | 398 | cbScratchBuf = 0;
|
---|
[58212] | 399 | }
|
---|
| 400 |
|
---|
[85553] | 401 | /**
|
---|
| 402 | * Resets a transfer data object.
|
---|
| 403 | */
|
---|
[58329] | 404 | void reset(void)
|
---|
[58212] | 405 | {
|
---|
[58329] | 406 | LogFlowFuncEnter();
|
---|
| 407 |
|
---|
| 408 | cObjToProcess = 0;
|
---|
[58212] | 409 | cObjProcessed = 0;
|
---|
| 410 | }
|
---|
[56901] | 411 |
|
---|
[85553] | 412 | /**
|
---|
| 413 | * Returns whether this transfer object is complete or not.
|
---|
| 414 | *
|
---|
| 415 | * @returns \c true if complete, \c false if not.
|
---|
| 416 | */
|
---|
[85371] | 417 | bool isComplete(void) const
|
---|
[58329] | 418 | {
|
---|
[85371] | 419 | return (cObjProcessed == cObjToProcess);
|
---|
[58329] | 420 | }
|
---|
| 421 |
|
---|
[85371] | 422 | /** Number of objects to process. */
|
---|
| 423 | uint64_t cObjToProcess;
|
---|
| 424 | /** Number of objects already processed. */
|
---|
| 425 | uint64_t cObjProcessed;
|
---|
| 426 | /** Pointer to an optional scratch buffer to use for
|
---|
| 427 | * doing the actual chunk transfers. */
|
---|
| 428 | void *pvScratchBuf;
|
---|
| 429 | /** Size (in bytes) of scratch buffer. */
|
---|
| 430 | size_t cbScratchBuf;
|
---|
| 431 | };
|
---|
[56901] | 432 |
|
---|
[85553] | 433 | /**
|
---|
| 434 | * Class for keeping around DnD transfer send data (Host -> Guest).
|
---|
| 435 | */
|
---|
[85371] | 436 | struct GuestDnDTransferSendData : public GuestDnDTransferData
|
---|
| 437 | {
|
---|
| 438 | GuestDnDTransferSendData()
|
---|
[85402] | 439 | : fObjState(0)
|
---|
[85373] | 440 | {
|
---|
[85402] | 441 | RT_ZERO(List);
|
---|
[98273] | 442 | int vrc2 = DnDTransferListInit(&List);
|
---|
| 443 | AssertRC(vrc2);
|
---|
[85373] | 444 | }
|
---|
[58212] | 445 |
|
---|
[85371] | 446 | virtual ~GuestDnDTransferSendData()
|
---|
[58329] | 447 | {
|
---|
[85371] | 448 | destroy();
|
---|
[58329] | 449 | }
|
---|
| 450 |
|
---|
[85553] | 451 | /**
|
---|
| 452 | * Destroys the object.
|
---|
| 453 | */
|
---|
[85371] | 454 | void destroy(void)
|
---|
[58212] | 455 | {
|
---|
[85402] | 456 | DnDTransferListDestroy(&List);
|
---|
[58212] | 457 | }
|
---|
| 458 |
|
---|
[85553] | 459 | /**
|
---|
| 460 | * Resets the object.
|
---|
| 461 | */
|
---|
[85371] | 462 | void reset(void)
|
---|
[58212] | 463 | {
|
---|
[85402] | 464 | DnDTransferListReset(&List);
|
---|
| 465 | fObjState = 0;
|
---|
[58212] | 466 |
|
---|
[85371] | 467 | GuestDnDTransferData::reset();
|
---|
[58212] | 468 | }
|
---|
| 469 |
|
---|
[85371] | 470 | /** Transfer List to handle. */
|
---|
[85402] | 471 | DNDTRANSFERLIST List;
|
---|
[85371] | 472 | /** Current state of object in transfer.
|
---|
| 473 | * This is needed for keeping compatibility to old(er) DnD HGCM protocols.
|
---|
| 474 | *
|
---|
| 475 | * At the moment we only support transferring one object at a time. */
|
---|
[85402] | 476 | uint32_t fObjState;
|
---|
[58212] | 477 | };
|
---|
[55556] | 478 |
|
---|
| 479 | /**
|
---|
[55422] | 480 | * Context structure for sending data to the guest.
|
---|
[51476] | 481 | */
|
---|
[85371] | 482 | struct GuestDnDSendCtx : public GuestDnDData
|
---|
[55422] | 483 | {
|
---|
[85537] | 484 | GuestDnDSendCtx(void);
|
---|
| 485 |
|
---|
[85553] | 486 | /**
|
---|
| 487 | * Resets the object.
|
---|
| 488 | */
|
---|
[85537] | 489 | void reset(void);
|
---|
| 490 |
|
---|
[55422] | 491 | /** Pointer to guest target class this context belongs to. */
|
---|
[85402] | 492 | GuestDnDTarget *pTarget;
|
---|
[85744] | 493 | /** Pointer to guest state this context belongs to. */
|
---|
| 494 | GuestDnDState *pState;
|
---|
[55422] | 495 | /** Target (VM) screen ID. */
|
---|
[85402] | 496 | uint32_t uScreenID;
|
---|
[85371] | 497 | /** Transfer data structure. */
|
---|
[85402] | 498 | GuestDnDTransferSendData Transfer;
|
---|
[55512] | 499 | /** Callback event to use. */
|
---|
[85402] | 500 | GuestDnDCallbackEvent EventCallback;
|
---|
[85018] | 501 | };
|
---|
[55422] | 502 |
|
---|
[85371] | 503 | struct GuestDnDTransferRecvData : public GuestDnDTransferData
|
---|
| 504 | {
|
---|
| 505 | GuestDnDTransferRecvData()
|
---|
| 506 | {
|
---|
[85402] | 507 | RT_ZERO(DroppedFiles);
|
---|
[98273] | 508 | int vrc2 = DnDDroppedFilesInit(&DroppedFiles);
|
---|
| 509 | AssertRC(vrc2);
|
---|
[85436] | 510 |
|
---|
[85402] | 511 | RT_ZERO(List);
|
---|
[98273] | 512 | vrc2 = DnDTransferListInit(&List);
|
---|
| 513 | AssertRC(vrc2);
|
---|
[85436] | 514 |
|
---|
[85402] | 515 | RT_ZERO(ObjCur);
|
---|
[98273] | 516 | vrc2 = DnDTransferObjectInit(&ObjCur);
|
---|
| 517 | AssertRC(vrc2);
|
---|
[85371] | 518 | }
|
---|
| 519 |
|
---|
| 520 | virtual ~GuestDnDTransferRecvData()
|
---|
| 521 | {
|
---|
| 522 | destroy();
|
---|
| 523 | }
|
---|
| 524 |
|
---|
[85553] | 525 | /**
|
---|
| 526 | * Destroys the object.
|
---|
| 527 | */
|
---|
[85371] | 528 | void destroy(void)
|
---|
| 529 | {
|
---|
[85402] | 530 | DnDTransferListDestroy(&List);
|
---|
[85371] | 531 | }
|
---|
| 532 |
|
---|
[85553] | 533 | /**
|
---|
| 534 | * Resets the object.
|
---|
| 535 | */
|
---|
[85371] | 536 | void reset(void)
|
---|
| 537 | {
|
---|
[85402] | 538 | DnDDroppedFilesClose(&DroppedFiles);
|
---|
| 539 | DnDTransferListReset(&List);
|
---|
| 540 | DnDTransferObjectReset(&ObjCur);
|
---|
[85371] | 541 |
|
---|
| 542 | GuestDnDTransferData::reset();
|
---|
| 543 | }
|
---|
| 544 |
|
---|
| 545 | /** The "VirtualBox Dropped Files" directory on the host we're going
|
---|
| 546 | * to utilize for transferring files from guest to the host. */
|
---|
[85402] | 547 | DNDDROPPEDFILES DroppedFiles;
|
---|
[85371] | 548 | /** Transfer List to handle.
|
---|
| 549 | * Currently we only support one transfer list at a time. */
|
---|
[85402] | 550 | DNDTRANSFERLIST List;
|
---|
[85371] | 551 | /** Current transfer object being handled.
|
---|
| 552 | * Currently we only support one transfer object at a time. */
|
---|
[85402] | 553 | DNDTRANSFEROBJECT ObjCur;
|
---|
[85371] | 554 | };
|
---|
| 555 |
|
---|
[55422] | 556 | /**
|
---|
| 557 | * Context structure for receiving data from the guest.
|
---|
| 558 | */
|
---|
[85371] | 559 | struct GuestDnDRecvCtx : public GuestDnDData
|
---|
[55422] | 560 | {
|
---|
[85537] | 561 | GuestDnDRecvCtx(void);
|
---|
| 562 |
|
---|
[85553] | 563 | /**
|
---|
| 564 | * Resets the object.
|
---|
| 565 | */
|
---|
[85537] | 566 | void reset(void);
|
---|
| 567 |
|
---|
[55422] | 568 | /** Pointer to guest source class this context belongs to. */
|
---|
[85402] | 569 | GuestDnDSource *pSource;
|
---|
[85744] | 570 | /** Pointer to guest state this context belongs to. */
|
---|
| 571 | GuestDnDState *pState;
|
---|
[57221] | 572 | /** Formats offered by the guest (and supported by the host). */
|
---|
[85402] | 573 | GuestDnDMIMEList lstFmtOffered;
|
---|
[85423] | 574 | /** Original drop format requested to receive from the guest. */
|
---|
[85402] | 575 | com::Utf8Str strFmtReq;
|
---|
[58212] | 576 | /** Intermediate drop format to be received from the guest.
|
---|
[57221] | 577 | * Some original drop formats require a different intermediate
|
---|
| 578 | * drop format:
|
---|
| 579 | *
|
---|
| 580 | * Receiving a file link as "text/plain" requires still to
|
---|
| 581 | * receive the file from the guest as "text/uri-list" first,
|
---|
[58212] | 582 | * then pointing to the file path on the host with the data
|
---|
| 583 | * in "text/plain" format returned. */
|
---|
[85402] | 584 | com::Utf8Str strFmtRecv;
|
---|
[55422] | 585 | /** Desired drop action to perform on the host.
|
---|
| 586 | * Needed to tell the guest if data has to be
|
---|
| 587 | * deleted e.g. when moving instead of copying. */
|
---|
[85402] | 588 | VBOXDNDACTION enmAction;
|
---|
[85371] | 589 | /** Transfer data structure. */
|
---|
[85402] | 590 | GuestDnDTransferRecvData Transfer;
|
---|
[55512] | 591 | /** Callback event to use. */
|
---|
[85402] | 592 | GuestDnDCallbackEvent EventCallback;
|
---|
[85018] | 593 | };
|
---|
[55422] | 594 |
|
---|
| 595 | /**
|
---|
[85553] | 596 | * Class for maintainig a (buffered) guest DnD message.
|
---|
[55422] | 597 | */
|
---|
| 598 | class GuestDnDMsg
|
---|
| 599 | {
|
---|
| 600 | public:
|
---|
| 601 |
|
---|
| 602 | GuestDnDMsg(void)
|
---|
| 603 | : uMsg(0)
|
---|
| 604 | , cParms(0)
|
---|
| 605 | , cParmsAlloc(0)
|
---|
| 606 | , paParms(NULL) { }
|
---|
| 607 |
|
---|
| 608 | virtual ~GuestDnDMsg(void)
|
---|
| 609 | {
|
---|
[58212] | 610 | reset();
|
---|
[55422] | 611 | }
|
---|
| 612 |
|
---|
| 613 | public:
|
---|
| 614 |
|
---|
[85553] | 615 | /**
|
---|
| 616 | * Appends a new HGCM parameter to the message and returns the pointer to it.
|
---|
| 617 | */
|
---|
[55422] | 618 | PVBOXHGCMSVCPARM getNextParam(void)
|
---|
| 619 | {
|
---|
| 620 | if (cParms >= cParmsAlloc)
|
---|
| 621 | {
|
---|
| 622 | if (!paParms)
|
---|
[58212] | 623 | paParms = (PVBOXHGCMSVCPARM)RTMemAlloc(4 * sizeof(VBOXHGCMSVCPARM));
|
---|
| 624 | else
|
---|
| 625 | paParms = (PVBOXHGCMSVCPARM)RTMemRealloc(paParms, (cParmsAlloc + 4) * sizeof(VBOXHGCMSVCPARM));
|
---|
| 626 | if (!paParms)
|
---|
[55422] | 627 | throw VERR_NO_MEMORY;
|
---|
| 628 | RT_BZERO(&paParms[cParmsAlloc], 4 * sizeof(VBOXHGCMSVCPARM));
|
---|
| 629 | cParmsAlloc += 4;
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | return &paParms[cParms++];
|
---|
| 633 | }
|
---|
| 634 |
|
---|
[85553] | 635 | /**
|
---|
| 636 | * Returns the current parameter count.
|
---|
| 637 | *
|
---|
| 638 | * @returns Current parameter count.
|
---|
| 639 | */
|
---|
[55422] | 640 | uint32_t getCount(void) const { return cParms; }
|
---|
[85553] | 641 |
|
---|
| 642 | /**
|
---|
| 643 | * Returns the pointer to the beginning of the HGCM parameters array. Use with care.
|
---|
| 644 | *
|
---|
| 645 | * @returns Pointer to the beginning of the HGCM parameters array.
|
---|
| 646 | */
|
---|
[55422] | 647 | PVBOXHGCMSVCPARM getParms(void) const { return paParms; }
|
---|
[85553] | 648 |
|
---|
| 649 | /**
|
---|
| 650 | * Returns the message type.
|
---|
| 651 | *
|
---|
| 652 | * @returns Message type.
|
---|
| 653 | */
|
---|
[55422] | 654 | uint32_t getType(void) const { return uMsg; }
|
---|
| 655 |
|
---|
[85553] | 656 | /**
|
---|
| 657 | * Resets the object.
|
---|
| 658 | */
|
---|
[58212] | 659 | void reset(void)
|
---|
| 660 | {
|
---|
| 661 | if (paParms)
|
---|
| 662 | {
|
---|
| 663 | /* Remove deep copies. */
|
---|
| 664 | for (uint32_t i = 0; i < cParms; i++)
|
---|
| 665 | {
|
---|
| 666 | if ( paParms[i].type == VBOX_HGCM_SVC_PARM_PTR
|
---|
| 667 | && paParms[i].u.pointer.size)
|
---|
| 668 | {
|
---|
| 669 | AssertPtr(paParms[i].u.pointer.addr);
|
---|
| 670 | RTMemFree(paParms[i].u.pointer.addr);
|
---|
| 671 | }
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | RTMemFree(paParms);
|
---|
| 675 | paParms = NULL;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | uMsg = cParms = cParmsAlloc = 0;
|
---|
| 679 | }
|
---|
| 680 |
|
---|
[85553] | 681 | /**
|
---|
| 682 | * Appends a new message parameter of type pointer.
|
---|
| 683 | *
|
---|
| 684 | * @returns VBox status code.
|
---|
| 685 | * @param pvBuf Pointer to data to use.
|
---|
| 686 | * @param cbBuf Size (in bytes) of data to use.
|
---|
| 687 | */
|
---|
[85554] | 688 | int appendPointer(void *pvBuf, uint32_t cbBuf)
|
---|
[55422] | 689 | {
|
---|
| 690 | PVBOXHGCMSVCPARM pParm = getNextParam();
|
---|
| 691 | if (!pParm)
|
---|
| 692 | return VERR_NO_MEMORY;
|
---|
| 693 |
|
---|
[58212] | 694 | void *pvTmp = NULL;
|
---|
[85423] | 695 | if (cbBuf)
|
---|
[55422] | 696 | {
|
---|
[85423] | 697 | AssertPtr(pvBuf);
|
---|
[58212] | 698 | pvTmp = RTMemDup(pvBuf, cbBuf);
|
---|
| 699 | if (!pvTmp)
|
---|
| 700 | return VERR_NO_MEMORY;
|
---|
[55422] | 701 | }
|
---|
| 702 |
|
---|
[75737] | 703 | HGCMSvcSetPv(pParm, pvTmp, cbBuf);
|
---|
[55422] | 704 | return VINF_SUCCESS;
|
---|
| 705 | }
|
---|
| 706 |
|
---|
[85553] | 707 | /**
|
---|
| 708 | * Appends a new message parameter of type string.
|
---|
| 709 | *
|
---|
| 710 | * @returns VBox status code.
|
---|
| 711 | * @param pszString Pointer to string data to use.
|
---|
| 712 | */
|
---|
[85554] | 713 | int appendString(const char *pszString)
|
---|
[55422] | 714 | {
|
---|
| 715 | PVBOXHGCMSVCPARM pParm = getNextParam();
|
---|
| 716 | if (!pParm)
|
---|
| 717 | return VERR_NO_MEMORY;
|
---|
| 718 |
|
---|
| 719 | char *pszTemp = RTStrDup(pszString);
|
---|
| 720 | if (!pszTemp)
|
---|
| 721 | return VERR_NO_MEMORY;
|
---|
| 722 |
|
---|
[75737] | 723 | HGCMSvcSetStr(pParm, pszTemp);
|
---|
[55422] | 724 | return VINF_SUCCESS;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
[85553] | 727 | /**
|
---|
| 728 | * Appends a new message parameter of type uint32_t.
|
---|
| 729 | *
|
---|
| 730 | * @returns VBox status code.
|
---|
| 731 | * @param u32Val uint32_t value to use.
|
---|
| 732 | */
|
---|
[85554] | 733 | int appendUInt32(uint32_t u32Val)
|
---|
[55422] | 734 | {
|
---|
| 735 | PVBOXHGCMSVCPARM pParm = getNextParam();
|
---|
| 736 | if (!pParm)
|
---|
| 737 | return VERR_NO_MEMORY;
|
---|
| 738 |
|
---|
[75737] | 739 | HGCMSvcSetU32(pParm, u32Val);
|
---|
[55422] | 740 | return VINF_SUCCESS;
|
---|
| 741 | }
|
---|
| 742 |
|
---|
[85553] | 743 | /**
|
---|
| 744 | * Appends a new message parameter of type uint64_t.
|
---|
| 745 | *
|
---|
| 746 | * @returns VBox status code.
|
---|
| 747 | * @param u64Val uint64_t value to use.
|
---|
| 748 | */
|
---|
[85554] | 749 | int appendUInt64(uint64_t u64Val)
|
---|
[55422] | 750 | {
|
---|
| 751 | PVBOXHGCMSVCPARM pParm = getNextParam();
|
---|
| 752 | if (!pParm)
|
---|
| 753 | return VERR_NO_MEMORY;
|
---|
| 754 |
|
---|
[75737] | 755 | HGCMSvcSetU64(pParm, u64Val);
|
---|
[55422] | 756 | return VINF_SUCCESS;
|
---|
| 757 | }
|
---|
| 758 |
|
---|
[85553] | 759 | /**
|
---|
| 760 | * Sets the HGCM message type (function number).
|
---|
| 761 | *
|
---|
| 762 | * @param uMsgType Message type to set.
|
---|
| 763 | */
|
---|
[55422] | 764 | void setType(uint32_t uMsgType) { uMsg = uMsgType; }
|
---|
| 765 |
|
---|
| 766 | protected:
|
---|
| 767 |
|
---|
| 768 | /** Message type. */
|
---|
| 769 | uint32_t uMsg;
|
---|
| 770 | /** Message parameters. */
|
---|
| 771 | uint32_t cParms;
|
---|
| 772 | /** Size of array. */
|
---|
| 773 | uint32_t cParmsAlloc;
|
---|
| 774 | /** Array of HGCM parameters */
|
---|
| 775 | PVBOXHGCMSVCPARM paParms;
|
---|
| 776 | };
|
---|
| 777 |
|
---|
| 778 | /** Guest DnD callback function definition. */
|
---|
[85121] | 779 | typedef DECLCALLBACKPTR(int, PFNGUESTDNDCALLBACK,(uint32_t uMsg, void *pvParms, size_t cbParms, void *pvUser));
|
---|
[55422] | 780 |
|
---|
| 781 | /**
|
---|
| 782 | * Structure for keeping a guest DnD callback.
|
---|
| 783 | * Each callback can handle one HGCM message, however, multiple HGCM messages can be registered
|
---|
| 784 | * to the same callback (function).
|
---|
| 785 | */
|
---|
| 786 | typedef struct GuestDnDCallback
|
---|
| 787 | {
|
---|
| 788 | GuestDnDCallback(void)
|
---|
| 789 | : uMessgage(0)
|
---|
| 790 | , pfnCallback(NULL)
|
---|
| 791 | , pvUser(NULL) { }
|
---|
| 792 |
|
---|
| 793 | GuestDnDCallback(PFNGUESTDNDCALLBACK pvCB, uint32_t uMsg, void *pvUsr = NULL)
|
---|
| 794 | : uMessgage(uMsg)
|
---|
| 795 | , pfnCallback(pvCB)
|
---|
| 796 | , pvUser(pvUsr) { }
|
---|
| 797 |
|
---|
| 798 | /** The HGCM message ID to handle. */
|
---|
| 799 | uint32_t uMessgage;
|
---|
| 800 | /** Pointer to callback function. */
|
---|
| 801 | PFNGUESTDNDCALLBACK pfnCallback;
|
---|
| 802 | /** Pointer to user-supplied data. */
|
---|
| 803 | void *pvUser;
|
---|
| 804 | } GuestDnDCallback;
|
---|
| 805 |
|
---|
| 806 | /** Contains registered callback pointers for specific HGCM message types. */
|
---|
| 807 | typedef std::map<uint32_t, GuestDnDCallback> GuestDnDCallbackMap;
|
---|
| 808 |
|
---|
[85744] | 809 | /**
|
---|
| 810 | * Class for keeping a DnD guest state around.
|
---|
| 811 | */
|
---|
[91312] | 812 | class GuestDnDState
|
---|
[51476] | 813 | {
|
---|
| 814 |
|
---|
| 815 | public:
|
---|
[90828] | 816 | DECLARE_TRANSLATE_METHODS(GuestDnDState)
|
---|
[51476] | 817 |
|
---|
[85744] | 818 | GuestDnDState(const ComObjPtr<Guest>& pGuest);
|
---|
| 819 | virtual ~GuestDnDState(void);
|
---|
[51476] | 820 |
|
---|
| 821 | public:
|
---|
| 822 |
|
---|
[97786] | 823 | VBOXDNDSTATE get(void) const { return m_enmState; }
|
---|
[97784] | 824 | int set(VBOXDNDSTATE enmState) { LogRel3(("DnD: State %s -> %s\n", DnDStateToStr(m_enmState), DnDStateToStr(enmState))); m_enmState = enmState; return 0; }
|
---|
| 825 | void lock() { RTCritSectEnter(&m_CritSect); };
|
---|
| 826 | void unlock() { RTCritSectLeave(&m_CritSect); };
|
---|
| 827 |
|
---|
[97783] | 828 | /** @name Guest response handling.
|
---|
| 829 | * @{ */
|
---|
[98273] | 830 | int notifyAboutGuestResponse(int vrcGuest = VINF_SUCCESS);
|
---|
| 831 | int waitForGuestResponseEx(RTMSINTERVAL msTimeout = 3000, int *pvrcGuest = NULL);
|
---|
| 832 | int waitForGuestResponse(int *pvrcGuest = NULL);
|
---|
[97783] | 833 | /** @} */
|
---|
[51476] | 834 |
|
---|
[74439] | 835 | void setActionsAllowed(VBOXDNDACTIONLIST a) { m_dndLstActionsAllowed = a; }
|
---|
| 836 | VBOXDNDACTIONLIST getActionsAllowed(void) const { return m_dndLstActionsAllowed; }
|
---|
[55422] | 837 |
|
---|
[74439] | 838 | void setActionDefault(VBOXDNDACTION a) { m_dndActionDefault = a; }
|
---|
| 839 | VBOXDNDACTION getActionDefault(void) const { return m_dndActionDefault; }
|
---|
[51476] | 840 |
|
---|
[57221] | 841 | void setFormats(const GuestDnDMIMEList &lstFormats) { m_lstFormats = lstFormats; }
|
---|
| 842 | GuestDnDMIMEList formats(void) const { return m_lstFormats; }
|
---|
[51476] | 843 |
|
---|
[55422] | 844 | void reset(void);
|
---|
| 845 |
|
---|
[97788] | 846 | /** @name Callback handling.
|
---|
| 847 | * @{ */
|
---|
| 848 | static DECLCALLBACK(int) i_defaultCallback(uint32_t uMsg, void *pvParms, size_t cbParms, void *pvUser);
|
---|
| 849 | int setCallback(uint32_t uMsg, PFNGUESTDNDCALLBACK pfnCallback, void *pvUser = NULL);
|
---|
| 850 | /** @} */
|
---|
| 851 |
|
---|
| 852 | /** @name Progress handling.
|
---|
| 853 | * @{ */
|
---|
[55422] | 854 | bool isProgressCanceled(void) const;
|
---|
[97801] | 855 | bool isProgressRunning(void) const;
|
---|
[98286] | 856 | int setProgress(unsigned uPercentage, uint32_t uStatus, int vrcOp = VINF_SUCCESS,
|
---|
[98273] | 857 | const Utf8Str &strMsg = Utf8Str::Empty /** @todo figure out what's the best way to pass empty Utf8Str by default - probably = Utf8Str() */);
|
---|
[97802] | 858 | HRESULT resetProgress(const ComObjPtr<Guest>& pParent, const Utf8Str &strDesc);
|
---|
[51476] | 859 | HRESULT queryProgressTo(IProgress **ppProgress);
|
---|
[97788] | 860 | /** @} */
|
---|
[51476] | 861 |
|
---|
[55422] | 862 | public:
|
---|
[51476] | 863 |
|
---|
[55422] | 864 | /** @name HGCM callback handling.
|
---|
| 865 | @{ */
|
---|
| 866 | int onDispatch(uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
| 867 | /** @} */
|
---|
| 868 |
|
---|
[85739] | 869 | public:
|
---|
[51476] | 870 |
|
---|
[55422] | 871 | /** Pointer to context this class is tied to. */
|
---|
| 872 | void *m_pvCtx;
|
---|
[97784] | 873 | RTCRITSECT m_CritSect;
|
---|
| 874 | /** The current state we're in. */
|
---|
| 875 | VBOXDNDSTATE m_enmState;
|
---|
[85739] | 876 | /** The DnD protocol version to use, depending on the
|
---|
| 877 | * installed Guest Additions. See DragAndDropSvc.h for
|
---|
| 878 | * a protocol changelog. */
|
---|
| 879 | uint32_t m_uProtocolVersion;
|
---|
| 880 | /** The guest feature flags reported to the host (VBOX_DND_GF_XXX). */
|
---|
| 881 | uint64_t m_fGuestFeatures0;
|
---|
[56653] | 882 | /** Event for waiting for response. */
|
---|
[55422] | 883 | RTSEMEVENT m_EventSem;
|
---|
[97783] | 884 | /** Last error reported from guest.
|
---|
| 885 | * Set to VERR_IPE_UNINITIALIZED_STATUS if not set yet. */
|
---|
[98273] | 886 | int m_vrcGuest;
|
---|
[56653] | 887 | /** Default action to perform in case of a
|
---|
| 888 | * successful drop. */
|
---|
[74439] | 889 | VBOXDNDACTION m_dndActionDefault;
|
---|
| 890 | /** Actions supported by the guest in case of a successful drop. */
|
---|
| 891 | VBOXDNDACTIONLIST m_dndLstActionsAllowed;
|
---|
[57221] | 892 | /** Format(s) requested/supported from the guest. */
|
---|
| 893 | GuestDnDMIMEList m_lstFormats;
|
---|
[55422] | 894 | /** Pointer to IGuest parent object. */
|
---|
[58212] | 895 | ComObjPtr<Guest> m_pParent;
|
---|
[55422] | 896 | /** Pointer to associated progress object. Optional. */
|
---|
[58212] | 897 | ComObjPtr<Progress> m_pProgress;
|
---|
[55422] | 898 | /** Callback map. */
|
---|
| 899 | GuestDnDCallbackMap m_mapCallbacks;
|
---|
[51476] | 900 | };
|
---|
| 901 |
|
---|
| 902 | /**
|
---|
[85537] | 903 | * Private singleton class for the guest's DnD implementation.
|
---|
[58212] | 904 | *
|
---|
[85537] | 905 | * Can't be instanciated directly, only via the factory pattern.
|
---|
| 906 | * Keeps track of all ongoing DnD transfers.
|
---|
[51476] | 907 | */
|
---|
[42261] | 908 | class GuestDnD
|
---|
| 909 | {
|
---|
| 910 | public:
|
---|
[51476] | 911 |
|
---|
[85553] | 912 | /**
|
---|
| 913 | * Creates the Singleton GuestDnD object.
|
---|
| 914 | *
|
---|
| 915 | * @returns Newly created Singleton object, or NULL on failure.
|
---|
| 916 | */
|
---|
[51476] | 917 | static GuestDnD *createInstance(const ComObjPtr<Guest>& pGuest)
|
---|
| 918 | {
|
---|
| 919 | Assert(NULL == GuestDnD::s_pInstance);
|
---|
| 920 | GuestDnD::s_pInstance = new GuestDnD(pGuest);
|
---|
| 921 | return GuestDnD::s_pInstance;
|
---|
| 922 | }
|
---|
| 923 |
|
---|
[85553] | 924 | /**
|
---|
| 925 | * Destroys the Singleton GuestDnD object.
|
---|
| 926 | */
|
---|
[51476] | 927 | static void destroyInstance(void)
|
---|
| 928 | {
|
---|
| 929 | if (GuestDnD::s_pInstance)
|
---|
| 930 | {
|
---|
| 931 | delete GuestDnD::s_pInstance;
|
---|
| 932 | GuestDnD::s_pInstance = NULL;
|
---|
| 933 | }
|
---|
| 934 | }
|
---|
| 935 |
|
---|
[85553] | 936 | /**
|
---|
| 937 | * Returns the Singleton GuestDnD object.
|
---|
| 938 | *
|
---|
| 939 | * @returns Pointer to Singleton GuestDnD object, or NULL if not created yet.
|
---|
| 940 | */
|
---|
[51476] | 941 | static inline GuestDnD *getInstance(void)
|
---|
| 942 | {
|
---|
| 943 | AssertPtr(GuestDnD::s_pInstance);
|
---|
| 944 | return GuestDnD::s_pInstance;
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | protected:
|
---|
| 948 |
|
---|
[85537] | 949 | /** List of registered DnD sources. */
|
---|
| 950 | typedef std::list< ComObjPtr<GuestDnDSource> > GuestDnDSrcList;
|
---|
| 951 | /** List of registered DnD targets. */
|
---|
| 952 | typedef std::list< ComObjPtr<GuestDnDTarget> > GuestDnDTgtList;
|
---|
| 953 |
|
---|
[98273] | 954 | /** Constructor; will throw vrc on failure. */
|
---|
[42261] | 955 | GuestDnD(const ComObjPtr<Guest>& pGuest);
|
---|
[51476] | 956 | virtual ~GuestDnD(void);
|
---|
[42261] | 957 |
|
---|
[51476] | 958 | public:
|
---|
[42261] | 959 |
|
---|
[51476] | 960 | /** @name Public helper functions.
|
---|
| 961 | * @{ */
|
---|
[58212] | 962 | HRESULT adjustScreenCoordinates(ULONG uScreenId, ULONG *puX, ULONG *puY) const;
|
---|
[85744] | 963 | GuestDnDState *getState(uint32_t = 0) const;
|
---|
[58212] | 964 | int hostCall(uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const;
|
---|
| 965 | GuestDnDMIMEList defaultFormats(void) const { return m_strDefaultFormats; }
|
---|
[51476] | 966 | /** @} */
|
---|
[42261] | 967 |
|
---|
[86530] | 968 | /** @name Source / target management.
|
---|
| 969 | * @{ */
|
---|
[85537] | 970 | int registerSource(const ComObjPtr<GuestDnDSource> &Source);
|
---|
| 971 | int unregisterSource(const ComObjPtr<GuestDnDSource> &Source);
|
---|
| 972 | size_t getSourceCount(void);
|
---|
| 973 |
|
---|
| 974 | int registerTarget(const ComObjPtr<GuestDnDTarget> &Target);
|
---|
| 975 | int unregisterTarget(const ComObjPtr<GuestDnDTarget> &Target);
|
---|
| 976 | size_t getTargetCount(void);
|
---|
| 977 | /** @} */
|
---|
| 978 |
|
---|
[51476] | 979 | public:
|
---|
[42261] | 980 |
|
---|
[51476] | 981 | /** @name Static low-level HGCM callback handler.
|
---|
| 982 | * @{ */
|
---|
| 983 | static DECLCALLBACK(int) notifyDnDDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
| 984 | /** @} */
|
---|
| 985 |
|
---|
| 986 | /** @name Static helper methods.
|
---|
| 987 | * @{ */
|
---|
[57221] | 988 | static bool isFormatInFormatList(const com::Utf8Str &strFormat, const GuestDnDMIMEList &lstFormats);
|
---|
[85746] | 989 | static GuestDnDMIMEList toFormatList(const com::Utf8Str &strFormats, const com::Utf8Str &strSep = DND_FORMATS_SEPARATOR_STR);
|
---|
[97772] | 990 | static com::Utf8Str toFormatString(const GuestDnDMIMEList &lstFormats, const com::Utf8Str &strSep = DND_FORMATS_SEPARATOR_STR);
|
---|
[57221] | 991 | static GuestDnDMIMEList toFilteredFormatList(const GuestDnDMIMEList &lstFormatsSupported, const GuestDnDMIMEList &lstFormatsWanted);
|
---|
| 992 | static GuestDnDMIMEList toFilteredFormatList(const GuestDnDMIMEList &lstFormatsSupported, const com::Utf8Str &strFormatsWanted);
|
---|
[74439] | 993 | static DnDAction_T toMainAction(VBOXDNDACTION dndAction);
|
---|
| 994 | static std::vector<DnDAction_T> toMainActions(VBOXDNDACTIONLIST dndActionList);
|
---|
| 995 | static VBOXDNDACTION toHGCMAction(DnDAction_T enmAction);
|
---|
| 996 | static void toHGCMActions(DnDAction_T enmDefAction, VBOXDNDACTION *pDefAction, const std::vector<DnDAction_T> vecAllowedActions, VBOXDNDACTIONLIST *pLstAllowedActions);
|
---|
[51476] | 997 | /** @} */
|
---|
| 998 |
|
---|
[50508] | 999 | protected:
|
---|
| 1000 |
|
---|
[51476] | 1001 | /** @name Singleton properties.
|
---|
| 1002 | * @{ */
|
---|
[51556] | 1003 | /** List of supported default MIME/Content-type formats. */
|
---|
[85537] | 1004 | GuestDnDMIMEList m_strDefaultFormats;
|
---|
[51476] | 1005 | /** Pointer to guest implementation. */
|
---|
[85537] | 1006 | const ComObjPtr<Guest> m_pGuest;
|
---|
[85744] | 1007 | /** The current state from the guest. At the
|
---|
| 1008 | * moment we only support only state a time (ARQ-style). */
|
---|
| 1009 | GuestDnDState *m_pState;
|
---|
[85537] | 1010 | /** Critical section to serialize access. */
|
---|
| 1011 | RTCRITSECT m_CritSect;
|
---|
| 1012 | /** Number of active transfers (guest->host or host->guest). */
|
---|
| 1013 | uint32_t m_cTransfersPending;
|
---|
| 1014 | GuestDnDSrcList m_lstSrc;
|
---|
| 1015 | GuestDnDTgtList m_lstTgt;
|
---|
[51476] | 1016 | /** @} */
|
---|
| 1017 |
|
---|
[42261] | 1018 | private:
|
---|
| 1019 |
|
---|
[85537] | 1020 | /** Static pointer to singleton instance. */
|
---|
[51476] | 1021 | static GuestDnD *s_pInstance;
|
---|
[42261] | 1022 | };
|
---|
| 1023 |
|
---|
[78093] | 1024 | /** Access to the GuestDnD's singleton instance. */
|
---|
[85537] | 1025 | #define GuestDnDInst() GuestDnD::getInstance()
|
---|
[42261] | 1026 |
|
---|
[55422] | 1027 | /** List of pointers to guest DnD Messages. */
|
---|
| 1028 | typedef std::list<GuestDnDMsg *> GuestDnDMsgList;
|
---|
| 1029 |
|
---|
[51556] | 1030 | /**
|
---|
| 1031 | * IDnDBase class implementation for sharing code between
|
---|
| 1032 | * IGuestDnDSource and IGuestDnDTarget implementation.
|
---|
| 1033 | */
|
---|
| 1034 | class GuestDnDBase
|
---|
| 1035 | {
|
---|
| 1036 | protected:
|
---|
| 1037 |
|
---|
[97780] | 1038 | GuestDnDBase(VirtualBoxBase *pBase);
|
---|
[51556] | 1039 |
|
---|
[97781] | 1040 | virtual ~GuestDnDBase(void);
|
---|
| 1041 |
|
---|
[51556] | 1042 | protected:
|
---|
| 1043 |
|
---|
[55422] | 1044 | /** Shared (internal) IDnDBase method implementations.
|
---|
[51556] | 1045 | * @{ */
|
---|
[85559] | 1046 | bool i_isFormatSupported(const com::Utf8Str &aFormat) const;
|
---|
[85558] | 1047 | const GuestDnDMIMEList &i_getFormats(void) const;
|
---|
[57221] | 1048 | HRESULT i_addFormats(const GuestDnDMIMEList &aFormats);
|
---|
| 1049 | HRESULT i_removeFormats(const GuestDnDMIMEList &aFormats);
|
---|
[51556] | 1050 | /** @} */
|
---|
| 1051 |
|
---|
[97780] | 1052 | /** @name Error handling.
|
---|
| 1053 | * @{ */
|
---|
| 1054 | HRESULT i_setErrorV(int vrc, const char *pcszMsgFmt, va_list va);
|
---|
| 1055 | HRESULT i_setError(int vrc, const char *pcszMsgFmt, ...);
|
---|
| 1056 | HRESULT i_setErrorAndReset(const char *pcszMsgFmt, ...);
|
---|
| 1057 | HRESULT i_setErrorAndReset(int vrc, const char *pcszMsgFmt, ...);
|
---|
| 1058 | /** @} */
|
---|
| 1059 |
|
---|
[51556] | 1060 | protected:
|
---|
| 1061 |
|
---|
[97780] | 1062 | /** @name Pure virtual functions needed to be implemented by the actual (derived) implementation.
|
---|
| 1063 | * @{ */
|
---|
| 1064 | virtual void i_reset(void) = 0;
|
---|
| 1065 | /** @} */
|
---|
| 1066 |
|
---|
| 1067 | protected:
|
---|
| 1068 |
|
---|
[55571] | 1069 | /** @name Functions for handling a simple host HGCM message queue.
|
---|
| 1070 | * @{ */
|
---|
| 1071 | int msgQueueAdd(GuestDnDMsg *pMsg);
|
---|
| 1072 | GuestDnDMsg *msgQueueGetNext(void);
|
---|
| 1073 | void msgQueueRemoveNext(void);
|
---|
| 1074 | void msgQueueClear(void);
|
---|
| 1075 | /** @} */
|
---|
[55422] | 1076 |
|
---|
[55571] | 1077 | int sendCancel(void);
|
---|
[85744] | 1078 | int updateProgress(GuestDnDData *pData, GuestDnDState *pState, size_t cbDataAdd = 0);
|
---|
| 1079 | int waitForEvent(GuestDnDCallbackEvent *pEvent, GuestDnDState *pState, RTMSINTERVAL msTimeout);
|
---|
[55422] | 1080 |
|
---|
| 1081 | protected:
|
---|
| 1082 |
|
---|
[97780] | 1083 | /** Pointer to base class to use for stuff like error handlng. */
|
---|
| 1084 | VirtualBoxBase *m_pBase;
|
---|
[55549] | 1085 | /** @name Public attributes (through getters/setters).
|
---|
[51556] | 1086 | * @{ */
|
---|
| 1087 | /** Pointer to guest implementation. */
|
---|
[55422] | 1088 | const ComObjPtr<Guest> m_pGuest;
|
---|
[57221] | 1089 | /** List of supported MIME types by the source. */
|
---|
| 1090 | GuestDnDMIMEList m_lstFmtSupported;
|
---|
| 1091 | /** List of offered MIME types to the counterpart. */
|
---|
| 1092 | GuestDnDMIMEList m_lstFmtOffered;
|
---|
[85537] | 1093 | /** Whether the object still is in pending state. */
|
---|
| 1094 | bool m_fIsPending;
|
---|
[85744] | 1095 | /** Pointer to state bound to this object. */
|
---|
| 1096 | GuestDnDState *m_pState;
|
---|
[51556] | 1097 | /** @} */
|
---|
[55422] | 1098 |
|
---|
[58212] | 1099 | /**
|
---|
| 1100 | * Internal stuff.
|
---|
| 1101 | */
|
---|
[55422] | 1102 | struct
|
---|
| 1103 | {
|
---|
[58212] | 1104 | /** Outgoing message queue (FIFO). */
|
---|
[85402] | 1105 | GuestDnDMsgList lstMsgOut;
|
---|
| 1106 | } m_DataBase;
|
---|
[51556] | 1107 | };
|
---|
[76562] | 1108 | #endif /* !MAIN_INCLUDED_GuestDnDPrivate_h */
|
---|
[51476] | 1109 |
|
---|