| 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 /** @const */ var BookmarkList = bmm.BookmarkList; | 5 /** @const */ var BookmarkList = bmm.BookmarkList; |
| 6 /** @const */ var BookmarkTree = bmm.BookmarkTree; | 6 /** @const */ var BookmarkTree = bmm.BookmarkTree; |
| 7 /** @const */ var Command = cr.ui.Command; | 7 /** @const */ var Command = cr.ui.Command; |
| 8 /** @const */ var CommandBinding = cr.ui.CommandBinding; | 8 /** @const */ var CommandBinding = cr.ui.CommandBinding; |
| 9 /** @const */ var LinkKind = cr.LinkKind; | 9 /** @const */ var LinkKind = cr.LinkKind; |
| 10 /** @const */ var ListItem = cr.ui.ListItem; | 10 /** @const */ var ListItem = cr.ui.ListItem; |
| 11 /** @const */ var Menu = cr.ui.Menu; | 11 /** @const */ var Menu = cr.ui.Menu; |
| 12 /** @const */ var MenuButton = cr.ui.MenuButton; | 12 /** @const */ var MenuButton = cr.ui.MenuButton; |
| 13 /** @const */ var Promise = cr.Promise; | 13 /** @const */ var Promise = cr.Promise; |
| 14 /** @const */ var Splitter = cr.ui.Splitter; | 14 /** @const */ var Splitter = cr.ui.Splitter; |
| 15 /** @const */ var TreeItem = cr.ui.TreeItem; | 15 /** @const */ var TreeItem = cr.ui.TreeItem; |
| 16 | 16 |
| 17 // Sometimes the extension API is not initialized. | 17 // Sometimes the extension API is not initialized. |
| 18 if (!chrome.bookmarks) | 18 if (!chrome.bookmarks) |
| 19 console.error('Bookmarks extension API is not available'); | 19 console.error('Bookmarks extension API is not available'); |
| 20 | 20 |
| 21 // Get the localized strings from the backend. | 21 // Get the localized strings from the backend. |
| 22 chrome.experimental.bookmarkManager.getStrings(function(data) { | 22 chrome.bookmarkManagerPrivate.getStrings(function(data) { |
| 23 // The strings may contain & which we need to strip. | 23 // The strings may contain & which we need to strip. |
| 24 for (var key in data) { | 24 for (var key in data) { |
| 25 data[key] = data[key].replace(/&/, ''); | 25 data[key] = data[key].replace(/&/, ''); |
| 26 } | 26 } |
| 27 | 27 |
| 28 loadTimeData.data = data; | 28 loadTimeData.data = data; |
| 29 i18nTemplate.process(document, loadTimeData); | 29 i18nTemplate.process(document, loadTimeData); |
| 30 | 30 |
| 31 recentTreeItem.label = loadTimeData.getString('recent'); | 31 recentTreeItem.label = loadTimeData.getString('recent'); |
| 32 searchTreeItem.label = loadTimeData.getString('search'); | 32 searchTreeItem.label = loadTimeData.getString('search'); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // Activate is handled by the open-in-same-window-command. | 212 // Activate is handled by the open-in-same-window-command. |
| 213 list.addEventListener('dblclick', function(e) { | 213 list.addEventListener('dblclick', function(e) { |
| 214 if (e.button == 0) | 214 if (e.button == 0) |
| 215 $('open-in-same-window-command').execute(); | 215 $('open-in-same-window-command').execute(); |
| 216 }); | 216 }); |
| 217 | 217 |
| 218 // The list dispatches an event when the user clicks on the URL or the Show in | 218 // The list dispatches an event when the user clicks on the URL or the Show in |
| 219 // folder part. | 219 // folder part. |
| 220 list.addEventListener('urlClicked', function(e) { | 220 list.addEventListener('urlClicked', function(e) { |
| 221 getLinkController().openUrlFromEvent(e.url, e.originalEvent); | 221 getLinkController().openUrlFromEvent(e.url, e.originalEvent); |
| 222 chrome.experimental.bookmarkManager.recordLaunch(); | 222 chrome.bookmarkManagerPrivate.recordLaunch(); |
| 223 }); | 223 }); |
| 224 | 224 |
| 225 $('term').onsearch = function(e) { | 225 $('term').onsearch = function(e) { |
| 226 setSearch(this.value); | 226 setSearch(this.value); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * Navigates to the search results for the search text. | 230 * Navigates to the search results for the search text. |
| 231 * @para {string} searchText The text to search for. | 231 * @para {string} searchText The text to search for. |
| 232 */ | 232 */ |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 effectAllowed = 'copyMoveLink'; | 536 effectAllowed = 'copyMoveLink'; |
| 537 } else { | 537 } else { |
| 538 effectAllowed = 'copyMove'; | 538 effectAllowed = 'copyMove'; |
| 539 } | 539 } |
| 540 e.dataTransfer.effectAllowed = effectAllowed; | 540 e.dataTransfer.effectAllowed = effectAllowed; |
| 541 | 541 |
| 542 var ids = draggedNodes.map(function(node) { | 542 var ids = draggedNodes.map(function(node) { |
| 543 return node.id; | 543 return node.id; |
| 544 }); | 544 }); |
| 545 | 545 |
| 546 chrome.experimental.bookmarkManager.startDrag(ids); | 546 chrome.bookmarkManagerPrivate.startDrag(ids); |
| 547 } | 547 } |
| 548 }, | 548 }, |
| 549 | 549 |
| 550 handleDragEnter: function(e) { | 550 handleDragEnter: function(e) { |
| 551 e.preventDefault(); | 551 e.preventDefault(); |
| 552 }, | 552 }, |
| 553 | 553 |
| 554 /** | 554 /** |
| 555 * Calback for the dragover event. | 555 * Calback for the dragover event. |
| 556 * @param {Event} e The dragover event. | 556 * @param {Event} e The dragover event. |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 } | 763 } |
| 764 | 764 |
| 765 if (dropPos == 'above') | 765 if (dropPos == 'above') |
| 766 index = relatedIndex; | 766 index = relatedIndex; |
| 767 else if (dropPos == 'below') | 767 else if (dropPos == 'below') |
| 768 index = relatedIndex + 1; | 768 index = relatedIndex + 1; |
| 769 | 769 |
| 770 selectItemsAfterUserAction(selectTarget, selectedTreeId); | 770 selectItemsAfterUserAction(selectTarget, selectedTreeId); |
| 771 | 771 |
| 772 if (index != undefined && index != -1) | 772 if (index != undefined && index != -1) |
| 773 chrome.experimental.bookmarkManager.drop(parentId, index); | 773 chrome.bookmarkManagerPrivate.drop(parentId, index); |
| 774 else | 774 else |
| 775 chrome.experimental.bookmarkManager.drop(parentId); | 775 chrome.bookmarkManagerPrivate.drop(parentId); |
| 776 | 776 |
| 777 e.preventDefault(); | 777 e.preventDefault(); |
| 778 | 778 |
| 779 // TODO(arv): Select the newly dropped items. | 779 // TODO(arv): Select the newly dropped items. |
| 780 } | 780 } |
| 781 this.dropDestination = null; | 781 this.dropDestination = null; |
| 782 this.hideDropOverlay_(); | 782 this.hideDropOverlay_(); |
| 783 }, | 783 }, |
| 784 | 784 |
| 785 clearDragData: function() { | 785 clearDragData: function() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 797 } | 797 } |
| 798 | 798 |
| 799 document.addEventListener('dragstart', this.handleDragStart.bind(this)); | 799 document.addEventListener('dragstart', this.handleDragStart.bind(this)); |
| 800 document.addEventListener('dragenter', this.handleDragEnter.bind(this)); | 800 document.addEventListener('dragenter', this.handleDragEnter.bind(this)); |
| 801 document.addEventListener('dragover', this.handleDragOver.bind(this)); | 801 document.addEventListener('dragover', this.handleDragOver.bind(this)); |
| 802 document.addEventListener('dragleave', this.handleDragLeave.bind(this)); | 802 document.addEventListener('dragleave', this.handleDragLeave.bind(this)); |
| 803 document.addEventListener('drop', this.handleDrop.bind(this)); | 803 document.addEventListener('drop', this.handleDrop.bind(this)); |
| 804 document.addEventListener('dragend', deferredClearData); | 804 document.addEventListener('dragend', deferredClearData); |
| 805 document.addEventListener('mouseup', deferredClearData); | 805 document.addEventListener('mouseup', deferredClearData); |
| 806 | 806 |
| 807 chrome.experimental.bookmarkManager.onDragEnter.addListener( | 807 chrome.bookmarkManagerPrivate.onDragEnter.addListener( |
| 808 this.handleChromeDragEnter.bind(this)); | 808 this.handleChromeDragEnter.bind(this)); |
| 809 chrome.experimental.bookmarkManager.onDragLeave.addListener( | 809 chrome.bookmarkManagerPrivate.onDragLeave.addListener( |
| 810 deferredClearData); | 810 deferredClearData); |
| 811 chrome.experimental.bookmarkManager.onDrop.addListener(deferredClearData); | 811 chrome.bookmarkManagerPrivate.onDrop.addListener(deferredClearData); |
| 812 } | 812 } |
| 813 }; | 813 }; |
| 814 | 814 |
| 815 dnd.init(); | 815 dnd.init(); |
| 816 | 816 |
| 817 // Commands | 817 // Commands |
| 818 | 818 |
| 819 cr.ui.decorate('menu', Menu); | 819 cr.ui.decorate('menu', Menu); |
| 820 cr.ui.decorate('button[menu]', MenuButton); | 820 cr.ui.decorate('button[menu]', MenuButton); |
| 821 cr.ui.decorate('command', Command); | 821 cr.ui.decorate('command', Command); |
| 822 | 822 |
| 823 cr.ui.contextMenuHandler.addContextMenuProperty(tree); | 823 cr.ui.contextMenuHandler.addContextMenuProperty(tree); |
| 824 list.contextMenu = $('context-menu'); | 824 list.contextMenu = $('context-menu'); |
| 825 tree.contextMenu = $('context-menu'); | 825 tree.contextMenu = $('context-menu'); |
| 826 | 826 |
| 827 // Disable almost all commands at startup. | 827 // Disable almost all commands at startup. |
| 828 var commands = document.querySelectorAll('command'); | 828 var commands = document.querySelectorAll('command'); |
| 829 for (var i = 0, command; command = commands[i]; i++) { | 829 for (var i = 0, command; command = commands[i]; i++) { |
| 830 if (command.id != 'import-menu-command' && | 830 if (command.id != 'import-menu-command' && |
| 831 command.id != 'export-menu-command') { | 831 command.id != 'export-menu-command') { |
| 832 command.disabled = true; | 832 command.disabled = true; |
| 833 } | 833 } |
| 834 } | 834 } |
| 835 | 835 |
| 836 var canEdit = true; | 836 var canEdit = true; |
| 837 chrome.experimental.bookmarkManager.canEdit(function(result) { | 837 chrome.bookmarkManagerPrivate.canEdit(function(result) { |
| 838 canEdit = result; | 838 canEdit = result; |
| 839 }); | 839 }); |
| 840 | 840 |
| 841 /** | 841 /** |
| 842 * Incognito mode availability can take the following values: , | 842 * Incognito mode availability can take the following values: , |
| 843 * - 'enabled' for when both normal and incognito modes are available; | 843 * - 'enabled' for when both normal and incognito modes are available; |
| 844 * - 'disabled' for when incognito mode is disabled; | 844 * - 'disabled' for when incognito mode is disabled; |
| 845 * - 'forced' for when incognito mode is forced (normal mode is unavailable). | 845 * - 'forced' for when incognito mode is forced (normal mode is unavailable). |
| 846 */ | 846 */ |
| 847 var incognitoModeAvailability = 'enabled'; | 847 var incognitoModeAvailability = 'enabled'; |
| 848 chrome.systemPrivate.getIncognitoModeAvailability(function(result) { | 848 chrome.systemPrivate.getIncognitoModeAvailability(function(result) { |
| 849 // TODO(rustema): propagate policy value to the bookmark manager when | 849 // TODO(rustema): propagate policy value to the bookmark manager when |
| 850 // it changes. | 850 // it changes. |
| 851 incognitoModeAvailability = result; | 851 incognitoModeAvailability = result; |
| 852 }); | 852 }); |
| 853 | 853 |
| 854 /** | 854 /** |
| 855 * New Windows are not allowed in Windows 8 metro mode. | 855 * New Windows are not allowed in Windows 8 metro mode. |
| 856 */ | 856 */ |
| 857 var canOpenNewWindows = true; | 857 var canOpenNewWindows = true; |
| 858 chrome.experimental.bookmarkManager.canOpenNewWindows(function(result) { | 858 chrome.bookmarkManagerPrivate.canOpenNewWindows(function(result) { |
| 859 canOpenNewWindows = result; | 859 canOpenNewWindows = result; |
| 860 }); | 860 }); |
| 861 | 861 |
| 862 /** | 862 /** |
| 863 * Helper function that updates the canExecute and labels for the open-like | 863 * Helper function that updates the canExecute and labels for the open-like |
| 864 * commands. | 864 * commands. |
| 865 * @param {!cr.ui.CanExecuteEvent} e The event fired by the command system. | 865 * @param {!cr.ui.CanExecuteEvent} e The event fired by the command system. |
| 866 * @param {!cr.ui.Command} command The command we are currently processing. | 866 * @param {!cr.ui.Command} command The command we are currently processing. |
| 867 */ | 867 */ |
| 868 function updateOpenCommands(e, command) { | 868 function updateOpenCommands(e, command) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 function update(canPaste) { | 929 function update(canPaste) { |
| 930 var command = $('paste-command'); | 930 var command = $('paste-command'); |
| 931 command.disabled = !canPaste; | 931 command.disabled = !canPaste; |
| 932 if (opt_f) | 932 if (opt_f) |
| 933 opt_f(); | 933 opt_f(); |
| 934 } | 934 } |
| 935 // We cannot paste into search and recent view. | 935 // We cannot paste into search and recent view. |
| 936 if (list.isSearch() || list.isRecent()) { | 936 if (list.isSearch() || list.isRecent()) { |
| 937 update(false); | 937 update(false); |
| 938 } else { | 938 } else { |
| 939 chrome.experimental.bookmarkManager.canPaste(list.parentId, update); | 939 chrome.bookmarkManagerPrivate.canPaste(list.parentId, update); |
| 940 } | 940 } |
| 941 } | 941 } |
| 942 | 942 |
| 943 document.addEventListener('canExecute', function(e) { | 943 document.addEventListener('canExecute', function(e) { |
| 944 var command = e.command; | 944 var command = e.command; |
| 945 var commandId = command.id; | 945 var commandId = command.id; |
| 946 if (commandId == 'import-menu-command') { | 946 if (commandId == 'import-menu-command') { |
| 947 e.canExecute = canEdit; | 947 e.canExecute = canEdit; |
| 948 } else if (commandId == 'export-menu-command') { | 948 } else if (commandId == 'export-menu-command') { |
| 949 // We can always execute the export-menu command. | 949 // We can always execute the export-menu command. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 } | 1139 } |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 list.addEventListener('change', updateCommandsBasedOnSelection); | 1142 list.addEventListener('change', updateCommandsBasedOnSelection); |
| 1143 tree.addEventListener('change', updateCommandsBasedOnSelection); | 1143 tree.addEventListener('change', updateCommandsBasedOnSelection); |
| 1144 | 1144 |
| 1145 function updateEditingCommands() { | 1145 function updateEditingCommands() { |
| 1146 var editingCommands = ['cut', 'delete', 'rename-folder', 'edit', | 1146 var editingCommands = ['cut', 'delete', 'rename-folder', 'edit', |
| 1147 'add-new-bookmark', 'new-folder', 'sort', 'paste']; | 1147 'add-new-bookmark', 'new-folder', 'sort', 'paste']; |
| 1148 | 1148 |
| 1149 chrome.experimental.bookmarkManager.canEdit(function(result) { | 1149 chrome.bookmarkManagerPrivate.canEdit(function(result) { |
| 1150 if (result != canEdit) { | 1150 if (result != canEdit) { |
| 1151 canEdit = result; | 1151 canEdit = result; |
| 1152 editingCommands.forEach(function(baseId) { | 1152 editingCommands.forEach(function(baseId) { |
| 1153 $(baseId + '-command').canExecuteChange(); | 1153 $(baseId + '-command').canExecuteChange(); |
| 1154 }); | 1154 }); |
| 1155 } | 1155 } |
| 1156 }); | 1156 }); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 var organizeButton = document.querySelector('.summary > button'); | 1159 var organizeButton = document.querySelector('.summary > button'); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 | 1328 |
| 1329 var p = Promise.all.apply(null, promises); | 1329 var p = Promise.all.apply(null, promises); |
| 1330 p.addListener(function(values) { | 1330 p.addListener(function(values) { |
| 1331 values.forEach(function(v) { | 1331 values.forEach(function(v) { |
| 1332 if (typeof v == 'string') | 1332 if (typeof v == 'string') |
| 1333 urls.push(v); | 1333 urls.push(v); |
| 1334 else | 1334 else |
| 1335 addNodes(v); | 1335 addNodes(v); |
| 1336 }); | 1336 }); |
| 1337 getLinkController().openUrls(urls, kind); | 1337 getLinkController().openUrls(urls, kind); |
| 1338 chrome.experimental.bookmarkManager.recordLaunch(); | 1338 chrome.bookmarkManagerPrivate.recordLaunch(); |
| 1339 }); | 1339 }); |
| 1340 } | 1340 } |
| 1341 | 1341 |
| 1342 /** | 1342 /** |
| 1343 * Opens an item in the list. | 1343 * Opens an item in the list. |
| 1344 */ | 1344 */ |
| 1345 function openItem() { | 1345 function openItem() { |
| 1346 var bookmarkNodes = getSelectedBookmarkNodes(); | 1346 var bookmarkNodes = getSelectedBookmarkNodes(); |
| 1347 // If we double clicked or pressed enter on a single folder, navigate to it. | 1347 // If we double clicked or pressed enter on a single folder, navigate to it. |
| 1348 if (bookmarkNodes.length == 1 && bmm.isFolder(bookmarkNodes[0])) { | 1348 if (bookmarkNodes.length == 1 && bmm.isFolder(bookmarkNodes[0])) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 case 'open-in-new-window-command': | 1559 case 'open-in-new-window-command': |
| 1560 openBookmarks(LinkKind.WINDOW); | 1560 openBookmarks(LinkKind.WINDOW); |
| 1561 break; | 1561 break; |
| 1562 case 'open-incognito-window-command': | 1562 case 'open-incognito-window-command': |
| 1563 openBookmarks(LinkKind.INCOGNITO); | 1563 openBookmarks(LinkKind.INCOGNITO); |
| 1564 break; | 1564 break; |
| 1565 case 'delete-command': | 1565 case 'delete-command': |
| 1566 deleteBookmarks(); | 1566 deleteBookmarks(); |
| 1567 break; | 1567 break; |
| 1568 case 'copy-command': | 1568 case 'copy-command': |
| 1569 chrome.experimental.bookmarkManager.copy(getSelectedBookmarkIds(), | 1569 chrome.bookmarkManagerPrivate.copy(getSelectedBookmarkIds(), |
| 1570 updatePasteCommand); | 1570 updatePasteCommand); |
| 1571 break; | 1571 break; |
| 1572 case 'cut-command': | 1572 case 'cut-command': |
| 1573 chrome.experimental.bookmarkManager.cut(getSelectedBookmarkIds(), | 1573 chrome.bookmarkManagerPrivate.cut(getSelectedBookmarkIds(), |
| 1574 updatePasteCommand); | 1574 updatePasteCommand); |
| 1575 break; | 1575 break; |
| 1576 case 'paste-command': | 1576 case 'paste-command': |
| 1577 selectItemsAfterUserAction(list); | 1577 selectItemsAfterUserAction(list); |
| 1578 chrome.experimental.bookmarkManager.paste(list.parentId, | 1578 chrome.bookmarkManagerPrivate.paste(list.parentId, |
| 1579 getSelectedBookmarkIds()); | 1579 getSelectedBookmarkIds()); |
| 1580 break; | 1580 break; |
| 1581 case 'sort-command': | 1581 case 'sort-command': |
| 1582 chrome.experimental.bookmarkManager.sortChildren(list.parentId); | 1582 chrome.bookmarkManagerPrivate.sortChildren(list.parentId); |
| 1583 break; | 1583 break; |
| 1584 case 'rename-folder-command': | 1584 case 'rename-folder-command': |
| 1585 case 'edit-command': | 1585 case 'edit-command': |
| 1586 if (document.activeElement == list) { | 1586 if (document.activeElement == list) { |
| 1587 var li = list.getListItem(list.selectedItem); | 1587 var li = list.getListItem(list.selectedItem); |
| 1588 if (li) | 1588 if (li) |
| 1589 li.editing = true; | 1589 li.editing = true; |
| 1590 } else { | 1590 } else { |
| 1591 document.activeElement.selectedItem.editing = true; | 1591 document.activeElement.selectedItem.editing = true; |
| 1592 } | 1592 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 document.addEventListener('copy', handle('copy-command')); | 1646 document.addEventListener('copy', handle('copy-command')); |
| 1647 document.addEventListener('cut', handle('cut-command')); | 1647 document.addEventListener('cut', handle('cut-command')); |
| 1648 | 1648 |
| 1649 var pasteHandler = handle('paste-command'); | 1649 var pasteHandler = handle('paste-command'); |
| 1650 document.addEventListener('paste', function(e) { | 1650 document.addEventListener('paste', function(e) { |
| 1651 // Paste is a bit special since we need to do an async call to see if we can | 1651 // Paste is a bit special since we need to do an async call to see if we can |
| 1652 // paste because the paste command might not be up to date. | 1652 // paste because the paste command might not be up to date. |
| 1653 updatePasteCommand(pasteHandler); | 1653 updatePasteCommand(pasteHandler); |
| 1654 }); | 1654 }); |
| 1655 })(); | 1655 })(); |
| OLD | NEW |