Skip to content

Commit ea566ef

Browse files
Links with empty hrefs should not be drag sources
https://bugs.webkit.org/show_bug.cgi?id=170241 <rdar://problem/31305505> Reviewed by Tim Horton. Source/WebCore: The m_dragSouceAction member of DragController represents the drag source actions that are available to the document, rather than the available actions given the dragging element. Thus, it is not correct to only check that (m_dragSourceAction & DragSourceActionAttachment) before proceeding down the attachment dragging codepath. This should be additionally guarded with a check that the element being dragged is, in fact, an attachment element. New API test (see Tools/ChangeLog). * page/DragController.cpp: (WebCore::DragController::startDrag): Tools: Adds a new API test: DataInteractionTests.LinkWithEmptyHREF. * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/ios/DataInteractionSimulator.h: Expose the current phase of the data interaction simulator for verifying behaviors in unit tests. * TestWebKitAPI/ios/DataInteractionSimulator.mm: (-[DataInteractionSimulator phase]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@214556 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent f9e6bdb commit ea566ef

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

Source/WebCore/ChangeLog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2017-03-29 Wenson Hsieh <[email protected]>
2+
3+
Links with empty hrefs should not be drag sources
4+
https://bugs.webkit.org/show_bug.cgi?id=170241
5+
<rdar://problem/31305505>
6+
7+
Reviewed by Tim Horton.
8+
9+
The m_dragSouceAction member of DragController represents the drag source actions that are available to the
10+
document, rather than the available actions given the dragging element. Thus, it is not correct to only check
11+
that (m_dragSourceAction & DragSourceActionAttachment) before proceeding down the attachment dragging codepath.
12+
This should be additionally guarded with a check that the element being dragged is, in fact, an attachment
13+
element.
14+
15+
New API test (see Tools/ChangeLog).
16+
17+
* page/DragController.cpp:
18+
(WebCore::DragController::startDrag):
19+
120
2017-03-29 Jeremy Jones <[email protected]>
221

322
WebVideoFullscreenInterfaceAVKit needs a strong self ref before dispatching to the main thread.

Source/WebCore/page/DragController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, DragOperation
10131013
}
10141014

10151015
#if ENABLE(ATTACHMENT_ELEMENT)
1016-
if (m_dragSourceAction & DragSourceActionAttachment) {
1016+
if (is<HTMLAttachmentElement>(element) && m_dragSourceAction & DragSourceActionAttachment) {
10171017
if (!dataTransfer.pasteboard().hasData()) {
10181018
selectElement(element);
10191019
if (!attachmentURL.isEmpty()) {

Tools/ChangeLog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2017-03-29 Wenson Hsieh <[email protected]>
2+
3+
Links with empty hrefs should not be drag sources
4+
https://bugs.webkit.org/show_bug.cgi?id=170241
5+
<rdar://problem/31305505>
6+
7+
Reviewed by Tim Horton.
8+
9+
Adds a new API test: DataInteractionTests.LinkWithEmptyHREF.
10+
11+
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
12+
(TestWebKitAPI::TEST):
13+
* TestWebKitAPI/ios/DataInteractionSimulator.h:
14+
15+
Expose the current phase of the data interaction simulator for verifying behaviors in unit tests.
16+
17+
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
18+
(-[DataInteractionSimulator phase]):
19+
120
2017-03-29 Jonathan Bedard <[email protected]>
221

322
Use TCP instead of FIFOs for Simulator/Device communication

Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

+14
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ - (NSString *)editorValue
172172
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
173173
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
174174

175+
EXPECT_EQ(DataInteractionCancelled, [dataInteractionSimulator phase]);
175176
EXPECT_FALSE([webView editorContainsImageElement]);
176177

177178
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
@@ -292,6 +293,19 @@ - (NSString *)editorValue
292293
EXPECT_WK_STREQ("PASS", [webView stringByEvaluatingJavaScript:@"target.textContent"].UTF8String);
293294
}
294295

296+
TEST(DataInteractionTests, LinkWithEmptyHREF)
297+
{
298+
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
299+
[webView synchronouslyLoadTestPageNamed:@"link-and-input"];
300+
[webView stringByEvaluatingJavaScript:@"document.querySelector('a').href = ''"];
301+
302+
RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
303+
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
304+
305+
EXPECT_EQ(DataInteractionCancelled, [dataInteractionSimulator phase]);
306+
EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
307+
}
308+
295309
} // namespace TestWebKitAPI
296310

297311
#endif // ENABLE(DATA_INTERACTION)

Tools/TestWebKitAPI/ios/DataInteractionSimulator.h

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef NS_ENUM(NSInteger, DataInteractionPhase) {
7171
@property (nonatomic, strong) UIItemProvider *externalItemProvider;
7272
@property (nonatomic, readonly) NSArray *observedEventNames;
7373
@property (nonatomic, readonly) NSArray *finalSelectionRects;
74+
@property (nonatomic, readonly) DataInteractionPhase phase;
7475

7576
@end
7677

Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm

+5
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ - (void)setExternalItemProvider:(UIItemProvider *)externalItemProvider
209209
_externalItemProvider = externalItemProvider;
210210
}
211211

212+
- (DataInteractionPhase)phase
213+
{
214+
return _phase;
215+
}
216+
212217
#pragma mark - _WKTestingDelegate
213218

214219
- (void)webViewDidPerformDataInteractionControllerOperation:(WKWebView *)webView

0 commit comments

Comments
 (0)