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

Side by Side Diff: chrome/browser/resources/ntp_android/ntp_android.js

Issue 10882024: Add webui handler for promotions on Android NTP. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Created 8 years, 3 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // File Description: 5 // File Description:
6 // Contains all the necessary functions for rendering the NTP on mobile 6 // Contains all the necessary functions for rendering the NTP on mobile
7 // devices. 7 // devices.
8 8
9 /** 9 /**
10 * The event type used to determine when a touch starts. 10 * The event type used to determine when a touch starts.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 * @type {boolean} 207 * @type {boolean}
208 */ 208 */
209 var hasRecentlyClosedTabs = false; 209 var hasRecentlyClosedTabs = false;
210 210
211 /** 211 /**
212 * Whether promo is not allowed or not (external to NTP). 212 * Whether promo is not allowed or not (external to NTP).
213 * @type {boolean} 213 * @type {boolean}
214 */ 214 */
215 var promoIsAllowed = false; 215 var promoIsAllowed = false;
216 216
217 /**
218 * Whether promo should be shown on Most Visited page (externally set).
219 * @type {boolean}
220 */
221 var promoIsAllowedOnMostVisited = false;
222
223 /**
224 * Whether promo should be shown on Open Tabs page (externally set).
225 * @type {boolean}
226 */
227 var promoIsAllowedOnOpenTabs = false;
228
229 /**
230 * Whether promo should show a virtual computer on Open Tabs (externally set).
231 * @type {boolean}
232 */
233 var promoIsAllowedAsVirtualComputer = false;
234
235 /**
236 * Promo-injected title of a virtual computer on an open tabs pane.
237 * @type {string}
238 */
239 var promoInjectedComputerTitleText = '';
240
241 /**
242 * Promo-injected last synced text of a virtual computer on an open tabs pane.
243 * @type {string}
244 */
245 var promoInjectedComputerLastSyncedText = '';
246
217 function setIncognitoMode(incognito) { 247 function setIncognitoMode(incognito) {
218 isIncognito = incognito; 248 isIncognito = incognito;
219 } 249 }
220 250
221 /** 251 /**
222 * The different sections that are displayed. 252 * The different sections that are displayed.
223 * @enum {number} 253 * @enum {number}
224 */ 254 */
225 var SectionType = { 255 var SectionType = {
226 BOOKMARKS: 0, 256 BOOKMARKS: 0,
227 INCOGNITO: 1, 257 INCOGNITO: 1,
228 MOST_VISITED: 2, 258 MOST_VISITED: 2,
229 RECENTLY_CLOSED: 3, 259 RECENTLY_CLOSED: 3,
230 SYNCED_DEVICES: 4, 260 SYNCED_DEVICES: 4,
231 FOREIGN_SESSION: 5, 261 FOREIGN_SESSION: 5,
232 FOREIGN_SESSION_HEADER: 6, 262 FOREIGN_SESSION_HEADER: 6,
233 SNAPSHOTS: 7, 263 SNAPSHOTS: 7,
264 PROMO_VC_SESSION_HEADER: 8,
234 UNKNOWN: 100, 265 UNKNOWN: 100,
235 }; 266 };
236 267
237 /** 268 /**
238 * The different ids used of our custom context menu. Sent to the ChromeView 269 * The different ids used of our custom context menu. Sent to the ChromeView
239 * and sent back when a menu is selected. 270 * and sent back when a menu is selected.
240 * @enum {number} 271 * @enum {number}
241 */ 272 */
242 var ContextMenuItemIds = { 273 var ContextMenuItemIds = {
243 BOOKMARK_EDIT: 0, 274 BOOKMARK_EDIT: 0,
244 BOOKMARK_DELETE: 1, 275 BOOKMARK_DELETE: 1,
245 BOOKMARK_OPEN_IN_NEW_TAB: 2, 276 BOOKMARK_OPEN_IN_NEW_TAB: 2,
246 BOOKMARK_OPEN_IN_INCOGNITO_TAB: 3, 277 BOOKMARK_OPEN_IN_INCOGNITO_TAB: 3,
247 BOOKMARK_SHORTCUT: 4, 278 BOOKMARK_SHORTCUT: 4,
248 279
249 MOST_VISITED_OPEN_IN_NEW_TAB: 10, 280 MOST_VISITED_OPEN_IN_NEW_TAB: 10,
250 MOST_VISITED_OPEN_IN_INCOGNITO_TAB: 11, 281 MOST_VISITED_OPEN_IN_INCOGNITO_TAB: 11,
251 MOST_VISITED_REMOVE: 12, 282 MOST_VISITED_REMOVE: 12,
252 283
253 RECENTLY_CLOSED_OPEN_IN_NEW_TAB: 20, 284 RECENTLY_CLOSED_OPEN_IN_NEW_TAB: 20,
254 RECENTLY_CLOSED_OPEN_IN_INCOGNITO_TAB: 21, 285 RECENTLY_CLOSED_OPEN_IN_INCOGNITO_TAB: 21,
255 RECENTLY_CLOSED_REMOVE: 22, 286 RECENTLY_CLOSED_REMOVE: 22,
256 287
257 FOREIGN_SESSIONS_REMOVE: 30, 288 FOREIGN_SESSIONS_REMOVE: 30,
289
290 PROMO_VC_SESSION_REMOVE: 40,
258 }; 291 };
259 292
260 /** 293 /**
261 * The URL of the element for the context menu. 294 * The URL of the element for the context menu.
262 * @type {string} 295 * @type {string}
263 */ 296 */
264 var contextMenuUrl = null; 297 var contextMenuUrl = null;
265 298
266 var contextMenuItem = null; 299 var contextMenuItem = null;
267 300
268 var currentSnapshots = null; 301 var currentSnapshots = null;
269 302
270 var currentSessions = null; 303 var currentSessions = null;
271 304
272 /** 305 /**
273 * The possible states of the sync section 306 * The possible states of the sync section
274 * @enum {number} 307 * @enum {number}
275 */ 308 */
276 var SyncState = { 309 var SyncState = {
277 INITIAL: 0, 310 INITIAL: 0,
278 WAITING_FOR_DATA: 1, 311 WAITING_FOR_DATA: 1,
279 DISPLAYING_LOADING: 2, 312 DISPLAYING_LOADING: 2,
280 DISPLAYED_LOADING: 3, 313 DISPLAYED_LOADING: 3,
281 LOADED: 3, 314 LOADED: 4,
282 }; 315 };
283 316
284 /** 317 /**
285 * The current state of the sync section. 318 * The current state of the sync section.
286 */ 319 */
287 var syncState = SyncState.INITIAL; 320 var syncState = SyncState.INITIAL;
288 321
289 /** 322 /**
290 * Whether or not sync is enabled. It will be undefined until 323 * Whether or not sync is enabled. It will be undefined until
291 * setSyncEnabled() is called. 324 * setSyncEnabled() is called.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // incognito NTPs have a bookmarks section. 424 // incognito NTPs have a bookmarks section.
392 if (getPaneIndexFromHash() < 0) 425 if (getPaneIndexFromHash() < 0)
393 document.location.hash = '#bookmarks'; 426 document.location.hash = '#bookmarks';
394 427
395 // Initialize common widgets. 428 // Initialize common widgets.
396 var titleScrollers = 429 var titleScrollers =
397 document.getElementsByClassName('section-title-wrapper'); 430 document.getElementsByClassName('section-title-wrapper');
398 for (var i = 0, len = titleScrollers.length; i < len; i++) 431 for (var i = 0, len = titleScrollers.length; i < len; i++)
399 initializeTitleScroller(titleScrollers[i]); 432 initializeTitleScroller(titleScrollers[i]);
400 433
434 // Initialize virtual computers for the sync promo.
435 createPromoVirtualComputers();
436
401 chrome.send('getMostVisited'); 437 chrome.send('getMostVisited');
402 chrome.send('getRecentlyClosedTabs'); 438 chrome.send('getRecentlyClosedTabs');
403 chrome.send('getForeignSessions'); 439 chrome.send('getForeignSessions');
404 chrome.send('getPromotions'); 440 chrome.send('getPromotions');
405 441
406 setCurrentBookmarkFolderData( 442 setCurrentBookmarkFolderData(
407 localStorage.getItem(DEFAULT_BOOKMARK_FOLDER_KEY)); 443 localStorage.getItem(DEFAULT_BOOKMARK_FOLDER_KEY));
408 444
409 addMainSection('incognito'); 445 addMainSection('incognito');
410 addMainSection('most_visited'); 446 addMainSection('most_visited');
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 856
821 var titleContainer = createElement('span', 'title'); 857 var titleContainer = createElement('span', 'title');
822 sessionOuterDiv.appendChild(titleContainer); 858 sessionOuterDiv.appendChild(titleContainer);
823 859
824 // Extra container to allow title & last-sync time to stack vertically. 860 // Extra container to allow title & last-sync time to stack vertically.
825 var sessionInnerDiv = createDiv(null); 861 var sessionInnerDiv = createDiv(null);
826 titleContainer.appendChild(sessionInnerDiv); 862 titleContainer.appendChild(sessionInnerDiv);
827 863
828 var title = createDiv('session-name'); 864 var title = createDiv('session-name');
829 title.textContent = item.title; 865 title.textContent = item.title;
866 if (item.titleId)
867 title.id = item.titleId;
Dan Beam 2012/08/25 00:48:20 nit: title.id = item.titleId || ''; (shorter and e
aruslan 2012/08/27 22:19:51 Done.
830 sessionInnerDiv.appendChild(title); 868 sessionInnerDiv.appendChild(title);
831 869
832 var lastSynced = createDiv('session-last-synced'); 870 var lastSynced = createDiv('session-last-synced');
833 lastSynced.textContent = 871 lastSynced.textContent =
834 templateData.opentabslastsynced + ': ' + item.userVisibleTimestamp; 872 templateData.opentabslastsynced + ': ' + item.userVisibleTimestamp;
873 if (item.userVisibleTimestampId)
874 lastSynced.id = item.userVisibleTimestampId;
835 sessionInnerDiv.appendChild(lastSynced); 875 sessionInnerDiv.appendChild(lastSynced);
836 876
837 sessionOuterDiv.addEventListener('click', function(evt) { 877 sessionOuterDiv.addEventListener('click', function(evt) {
838 var clickCallback = 878 var clickCallback =
839 opt_clickCallback ? opt_clickCallback : itemShortcutClickHandler; 879 opt_clickCallback ? opt_clickCallback : itemShortcutClickHandler;
840 clickCallback(item, evt); 880 clickCallback(item, evt);
841 }); 881 });
842 return sessionOuterDiv; 882 return sessionOuterDiv;
843 } 883 }
844 884
845 /** 885 /**
846 * Saves the number of most visited pages and updates promo visibility. 886 * Saves the number of most visited pages and updates promo visibility.
847 * @param {number} n Number of most visited pages. 887 * @param {number} n Number of most visited pages.
848 */ 888 */
849 function setNumberOfMostVisitedPages(n) { 889 function setNumberOfMostVisitedPages(n) {
850 numberOfMostVisitedPages = n; 890 numberOfMostVisitedPages = n;
851 promoSetVisibility(); 891 updatePromoVisibility();
852 } 892 }
853 893
854 /** 894 /**
855 * Saves the recently closed tabs flag and updates promo visibility. 895 * Saves the recently closed tabs flag and updates promo visibility.
856 * @param {boolean} anyTabs Whether there are any recently closed tabs. 896 * @param {boolean} anyTabs Whether there are any recently closed tabs.
857 */ 897 */
858 function setHasRecentlyClosedTabs(anyTabs) { 898 function setHasRecentlyClosedTabs(anyTabs) {
859 hasRecentlyClosedTabs = anyTabs; 899 hasRecentlyClosedTabs = anyTabs;
860 promoSetVisibility(); 900 updatePromoVisibility();
861 } 901 }
862 902
863 /** 903 /**
864 * Updates the most visited pages. 904 * Updates the most visited pages.
865 * 905 *
866 * @param {Array.<Object>} List of data for displaying the list of most 906 * @param {Array.<Object>} List of data for displaying the list of most
867 * visited pages (see C++ handler for model description). 907 * visited pages (see C++ handler for model description).
868 * @param {boolean} hasBlacklistedUrls Whether any blacklisted URLs are 908 * @param {boolean} hasBlacklistedUrls Whether any blacklisted URLs are
869 * present. 909 * present.
870 */ 910 */
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 1000
961 // update the shadows on the breadcrumb bar 1001 // update the shadows on the breadcrumb bar
962 computeDynamicLayout(); 1002 computeDynamicLayout();
963 } 1003 }
964 1004
965 /** 1005 /**
966 * Checks if promo is allowed and MostVisited requirements are satisfied. 1006 * Checks if promo is allowed and MostVisited requirements are satisfied.
967 * @return {boolean} Whether the promo should be shown on most_visited. 1007 * @return {boolean} Whether the promo should be shown on most_visited.
968 */ 1008 */
969 function shouldPromoBeShownOnMostVisited() { 1009 function shouldPromoBeShownOnMostVisited() {
970 return promoIsAllowed && 1010 return promoIsAllowed && promoIsAllowedOnMostVisited &&
971 (numberOfMostVisitedPages >= 2) && 1011 (numberOfMostVisitedPages >= 2) &&
972 (!hasRecentlyClosedTabs); 1012 (!hasRecentlyClosedTabs);
Dan Beam 2012/08/25 00:48:20 nit: the style guide says don't use extra (), thes
aruslan 2012/08/27 22:19:51 Done.
973 } 1013 }
974 1014
975 /** 1015 /**
976 * Checks if promo is allowed and OpenTabs requirements are satisfied. 1016 * Checks if promo is allowed and OpenTabs requirements are satisfied.
977 * @return {boolean} Whether the promo should be shown on open_tabs. 1017 * @return {boolean} Whether the promo should be shown on open_tabs.
978 */ 1018 */
979 function shouldPromoBeShownOnOpenTabs() { 1019 function shouldPromoBeShownOnOpenTabs() {
980 var snapshotsCount = 1020 var snapshotsCount =
981 currentSnapshots == null ? 0 : currentSnapshots.length; 1021 currentSnapshots == null ? 0 : currentSnapshots.length;
982 var sessionsCount = currentSessions == null ? 0 : currentSessions.length; 1022 var sessionsCount = currentSessions == null ? 0 : currentSessions.length;
983 return promoIsAllowed && 1023 return promoIsAllowed && promoIsAllowedOnOpenTabs &&
984 (snapshotsCount + sessionsCount != 0); 1024 (snapshotsCount + sessionsCount != 0);
985 } 1025 }
986 1026
987 /** 1027 /**
988 * Checks if promo is allowed and SyncPromo requirements are satisfied. 1028 * Checks if promo is allowed and SyncPromo requirements are satisfied.
989 * @return {boolean} Whether the promo should be shown on sync_promo. 1029 * @return {boolean} Whether the promo should be shown on sync_promo.
990 */ 1030 */
991 function shouldPromoBeShownOnSyncPromo() { 1031 function shouldPromoBeShownOnSync() {
992 var snapshotsCount = 1032 var snapshotsCount =
993 currentSnapshots == null ? 0 : currentSnapshots.length; 1033 currentSnapshots == null ? 0 : currentSnapshots.length;
994 var sessionsCount = currentSessions == null ? 0 : currentSessions.length; 1034 var sessionsCount = currentSessions == null ? 0 : currentSessions.length;
995 return promoIsAllowed && 1035 return promoIsAllowed && promoIsAllowedOnOpenTabs &&
996 (snapshotsCount + sessionsCount == 0); 1036 (snapshotsCount + sessionsCount == 0);
997 } 1037 }
998 1038
999 /** 1039 /**
1000 * Records a promo impression on a given section if necessary. 1040 * Records a promo impression on a given section if necessary.
1001 * @param {string} section Active section name to check. 1041 * @param {string} section Active section name to check.
1002 */ 1042 */
1003 function promoUpdateImpressions(section) { 1043 function promoUpdateImpressions(section) {
1004 if (section == 'most_visited' && shouldPromoBeShownOnMostVisited()) { 1044 if (section == 'most_visited' && shouldPromoBeShownOnMostVisited())
1005 chrome.send('recordImpression', ['most_visited']); 1045 chrome.send('recordImpression', ['most_visited']);
1006 } else if (section == 'open_tabs' && shouldPromoBeShownOnOpenTabs()) { 1046 else if (section == 'open_tabs' && shouldPromoBeShownOnOpenTabs())
1007 chrome.send('recordImpression', ['open_tabs']); 1047 chrome.send('recordImpression', ['open_tabs']);
1008 } else if (section == 'open_tabs' && shouldPromoBeShownOnSyncPromo()) { 1048 else if (section == 'open_tabs' && shouldPromoBeShownOnSync())
1009 chrome.send('recordImpression', ['sync_promo']); 1049 chrome.send('recordImpression', ['sync_promo']);
1010 }
1011 } 1050 }
1012 1051
1013 /** 1052 /**
1014 * Sets the visibility on all promo-related items as necessary. 1053 * Updates the visibility on all promo-related items as necessary.
1015 */ 1054 */
1016 function promoSetVisibility() { 1055 function updatePromoVisibility() {
1017 var mostVisited = $('promo_message_on_most_visited'); 1056 var mostVisitedEl = $('promo_message_on_most_visited');
1018 var openTabs = $('promo_message_on_open_tabs'); 1057 var openTabsVCEl = $('promo_vc_list');
1019 if (shouldPromoBeShownOnMostVisited()) { 1058 var syncPromoLegacyEl = $('promo_message_on_sync_promo_legacy');
1020 mostVisited.style.display = 'block'; 1059 var syncPromoReceivedEl = $('promo_message_on_sync_promo_received');
1021 } else { 1060 mostVisitedEl.style.display =
Dan Beam 2012/08/25 00:48:20 mostVisitedEl.hidden = !shouldPromoBeShownOnMostVi
aruslan 2012/08/27 22:19:51 The rest of the code uses style.display, and there
Dan Beam 2012/08/28 00:32:31 it's probably not intentional, either way it's fin
1022 mostVisited.style.display = 'none'; 1061 shouldPromoBeShownOnMostVisited() ? 'block' : 'none';
1023 } 1062 syncPromoReceivedEl.style.display =
1024 if (shouldPromoBeShownOnOpenTabs()) { 1063 shouldPromoBeShownOnSync() ? 'block' : 'none';
1025 openTabs.style.display = 'block'; 1064 syncPromoLegacyEl.style.display =
1026 } else { 1065 shouldPromoBeShownOnSync() ? 'none' : 'block';
1027 openTabs.style.display = 'none'; 1066 openTabsVCEl.style.display =
1028 } 1067 (shouldPromoBeShownOnOpenTabs() && promoIsAllowedAsVirtualComputer) ?
1068 'block' : 'none';
1029 } 1069 }
1030 1070
1031 /** 1071 /**
1072 * Called from native.
1073 * Clears the promotion.
1074 */
1075 function clearPromotions() {
1076 setPromotions({});
1077 }
1078
1079 /**
1032 * Called from native. 1080 * Called from native.
1033 * Sets the text for all promo-related items, updates 1081 * Sets the text for all promo-related items, updates
1034 * promo-send-email-target items to send email on click and 1082 * promo-send-email-target items to send email on click and
1035 * updates the visibility of items. 1083 * updates the visibility of items.
1036 * @param {Object} promotions Dictionary used to fill-in the text. 1084 * @param {Object} promotions Dictionary used to fill-in the text.
1037 */ 1085 */
1038 function setPromotions(promotions) { 1086 function setPromotions(promotions) {
1039 var mostVisited = $('promo_message_on_most_visited'); 1087 var mostVisitedEl = $('promo_message_on_most_visited');
1040 var openTabs = $('promo_message_on_open_tabs'); 1088 var openTabsEl = $('promo_message_on_open_tabs');
1041 var syncPromoLegacy = $('promo_message_on_sync_promo_legacy'); 1089 var syncPromoReceivedEl = $('promo_message_on_sync_promo_received');
1042 mostVisited.innerHTML = promotions['promoMessage']; 1090
1043 openTabs.innerHTML = promotions['promoMessage'];
1044 if (promotions['promoMessageLong']) {
1045 syncPromoLegacy.innerHTML = promotions['promoMessageLong'];
1046 }
1047 promoIsAllowed = promotions['promoIsAllowed'] === true; 1091 promoIsAllowed = promotions['promoIsAllowed'] === true;
Dan Beam 2012/08/25 00:48:20 you should use . notation instead of [''] notation
aruslan 2012/08/27 22:19:51 Done.
1092 promoIsAllowedOnMostVisited =
1093 promotions['promoIsAllowedOnMostVisited'] === true;
1094 promoIsAllowedOnOpenTabs = promotions['promoIsAllowedOnOpenTabs'] === true;
1095 promoIsAllowedAsVirtualComputer = promotions['promoIsAllowedAsVC'] === true;
1096
1097 mostVisitedEl.innerHTML = promotions['promoMessage'] || '';
Dan Beam 2012/08/25 00:48:20 this is bad if there's a <script> in the message,
aruslan 2012/08/27 22:19:51 Done.
1098 if (openTabsEl)
1099 openTabsEl.innerHTML = promotions['promoMessage'] || '';
1100 syncPromoReceivedEl.innerHTML = promotions['promoMessageLong'] || '';
1101
1102 promoInjectedComputerTitleText = promotions['promoVCTitle'] || '';
1103 promoInjectedComputerLastSyncedText = promotions['promoVCLastSynced'] || '';
1104 var openTabsVCTitleEl = $('promo_vc_title');
1105 if (openTabsVCTitleEl)
1106 openTabsVCTitleEl.textContent = promoInjectedComputerTitleText;
1107 var openTabsVCLastSyncEl = $('promo_vc_lastsync');
1108 if (openTabsVCLastSyncEl)
1109 openTabsVCLastSyncEl.textContent = promoInjectedComputerLastSyncedText;
1110
1048 if (promoIsAllowed) { 1111 if (promoIsAllowed) {
1049 var promoTargets = 1112 var promoButtonEls =
1050 document.getElementsByClassName('promo-action-target'); 1113 document.getElementsByClassName('promo-button');
1051 for (var i = 0, len = promoTargets.length; i < len; i++) { 1114 for (var i = 0, len = promoButtonEls.length; i < len; i++) {
1052 promoTargets[i].href = 'javascript:void(0)'; 1115 promoButtonEls[i].href = 'javascript:void(0)';
Dan Beam 2012/08/25 00:48:20 hmm, why is this necessary? why not just '#' and d
aruslan 2012/08/27 22:19:51 Done -- thanks!
1053 promoTargets[i].onclick = promoAction; 1116 promoButtonEls[i].onclick = executePromoAction;
1117 addActiveTouchListener(promoButtonEls[i], 'promo-button-active');
1054 } 1118 }
1055 } 1119 }
1056 promoSetVisibility(); 1120 updatePromoVisibility();
1057 } 1121 }
1058 1122
1059 /** 1123 /**
1060 * On-click handler for promo email targets. 1124 * On-click handler for promo email targets.
1061 * Performs the promo action "send email". 1125 * Performs the promo action "send email".
1062 * @param {Object} evt User interface event that triggered the action. 1126 * @param {Object} evt User interface event that triggered the action.
1063 */ 1127 */
1064 function promoAction(evt) { 1128 function executePromoAction(evt) {
1065 if (evt.preventDefault) 1129 if (evt.preventDefault)
1066 evt.preventDefault(); 1130 evt.preventDefault();
1067 evt.returnValue = false; 1131 evt.returnValue = false;
1068 chrome.send('promoActionTriggered'); 1132 chrome.send('promoActionTriggered');
1069 } 1133 }
1070 1134
1071 /** 1135 /**
1072 * Called by the browser when a context menu has been selected. 1136 * Called by the browser when a context menu has been selected.
1073 * 1137 *
1074 * @param {number} itemId The id of the item that was selected, as specified 1138 * @param {number} itemId The id of the item that was selected, as specified
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 break; 1179 break;
1116 1180
1117 case ContextMenuItemIds.FOREIGN_SESSIONS_REMOVE: 1181 case ContextMenuItemIds.FOREIGN_SESSIONS_REMOVE:
1118 if (contextMenuItem != null) { 1182 if (contextMenuItem != null) {
1119 chrome.send( 1183 chrome.send(
1120 'deleteForeignSession', [contextMenuItem.sessionTag]); 1184 'deleteForeignSession', [contextMenuItem.sessionTag]);
1121 chrome.send('getForeignSessions'); 1185 chrome.send('getForeignSessions');
1122 } 1186 }
1123 break; 1187 break;
1124 1188
1189 case ContextMenuItemIds.PROMO_VC_SESSION_REMOVE:
1190 chrome.send('promoDisabled');
1191 break;
1192
1125 default: 1193 default:
1126 log.error('Unknown context menu selected id=' + itemId); 1194 log.error('Unknown context menu selected id=' + itemId);
1127 break; 1195 break;
1128 } 1196 }
1129 } 1197 }
1130 1198
1131 /** 1199 /**
1132 * Generates the full bookmark folder hierarchy and populates the scrollable 1200 * Generates the full bookmark folder hierarchy and populates the scrollable
1133 * title element. 1201 * title element.
1134 * 1202 *
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 syncEnabled = enabled; 1410 syncEnabled = enabled;
1343 1411
1344 if (enabled) { 1412 if (enabled) {
1345 if (!localStorage.getItem(SYNC_ENABLED_KEY)) { 1413 if (!localStorage.getItem(SYNC_ENABLED_KEY)) {
1346 localStorage.setItem(SYNC_ENABLED_KEY, 'true'); 1414 localStorage.setItem(SYNC_ENABLED_KEY, 'true');
1347 setCurrentBookmarkFolderData('0'); 1415 setCurrentBookmarkFolderData('0');
1348 } 1416 }
1349 } else { 1417 } else {
1350 localStorage.removeItem(SYNC_ENABLED_KEY); 1418 localStorage.removeItem(SYNC_ENABLED_KEY);
1351 } 1419 }
1420 updatePromoVisibility();
1352 1421
1353 if (bookmarkData) { 1422 if (bookmarkData) {
1354 // Bookmark data can now be displayed (or needs to be refiltered) 1423 // Bookmark data can now be displayed (or needs to be refiltered)
1355 bookmarks(bookmarkData); 1424 bookmarks(bookmarkData);
1356 } 1425 }
1357 1426
1358 updateSyncEmptyState(); 1427 updateSyncEmptyState();
1359 } catch (e) {} 1428 } catch (e) {}
1360 } 1429 }
1361 1430
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 if (!syncEnabled) { 1490 if (!syncEnabled) {
1422 syncEnableSync.style.display = '-webkit-box'; 1491 syncEnableSync.style.display = '-webkit-box';
1423 centerEmptySections(syncEnableSync); 1492 centerEmptySections(syncEnableSync);
1424 } else if (sessionsCount + snapshotsCount == 0) { 1493 } else if (sessionsCount + snapshotsCount == 0) {
1425 syncPromo.style.display = '-webkit-box'; 1494 syncPromo.style.display = '-webkit-box';
1426 centerEmptySections(syncPromo); 1495 centerEmptySections(syncPromo);
1427 } else { 1496 } else {
1428 openTabsList.style.display = sessionsCount == 0 ? 'none' : 'block'; 1497 openTabsList.style.display = sessionsCount == 0 ? 'none' : 'block';
1429 snapshotsList.style.display = snapshotsCount == 0 ? 'none' : 'block'; 1498 snapshotsList.style.display = snapshotsCount == 0 ? 'none' : 'block';
1430 } 1499 }
1431 promoSetVisibility(); 1500 updatePromoVisibility();
1432 } 1501 }
1433 1502
1434 /** 1503 /**
1435 * Called externally when updated snapshot data is available. 1504 * Called externally when updated snapshot data is available.
1436 * 1505 *
1437 * @param {Object} data The snapshot data 1506 * @param {Object} data The snapshot data
1438 */ 1507 */
1439 function snapshots(data) { 1508 function snapshots(data) {
1440 var list = findList('snapshots'); 1509 var list = findList('snapshots');
1441 list.innerHTML = ''; 1510 list.innerHTML = '';
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 }, 0); 1601 }, 0);
1533 expando.className = 'expando closed'; 1602 expando.className = 'expando closed';
1534 } else { 1603 } else {
1535 element.style.height = element.expandedHeight; 1604 element.style.height = element.expandedHeight;
1536 expando.className = 'expando open'; 1605 expando.className = 'expando open';
1537 } 1606 }
1538 } 1607 }
1539 } 1608 }
1540 1609
1541 /** 1610 /**
1611 * Initializes the promo_vc_list div to look like a foreign session
1612 * with a desktop.
1613 */
1614 function createPromoVirtualComputers() {
1615 var list = findList('promo_vc');
Dan Beam 2012/08/25 00:48:20 I'm scared of code without newlines :(
aruslan 2012/08/27 22:19:51 Done.
1616 list.innerHTML = '';
1617 var sessionEl = createDiv();
1618 list.appendChild(sessionEl);
1619 var sessionHeader = createDiv('session-header');
1620 sessionEl.appendChild(sessionHeader);
1621 var sessionChildren = createDiv('session-children-container');
1622 var promoMessage = createDiv('promo-message');
1623 promoMessage.id = 'promo_message_on_open_tabs';
1624 sessionChildren.appendChild(promoMessage);
1625 sessionEl.appendChild(sessionChildren);
1626 var expando = createDiv();
1627 var expandoFunction = createExpandoFunction(expando, sessionChildren);
1628
1629 var headerList = [{
1630 'title': promoInjectedComputerTitleText,
1631 'titleId': 'promo_vc_title',
1632 'userVisibleTimestamp': promoInjectedComputerLastSyncedText,
1633 'userVisibleTimestampId': 'promo_vc_lastsync',
1634 'iconStyle': 'laptop'
1635 }];
1636
1637 populateData(sessionHeader, SectionType.PROMO_VC_SESSION_HEADER, headerList,
1638 makeForeignSessionListEntry, expandoFunction);
1639 sessionHeader.appendChild(expando);
1640 }
1641
1642 /**
1542 * Called externally when updated synced sessions data is available. 1643 * Called externally when updated synced sessions data is available.
1543 * 1644 *
1544 * @param {Object} data The snapshot data 1645 * @param {Object} data The snapshot data
1545 */ 1646 */
1546 function setForeignSessions(data, tabSyncEnabled) { 1647 function setForeignSessions(data, tabSyncEnabled) {
1547 var list = findList('open_tabs'); 1648 var list = findList('open_tabs');
1548 list.innerHTML = ''; 1649 list.innerHTML = '';
1549 1650
1550 currentSessions = data; 1651 currentSessions = data;
1551 updateSyncEmptyState(); 1652 updateSyncEmptyState();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 function getSectionTypeString(section) { 1848 function getSectionTypeString(section) {
1748 switch (section) { 1849 switch (section) {
1749 case SectionType.BOOKMARKS: 1850 case SectionType.BOOKMARKS:
1750 return 'bookmarks'; 1851 return 'bookmarks';
1751 case SectionType.MOST_VISITED: 1852 case SectionType.MOST_VISITED:
1752 return 'most_visited'; 1853 return 'most_visited';
1753 case SectionType.RECENTLY_CLOSED: 1854 case SectionType.RECENTLY_CLOSED:
1754 return 'recently_closed'; 1855 return 'recently_closed';
1755 case SectionType.SYNCED_DEVICES: 1856 case SectionType.SYNCED_DEVICES:
1756 return 'synced_devices'; 1857 return 'synced_devices';
1858 case SectionType.PROMO_VC_SESSION_HEADER:
Dan Beam 2012/08/25 00:48:20 I'm slightly confused by this, why can't this just
aruslan 2012/08/27 22:19:51 Done -- as this is not an enum, changed it to be s
1859 return 'promo_vc_session_header';
1757 case SectionType.UNKNOWN: 1860 case SectionType.UNKNOWN:
1758 default: 1861 default:
1759 return 'unknown'; 1862 return 'unknown';
1760 } 1863 }
1761 } 1864 }
1762 1865
1763 /** 1866 /**
1764 * Render the given data into the given list, and hide or show the entire 1867 * Render the given data into the given list, and hide or show the entire
1765 * container based on whether there are any elements. The decorator function 1868 * container based on whether there are any elements. The decorator function
1766 * is used to create the element to be inserted based on the given data 1869 * is used to create the element to be inserted based on the given data
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 [ContextMenuItemIds.RECENTLY_CLOSED_OPEN_IN_INCOGNITO_TAB, 2424 [ContextMenuItemIds.RECENTLY_CLOSED_OPEN_IN_INCOGNITO_TAB,
2322 templateData.elementopeninincognitotab], 2425 templateData.elementopeninincognitotab],
2323 [ContextMenuItemIds.RECENTLY_CLOSED_REMOVE, 2426 [ContextMenuItemIds.RECENTLY_CLOSED_REMOVE,
2324 templateData.elementremove] 2427 templateData.elementremove]
2325 ]); 2428 ]);
2326 } else if (section == SectionType.FOREIGN_SESSION_HEADER) { 2429 } else if (section == SectionType.FOREIGN_SESSION_HEADER) {
2327 chrome.send('showContextMenu', [ 2430 chrome.send('showContextMenu', [
2328 [ContextMenuItemIds.FOREIGN_SESSIONS_REMOVE, 2431 [ContextMenuItemIds.FOREIGN_SESSIONS_REMOVE,
2329 templateData.elementremove] 2432 templateData.elementremove]
2330 ]); 2433 ]);
2434 } else if (section == SectionType.PROMO_VC_SESSION_HEADER) {
2435 chrome.send('showContextMenu', [
Dan Beam 2012/08/25 00:48:20 this is super repetitive, why not do something lik
aruslan 2012/08/27 22:19:51 Done.
2436 [ContextMenuItemIds.PROMO_VC_SESSION_REMOVE,
2437 templateData.elementremove]
2438 ]);
2331 } 2439 }
2332 return false; 2440 return false;
2333 } 2441 }
2334 2442
2335 // Return an object with all the exports 2443 // Return an object with all the exports
2336 return { 2444 return {
2337 bookmarks: bookmarks, 2445 bookmarks: bookmarks,
2338 bookmarkChanged: bookmarkChanged, 2446 bookmarkChanged: bookmarkChanged,
2339 setForeignSessions: setForeignSessions, 2447 clearPromotions: clearPromotions,
2340 init: init, 2448 init: init,
2341 onCustomMenuSelected: onCustomMenuSelected, 2449 onCustomMenuSelected: onCustomMenuSelected,
2342 openSection: openSection, 2450 openSection: openSection,
2343 setFaviconDominantColor: setFaviconDominantColor, 2451 setFaviconDominantColor: setFaviconDominantColor,
2452 setForeignSessions: setForeignSessions,
2344 setIncognitoMode: setIncognitoMode, 2453 setIncognitoMode: setIncognitoMode,
2345 setMostVisitedPages: setMostVisitedPages, 2454 setMostVisitedPages: setMostVisitedPages,
2346 setPromotions: setPromotions, 2455 setPromotions: setPromotions,
2347 setRecentlyClosedTabs: setRecentlyClosedTabs, 2456 setRecentlyClosedTabs: setRecentlyClosedTabs,
2348 setSyncEnabled: setSyncEnabled, 2457 setSyncEnabled: setSyncEnabled,
2349 snapshots: snapshots 2458 snapshots: snapshots
2350 }; 2459 };
2351 }); 2460 });
2352 2461
2353 ///////////////////////////////////////////////////////////////////////////// 2462 /////////////////////////////////////////////////////////////////////////////
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2479 // NTP Entry point. 2588 // NTP Entry point.
2480 ///////////////////////////////////////////////////////////////////////////// 2589 /////////////////////////////////////////////////////////////////////////////
2481 2590
2482 /* 2591 /*
2483 * Handles initializing the UI when the page has finished loading. 2592 * Handles initializing the UI when the page has finished loading.
2484 */ 2593 */
2485 window.addEventListener('DOMContentLoaded', function(evt) { 2594 window.addEventListener('DOMContentLoaded', function(evt) {
2486 ntp.init(); 2595 ntp.init();
2487 $('content-area').style.display = 'block'; 2596 $('content-area').style.display = 'block';
2488 }); 2597 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698