| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/webdropdata.h" | 5 #include "webkit/glue/webdropdata.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 WebDropData::FileInfo::FileInfo() { | 24 WebDropData::FileInfo::FileInfo() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 WebDropData::FileInfo::FileInfo(const string16& path, | 27 WebDropData::FileInfo::FileInfo(const string16& path, |
| 28 const string16& display_name) | 28 const string16& display_name) |
| 29 : path(path), | 29 : path(path), |
| 30 display_name(display_name) { | 30 display_name(display_name) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 WebDropData::WebDropData(const WebDragData& drag_data) | 33 WebDropData::WebDropData(const WebDragData& drag_data) |
| 34 : referrer_policy(WebKit::WebReferrerPolicyDefault) { | 34 : referrer_policy(WebKit::WebReferrerPolicyDefault), |
| 35 text(NullableString16(true)), |
| 36 html(NullableString16(true)) { |
| 35 const WebVector<WebDragData::Item>& item_list = drag_data.items(); | 37 const WebVector<WebDragData::Item>& item_list = drag_data.items(); |
| 36 for (size_t i = 0; i < item_list.size(); ++i) { | 38 for (size_t i = 0; i < item_list.size(); ++i) { |
| 37 const WebDragData::Item& item = item_list[i]; | 39 const WebDragData::Item& item = item_list[i]; |
| 38 switch (item.storageType) { | 40 switch (item.storageType) { |
| 39 case WebDragData::Item::StorageTypeString: { | 41 case WebDragData::Item::StorageTypeString: { |
| 40 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { | 42 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { |
| 41 plain_text = item.stringData; | 43 text = NullableString16(item.stringData, false); |
| 42 break; | 44 break; |
| 43 } | 45 } |
| 44 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) { | 46 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) { |
| 45 url = GURL(item.stringData); | 47 url = GURL(item.stringData); |
| 46 url_title = item.title; | 48 url_title = item.title; |
| 47 break; | 49 break; |
| 48 } | 50 } |
| 49 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) { | 51 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeDownloadURL)) { |
| 50 download_metadata = item.stringData; | 52 download_metadata = item.stringData; |
| 51 break; | 53 break; |
| 52 } | 54 } |
| 53 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { | 55 if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { |
| 54 text_html = item.stringData; | 56 html = NullableString16(item.stringData, false); |
| 55 html_base_url = item.baseURL; | 57 html_base_url = item.baseURL; |
| 56 break; | 58 break; |
| 57 } | 59 } |
| 58 custom_data.insert(std::make_pair(item.stringType, item.stringData)); | 60 custom_data.insert(std::make_pair(item.stringType, item.stringData)); |
| 59 break; | 61 break; |
| 60 } | 62 } |
| 61 case WebDragData::Item::StorageTypeBinaryData: | 63 case WebDragData::Item::StorageTypeBinaryData: |
| 62 file_contents.assign(item.binaryData.data(), | 64 file_contents.assign(item.binaryData.data(), |
| 63 item.binaryData.size()); | 65 item.binaryData.size()); |
| 64 file_description_filename = item.title; | 66 file_description_filename = item.title; |
| 65 break; | 67 break; |
| 66 case WebDragData::Item::StorageTypeFilename: | 68 case WebDragData::Item::StorageTypeFilename: |
| 67 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. | 69 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. |
| 68 filenames.push_back(FileInfo(item.filenameData, | 70 filenames.push_back(FileInfo(item.filenameData, |
| 69 item.displayNameData)); | 71 item.displayNameData)); |
| 70 break; | 72 break; |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 WebDropData::WebDropData() | 77 WebDropData::WebDropData() |
| 76 : referrer_policy(WebKit::WebReferrerPolicyDefault) { | 78 : referrer_policy(WebKit::WebReferrerPolicyDefault), |
| 79 text(NullableString16(true)), |
| 80 html(NullableString16(true)) { |
| 77 } | 81 } |
| 78 | 82 |
| 79 WebDropData::~WebDropData() { | 83 WebDropData::~WebDropData() { |
| 80 } | 84 } |
| 81 | 85 |
| 82 WebDragData WebDropData::ToDragData() const { | 86 WebDragData WebDropData::ToDragData() const { |
| 83 std::vector<WebDragData::Item> item_list; | 87 std::vector<WebDragData::Item> item_list; |
| 84 | 88 |
| 85 // These fields are currently unused when dragging into WebKit. | 89 // These fields are currently unused when dragging into WebKit. |
| 86 DCHECK(download_metadata.empty()); | 90 DCHECK(download_metadata.empty()); |
| 87 DCHECK(file_contents.empty()); | 91 DCHECK(file_contents.empty()); |
| 88 DCHECK(file_description_filename.empty()); | 92 DCHECK(file_description_filename.empty()); |
| 89 | 93 |
| 90 // TODO(dcheng): We need a way to distinguish between null and empty strings. | 94 if (!text.is_null()) { |
| 91 if (!plain_text.empty()) { | |
| 92 WebDragData::Item item; | 95 WebDragData::Item item; |
| 93 item.storageType = WebDragData::Item::StorageTypeString; | 96 item.storageType = WebDragData::Item::StorageTypeString; |
| 94 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); | 97 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 95 item.stringData = plain_text; | 98 item.stringData = text.string(); |
| 96 item_list.push_back(item); | 99 item_list.push_back(item); |
| 97 } | 100 } |
| 98 | 101 |
| 102 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 103 // meaningful to write an empty URL to the clipboard? |
| 99 if (!url.is_empty()) { | 104 if (!url.is_empty()) { |
| 100 WebDragData::Item item; | 105 WebDragData::Item item; |
| 101 item.storageType = WebDragData::Item::StorageTypeString; | 106 item.storageType = WebDragData::Item::StorageTypeString; |
| 102 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); | 107 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 103 item.stringData = WebString::fromUTF8(url.spec()); | 108 item.stringData = WebString::fromUTF8(url.spec()); |
| 104 item.title = url_title; | 109 item.title = url_title; |
| 105 item_list.push_back(item); | 110 item_list.push_back(item); |
| 106 } | 111 } |
| 107 | 112 |
| 108 if (!text_html.empty()) { | 113 if (!html.is_null()) { |
| 109 WebDragData::Item item; | 114 WebDragData::Item item; |
| 110 item.storageType = WebDragData::Item::StorageTypeString; | 115 item.storageType = WebDragData::Item::StorageTypeString; |
| 111 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); | 116 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 112 item.stringData = text_html; | 117 item.stringData = html.string(); |
| 113 item.baseURL = html_base_url; | 118 item.baseURL = html_base_url; |
| 114 item_list.push_back(item); | 119 item_list.push_back(item); |
| 115 } | 120 } |
| 116 | 121 |
| 117 for (std::vector<FileInfo>::const_iterator it = | 122 for (std::vector<FileInfo>::const_iterator it = |
| 118 filenames.begin(); it != filenames.end(); ++it) { | 123 filenames.begin(); it != filenames.end(); ++it) { |
| 119 WebDragData::Item item; | 124 WebDragData::Item item; |
| 120 item.storageType = WebDragData::Item::StorageTypeFilename; | 125 item.storageType = WebDragData::Item::StorageTypeFilename; |
| 121 item.filenameData = it->path; | 126 item.filenameData = it->path; |
| 122 item.displayNameData = it->display_name; | 127 item.displayNameData = it->display_name; |
| 123 item_list.push_back(item); | 128 item_list.push_back(item); |
| 124 } | 129 } |
| 125 | 130 |
| 126 for (std::map<string16, string16>::const_iterator it = custom_data.begin(); | 131 for (std::map<string16, string16>::const_iterator it = custom_data.begin(); |
| 127 it != custom_data.end(); | 132 it != custom_data.end(); |
| 128 ++it) { | 133 ++it) { |
| 129 WebDragData::Item item; | 134 WebDragData::Item item; |
| 130 item.storageType = WebDragData::Item::StorageTypeString; | 135 item.storageType = WebDragData::Item::StorageTypeString; |
| 131 item.stringType = it->first; | 136 item.stringType = it->first; |
| 132 item.stringData = it->second; | 137 item.stringData = it->second; |
| 133 item_list.push_back(item); | 138 item_list.push_back(item); |
| 134 } | 139 } |
| 135 | 140 |
| 136 WebDragData result; | 141 WebDragData result; |
| 137 result.initialize(); | 142 result.initialize(); |
| 138 result.setItems(item_list); | 143 result.setItems(item_list); |
| 139 result.setFilesystemId(filesystem_id); | 144 result.setFilesystemId(filesystem_id); |
| 140 return result; | 145 return result; |
| 141 } | 146 } |
| OLD | NEW |