Skip to content

Web Extensions: Parsing for Create() Bookmark function #47248

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

Conversation

akutira-umich
Copy link
Contributor

@akutira-umich akutira-umich commented Jun 26, 2025

7c3bccb

Web Extensions: Parsing for Create() Bookmark function
rdar://154231013
https://bugs.webkit.org/show_bug.cgi?id=294932

Reviewed by Timothy Hatcher.

Parses the create function using a CreateDetails Object which takes in the parameters
for the dictionary. For now this info from the dictionary is put into MockBookmarkNodes.
Also makes sure default type of a bookmark create request is assigned properly and
dateAdded is a parameter you can set only for testing purposes.
Created tests for these as well.

* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIBookmarksCocoa.mm:
(WebKit::toWebAPI):
(WebKit::toTypeImpl):
(WebKit::WebExtensionAPIBookmarks::createBookmark):
(WebKit::WebExtensionAPIBookmarks::getRecent):
(WebKit::WebExtensionAPIBookmarks::createDictionaryFromNode):
* Source/WebKit/WebProcess/Extensions/API/WebExtensionAPIBookmarks.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIBookmarks.mm:
(TestWebKitAPI::TEST_F(WKWebExtensionAPIBookmarks, BookmarksAPICreateParse)):

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

2092a9f

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@akutira-umich akutira-umich force-pushed the eng/Web-Extensions-Parsing-for-Create-and-Move-Bookmark-function branch from e2a9977 to 47efa34 Compare June 26, 2025 17:40
@akutira-umich akutira-umich force-pushed the eng/Web-Extensions-Parsing-for-Create-and-Move-Bookmark-function branch from 47efa34 to cc2a9e2 Compare June 26, 2025 22:24
@akutira-umich akutira-umich force-pushed the eng/Web-Extensions-Parsing-for-Create-and-Move-Bookmark-function branch from cc2a9e2 to 9b87032 Compare June 27, 2025 21:41

static NSDictionary *toWebAPI(const WebExtensionAPIBookmarks::MockBookmarkNode& node)
{
NSString* typeString = toWebAPI(node.type, node.url.createNSString().get());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
NSString* typeString = toWebAPI(node.type, node.url.createNSString().get());

dateAddedKey: @(node.dateAdded.secondsSinceEpoch().milliseconds()),
typeKey: bookmarkKey
typeKey: typeString
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
typeKey: typeString
typeKey: toWebAPI(node.type, node.url.createNSString().get());

@@ -67,15 +108,32 @@
if (!validateDictionary(bookmark, @"bookmark", requiredKeys, types, outExceptionString))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!validateDictionary(bookmark, @"bookmark", requiredKeys, types, outExceptionString))
if (!validateDictionary(bookmark, @"bookmark", nil, types, outExceptionString))

@@ -67,15 +108,32 @@
if (!validateDictionary(bookmark, @"bookmark", requiredKeys, types, outExceptionString))
return;

parsedDetails.index = objectForKey<NSNumber>(bookmark, indexKey).intValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
parsedDetails.index = objectForKey<NSNumber>(bookmark, indexKey).intValue;
parsedDetails.index = objectForKey<NSNumber>(bookmark, indexKey).unsignedLongValue;

parsedDetails.url = objectForKey<NSString>(bookmark, urlKey);

if (bookmark[typeKey]) {
std::optional<WebExtensionAPIBookmarks::BookmarkTreeNodeType> parsedType = toImpl(dynamic_objc_cast<NSString>(bookmark[typeKey]));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::optional<WebExtensionAPIBookmarks::BookmarkTreeNodeType> parsedType = toImpl(dynamic_objc_cast<NSString>(bookmark[typeKey]));
auto parsedType = toTypeImpl(dynamic_objc_cast<NSString>(bookmark[typeKey]));

return tempNode;
}

static std::optional<WebExtensionAPIBookmarks::BookmarkTreeNodeType> toImpl(NSString *typeString)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static std::optional<WebExtensionAPIBookmarks::BookmarkTreeNodeType> toImpl(NSString *typeString)
static std::optional<WebExtensionAPIBookmarks::BookmarkTreeNodeType> toTypeImpl(NSString *typeString)

Comment on lines 118 to 117
if (!parsedType)
*outExceptionString = toErrorString(nullString(), typeKey, @"it must specify either 'bookmark' or 'folder'").createNSString().autorelease();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!parsedType)
*outExceptionString = toErrorString(nullString(), typeKey, @"it must specify either 'bookmark' or 'folder'").createNSString().autorelease();
if (!parsedType) {
*outExceptionString = toErrorString(nullString(), typeKey, @"it must specify either 'bookmark' or 'folder'").createNSString().autorelease();
return;
}

private:

public:
enum class BookmarkTreeNodeType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
enum class BookmarkTreeNodeType {
enum class BookmarkTreeNodeType : uint_8_t {

};

struct CreateDetails {
std::optional<int> index;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::optional<int> index;
std::optional<size_t> index;

@akutira-umich akutira-umich force-pushed the eng/Web-Extensions-Parsing-for-Create-and-Move-Bookmark-function branch from 9b87032 to 2092a9f Compare June 30, 2025 16:48
@xeenon xeenon added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing WebKit Extensions Bugs related to extension support. labels Jun 30, 2025
rdar://154231013
https://bugs.webkit.org/show_bug.cgi?id=294932

Reviewed by Timothy Hatcher.

Parses the create function using a CreateDetails Object which takes in the parameters
for the dictionary. For now this info from the dictionary is put into MockBookmarkNodes.
Also makes sure default type of a bookmark create request is assigned properly and
dateAdded is a parameter you can set only for testing purposes.
Created tests for these as well.

* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIBookmarksCocoa.mm:
(WebKit::toWebAPI):
(WebKit::toTypeImpl):
(WebKit::WebExtensionAPIBookmarks::createBookmark):
(WebKit::WebExtensionAPIBookmarks::getRecent):
(WebKit::WebExtensionAPIBookmarks::createDictionaryFromNode):
* Source/WebKit/WebProcess/Extensions/API/WebExtensionAPIBookmarks.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIBookmarks.mm:
(TestWebKitAPI::TEST_F(WKWebExtensionAPIBookmarks, BookmarksAPICreateParse)):

Canonical link: https://commits.webkit.org/296824@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Web-Extensions-Parsing-for-Create-and-Move-Bookmark-function branch from 2092a9f to 7c3bccb Compare June 30, 2025 20:24
@webkit-commit-queue
Copy link
Collaborator

Committed 296824@main (7c3bccb): https://commits.webkit.org/296824@main

Reviewed commits have been landed. Closing PR #47248 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 7c3bccb into WebKit:main Jun 30, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Extensions Bugs related to extension support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants