Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/resources/md_history/history.js

Issue 1932413003: [MD History] Refactor history.html into a history-app element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nit Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Send the history query immediately. This allows the query to process during 5 // Send the history query immediately. This allows the query to process during
6 // the initial page startup. 6 // the initial page startup.
7 chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); 7 chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]);
8 chrome.send('getForeignSessions'); 8 chrome.send('getForeignSessions');
9 9
10 /** 10 /**
11 * @param {HTMLElement} element 11 * @param {HTMLElement} element
12 * @return {!Promise} Resolves once a Polymer element has been fully upgraded. 12 * @return {!Promise} Resolves once a Polymer element has been fully upgraded.
13 */ 13 */
14 function waitForUpgrade(element) { 14 function waitForUpgrade(element) {
15 return new Promise(function(resolve, reject) { 15 return new Promise(function(resolve, reject) {
16 if (window.Polymer && Polymer.isInstance && Polymer.isInstance(element)) 16 if (window.Polymer && Polymer.isInstance && Polymer.isInstance(element))
17 resolve(); 17 resolve();
18 else 18 else
19 $('bundle').addEventListener('load', resolve); 19 $('bundle').addEventListener('load', resolve);
20 }); 20 });
21 } 21 }
22 22
23 /**
24 * Listens for history-item being selected or deselected (through checkbox)
25 * and changes the view of the top toolbar.
26 * @param {{detail: {countAddition: number}}} e
27 */
28 window.addEventListener('history-checkbox-select', function(e) {
29 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar'));
30 toolbar.count += e.detail.countAddition;
31 });
32
33 /**
34 * Listens for call to cancel selection and loops through all items to set
35 * checkbox to be unselected.
36 */
37 window.addEventListener('unselect-all', function() {
38 var historyList = /** @type {HistoryListElement} */($('history-list'));
39 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar'));
40 historyList.unselectAllItems(toolbar.count);
41 toolbar.count = 0;
42 });
43
44 /**
45 * Listens for call to delete all selected items and loops through all items to
46 * to determine which ones are selected and deletes these.
47 */
48 window.addEventListener('delete-selected', function() {
49 if (!loadTimeData.getBoolean('allowDeletingHistory'))
50 return;
51
52 // TODO(hsampson): add a popup to check whether the user definitely wants to
53 // delete the selected items.
54
55 var historyList = /** @type {HistoryListElement} */($('history-list'));
56 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar'));
57 var toBeRemoved = historyList.getSelectedItems(toolbar.count);
58 chrome.send('removeVisits', toBeRemoved);
59 });
60
61 /**
62 * When the search is changed refresh the results from the backend. Ensures that
63 * the search bar is updated with the new search term.
64 * @param {{detail: {search: string}}} e
65 */
66 window.addEventListener('search-changed', function(e) {
67 $('toolbar').setSearchTerm(e.detail.search);
68 /** @type {HistoryListElement} */($('history-list')).setLoading();
69 /** @type {HistoryToolbarElement} */($('toolbar')).searching = true;
70 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]);
71 });
72
73 /**
74 * Switches between displaying history data and synced tabs data for the page.
75 */
76 window.addEventListener('switch-display', function(e) {
77 $('history-synced-device-manager').hidden =
78 e.detail.display != 'synced-tabs-button';
79 $('history-list').hidden = e.detail.display != 'history-button';
80 });
81
82 // Chrome Callbacks------------------------------------------------------------- 23 // Chrome Callbacks-------------------------------------------------------------
83 24
84 /** 25 /**
85 * Our history system calls this function with results from searches. 26 * Our history system calls this function with results from searches.
86 * @param {HistoryQuery} info An object containing information about the query. 27 * @param {HistoryQuery} info An object containing information about the query.
87 * @param {!Array<HistoryEntry>} results A list of results. 28 * @param {!Array<HistoryEntry>} results A list of results.
88 */ 29 */
89 function historyResult(info, results) { 30 function historyResult(info, results) {
90 var listElem = $('history-list'); 31 var appElem = $('history-app');
91 waitForUpgrade(listElem).then(function() { 32 waitForUpgrade(appElem).then(function() {
92 var list = /** @type {HistoryListElement} */(listElem); 33 /** @type {HistoryAppElement} */(appElem).historyResult(info, results);
93 list.addNewResults(results, info.term);
94 /** @type {HistoryToolbarElement} */$('toolbar').searching = false;
95 if (info.finished)
96 list.disableResultLoading();
97 // TODO(tsergeant): Showing everything as soon as the list is ready is not 34 // TODO(tsergeant): Showing everything as soon as the list is ready is not
98 // ideal, as the sidebar can still pop in after. Fix this to show everything 35 // ideal, as the sidebar can still pop in after. Fix this to show everything
99 // at once. 36 // at once.
100 document.body.classList.remove('loading'); 37 document.body.classList.remove('loading');
101 }); 38 });
102 } 39 }
103 40
104 /** 41 /**
105 * Called by the history backend after receiving results and after discovering 42 * Called by the history backend after receiving results and after discovering
106 * the existence of other forms of browsing history. 43 * the existence of other forms of browsing history.
(...skipping 10 matching lines...) Expand all
117 /** 54 /**
118 * Receives the synced history data. An empty list means that either there are 55 * Receives the synced history data. An empty list means that either there are
119 * no foreign sessions, or tab sync is disabled for this profile. 56 * no foreign sessions, or tab sync is disabled for this profile.
120 * |isTabSyncEnabled| makes it possible to distinguish between the cases. 57 * |isTabSyncEnabled| makes it possible to distinguish between the cases.
121 * 58 *
122 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the 59 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the
123 * sessions from other devices. 60 * sessions from other devices.
124 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? 61 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile?
125 */ 62 */
126 function setForeignSessions(sessionList, isTabSyncEnabled) { 63 function setForeignSessions(sessionList, isTabSyncEnabled) {
127 // TODO(calamity): Add a 'no synced devices' message when sessions are empty. 64 var appElem = $('history-app');
128 $('history-side-bar').hidden = !isTabSyncEnabled; 65 waitForUpgrade(appElem).then(function() {
129 var syncedDeviceElem = $('history-synced-device-manager'); 66 /** @type {HistoryAppElement} */(appElem)
130 waitForUpgrade(syncedDeviceElem).then(function() { 67 .setForeignSessions(sessionList, isTabSyncEnabled);
131 var syncedDeviceManager =
132 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem);
133 if (isTabSyncEnabled) {
134 syncedDeviceManager.setSyncedHistory(sessionList);
135 /** @type {HistoryToolbarElement} */($('toolbar')).hasSidebar = true;
136 }
137 }); 68 });
138 } 69 }
139 70
140 /** 71 /**
141 * Called by the history backend when deletion was succesful. 72 * Called by the history backend when deletion was succesful.
142 */ 73 */
143 function deleteComplete() { 74 function deleteComplete() {
144 var historyList = /** @type {HistoryListElement} */($('history-list')); 75 var appElem = $('history-app');
145 var toolbar = /** @type {HistoryToolbarElement} */($('toolbar')); 76 waitForUpgrade(appElem).then(function() {
146 historyList.removeDeletedHistory(toolbar.count); 77 /** @type {HistoryAppElement} */(appElem).deleteComplete();
147 toolbar.count = 0; 78 });
148 } 79 }
149 80
150 /** 81 /**
151 * Called by the history backend when the deletion failed. 82 * Called by the history backend when the deletion failed.
152 */ 83 */
153 function deleteFailed() { 84 function deleteFailed() {
154 } 85 }
155 86
156 /** 87 /**
157 * Called when the history is deleted by someone else. 88 * Called when the history is deleted by someone else.
158 */ 89 */
159 function historyDeleted() { 90 function historyDeleted() {
160 } 91 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/history.html ('k') | chrome/browser/resources/md_history/side_bar.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698