Skip to content

Commit

Permalink
An extension shouldn't be able to close another extension's popup wit…
Browse files Browse the repository at this point in the history
…h a call to `openPopup()`.

https://webkit.org/b/275914
rdar://127836084

w3c/webextensions#160

Reviewed by Timothy Hatcher.

Adds a static member to WebExtensionContext which signifies whether or
not any extension has an open popup, along with other changes to
WebExtensionContext to update this variable.

* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIActionCocoa.mm:
(WebKit::WebExtensionContext::actionOpenPopup): Modified to check the
state of popupIsOpen
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionActionCocoa.mm:
(WebKit::WebExtensionAction::readyToPresentPopup): Modified to set the
state of s_isPopupOpen when a popup is presented
(WebKit::WebExtensionAction::closePopup): Modified to set the state of
s_isPopupOpen when a popup is closed
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
(WebKit::WebExtensionContext::popupOpening): Setter for s_isPopupOpen
(WebKit::WebExtensionContext::popupClosed):  Setter for s_isPopupOpen
(WebKit::WebExtensionContext::popupIsOpen const): Getter for
s_isPopupOpen

Canonical link: https://commits.webkit.org/280422@main
  • Loading branch information
AriYoung00 authored and mnutt committed Jun 30, 2024
1 parent 70ae2db commit ad6d4cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@
return;
}

if (extensionController()->isShowingActionPopup()) {
completionHandler(toWebExtensionError(apiName, nil, @"another popup is already open"));
return;
}

RefPtr<WebExtensionWindow> window;
RefPtr<WebExtensionTab> tab;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ - (void)_otherPopoverWillShow:(NSNotification *)notification
setHasUnreadBadgeText(false);

m_popupPresented = true;
if (RefPtr extensionController = extensionContext()->extensionController())
extensionController->setShowingActionPopup(true);

dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, protectedThis = Ref { *this }]() {
if (!extensionContext() || !popupPresented())
Expand Down Expand Up @@ -942,6 +944,9 @@ - (void)_otherPopoverWillShow:(NSNotification *)notification
m_popupPresented = false;
m_presentsPopupWhenReady = false;

if (RefPtr extensionController = extensionContext()->extensionController())
extensionController->setShowingActionPopup(false);

[m_popupWebView _close];
m_popupWebView = nil;

Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/UIProcess/Extensions/WebExtensionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class WebExtensionController : public API::ObjectImpl<API::Object::Type::WebExte
void resourceLoadDidReceiveResponse(WebPageProxyIdentifier, const ResourceLoadInfo&, const WebCore::ResourceResponse&);
void resourceLoadDidCompleteWithError(WebPageProxyIdentifier, const ResourceLoadInfo&, const WebCore::ResourceResponse&, const WebCore::ResourceError&);

bool isShowingActionPopup() { return m_showingActionPopup; };
void setShowingActionPopup(bool isOpen) { m_showingActionPopup = isOpen; };

#ifdef __OBJC__
_WKWebExtensionController *wrapper() const { return (_WKWebExtensionController *)API::ObjectImpl<API::Object::Type::WebExtensionController>::wrapper(); }
_WKWebExtensionControllerDelegatePrivate *delegate() const { return (_WKWebExtensionControllerDelegatePrivate *)wrapper().delegate; }
Expand Down Expand Up @@ -253,6 +256,7 @@ class WebExtensionController : public API::ObjectImpl<API::Object::Type::WebExte
#else
bool m_testingMode : 1 { true };
#endif
bool m_showingActionPopup { false };

std::unique_ptr<WebCore::Timer> m_purgeOldMatchedRulesTimer;
std::unique_ptr<HTTPCookieStoreObserver> m_cookieStoreObserver;
Expand Down

0 comments on commit ad6d4cf

Please sign in to comment.