From 4cd69c9df3932e49035491d1da0789ed0a7a22a5 Mon Sep 17 00:00:00 2001 From: Jean Haberer Date: Mon, 3 Feb 2025 12:00:34 -0800 Subject: [PATCH] Trigger a signal in the UI Process when the web page provides a spatial backdrop https://bugs.webkit.org/show_bug.cgi?id=286510 rdar://141175983 Reviewed by Ada Chan and Chris Dumez. Expose the value of a spatial backdrop link tag to the UI Process. * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WTF/wtf/PlatformEnableCocoa.h: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/Document.cpp: (WebCore::Document::spatialBackdropSource): (WebCore::Document::spatialBackdropLinkElementChanged): (WebCore::Document::determineActiveSpatialBackdropSource): (WebCore::Document::spatialBackdropSourceChanged): (WebCore::Document::setURL): * Source/WebCore/dom/Document.h: * Source/WebCore/dom/SpatialBackdropSource.cpp: Added. (WebCore::SpatialBackdropSource::SpatialBackdropSource): * Source/WebCore/dom/SpatialBackdropSource.h: Added. (WebCore::SpatialBackdropSource::SpatialBackdropSource): (WebCore::operator==): Transports the spatial backdrop properties that are useful to know for the UI Process, this includes the source (current URL) from which the backdrop was provided, and the URL of both the provided model and environmentmap. * Source/WebCore/html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::attributeChanged): (WebCore::HTMLLinkElement::process): (WebCore::HTMLLinkElement::removedFromAncestor): (WebCore::HTMLLinkElement::isURLAttribute const): (WebCore::HTMLLinkElement::environmentmap const): (WebCore::HTMLLinkElement::isSpatialBackdrop const): * Source/WebCore/html/HTMLLinkElement.h: * Source/WebCore/html/HTMLLinkElement.idl: * Source/WebCore/html/LinkRelAttribute.cpp: * Source/WebCore/html/LinkRelAttribute.h: Add the "spatial-backdrop" rel, and the "environmentmap" attribute to the link tag. * Source/WebCore/page/ChromeClient.h: (WebCore::ChromeClient::spatialBackdropSourceChanged const): * Source/WebCore/page/Page.cpp: (WebCore::Page::spatialBackdropSource const): * Source/WebCore/page/Page.h: * Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h: * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: * Source/WebKit/SourcesCocoa.txt: * Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _spatialBackdropSource]): * Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h: * Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h: * Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.h: Added. * Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.mm: Added. (-[_WKSpatialBackdropSource initWithSpatialBackdropSource:]): * Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSourceInternal.h: Added. * Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.mm: * Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h: * Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm: (WebKit::PageClientImplCocoa::spatialBackdropSourceWillChange): (WebKit::PageClientImplCocoa::spatialBackdropSourceDidChange): * Source/WebKit/UIProcess/PageClient.h: (WebKit::PageClient::spatialBackdropSourceWillChange): (WebKit::PageClient::spatialBackdropSourceDidChange): * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::spatialBackdropSource const): (WebKit::WebPageProxy::spatialBackdropSourceChanged): * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/UIProcess/WebPageProxy.messages.in: * Source/WebKit/UIProcess/WebPageProxyInternals.h: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::spatialBackdropSourceChanged const): * Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h: * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::didFinishLoad): (WebKit::WebPage::spatialBackdropSourceChanged): * Source/WebKit/WebProcess/WebPage/WebPage.h: Canonical link: https://commits.webkit.org/289748@main --- .../Preferences/UnifiedWebPreferences.yaml | 17 ++++++ Source/WTF/wtf/PlatformEnableCocoa.h | 4 ++ Source/WebCore/Headers.cmake | 1 + Source/WebCore/Sources.txt | 1 + .../WebCore/WebCore.xcodeproj/project.pbxproj | 6 ++ Source/WebCore/dom/Document.cpp | 45 +++++++++++++++ Source/WebCore/dom/Document.h | 18 ++++++ Source/WebCore/dom/SpatialBackdropSource.cpp | 41 ++++++++++++++ Source/WebCore/dom/SpatialBackdropSource.h | 41 ++++++++++++++ Source/WebCore/html/HTMLLinkElement.cpp | 40 ++++++++++++- Source/WebCore/html/HTMLLinkElement.h | 8 +++ Source/WebCore/html/HTMLLinkElement.idl | 1 + Source/WebCore/html/LinkRelAttribute.cpp | 6 ++ Source/WebCore/html/LinkRelAttribute.h | 3 + Source/WebCore/page/ChromeClient.h | 5 +- Source/WebCore/page/Page.cpp | 12 ++++ Source/WebCore/page/Page.h | 5 ++ .../WebKit/Shared/API/Cocoa/WebKitPrivate.h | 1 + .../WebCoreArgumentCoders.serialization.in | 8 +++ Source/WebKit/SourcesCocoa.txt | 1 + .../WebKit/UIProcess/API/Cocoa/WKWebView.mm | 21 +++++++ .../UIProcess/API/Cocoa/WKWebViewInternal.h | 8 +++ .../UIProcess/API/Cocoa/WKWebViewPrivate.h | 3 + .../API/Cocoa/_WKSpatialBackdropSource.h | 40 +++++++++++++ .../API/Cocoa/_WKSpatialBackdropSource.mm | 56 +++++++++++++++++++ .../Cocoa/_WKSpatialBackdropSourceInternal.h | 38 +++++++++++++ .../API/Cocoa/_WKWebPushDaemonConnection.mm | 1 + .../UIProcess/Cocoa/PageClientImplCocoa.h | 4 ++ .../UIProcess/Cocoa/PageClientImplCocoa.mm | 13 +++++ Source/WebKit/UIProcess/PageClient.h | 4 ++ Source/WebKit/UIProcess/WebPageProxy.cpp | 21 +++++++ Source/WebKit/UIProcess/WebPageProxy.h | 8 +++ .../WebKit/UIProcess/WebPageProxy.messages.in | 3 + .../WebKit/UIProcess/WebPageProxyInternals.h | 4 ++ .../WebKit/WebKit.xcodeproj/project.pbxproj | 10 ++++ .../WebCoreSupport/WebChromeClient.cpp | 7 +++ .../WebCoreSupport/WebChromeClient.h | 5 +- Source/WebKit/WebProcess/WebPage/WebPage.cpp | 12 ++++ Source/WebKit/WebProcess/WebPage/WebPage.h | 4 ++ 39 files changed, 523 insertions(+), 3 deletions(-) create mode 100644 Source/WebCore/dom/SpatialBackdropSource.cpp create mode 100644 Source/WebCore/dom/SpatialBackdropSource.h create mode 100644 Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.h create mode 100644 Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.mm create mode 100644 Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSourceInternal.h diff --git a/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml b/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml index 7c5181ebb146..bfb05ee4c5d7 100644 --- a/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml +++ b/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml @@ -8680,6 +8680,23 @@ WebLocksAPIEnabled: sharedPreferenceForWebProcess: true richJavaScript: true +WebPageSpatialBackdropEnabled: + type: bool + status: testable + category: html + condition: ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + humanReadableName: "Web Page Spatial Backdrop" + humanReadableDescription: "Enable Web Page Spatial Backdrop" + defaultValue: + WebKitLegacy: + default: false + WebKit: + default: false + WebCore: + default: false + disableInLockdownMode: true + sharedPreferenceForWebProcess: true + WebRTCAV1CodecEnabled: type: bool status: preview diff --git a/Source/WTF/wtf/PlatformEnableCocoa.h b/Source/WTF/wtf/PlatformEnableCocoa.h index 7e1ef6e1cf3e..3a37ab9ac9ae 100644 --- a/Source/WTF/wtf/PlatformEnableCocoa.h +++ b/Source/WTF/wtf/PlatformEnableCocoa.h @@ -812,6 +812,10 @@ #define ENABLE_SPATIAL_IMAGE_DETECTION 1 #endif +#if !defined(ENABLE_WEB_PAGE_SPATIAL_BACKDROP) && PLATFORM(VISION) +#define ENABLE_WEB_PAGE_SPATIAL_BACKDROP 1 +#endif + #if !defined(ENABLE_SPEECH_SYNTHESIS) && !PLATFORM(MACCATALYST) #define ENABLE_SPEECH_SYNTHESIS 1 #endif diff --git a/Source/WebCore/Headers.cmake b/Source/WebCore/Headers.cmake index 51c5e7586801..5948e5735068 100644 --- a/Source/WebCore/Headers.cmake +++ b/Source/WebCore/Headers.cmake @@ -1166,6 +1166,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS dom/SimulatedClickOptions.h dom/SlotAssignmentMode.h dom/SpaceSplitString.h + dom/SpatialBackdropSource.h dom/StartViewTransitionOptions.h dom/StaticRange.h dom/StyledElement.h diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index a94238b98f06..de26dfe7bf09 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -1358,6 +1358,7 @@ dom/SimpleRange.cpp dom/SimulatedClick.cpp dom/SlotAssignment.cpp dom/SpaceSplitString.cpp +dom/SpatialBackdropSource.cpp dom/StaticNodeList.cpp dom/StaticRange.cpp dom/StringCallback.cpp diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj index 9aeacc4d2a6a..9ed953ccc728 100644 --- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj @@ -5189,6 +5189,7 @@ C6F0900F14327B6100685849 /* MutationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0900614327B6100685849 /* MutationObserver.h */; settings = {ATTRIBUTES = (Private, ); }; }; C6F0902D14327D4F00685849 /* JSMutationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0902514327D4F00685849 /* JSMutationObserver.h */; }; C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D467041E60C3EB008195FB /* AutoplayEvent.h */; settings = {ATTRIBUTES = (Private, ); }; }; + CA3344082D16174C007473A1 /* SpatialBackdropSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3344072D16174C007473A1 /* SpatialBackdropSource.h */; settings = {ATTRIBUTES = (Private, ); }; }; CA3A4AAF25416E40006CDAE2 /* ImageResolution.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3A4AAD25416E3E006CDAE2 /* ImageResolution.h */; }; CA3BF67E10D99BAE00E6CE53 /* ScrollAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3BF67D10D99BAE00E6CE53 /* ScrollAnimator.h */; settings = {ATTRIBUTES = (Private, ); }; }; CA6C1530220B98CC0055CBFC /* JSValueInWrappedObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 931AE3B81FB80EAE00F5EFB2 /* JSValueInWrappedObject.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -18859,6 +18860,8 @@ CA1635DC2072E76900E7D2CE /* ReferrerPolicy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReferrerPolicy.cpp; sourceTree = ""; }; CA1933D52407D6400071241A /* PerformancePaintTiming.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PerformancePaintTiming.h; sourceTree = ""; }; CA1933D82407EDCF0071241A /* PerformancePaintTiming.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PerformancePaintTiming.idl; sourceTree = ""; }; + CA3344072D16174C007473A1 /* SpatialBackdropSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpatialBackdropSource.h; sourceTree = ""; }; + CA3344092D1625B9007473A1 /* SpatialBackdropSource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SpatialBackdropSource.cpp; sourceTree = ""; }; CA3A4AAB25416E3C006CDAE2 /* ImageResolution.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageResolution.cpp; sourceTree = ""; }; CA3A4AAD25416E3E006CDAE2 /* ImageResolution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageResolution.h; sourceTree = ""; }; CA3BF67B10D99BAE00E6CE53 /* ScrollAnimator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollAnimator.cpp; sourceTree = ""; }; @@ -38781,6 +38784,8 @@ 9B4F0632289F2F08007831DB /* SlotAssignmentMode.idl */, D01A27AB10C9BFD800026A42 /* SpaceSplitString.cpp */, D01A27AC10C9BFD800026A42 /* SpaceSplitString.h */, + CA3344092D1625B9007473A1 /* SpatialBackdropSource.cpp */, + CA3344072D16174C007473A1 /* SpatialBackdropSource.h */, EE7A169F2C607BFA0057B563 /* StartViewTransitionOptions.h */, EE7A169E2C607AF00057B563 /* StartViewTransitionOptions.idl */, BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */, @@ -44044,6 +44049,7 @@ 72F7E746279B8F7500D82D2D /* SourceImage.h in Headers */, D01A27AE10C9BFD800026A42 /* SpaceSplitString.h in Headers */, 46A877482D0D426800DE225E /* SpanCoreAudio.h in Headers */, + CA3344082D16174C007473A1 /* SpatialBackdropSource.h in Headers */, B9CA3B402CAB1D3E00B2607C /* SpatialImageControls.h in Headers */, 626CDE0F1140424C001E5A68 /* SpatialNavigation.h in Headers */, 517C11D52C6DD6A100489490 /* SpatialVideoMetadata.h in Headers */, diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp index c966a22473f1..29f0fd7cf30d 100644 --- a/Source/WebCore/dom/Document.cpp +++ b/Source/WebCore/dom/Document.cpp @@ -1340,6 +1340,47 @@ const Color& Document::themeColor() return m_cachedThemeColor; } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +void Document::spatialBackdropLinkElementChanged() +{ + spatialBackdropSourceChanged(); +} + +void Document::spatialBackdropSourceChanged() +{ + if (!settings().webPageSpatialBackdropEnabled()) + return; + + auto newSpatialBackdropSource = determineActiveSpatialBackdropSource(); + if (m_cachedSpatialBackdropSource == newSpatialBackdropSource) + return; + m_cachedSpatialBackdropSource = WTFMove(newSpatialBackdropSource); + + if (RefPtr page = this->page()) + page->chrome().client().spatialBackdropSourceChanged(); +} + +std::optional Document::determineActiveSpatialBackdropSource() const +{ + auto sourceURL = m_url.url(); + if (!sourceURL.isValid()) + return std::nullopt; + + for (auto& linkElement : descendantsOfType(*this)) { + if (!linkElement.isSpatialBackdrop()) + continue; + + auto modelURL = linkElement.href(); + if (!modelURL.isValid()) + return std::nullopt; + + return SpatialBackdropSource { WTFMove(sourceURL), WTFMove(modelURL), linkElement.environmentMap() }; + } + + return std::nullopt; +} +#endif + Color Document::linkColor(const RenderStyle& style) const { if (m_linkColor.isValid()) @@ -4213,6 +4254,10 @@ void Document::setURL(const URL& url) m_documentURI = m_url.url(); m_adjustedURL = adjustedURL(); updateBaseURL(); + +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + spatialBackdropSourceChanged(); +#endif } const URL& Document::urlForBindings() diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h index 134c216b3351..08303e53491e 100644 --- a/Source/WebCore/dom/Document.h +++ b/Source/WebCore/dom/Document.h @@ -48,6 +48,7 @@ #include "RenderPtr.h" #include "ReportingClient.h" #include "ScriptExecutionContext.h" +#include "SpatialBackdropSource.h" #include "StringWithDirection.h" #include "Supplementable.h" #include "TextIndicator.h" @@ -917,6 +918,10 @@ class Document const Color& themeColor(); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + const std::optional& spatialBackdropSource() const { return m_cachedSpatialBackdropSource; } +#endif + void setTextColor(const Color& color) { m_textColor = color; } const Color& textColor() const { return m_textColor; } @@ -1107,6 +1112,10 @@ class Document void metaElementThemeColorChanged(HTMLMetaElement&); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + void spatialBackdropLinkElementChanged(); +#endif + #if ENABLE(DARK_MODE_CSS) void processColorScheme(const String& colorScheme); void metaElementColorSchemeChanged(); @@ -2069,6 +2078,11 @@ class Document WeakPtr determineActiveThemeColorMetaElement(); void themeColorChanged(); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + std::optional determineActiveSpatialBackdropSource() const; + void spatialBackdropSourceChanged(); +#endif + void invalidateAccessKeyCacheSlowCase(); void buildAccessKeyCache(); @@ -2230,6 +2244,10 @@ class Document WeakPtr m_activeThemeColorMetaElement; Color m_applicationManifestThemeColor; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + std::optional m_cachedSpatialBackdropSource; +#endif + Color m_textColor { Color::black }; Color m_linkColor; Color m_visitedLinkColor; diff --git a/Source/WebCore/dom/SpatialBackdropSource.cpp b/Source/WebCore/dom/SpatialBackdropSource.cpp new file mode 100644 index 000000000000..949a81470467 --- /dev/null +++ b/Source/WebCore/dom/SpatialBackdropSource.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2025 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +#include "config.h" +#include "SpatialBackdropSource.h" + +namespace WebCore { + +SpatialBackdropSource::SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, std::optional&& environmentMapURL) + : m_sourceURL(WTFMove(sourceURL)) + , m_modelURL(WTFMove(modelURL)) + , m_environmentMapURL(WTFMove(environmentMapURL)) +{ +} + +SpatialBackdropSource::SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, URL&& environmentMapURL) + : m_sourceURL(WTFMove(sourceURL)) + , m_modelURL(WTFMove(modelURL)) + , m_environmentMapURL(environmentMapURL.isValid() ? std::make_optional(WTFMove(environmentMapURL)) : std::nullopt) +{ +} + +} // namespace WebCore +#endif diff --git a/Source/WebCore/dom/SpatialBackdropSource.h b/Source/WebCore/dom/SpatialBackdropSource.h new file mode 100644 index 000000000000..ccc813e5ae9e --- /dev/null +++ b/Source/WebCore/dom/SpatialBackdropSource.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2025 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#pragma once + +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + +#include + +namespace WebCore { + +struct SpatialBackdropSource { +public: + URL m_sourceURL; + URL m_modelURL; + std::optional m_environmentMapURL; + + WEBCORE_EXPORT SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, std::optional&& environmentMapURL); + SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, URL&& environmentMapURL); + + friend bool operator==(const SpatialBackdropSource&, const SpatialBackdropSource&) = default; +}; + +} // namespace WebCore +#endif diff --git a/Source/WebCore/html/HTMLLinkElement.cpp b/Source/WebCore/html/HTMLLinkElement.cpp index 6531d34cc615..c8f36a924863 100644 --- a/Source/WebCore/html/HTMLLinkElement.cpp +++ b/Source/WebCore/html/HTMLLinkElement.cpp @@ -197,11 +197,18 @@ void HTMLLinkElement::attributeChanged(const QualifiedName& name, const AtomStri case AttributeNames::relAttr: { auto parsedRel = LinkRelAttribute(document(), newValue); auto didMutateRel = parsedRel != m_relAttribute; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + auto wasSpatialBackdrop = m_relAttribute.isSpatialBackdrop; +#endif m_relAttribute = WTFMove(parsedRel); if (m_relList) m_relList->associatedAttributeValueChanged(); if (didMutateRel) process(); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + if (wasSpatialBackdrop && !m_relAttribute.isSpatialBackdrop) + document().spatialBackdropLinkElementChanged(); +#endif break; } case AttributeNames::hrefAttr: { @@ -212,6 +219,16 @@ void HTMLLinkElement::attributeChanged(const QualifiedName& name, const AtomStri process(); break; } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + case AttributeNames::environmentmapAttr: { + URL environmentMapURL = getNonEmptyURLAttribute(environmentmapAttr); + if (environmentMapURL == m_environmentMapURL) + return; + m_environmentMapURL = WTFMove(environmentMapURL); + process(); + break; + } +#endif case AttributeNames::typeAttr: if (newValue == m_type) return; @@ -300,6 +317,11 @@ void HTMLLinkElement::process() if (m_isHandlingBeforeLoad) return; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + if (m_relAttribute.isSpatialBackdrop) + document().spatialBackdropLinkElementChanged(); +#endif + processInternalResourceLink(); if (m_relAttribute.isInternalResourceLink) return; @@ -528,6 +550,11 @@ void HTMLLinkElement::removedFromAncestor(RemovalType removalType, ContainerNode bool wasLoading = styleSheetIsLoading(); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + if (m_relAttribute.isSpatialBackdrop) + oldParentOfRemovedTree.document().spatialBackdropLinkElementChanged(); +#endif + if (m_sheet) clearSheet(); @@ -728,7 +755,11 @@ void HTMLLinkElement::startLoadingDynamicSheet() bool HTMLLinkElement::isURLAttribute(const Attribute& attribute) const { - return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribute(attribute); + return attribute.name().localName() == hrefAttr +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + || attribute.name().localName() == environmentmapAttr +#endif + || HTMLElement::isURLAttribute(attribute); } URL HTMLLinkElement::href() const @@ -741,6 +772,13 @@ const AtomString& HTMLLinkElement::rel() const return attributeWithoutSynchronization(relAttr); } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +URL HTMLLinkElement::environmentMap() const +{ + return document().completeURL(attributeWithoutSynchronization(environmentmapAttr)); +} +#endif + AtomString HTMLLinkElement::target() const { return attributeWithoutSynchronization(targetAttr); diff --git a/Source/WebCore/html/HTMLLinkElement.h b/Source/WebCore/html/HTMLLinkElement.h index 5042257402f4..ec4f3f54107e 100644 --- a/Source/WebCore/html/HTMLLinkElement.h +++ b/Source/WebCore/html/HTMLLinkElement.h @@ -57,6 +57,11 @@ class HTMLLinkElement final : public HTMLElement, public CachedStyleSheetClient, URL href() const; WEBCORE_EXPORT const AtomString& rel() const; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + URL environmentMap() const; + bool isSpatialBackdrop() const { return m_relAttribute.isSpatialBackdrop; } +#endif + AtomString target() const final; const AtomString& type() const; @@ -162,6 +167,9 @@ class HTMLLinkElement final : public HTMLElement, public CachedStyleSheetClient, String m_media; String m_integrityMetadataForPendingSheetRequest; URL m_url; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + URL m_environmentMapURL; +#endif std::unique_ptr m_sizes; std::unique_ptr m_relList; std::unique_ptr m_blockingList; diff --git a/Source/WebCore/html/HTMLLinkElement.idl b/Source/WebCore/html/HTMLLinkElement.idl index 3d7ffd8a8c4c..c06cb77cb2b7 100644 --- a/Source/WebCore/html/HTMLLinkElement.idl +++ b/Source/WebCore/html/HTMLLinkElement.idl @@ -27,6 +27,7 @@ [Reflect] attribute boolean disabled; [CEReactions=NotNeeded, Reflect] attribute DOMString charset; [CEReactions=NotNeeded, Reflect, URL] attribute USVString href; + [CEReactions=NotNeeded, Conditional=WEB_PAGE_SPATIAL_BACKDROP, EnabledBySetting=WebPageSpatialBackdropEnabled, Reflect, URL] attribute USVString environmentMap; [CEReactions=NotNeeded, Reflect] attribute DOMString hreflang; [CEReactions=NotNeeded, Reflect] attribute DOMString media; [CEReactions=NotNeeded, Reflect] attribute DOMString rel; diff --git a/Source/WebCore/html/LinkRelAttribute.cpp b/Source/WebCore/html/LinkRelAttribute.cpp index bb86993dc819..3707e864dd0a 100644 --- a/Source/WebCore/html/LinkRelAttribute.cpp +++ b/Source/WebCore/html/LinkRelAttribute.cpp @@ -65,6 +65,12 @@ static constexpr std::pair linkTypesA { "preconnect"_s, { [](auto document) { return document.settings().linkPreconnectEnabled(); }, [](auto relAttribute) { relAttribute.isLinkPreconnect = true; } } }, { "prefetch"_s, { [](auto document) { return document.settings().linkPrefetchEnabled(); }, [](auto relAttribute) { relAttribute.isLinkPrefetch = true; } } }, { "preload"_s, { [](auto document) { return document.settings().linkPreloadEnabled(); }, [](auto relAttribute) { relAttribute.isLinkPreload = true; } } }, +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + { "spatial-backdrop"_s, { + [](auto document) { return document.settings().webPageSpatialBackdropEnabled(); }, + [](auto relAttribute) { relAttribute.isSpatialBackdrop = true; } + } }, +#endif { "stylesheet"_s, { [](auto) { return true; }, [](auto relAttribute) { relAttribute.isStyleSheet = true; } } }, }; diff --git a/Source/WebCore/html/LinkRelAttribute.h b/Source/WebCore/html/LinkRelAttribute.h index a5e1f2be6b26..7062cb785fa7 100644 --- a/Source/WebCore/html/LinkRelAttribute.h +++ b/Source/WebCore/html/LinkRelAttribute.h @@ -53,6 +53,9 @@ struct LinkRelAttribute { bool isApplicationManifest : 1 { false }; #endif bool isInternalResourceLink : 1 { false }; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + bool isSpatialBackdrop : 1 { false }; +#endif LinkRelAttribute() = default; LinkRelAttribute(Document&, StringView); diff --git a/Source/WebCore/page/ChromeClient.h b/Source/WebCore/page/ChromeClient.h index 41cb12a96e88..aa36cc81a3cb 100644 --- a/Source/WebCore/page/ChromeClient.h +++ b/Source/WebCore/page/ChromeClient.h @@ -288,7 +288,10 @@ class ChromeClient { virtual void themeColorChanged() const { } virtual void pageExtendedBackgroundColorDidChange() const { } virtual void sampledPageTopColorChanged() const { } - +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + virtual void spatialBackdropSourceChanged() const { } +#endif + #if ENABLE(APP_HIGHLIGHTS) virtual WebCore::HighlightVisibility appHighlightsVisiblility() const { return HighlightVisibility::Hidden; }; #endif diff --git a/Source/WebCore/page/Page.cpp b/Source/WebCore/page/Page.cpp index 0c476bf2c401..ad3f971c60c0 100644 --- a/Source/WebCore/page/Page.cpp +++ b/Source/WebCore/page/Page.cpp @@ -3418,6 +3418,18 @@ Color Page::themeColor() const return { }; } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +std::optional Page::spatialBackdropSource() const +{ + RefPtr localMainFrame = this->localMainFrame(); + RefPtr document = localMainFrame ? localMainFrame->document() : nullptr; + if (!document) + return std::nullopt; + + return document->spatialBackdropSource(); +} +#endif + Color Page::pageExtendedBackgroundColor() const { RefPtr localMainFrame = this->localMainFrame(); diff --git a/Source/WebCore/page/Page.h b/Source/WebCore/page/Page.h index d1e71ab2fad4..5f8ba4878118 100644 --- a/Source/WebCore/page/Page.h +++ b/Source/WebCore/page/Page.h @@ -38,6 +38,7 @@ #include "RegistrableDomain.h" #include "ScriptTelemetryCategory.h" #include "ScrollTypes.h" +#include "SpatialBackdropSource.h" #include "Supplementable.h" #include "Timer.h" #include "UserInterfaceLayoutDirection.h" @@ -877,6 +878,10 @@ class Page : public RefCountedAndCanMakeWeakPtr, public Supplementable spatialBackdropSource() const; +#endif + #if HAVE(APP_ACCENT_COLORS) && PLATFORM(MAC) WEBCORE_EXPORT void setAppUsesCustomAccentColor(bool); WEBCORE_EXPORT bool appUsesCustomAccentColor() const; diff --git a/Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h b/Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h index ceb22fba857b..88306c97e1af 100644 --- a/Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h +++ b/Source/WebKit/Shared/API/Cocoa/WebKitPrivate.h @@ -50,6 +50,7 @@ #import #import #import +#import #import #import #import diff --git a/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in b/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in index e22cdda0d50f..c403361bc0ef 100644 --- a/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in +++ b/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in @@ -897,6 +897,14 @@ struct WebCore::ShareData { enum class WebCore::ShareDataOriginator : bool +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +struct WebCore::SpatialBackdropSource { + URL m_sourceURL; + URL m_modelURL; + std::optional m_environmentMapURL; +}; +#endif + using WebCore::TargetedElementIdentifiers = std::pair; using WebCore::TargetedElementSelectors = Vector>; diff --git a/Source/WebKit/SourcesCocoa.txt b/Source/WebKit/SourcesCocoa.txt index 78058a0800df..29abc942aa7d 100644 --- a/Source/WebKit/SourcesCocoa.txt +++ b/Source/WebKit/SourcesCocoa.txt @@ -296,6 +296,7 @@ UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm UIProcess/API/Cocoa/_WKResourceLoadInfo.mm UIProcess/API/Cocoa/_WKSessionState.mm +UIProcess/API/Cocoa/_WKSpatialBackdropSource.mm UIProcess/API/Cocoa/_WKSystemPreferences.mm UIProcess/API/Cocoa/_WKTargetedElementInfo.mm UIProcess/API/Cocoa/_WKTargetedElementRequest.mm diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm index bcdc46569ab1..9e91faee03a5 100644 --- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm +++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm @@ -126,6 +126,7 @@ #import "_WKPageLoadTimingInternal.h" #import "_WKRemoteObjectRegistryInternal.h" #import "_WKSessionStateInternal.h" +#import "_WKSpatialBackdropSourceInternal.h" #import "_WKTargetedElementInfoInternal.h" #import "_WKTargetedElementRequestInternal.h" #import "_WKTextInputContextInternal.h" @@ -159,6 +160,7 @@ #import #import #import +#import #import #import #import @@ -1865,6 +1867,16 @@ - (void)_invalidateWindowSnapshotReadinessHandler } #endif +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +- (void)_spatialBackdropSourceDidChange +{ + if (auto spatialBackdropSource = _page->spatialBackdropSource()) + _cachedSpatialBackdropSource = adoptNS([[_WKSpatialBackdropSource alloc] initWithSpatialBackdropSource:spatialBackdropSource.value()]); + else + _cachedSpatialBackdropSource = nil; +} +#endif + #if ENABLE(ATTACHMENT_ELEMENT) - (void)_didInsertAttachment:(API::Attachment&)attachment withSource:(NSString *)source @@ -4716,6 +4728,15 @@ - (void)_setCanUseCredentialStorage:(BOOL)canUseCredentialStorage return cocoaColorOrNil(_page->sampledPageTopColor()).autorelease(); } +- (_WKSpatialBackdropSource *)_spatialBackdropSource +{ +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + return _cachedSpatialBackdropSource.get(); +#else + return nil; +#endif +} + - (id <_WKInputDelegate>)_inputDelegate { return _inputDelegate.getAutoreleased(); diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h b/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h index f7684bf5b1cb..101101409b53 100644 --- a/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h +++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h @@ -396,6 +396,10 @@ struct PerWebProcessState { String _defaultSTSLabel; #endif +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + RetainPtr<_WKSpatialBackdropSource> _cachedSpatialBackdropSource; +#endif + BOOL _didAccessBackForwardList; BOOL _dontResetTransientActivationAfterRunJavaScript; @@ -419,6 +423,10 @@ struct PerWebProcessState { - (void)_invalidateWindowSnapshotReadinessHandler; #endif +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +- (void)_spatialBackdropSourceDidChange; +#endif + #if ENABLE(ATTACHMENT_ELEMENT) - (void)_didRemoveAttachment:(API::Attachment&)attachment; - (void)_didInsertAttachment:(API::Attachment&)attachment withSource:(NSString *)source; diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h b/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h index aaa2caadb2f1..1ce314dd75c3 100644 --- a/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h +++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h @@ -136,6 +136,7 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) { @class _WKRemoteObjectRegistry; @class _WKSafeBrowsingWarning; @class _WKSessionState; +@class _WKSpatialBackdropSource; @class _WKTargetedElementInfo; @class _WKTargetedElementRequest; @class _WKTextInputContext; @@ -455,6 +456,8 @@ for this property. @property (nonatomic, readonly) NSColor *_sampledPageTopColor WK_API_AVAILABLE(macos(12.0)); #endif +@property (nonatomic, readonly) _WKSpatialBackdropSource *_spatialBackdropSource WK_API_AVAILABLE(visionos(WK_XROS_TBA)); + - (void)_grantAccessToAssetServices WK_API_AVAILABLE(macos(12.0), ios(14.0)); - (void)_revokeAccessToAssetServices WK_API_AVAILABLE(macos(12.0), ios(14.0)); diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.h b/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.h new file mode 100644 index 000000000000..a59f065dc758 --- /dev/null +++ b/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2025 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. + */ + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +WK_CLASS_AVAILABLE(visionos(WK_XROS_TBA)) +@interface _WKSpatialBackdropSource : NSObject + +@property (nonatomic, readonly) NSURL *sourceURL WK_API_AVAILABLE(visionos(WK_XROS_TBA)); +@property (nonatomic, readonly) NSURL *modelURL WK_API_AVAILABLE(visionos(WK_XROS_TBA)); +@property (nonatomic, readonly, nullable) NSURL *environmentMapURL WK_API_AVAILABLE(visionos(WK_XROS_TBA)); + +@end + +NS_ASSUME_NONNULL_END diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.mm b/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.mm new file mode 100644 index 000000000000..7b8edae5150e --- /dev/null +++ b/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSource.mm @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2025 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. + */ + +#import "config.h" +#import "_WKSpatialBackdropSourceInternal.h" + +#import + +@implementation _WKSpatialBackdropSource + +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +- (instancetype)initWithSpatialBackdropSource:(const WebCore::SpatialBackdropSource&) spatialBackdropSource +{ + if (!(self = [super init])) + return nil; + + _sourceURL = [spatialBackdropSource.m_sourceURL copy]; + _modelURL = [spatialBackdropSource.m_modelURL copy]; + if (spatialBackdropSource.m_environmentMapURL) + _environmentMapURL = [spatialBackdropSource.m_environmentMapURL.value() copy]; + + return self; +} + +- (void)dealloc +{ + [_sourceURL release]; + [_modelURL release]; + [_environmentMapURL release]; + [super dealloc]; +} +#endif + +@end diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSourceInternal.h b/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSourceInternal.h new file mode 100644 index 000000000000..2dedc09ce69b --- /dev/null +++ b/Source/WebKit/UIProcess/API/Cocoa/_WKSpatialBackdropSourceInternal.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2025 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. + */ + +#import "_WKSpatialBackdropSource.h" + +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +namespace WebCore { +struct SpatialBackdropSource; +} + +@interface _WKSpatialBackdropSource () + +- (instancetype)initWithSpatialBackdropSource:(const WebCore::SpatialBackdropSource&) spatialBackdropSource; + +@end +#endif diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.mm b/Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.mm index 8cd456770de0..8e3975ae1fe6 100644 --- a/Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.mm +++ b/Source/WebKit/UIProcess/API/Cocoa/_WKWebPushDaemonConnection.mm @@ -32,6 +32,7 @@ #import "WKSecurityOriginInternal.h" #import "WebPushDaemonConnectionConfiguration.h" #import "_WKNotificationDataInternal.h" +#import "_WKWebPushMessageInternal.h" #import "_WKWebPushSubscriptionDataInternal.h" #import #import diff --git a/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h b/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h index 6fc14177f377..86517f66007b 100644 --- a/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h +++ b/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h @@ -70,6 +70,10 @@ class PageClientImplCocoa : public PageClient { void themeColorWillChange() final; void themeColorDidChange() final; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + void spatialBackdropSourceWillChange() final; + void spatialBackdropSourceDidChange() final; +#endif void underPageBackgroundColorWillChange() final; void underPageBackgroundColorDidChange() final; void sampledPageTopColorWillChange() final; diff --git a/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm b/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm index 2d02f6920470..490e0077cb51 100644 --- a/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm +++ b/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm @@ -88,6 +88,19 @@ [m_webView didChangeValueForKey:@"_sampledPageTopColor"]; } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +void PageClientImplCocoa::spatialBackdropSourceWillChange() +{ + [m_webView willChangeValueForKey:@"_spatialBackdropSource"]; +} + +void PageClientImplCocoa::spatialBackdropSourceDidChange() +{ + [m_webView _spatialBackdropSourceDidChange]; + [m_webView didChangeValueForKey:@"_spatialBackdropSource"]; +} +#endif + void PageClientImplCocoa::isPlayingAudioWillChange() { [m_webView willChangeValueForKey:NSStringFromSelector(@selector(_isPlayingAudio))]; diff --git a/Source/WebKit/UIProcess/PageClient.h b/Source/WebKit/UIProcess/PageClient.h index 604076d0bbff..4e563b34a629 100644 --- a/Source/WebKit/UIProcess/PageClient.h +++ b/Source/WebKit/UIProcess/PageClient.h @@ -617,6 +617,10 @@ class PageClient : public CanMakeWeakPtr { virtual void themeColorWillChange() { } virtual void themeColorDidChange() { } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + virtual void spatialBackdropSourceWillChange() { } + virtual void spatialBackdropSourceDidChange() { } +#endif virtual void underPageBackgroundColorWillChange() { } virtual void underPageBackgroundColorDidChange() { } virtual void sampledPageTopColorWillChange() { } diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp index 2d72818ae5db..b35369920008 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.cpp +++ b/Source/WebKit/UIProcess/WebPageProxy.cpp @@ -12527,6 +12527,27 @@ void WebPageProxy::sampledPageTopColorChanged(const Color& sampledPageTopColor) pageClient->sampledPageTopColorDidChange(); } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +std::optional WebPageProxy::spatialBackdropSource() const +{ + return internals().spatialBackdropSource; +} + +void WebPageProxy::spatialBackdropSourceChanged(std::optional&& spatialBackdropSource) +{ + if (internals().spatialBackdropSource == spatialBackdropSource) + return; + + if (RefPtr pageClient = this->pageClient()) + pageClient->spatialBackdropSourceWillChange(); + + internals().spatialBackdropSource = WTFMove(spatialBackdropSource); + + if (RefPtr pageClient = this->pageClient()) + pageClient->spatialBackdropSourceDidChange(); +} +#endif + void WebPageProxy::copyLinkWithHighlight() { send(Messages::WebPage::CopyLinkWithHighlight()); diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h index 03c2a52e3509..fc618129f07c 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.h +++ b/Source/WebKit/UIProcess/WebPageProxy.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -922,6 +923,10 @@ class WebPageProxy final : public API::ObjectImpl, publ // Corresponds to the web content's `` or application manifest's `"theme_color"`. WebCore::Color themeColor() const; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + std::optional spatialBackdropSource() const; +#endif + WebCore::Color underlayColor() const; void setUnderlayColor(const WebCore::Color&); @@ -2822,6 +2827,9 @@ class WebPageProxy final : public API::ObjectImpl, publ void themeColorChanged(const WebCore::Color&); void pageExtendedBackgroundColorDidChange(const WebCore::Color&); void sampledPageTopColorChanged(const WebCore::Color&); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + void spatialBackdropSourceChanged(std::optional&&); +#endif WebCore::Color platformUnderPageBackgroundColor() const; void setCanShortCircuitHorizontalWheelEvents(bool canShortCircuitHorizontalWheelEvents) { m_canShortCircuitHorizontalWheelEvents = canShortCircuitHorizontalWheelEvents; } diff --git a/Source/WebKit/UIProcess/WebPageProxy.messages.in b/Source/WebKit/UIProcess/WebPageProxy.messages.in index 8d03506319ed..348b5f7351c2 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.messages.in +++ b/Source/WebKit/UIProcess/WebPageProxy.messages.in @@ -83,6 +83,9 @@ messages -> WebPageProxy { DidChangePageCount(unsigned pageCount) #if PLATFORM(MAC) ThemeColorChanged(WebCore::Color themeColor) +#endif +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + [EnabledBy=WebPageSpatialBackdropEnabled] SpatialBackdropSourceChanged(std::optional spatialBackdropSource) #endif PageExtendedBackgroundColorDidChange(WebCore::Color backgroundColor) SampledPageTopColorChanged(WebCore::Color sampledPageTopColor) diff --git a/Source/WebKit/UIProcess/WebPageProxyInternals.h b/Source/WebKit/UIProcess/WebPageProxyInternals.h index d66f092fd7db..583715bf16fb 100644 --- a/Source/WebKit/UIProcess/WebPageProxyInternals.h +++ b/Source/WebKit/UIProcess/WebPageProxyInternals.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -326,6 +327,9 @@ struct WebPageProxy::Internals final : WebPopupMenuProxy::Client WebCore::ScrollPinningBehavior scrollPinningBehavior { WebCore::ScrollPinningBehavior::DoNotPin }; WebCore::IntSize sizeToContentAutoSizeMaximumSize; WebCore::Color themeColor; +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + std::optional spatialBackdropSource; +#endif RunLoop::Timer tryCloseTimeoutTimer; WebCore::Color underPageBackgroundColorOverride; WebCore::Color underlayColor; diff --git a/Source/WebKit/WebKit.xcodeproj/project.pbxproj b/Source/WebKit/WebKit.xcodeproj/project.pbxproj index a2a925846a48..76831a7b2c8a 100644 --- a/Source/WebKit/WebKit.xcodeproj/project.pbxproj +++ b/Source/WebKit/WebKit.xcodeproj/project.pbxproj @@ -2223,6 +2223,8 @@ C6A4CA0B2252899800169289 /* WKBundlePageMac.h in Headers */ = {isa = PBXBuildFile; fileRef = C6A4CA092252899800169289 /* WKBundlePageMac.h */; settings = {ATTRIBUTES = (Private, ); }; }; C6A4CA0C2252899800169289 /* WKBundlePageMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6A4CA0A2252899800169289 /* WKBundlePageMac.mm */; }; CA05397923EE324400A553DC /* ContentAsStringIncludesChildFrames.h in Headers */ = {isa = PBXBuildFile; fileRef = CA05397823EE324400A553DC /* ContentAsStringIncludesChildFrames.h */; }; + CA33440C2D1673FC007473A1 /* _WKSpatialBackdropSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CA33440B2D1673FB007473A1 /* _WKSpatialBackdropSource.h */; settings = {ATTRIBUTES = (Private, ); }; }; + CA33440F2D1680F9007473A1 /* _WKSpatialBackdropSourceInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = CA33440E2D1680F9007473A1 /* _WKSpatialBackdropSourceInternal.h */; }; CD003A5319D49B5D005ABCE0 /* WebMediaKeyStorageManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CD003A5119D49B5D005ABCE0 /* WebMediaKeyStorageManager.h */; }; CD0C6831201FD10100A59409 /* WKFullScreenViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = CD0C682F201FD10100A59409 /* WKFullScreenViewController.h */; }; CD19A26E1A13E834008D650E /* WebDiagnosticLoggingClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CD19A26A1A13E821008D650E /* WebDiagnosticLoggingClient.h */; }; @@ -7691,6 +7693,9 @@ C6A4CA092252899800169289 /* WKBundlePageMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKBundlePageMac.h; sourceTree = ""; }; C6A4CA0A2252899800169289 /* WKBundlePageMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKBundlePageMac.mm; sourceTree = ""; }; CA05397823EE324400A553DC /* ContentAsStringIncludesChildFrames.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentAsStringIncludesChildFrames.h; sourceTree = ""; }; + CA33440B2D1673FB007473A1 /* _WKSpatialBackdropSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKSpatialBackdropSource.h; sourceTree = ""; }; + CA33440D2D16748F007473A1 /* _WKSpatialBackdropSource.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKSpatialBackdropSource.mm; sourceTree = ""; }; + CA33440E2D1680F9007473A1 /* _WKSpatialBackdropSourceInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKSpatialBackdropSourceInternal.h; sourceTree = ""; }; CD003A5019D49B5D005ABCE0 /* WebMediaKeyStorageManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebMediaKeyStorageManager.cpp; path = MediaCache/WebMediaKeyStorageManager.cpp; sourceTree = ""; }; CD003A5119D49B5D005ABCE0 /* WebMediaKeyStorageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebMediaKeyStorageManager.h; path = MediaCache/WebMediaKeyStorageManager.h; sourceTree = ""; }; CD09FD0A26152E2300E4ACF1 /* WebKitSwift.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebKitSwift.xcconfig; sourceTree = ""; }; @@ -11658,6 +11663,9 @@ 1A002D3F196B329400B9AD44 /* _WKSessionState.h */, 1A002D3E196B329400B9AD44 /* _WKSessionState.mm */, 1A002D42196B337000B9AD44 /* _WKSessionStateInternal.h */, + CA33440B2D1673FB007473A1 /* _WKSpatialBackdropSource.h */, + CA33440D2D16748F007473A1 /* _WKSpatialBackdropSource.mm */, + CA33440E2D1680F9007473A1 /* _WKSpatialBackdropSourceInternal.h */, 8644890A27B47020007A1C66 /* _WKSystemPreferences.h */, 8644890C27B47045007A1C66 /* _WKSystemPreferences.mm */, 8644890E27B5CB43007A1C66 /* _WKSystemPreferencesInternal.h */, @@ -16303,6 +16311,8 @@ 376311FE1A3FB600005A2E51 /* _WKSameDocumentNavigationTypeInternal.h in Headers */, 1A002D44196B338900B9AD44 /* _WKSessionState.h in Headers */, 1A002D43196B337000B9AD44 /* _WKSessionStateInternal.h in Headers */, + CA33440C2D1673FC007473A1 /* _WKSpatialBackdropSource.h in Headers */, + CA33440F2D1680F9007473A1 /* _WKSpatialBackdropSourceInternal.h in Headers */, 8644890B27B47020007A1C66 /* _WKSystemPreferences.h in Headers */, 8644890F27B5CB43007A1C66 /* _WKSystemPreferencesInternal.h in Headers */, F4D985C82690FC1200BBCCBE /* _WKTapHandlingResult.h in Headers */, diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp index 9a82e229dd98..741f3ec3f220 100644 --- a/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp +++ b/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp @@ -1425,6 +1425,13 @@ void WebChromeClient::sampledPageTopColorChanged() const protectedPage()->sampledPageTopColorChanged(); } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +void WebChromeClient::spatialBackdropSourceChanged() const +{ + protectedPage()->spatialBackdropSourceChanged(); +} +#endif + #if ENABLE(APP_HIGHLIGHTS) WebCore::HighlightVisibility WebChromeClient::appHighlightsVisiblility() const { diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h b/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h index 34922f815064..b5a0211271ba 100644 --- a/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h +++ b/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h @@ -369,7 +369,10 @@ class WebChromeClient final : public WebCore::ChromeClient { void themeColorChanged() const final; void pageExtendedBackgroundColorDidChange() const final; void sampledPageTopColorChanged() const final; - +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + void spatialBackdropSourceChanged() const final; +#endif + #if ENABLE(APP_HIGHLIGHTS) WebCore::HighlightVisibility appHighlightsVisiblility() const final; #endif diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp index 0b8b2e8812ad..60f4bd1ba03a 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp @@ -7922,6 +7922,10 @@ void WebPage::didFinishLoad(WebFrame& frame) #if ENABLE(VIEWPORT_RESIZING) shrinkToFitContent(ZoomToInitialScale::Yes); #endif + +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + spatialBackdropSourceChanged(); +#endif } void WebPage::didSameDocumentNavigationForFrame(WebFrame& frame) @@ -8093,6 +8097,14 @@ void WebPage::flushPendingSampledPageTopColorChange() send(Messages::WebPageProxy::SampledPageTopColorChanged(m_page->sampledPageTopColor())); } +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) +void WebPage::spatialBackdropSourceChanged() +{ + if (m_page->settings().webPageSpatialBackdropEnabled()) + send(Messages::WebPageProxy::SpatialBackdropSourceChanged(m_page->spatialBackdropSource())); +} +#endif + void WebPage::flushPendingEditorStateUpdate() { if (!hasPendingEditorStateUpdate()) diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h index 4110af7889bd..64d2cc9ee9e7 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPage.h +++ b/Source/WebKit/WebProcess/WebPage/WebPage.h @@ -1561,6 +1561,10 @@ class WebPage final : public API::ObjectImpl, pub void sampledPageTopColorChanged() { m_pendingSampledPageTopColorChange = true; } void flushPendingSampledPageTopColorChange(); +#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP) + void spatialBackdropSourceChanged(); +#endif + void flushPendingEditorStateUpdate(); void loadAndDecodeImage(WebCore::ResourceRequest&&, std::optional sizeConstraint, size_t, CompletionHandler>&&)>&&);