ArgumentCodersQt.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include "config.h"
  17. #include "ArgumentCodersQt.h"
  18. #include "ArgumentCoders.h"
  19. #include "WebCoreArgumentCoders.h"
  20. #include <QMimeData>
  21. #include <QStringList>
  22. #include <wtf/text/StringHash.h>
  23. #include <wtf/text/WTFString.h>
  24. using namespace WebCore;
  25. namespace CoreIPC {
  26. typedef HashMap<String , Vector<uint8_t> > MIMEDataHashMap;
  27. void ArgumentCoder<WebCore::DragData>::encode(ArgumentEncoder& encoder, const DragData& dragData)
  28. {
  29. encoder << dragData.clientPosition();
  30. encoder << dragData.globalPosition();
  31. encoder << (uint64_t)dragData.draggingSourceOperationMask();
  32. encoder << (uint64_t)dragData.flags();
  33. bool hasPlatformData = dragData.platformData();
  34. encoder << hasPlatformData;
  35. if (!hasPlatformData)
  36. return;
  37. QStringList formats = dragData.platformData()->formats();
  38. MIMEDataHashMap map;
  39. int size = formats.size();
  40. for (int i = 0; i < size; i++) {
  41. QByteArray bytes = dragData.platformData()->data(formats[i]);
  42. Vector<uint8_t> vdata;
  43. vdata.append((uint8_t*)(bytes.data()), bytes.size());
  44. map.add(String(formats[i]), vdata);
  45. }
  46. encoder << map;
  47. }
  48. bool ArgumentCoder<WebCore::DragData>::decode(ArgumentDecoder& decoder, DragData& dragData)
  49. {
  50. IntPoint clientPosition;
  51. IntPoint globalPosition;
  52. uint64_t sourceOperationMask;
  53. uint64_t flags;
  54. if (!decoder.decode(clientPosition))
  55. return false;
  56. if (!decoder.decode(globalPosition))
  57. return false;
  58. if (!decoder.decode(sourceOperationMask))
  59. return false;
  60. if (!decoder.decode(flags))
  61. return false;
  62. bool hasPlatformData;
  63. if (!decoder.decode(hasPlatformData))
  64. return false;
  65. QMimeData* mimeData = 0;
  66. if (hasPlatformData) {
  67. MIMEDataHashMap map;
  68. if (!decoder.decode(map))
  69. return false;
  70. mimeData = new QMimeData;
  71. MIMEDataHashMap::iterator it = map.begin();
  72. MIMEDataHashMap::iterator end = map.end();
  73. for (; it != end; ++it) {
  74. QByteArray bytes((char*)it->value.data(), it->value.size());
  75. mimeData->setData(it->key, bytes);
  76. }
  77. }
  78. dragData = DragData(mimeData, clientPosition, globalPosition, (DragOperation)sourceOperationMask, (DragApplicationFlags)flags);
  79. return true;
  80. }
  81. }