Skip to content

Commit

Permalink
Revert 465b681. rdar://problem/112231965
Browse files Browse the repository at this point in the history
Identifier: 259548.869@safari-7615.3.12.11-branch
  • Loading branch information
MyahCobbs committed Jul 13, 2023
1 parent 1ca98b9 commit 7db474f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 43 deletions.
19 changes: 5 additions & 14 deletions Source/WebCore/bindings/js/RunJavaScriptParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,34 @@ namespace WebCore {

enum class RunAsAsyncFunction : bool { No, Yes };
enum class ForceUserGesture : bool { No, Yes };
enum class RemoveTransientActivation : bool { No, Yes };

using ArgumentWireBytesMap = HashMap<String, Vector<uint8_t>>;

struct RunJavaScriptParameters {
RunJavaScriptParameters(String&& source, URL&& sourceURL, RunAsAsyncFunction runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, ForceUserGesture forceUserGesture, RemoveTransientActivation removeTransientActivation)
RunJavaScriptParameters(String&& source, URL&& sourceURL, RunAsAsyncFunction runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, ForceUserGesture forceUserGesture)
: source(WTFMove(source))
, sourceURL(WTFMove(sourceURL))
, runAsAsyncFunction(runAsAsyncFunction)
, arguments(WTFMove(arguments))
, forceUserGesture(forceUserGesture)
, removeTransientActivation(removeTransientActivation)
{
}

RunJavaScriptParameters(const String& source, URL&& sourceURL, bool runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, bool forceUserGesture, RemoveTransientActivation removeTransientActivation)
RunJavaScriptParameters(const String& source, URL&& sourceURL, bool runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, bool forceUserGesture)
: source(source)
, sourceURL(WTFMove(sourceURL))
, runAsAsyncFunction(runAsAsyncFunction ? RunAsAsyncFunction::Yes : RunAsAsyncFunction::No)
, arguments(WTFMove(arguments))
, forceUserGesture(forceUserGesture ? ForceUserGesture::Yes : ForceUserGesture::No)
, removeTransientActivation(removeTransientActivation)
{
}

RunJavaScriptParameters(String&& source, URL&& sourceURL, bool runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, bool forceUserGesture, RemoveTransientActivation removeTransientActivation)
RunJavaScriptParameters(String&& source, URL&& sourceURL, bool runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, bool forceUserGesture)
: source(WTFMove(source))
, sourceURL(WTFMove(sourceURL))
, runAsAsyncFunction(runAsAsyncFunction ? RunAsAsyncFunction::Yes : RunAsAsyncFunction::No)
, arguments(WTFMove(arguments))
, forceUserGesture(forceUserGesture ? ForceUserGesture::Yes : ForceUserGesture::No)
, removeTransientActivation(removeTransientActivation)
{
}

Expand All @@ -74,11 +70,10 @@ struct RunJavaScriptParameters {
RunAsAsyncFunction runAsAsyncFunction;
std::optional<ArgumentWireBytesMap> arguments;
ForceUserGesture forceUserGesture;
RemoveTransientActivation removeTransientActivation;

template<typename Encoder> void encode(Encoder& encoder) const
{
encoder << source << sourceURL << runAsAsyncFunction << arguments << forceUserGesture << removeTransientActivation;
encoder << source << sourceURL << runAsAsyncFunction << arguments << forceUserGesture;
}

template<typename Decoder> static std::optional<RunJavaScriptParameters> decode(Decoder& decoder)
Expand All @@ -103,11 +98,7 @@ struct RunJavaScriptParameters {
if (!decoder.decode(forceUserGesture))
return std::nullopt;

RemoveTransientActivation removeTransientActivation;
if (!decoder.decode(removeTransientActivation))
return std::nullopt;

return { RunJavaScriptParameters { WTFMove(source), WTFMove(sourceURL), runAsAsyncFunction, WTFMove(arguments), forceUserGesture, removeTransientActivation } };
return { RunJavaScriptParameters { WTFMove(source), WTFMove(sourceURL), runAsAsyncFunction, WTFMove(arguments), forceUserGesture } };
}
};

Expand Down
18 changes: 16 additions & 2 deletions Source/WebCore/bindings/js/ScriptController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ JSC::JSValue ScriptController::executeScriptIgnoringException(const String& scri

JSC::JSValue ScriptController::executeScriptInWorldIgnoringException(DOMWrapperWorld& world, const String& script, bool forceUserGesture)
{
auto result = executeScriptInWorld(world, { script, URL { }, false, std::nullopt, forceUserGesture, RemoveTransientActivation::No });
auto result = executeScriptInWorld(world, { script, URL { }, false, std::nullopt, forceUserGesture });
return result ? result.value() : JSC::JSValue { };
}

Expand All @@ -594,6 +594,20 @@ ValueOrException ScriptController::executeScriptInWorld(DOMWrapperWorld& world,

UserGestureIndicator gestureIndicator(parameters.forceUserGesture == ForceUserGesture::Yes ? std::optional<ProcessingUserGestureState>(ProcessingUserGesture) : std::nullopt, m_frame.document());

#if PLATFORM(COCOA)
if (linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::EvaluateJavaScriptWithoutTransientActivation)) {
// Script executed by the user agent under simulated user gesture should not leave behind transient activation
if (parameters.forceUserGesture == ForceUserGesture::Yes && UserGestureIndicator::currentUserGesture()) {
UserGestureIndicator::currentUserGesture()->addDestructionObserver([](UserGestureToken& token) {
token.forEachImpactedDocument([](Document& document) {
if (auto* window = document.domWindow())
window->consumeTransientActivation();
});
});
}
}
#endif

if (!canExecuteScripts(AboutToExecuteScript) || isPaused())
return makeUnexpected(ExceptionDetails { "Cannot execute JavaScript in this document"_s });

Expand Down Expand Up @@ -705,7 +719,7 @@ JSC::JSValue ScriptController::executeUserAgentScriptInWorldIgnoringException(DO
}
ValueOrException ScriptController::executeUserAgentScriptInWorld(DOMWrapperWorld& world, const String& script, bool forceUserGesture)
{
return executeScriptInWorld(world, { script, URL { }, false, std::nullopt, forceUserGesture, RemoveTransientActivation::No });
return executeScriptInWorld(world, { script, URL { }, false, std::nullopt, forceUserGesture });
}

void ScriptController::executeAsynchronousUserAgentScriptInWorld(DOMWrapperWorld& world, RunJavaScriptParameters&& parameters, ResolveFunction&& resolveCompletionHandler)
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/Shared/Cocoa/DefaultWebBrowserChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ bool isRunningTest(const String& bundleID);
void determineTrackingPreventionState();
bool doesAppHaveTrackingPreventionEnabled();
bool doesParentProcessHaveTrackingPreventionEnabled(AuxiliaryProcess&, bool hasRequestedCrossWebsiteTrackingPermission);
bool shouldEvaluateJavaScriptWithoutTransientActivation();
bool isFullWebBrowser();
bool isParentProcessAFullWebBrowser(AuxiliaryProcess&);

Expand Down
12 changes: 0 additions & 12 deletions Source/WebKit/Shared/Cocoa/DefaultWebBrowserChecks.mm
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,6 @@ static bool isFullWebBrowser(const String& bundleIdentifier)
return fullWebBrowser || isRunningTest(bundleIdentifier);
}

bool shouldEvaluateJavaScriptWithoutTransientActivation()
{
static bool staticShouldEvaluateJavaScriptWithoutTransientActivation = [] {
if (linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::EvaluateJavaScriptWithoutTransientActivation))
return true;

return isFullWebBrowser();
}();

return staticShouldEvaluateJavaScriptWithoutTransientActivation;
}

bool isFullWebBrowser()
{
ASSERT(!isInWebKitChildProcess());
Expand Down
9 changes: 1 addition & 8 deletions Source/WebKit/UIProcess/API/C/WKPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
#endif

#if PLATFORM(COCOA)
#include "DefaultWebBrowserChecks.h"
#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
#endif

Expand Down Expand Up @@ -2607,13 +2606,7 @@ void WKPageSetPageStateClient(WKPageRef pageRef, WKPageStateClientBase* client)
void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
{
CRASH_IF_SUSPENDED;
#if PLATFORM(COCOA)
auto removeTransientActivation = shouldEvaluateJavaScriptWithoutTransientActivation() ? RemoveTransientActivation::Yes : RemoveTransientActivation::No;
#else
auto removeTransientActivation = RemoveTransientActivation::No;
#endif

toImpl(pageRef)->runJavaScriptInMainFrame({ toImpl(scriptRef)->string(), URL { }, false, std::nullopt, true, removeTransientActivation }, [context, callback] (auto&& result) {
toImpl(pageRef)->runJavaScriptInMainFrame({ toImpl(scriptRef)->string(), URL { }, false, std::nullopt, true }, [context, callback] (auto&& result) {
if (result.has_value())
callback(toAPI(result.value().get()), nullptr, context);
else
Expand Down
4 changes: 1 addition & 3 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#import "CocoaImage.h"
#import "CompletionHandlerCallChecker.h"
#import "ContentAsStringIncludesChildFrames.h"
#import "DefaultWebBrowserChecks.h"
#import "DiagnosticLoggingClient.h"
#import "FindClient.h"
#import "FullscreenClient.h"
Expand Down Expand Up @@ -1164,8 +1163,7 @@ - (void)_evaluateJavaScript:(NSString *)javaScriptString asAsyncFunction:(BOOL)a
frameID = frame._handle->_frameHandle->frameID();
}

auto removeTransientActivation = WebKit::shouldEvaluateJavaScriptWithoutTransientActivation() ? WebCore::RemoveTransientActivation::Yes : WebCore::RemoveTransientActivation::No;
_page->runJavaScriptInFrameInScriptWorld({ javaScriptString, sourceURL, !!asAsyncFunction, WTFMove(argumentsMap), !!forceUserGesture, removeTransientActivation }, frameID, *world->_contentWorld.get(), [handler] (auto&& result) {
_page->runJavaScriptInFrameInScriptWorld({ javaScriptString, sourceURL, !!asAsyncFunction, WTFMove(argumentsMap), !!forceUserGesture }, frameID, *world->_contentWorld.get(), [handler] (auto&& result) {
if (!handler)
return;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3960,7 +3960,7 @@ void webkitWebViewRunJavascriptWithoutForcedUserGestures(WebKitWebView* webView,
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
g_return_if_fail(script);

RunJavaScriptParameters params = { String::fromUTF8(script), URL { }, false, std::nullopt, false, RemoveTransientActivation::No };
RunJavaScriptParameters params = { String::fromUTF8(script), URL { }, false, std::nullopt, false };
webkitWebViewRunJavaScriptWithParams(webView, script, WTFMove(params), cancellable, callback, userData);
}

Expand All @@ -3985,7 +3985,7 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script,
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
g_return_if_fail(script);

RunJavaScriptParameters params = { String::fromUTF8(script), URL { }, false, std::nullopt, true, RemoveTransientActivation::No };
RunJavaScriptParameters params = { String::fromUTF8(script), URL { }, false, std::nullopt, true };
webkitWebViewRunJavaScriptWithParams(webView, script, WTFMove(params), cancellable, callback, userData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void RemoteInspectorProtocolHandler::inspect(const String& hostAndPort, Connecti

void RemoteInspectorProtocolHandler::runScript(const String& script)
{
m_page.runJavaScriptInMainFrame({ script, URL { }, false, std::nullopt, false, RemoveTransientActivation::No },
m_page.runJavaScriptInMainFrame({ script, URL { }, false, std::nullopt, false },
[] (auto&& result) {
if (!result.has_value())
LOG_ERROR("Exception running script \"%s\"", result.error().message.utf8().data());
Expand Down

0 comments on commit 7db474f

Please sign in to comment.