Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: be5aff9f77c6050e47b364c7d2db9fa73d197df4
      
https://github.com/WebKit/WebKit/commit/be5aff9f77c6050e47b364c7d2db9fa73d197df4
  Author: Ari Young <[email protected]>
  Date:   2024-09-19 (Thu, 19 Sep 2024)

  Changed paths:
    M Source/WebKit/UIProcess/API/Cocoa/WKWebExtension.mm
    M 
Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPISidebarCocoa.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionSidebarCocoa.mm
    M Source/WebKit/UIProcess/Extensions/WebExtension.h
    M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
    M Source/WebKit/UIProcess/Extensions/WebExtensionSidebar.h
    M 
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPISidePanelCocoa.mm
    M 
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPISidebarActionCocoa.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPISidebar.mm
    M Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.h
    M Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.mm

  Log Message:
  -----------
  Implement sidebarAction/sidePanel open/close/toggle API methods.
https://webkit.org/b/279684
rdar://135894111

Reviewed by Timothy Hatcher.

This PR fills in the implementation of the `sidebarAction.open()`,
`sidebarAction.close()`, `sidebarAction.toggle()`, and
`sidePanel.open()` APIs. It also fixes a bug in the implementation
of `sidebarAction.isOpen`. Finally, this PR also adds a reasonably
comprehensive set of unit tests that exercise the behavior of these
API methods.

* Source/WebKit/UIProcess/API/Cocoa/WKWebExtension.mm:
(-[WKWebExtension _hasSidebar]): Replace WebExtension::hasSidebar with
WebExtension::hasAnySidebar
* 
Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPISidebarCocoa.mm:
(WebKit::toExpected): Replace call to toWebExtensionError with
makeUnexpected
(WebKit::getSidebarWithIdentifiers): Replace calls to
toWebExtensionError with makeUnexpected
(WebKit::getOrCreateSidebarWithIdentifiers): Replace calls to
toWebExtensionError with makeUnexpected
(WebKit::scopedAPINameFor): Add helper method to create full API name
for methods which service both sidebarAction and sidePanel
(WebKit::WebExtensionContext::openSidebar): Replaced openSidebarForTab
with openSidebar (allows for less-convoluted code in other locations).
Removed call to fireActionClickEventIfNeeded, added call to delegate to
actually open sidebar.
(WebKit::WebExtensionContext::closeSidebar): Replaced closeSidebarForTab
with closeSidebar, added call to delegate to actually close sidebar.
(WebKit::WebExtensionContext::canProgrammaticallyOpenSidebar): Moved
this method to WebExtensionContext rather than WebExtensionSidebar,
added implementation.
(WebKit::WebExtensionContext::canProgrammaticallyCloseSidebar): Moved
this method to WebExtensionContext rather than WebExtensionSidebar,
added implementation.
(WebKit::WebExtensionContext::sidebarOpen): Simplified implementation
based on other changes in this PR, added condition that relevant tab
must have active user gesture to programmatically open sidebar.
(WebKit::WebExtensionContext::sidebarClose): Cleaned up implementation,
added condition that relevant tab must have active user gesture to
programmatically close sidebar.
(WebKit::WebExtensionContext::sidebarIsOpen): Removed code which checks
if window-specific sidebar is open (window-specific objects should never
directly be open).
(WebKit::WebExtensionContext::sidebarToggle): Fixed minor issues in
implementation, cleaned up implementation.
(WebKit::WebExtensionContext::sidebarGetTitle): Add API name to error
message
(WebKit::WebExtensionContext::sidebarSetTitle): Add API name to error
message
(WebKit::WebExtensionContext::sidebarGetOptions): Add API name to error
message
(WebKit::WebExtensionContext::sidebarSetOptions): Add API name to error
message
(WebKit::WebExtensionContext::openSidebarForTab): Deleted (renamed to
openSidebar).
(WebKit::WebExtensionContext::closeSidebarForTab): Deleted (renamed to
closeSidebar).
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm:
(WebKit::WebExtension::hasSidebarAction): Helper method to check whether
this extension uses sidebarAction
(WebKit::WebExtension::hasSidePanel): Helper method to check whether
this extension uses sidePanel
(WebKit::WebExtension::hasAnySidebar): Helper method to check whether
this extension uses sidebarAction or sidePanel
(WebKit::WebExtension::hasSidebar): Deleted (replaced with
hasAnySidebar).
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::getOrCreateSidebar): Replace calls to
WebExtension::hasSidebar with WebExtension::hasAnySidebar
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionSidebarCocoa.mm:
(WebKit::WebExtensionSidebar::canProgrammaticallyOpenSidebar const): Deleted
(moved to WebExtensionContext).
(WebKit::WebExtensionSidebar::openSidebarWhenReady): Deleted.
(WebKit::WebExtensionSidebar::canProgrammaticallyCloseSidebar const): Deleted
(moved to WebExtensionContext).
(WebKit::WebExtensionSidebar::closeSidebarWhenReady): Deleted.
* Source/WebKit/UIProcess/Extensions/WebExtension.h: Add declarations of
  hasSidebarAction, hasSidePanel, hasAnySidebar; remove declaration of
  hasSidebar
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h: Removed
  declarations of openSidebarForTab and closeSidebarForTab, added
declarations of openSidebar, closeSidebar,
canProgrammaticallyOpenSidebar, and canProgrammaticallyCloseSidebar
* Source/WebKit/UIProcess/Extensions/WebExtensionSidebar.h: Removed
  declarations of canProgrammaticallyOpenSidebar, openSidebarWhenReady,
canProgrammaticallyCloseSidebar, and closeSidebarWhenReady.
* 
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPISidePanelCocoa.mm:
(WebKit::parseWindowIdentifier): Fix bug (accidentally typo'd tabIdKey
rather than windowIdKey).
(WebKit::WebExtensionAPISidePanel::open): Add user gesture check
* 
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPISidebarActionCocoa.mm:
(WebKit::WebExtensionAPISidebarAction::open): Add user gesture check
(WebKit::WebExtensionAPISidebarAction::close): Add user gesture check
(WebKit::WebExtensionAPISidebarAction::toggle): Add user gesture check
(WebKit::WebExtensionAPISidebarAction::isOpen): Only return error for
invalid window ID if windowId has a value AND isValid(windowId) also
fails, rather than just if isValid(windowId) fails
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPISidebar.mm: Add
  import for _WKWebExtensionSidebar.h, add default path to
sidePanelManifest global
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, SidebarActionClearTabPanel)): 
Renamed old test to fix typo
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidebarActionOpenFailsWithoutUserGesture)):
Added test ensuring that sidebarAction.open() fails if the current tab
has no user gesture.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidebarActionCloseFailsWithoutUserGesture)):
Added test ensuring that sidebarAction.close() fails if the current tab
has no user gesture.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidebarActionToggleFailsWithoutUserGesture)):
Added test ensuring that sidebarAction.toggle() fails if the current tab
has no user gesture.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidebarActionOpenSucceedsWithUserGesture)):
Added test ensuring that sidebarAction.open() succeeds if the current
tab has a user gesture. Also ensures that the relevant delegate method
is called correctly.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidebarActionCloseSucceedsWithUserGesture)):
Added test ensuring that sidebarAction.close() succeeds if the current
tab has a user gesture. Also ensures that the relevant delegate method
is called correctly.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidebarActionToggleSucceedsWithUserGesture)):
Added test ensuring that sidebarAction.toggle() succeeds if the current
tab has a user gesture. Also ensures that the relevant delegate method
is called correctly.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidePanelOpenForTabFailsWithoutUserGesture)):
Added test ensuring that sidePanel.open({ tabId: ... }) fails if the
current tab has no user gesture.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidePanelOpenForWindowFailsWithoutUserGesture)):
Added test ensuring that sidePanel.open({ windowId: ... }) fails if the
current tab has no user gesture.
(TestWebKitAPI::TEST_F(WKWebExtnsionAPISidebar, 
SidePanelOpenForTabSucceedsWithUserGesture)):
Added test ensuring that sidePanel.open({ tabId: ... }) succeeds if the
current tab has a user gesture. Also ensures that the relevant delegate
method is called correctly.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, 
SidePanelOpenForWindowSucceedsWithUserGesture)):
Added test ensuring that sidePanel.open({ windowId: ... }) succeeds if
the current tab has a user gesture. Also ensures that the relevant
delegate method is called correctly, and that the sidebar is opened in
the correct window.
(TestWebKitAPI::TEST_F(WKWebExtensionAPISidebar, SidebarAcionClearTabPanel)): 
Deleted (renamed to SidebarActionClearTabPanel).
* Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.h: Added
  presentSidebar, closeSidebar, and didUpdateSidebar callback
properties.
* Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.mm:
(-[TestWebExtensionsDelegate 
_webExtensionController:presentSidebar:forExtensionContext:completionHandler:]):
Added.
(-[TestWebExtensionsDelegate 
_webExtensionController:closeSidebar:forExtensionContext:completionHandler:]):
Added.
(-[TestWebExtensionsDelegate 
_webExtensionController:didUpdateSidebar:forExtensionContext:]):
Added.

Canonical link: https://commits.webkit.org/283934@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to