Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inspectable property to _WKWebExtensionContext. #7497

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ WK_EXTERN NSErrorDomain const _WKWebExtensionErrorDomain WK_API_AVAILABLE(macos(
@constant WKWebExtensionErrorResourceNotFound Indicates that a specified resource was not found on disk.
@constant WKWebExtensionErrorInvalidResourceCodeSignature Indicates that a resource failed the bundle's code signature checks.
@constant WKWebExtensionErrorInvalidManifest Indicates that an invalid `manifest.json` was encountered.
@constant WKWebExtensionErrorUnsupportedManifestVersion Indicates that a the manifest version is not supported.
@constant WKWebExtensionErrorUnsupportedManifestVersion Indicates that the manifest version is not supported.
@constant WKWebExtensionErrorInvalidManifestEntry Indicates that an invalid manifest entry was encountered.
@constant WKWebExtensionErrorInvalidDeclarativeNetRequestEntry Indicates that an invalid declarative net request entry was encountered.
@constant WKWebExtensionErrorInvalidBackgroundPersistence Indicates that the extension specified background persistence that was not compatible with the platform or features requested.
Expand Down Expand Up @@ -123,15 +123,15 @@ WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
@property (nonatomic, readonly, copy) NSDictionary<NSString *, id> *manifest;

/*!
@abstract The parsed manifest version, or `0` is if there is no version specified in the manifest.
@abstract The parsed manifest version, or `0` if there is no version specified in the manifest.
@note An `WKWebExtensionErrorUnsupportedManifestVersion` error will be reported if the manifest version isn't specified.
*/
@property (nonatomic, readonly) double manifestVersion;

/*!
@abstract Checks if a manifest version is supported by the extension.
@param manifestVersion The version number to check.
@result Returns `YES` if the extension specified a manifest version that is is greater than or equal to `manifestVersion`.
@result Returns `YES` if the extension specified a manifest version that is greater than or equal to `manifestVersion`.
*/
- (BOOL)usesManifestVersion:(double)manifestVersion;

Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
*/
@property (nonatomic, copy) NSString *uniqueIdentifier;

/*!
@abstract Determines whether Web Inspector can inspect the @link WKWebView @/link instances for this context.
@discussion A context can control multiple `WKWebView` instances, from the background content, to the popover.
You should set this to `YES` when needed for debugging purposes. The default value is `NO`.
*/
@property (nonatomic, getter=isInspectable) BOOL inspectable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this property expose itself in Swift as isInspectable, or do we need to add NS_SWIFT_NAME(isInspectable) to match the inspectable property from JSContext and WKWebView? (During API review we had determined the inspectable was the correct property name for ObjC, and isInspectable was the correct property name for Swift).


/*!
@abstract The currently granted permissions and their expiration dates.
@discussion Permissions that don't expire will have a distant future date. This will never include expired entries at time of access.
Expand Down
19 changes: 19 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ - (void)setUniqueIdentifier:(NSString *)uniqueIdentifier
_webExtensionContext->setUniqueIdentifier(uniqueIdentifier);
}

- (BOOL)isInspectable
{
return _webExtensionContext->isInspectable();
}

- (void)setInspectable:(BOOL)inspectable
{
_webExtensionContext->setInspectable(inspectable);
}

static inline WallTime toImpl(NSDate *date)
{
return date ? WebKit::toImpl(date) : WebKit::toImpl(NSDate.distantFuture);
Expand Down Expand Up @@ -513,6 +523,15 @@ - (void)setUniqueIdentifier:(NSString *)uniqueIdentifier
{
}

- (BOOL)isInspectable
{
return NO;
}

- (void)setInspectable:(BOOL)inspectable
{
}

- (NSDictionary<_WKWebExtensionPermission, NSDate *> *)grantedPermissions
{
return nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ static _WKWebExtensionContextError toAPI(WebExtensionContext::Error error)
m_uniqueIdentifier = uniqueIdentifier;
}

void WebExtensionContext::setInspectable(bool inspectable)
{
m_inspectable = inspectable;

m_backgroundWebView.get().inspectable = inspectable;
}

const WebExtensionContext::InjectedContentVector& WebExtensionContext::injectedContents()
{
// FIXME: <https://webkit.org/b/248429> Support dynamic content scripts by including them here.
Expand Down Expand Up @@ -1171,6 +1178,7 @@ static _WKWebExtensionContextError toAPI(WebExtensionContext::Error error)

m_backgroundWebView.get().UIDelegate = m_delegate.get();
m_backgroundWebView.get().navigationDelegate = m_delegate.get();
m_backgroundWebView.get().inspectable = m_inspectable;

if (extension().backgroundContentIsServiceWorker())
m_backgroundWebView.get()._remoteInspectionNameOverride = WEB_UI_FORMAT_CFSTRING("%@ β€” Extension Service Worker", "Label for an inspectable Web Extension service worker", (__bridge CFStringRef)extension().displayShortName());
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class WebExtensionContext : public API::ObjectImpl<API::Object::Type::WebExtensi
const String& uniqueIdentifier() const { return m_uniqueIdentifier; }
void setUniqueIdentifier(String&&);

bool isInspectable() const { return m_inspectable; }
void setInspectable(bool);

const InjectedContentVector& injectedContents();
bool hasInjectedContentForURL(NSURL *);

Expand Down Expand Up @@ -287,6 +290,8 @@ class WebExtensionContext : public API::ObjectImpl<API::Object::Type::WebExtensi
String m_uniqueIdentifier = UUID::createVersion4().toString();
bool m_customUniqueIdentifier { false };

bool m_inspectable { false };

RefPtr<API::ContentWorld> m_contentScriptWorld;

PermissionsMap m_grantedPermissions;
Expand Down