| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 var BookmarksStore = Polymer({ | 5 var BookmarksStore = Polymer({ |
| 6 is: 'bookmarks-store', | 6 is: 'bookmarks-store', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {BookmarkTreeNode} */ | 9 /** @type {BookmarkTreeNode} */ |
| 10 rootNode: { | 10 rootNode: { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 * Initializes the store with data from the bookmarks API. | 72 * Initializes the store with data from the bookmarks API. |
| 73 * Called by app on attached. | 73 * Called by app on attached. |
| 74 */ | 74 */ |
| 75 initializeStore: function() { | 75 initializeStore: function() { |
| 76 chrome.bookmarks.getTree(function(results) { | 76 chrome.bookmarks.getTree(function(results) { |
| 77 this.setupStore_(results[0]); | 77 this.setupStore_(results[0]); |
| 78 }.bind(this)); | 78 }.bind(this)); |
| 79 // Attach bookmarks API listeners. | 79 // Attach bookmarks API listeners. |
| 80 chrome.bookmarks.onRemoved.addListener(this.onBookmarkRemoved_.bind(this)); | 80 chrome.bookmarks.onRemoved.addListener(this.onBookmarkRemoved_.bind(this)); |
| 81 chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this)); | 81 chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this)); |
| 82 chrome.bookmarks.onImportBegan.addListener(this.onImportBegan_.bind(this)); |
| 83 chrome.bookmarks.onImportEnded.addListener(this.onImportEnded_.bind(this)); |
| 82 }, | 84 }, |
| 83 | 85 |
| 84 ////////////////////////////////////////////////////////////////////////////// | 86 ////////////////////////////////////////////////////////////////////////////// |
| 85 // bookmarks-store, private: | 87 // bookmarks-store, private: |
| 86 | 88 |
| 87 /** | 89 /** |
| 88 * @param {BookmarkTreeNode} rootNode | 90 * @param {BookmarkTreeNode} rootNode |
| 89 * @private | 91 * @private |
| 90 */ | 92 */ |
| 91 setupStore_: function(rootNode) { | 93 setupStore_: function(rootNode) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 onBookmarkChanged_: function(id, changeInfo) { | 321 onBookmarkChanged_: function(id, changeInfo) { |
| 320 if (changeInfo.title) | 322 if (changeInfo.title) |
| 321 this.set(this.idToNodeMap_[id].path + '.title', changeInfo.title); | 323 this.set(this.idToNodeMap_[id].path + '.title', changeInfo.title); |
| 322 if (changeInfo.url) | 324 if (changeInfo.url) |
| 323 this.set(this.idToNodeMap_[id].path + '.url', changeInfo.url); | 325 this.set(this.idToNodeMap_[id].path + '.url', changeInfo.url); |
| 324 | 326 |
| 325 if (this.searchTerm) | 327 if (this.searchTerm) |
| 326 this.updateSearchDisplay_(); | 328 this.updateSearchDisplay_(); |
| 327 }, | 329 }, |
| 328 | 330 |
| 331 /** |
| 332 * Called when importing bookmark is started. |
| 333 */ |
| 334 onImportBegan_: function() { |
| 335 // TODO(rongjie): pause onCreated once this event is used. |
| 336 }, |
| 337 |
| 338 /** |
| 339 * Called when importing bookmark node is finished. |
| 340 */ |
| 341 onImportEnded_: function() { |
| 342 chrome.bookmarks.getTree(function(results) { |
| 343 this.setupStore_(results[0]); |
| 344 this.updateSelectedDisplay_(); |
| 345 }.bind(this)); |
| 346 }, |
| 347 |
| 329 ////////////////////////////////////////////////////////////////////////////// | 348 ////////////////////////////////////////////////////////////////////////////// |
| 330 // bookmarks-store, bookmarks app event listeners: | 349 // bookmarks-store, bookmarks app event listeners: |
| 331 | 350 |
| 332 /** | 351 /** |
| 333 * @param {Event} e | 352 * @param {Event} e |
| 334 * @private | 353 * @private |
| 335 */ | 354 */ |
| 336 onSearchTermChanged_: function(e) { | 355 onSearchTermChanged_: function(e) { |
| 337 this.searchTerm = /** @type {string} */ (e.detail); | 356 this.searchTerm = /** @type {string} */ (e.detail); |
| 338 }, | 357 }, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 idToNodeMap[bookmarkNode.id] = bookmarkNode; | 456 idToNodeMap[bookmarkNode.id] = bookmarkNode; |
| 438 | 457 |
| 439 if (bookmarkNode.url) | 458 if (bookmarkNode.url) |
| 440 return; | 459 return; |
| 441 | 460 |
| 442 bookmarkNode.isSelectedFolder = false; | 461 bookmarkNode.isSelectedFolder = false; |
| 443 bookmarkNode.isOpen = true; | 462 bookmarkNode.isOpen = true; |
| 444 for (var i = 0; i < bookmarkNode.children.length; i++) | 463 for (var i = 0; i < bookmarkNode.children.length; i++) |
| 445 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); | 464 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); |
| 446 }; | 465 }; |
| OLD | NEW |