diff options
Diffstat (limited to 'chrome')
6 files changed, 76 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc index 11fd56d..dab25b1 100644 --- a/chrome/browser/extensions/extension_bookmark_manager_api.cc +++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc @@ -78,6 +78,7 @@ bool CanPasteBookmarkManagerFunction::RunImpl() { SendResponse(true); return true; } + void BookmarkManagerIOFunction::SelectFile(SelectFileDialog::Type type) { // Balanced in one of the three callbacks of SelectFileDialog: // either FileSelectionCanceled, MultiFilesSelected, or FileSelected @@ -98,12 +99,12 @@ void BookmarkManagerIOFunction::SelectFile(SelectFileDialog::Type type) { } void BookmarkManagerIOFunction::FileSelectionCanceled(void* params) { - Release(); //Balanced in BookmarkManagerIOFunction::SelectFile() + Release(); // Balanced in BookmarkManagerIOFunction::SelectFile() } void BookmarkManagerIOFunction::MultiFilesSelected( const std::vector<FilePath>& files, void* params) { - Release(); //Balanced in BookmarkManagerIOFunction::SelectFile() + Release(); // Balanced in BookmarkManagerIOFunction::SelectFile() NOTREACHED() << "Should not be able to select multiple files"; } @@ -124,7 +125,7 @@ void ImportBookmarksFunction::FileSelected(const FilePath& path, FAVORITES, new ProfileWriter(profile()), true); - Release(); //Balanced in BookmarkManagerIOFunction::SelectFile() + Release(); // Balanced in BookmarkManagerIOFunction::SelectFile() } bool ExportBookmarksFunction::RunImpl() { @@ -136,7 +137,14 @@ void ExportBookmarksFunction::FileSelected(const FilePath& path, int index, void* params) { bookmark_html_writer::WriteBookmarks(profile()->GetBookmarkModel(), path); - Release(); //Balanced in BookmarkManagerIOFunction::SelectFile() + Release(); // Balanced in BookmarkManagerIOFunction::SelectFile() +} + +bool SortChildrenBookmarkManagerFunction::RunImpl() { + const BookmarkNode* parent_node = GetNodeFromArguments(); + BookmarkModel* model = profile()->GetBookmarkModel(); + model->SortChildren(parent_node); + return true; } bool BookmarkManagerGetStringsFunction::RunImpl() { diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.h b/chrome/browser/extensions/extension_bookmark_manager_api.h index 72f1bf0..188164e 100644 --- a/chrome/browser/extensions/extension_bookmark_manager_api.h +++ b/chrome/browser/extensions/extension_bookmark_manager_api.h @@ -88,6 +88,17 @@ class ExportBookmarksFunction : public BookmarkManagerIOFunction { DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.export"); }; +class SortChildrenBookmarkManagerFunction + : public ClipboardBookmarkManagerFunction { + public: + // Override ClipboardBookmarkManagerFunction. + virtual bool RunImpl(); + + private: + DECLARE_EXTENSION_FUNCTION_NAME( + "experimental.bookmarkManager.sortChildren"); +}; + class BookmarkManagerGetStringsFunction : public AsyncExtensionFunction { public: // Override AsyncExtensionFunction. diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 936d871..7ba97ff 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -142,6 +142,7 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<CanPasteBookmarkManagerFunction>(); RegisterFunction<ImportBookmarksFunction>(); RegisterFunction<ExportBookmarksFunction>(); + RegisterFunction<SortChildrenBookmarkManagerFunction>(); RegisterFunction<BookmarkManagerGetStringsFunction>(); // History diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 5255897..f3a6182 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -2001,6 +2001,15 @@ ] }, { + "name": "sortChildren", + "type": "function", + "description": "Sorts the children of a given folder", + "nodoc": "true", + "parameters": [ + {"type": "string", "name": "parentId", "description": "The ID of the folder to sort the children of"} + ] + }, + { "name": "getStrings", "type": "function", "description": "Gets the i18n strings for the bookmark manager", diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/test.js b/chrome/test/data/extensions/api_test/bookmark_manager/test.js index e0f596e..b7001b2 100644 --- a/chrome/test/data/extensions/api_test/bookmark_manager/test.js +++ b/chrome/test/data/extensions/api_test/bookmark_manager/test.js @@ -9,6 +9,7 @@ const bookmarks = chrome.bookmarks; const bookmarkManager = chrome.experimental.bookmarkManager; const MAC = /Mac/.test(navigator.platform); var node, node2, count; +var folder, nodeA, nodeB; var tests = [ function getStrings() { @@ -16,6 +17,42 @@ var tests = [ assertEq('string', typeof strings['title']); assertEq('string', typeof strings['search_button']); })); + }, + + function sortChildren() { + folder = { + parentId: '1', + title: 'Folder' + }; + nodeA = { + title: 'a', + url: 'http://www.example.com/a' + }; + nodeB = { + title: 'b', + url: 'http://www.example.com/b' + }; + bookmarks.create(folder, pass(function(result) { + folder.id = result.id; + nodeA.parentId = folder.id; + nodeB.parentId = folder.id; + + bookmarks.create(nodeB, pass(function(result) { + nodeB.id = result.id; + })); + bookmarks.create(nodeA, pass(function(result) { + nodeA.id = result.id; + })); + })); + }, + + function sortChildren2() { + bookmarkManager.sortChildren(folder.id); + + bookmarks.getChildren(folder.id, pass(function(children) { + assertEq(nodeA.id, children[0].id); + assertEq(nodeB.id, children[1].id); + })); } ]; diff --git a/chrome/test/data/extensions/bookmarkmanager/main.html b/chrome/test/data/extensions/bookmarkmanager/main.html index 8915a41..db688c3 100644 --- a/chrome/test/data/extensions/bookmarkmanager/main.html +++ b/chrome/test/data/extensions/bookmarkmanager/main.html @@ -1368,11 +1368,11 @@ function updateCommandsBasedOnSelection(e) { if (e.target == document.activeElement) { // Paste only needs to updated when the tree selection changes. var commandNames = ['copy', 'cut', 'delete', 'rename-folder', 'edit', - 'sort', 'add-new-bookmark', 'new-folder', 'show-in-folder', - 'open-in-new-tab', 'open-in-new-window', 'open-incognito-window'] + 'add-new-bookmark', 'new-folder', 'open-in-new-tab', + 'open-in-new-window', 'open-incognito-window']; if (e.target == tree) { - commandNames.push('paste'); + commandNames.push('paste', 'show-in-folder', 'sort'); } commandNames.forEach(function(baseId) { @@ -1568,6 +1568,9 @@ function handleCommand(e) { case 'paste-command': chrome.experimental.bookmarkManager.paste(list.parentId); break; + case 'sort-command': + chrome.experimental.bookmarkManager.sortChildren(list.parentId); + break; } } |