-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WebKit API scaffolding to request targeted elements for remote in…
…spection https://bugs.webkit.org/show_bug.cgi?id=271333 Reviewed by Aditya Keerthi. Add WebKit API objects and SPI stubs to hit-test DOM elements for improved element targeting when the web view is in element selection mode. See below for more details. * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/page/ElementTargeting.cpp: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. (WebCore::findTargetedElements): * Source/WebCore/page/ElementTargeting.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebCore/page/ElementTargetingTypes.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. Add a header declaring the new core types in WebCore: `TargetedElementInfo` (which corresponds to the API object of the same name in WebKit) and `TargetedElementRequest` (which corresponds to `_WKTargetedElementRequest`). * Source/WebKit/Scripts/webkit/messages.py: (headers_for_type): * Source/WebKit/Shared/API/APIObject.h: * Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h: Add the new private headers to the umbrella. * Source/WebKit/Shared/Cocoa/APIObject.mm: (API::Object::newObject): * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: * Source/WebKit/Sources.txt: * Source/WebKit/SourcesCocoa.txt: * Source/WebKit/UIProcess/API/APITargetedElementInfo.cpp: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. (API::TargetedElementInfo::TargetedElementInfo): Add an API object to represent a single targeted element retrieved via the new SPI, which is wrapped by the Objective-C SPI object `_WKTargetedElementInfo`. (API::TargetedElementInfo::isSameElement const): (API::TargetedElementInfo::boundsInWebView const): * Source/WebKit/UIProcess/API/APITargetedElementInfo.h: Added. * Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _requestTargetedElementInfo:completionHandler:]): * Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h: * Source/WebKit/UIProcess/API/Cocoa/_WKRectEdge.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. Move the existing macOS-specific declaration of `_WKRectEdge` out to a separate header, and make it available on iOS as well. This allows us to reuse this type for the new property on `_WKTargetedElementInfo`. * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm: Added. (-[_WKTargetedElementInfo dealloc]): (-[_WKTargetedElementInfo _apiObject]): (-[_WKTargetedElementInfo positionType]): (-[_WKTargetedElementInfo bounds]): (-[_WKTargetedElementInfo selectors]): (-[_WKTargetedElementInfo renderedText]): (-[_WKTargetedElementInfo offsetEdges]): (-[_WKTargetedElementInfo hasBottomOffset]): (-[_WKTargetedElementInfo hasLeftOffset]): (-[_WKTargetedElementInfo hasRightOffset]): (-[_WKTargetedElementInfo isSameElement:]): * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfoInternal.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementRequest.h: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementRequest.mm: Copied from Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h. I opted to avoid making a new API object to represent the request object, since it's only a single `CGPoint` (and may include another boolean parameter in the future). If these request options become more complex, we can consider introducing an intermediate `API::TargetedElementRequest` class to represent this. * Source/WebKit/UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.mm: * Source/WebKit/UIProcess/Cocoa/VideoPresentationManagerProxy.mm: Some build fixes here, due to unified source order changes. * Source/WebKit/UIProcess/PageClient.h: (WebKit::PageClient::rootViewToWebView const): Add a client helper method to map the given rect from root view coordinates to web view coordinates. On iOS, this maps from `WKContentView`'s coordinate space to `WKWebView`. * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::requestTargetedElement): * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/UIProcess/ios/PageClientImplIOS.h: * Source/WebKit/UIProcess/ios/PageClientImplIOS.mm: (WebKit::PageClientImpl::rootViewToWebView const): * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::requestTargetedElement): * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPage.messages.in: Canonical link: https://commits.webkit.org/276475@main
- Loading branch information
Showing
34 changed files
with
692 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "ElementTargeting.h" | ||
|
||
namespace WebCore { | ||
|
||
Vector<TargetedElementInfo> findTargetedElements(Page&, TargetedElementRequest&&) | ||
{ | ||
return { }; | ||
} | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ElementTargetingTypes.h" | ||
#include <wtf/Vector.h> | ||
|
||
namespace WebCore { | ||
|
||
class Page; | ||
|
||
WEBCORE_EXPORT Vector<TargetedElementInfo> findTargetedElements(Page&, TargetedElementRequest&&); | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ElementIdentifier.h" | ||
#include "FloatPoint.h" | ||
#include "FloatRect.h" | ||
#include "RectEdges.h" | ||
#include "RenderStyleConstants.h" | ||
#include "ScriptExecutionContextIdentifier.h" | ||
#include <wtf/Vector.h> | ||
#include <wtf/text/WTFString.h> | ||
|
||
namespace WebCore { | ||
|
||
struct TargetedElementRequest { | ||
FloatPoint pointInRootView; | ||
}; | ||
|
||
struct TargetedElementInfo { | ||
ElementIdentifier elementIdentifier; | ||
ScriptExecutionContextIdentifier documentIdentifier; | ||
RectEdges<bool> offsetEdges; | ||
String renderedText; | ||
Vector<String> selectors; | ||
FloatRect boundsInRootView; | ||
PositionType positionType { PositionType::Static }; | ||
}; | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "APITargetedElementInfo.h" | ||
|
||
#include "PageClient.h" | ||
#include "WebPageProxy.h" | ||
|
||
namespace API { | ||
using namespace WebKit; | ||
|
||
TargetedElementInfo::TargetedElementInfo(WebPageProxy& page, WebCore::TargetedElementInfo&& info) | ||
: m_info(WTFMove(info)) | ||
, m_page(page) | ||
{ | ||
} | ||
|
||
bool TargetedElementInfo::isSameElement(const TargetedElementInfo& other) const | ||
{ | ||
return m_info.elementIdentifier == other.m_info.elementIdentifier | ||
&& m_info.documentIdentifier == other.m_info.documentIdentifier; | ||
} | ||
|
||
WebCore::FloatRect TargetedElementInfo::boundsInWebView() const | ||
{ | ||
RefPtr page = m_page.get(); | ||
if (!page) | ||
return { }; | ||
return page->pageClient().rootViewToWebView(boundsInRootView()); | ||
} | ||
|
||
} // namespace API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "APIObject.h" | ||
#include <WebCore/ElementTargetingTypes.h> | ||
#include <wtf/Forward.h> | ||
#include <wtf/WeakPtr.h> | ||
|
||
namespace WebKit { | ||
class WebPageProxy; | ||
} | ||
|
||
namespace API { | ||
|
||
class TargetedElementInfo final : public ObjectImpl<Object::Type::TargetedElementInfo> { | ||
public: | ||
static Ref<TargetedElementInfo> create(WebKit::WebPageProxy& page, WebCore::TargetedElementInfo&& info) | ||
{ | ||
return adoptRef(*new TargetedElementInfo(page, WTFMove(info))); | ||
} | ||
|
||
explicit TargetedElementInfo(WebKit::WebPageProxy&, WebCore::TargetedElementInfo&&); | ||
|
||
WebCore::RectEdges<bool> offsetEdges() const { return m_info.offsetEdges; } | ||
|
||
const WTF::String& renderedText() const { return m_info.renderedText; } | ||
const Vector<WTF::String>& selectors() const { return m_info.selectors; } | ||
WebCore::PositionType positionType() const { return m_info.positionType; } | ||
WebCore::FloatRect boundsInRootView() const { return m_info.boundsInRootView; } | ||
WebCore::FloatRect boundsInWebView() const; | ||
|
||
bool isSameElement(const TargetedElementInfo&) const; | ||
|
||
WebCore::ElementIdentifier elementIdentifier() const { return m_info.elementIdentifier; } | ||
WebCore::ScriptExecutionContextIdentifier documentIdentifier() const { return m_info.documentIdentifier; } | ||
|
||
private: | ||
WebCore::TargetedElementInfo m_info; | ||
WeakPtr<WebKit::WebPageProxy> m_page; | ||
}; | ||
|
||
} // namespace API |
Oops, something went wrong.