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

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

Issue 2875013002: DataTransfer: Make |types| be a FrozenArray<DOMString>. (Closed)
Patch Set: Fix win_chromium_compile_dbg_ng Created 3 years, 7 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
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 DataObjectItem* DataObject::Item(unsigned long index) { 83 DataObjectItem* DataObject::Item(unsigned long index) {
84 if (index >= length()) 84 if (index >= length())
85 return nullptr; 85 return nullptr;
86 return item_list_[index]; 86 return item_list_[index];
87 } 87 }
88 88
89 void DataObject::DeleteItem(unsigned long index) { 89 void DataObject::DeleteItem(unsigned long index) {
90 if (index >= length()) 90 if (index >= length())
91 return; 91 return;
92 item_list_.erase(index); 92 item_list_.erase(index);
93 NotifyItemListChanged();
93 } 94 }
94 95
95 void DataObject::ClearAll() { 96 void DataObject::ClearAll() {
97 if (item_list_.IsEmpty())
98 return;
96 item_list_.clear(); 99 item_list_.clear();
100 NotifyItemListChanged();
97 } 101 }
98 102
99 DataObjectItem* DataObject::Add(const String& data, const String& type) { 103 DataObjectItem* DataObject::Add(const String& data, const String& type) {
100 DataObjectItem* item = DataObjectItem::CreateFromString(type, data); 104 DataObjectItem* item = DataObjectItem::CreateFromString(type, data);
101 if (!InternalAddStringItem(item)) 105 if (!InternalAddStringItem(item))
102 return nullptr; 106 return nullptr;
103 return item; 107 return item;
104 } 108 }
105 109
106 DataObjectItem* DataObject::Add(File* file) { 110 DataObjectItem* DataObject::Add(File* file) {
(...skipping 14 matching lines...) Expand all
121 InternalAddFileItem(item); 125 InternalAddFileItem(item);
122 return item; 126 return item;
123 } 127 }
124 128
125 void DataObject::ClearData(const String& type) { 129 void DataObject::ClearData(const String& type) {
126 for (size_t i = 0; i < item_list_.size(); ++i) { 130 for (size_t i = 0; i < item_list_.size(); ++i) {
127 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && 131 if (item_list_[i]->Kind() == DataObjectItem::kStringKind &&
128 item_list_[i]->GetType() == type) { 132 item_list_[i]->GetType() == type) {
129 // 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'.
130 item_list_.erase(i); 134 item_list_.erase(i);
135 NotifyItemListChanged();
131 return; 136 return;
132 } 137 }
133 } 138 }
134 } 139 }
135 140
136 Vector<String> DataObject::Types() const { 141 Vector<String> DataObject::Types() const {
137 Vector<String> results; 142 Vector<String> results;
138 #if DCHECK_IS_ON() 143 #if DCHECK_IS_ON()
139 HashSet<String> types_seen; 144 HashSet<String> types_seen;
140 #endif 145 #endif
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 254
250 bool DataObject::InternalAddStringItem(DataObjectItem* item) { 255 bool DataObject::InternalAddStringItem(DataObjectItem* item) {
251 DCHECK_EQ(item->Kind(), DataObjectItem::kStringKind); 256 DCHECK_EQ(item->Kind(), DataObjectItem::kStringKind);
252 for (size_t i = 0; i < item_list_.size(); ++i) { 257 for (size_t i = 0; i < item_list_.size(); ++i) {
253 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && 258 if (item_list_[i]->Kind() == DataObjectItem::kStringKind &&
254 item_list_[i]->GetType() == item->GetType()) 259 item_list_[i]->GetType() == item->GetType())
255 return false; 260 return false;
256 } 261 }
257 262
258 item_list_.push_back(item); 263 item_list_.push_back(item);
264 NotifyItemListChanged();
259 return true; 265 return true;
260 } 266 }
261 267
262 void DataObject::InternalAddFileItem(DataObjectItem* item) { 268 void DataObject::InternalAddFileItem(DataObjectItem* item) {
263 DCHECK_EQ(item->Kind(), DataObjectItem::kFileKind); 269 DCHECK_EQ(item->Kind(), DataObjectItem::kFileKind);
264 item_list_.push_back(item); 270 item_list_.push_back(item);
271 NotifyItemListChanged();
272 }
273
274 void DataObject::AddObserver(Observer* observer) {
275 DCHECK(!observers_.Contains(observer));
276 observers_.insert(observer);
277 }
278
279 void DataObject::NotifyItemListChanged() const {
280 for (const auto& observer : observers_)
281 observer->OnItemListChanged();
265 } 282 }
266 283
267 DEFINE_TRACE(DataObject) { 284 DEFINE_TRACE(DataObject) {
268 visitor->Trace(item_list_); 285 visitor->Trace(item_list_);
286 visitor->Trace(observers_);
269 Supplementable<DataObject>::Trace(visitor); 287 Supplementable<DataObject>::Trace(visitor);
270 } 288 }
271 289
272 DataObject* DataObject::Create(WebDragData data) { 290 DataObject* DataObject::Create(WebDragData data) {
273 DataObject* data_object = Create(); 291 DataObject* data_object = Create();
274 bool has_file_system = false; 292 bool has_file_system = false;
275 293
276 WebVector<WebDragData::Item> items = data.Items(); 294 WebVector<WebDragData::Item> items = data.Items();
277 for (unsigned i = 0; i < items.size(); ++i) { 295 for (unsigned i = 0; i < items.size(); ++i) {
278 WebDragData::Item item = items[i]; 296 WebDragData::Item item = items[i];
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } else { 387 } else {
370 NOTREACHED(); 388 NOTREACHED();
371 } 389 }
372 item_list[i] = item; 390 item_list[i] = item;
373 } 391 }
374 data.SwapItems(item_list); 392 data.SwapItems(item_list);
375 return data; 393 return data;
376 } 394 }
377 395
378 } // namespace blink 396 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/clipboard/DataObject.h ('k') | third_party/WebKit/Source/core/clipboard/DataObjectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698