Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/renderer/drop_data_builder.cc

Issue 2658573003: Use explicit WebString conversions in clipboard and drag-and-drop code (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/clipboard_utils.cc ('k') | content/renderer/webclipboard_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/drop_data_builder.h" 5 #include "content/renderer/drop_data_builder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "content/public/common/drop_data.h" 10 #include "content/public/common/drop_data.h"
11 #include "third_party/WebKit/public/platform/FilePathConversion.h" 11 #include "third_party/WebKit/public/platform/FilePathConversion.h"
12 #include "third_party/WebKit/public/platform/URLConversion.h" 12 #include "third_party/WebKit/public/platform/URLConversion.h"
13 #include "third_party/WebKit/public/platform/WebDragData.h" 13 #include "third_party/WebKit/public/platform/WebDragData.h"
14 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebVector.h" 15 #include "third_party/WebKit/public/platform/WebVector.h"
16 #include "ui/base/clipboard/clipboard.h" 16 #include "ui/base/clipboard/clipboard.h"
17 17
18 using blink::WebDragData; 18 using blink::WebDragData;
19 using blink::WebString;
19 using blink::WebVector; 20 using blink::WebVector;
20 21
21 namespace content { 22 namespace content {
22 23
23 // static 24 // static
24 DropData DropDataBuilder::Build(const WebDragData& drag_data) { 25 DropData DropDataBuilder::Build(const WebDragData& drag_data) {
25 DropData result; 26 DropData result;
26 result.key_modifiers = drag_data.modifierKeyState(); 27 result.key_modifiers = drag_data.modifierKeyState();
27 result.referrer_policy = blink::WebReferrerPolicyDefault; 28 result.referrer_policy = blink::WebReferrerPolicyDefault;
28 29
29 const WebVector<WebDragData::Item>& item_list = drag_data.items(); 30 const WebVector<WebDragData::Item>& item_list = drag_data.items();
30 for (size_t i = 0; i < item_list.size(); ++i) { 31 for (size_t i = 0; i < item_list.size(); ++i) {
31 const WebDragData::Item& item = item_list[i]; 32 const WebDragData::Item& item = item_list[i];
32 switch (item.storageType) { 33 switch (item.storageType) {
33 case WebDragData::Item::StorageTypeString: { 34 case WebDragData::Item::StorageTypeString: {
34 base::string16 str_type(item.stringType); 35 base::string16 str_type(item.stringType.utf16());
35 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) { 36 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) {
36 result.text = base::NullableString16(item.stringData, false); 37 result.text = WebString::toNullableString16(item.stringData);
37 break; 38 break;
38 } 39 }
39 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) { 40 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) {
40 result.url = blink::WebStringToGURL(item.stringData); 41 result.url = blink::WebStringToGURL(item.stringData);
41 result.url_title = item.title; 42 result.url_title = item.title.utf16();
42 break; 43 break;
43 } 44 }
44 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) { 45 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) {
45 result.download_metadata = item.stringData; 46 result.download_metadata = item.stringData.utf16();
46 break; 47 break;
47 } 48 }
48 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) { 49 if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) {
49 result.html = base::NullableString16(item.stringData, false); 50 result.html = WebString::toNullableString16(item.stringData);
50 result.html_base_url = item.baseURL; 51 result.html_base_url = item.baseURL;
51 break; 52 break;
52 } 53 }
53 result.custom_data.insert( 54 result.custom_data.insert(
54 std::make_pair(item.stringType, item.stringData)); 55 std::make_pair(item.stringType.utf16(), item.stringData.utf16()));
55 break; 56 break;
56 } 57 }
57 case WebDragData::Item::StorageTypeBinaryData: 58 case WebDragData::Item::StorageTypeBinaryData:
58 result.file_contents.assign(item.binaryData.data(), 59 result.file_contents.assign(item.binaryData.data(),
59 item.binaryData.size()); 60 item.binaryData.size());
60 result.file_description_filename = item.title; 61 result.file_description_filename = item.title.utf16();
61 break; 62 break;
62 case WebDragData::Item::StorageTypeFilename: 63 case WebDragData::Item::StorageTypeFilename:
63 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk. 64 // TODO(varunjain): This only works on chromeos. Support win/mac/gtk.
64 result.filenames.push_back(ui::FileInfo( 65 result.filenames.push_back(ui::FileInfo(
65 blink::WebStringToFilePath(item.filenameData), 66 blink::WebStringToFilePath(item.filenameData),
66 blink::WebStringToFilePath(item.displayNameData))); 67 blink::WebStringToFilePath(item.displayNameData)));
67 break; 68 break;
68 case WebDragData::Item::StorageTypeFileSystemFile: { 69 case WebDragData::Item::StorageTypeFileSystemFile: {
69 DropData::FileSystemFileInfo info; 70 DropData::FileSystemFileInfo info;
70 info.url = item.fileSystemURL; 71 info.url = item.fileSystemURL;
71 info.size = item.fileSystemFileSize; 72 info.size = item.fileSystemFileSize;
72 info.filesystem_id = item.fileSystemId.ascii(); 73 info.filesystem_id = item.fileSystemId.ascii();
73 result.file_system_files.push_back(info); 74 result.file_system_files.push_back(info);
74 break; 75 break;
75 } 76 }
76 } 77 }
77 } 78 }
78 79
79 return result; 80 return result;
80 } 81 }
81 82
82 } // namespace content 83 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/clipboard_utils.cc ('k') | content/renderer/webclipboard_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698