Chromium Code Reviews| Index: chrome/browser/resources/md_bookmarks/util.js |
| diff --git a/chrome/browser/resources/md_bookmarks/util.js b/chrome/browser/resources/md_bookmarks/util.js |
| index c062786787ae08dc97953678fbf2188dc892f9bf..9165761e42ca6f85abb14a8d5112911fa185417c 100644 |
| --- a/chrome/browser/resources/md_bookmarks/util.js |
| +++ b/chrome/browser/resources/md_bookmarks/util.js |
| @@ -19,6 +19,26 @@ cr.define('bookmarks.util', function() { |
| } |
| /** |
| + * @param {BookmarkTreeNode} treeNode |
| + * @return {BookmarkNode} |
| + */ |
| + function normalizeNode(treeNode) { |
| + var node = Object.assign({}, treeNode); |
| + // Node index is not necessary and not kept up-to-date. Remove it from the |
| + // data structure so we don't accidentally depend on the incorrect |
| + // information. |
| + delete node.index; |
| + |
| + if (!('url' in node)) { |
| + // The onCreated API listener returns folders without |children| defined. |
|
calamity
2017/04/04 08:14:51
K.
|
| + node.children = (node.children || []).map(function(child) { |
| + return child.id; |
| + }); |
| + } |
| + return /** @type {BookmarkNode} */ (node); |
| + } |
| + |
| + /** |
| * @param {BookmarkTreeNode} rootNode |
| * @return {NodeList} |
| */ |
| @@ -30,20 +50,13 @@ cr.define('bookmarks.util', function() { |
| while (stack.length > 0) { |
| var node = stack.pop(); |
| - // Node index is not necessary and not kept up-to-date. Remove it from the |
| - // data structure so we don't accidentally depend on the incorrect |
| - // information. |
| - delete node.index; |
| - nodeList[node.id] = node; |
| + nodeList[node.id] = normalizeNode(node); |
| if (!node.children) |
| continue; |
| - var childIds = []; |
| node.children.forEach(function(child) { |
| - childIds.push(child.id); |
| stack.push(child); |
| }); |
| - node.children = childIds; |
| } |
| return nodeList; |
| @@ -94,6 +107,7 @@ cr.define('bookmarks.util', function() { |
| getDisplayedList: getDisplayedList, |
| hasChildFolders: hasChildFolders, |
| isShowingSearch: isShowingSearch, |
| + normalizeNode: normalizeNode, |
| normalizeNodes: normalizeNodes, |
| ROOT_NODE_ID: '0', |
| }; |