| 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 /** | 5 /** |
| 6 * @typedef {{device: string, | 6 * @typedef {{device: string, |
| 7 * lastUpdateTime: string, | 7 * lastUpdateTime: string, |
| 8 * separatorIndexes: !Array<number>, | 8 * separatorIndexes: !Array<number>, |
| 9 * timestamp: number, | 9 * timestamp: number, |
| 10 * tabs: !Array<!ForeignSessionTab>, | 10 * tabs: !Array<!ForeignSessionTab>, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 value: loadTimeData.getBoolean('isGuestSession'), | 50 value: loadTimeData.getBoolean('isGuestSession'), |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 /** @private */ | 53 /** @private */ |
| 54 fetchingSyncedTabs_: { | 54 fetchingSyncedTabs_: { |
| 55 type: Boolean, | 55 type: Boolean, |
| 56 value: false, | 56 value: false, |
| 57 } | 57 } |
| 58 }, | 58 }, |
| 59 | 59 |
| 60 listeners: { |
| 61 'toggle-menu': 'onToggleMenu_', |
| 62 }, |
| 63 |
| 60 /** @override */ | 64 /** @override */ |
| 61 attached: function() { | 65 attached: function() { |
| 62 // Update the sign in state. | 66 // Update the sign in state. |
| 63 chrome.send('otherDevicesInitialized'); | 67 chrome.send('otherDevicesInitialized'); |
| 64 }, | 68 }, |
| 65 | 69 |
| 66 /** | 70 /** |
| 67 * @param {!ForeignSession} session | 71 * @param {!ForeignSession} session |
| 68 * @return {!ForeignDeviceInternal} | 72 * @return {!ForeignDeviceInternal} |
| 69 */ | 73 */ |
| 70 createInternalDevice_: function(session) { | 74 createInternalDevice_: function(session) { |
| 71 var tabs = []; | 75 var tabs = []; |
| 72 var separatorIndexes = []; | 76 var separatorIndexes = []; |
| 73 for (var i = 0; i < session.windows.length; i++) { | 77 for (var i = 0; i < session.windows.length; i++) { |
| 74 var windowId = session.windows[i].sessionId; | 78 var windowId = session.windows[i].sessionId; |
| 75 var newTabs = session.windows[i].tabs; | 79 var newTabs = session.windows[i].tabs; |
| 76 if (newTabs.length == 0) | 80 if (newTabs.length == 0) |
| 77 continue; | 81 continue; |
| 78 | 82 |
| 79 newTabs.forEach(function(tab) { | 83 newTabs.forEach(function(tab) { |
| 80 tab.windowId = windowId; | 84 tab.windowId = windowId; |
| 81 }); | 85 }); |
| 82 | 86 |
| 87 var windowAdded = false; |
| 83 if (!this.searchTerm) { | 88 if (!this.searchTerm) { |
| 84 // Add all the tabs if there is no search term. | 89 // Add all the tabs if there is no search term. |
| 85 tabs = tabs.concat(newTabs); | 90 tabs = tabs.concat(newTabs); |
| 86 separatorIndexes.push(tabs.length - 1); | 91 windowAdded = true; |
| 87 } else { | 92 } else { |
| 88 var searchText = this.searchTerm.toLowerCase(); | 93 var searchText = this.searchTerm.toLowerCase(); |
| 89 var windowAdded = false; | |
| 90 for (var j = 0; j < newTabs.length; j++) { | 94 for (var j = 0; j < newTabs.length; j++) { |
| 91 var tab = newTabs[j]; | 95 var tab = newTabs[j]; |
| 92 if (tab.title.toLowerCase().indexOf(searchText) != -1) { | 96 if (tab.title.toLowerCase().indexOf(searchText) != -1) { |
| 93 tabs.push(tab); | 97 tabs.push(tab); |
| 94 windowAdded = true; | 98 windowAdded = true; |
| 95 } | 99 } |
| 96 } | 100 } |
| 97 if (windowAdded) | |
| 98 separatorIndexes.push(tabs.length - 1); | |
| 99 } | 101 } |
| 100 | 102 if (windowAdded && i != session.windows.length - 1) |
| 103 separatorIndexes.push(tabs.length - 1); |
| 101 } | 104 } |
| 102 return { | 105 return { |
| 103 device: session.name, | 106 device: session.name, |
| 104 lastUpdateTime: '– ' + session.modifiedTime, | 107 lastUpdateTime: '– ' + session.modifiedTime, |
| 105 separatorIndexes: separatorIndexes, | 108 separatorIndexes: separatorIndexes, |
| 106 timestamp: session.timestamp, | 109 timestamp: session.timestamp, |
| 107 tabs: tabs, | 110 tabs: tabs, |
| 108 tag: session.tag, | 111 tag: session.tag, |
| 109 }; | 112 }; |
| 110 }, | 113 }, |
| 111 | 114 |
| 112 | |
| 113 onSignInTap_: function() { | 115 onSignInTap_: function() { |
| 114 chrome.send('SyncSetupShowSetupUI'); | 116 chrome.send('SyncSetupShowSetupUI'); |
| 115 chrome.send('SyncSetupStartSignIn', [false]); | 117 chrome.send('SyncSetupStartSignIn', [false]); |
| 116 }, | 118 }, |
| 117 | 119 |
| 120 onToggleMenu_: function(e) { |
| 121 this.$.menu.toggleMenu(e.detail.target, e.detail.tag); |
| 122 }, |
| 123 |
| 124 onOpenAllTap_: function() { |
| 125 md_history.BrowserService.getInstance().openForeignSessionAllTabs( |
| 126 this.$.menu.itemData); |
| 127 this.$.menu.closeMenu(); |
| 128 }, |
| 129 |
| 130 onDeleteSessionTap_: function() { |
| 131 md_history.BrowserService.getInstance().deleteForeignSession( |
| 132 this.$.menu.itemData); |
| 133 this.$.menu.closeMenu(); |
| 134 }, |
| 135 |
| 118 /** @private */ | 136 /** @private */ |
| 119 clearDisplayedSyncedDevices_: function() { | 137 clearDisplayedSyncedDevices_: function() { |
| 120 this.syncedDevices_ = []; | 138 this.syncedDevices_ = []; |
| 121 }, | 139 }, |
| 122 | 140 |
| 123 /** | 141 /** |
| 124 * Decide whether or not should display no synced tabs message. | 142 * Decide whether or not should display no synced tabs message. |
| 125 * @param {boolean} signInState | 143 * @param {boolean} signInState |
| 126 * @param {number} syncedDevicesLength | 144 * @param {number} syncedDevicesLength |
| 127 * @param {boolean} guestSession | 145 * @param {boolean} guestSession |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // User signed in, show the loading message when querying for synced | 228 // User signed in, show the loading message when querying for synced |
| 211 // devices. | 229 // devices. |
| 212 this.fetchingSyncedTabs_ = true; | 230 this.fetchingSyncedTabs_ = true; |
| 213 }, | 231 }, |
| 214 | 232 |
| 215 searchTermChanged: function(searchTerm) { | 233 searchTermChanged: function(searchTerm) { |
| 216 this.clearDisplayedSyncedDevices_(); | 234 this.clearDisplayedSyncedDevices_(); |
| 217 this.updateSyncedDevices(this.sessionList); | 235 this.updateSyncedDevices(this.sessionList); |
| 218 } | 236 } |
| 219 }); | 237 }); |
| OLD | NEW |