#include "content/renderer/drop_data_builder.h"
#include "base/strings/string_util.h"
#include "content/public/common/drop_data.h"
#include "third_party/WebKit/public/platform/WebDragData.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "ui/base/clipboard/clipboard.h"
using blink::WebDragData;
using blink::WebVector;
namespace content {
DropData DropDataBuilder::Build(const WebDragData& drag_data) {
DropData result;
result.referrer_policy = blink::WebReferrerPolicyDefault;
const WebVector<WebDragData::Item>& item_list = drag_data.items();
for (size_t i = 0; i < item_list.size(); ++i) {
const WebDragData::Item& item = item_list[i];
switch (item.storageType) {
case WebDragData::Item::StorageTypeString: {
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) {
result.text = base::NullableString16(item.stringData, false);
break;
}
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) {
result.url = GURL(item.stringData);
result.url_title = item.title;
break;
}
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) {
result.download_metadata = item.stringData;
break;
}
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) {
result.html = base::NullableString16(item.stringData, false);
result.html_base_url = item.baseURL;
break;
}
result.custom_data.insert(
std::make_pair(item.stringType, item.stringData));
break;
}
case WebDragData::Item::StorageTypeBinaryData:
result.file_contents.assign(item.binaryData.data(),
item.binaryData.size());
result.file_description_filename = item.title;
break;
case WebDragData::Item::StorageTypeFilename:
result.filenames.push_back(ui::FileInfo(
base::FilePath::FromUTF16Unsafe(item.filenameData),
base::FilePath::FromUTF16Unsafe(item.displayNameData)));
break;
}
}
return result;
}
}