Skip to content

Commit

Permalink
Apply patch. rdar://123475774
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Robson committed Mar 1, 2024
1 parent 4e42d28 commit 6b90bda
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Source/WebKit/UIProcess/Cocoa/MarketplaceKitWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class MarketplaceKitWrapper : NSObject {

@objc
@available(iOS 17.4, *)
public static func requestAppInstallation(topOrigin: URL, url: URL) {
public static func requestAppInstallation(topOrigin: URL, url: URL, completionHandler: @escaping (Error?) -> Void) {
Task { @MainActor in
do {
#if canImport(MarketplaceKit, _version: "1.4.77.2")
Expand All @@ -44,8 +44,10 @@ public final class MarketplaceKitWrapper : NSObject {
try await AppLibrary.current.requestAppInstallation(with: LinkMetadata(referrer: topOrigin, url: url))
#endif
logger.debug("WKMarketplaceKit.requestAppInstallation with top origin \(topOrigin, privacy: .sensitive) for \(url, privacy: .sensitive) succeeded")
completionHandler(nil);
} catch {
logger.error("WKMarketplaceKit.requestAppInstallation with top origin \(topOrigin, privacy: .sensitive) for \(url, privacy: .sensitive) failed: \(error, privacy: .public)")
completionHandler(error);
}
}
}
Expand Down
28 changes: 26 additions & 2 deletions Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#import "_WKFrameHandleInternal.h"
#import "_WKRenderingProgressEventsInternal.h"
#import "_WKSameDocumentNavigationTypeInternal.h"
#import <JavaScriptCore/ConsoleTypes.h>
#import <WebCore/AuthenticationMac.h>
#import <WebCore/ContentRuleListResults.h>
#import <WebCore/Credential.h>
Expand Down Expand Up @@ -103,7 +104,7 @@
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL(WebKit, WebKitSwift, WKMarketplaceKit)

@interface WKMarketplaceKit : NSObject
+ (void)requestAppInstallationWithTopOrigin:(NSURL *)topOrigin url:(NSURL *)url;
+ (void)requestAppInstallationWithTopOrigin:(NSURL *)topOrigin url:(NSURL *)url completionHandler:(void (^)(NSError *))completionHandler;
@end
#endif

Expand Down Expand Up @@ -420,8 +421,25 @@ static bool isMarketplaceKitURL(const URL& url)

static void interceptMarketplaceKitNavigation(Ref<API::NavigationAction>&& action, WebPageProxy& page)
{
std::optional<FrameIdentifier> sourceFrameID;
if (auto sourceFrame = action->sourceFrame())
sourceFrameID = sourceFrame->handle()->frameID();

auto addConsoleError = [sourceFrameID, url = action->request().url(), weakPage = WeakPtr { page }](const String& error) {
if (!sourceFrameID || !weakPage)
return;

weakPage->addConsoleMessage(*sourceFrameID, MessageSource::Network, MessageLevel::Error, makeString("Can't handle MarketplaceKit link ", url.string().utf8().data(), " due to error: "_s, error));
};

if (!action->shouldOpenExternalSchemes() || !action->isProcessingUserGesture() || action->isRedirect() || action->data().requesterTopOrigin.isNull()) {
RELEASE_LOG_ERROR(Loading, "NavigationState: can't handle MarketplaceKit navigation with shouldOpenExternalSchemes: %d, isProcessingUserGesture: %d, isRedirect: %d, requesterTopOriginIsNull: %d", action->shouldOpenExternalSchemes(), action->isProcessingUserGesture(), action->isRedirect(), action->data().requesterTopOrigin.isNull());

if (!action->isProcessingUserGesture())
addConsoleError("must be activated via a user gesture"_s);
else if (action->isRedirect())
addConsoleError("must be a direct link without a redirect"_s);

return;
}

Expand All @@ -433,7 +451,13 @@ static void interceptMarketplaceKitNavigation(Ref<API::NavigationAction>&& actio
return;
}

[getWKMarketplaceKitClass() requestAppInstallationWithTopOrigin:requesterTopOriginURL.get() url:url.get()];
if (![getWKMarketplaceKitClass() respondsToSelector:@selector(requestAppInstallationWithTopOrigin:url:completionHandler:)])
return;

[getWKMarketplaceKitClass() requestAppInstallationWithTopOrigin:requesterTopOriginURL.get() url:url.get() completionHandler:makeBlockPtr([addConsoleError = WTFMove(addConsoleError)](NSError *error) mutable {
if (error)
addConsoleError(error.description);
}).get()];
}

#endif // HAVE(MARKETPLACE_KIT)
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
#include "WebViewDidMoveToWindowObserver.h"
#include "WebWheelEventCoalescer.h"
#include "WebsiteDataStore.h"
#include <JavaScriptCore/ConsoleTypes.h>
#include <WebCore/AlternativeTextClient.h>
#include <WebCore/AppHighlight.h>
#include <WebCore/ArchiveError.h>
Expand Down Expand Up @@ -13541,6 +13542,11 @@ void WebPageProxy::renderTreeAsText(WebCore::FrameIdentifier frameID, size_t bas
completionHandler(WTFMove(result));
}

void WebPageProxy::addConsoleMessage(FrameIdentifier frameID, MessageSource messageSource, MessageLevel messageLevel, const String& message, std::optional<ResourceLoaderIdentifier> coreIdentifier)
{
send(Messages::WebPage::AddConsoleMessage { frameID, messageSource, messageLevel, message, coreIdentifier });
}

} // namespace WebKit

#undef WEBPAGEPROXY_RELEASE_LOG
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ template<typename> struct ConnectionSendSyncResult;
using DataReference = std::span<const uint8_t>;
}

namespace JSC {
enum class MessageSource : uint8_t;
enum class MessageLevel : uint8_t;
};

namespace PAL {
class SessionID;
enum class HysteresisState : bool;
Expand Down Expand Up @@ -2315,6 +2320,8 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ
void updateMediaCapability();
#endif

void addConsoleMessage(WebCore::FrameIdentifier, JSC::MessageSource, JSC::MessageLevel, const String&, std::optional<WebCore::ResourceLoaderIdentifier> = std::nullopt);

private:
WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
void platformInitialize();
Expand Down

0 comments on commit 6b90bda

Please sign in to comment.