| 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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 608 |
| 610 // A mask to darken the thumbnail on focus. | 609 // A mask to darken the thumbnail on focus. |
| 611 var maskElement = createAndAppendElement( | 610 var maskElement = createAndAppendElement( |
| 612 tileElement, 'div', CLASSES.THUMBNAIL_MASK); | 611 tileElement, 'div', CLASSES.THUMBNAIL_MASK); |
| 613 | 612 |
| 614 // The button used to blacklist this page. | 613 // The button used to blacklist this page. |
| 615 var blacklistButton = createAndAppendElement( | 614 var blacklistButton = createAndAppendElement( |
| 616 tileElement, 'div', CLASSES.BLACKLIST_BUTTON); | 615 tileElement, 'div', CLASSES.BLACKLIST_BUTTON); |
| 617 var blacklistFunction = generateBlacklistFunction(rid); | 616 var blacklistFunction = generateBlacklistFunction(rid); |
| 618 blacklistButton.addEventListener('click', blacklistFunction); | 617 blacklistButton.addEventListener('click', blacklistFunction); |
| 619 blacklistButton.title = templateData.removeThumbnailTooltip; | 618 blacklistButton.title = configData.translatedStrings.removeThumbnailTooltip; |
| 620 | 619 |
| 621 // When a tile is focused, have delete also blacklist the page. | 620 // When a tile is focused, have delete also blacklist the page. |
| 622 registerKeyHandler(tileElement, KEYCODE.DELETE, blacklistFunction); | 621 registerKeyHandler(tileElement, KEYCODE.DELETE, blacklistFunction); |
| 623 | 622 |
| 624 // The page favicon, if any. | 623 // The page favicon, if any. |
| 625 var faviconUrl = page.faviconUrl; | 624 var faviconUrl = page.faviconUrl; |
| 626 if (faviconUrl) { | 625 if (faviconUrl) { |
| 627 var favicon = createAndAppendElement( | 626 var favicon = createAndAppendElement( |
| 628 tileElement, 'div', CLASSES.FAVICON); | 627 tileElement, 'div', CLASSES.FAVICON); |
| 629 favicon.style.backgroundImage = 'url(' + faviconUrl + ')'; | 628 favicon.style.backgroundImage = 'url(' + faviconUrl + ')'; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 * @return {Object} the handle to the embeddedSearch API. | 910 * @return {Object} the handle to the embeddedSearch API. |
| 912 */ | 911 */ |
| 913 function getEmbeddedSearchApiHandle() { | 912 function getEmbeddedSearchApiHandle() { |
| 914 if (window.cideb) | 913 if (window.cideb) |
| 915 return window.cideb; | 914 return window.cideb; |
| 916 if (window.chrome && window.chrome.embeddedSearch) | 915 if (window.chrome && window.chrome.embeddedSearch) |
| 917 return window.chrome.embeddedSearch; | 916 return window.chrome.embeddedSearch; |
| 918 return null; | 917 return null; |
| 919 } | 918 } |
| 920 | 919 |
| 921 | |
| 922 /** | |
| 923 * @return {boolean} True if this is a Google page and not some other search | |
| 924 * provider. Used to determine whether to show the logo and fakebox. | |
| 925 */ | |
| 926 function isGooglePage() { | |
| 927 return location.href.indexOf('isGoogle') != -1; | |
| 928 } | |
| 929 | |
| 930 | |
| 931 /** | 920 /** |
| 932 * Extract the desired navigation behavior from a click button. | 921 * Extract the desired navigation behavior from a click button. |
| 933 * @param {number} button The Event#button property of a click event. | 922 * @param {number} button The Event#button property of a click event. |
| 934 * @return {WindowOpenDisposition} The desired behavior for | 923 * @return {WindowOpenDisposition} The desired behavior for |
| 935 * navigateContentWindow. | 924 * navigateContentWindow. |
| 936 */ | 925 */ |
| 937 function getDispositionFromClickButton(button) { | 926 function getDispositionFromClickButton(button) { |
| 938 if (button == MIDDLE_MOUSE_BUTTON) | 927 if (button == MIDDLE_MOUSE_BUTTON) |
| 939 return WindowOpenDisposition.NEW_BACKGROUND_TAB; | 928 return WindowOpenDisposition.NEW_BACKGROUND_TAB; |
| 940 return WindowOpenDisposition.CURRENT_TAB; | 929 return WindowOpenDisposition.CURRENT_TAB; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 951 notification = $(IDS.NOTIFICATION); | 940 notification = $(IDS.NOTIFICATION); |
| 952 attribution = $(IDS.ATTRIBUTION); | 941 attribution = $(IDS.ATTRIBUTION); |
| 953 ntpContents = $(IDS.NTP_CONTENTS); | 942 ntpContents = $(IDS.NTP_CONTENTS); |
| 954 | 943 |
| 955 for (var i = 0; i < NUM_ROWS; i++) { | 944 for (var i = 0; i < NUM_ROWS; i++) { |
| 956 var row = document.createElement('div'); | 945 var row = document.createElement('div'); |
| 957 row.classList.add(CLASSES.ROW); | 946 row.classList.add(CLASSES.ROW); |
| 958 tilesContainer.appendChild(row); | 947 tilesContainer.appendChild(row); |
| 959 } | 948 } |
| 960 | 949 |
| 961 if (isGooglePage()) { | 950 if (configData.isGooglePage) { |
| 962 var logo = document.createElement('div'); | 951 var logo = document.createElement('div'); |
| 963 logo.id = IDS.LOGO; | 952 logo.id = IDS.LOGO; |
| 964 | 953 |
| 965 fakebox = document.createElement('div'); | 954 fakebox = document.createElement('div'); |
| 966 fakebox.id = IDS.FAKEBOX; | 955 fakebox.id = IDS.FAKEBOX; |
| 967 fakebox.innerHTML = | 956 fakebox.innerHTML = |
| 968 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + | 957 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + |
| 969 '<div id=cursor></div>'; | 958 '<div id=cursor></div>'; |
| 970 | 959 |
| 971 ntpContents.insertBefore(fakebox, ntpContents.firstChild); | 960 ntpContents.insertBefore(fakebox, ntpContents.firstChild); |
| 972 ntpContents.insertBefore(logo, ntpContents.firstChild); | 961 ntpContents.insertBefore(logo, ntpContents.firstChild); |
| 973 } else { | 962 } else { |
| 974 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); | 963 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); |
| 975 } | 964 } |
| 976 | 965 |
| 977 var recentTabsText = templateData.recentTabs; | 966 var recentTabsText = configData.translatedStrings.recentTabs; |
| 978 if (recentTabsText) { | 967 if (recentTabsText) { |
| 979 var recentTabsLink = document.createElement('span'); | 968 var recentTabsLink = document.createElement('span'); |
| 980 recentTabsLink.id = IDS.RECENT_TABS; | 969 recentTabsLink.id = IDS.RECENT_TABS; |
| 981 recentTabsLink.addEventListener('click', function(event) { | 970 recentTabsLink.addEventListener('click', function(event) { |
| 982 ntpApiHandle.navigateContentWindow( | 971 ntpApiHandle.navigateContentWindow( |
| 983 'chrome://history', getDispositionFromClickButton(event.button)); | 972 'chrome://history', getDispositionFromClickButton(event.button)); |
| 984 }); | 973 }); |
| 985 recentTabsLink.textContent = recentTabsText; | 974 recentTabsLink.textContent = recentTabsText; |
| 986 ntpContents.appendChild(recentTabsLink); | 975 ntpContents.appendChild(recentTabsLink); |
| 987 // Move the attribution up to prevent it from overlapping. | 976 // Move the attribution up to prevent it from overlapping. |
| 988 attribution.style.bottom = '28px'; | 977 attribution.style.bottom = '28px'; |
| 989 } | 978 } |
| 990 | 979 |
| 991 var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); | 980 var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); |
| 992 notificationMessage.textContent = templateData.thumbnailRemovedNotification; | 981 notificationMessage.textContent = |
| 982 configData.translatedStrings.thumbnailRemovedNotification; |
| 993 var undoLink = $(IDS.UNDO_LINK); | 983 var undoLink = $(IDS.UNDO_LINK); |
| 994 undoLink.addEventListener('click', onUndo); | 984 undoLink.addEventListener('click', onUndo); |
| 995 registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); | 985 registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); |
| 996 undoLink.textContent = templateData.undoThumbnailRemove; | 986 undoLink.textContent = configData.translatedStrings.undoThumbnailRemove; |
| 997 var restoreAllLink = $(IDS.RESTORE_ALL_LINK); | 987 var restoreAllLink = $(IDS.RESTORE_ALL_LINK); |
| 998 restoreAllLink.addEventListener('click', onRestoreAll); | 988 restoreAllLink.addEventListener('click', onRestoreAll); |
| 999 registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); | 989 registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); |
| 1000 restoreAllLink.textContent = templateData.restoreThumbnailsShort; | 990 restoreAllLink.textContent = |
| 1001 $(IDS.ATTRIBUTION_TEXT).textContent = templateData.attributionIntro; | 991 configData.translatedStrings.restoreThumbnailsShort; |
| 992 $(IDS.ATTRIBUTION_TEXT).textContent = |
| 993 configData.translatedStrings.attributionIntro; |
| 1002 | 994 |
| 1003 var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); | 995 var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); |
| 1004 notificationCloseButton.addEventListener('click', hideNotification); | 996 notificationCloseButton.addEventListener('click', hideNotification); |
| 1005 | 997 |
| 1006 userInitiatedMostVisitedChange = false; | 998 userInitiatedMostVisitedChange = false; |
| 1007 window.addEventListener('resize', onResize); | 999 window.addEventListener('resize', onResize); |
| 1008 onResize(); | 1000 onResize(); |
| 1009 | 1001 |
| 1010 var topLevelHandle = getEmbeddedSearchApiHandle(); | 1002 var topLevelHandle = getEmbeddedSearchApiHandle(); |
| 1011 | 1003 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 document.addEventListener('DOMContentLoaded', init); | 1045 document.addEventListener('DOMContentLoaded', init); |
| 1054 } | 1046 } |
| 1055 | 1047 |
| 1056 return { | 1048 return { |
| 1057 init: init, | 1049 init: init, |
| 1058 listen: listen | 1050 listen: listen |
| 1059 }; | 1051 }; |
| 1060 } | 1052 } |
| 1061 | 1053 |
| 1062 if (!window.localNTPUnitTest) { | 1054 if (!window.localNTPUnitTest) { |
| 1063 LocalNTP(location).listen(); | 1055 LocalNTP().listen(); |
| 1064 } | 1056 } |
| OLD | NEW |