OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 (function() { | 7 (function() { |
8 /** @const */ var BookmarkList = bmm.BookmarkList; | 8 /** @const */ var BookmarkList = bmm.BookmarkList; |
9 /** @const */ var BookmarkTree = bmm.BookmarkTree; | 9 /** @const */ var BookmarkTree = bmm.BookmarkTree; |
10 /** @const */ var Command = cr.ui.Command; | 10 /** @const */ var Command = cr.ui.Command; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 * Returns a promise for all the URLs in the {@code nodes} and the direct | 311 * Returns a promise for all the URLs in the {@code nodes} and the direct |
312 * children of {@code nodes}. | 312 * children of {@code nodes}. |
313 * @param {!Array<BookmarkTreeNode>} nodes . | 313 * @param {!Array<BookmarkTreeNode>} nodes . |
314 * @return {!Promise<Array<string>>} . | 314 * @return {!Promise<Array<string>>} . |
315 */ | 315 */ |
316 function getAllUrls(nodes) { | 316 function getAllUrls(nodes) { |
317 var urls = []; | 317 var urls = []; |
318 | 318 |
319 // Adds the node and all its direct children. | 319 // Adds the node and all its direct children. |
320 function addNodes(node) { | 320 function addNodes(node) { |
321 if (node.id == 'new') | 321 if (!node || node.id == 'new') |
322 return; | 322 return; |
323 | 323 |
324 if (node.children) { | 324 if (node.children) { |
325 node.children.forEach(function(child) { | 325 node.children.forEach(function(child) { |
326 if (!bmm.isFolder(child)) | 326 if (!bmm.isFolder(child)) |
327 urls.push(child.url); | 327 urls.push(child.url); |
328 }); | 328 }); |
329 } else { | 329 } else { |
330 urls.push(node.url); | 330 urls.push(node.url); |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 // Get a future promise for the nodes. | 334 // Get a future promise for the nodes. |
335 // TODO(deepak.m1): All the nodes here should be existed. When we delete | |
Bernhard Bauer
2015/04/30 15:08:07
Move this up to addNodes(), because that's where t
Deepak
2015/04/30 16:11:19
Done.
| |
336 // the nodes then datamodel gets updated but still it shows deleted items as | |
337 // selected items and accessing those nodes throws chrome.runtime.lastError. | |
338 // Please refer https://crbug.com/480935. | |
335 var promises = nodes.map(function(node) { | 339 var promises = nodes.map(function(node) { |
336 if (bmm.isFolder(assert(node))) | 340 if (bmm.isFolder(assert(node))) |
337 return bmm.loadSubtree(node.id); | 341 return bmm.loadSubtree(node.id); |
338 // Not a folder so we already have all the data we need. | 342 // Not a folder so we already have all the data we need. |
339 return Promise.resolve(node); | 343 return Promise.resolve(node); |
340 }); | 344 }); |
341 | 345 |
342 return Promise.all(promises).then(function(nodes) { | 346 return Promise.all(promises).then(function(nodes) { |
343 nodes.forEach(addNodes); | 347 nodes.forEach(addNodes); |
344 return urls; | 348 return urls; |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 | 1521 |
1518 cr.ui.FocusOutlineManager.forDocument(document); | 1522 cr.ui.FocusOutlineManager.forDocument(document); |
1519 initializeSplitter(); | 1523 initializeSplitter(); |
1520 bmm.addBookmarkModelListeners(); | 1524 bmm.addBookmarkModelListeners(); |
1521 dnd.init(selectItemsAfterUserAction); | 1525 dnd.init(selectItemsAfterUserAction); |
1522 bmm.tree.reload(); | 1526 bmm.tree.reload(); |
1523 } | 1527 } |
1524 | 1528 |
1525 initializeBookmarkManager(); | 1529 initializeBookmarkManager(); |
1526 })(); | 1530 })(); |
OLD | NEW |