summaryrefslogtreecommitdiffstats
path: root/webkit/glue/clipboard_conversion.cc
blob: 28f191d2d34e64ec27e574e305dcff89ce49c342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "webkit/glue/clipboard_conversion.h"

#include "build/build_config.h"

#include "ChromiumDataObject.h"
#include "ClipboardUtilitiesChromium.h"
#include "KURL.h"
#include "SharedBuffer.h"
#include <wtf/Vector.h>

#include "webkit/glue/glue_util.h"

namespace webkit_glue {

WebDropData ChromiumDataObjectToWebDropData(
    WebCore::ChromiumDataObject* data_object) {
  WebDropData drop_data;
  drop_data.url = KURLToGURL(data_object->url);
  drop_data.url_title = StringToStdWString(data_object->urlTitle);

  drop_data.file_extension = StringToStdWString(data_object->fileExtension);

  for (size_t i = 0; i < data_object->filenames.size(); ++i) {
    drop_data.filenames.push_back(StringToStdWString(
        data_object->filenames[i]));
  }

  drop_data.plain_text = StringToStdWString(data_object->plainText);

  drop_data.text_html = StringToStdWString(data_object->textHtml);
  drop_data.html_base_url = KURLToGURL(data_object->htmlBaseUrl);

  drop_data.file_description_filename = StringToStdWString(
      data_object->fileContentFilename);
  if (data_object->fileContent) {
    drop_data.file_contents.assign(data_object->fileContent->data(),
        data_object->fileContent->size());
  }

  return drop_data;
}

PassRefPtr<WebCore::ChromiumDataObject> WebDropDataToChromiumDataObject(
    const WebDropData& drop_data) {
  RefPtr<WebCore::ChromiumDataObject> data_object =
      WebCore::ChromiumDataObject::create();
  data_object->url = GURLToKURL(drop_data.url);
  data_object->urlTitle = StdWStringToString(drop_data.url_title);

  data_object->fileExtension = StdWStringToString(drop_data.file_extension);

  for (size_t i = 0; i < drop_data.filenames.size(); ++i) {
    data_object->filenames.append(StdWStringToString(drop_data.filenames[i]));
  }

  data_object->plainText = StdWStringToString(drop_data.plain_text);

  data_object->textHtml = StdWStringToString(drop_data.text_html);
  data_object->htmlBaseUrl = GURLToKURL(drop_data.html_base_url);

  data_object->fileContentFilename = StdWStringToString(
      drop_data.file_description_filename);
  if (!drop_data.file_contents.empty()) {
    data_object->fileContent =
        WebCore::SharedBuffer::create(drop_data.file_contents.data(),
                                      drop_data.file_contents.size());
  }

  return data_object;
}

}  // namespace webkit_glue