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

Side by Side Diff: third_party/WebKit/Source/core/clipboard/DataObject.cpp

Issue 2566403003: Migrate WTF::Vector::append() to ::push_back() [part 3 of N] (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2008, 2009, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #endif 48 #endif
49 WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer(); 49 WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer();
50 uint64_t sequenceNumber = 50 uint64_t sequenceNumber =
51 Platform::current()->clipboard()->sequenceNumber(buffer); 51 Platform::current()->clipboard()->sequenceNumber(buffer);
52 bool ignored; 52 bool ignored;
53 WebVector<WebString> webTypes = 53 WebVector<WebString> webTypes =
54 Platform::current()->clipboard()->readAvailableTypes(buffer, &ignored); 54 Platform::current()->clipboard()->readAvailableTypes(buffer, &ignored);
55 for (const WebString& type : webTypes) { 55 for (const WebString& type : webTypes) {
56 if (pasteMode == PlainTextOnly && type != mimeTypeTextPlain) 56 if (pasteMode == PlainTextOnly && type != mimeTypeTextPlain)
57 continue; 57 continue;
58 dataObject->m_itemList.append( 58 dataObject->m_itemList.push_back(
59 DataObjectItem::createFromPasteboard(type, sequenceNumber)); 59 DataObjectItem::createFromPasteboard(type, sequenceNumber));
60 ASSERT(typesSeen.add(type).isNewEntry); 60 ASSERT(typesSeen.add(type).isNewEntry);
61 } 61 }
62 return dataObject; 62 return dataObject;
63 } 63 }
64 64
65 DataObject* DataObject::createFromString(const String& data) { 65 DataObject* DataObject::createFromString(const String& data) {
66 DataObject* dataObject = create(); 66 DataObject* dataObject = create();
67 dataObject->add(data, mimeTypeTextPlain); 67 dataObject->add(data, mimeTypeTextPlain);
68 return dataObject; 68 return dataObject;
(...skipping 30 matching lines...) Expand all
99 if (!internalAddStringItem(item)) 99 if (!internalAddStringItem(item))
100 return nullptr; 100 return nullptr;
101 return item; 101 return item;
102 } 102 }
103 103
104 DataObjectItem* DataObject::add(File* file) { 104 DataObjectItem* DataObject::add(File* file) {
105 if (!file) 105 if (!file)
106 return nullptr; 106 return nullptr;
107 107
108 DataObjectItem* item = DataObjectItem::createFromFile(file); 108 DataObjectItem* item = DataObjectItem::createFromFile(file);
109 m_itemList.append(item); 109 m_itemList.push_back(item);
110 return item; 110 return item;
111 } 111 }
112 112
113 void DataObject::clearData(const String& type) { 113 void DataObject::clearData(const String& type) {
114 for (size_t i = 0; i < m_itemList.size(); ++i) { 114 for (size_t i = 0; i < m_itemList.size(); ++i) {
115 if (m_itemList[i]->kind() == DataObjectItem::StringKind && 115 if (m_itemList[i]->kind() == DataObjectItem::StringKind &&
116 m_itemList[i]->type() == type) { 116 m_itemList[i]->type() == type) {
117 // Per the spec, type must be unique among all items of kind 'string'. 117 // Per the spec, type must be unique among all items of kind 'string'.
118 m_itemList.remove(i); 118 m_itemList.remove(i);
119 return; 119 return;
120 } 120 }
121 } 121 }
122 } 122 }
123 123
124 Vector<String> DataObject::types() const { 124 Vector<String> DataObject::types() const {
125 Vector<String> results; 125 Vector<String> results;
126 #if ENABLE(ASSERT) 126 #if ENABLE(ASSERT)
127 HashSet<String> typesSeen; 127 HashSet<String> typesSeen;
128 #endif 128 #endif
129 bool containsFiles = false; 129 bool containsFiles = false;
130 for (const auto& item : m_itemList) { 130 for (const auto& item : m_itemList) {
131 switch (item->kind()) { 131 switch (item->kind()) {
132 case DataObjectItem::StringKind: 132 case DataObjectItem::StringKind:
133 // Per the spec, type must be unique among all items of kind 'string'. 133 // Per the spec, type must be unique among all items of kind 'string'.
134 results.append(item->type()); 134 results.push_back(item->type());
135 ASSERT(typesSeen.add(item->type()).isNewEntry); 135 ASSERT(typesSeen.add(item->type()).isNewEntry);
136 break; 136 break;
137 case DataObjectItem::FileKind: 137 case DataObjectItem::FileKind:
138 containsFiles = true; 138 containsFiles = true;
139 break; 139 break;
140 } 140 }
141 } 141 }
142 if (containsFiles) { 142 if (containsFiles) {
143 results.append(mimeTypeFiles); 143 results.push_back(mimeTypeFiles);
144 ASSERT(typesSeen.add(mimeTypeFiles).isNewEntry); 144 ASSERT(typesSeen.add(mimeTypeFiles).isNewEntry);
145 } 145 }
146 return results; 146 return results;
147 } 147 }
148 148
149 String DataObject::getData(const String& type) const { 149 String DataObject::getData(const String& type) const {
150 for (size_t i = 0; i < m_itemList.size(); ++i) { 150 for (size_t i = 0; i < m_itemList.size(); ++i) {
151 if (m_itemList[i]->kind() == DataObjectItem::StringKind && 151 if (m_itemList[i]->kind() == DataObjectItem::StringKind &&
152 m_itemList[i]->type() == type) 152 m_itemList[i]->type() == type)
153 return m_itemList[i]->getAsString(); 153 return m_itemList[i]->getAsString();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (m_itemList[i]->isFilename()) 193 if (m_itemList[i]->isFilename())
194 return true; 194 return true;
195 } 195 }
196 return false; 196 return false;
197 } 197 }
198 198
199 Vector<String> DataObject::filenames() const { 199 Vector<String> DataObject::filenames() const {
200 Vector<String> results; 200 Vector<String> results;
201 for (size_t i = 0; i < m_itemList.size(); ++i) { 201 for (size_t i = 0; i < m_itemList.size(); ++i) {
202 if (m_itemList[i]->isFilename()) 202 if (m_itemList[i]->isFilename())
203 results.append(toFile(m_itemList[i]->getAsFile())->path()); 203 results.push_back(toFile(m_itemList[i]->getAsFile())->path());
204 } 204 }
205 return results; 205 return results;
206 } 206 }
207 207
208 void DataObject::addFilename(const String& filename, 208 void DataObject::addFilename(const String& filename,
209 const String& displayName) { 209 const String& displayName) {
210 internalAddFileItem(DataObjectItem::createFromFile( 210 internalAddFileItem(DataObjectItem::createFromFile(
211 File::createForUserProvidedFile(filename, displayName))); 211 File::createForUserProvidedFile(filename, displayName)));
212 } 212 }
213 213
(...skipping 15 matching lines...) Expand all
229 } 229 }
230 230
231 bool DataObject::internalAddStringItem(DataObjectItem* item) { 231 bool DataObject::internalAddStringItem(DataObjectItem* item) {
232 ASSERT(item->kind() == DataObjectItem::StringKind); 232 ASSERT(item->kind() == DataObjectItem::StringKind);
233 for (size_t i = 0; i < m_itemList.size(); ++i) { 233 for (size_t i = 0; i < m_itemList.size(); ++i) {
234 if (m_itemList[i]->kind() == DataObjectItem::StringKind && 234 if (m_itemList[i]->kind() == DataObjectItem::StringKind &&
235 m_itemList[i]->type() == item->type()) 235 m_itemList[i]->type() == item->type())
236 return false; 236 return false;
237 } 237 }
238 238
239 m_itemList.append(item); 239 m_itemList.push_back(item);
240 return true; 240 return true;
241 } 241 }
242 242
243 void DataObject::internalAddFileItem(DataObjectItem* item) { 243 void DataObject::internalAddFileItem(DataObjectItem* item) {
244 ASSERT(item->kind() == DataObjectItem::FileKind); 244 ASSERT(item->kind() == DataObjectItem::FileKind);
245 m_itemList.append(item); 245 m_itemList.push_back(item);
246 } 246 }
247 247
248 DEFINE_TRACE(DataObject) { 248 DEFINE_TRACE(DataObject) {
249 visitor->trace(m_itemList); 249 visitor->trace(m_itemList);
250 Supplementable<DataObject>::trace(visitor); 250 Supplementable<DataObject>::trace(visitor);
251 } 251 }
252 252
253 DataObject* DataObject::create(WebDragData data) { 253 DataObject* DataObject::create(WebDragData data) {
254 DataObject* dataObject = create(); 254 DataObject* dataObject = create();
255 255
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 336 }
337 item.title = originalItem->title(); 337 item.title = originalItem->title();
338 item.baseURL = originalItem->baseURL(); 338 item.baseURL = originalItem->baseURL();
339 itemList[i] = item; 339 itemList[i] = item;
340 } 340 }
341 data.swapItems(itemList); 341 data.swapItems(itemList);
342 return data; 342 return data;
343 } 343 }
344 344
345 } // namespace blink 345 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698