Title: [270216] trunk/Source/WebKit
Revision
270216
Author
[email protected]
Date
2020-11-28 04:52:02 -0800 (Sat, 28 Nov 2020)

Log Message

[macOS] Issue sandbox extension to icon services when starting a drag operation
https://bugs.webkit.org/show_bug.cgi?id=219159
<rdar://problem/71585876>

Reviewed by Brent Fulgham.

Issue sandbox extension to icon services when starting a drag operation on macOS, since the WebContent process needs
access to these services when a drag is started. This patch detects when a drag is about to start, and sends sandbox
extensions to the icon services along with the mouse event. The sandbox extensions are then temporarily consumed
while handling the mouse event in the WebContent process.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::processNextQueuedMouseEvent):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::mouseEvent):
(WebKit::WebPage::simulateMouseDown):
(WebKit::WebPage::simulateMouseUp):
(WebKit::WebPage::simulateMouseMotion):
(WebKit::WebPage::consumeSandboxExtensions):
(WebKit::WebPage::revokeSandboxExtensions):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (270215 => 270216)


--- trunk/Source/WebKit/ChangeLog	2020-11-28 05:17:21 UTC (rev 270215)
+++ trunk/Source/WebKit/ChangeLog	2020-11-28 12:52:02 UTC (rev 270216)
@@ -1,3 +1,28 @@
+2020-11-28  Per Arne Vollan  <[email protected]>
+
+        [macOS] Issue sandbox extension to icon services when starting a drag operation
+        https://bugs.webkit.org/show_bug.cgi?id=219159
+        <rdar://problem/71585876>
+
+        Reviewed by Brent Fulgham.
+
+        Issue sandbox extension to icon services when starting a drag operation on macOS, since the WebContent process needs
+        access to these services when a drag is started. This patch detects when a drag is about to start, and sends sandbox
+        extensions to the icon services along with the mouse event. The sandbox extensions are then temporarily consumed
+        while handling the mouse event in the WebContent process.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::processNextQueuedMouseEvent):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::mouseEvent):
+        (WebKit::WebPage::simulateMouseDown):
+        (WebKit::WebPage::simulateMouseUp):
+        (WebKit::WebPage::simulateMouseMotion):
+        (WebKit::WebPage::consumeSandboxExtensions):
+        (WebKit::WebPage::revokeSandboxExtensions):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2020-11-27  Fujii Hironori  <[email protected]>
 
         Unreviewed, reverting r270210.

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (270215 => 270216)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-11-28 05:17:21 UTC (rev 270215)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-11-28 12:52:02 UTC (rev 270216)
@@ -2600,8 +2600,16 @@
         m_process->startResponsivenessTimer();
     }
 
+    Optional<SandboxExtension::HandleArray> sandboxExtensions;
+
+#if PLATFORM(MAC)
+    bool eventMayStartDrag = !m_currentDragOperation && eventType == WebEvent::MouseMove && event.button() != WebMouseEvent::Button::NoButton;
+    if (eventMayStartDrag)
+        sandboxExtensions = SandboxExtension::createHandlesForMachLookup({ "com.apple.iconservices"_s, "com.apple.iconservices.store"_s }, WTF::nullopt);
+#endif
+    
     LOG(MouseHandling, "UIProcess: sent mouse event %s (queue size %zu)", webMouseEventTypeString(eventType), m_mouseEventQueue.size());
-    send(Messages::WebPage::MouseEvent(event));
+    send(Messages::WebPage::MouseEvent(event, sandboxExtensions));
 }
 
 void WebPageProxy::doAfterProcessingAllPendingMouseEvents(WTF::Function<void ()>&& action)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (270215 => 270216)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-11-28 05:17:21 UTC (rev 270215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-11-28 12:52:02 UTC (rev 270216)
@@ -2803,7 +2803,7 @@
     }
 }
 
-void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
+void WebPage::mouseEvent(const WebMouseEvent& mouseEvent, Optional<SandboxExtension::HandleArray>&& sandboxExtensions)
 {
     SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true };
 
@@ -2826,6 +2826,10 @@
         return;
     }
 
+    Vector<RefPtr<SandboxExtension>> mouseEventSandboxExtensions;
+    if (sandboxExtensions)
+        mouseEventSandboxExtensions = consumeSandboxExtensions(WTFMove(*sandboxExtensions));
+
     bool handled = false;
 
 #if !PLATFORM(IOS_FAMILY)
@@ -2841,6 +2845,8 @@
     }
 
     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), handled));
+
+    revokeSandboxExtensions(mouseEventSandboxExtensions);
 }
 
 static bool handleWheelEvent(const WebWheelEvent& wheelEvent, Page* page, OptionSet<WheelEventProcessingSteps> processingSteps)
@@ -4137,7 +4143,7 @@
     m_isStartingDrag = false;
     m_page->mainFrame().eventHandler().dragCancelled();
 }
-    
+
 #endif // ENABLE(DRAG_SUPPORT)
 
 WebUndoStep* WebPage::webUndoStep(WebUndoStepID stepID)
@@ -5242,18 +5248,18 @@
 void WebPage::simulateMouseDown(int button, WebCore::IntPoint position, int clickCount, WKEventModifiers modifiers, WallTime time)
 {
     static_assert(sizeof(WKEventModifiers) >= sizeof(WebEvent::Modifier), "WKEventModifiers must be greater than or equal to the size of WebEvent::Modifier");
-    mouseEvent(WebMouseEvent(WebMouseEvent::MouseDown, static_cast<WebMouseEvent::Button>(button), 0, position, position, 0, 0, 0, clickCount, OptionSet<WebEvent::Modifier>::fromRaw(modifiers), time, WebCore::ForceAtClick, WebMouseEvent::NoTap));
+    mouseEvent(WebMouseEvent(WebMouseEvent::MouseDown, static_cast<WebMouseEvent::Button>(button), 0, position, position, 0, 0, 0, clickCount, OptionSet<WebEvent::Modifier>::fromRaw(modifiers), time, WebCore::ForceAtClick, WebMouseEvent::NoTap), WTF::nullopt);
 }
 
 void WebPage::simulateMouseUp(int button, WebCore::IntPoint position, int clickCount, WKEventModifiers modifiers, WallTime time)
 {
     static_assert(sizeof(WKEventModifiers) >= sizeof(WebEvent::Modifier), "WKEventModifiers must be greater than or equal to the size of WebEvent::Modifier");
-    mouseEvent(WebMouseEvent(WebMouseEvent::MouseUp, static_cast<WebMouseEvent::Button>(button), 0, position, position, 0, 0, 0, clickCount, OptionSet<WebEvent::Modifier>::fromRaw(modifiers), time, WebCore::ForceAtClick, WebMouseEvent::NoTap));
+    mouseEvent(WebMouseEvent(WebMouseEvent::MouseUp, static_cast<WebMouseEvent::Button>(button), 0, position, position, 0, 0, 0, clickCount, OptionSet<WebEvent::Modifier>::fromRaw(modifiers), time, WebCore::ForceAtClick, WebMouseEvent::NoTap), WTF::nullopt);
 }
 
 void WebPage::simulateMouseMotion(WebCore::IntPoint position, WallTime time)
 {
-    mouseEvent(WebMouseEvent(WebMouseEvent::MouseMove, WebMouseEvent::NoButton, 0, position, position, 0, 0, 0, 0, OptionSet<WebEvent::Modifier> { }, time, 0, WebMouseEvent::NoTap));
+    mouseEvent(WebMouseEvent(WebMouseEvent::MouseMove, WebMouseEvent::NoButton, 0, position, position, 0, 0, 0, 0, OptionSet<WebEvent::Modifier> { }, time, 0, WebMouseEvent::NoTap), WTF::nullopt);
 }
 
 void WebPage::setCompositionForTesting(const String& compositionString, uint64_t from, uint64_t length, bool suppressUnderline, const Vector<CompositionHighlight>& highlights)
@@ -7033,6 +7039,27 @@
 }
 #endif
 
+Vector<RefPtr<SandboxExtension>> WebPage::consumeSandboxExtensions(SandboxExtension::HandleArray&& sandboxExtensions)
+{
+    Vector<RefPtr<SandboxExtension>> dragSandboxExtensions;
+    for (auto& sandboxExtension : sandboxExtensions) {
+        auto extension = SandboxExtension::create(WTFMove(sandboxExtension));
+        if (!extension)
+            continue;
+        bool ok = extension->consume();
+        ASSERT_UNUSED(ok, ok);
+        dragSandboxExtensions.append(WTFMove(extension));
+    }
+    return dragSandboxExtensions;
+}
+
+void WebPage::revokeSandboxExtensions(Vector<RefPtr<SandboxExtension>>& sandboxExtensions)
+{
+    for (auto& sandboxExtension : sandboxExtensions)
+        sandboxExtension->revoke();
+    sandboxExtensions.clear();
+}
+
 } // namespace WebKit
 
 #undef RELEASE_LOG_IF_ALLOWED

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (270215 => 270216)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-11-28 05:17:21 UTC (rev 270215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-11-28 12:52:02 UTC (rev 270216)
@@ -1488,7 +1488,7 @@
 
     void setNeedsFontAttributes(bool);
 
-    void mouseEvent(const WebMouseEvent&);
+    void mouseEvent(const WebMouseEvent&, Optional<SandboxExtension::HandleArray>&& sandboxExtensions);
     void keyEvent(const WebKeyboardEvent&);
 
 #if ENABLE(IOS_TOUCH_EVENTS)
@@ -1783,6 +1783,9 @@
 
     void platformDidScalePage();
 
+    Vector<RefPtr<SandboxExtension>> consumeSandboxExtensions(SandboxExtension::HandleArray&&);
+    void revokeSandboxExtensions(Vector<RefPtr<SandboxExtension>>& sandboxExtensions);
+    
     WebCore::PageIdentifier m_identifier;
 
     std::unique_ptr<WebCore::Page> m_page;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (270215 => 270216)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-11-28 05:17:21 UTC (rev 270215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-11-28 12:52:02 UTC (rev 270216)
@@ -45,7 +45,7 @@
 
     ExecuteEditCommandWithCallback(String name, String argument) -> () Async
     KeyEvent(WebKit::WebKeyboardEvent event)
-    MouseEvent(WebKit::WebMouseEvent event)
+    MouseEvent(WebKit::WebMouseEvent event, Optional<WebKit::SandboxExtension::HandleArray> sandboxExtensions)
 #if PLATFORM(IOS_FAMILY)
     SetViewportConfigurationViewLayoutSize(WebCore::FloatSize size, double scaleFactor, double minimumEffectiveDeviceWidth)
     SetMaximumUnobscuredSize(WebCore::FloatSize size)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to