Changeset 146644 in webkit
- Timestamp:
- Mar 22, 2013 1:04:15 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r146643 r146644 1 2013-03-22 Daniel Cheng <dcheng@chromium.org> 2 3 Data store should be readable in dragstart/copy/cut events 4 https://bugs.webkit.org/show_bug.cgi?id=23695 5 6 Reviewed by Tony Chang. 7 8 * editing/pasteboard/can-read-in-copy-and-cut-events-expected.txt: Added. 9 * editing/pasteboard/can-read-in-copy-and-cut-events.html: Added. 10 * editing/pasteboard/can-read-in-dragstart-event-expected.txt: Added. 11 * editing/pasteboard/can-read-in-dragstart-event.html: Added. 12 1 13 2013-03-22 Stephen Chenney <schenney@chromium.org> 2 14 -
trunk/Source/WebCore/ChangeLog
r146642 r146644 1 2013-03-22 Daniel Cheng <dcheng@chromium.org> 2 3 Data store should be readable in dragstart/copy/cut events 4 https://bugs.webkit.org/show_bug.cgi?id=23695 5 6 Reviewed by Tony Chang. 7 8 There were several events where data could be written but not read back due to the fact that 9 different Clipboard method implementations checked permissions inconsistently. This patch 10 adds helper methods to check if an operation is permitted on a Clipboard and refactors all 11 direct comparisons against Clipboard::m_policy to use the new helpers instead. This fixes 12 several bugs where Clipboard::types and Clipboard::getData are not usable inside the 13 aforementioned events. 14 15 Tests: editing/pasteboard/can-read-in-copy-and-cut-events.html 16 editing/pasteboard/can-read-in-dragstart-event.html 17 18 * dom/Clipboard.cpp: 19 (WebCore::Clipboard::canReadTypes): Formerly restricted to ClipboardReadable and 20 ClipboardTypesReadable; now allows ClipboardWritable as 21 well. 22 (WebCore::Clipboard::canReadData): Formerly restricted to ClipboardReadable; now allows 23 ClipboardWritable as well. 24 (WebCore::Clipboard::canWriteData): 25 (WebCore::Clipboard::canSetDragImage): 26 (WebCore::Clipboard::hasFileOfType): 27 (WebCore::Clipboard::hasStringOfType): 28 (WebCore::Clipboard::setDropEffect): 29 (WebCore::Clipboard::setEffectAllowed): 30 * dom/Clipboard.h: 31 (Clipboard): 32 * platform/blackberry/ClipboardBlackBerry.cpp: 33 (WebCore::ClipboardBlackBerry::clearData): 34 (WebCore::ClipboardBlackBerry::clearAllData): 35 (WebCore::ClipboardBlackBerry::getData): 36 (WebCore::ClipboardBlackBerry::setData): 37 (WebCore::ClipboardBlackBerry::types): 38 * platform/chromium/ClipboardChromium.cpp: 39 (WebCore::DataTransferItemPolicyWrapper::kind): 40 (WebCore::DataTransferItemPolicyWrapper::type): 41 (WebCore::DataTransferItemPolicyWrapper::getAsString): 42 (WebCore::DataTransferItemPolicyWrapper::getAsFile): 43 (WebCore::ClipboardChromium::clearData): 44 (WebCore::ClipboardChromium::clearAllData): 45 (WebCore::ClipboardChromium::getData): 46 (WebCore::ClipboardChromium::setData): 47 (WebCore::ClipboardChromium::types): 48 (WebCore::ClipboardChromium::files): 49 (WebCore::ClipboardChromium::setDragImage): 50 * platform/gtk/ClipboardGtk.cpp: 51 (WebCore::ClipboardGtk::clearData): 52 (WebCore::ClipboardGtk::clearAllData): 53 (WebCore::ClipboardGtk::getData): 54 (WebCore::ClipboardGtk::setData): 55 (WebCore::ClipboardGtk::types): 56 (WebCore::ClipboardGtk::files): 57 (WebCore::ClipboardGtk::setDragImage): 58 * platform/mac/ClipboardMac.mm: 59 (WebCore::ClipboardMac::clearData): 60 (WebCore::ClipboardMac::clearAllData): 61 (WebCore::ClipboardMac::getData): 62 (WebCore::ClipboardMac::setData): 63 (WebCore::ClipboardMac::types): 64 (WebCore::ClipboardMac::files): 65 (WebCore::ClipboardMac::setDragImage): 66 * platform/qt/ClipboardQt.cpp: 67 (WebCore::ClipboardQt::clearData): 68 (WebCore::ClipboardQt::clearAllData): 69 (WebCore::ClipboardQt::getData): 70 (WebCore::ClipboardQt::setData): 71 (WebCore::ClipboardQt::types): 72 (WebCore::ClipboardQt::files): 73 (WebCore::ClipboardQt::setDragImage): 74 (WebCore::ClipboardQt::items): 75 * platform/qt/DataTransferItemListQt.cpp: 76 (WebCore::DataTransferItemListQt::length): 77 (WebCore::DataTransferItemListQt::item): 78 (WebCore::DataTransferItemListQt::deleteItem): 79 (WebCore::DataTransferItemListQt::clear): 80 (WebCore::DataTransferItemListQt::add): 81 * platform/qt/DataTransferItemQt.cpp: 82 (WebCore::DataTransferItemQt::getAsString): 83 * platform/win/ClipboardWin.cpp: 84 (WebCore::ClipboardWin::clearData): 85 (WebCore::ClipboardWin::clearAllData): 86 (WebCore::ClipboardWin::getData): 87 (WebCore::ClipboardWin::setData): 88 (WebCore::ClipboardWin::types): 89 (WebCore::ClipboardWin::files): 90 (WebCore::ClipboardWin::setDragImage): 91 1 92 2013-03-22 Andrei Bucur <abucur@adobe.com> 2 93 -
trunk/Source/WebCore/dom/Clipboard.cpp
r144565 r146644 52 52 } 53 53 54 bool Clipboard::canReadTypes() const 55 { 56 return m_policy == ClipboardReadable || m_policy == ClipboardTypesReadable || m_policy == ClipboardWritable; 57 } 58 59 bool Clipboard::canReadData() const 60 { 61 return m_policy == ClipboardReadable || m_policy == ClipboardWritable; 62 } 63 64 bool Clipboard::canWriteData() const 65 { 66 return m_policy == ClipboardWritable; 67 } 68 69 bool Clipboard::canSetDragImage() const 70 { 71 return m_policy == ClipboardImageWritable || m_policy == ClipboardWritable; 72 } 73 54 74 // These "conversion" methods are called by both WebCore and WebKit, and never make sense to JS, so we don't 55 75 // worry about security for these. They don't allow access to the pasteboard anyway. … … 129 149 bool Clipboard::hasFileOfType(const String& type) const 130 150 { 131 if ( m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)151 if (!canReadTypes()) 132 152 return false; 133 153 … … 145 165 bool Clipboard::hasStringOfType(const String& type) const 146 166 { 147 if ( m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)167 if (!canReadTypes()) 148 168 return false; 149 169 … … 160 180 return; 161 181 162 if (m_policy == ClipboardReadable || m_policy == ClipboardTypesReadable) 182 // FIXME: The spec actually allows this in all circumstances, even though there's no point in 183 // setting the drop effect when this condition is not true. 184 if (canReadTypes()) 163 185 m_dropEffect = effect; 164 186 } … … 180 202 181 203 182 if ( m_policy == ClipboardWritable)204 if (canWriteData()) 183 205 m_effectAllowed = effect; 184 206 } -
trunk/Source/WebCore/dom/Clipboard.h
r142170 r146644 87 87 88 88 void setAccessPolicy(ClipboardAccessPolicy); 89 ClipboardAccessPolicy policy() const { return m_policy; } 89 bool canReadTypes() const; 90 bool canReadData() const; 91 bool canWriteData() const; 92 // Note that the spec doesn't actually allow drag image modification outside the dragstart 93 // event. This capability is maintained for backwards compatiblity for ports that have 94 // supported this in the past. On many ports, attempting to set a drag image outside the 95 // dragstart operation is a no-op anyway. 96 bool canSetDragImage() const; 90 97 91 98 DragOperation sourceOperation() const; … … 110 117 bool hasFileOfType(const String&) const; 111 118 bool hasStringOfType(const String&) const; 112 119 120 // Instead of using this member directly, prefer to use the can*() methods above. 113 121 ClipboardAccessPolicy m_policy; 114 122 String m_dropEffect; -
trunk/Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp
r142170 r146644 43 43 void ClipboardBlackBerry::clearData(const String& type) 44 44 { 45 if ( policy() != ClipboardWritable)45 if (!canWriteData()) 46 46 return; 47 47 … … 51 51 void ClipboardBlackBerry::clearAllData() 52 52 { 53 if ( policy() != ClipboardWritable)53 if (!canWriteData()) 54 54 return; 55 55 … … 59 59 String ClipboardBlackBerry::getData(const String& type) const 60 60 { 61 if ( policy() != ClipboardReadable)61 if (!canReadData()) 62 62 return String(); 63 63 … … 67 67 bool ClipboardBlackBerry::setData(const String& type, const String& text) 68 68 { 69 if ( policy() != ClipboardWritable)69 if (!canWriteData()) 70 70 return false; 71 71 … … 81 81 ListHashSet<String> ClipboardBlackBerry::types() const 82 82 { 83 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)83 if (!canReadTypes()) 84 84 return ListHashSet<String>(); 85 85 -
trunk/Source/WebCore/platform/chromium/ClipboardChromium.cpp
r142170 r146644 90 90 size_t DataTransferItemListPolicyWrapper::length() const 91 91 { 92 if ( m_clipboard->policy() == ClipboardNumb)92 if (!m_clipboard->canReadTypes()) 93 93 return 0; 94 94 return m_dataObject->length(); … … 97 97 PassRefPtr<DataTransferItem> DataTransferItemListPolicyWrapper::item(unsigned long index) 98 98 { 99 if ( m_clipboard->policy() == ClipboardNumb)99 if (!m_clipboard->canReadTypes()) 100 100 return 0; 101 101 RefPtr<ChromiumDataObjectItem> item = m_dataObject->item(index); … … 108 108 void DataTransferItemListPolicyWrapper::deleteItem(unsigned long index, ExceptionCode& ec) 109 109 { 110 if ( m_clipboard->policy() != ClipboardWritable) {110 if (!m_clipboard->canWriteData()) { 111 111 ec = INVALID_STATE_ERR; 112 112 return; … … 117 117 void DataTransferItemListPolicyWrapper::clear() 118 118 { 119 if ( m_clipboard->policy() != ClipboardWritable)119 if (!m_clipboard->canWriteData()) 120 120 return; 121 121 m_dataObject->clearAll(); … … 124 124 void DataTransferItemListPolicyWrapper::add(const String& data, const String& type, ExceptionCode& ec) 125 125 { 126 if ( m_clipboard->policy() != ClipboardWritable)126 if (!m_clipboard->canWriteData()) 127 127 return; 128 128 m_dataObject->add(data, type, ec); … … 131 131 void DataTransferItemListPolicyWrapper::add(PassRefPtr<File> file) 132 132 { 133 if ( m_clipboard->policy() != ClipboardWritable)133 if (!m_clipboard->canWriteData()) 134 134 return; 135 135 m_dataObject->add(file, m_clipboard->frame()->document()->scriptExecutionContext()); … … 157 157 String DataTransferItemPolicyWrapper::kind() const 158 158 { 159 if ( m_clipboard->policy() == ClipboardNumb)159 if (!m_clipboard->canReadTypes()) 160 160 return String(); 161 161 return m_item->kind(); … … 164 164 String DataTransferItemPolicyWrapper::type() const 165 165 { 166 if ( m_clipboard->policy() == ClipboardNumb)166 if (!m_clipboard->canReadTypes()) 167 167 return String(); 168 168 return m_item->type(); … … 171 171 void DataTransferItemPolicyWrapper::getAsString(PassRefPtr<StringCallback> callback) const 172 172 { 173 if ( m_clipboard->policy() != ClipboardReadable && m_clipboard->policy() != ClipboardWritable)173 if (!m_clipboard->canReadData()) 174 174 return; 175 175 … … 179 179 PassRefPtr<Blob> DataTransferItemPolicyWrapper::getAsFile() const 180 180 { 181 if ( m_clipboard->policy() != ClipboardReadable && m_clipboard->policy() != ClipboardWritable)181 if (!m_clipboard->canReadData()) 182 182 return 0; 183 183 … … 239 239 void ClipboardChromium::clearData(const String& type) 240 240 { 241 if ( policy() != ClipboardWritable)241 if (!canWriteData()) 242 242 return; 243 243 … … 249 249 void ClipboardChromium::clearAllData() 250 250 { 251 if ( policy() != ClipboardWritable)251 if (!canWriteData()) 252 252 return; 253 253 … … 257 257 String ClipboardChromium::getData(const String& type) const 258 258 { 259 if ( policy() != ClipboardReadable)259 if (!canReadData()) 260 260 return String(); 261 261 … … 269 269 bool ClipboardChromium::setData(const String& type, const String& data) 270 270 { 271 if ( policy() != ClipboardWritable)271 if (!canWriteData()) 272 272 return false; 273 273 … … 278 278 ListHashSet<String> ClipboardChromium::types() const 279 279 { 280 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)280 if (!canReadTypes()) 281 281 return ListHashSet<String>(); 282 282 … … 287 287 { 288 288 RefPtr<FileList> files = FileList::create(); 289 if ( policy() != ClipboardReadable)289 if (!canReadData()) 290 290 return files.release(); 291 291 … … 303 303 void ClipboardChromium::setDragImage(CachedImage* image, Node* node, const IntPoint& loc) 304 304 { 305 if ( policy() != ClipboardImageWritable && policy() != ClipboardWritable)305 if (!canSetDragImage()) 306 306 return; 307 307 -
trunk/Source/WebCore/platform/gtk/ClipboardGtk.cpp
r142170 r146644 104 104 void ClipboardGtk::clearData(const String& typeString) 105 105 { 106 if ( policy() != ClipboardWritable)106 if (!canWriteData()) 107 107 return; 108 108 … … 134 134 void ClipboardGtk::clearAllData() 135 135 { 136 if ( policy() != ClipboardWritable)136 if (!canWriteData()) 137 137 return; 138 138 … … 149 149 String ClipboardGtk::getData(const String& typeString) const 150 150 { 151 if ( policy() != ClipboardReadable|| !m_dataObject)151 if (!canReadData() || !m_dataObject) 152 152 return String(); 153 153 … … 170 170 bool ClipboardGtk::setData(const String& typeString, const String& data) 171 171 { 172 if ( policy() != ClipboardWritable)172 if (!canWriteData()) 173 173 return false; 174 174 … … 191 191 ListHashSet<String> ClipboardGtk::types() const 192 192 { 193 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)193 if (!canReadTypes()) 194 194 return ListHashSet<String>(); 195 195 … … 220 220 PassRefPtr<FileList> ClipboardGtk::files() const 221 221 { 222 if ( policy() != ClipboardReadable)222 if (!canReadData()) 223 223 return FileList::create(); 224 224 … … 245 245 void ClipboardGtk::setDragImage(CachedImage* image, Node* element, const IntPoint& location) 246 246 { 247 if ( policy() != ClipboardImageWritable && policy() != ClipboardWritable)247 if (!canSetDragImage()) 248 248 return; 249 249 -
trunk/Source/WebCore/platform/mac/ClipboardMac.mm
r144568 r146644 156 156 void ClipboardMac::clearData(const String& type) 157 157 { 158 if ( policy() != ClipboardWritable)158 if (!canWriteData()) 159 159 return; 160 160 … … 168 168 void ClipboardMac::clearAllData() 169 169 { 170 if ( policy() != ClipboardWritable)170 if (!canWriteData()) 171 171 return; 172 172 … … 221 221 String ClipboardMac::getData(const String& type) const 222 222 { 223 if ( policy() != ClipboardReadable|| m_clipboardContents == DragAndDropFiles)223 if (!canReadData() || m_clipboardContents == DragAndDropFiles) 224 224 return String(); 225 225 … … 250 250 bool ClipboardMac::setData(const String &type, const String &data) 251 251 { 252 if ( policy() != ClipboardWritable|| m_clipboardContents == DragAndDropFiles)252 if (!canWriteData() || m_clipboardContents == DragAndDropFiles) 253 253 return false; 254 254 // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner … … 284 284 ListHashSet<String> ClipboardMac::types() const 285 285 { 286 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)286 if (!canReadTypes()) 287 287 return ListHashSet<String>(); 288 288 … … 313 313 PassRefPtr<FileList> ClipboardMac::files() const 314 314 { 315 if ( policy() != ClipboardReadable|| m_clipboardContents == DragAndDropData)315 if (!canReadData() || m_clipboardContents == DragAndDropData) 316 316 return FileList::create(); 317 317 … … 341 341 void ClipboardMac::setDragImage(CachedImage* image, Node *node, const IntPoint &loc) 342 342 { 343 if ( policy() == ClipboardImageWritable || policy() == ClipboardWritable) {343 if (canSetDragImage()) { 344 344 if (m_dragImage) 345 345 m_dragImage->removeClient(this); -
trunk/Source/WebCore/platform/qt/ClipboardQt.cpp
r142170 r146644 113 113 void ClipboardQt::clearData(const String& type) 114 114 { 115 if ( policy() != ClipboardWritable)115 if (!canWriteData()) 116 116 return; 117 117 … … 132 132 void ClipboardQt::clearAllData() 133 133 { 134 if ( policy() != ClipboardWritable)134 if (!canWriteData()) 135 135 return; 136 136 … … 147 147 { 148 148 149 if ( policy() != ClipboardReadable)149 if (!canReadData()) 150 150 return String(); 151 151 … … 164 164 bool ClipboardQt::setData(const String& type, const String& data) 165 165 { 166 if ( policy() != ClipboardWritable)166 if (!canWriteData()) 167 167 return false; 168 168 … … 185 185 ListHashSet<String> ClipboardQt::types() const 186 186 { 187 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)187 if (!canReadTypes()) 188 188 return ListHashSet<String>(); 189 189 … … 198 198 PassRefPtr<FileList> ClipboardQt::files() const 199 199 { 200 if ( policy() != ClipboardReadable|| !m_readableData->hasUrls())200 if (!canReadData() || !m_readableData->hasUrls()) 201 201 return FileList::create(); 202 202 … … 226 226 void ClipboardQt::setDragImage(CachedImage* image, Node *node, const IntPoint &loc) 227 227 { 228 if ( policy() != ClipboardImageWritable && policy() != ClipboardWritable)228 if (!canSetDragImage()) 229 229 return; 230 230 … … 360 360 return items; 361 361 362 if (isForCopyAndPaste() && policy() == ClipboardReadable) {362 if (isForCopyAndPaste() && canReadData()) { 363 363 const QStringList types = m_readableData->formats(); 364 364 for (int i = 0; i < types.count(); ++i) -
trunk/Source/WebCore/platform/qt/DataTransferItemListQt.cpp
r105825 r146644 48 48 size_t DataTransferItemListQt::length() const 49 49 { 50 if ( m_owner->policy() == ClipboardNumb)50 if (!m_owner->canReadTypes()) 51 51 return 0; 52 52 … … 56 56 PassRefPtr<DataTransferItem> DataTransferItemListQt::item(unsigned long index) 57 57 { 58 if ( m_owner->policy() == ClipboardNumb|| index >= length())58 if (!m_owner->canReadTypes() || index >= length()) 59 59 return 0; 60 60 … … 64 64 void DataTransferItemListQt::deleteItem(unsigned long index, ExceptionCode& ec) 65 65 { 66 if ( m_owner->policy() != ClipboardWritable) {66 if (!m_owner->canWriteData()) { 67 67 ec = INVALID_STATE_ERR; 68 68 return; … … 77 77 void DataTransferItemListQt::clear() 78 78 { 79 if ( m_owner->policy() != ClipboardWritable)79 if (!m_owner->canWriteData()) 80 80 return; 81 81 … … 86 86 void DataTransferItemListQt::add(const String& data, const String& type, ExceptionCode& ec) 87 87 { 88 if ( m_owner->policy() != ClipboardWritable)88 if (!m_owner->canWriteData()) 89 89 return; 90 90 … … 102 102 void DataTransferItemListQt::add(PassRefPtr<File> file) 103 103 { 104 if ( m_owner->policy() != ClipboardWritable|| !file)104 if (!m_owner->canWriteData() || !file) 105 105 return; 106 106 -
trunk/Source/WebCore/platform/qt/DataTransferItemQt.cpp
r105648 r146644 96 96 void DataTransferItemQt::getAsString(PassRefPtr<StringCallback> callback) const 97 97 { 98 if ((owner()->policy() != ClipboardReadable && owner()->policy() != ClipboardWritable) 99 || kind() != kindString) 98 if (!owner()->policy()->canReadData() || kind() != kindString) 100 99 return; 101 100 -
trunk/Source/WebCore/platform/win/ClipboardWin.cpp
r142170 r146644 408 408 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> 409 409 ASSERT(isForDragAndDrop()); 410 if ( policy() != ClipboardWritable|| !m_writableDataObject)410 if (!canWriteData() || !m_writableDataObject) 411 411 return; 412 412 … … 428 428 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> 429 429 ASSERT(isForDragAndDrop()); 430 if ( policy() != ClipboardWritable)430 if (!canWriteData()) 431 431 return; 432 432 … … 438 438 String ClipboardWin::getData(const String& type) const 439 439 { 440 if ( policy() != ClipboardReadable|| (!m_dataObject && m_dragDataMap.isEmpty()))440 if (!canReadData() || (!m_dataObject && m_dragDataMap.isEmpty())) 441 441 return ""; 442 442 … … 460 460 // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> 461 461 ASSERT(isForDragAndDrop()); 462 if ( policy() != ClipboardWritable|| !m_writableDataObject)462 if (!canWriteData() || !m_writableDataObject) 463 463 return false; 464 464 … … 503 503 { 504 504 ListHashSet<String> results; 505 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)505 if (!canReadTypes()) 506 506 return results; 507 507 … … 541 541 #else 542 542 RefPtr<FileList> files = FileList::create(); 543 if ( policy() != ClipboardReadable && policy() != ClipboardTypesReadable)543 if (!canReadData()) 544 544 return files.release(); 545 545 … … 579 579 void ClipboardWin::setDragImage(CachedImage* image, Node *node, const IntPoint &loc) 580 580 { 581 if ( policy() != ClipboardImageWritable && policy() != ClipboardWritable)581 if (!canSetDragImage()) 582 582 return; 583 583
Note: See TracChangeset
for help on using the changeset viewer.