1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "webkit/glue/webdropdata.h" 6 7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" 12 13 using WebKit::WebData; 14 using WebKit::WebDragData; 15 using WebKit::WebString; 16 using WebKit::WebVector; 17 WebDropData(const WebDragData & drag_data)18WebDropData::WebDropData(const WebDragData& drag_data) 19 : url(drag_data.url()), 20 url_title(drag_data.urlTitle()), 21 download_metadata(drag_data.downloadMetadata()), 22 file_extension(drag_data.fileExtension()), 23 plain_text(drag_data.plainText()), 24 text_html(drag_data.htmlText()), 25 html_base_url(drag_data.htmlBaseURL()), 26 file_description_filename(drag_data.fileContentFilename()) { 27 if (drag_data.containsFilenames()) { 28 WebVector<WebString> filenames_copy; 29 drag_data.filenames(filenames_copy); 30 for (size_t i = 0; i < filenames_copy.size(); ++i) 31 filenames.push_back(filenames_copy[i]); 32 } 33 WebData contents = drag_data.fileContent(); 34 if (!contents.isEmpty()) 35 file_contents.assign(contents.data(), contents.size()); 36 } 37 WebDropData()38WebDropData::WebDropData() { 39 } 40 ~WebDropData()41WebDropData::~WebDropData() { 42 } 43 ToDragData() const44WebDragData WebDropData::ToDragData() const { 45 WebDragData result; 46 result.initialize(); 47 result.setURL(url); 48 result.setURLTitle(url_title); 49 result.setFileExtension(file_extension); 50 result.setFilenames(filenames); 51 result.setPlainText(plain_text); 52 result.setHTMLText(text_html); 53 result.setHTMLBaseURL(html_base_url); 54 result.setFileContentFilename(file_description_filename); 55 result.setFileContent(WebData(file_contents.data(), file_contents.size())); 56 return result; 57 } 58