| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 6 /** |
| 7 * @fileoverview The local InstantExtended NTP. | 7 * @fileoverview The local InstantExtended NTP. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Controls rendering the new tab page for InstantExtended. | 11 * Controls rendering the new tab page for InstantExtended. |
| 12 * @param {Object} location window.location or a mock. | |
| 13 * @return {Object} A limited interface for testing the local NTP. | 12 * @return {Object} A limited interface for testing the local NTP. |
| 14 */ | 13 */ |
| 15 function LocalNTP(location) { | 14 function LocalNTP() { |
| 16 <include src="../../../../ui/webui/resources/js/assert.js"> | 15 <include src="../../../../ui/webui/resources/js/assert.js"> |
| 17 | 16 |
| 18 | 17 |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * Enum for classnames. | 20 * Enum for classnames. |
| 22 * @enum {string} | 21 * @enum {string} |
| 23 * @const | 22 * @const |
| 24 */ | 23 */ |
| 25 var CLASSES = { | 24 var CLASSES = { |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 564 |
| 566 // A mask to darken the thumbnail on focus. | 565 // A mask to darken the thumbnail on focus. |
| 567 var maskElement = createAndAppendElement( | 566 var maskElement = createAndAppendElement( |
| 568 tileElement, 'div', CLASSES.THUMBNAIL_MASK); | 567 tileElement, 'div', CLASSES.THUMBNAIL_MASK); |
| 569 | 568 |
| 570 // The button used to blacklist this page. | 569 // The button used to blacklist this page. |
| 571 var blacklistButton = createAndAppendElement( | 570 var blacklistButton = createAndAppendElement( |
| 572 tileElement, 'div', CLASSES.BLACKLIST_BUTTON); | 571 tileElement, 'div', CLASSES.BLACKLIST_BUTTON); |
| 573 var blacklistFunction = generateBlacklistFunction(rid); | 572 var blacklistFunction = generateBlacklistFunction(rid); |
| 574 blacklistButton.addEventListener('click', blacklistFunction); | 573 blacklistButton.addEventListener('click', blacklistFunction); |
| 575 blacklistButton.title = templateData.removeThumbnailTooltip; | 574 blacklistButton.title = configData.translatedStrings.removeThumbnailTooltip; |
| 576 | 575 |
| 577 // When a tile is focused, have delete also blacklist the page. | 576 // When a tile is focused, have delete also blacklist the page. |
| 578 registerKeyHandler(tileElement, KEYCODE.DELETE, blacklistFunction); | 577 registerKeyHandler(tileElement, KEYCODE.DELETE, blacklistFunction); |
| 579 | 578 |
| 580 // The page favicon, if any. | 579 // The page favicon, if any. |
| 581 var faviconUrl = page.faviconUrl; | 580 var faviconUrl = page.faviconUrl; |
| 582 if (faviconUrl) { | 581 if (faviconUrl) { |
| 583 var favicon = createAndAppendElement( | 582 var favicon = createAndAppendElement( |
| 584 tileElement, 'div', CLASSES.FAVICON); | 583 tileElement, 'div', CLASSES.FAVICON); |
| 585 favicon.style.backgroundImage = 'url(' + faviconUrl + ')'; | 584 favicon.style.backgroundImage = 'url(' + faviconUrl + ')'; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 * @return {Object} the handle to the embeddedSearch API. | 875 * @return {Object} the handle to the embeddedSearch API. |
| 877 */ | 876 */ |
| 878 function getEmbeddedSearchApiHandle() { | 877 function getEmbeddedSearchApiHandle() { |
| 879 if (window.cideb) | 878 if (window.cideb) |
| 880 return window.cideb; | 879 return window.cideb; |
| 881 if (window.chrome && window.chrome.embeddedSearch) | 880 if (window.chrome && window.chrome.embeddedSearch) |
| 882 return window.chrome.embeddedSearch; | 881 return window.chrome.embeddedSearch; |
| 883 return null; | 882 return null; |
| 884 } | 883 } |
| 885 | 884 |
| 886 | |
| 887 /** | |
| 888 * @return {boolean} True if this is a Google page and not some other search | |
| 889 * provider. Used to determine whether to show the logo and fakebox. | |
| 890 */ | |
| 891 function isGooglePage() { | |
| 892 return location.href.indexOf('isGoogle') != -1; | |
| 893 } | |
| 894 | |
| 895 | |
| 896 /** | 885 /** |
| 897 * Extract the desired navigation behavior from a click button. | 886 * Extract the desired navigation behavior from a click button. |
| 898 * @param {number} button The Event#button property of a click event. | 887 * @param {number} button The Event#button property of a click event. |
| 899 * @return {WindowOpenDisposition} The desired behavior for | 888 * @return {WindowOpenDisposition} The desired behavior for |
| 900 * navigateContentWindow. | 889 * navigateContentWindow. |
| 901 */ | 890 */ |
| 902 function getDispositionFromClickButton(button) { | 891 function getDispositionFromClickButton(button) { |
| 903 if (button == MIDDLE_MOUSE_BUTTON) | 892 if (button == MIDDLE_MOUSE_BUTTON) |
| 904 return WindowOpenDisposition.NEW_BACKGROUND_TAB; | 893 return WindowOpenDisposition.NEW_BACKGROUND_TAB; |
| 905 return WindowOpenDisposition.CURRENT_TAB; | 894 return WindowOpenDisposition.CURRENT_TAB; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 916 notification = $(IDS.NOTIFICATION); | 905 notification = $(IDS.NOTIFICATION); |
| 917 attribution = $(IDS.ATTRIBUTION); | 906 attribution = $(IDS.ATTRIBUTION); |
| 918 ntpContents = $(IDS.NTP_CONTENTS); | 907 ntpContents = $(IDS.NTP_CONTENTS); |
| 919 | 908 |
| 920 for (var i = 0; i < NUM_ROWS; i++) { | 909 for (var i = 0; i < NUM_ROWS; i++) { |
| 921 var row = document.createElement('div'); | 910 var row = document.createElement('div'); |
| 922 row.classList.add(CLASSES.ROW); | 911 row.classList.add(CLASSES.ROW); |
| 923 tilesContainer.appendChild(row); | 912 tilesContainer.appendChild(row); |
| 924 } | 913 } |
| 925 | 914 |
| 926 if (isGooglePage()) { | 915 if (configData.isGooglePage) { |
| 927 var logo = document.createElement('div'); | 916 var logo = document.createElement('div'); |
| 928 logo.id = IDS.LOGO; | 917 logo.id = IDS.LOGO; |
| 929 | 918 |
| 930 fakebox = document.createElement('div'); | 919 fakebox = document.createElement('div'); |
| 931 fakebox.id = IDS.FAKEBOX; | 920 fakebox.id = IDS.FAKEBOX; |
| 932 fakebox.innerHTML = | 921 fakebox.innerHTML = |
| 933 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + | 922 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + |
| 934 '<div id=cursor></div>'; | 923 '<div id=cursor></div>'; |
| 935 | 924 |
| 936 ntpContents.insertBefore(fakebox, ntpContents.firstChild); | 925 ntpContents.insertBefore(fakebox, ntpContents.firstChild); |
| 937 ntpContents.insertBefore(logo, ntpContents.firstChild); | 926 ntpContents.insertBefore(logo, ntpContents.firstChild); |
| 938 } else { | 927 } else { |
| 939 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); | 928 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); |
| 940 } | 929 } |
| 941 | 930 |
| 942 var recentTabsText = templateData.recentTabs; | 931 var recentTabsText = configData.translatedStrings.recentTabs; |
| 943 if (recentTabsText) { | 932 if (recentTabsText) { |
| 944 var recentTabsLink = document.createElement('span'); | 933 var recentTabsLink = document.createElement('span'); |
| 945 recentTabsLink.id = IDS.RECENT_TABS; | 934 recentTabsLink.id = IDS.RECENT_TABS; |
| 946 recentTabsLink.addEventListener('click', function(event) { | 935 recentTabsLink.addEventListener('click', function(event) { |
| 947 ntpApiHandle.navigateContentWindow( | 936 ntpApiHandle.navigateContentWindow( |
| 948 'chrome://history', getDispositionFromClickButton(event.button)); | 937 'chrome://history', getDispositionFromClickButton(event.button)); |
| 949 }); | 938 }); |
| 950 recentTabsLink.textContent = recentTabsText; | 939 recentTabsLink.textContent = recentTabsText; |
| 951 ntpContents.appendChild(recentTabsLink); | 940 ntpContents.appendChild(recentTabsLink); |
| 952 // Move the attribution up to prevent it from overlapping. | 941 // Move the attribution up to prevent it from overlapping. |
| 953 attribution.style.bottom = '28px'; | 942 attribution.style.bottom = '28px'; |
| 954 } | 943 } |
| 955 | 944 |
| 956 var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); | 945 var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); |
| 957 notificationMessage.textContent = templateData.thumbnailRemovedNotification; | 946 notificationMessage.textContent = |
| 947 configData.translatedStrings.thumbnailRemovedNotification; |
| 958 var undoLink = $(IDS.UNDO_LINK); | 948 var undoLink = $(IDS.UNDO_LINK); |
| 959 undoLink.addEventListener('click', onUndo); | 949 undoLink.addEventListener('click', onUndo); |
| 960 registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); | 950 registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); |
| 961 undoLink.textContent = templateData.undoThumbnailRemove; | 951 undoLink.textContent = configData.translatedStrings.undoThumbnailRemove; |
| 962 var restoreAllLink = $(IDS.RESTORE_ALL_LINK); | 952 var restoreAllLink = $(IDS.RESTORE_ALL_LINK); |
| 963 restoreAllLink.addEventListener('click', onRestoreAll); | 953 restoreAllLink.addEventListener('click', onRestoreAll); |
| 964 registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); | 954 registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); |
| 965 restoreAllLink.textContent = templateData.restoreThumbnailsShort; | 955 restoreAllLink.textContent = |
| 966 $(IDS.ATTRIBUTION_TEXT).textContent = templateData.attributionIntro; | 956 configData.translatedStrings.restoreThumbnailsShort; |
| 957 $(IDS.ATTRIBUTION_TEXT).textContent = |
| 958 configData.translatedStrings.attributionIntro; |
| 967 | 959 |
| 968 var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); | 960 var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); |
| 969 notificationCloseButton.addEventListener('click', hideNotification); | 961 notificationCloseButton.addEventListener('click', hideNotification); |
| 970 | 962 |
| 971 userInitiatedMostVisitedChange = false; | 963 userInitiatedMostVisitedChange = false; |
| 972 window.addEventListener('resize', onResize); | 964 window.addEventListener('resize', onResize); |
| 973 onResize(); | 965 onResize(); |
| 974 | 966 |
| 975 var topLevelHandle = getEmbeddedSearchApiHandle(); | 967 var topLevelHandle = getEmbeddedSearchApiHandle(); |
| 976 | 968 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 document.addEventListener('DOMContentLoaded', init); | 1010 document.addEventListener('DOMContentLoaded', init); |
| 1019 } | 1011 } |
| 1020 | 1012 |
| 1021 return { | 1013 return { |
| 1022 init: init, | 1014 init: init, |
| 1023 listen: listen | 1015 listen: listen |
| 1024 }; | 1016 }; |
| 1025 } | 1017 } |
| 1026 | 1018 |
| 1027 if (!window.localNTPUnitTest) { | 1019 if (!window.localNTPUnitTest) { |
| 1028 LocalNTP(location).listen(); | 1020 LocalNTP().listen(); |
| 1029 } | 1021 } |
| OLD | NEW |