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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameWidgetBase.cpp

Issue 2508013002: Drag-and-drop across OOPIFs. (Closed)
Patch Set: Some fixes for tests. Rebased. Created 4 years, 1 month 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/WebFrameWidgetBase.h" 5 #include "web/WebFrameWidgetBase.h"
6 6
7 #include "core/frame/FrameHost.h" 7 #include "core/frame/FrameHost.h"
8 #include "core/frame/VisualViewport.h" 8 #include "core/frame/VisualViewport.h"
9 #include "core/input/EventHandler.h" 9 #include "core/input/EventHandler.h"
10 #include "core/page/DragActions.h" 10 #include "core/page/DragActions.h"
11 #include "core/page/DragController.h" 11 #include "core/page/DragController.h"
12 #include "core/page/DragData.h" 12 #include "core/page/DragData.h"
13 #include "core/page/DragSession.h" 13 #include "core/page/DragSession.h"
14 #include "core/page/Page.h" 14 #include "core/page/Page.h"
15 #include "public/web/WebAutofillClient.h" 15 #include "public/web/WebAutofillClient.h"
16 #include "public/web/WebDocument.h" 16 #include "public/web/WebDocument.h"
17 #include "public/web/WebWidgetClient.h"
17 #include "web/WebLocalFrameImpl.h" 18 #include "web/WebLocalFrameImpl.h"
18 #include "web/WebViewImpl.h" 19 #include "web/WebViewImpl.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
23 // Ensure that the WebDragOperation enum values stay in sync with the original
24 // DragOperation constants.
25 #define STATIC_ASSERT_ENUM(a, b) \
26 static_assert(static_cast<int>(a) == static_cast<int>(b), \
27 "mismatching enum : " #a)
28 STATIC_ASSERT_ENUM(DragOperationNone, WebDragOperationNone);
29 STATIC_ASSERT_ENUM(DragOperationCopy, WebDragOperationCopy);
30 STATIC_ASSERT_ENUM(DragOperationLink, WebDragOperationLink);
31 STATIC_ASSERT_ENUM(DragOperationGeneric, WebDragOperationGeneric);
32 STATIC_ASSERT_ENUM(DragOperationPrivate, WebDragOperationPrivate);
33 STATIC_ASSERT_ENUM(DragOperationMove, WebDragOperationMove);
34 STATIC_ASSERT_ENUM(DragOperationDelete, WebDragOperationDelete);
35 STATIC_ASSERT_ENUM(DragOperationEvery, WebDragOperationEvery);
36
22 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter( 37 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter(
23 const WebDragData& webDragData, 38 const WebDragData& webDragData,
24 const WebPoint& pointInViewport, 39 const WebPoint& pointInViewport,
25 const WebPoint& screenPoint, 40 const WebPoint& screenPoint,
26 WebDragOperationsMask operationsAllowed, 41 WebDragOperationsMask operationsAllowed,
27 int modifiers) { 42 int modifiers) {
28 DCHECK(!m_currentDragData); 43 DCHECK(!m_currentDragData);
29 44
30 m_currentDragData = DataObject::create(webDragData); 45 m_currentDragData = DataObject::create(webDragData);
31 m_operationsAllowed = operationsAllowed; 46 m_operationsAllowed = operationsAllowed;
(...skipping 12 matching lines...) Expand all
44 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver, 59 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver,
45 modifiers); 60 modifiers);
46 } 61 }
47 62
48 void WebFrameWidgetBase::dragTargetDragLeave() { 63 void WebFrameWidgetBase::dragTargetDragLeave() {
49 DCHECK(m_currentDragData); 64 DCHECK(m_currentDragData);
50 65
51 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(), 66 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(),
52 static_cast<DragOperation>(m_operationsAllowed)); 67 static_cast<DragOperation>(m_operationsAllowed));
53 68
54 page()->dragController().dragExited(&dragData); 69 page()->dragController().dragExited(&dragData, localFrameRoot());
55 70
56 // FIXME: why is the drag scroll timer not stopped here? 71 // FIXME: why is the drag scroll timer not stopped here?
57 72
58 m_dragOperation = WebDragOperationNone; 73 m_dragOperation = WebDragOperationNone;
59 m_currentDragData = nullptr; 74 m_currentDragData = nullptr;
75
76 page()->dragController().dragEnded();
dcheng 2016/11/17 18:02:58 Why does this need to call dragEnded()?
paulmeyer 2016/11/17 20:22:25 Because the state needs to be cleared in DragContr
77 m_doingDragAndDrop = false;
60 } 78 }
61 79
62 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, 80 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData,
63 const WebPoint& pointInViewport, 81 const WebPoint& pointInViewport,
64 const WebPoint& screenPoint, 82 const WebPoint& screenPoint,
65 int modifiers) { 83 int modifiers) {
66 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); 84 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport));
67 85
68 DCHECK(m_currentDragData); 86 DCHECK(m_currentDragData);
69 m_currentDragData = DataObject::create(webDragData); 87 m_currentDragData = DataObject::create(webDragData);
70 WebViewImpl::UserGestureNotifier notifier(view()); 88 WebViewImpl::UserGestureNotifier notifier(view());
71 89
72 // If this webview transitions from the "drop accepting" state to the "not 90 // If this webview transitions from the "drop accepting" state to the "not
73 // accepting" state, then our IPC message reply indicating that may be in- 91 // accepting" state, then our IPC message reply indicating that may be in-
74 // flight, or else delayed by javascript processing in this webview. If a 92 // flight, or else delayed by javascript processing in this webview. If a
75 // drop happens before our IPC reply has reached the browser process, then 93 // drop happens before our IPC reply has reached the browser process, then
76 // the browser forwards the drop to this webview. So only allow a drop to 94 // the browser forwards the drop to this webview. So only allow a drop to
77 // proceed if our webview m_dragOperation state is not DragOperationNone. 95 // proceed if our webview m_dragOperation state is not DragOperationNone.
78 96
79 if (m_dragOperation == WebDragOperationNone) { 97 if (m_dragOperation == WebDragOperationNone) {
80 // IPC RACE CONDITION: do not allow this drop. 98 // IPC RACE CONDITION: do not allow this drop.
81 dragTargetDragLeave(); 99 dragTargetDragLeave();
82 return; 100 return;
83 } 101 }
84 102
85 m_currentDragData->setModifiers(modifiers); 103 m_currentDragData->setModifiers(modifiers);
86 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, 104 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint,
87 static_cast<DragOperation>(m_operationsAllowed)); 105 static_cast<DragOperation>(m_operationsAllowed));
88 106
89 page()->dragController().performDrag(&dragData); 107 page()->dragController().performDrag(&dragData, localFrameRoot());
90 108
91 m_dragOperation = WebDragOperationNone; 109 m_dragOperation = WebDragOperationNone;
92 m_currentDragData = nullptr; 110 m_currentDragData = nullptr;
111
112 page()->dragController().dragEnded();
dcheng 2016/11/17 18:02:58 Why does this need to call dragEnded() now?
paulmeyer 2016/11/17 20:22:25 See above comment.
dcheng 2016/11/17 20:30:29 How come this Just Worked before?
paulmeyer 2016/11/17 21:14:45 To be honest, I'm not entirely sure. That is, I do
113 m_doingDragAndDrop = false;
93 } 114 }
94 115
95 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport, 116 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport,
96 const WebPoint& screenPoint, 117 const WebPoint& screenPoint,
97 WebDragOperation operation) { 118 WebDragOperation operation) {
98 WebPoint pointInRootFrame( 119 WebPoint pointInRootFrame(
99 page()->frameHost().visualViewport().viewportToRootFrame( 120 page()->frameHost().visualViewport().viewportToRootFrame(
100 pointInViewport)); 121 pointInViewport));
101 PlatformMouseEvent pme( 122 PlatformMouseEvent pme(
102 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left, 123 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left,
103 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers, 124 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers,
104 PlatformMouseEvent::RealOrIndistinguishable, 125 PlatformMouseEvent::RealOrIndistinguishable,
105 WTF::monotonicallyIncreasingTime()); 126 WTF::monotonicallyIncreasingTime());
106 page()->deprecatedLocalMainFrame()->eventHandler().dragSourceEndedAt( 127 localFrameRoot()->eventHandler().dragSourceEndedAt(
107 pme, static_cast<DragOperation>(operation)); 128 pme, static_cast<DragOperation>(operation));
108 } 129 }
109 130
110 void WebFrameWidgetBase::dragSourceSystemDragEnded() { 131 void WebFrameWidgetBase::dragSourceSystemDragEnded() {
111 // It's possible for us to get this callback while not doing a drag if it's 132 // It's possible for us to get this callback while not doing a drag if it's
112 // from a previous page that got unloaded. 133 // from a previous page that got unloaded.
113 if (view()->doingDragAndDrop()) { 134 if (m_doingDragAndDrop) {
114 page()->dragController().dragEnded(); 135 page()->dragController().dragEnded();
115 view()->setDoingDragAndDrop(false); 136 m_doingDragAndDrop = false;
116 } 137 }
117 } 138 }
118 139
140 void WebFrameWidgetBase::startDragging(WebReferrerPolicy policy,
141 const WebDragData& data,
142 WebDragOperationsMask mask,
143 const WebImage& dragImage,
144 const WebPoint& dragImageOffset) {
145 m_doingDragAndDrop = true;
146 client()->startDragging(policy, data, mask, dragImage, dragImageOffset);
147 }
148
119 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( 149 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver(
120 const WebPoint& pointInViewport, 150 const WebPoint& pointInViewport,
121 const WebPoint& screenPoint, 151 const WebPoint& screenPoint,
122 DragAction dragAction, 152 DragAction dragAction,
123 int modifiers) { 153 int modifiers) {
124 DCHECK(m_currentDragData); 154 DCHECK(m_currentDragData);
125 155
126 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); 156 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport));
127 157
158 m_doingDragAndDrop = true;
128 m_currentDragData->setModifiers(modifiers); 159 m_currentDragData->setModifiers(modifiers);
129 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, 160 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint,
130 static_cast<DragOperation>(m_operationsAllowed)); 161 static_cast<DragOperation>(m_operationsAllowed));
131 162
132 DragSession dragSession; 163 DragSession dragSession;
133 dragSession = page()->dragController().dragEnteredOrUpdated(&dragData); 164 dragSession = page()->dragController().dragEnteredOrUpdated(&dragData,
165 localFrameRoot());
134 166
135 DragOperation dropEffect = dragSession.operation; 167 DragOperation dropEffect = dragSession.operation;
136 168
137 // Mask the drop effect operation against the drag source's allowed 169 // Mask the drop effect operation against the drag source's allowed
138 // operations. 170 // operations.
139 if (!(dropEffect & dragData.draggingSourceOperationMask())) 171 if (!(dropEffect & dragData.draggingSourceOperationMask()))
140 dropEffect = DragOperationNone; 172 dropEffect = DragOperationNone;
141 173
142 m_dragOperation = static_cast<WebDragOperation>(dropEffect); 174 m_dragOperation = static_cast<WebDragOperation>(dropEffect);
143 175
144 return m_dragOperation; 176 return m_dragOperation;
145 } 177 }
146 178
147 WebPoint WebFrameWidgetBase::viewportToRootFrame( 179 WebPoint WebFrameWidgetBase::viewportToRootFrame(
148 const WebPoint& pointInViewport) const { 180 const WebPoint& pointInViewport) const {
149 return page()->frameHost().visualViewport().viewportToRootFrame( 181 return page()->frameHost().visualViewport().viewportToRootFrame(
150 pointInViewport); 182 pointInViewport);
151 } 183 }
152 184
185 LocalFrame* WebFrameWidgetBase::localFrameRoot() const {
186 return static_cast<WebLocalFrameImpl*>(localRoot())->frame();
dcheng 2016/11/17 18:02:58 toCoreFrame(localRoot())
paulmeyer 2016/11/17 20:22:25 Done.
187 }
188
153 WebViewImpl* WebFrameWidgetBase::view() const { 189 WebViewImpl* WebFrameWidgetBase::view() const {
154 return static_cast<WebLocalFrameImpl*>(localRoot())->viewImpl(); 190 return static_cast<WebLocalFrameImpl*>(localRoot())->viewImpl();
155 } 191 }
156 192
157 Page* WebFrameWidgetBase::page() const { 193 Page* WebFrameWidgetBase::page() const {
158 return view()->page(); 194 return view()->page();
159 } 195 }
160 196
161 } // namespace blink 197 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698