Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "web/WebFrameWidgetBase.h" | |
| 6 | |
| 7 #include "core/frame/FrameHost.h" | |
| 8 #include "core/frame/VisualViewport.h" | |
| 9 #include "core/page/DragActions.h" | |
| 10 #include "core/page/DragController.h" | |
| 11 #include "core/page/DragData.h" | |
| 12 #include "core/page/DragSession.h" | |
| 13 #include "core/page/Page.h" | |
| 14 #include "public/web/WebAutofillClient.h" | |
| 15 #include "public/web/WebDocument.h" | |
| 16 #include "web/WebLocalFrameImpl.h" | |
| 17 #include "web/WebViewImpl.h" | |
| 18 | |
| 19 namespace blink { | |
| 20 | |
| 21 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter( | |
| 22 const WebDragData& webDragData, | |
| 23 const WebPoint& pointInViewport, | |
| 24 const WebPoint& screenPoint, | |
| 25 WebDragOperationsMask operationsAllowed, | |
| 26 int modifiers) { | |
| 27 DCHECK(!m_currentDragData); | |
| 28 | |
| 29 m_currentDragData = DataObject::create(webDragData); | |
| 30 m_operationsAllowed = operationsAllowed; | |
| 31 | |
| 32 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragEnter, | |
| 33 modifiers); | |
| 34 } | |
| 35 | |
| 36 WebDragOperation WebFrameWidgetBase::dragTargetDragOver( | |
| 37 const WebPoint& pointInViewport, | |
| 38 const WebPoint& screenPoint, | |
| 39 WebDragOperationsMask operationsAllowed, | |
| 40 int modifiers) { | |
| 41 m_operationsAllowed = operationsAllowed; | |
| 42 | |
| 43 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver, | |
| 44 modifiers); | |
| 45 } | |
| 46 | |
| 47 void WebFrameWidgetBase::dragTargetDragLeave() { | |
| 48 DCHECK(m_currentDragData); | |
| 49 | |
| 50 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(), | |
| 51 static_cast<DragOperation>(m_operationsAllowed)); | |
| 52 | |
| 53 page()->dragController().dragExited(&dragData); | |
| 54 | |
| 55 // FIXME: why is the drag scroll timer not stopped here? | |
| 56 | |
| 57 m_dragOperation = WebDragOperationNone; | |
| 58 m_currentDragData = nullptr; | |
| 59 } | |
| 60 | |
| 61 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, | |
| 62 const WebPoint& pointInViewport, | |
| 63 const WebPoint& screenPoint, | |
| 64 int modifiers) { | |
| 65 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); | |
| 66 | |
| 67 DCHECK(m_currentDragData); | |
| 68 m_currentDragData = DataObject::create(webDragData); | |
| 69 WebViewImpl::UserGestureNotifier notifier(view()); | |
| 70 | |
| 71 // If this webview transitions from the "drop accepting" state to the "not | |
| 72 // accepting" state, then our IPC message reply indicating that may be in- | |
| 73 // flight, or else delayed by javascript processing in this webview. If a | |
| 74 // drop happens before our IPC reply has reached the browser process, then | |
| 75 // the browser forwards the drop to this webview. So only allow a drop to | |
| 76 // proceed if our webview m_dragOperation state is not DragOperationNone. | |
| 77 | |
| 78 if (m_dragOperation == | |
| 79 WebDragOperationNone) { // IPC RACE CONDITION: do not allow this drop. | |
|
dcheng
2016/11/09 20:23:17
Nit: let's put this comment on the previous line,
paulmeyer
2016/11/09 23:19:11
Done.
| |
| 80 dragTargetDragLeave(); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 m_currentDragData->setModifiers(modifiers); | |
| 85 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, | |
| 86 static_cast<DragOperation>(m_operationsAllowed)); | |
| 87 | |
| 88 page()->dragController().performDrag(&dragData); | |
| 89 | |
| 90 m_dragOperation = WebDragOperationNone; | |
| 91 m_currentDragData = nullptr; | |
| 92 } | |
| 93 | |
| 94 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( | |
| 95 const WebPoint& pointInViewport, | |
| 96 const WebPoint& screenPoint, | |
| 97 DragAction dragAction, | |
| 98 int modifiers) { | |
| 99 DCHECK(m_currentDragData); | |
| 100 | |
| 101 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); | |
| 102 | |
| 103 m_currentDragData->setModifiers(modifiers); | |
| 104 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, | |
| 105 static_cast<DragOperation>(m_operationsAllowed)); | |
| 106 | |
| 107 DragSession dragSession; | |
| 108 dragSession = page()->dragController().dragEnteredOrUpdated(&dragData); | |
| 109 | |
| 110 DragOperation dropEffect = dragSession.operation; | |
| 111 | |
| 112 // Mask the drop effect operation against the drag source's allowed | |
| 113 // operations. | |
| 114 if (!(dropEffect & dragData.draggingSourceOperationMask())) | |
| 115 dropEffect = DragOperationNone; | |
| 116 | |
| 117 m_dragOperation = static_cast<WebDragOperation>(dropEffect); | |
| 118 | |
| 119 return m_dragOperation; | |
| 120 } | |
| 121 | |
| 122 WebPoint WebFrameWidgetBase::viewportToRootFrame( | |
| 123 const WebPoint& pointInViewport) const { | |
| 124 return page()->frameHost().visualViewport().viewportToRootFrame( | |
| 125 pointInViewport); | |
| 126 } | |
| 127 | |
| 128 WebViewImpl* WebFrameWidgetBase::view() const { | |
| 129 return static_cast<WebLocalFrameImpl*>(localRoot())->viewImpl(); | |
| 130 } | |
| 131 | |
| 132 Page* WebFrameWidgetBase::page() const { | |
| 133 return view()->page(); | |
| 134 } | |
| 135 | |
| 136 } // namespace blink | |
| OLD | NEW |