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 // 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 var upgradePromise = null; | |
tsergeant
2016/07/21 07:25:27
Nit: /** @type {Promise} */
calamity
2016/07/25 03:43:30
Done.
| |
11 | |
10 /** | 12 /** |
11 * @param {HTMLElement} element | 13 * @return {!Promise} Resolves once the history-app has been fully upgraded. |
12 * @return {!Promise} Resolves once a Polymer element has been fully upgraded. | |
13 */ | 14 */ |
14 function waitForUpgrade(element) { | 15 function waitForAppUpgrade() { |
15 return new Promise(function(resolve, reject) { | 16 if (!upgradePromise) { |
16 if (window.Polymer && Polymer.isInstance && Polymer.isInstance(element)) | 17 upgradePromise = new Promise(function(resolve, reject) { |
17 resolve(); | 18 if (window.Polymer && Polymer.isInstance && |
18 else | 19 Polymer.isInstance($('history-app'))) { |
19 $('bundle').addEventListener('load', resolve); | 20 resolve(); |
20 }); | 21 } else { |
22 $('bundle').addEventListener('load', resolve); | |
23 } | |
24 }); | |
25 } | |
26 return upgradePromise; | |
21 } | 27 } |
22 | 28 |
23 // Chrome Callbacks------------------------------------------------------------- | 29 // Chrome Callbacks------------------------------------------------------------- |
24 | 30 |
25 /** | 31 /** |
26 * Our history system calls this function with results from searches. | 32 * Our history system calls this function with results from searches. |
27 * @param {HistoryQuery} info An object containing information about the query. | 33 * @param {HistoryQuery} info An object containing information about the query. |
28 * @param {!Array<HistoryEntry>} results A list of results. | 34 * @param {!Array<HistoryEntry>} results A list of results. |
29 */ | 35 */ |
30 function historyResult(info, results) { | 36 function historyResult(info, results) { |
31 var appElem = $('history-app'); | 37 waitForAppUpgrade().then(function() { |
32 waitForUpgrade(appElem).then(function() { | 38 /** @type {HistoryAppElement} */($('history-app')) |
33 /** @type {HistoryAppElement} */(appElem).historyResult(info, results); | 39 .historyResult(info, results); |
34 // TODO(tsergeant): Showing everything as soon as the list is ready is not | 40 // TODO(tsergeant): Showing everything as soon as the list is ready is not |
35 // ideal, as the sidebar can still pop in after. Fix this to show everything | 41 // ideal, as the sidebar can still pop in after. Fix this to show everything |
36 // at once. | 42 // at once. |
37 document.body.classList.remove('loading'); | 43 document.body.classList.remove('loading'); |
38 }); | 44 }); |
39 } | 45 } |
40 | 46 |
41 /** | 47 /** |
42 * Called by the history backend after receiving results and after discovering | 48 * Called by the history backend after receiving results and after discovering |
43 * the existence of other forms of browsing history. | 49 * the existence of other forms of browsing history. |
44 * @param {boolean} hasSyncedResults Whether there are synced results. | 50 * @param {boolean} hasSyncedResults Whether there are synced results. |
45 * @param {boolean} includeOtherFormsOfBrowsingHistory Whether to include | 51 * @param {boolean} includeOtherFormsOfBrowsingHistory Whether to include |
46 * a sentence about the existence of other forms of browsing history. | 52 * a sentence about the existence of other forms of browsing history. |
47 */ | 53 */ |
48 function showNotification( | 54 function showNotification( |
49 hasSyncedResults, includeOtherFormsOfBrowsingHistory) { | 55 hasSyncedResults, includeOtherFormsOfBrowsingHistory) { |
50 // TODO(msramek): |hasSyncedResults| was used in the old WebUI to show | 56 // TODO(msramek): |hasSyncedResults| was used in the old WebUI to show |
51 // the message about other signed-in devices. This message does not exist | 57 // the message about other signed-in devices. This message does not exist |
52 // in the MD history anymore, so the parameter is not needed. Remove it | 58 // in the MD history anymore, so the parameter is not needed. Remove it |
53 // when WebUI is removed and this becomes the only client of | 59 // when WebUI is removed and this becomes the only client of |
54 // BrowsingHistoryHandler. | 60 // BrowsingHistoryHandler. |
55 var appElem = $('history-app'); | 61 waitForAppUpgrade().then(function() { |
56 waitForUpgrade(appElem).then(function() { | 62 /** @type {HistoryAppElement} */($('history-app')) |
57 /** @type {HistoryAppElement} */(appElem) | |
58 .getSideBar().showFooter = includeOtherFormsOfBrowsingHistory; | 63 .getSideBar().showFooter = includeOtherFormsOfBrowsingHistory; |
59 }); | 64 }); |
60 } | 65 } |
61 | 66 |
62 /** | 67 /** |
63 * Receives the synced history data. An empty list means that either there are | 68 * Receives the synced history data. An empty list means that either there are |
64 * no foreign sessions, or tab sync is disabled for this profile. | 69 * no foreign sessions, or tab sync is disabled for this profile. |
65 * |isTabSyncEnabled| makes it possible to distinguish between the cases. | 70 * |isTabSyncEnabled| makes it possible to distinguish between the cases. |
66 * | 71 * |
67 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the | 72 * @param {!Array<!ForeignSession>} sessionList Array of objects describing the |
68 * sessions from other devices. | 73 * sessions from other devices. |
69 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? | 74 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
70 */ | 75 */ |
71 function setForeignSessions(sessionList, isTabSyncEnabled) { | 76 function setForeignSessions(sessionList, isTabSyncEnabled) { |
72 var appElem = $('history-app'); | 77 waitForAppUpgrade().then(function() { |
73 waitForUpgrade(appElem).then(function() { | 78 /** @type {HistoryAppElement} */($('history-app')) |
74 /** @type {HistoryAppElement} */(appElem) | |
75 .setForeignSessions(sessionList, isTabSyncEnabled); | 79 .setForeignSessions(sessionList, isTabSyncEnabled); |
76 }); | 80 }); |
77 } | 81 } |
78 | 82 |
79 /** | 83 /** |
80 * Called when the history is deleted by someone else. | 84 * Called when the history is deleted by someone else. |
81 */ | 85 */ |
82 function historyDeleted() { | 86 function historyDeleted() { |
83 } | 87 } |
84 | 88 |
85 /** | 89 /** |
86 * Called by the history backend after user's sign in state changes. | 90 * Called by the history backend after user's sign in state changes. |
87 * @param {boolean} isUserSignedIn Whether user is signed in or not now. | 91 * @param {boolean} isUserSignedIn Whether user is signed in or not now. |
88 */ | 92 */ |
89 function updateSignInState(isUserSignedIn) { | 93 function updateSignInState(isUserSignedIn) { |
90 var appElem = $('history-app'); | 94 waitForAppUpgrade().then(function() { |
91 waitForUpgrade(appElem).then(function() { | 95 /** @type {HistoryAppElement} */($('history-app')) |
92 /** @type {HistoryAppElement} */(appElem) | |
93 .updateSignInState(isUserSignedIn); | 96 .updateSignInState(isUserSignedIn); |
94 }); | 97 }); |
95 } | 98 } |
OLD | NEW |