| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 window.addEventListener('load', function() { | 5 window.addEventListener('load', function() { |
| 6 chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); | 6 chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); |
| 7 chrome.send('getForeignSessions'); |
| 7 }); | 8 }); |
| 8 | 9 |
| 9 /** | 10 /** |
| 10 * Listens for history-item being selected or deselected (through checkbox) | 11 * Listens for history-item being selected or deselected (through checkbox) |
| 11 * and changes the view of the top toolbar. | 12 * and changes the view of the top toolbar. |
| 12 * @param {{detail: {countAddition: number}}} e | 13 * @param {{detail: {countAddition: number}}} e |
| 13 */ | 14 */ |
| 14 window.addEventListener('history-checkbox-select', function(e) { | 15 window.addEventListener('history-checkbox-select', function(e) { |
| 15 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); | 16 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); |
| 16 toolbar.count += e.detail.countAddition; | 17 toolbar.count += e.detail.countAddition; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 // TODO(hsampson): add a popup to check whether the user definitely wants to | 39 // TODO(hsampson): add a popup to check whether the user definitely wants to |
| 39 // delete the selected items. | 40 // delete the selected items. |
| 40 | 41 |
| 41 var historyList = /** @type {HistoryListElement} */($('history-list')); | 42 var historyList = /** @type {HistoryListElement} */($('history-list')); |
| 42 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); | 43 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); |
| 43 var toBeRemoved = historyList.getSelectedItems(toolbar.count); | 44 var toBeRemoved = historyList.getSelectedItems(toolbar.count); |
| 44 chrome.send('removeVisits', toBeRemoved); | 45 chrome.send('removeVisits', toBeRemoved); |
| 45 }); | 46 }); |
| 46 | 47 |
| 47 | |
| 48 /** | 48 /** |
| 49 * When the search is changed refresh the results from the backend. | 49 * When the search is changed refresh the results from the backend. |
| 50 */ | 50 */ |
| 51 window.addEventListener('search-changed', function(e) { | 51 window.addEventListener('search-changed', function(e) { |
| 52 /** @type {HistoryListElement} */($('history-list')).setLoading(); | 52 /** @type {HistoryListElement} */($('history-list')).setLoading(); |
| 53 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]); | 53 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]); |
| 54 }); | 54 }); |
| 55 | 55 |
| 56 /** |
| 57 * Switches between displaying history data and synced tabs data for the page. |
| 58 */ |
| 59 window.addEventListener('switch-display', function(e) { |
| 60 $('history-synced-device-manager').hidden = |
| 61 e.detail.display != 'synced-tabs-button'; |
| 62 $('history-list').hidden = e.detail.display != 'history-button'; |
| 63 }); |
| 64 |
| 56 // Chrome Callbacks------------------------------------------------------------- | 65 // Chrome Callbacks------------------------------------------------------------- |
| 57 | 66 |
| 58 /** | 67 /** |
| 59 * Our history system calls this function with results from searches. | 68 * Our history system calls this function with results from searches. |
| 60 * @param {HistoryQuery} info An object containing information about the query. | 69 * @param {HistoryQuery} info An object containing information about the query. |
| 61 * @param {!Array<HistoryEntry>} results A list of results. | 70 * @param {!Array<HistoryEntry>} results A list of results. |
| 62 */ | 71 */ |
| 63 function historyResult(info, results) { | 72 function historyResult(info, results) { |
| 64 var historyList = /** @type {HistoryListElement} */($('history-list')); | 73 var historyList = /** @type {HistoryListElement} */($('history-list')); |
| 65 historyList.addNewResults(results, info.term); | 74 historyList.addNewResults(results, info.term); |
| 66 if (info.finished) | 75 if (info.finished) |
| 67 historyList.disableResultLoading(); | 76 historyList.disableResultLoading(); |
| 68 } | 77 } |
| 69 | 78 |
| 70 /** | 79 /** |
| 80 * Receives the synced history data. An empty list means that either there are |
| 81 * no foreign sessions, or tab sync is disabled for this profile. |
| 82 * |isTabSyncEnabled| makes it possible to distinguish between the cases. |
| 83 * |
| 84 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the |
| 85 * sessions from other devices. |
| 86 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
| 87 */ |
| 88 function setForeignSessions(sessionList, isTabSyncEnabled) { |
| 89 // TODO(calamity): Add a 'no synced devices' message when sessions are empty. |
| 90 $('history-side-bar').hidden = !isTabSyncEnabled; |
| 91 if (isTabSyncEnabled) { |
| 92 var syncedDeviceManager = /** @type {HistorySyncedDeviceManagerElement} */( |
| 93 $('history-synced-device-manager')); |
| 94 syncedDeviceManager.addSyncedHistory(sessionList); |
| 95 } |
| 96 } |
| 97 |
| 98 /** |
| 71 * Called by the history backend when deletion was succesful. | 99 * Called by the history backend when deletion was succesful. |
| 72 */ | 100 */ |
| 73 function deleteComplete() { | 101 function deleteComplete() { |
| 74 var historyList = /** @type {HistoryListElement} */($('history-list')); | 102 var historyList = /** @type {HistoryListElement} */($('history-list')); |
| 75 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); | 103 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); |
| 76 historyList.removeDeletedHistory(toolbar.count); | 104 historyList.removeDeletedHistory(toolbar.count); |
| 77 toolbar.count = 0; | 105 toolbar.count = 0; |
| 78 } | 106 } |
| 79 | 107 |
| 80 /** | 108 /** |
| 81 * Called by the history backend when the deletion failed. | 109 * Called by the history backend when the deletion failed. |
| 82 */ | 110 */ |
| 83 function deleteFailed() { | 111 function deleteFailed() { |
| 84 } | 112 } |
| 85 | 113 |
| 86 /** | 114 /** |
| 87 * Called when the history is deleted by someone else. | 115 * Called when the history is deleted by someone else. |
| 88 */ | 116 */ |
| 89 function historyDeleted() { | 117 function historyDeleted() { |
| 90 } | 118 } |
| OLD | NEW |