Skip to content

Commit

Permalink
Remove testingMode from WebExtensionContext.
Browse files Browse the repository at this point in the history
https://webkit.org/b/269735
rdar://problem/123254659

Reviewed by Brian Weinstein.

testingMode was added to WebExtensionController, so it is no longer needed on WebExtensionContext.
Removing it prevents the context and controller from mismathcing.

* Source/WebKit/Shared/Extensions/WebExtensionContextParameters.h:
* Source/WebKit/Shared/Extensions/WebExtensionContextParameters.serialization.in:
* Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionContext.mm:
(-[_WKWebExtensionContext _inTestingMode]): Deleted.
(-[_WKWebExtensionContext _setTestingMode:]): Deleted.
* Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionContextPrivate.h:
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::setTestingMode): Deleted.
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.cpp:
(WebKit::WebExtensionContext::parameters const):
(WebKit::WebExtensionContext::inTestingMode const):
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
(WebKit::WebExtensionContext::inTestingMode const): Deleted.
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPINamespaceCocoa.mm:
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIPermissionsCocoa.mm:
* Source/WebKit/WebProcess/Extensions/Cocoa/WebExtensionContextProxyCocoa.mm:
(WebKit::WebExtensionContextProxy::getOrCreate):
* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.cpp:
(WebKit::WebExtensionContextProxy::inTestingMode const):
* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.h:
* Tools/TestWebKitAPI/cocoa/WebExtensionUtilities.mm:
(-[TestWebExtensionManager initForExtension:extensionControllerConfiguration:]):

Canonical link: https://commits.webkit.org/275006@main
  • Loading branch information
xeenon committed Feb 19, 2024
1 parent 066b75f commit 948644e
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct WebExtensionContextParameters {
Ref<API::Data> manifestJSON;

double manifestVersion { 0 };
bool testingMode { false };
bool isSessionStorageAllowedInContentScripts { false };

std::optional<WebCore::PageIdentifier> backgroundPageIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct WebKit::WebExtensionContextParameters {
Ref<API::Data> manifestJSON;

double manifestVersion;
bool testingMode;
bool isSessionStorageAllowedInContentScripts;

std::optional<WebCore::PageIdentifier> backgroundPageIdentifier;
Expand Down
19 changes: 0 additions & 19 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -792,16 +792,6 @@ - (void)didChangeTabProperties:(_WKWebExtensionTabChangedProperties)properties f
_webExtensionContext->didChangeTabProperties(toImpl(changedTab, *_webExtensionContext), toImpl(properties));
}

- (BOOL)_inTestingMode
{
return _webExtensionContext->inTestingMode();
}

- (void)_setTestingMode:(BOOL)testingMode
{
_webExtensionContext->setTestingMode(testingMode);
}

- (WKWebView *)_backgroundWebView
{
return _webExtensionContext->backgroundWebView();
Expand Down Expand Up @@ -1158,15 +1148,6 @@ - (void)didChangeTabProperties:(_WKWebExtensionTabChangedProperties)properties f
{
}

- (BOOL)_inTestingMode
{
return NO;
}

- (void)_setTestingMode:(BOOL)testingMode
{
}

- (WKWebView *)_backgroundWebView
{
return nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ NS_ASSUME_NONNULL_BEGIN

@interface _WKWebExtensionContext ()

/*!
@abstract Enables extra `browser.test` APIs and unsupported API stubs for testing.
@discussion Defaults to `YES` in debug builds.
*/
@property (nonatomic, getter=_inTestingMode, setter=_setTestingMode:) BOOL _testingMode;

/*! @abstract The extension background view used for the extension, or `nil` if the extension does not have background content or it is currently unloaded. */
@property (nonatomic, nullable, readonly) WKWebView *_backgroundWebView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2480,15 +2480,6 @@ static _WKWebExtensionContextError toAPI(WebExtensionContext::Error error)
tab.setTemporaryPermissionMatchPattern(nullptr);
}

void WebExtensionContext::setTestingMode(bool testingMode)
{
ASSERT(!isLoaded());
if (isLoaded())
return;

m_testingMode = testingMode;
}

std::optional<WebCore::PageIdentifier> WebExtensionContext::backgroundPageIdentifier() const
{
if (!m_backgroundWebView || extension().backgroundContentIsServiceWorker())
Expand Down
7 changes: 6 additions & 1 deletion Source/WebKit/UIProcess/Extensions/WebExtensionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "WebExtensionContextParameters.h"
#include "WebExtensionContextProxyMessages.h"
#include "WebExtensionController.h"
#include "WebPageProxy.h"
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
Expand Down Expand Up @@ -65,7 +66,6 @@ WebExtensionContextParameters WebExtensionContext::parameters() const
extension().serializeLocalization(),
extension().serializeManifest(),
extension().manifestVersion(),
inTestingMode(),
isSessionStorageAllowedInContentScripts(),
backgroundPageIdentifier(),
#if ENABLE(INSPECTOR_EXTENSIONS)
Expand All @@ -76,6 +76,11 @@ WebExtensionContextParameters WebExtensionContext::parameters() const
};
}

bool WebExtensionContext::inTestingMode() const
{
return m_extensionController && m_extensionController->inTestingMode();
}

const WebExtensionContext::UserContentControllerProxySet& WebExtensionContext::userContentControllers() const
{
ASSERT(isLoaded());
Expand Down
8 changes: 1 addition & 7 deletions Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ class WebExtensionContext : public API::ObjectImpl<API::Object::Type::WebExtensi
bool hasActiveUserGesture(WebExtensionTab&) const;
void clearUserGesture(WebExtensionTab&);

bool inTestingMode() const { return m_testingMode; }
void setTestingMode(bool);
bool inTestingMode() const;

URL backgroundContentURL();
WKWebView *backgroundWebView() const { return m_backgroundWebView.get(); }
Expand Down Expand Up @@ -810,11 +809,6 @@ class WebExtensionContext : public API::ObjectImpl<API::Object::Type::WebExtensi

bool m_requestedOptionalAccessToAllHosts { false };
bool m_hasAccessInPrivateBrowsing { false };
#ifdef NDEBUG
bool m_testingMode { false };
#else
bool m_testingMode { true };
#endif

VoidCompletionHandlerVector m_actionsToPerformAfterBackgroundContentLoads;
EventListenerTypeCountedSet m_backgroundContentEventListeners;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
#endif

#import "config.h"
#import "CocoaHelpers.h"
#import "WebExtensionAPINamespace.h"
#import <WebKit/_WKWebExtensionPermission.h>

#if ENABLE(WK_WEB_EXTENSIONS)

#import "CocoaHelpers.h"
#import "WebExtensionControllerProxy.h"
#import <WebKit/_WKWebExtensionPermission.h>

namespace WebKit {

bool WebExtensionAPINamespace::isPropertyAllowed(const ASCIILiteral& name, WebPage& page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#import "config.h"
#import "WebExtensionAPIPermissions.h"

#if ENABLE(WK_WEB_EXTENSIONS)

#import "CocoaHelpers.h"
#import "Logging.h"
#import "MessageSenderInlines.h"
Expand All @@ -40,8 +42,6 @@
#import "WebProcess.h"
#import <wtf/cocoa/VectorCocoa.h>

#if ENABLE(WK_WEB_EXTENSIONS)

namespace WebKit {

static NSString * const permissionsKey = @"permissions";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
context.m_localization = parseLocalization(parameters.localizationJSON.get(), parameters.baseURL);
context.m_manifest = parseJSON(parameters.manifestJSON.get());
context.m_manifestVersion = parameters.manifestVersion;
context.m_testingMode = parameters.testingMode;
context.m_isSessionStorageAllowedInContentScripts = parameters.isSessionStorageAllowedInContentScripts;

if (parameters.backgroundPageIdentifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ std::optional<WebExtensionTabIdentifier> WebExtensionContextProxy::tabIdentifier
return std::nullopt;
}

bool WebExtensionContextProxy::inTestingMode() const
{
return m_extensionControllerProxy && m_extensionControllerProxy->inTestingMode();
}

RefPtr<WebPage> WebExtensionContextProxy::backgroundPage() const
{
return m_backgroundPage.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WebExtensionContextProxy final : public RefCounted<WebExtensionContextProx

bool isSessionStorageAllowedInContentScripts() { return m_isSessionStorageAllowedInContentScripts; }

bool inTestingMode() { return m_testingMode; }
bool inTestingMode() const;

WebCore::DOMWrapperWorld& toDOMWrapperWorld(WebExtensionContentWorldType);

Expand Down Expand Up @@ -215,7 +215,6 @@ class WebExtensionContextProxy final : public RefCounted<WebExtensionContextProx
RetainPtr<_WKWebExtensionLocalization> m_localization;
RetainPtr<NSDictionary> m_manifest;
double m_manifestVersion { 0 };
bool m_testingMode { false };
bool m_isSessionStorageAllowedInContentScripts { false };
RefPtr<WebCore::DOMWrapperWorld> m_contentScriptWorld;
WeakFrameSet m_extensionContentFrames;
Expand Down
1 change: 0 additions & 1 deletion Tools/TestWebKitAPI/cocoa/WebExtensionUtilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ - (instancetype)initForExtension:(_WKWebExtension *)extension extensionControlle
_controller = [[_WKWebExtensionController alloc] initWithConfiguration:configuration ?: _WKWebExtensionControllerConfiguration.nonPersistentConfiguration];

_controller._testingMode = YES;
_context._testingMode = YES;

// This should always be self. If you need the delegate, use the controllerDelegate property.
// Delegate method calls will be forwarded to the controllerDelegate.
Expand Down

0 comments on commit 948644e

Please sign in to comment.