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

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

Issue 2875013002: DataTransfer: Make |types| be a FrozenArray<DOMString>. (Closed)
Patch Set: Use an observer to be notified of changes 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return ConvertURIListToURL(data); 185 return ConvertURIListToURL(data);
186 } 186 }
187 187
188 void DataTransfer::setData(const String& type, const String& data) { 188 void DataTransfer::setData(const String& type, const String& data) {
189 if (!CanWriteData()) 189 if (!CanWriteData())
190 return; 190 return;
191 191
192 data_object_->SetData(NormalizeType(type), data); 192 data_object_->SetData(NormalizeType(type), data);
193 } 193 }
194 194
195 // extensions beyond IE's API 195 bool DataTransfer::hasDataStoreItemListChanged() const {
196 Vector<String> DataTransfer::types() const { 196 return data_store_item_list_changed_ || !CanReadTypes();
197 }
198
199 void DataTransfer::OnItemListChanged() {
200 data_store_item_list_changed_ = true;
201 }
202
203 Vector<String> DataTransfer::types() {
197 Vector<String> types; 204 Vector<String> types;
198 if (!CanReadTypes()) 205 if (!CanReadTypes())
199 return types; 206 return types;
jsbell 2017/05/15 20:49:28 Not new in this CL, but how about `return Vector<S
Raphael Kubo da Costa (rakuco) 2017/05/16 08:51:51 Done.
200 207
208 data_store_item_list_changed_ = false;
201 return data_object_->Types(); 209 return data_object_->Types();
202 } 210 }
203 211
204 FileList* DataTransfer::files() const { 212 FileList* DataTransfer::files() const {
205 FileList* files = FileList::Create(); 213 FileList* files = FileList::Create();
206 if (!CanReadData()) 214 if (!CanReadData())
207 return files; 215 return files;
208 216
209 for (size_t i = 0; i < data_object_->length(); ++i) { 217 for (size_t i = 0; i < data_object_->length(); ++i) {
210 if (data_object_->Item(i)->Kind() == DataObjectItem::kFileKind) { 218 if (data_object_->Item(i)->Kind() == DataObjectItem::kFileKind) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 return data_object_; 430 return data_object_;
423 } 431 }
424 432
425 DataTransfer::DataTransfer(DataTransferType type, 433 DataTransfer::DataTransfer(DataTransferType type,
426 DataTransferAccessPolicy policy, 434 DataTransferAccessPolicy policy,
427 DataObject* data_object) 435 DataObject* data_object)
428 : policy_(policy), 436 : policy_(policy),
429 drop_effect_("uninitialized"), 437 drop_effect_("uninitialized"),
430 effect_allowed_("uninitialized"), 438 effect_allowed_("uninitialized"),
431 transfer_type_(type), 439 transfer_type_(type),
432 data_object_(data_object) {} 440 data_object_(data_object),
441 data_store_item_list_changed_(true) {
442 data_object_->AddObserver(this);
443 }
433 444
434 void DataTransfer::setDragImage(ImageResourceContent* image, 445 void DataTransfer::setDragImage(ImageResourceContent* image,
435 Node* node, 446 Node* node,
436 const IntPoint& loc) { 447 const IntPoint& loc) {
437 if (!CanSetDragImage()) 448 if (!CanSetDragImage())
438 return; 449 return;
439 450
440 drag_image_ = image; 451 drag_image_ = image;
441 drag_loc_ = loc; 452 drag_loc_ = loc;
442 drag_image_element_ = node; 453 drag_image_element_ = node;
(...skipping 11 matching lines...) Expand all
454 return true; 465 return true;
455 } 466 }
456 } 467 }
457 return false; 468 return false;
458 } 469 }
459 470
460 bool DataTransfer::HasStringOfType(const String& type) const { 471 bool DataTransfer::HasStringOfType(const String& type) const {
461 if (!CanReadTypes()) 472 if (!CanReadTypes())
462 return false; 473 return false;
463 474
464 return types().Contains(type); 475 return data_object_->Types().Contains(type);
465 } 476 }
466 477
467 DragOperation ConvertDropZoneOperationToDragOperation( 478 DragOperation ConvertDropZoneOperationToDragOperation(
468 const String& drag_operation) { 479 const String& drag_operation) {
469 if (drag_operation == "copy") 480 if (drag_operation == "copy")
470 return kDragOperationCopy; 481 return kDragOperationCopy;
471 if (drag_operation == "move") 482 if (drag_operation == "move")
472 return kDragOperationMove; 483 return kDragOperationMove;
473 if (drag_operation == "link") 484 if (drag_operation == "link")
474 return kDragOperationLink; 485 return kDragOperationLink;
(...skipping 13 matching lines...) Expand all
488 } 499 }
489 } 500 }
490 501
491 DEFINE_TRACE(DataTransfer) { 502 DEFINE_TRACE(DataTransfer) {
492 visitor->Trace(data_object_); 503 visitor->Trace(data_object_);
493 visitor->Trace(drag_image_); 504 visitor->Trace(drag_image_);
494 visitor->Trace(drag_image_element_); 505 visitor->Trace(drag_image_element_);
495 } 506 }
496 507
497 } // namespace blink 508 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698