new_new_tab.html revision ac1e49eb6695f711d72215fcdf9388548942a00d
1<!DOCTYPE html> 2<html i18n-values=" 3 dir:textdirection; 4 bookmarkbarattached:bookmarkbarattached; 5 hasattribution:hasattribution; 6 anim:anim; 7 syncispresent:syncispresent; 8 customlogo:customlogo" 9 install-animation-enabled="true"> 10<head> 11<meta charset="utf-8"> 12<title i18n-content="title"></title> 13<script> 14// Logging info for benchmarking purposes. 15var log = []; 16function logEvent(name, shouldLogTime) { 17 if (shouldLogTime) { 18 chrome.send('logEventTime', [name]); 19 } 20 log.push([name, Date.now()]); 21} 22logEvent('Tab.NewTabScriptStart', true); 23 24var global = this; 25 26/** 27 * Registers a callback function so that if the backend calls it too early it 28 * will get delayed until DOMContentLoaded is fired. 29 * @param {string} name The name of the global function that the backend calls. 30 */ 31function registerCallback(name) { 32 var f = function(var_args) { 33 var args = Array.prototype.slice.call(arguments); 34 // If we still have the temporary function we delay until the dom is ready. 35 if (global[name] == f) { 36 logEvent(name + ' is not yet ready. Waiting for DOMContentLoaded'); 37 document.addEventListener('DOMContentLoaded', function() { 38 logEvent('Calling the new ' + name); 39 global[name].apply(null, args); 40 }); 41 } 42 }; 43 global[name] = f; 44} 45 46chrome.send('getMostVisited'); 47chrome.send('getRecentlyClosedTabs'); 48chrome.send('getForeignSessions'); 49chrome.send('getApps'); 50 51registerCallback('mostVisitedPages'); 52registerCallback('recentlyClosedTabs'); 53registerCallback('syncMessageChanged'); 54registerCallback('getAppsCallback'); 55registerCallback('setShownSections'); 56registerCallback('foreignSessions'); 57 58</script> 59<!-- template data placeholder --> 60<link rel="stylesheet" href="new_new_tab.css"> 61<link rel="stylesheet" href="ntp/most_visited.css"> 62<link rel="stylesheet" href="ntp/apps.css"> 63<link rel="stylesheet" href="shared/css/menu.css"> 64<script> 65 66/** 67 * Bitmask for the different UI sections. 68 * This matches the Section enum in /dom_ui/shown_sections_handler.h 69 * @enum {number} 70 */ 71var Section = { 72 THUMB: 1 << 0, 73 APPS: 1 << 6 74}; 75 76// These are used to hide sections and are part of the |shownSections| bitmask, 77// but are not sections themselves. 78var MINIMIZED_THUMB = 1 << (0 + 16); 79var MINIMIZED_RECENT = 1 << (2 + 16); 80var MINIMIZED_APPS = 1 << (6 + 16); 81 82var shownSections = templateData['shown_sections']; 83 84// Until themes can clear the cache, force-reload the theme stylesheet. 85document.write('<link id="themecss" rel="stylesheet" ' + 86 'href="chrome://theme/css/newtab.css?' + 87 Date.now() + '">'); 88 89function useSmallGrid() { 90 return window.innerWidth <= 940; 91} 92 93function isRtl() { 94 return templateData['textdirection'] == 'rtl'; 95} 96 97// Parse any name value pairs passed through the URL hash. 98var hashParams = (function() { 99 var result = {}; 100 if (location.hash.length) { 101 location.hash.substr(1).split('&').forEach(function(pair) { 102 pair = pair.split('='); 103 if (pair.length != 2) { 104 throw new Error('Unexpected hash value: ' + location.hash); 105 } 106 107 result[pair[0]] = pair[1]; 108 }); 109 } 110 return result; 111})(); 112 113// Reflect the mode param as an attribute so we can use CSS attribute selectors 114// on it. 115if ('mode' in hashParams) { 116 document.documentElement.setAttribute('mode', hashParams['mode']); 117} 118 119</script> 120</head> 121<body class="loading" 122 i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize"> 123 124<div id="attribution" class="attribution nolayout"> 125 <div i18n-content="attributionintro"></div> 126 <img id="attribution-img"> 127</div> 128 129<div id="main"> 130 131 <div id="notification-container"> 132 <div id="notification"> 133 <span> </span> 134 <span class="link"><span class="link-color"></span></span> 135 </div> 136 </div> 137 138 <div id="login-container"> 139 <span id="login-username"></span> 140 </div> 141 142 <div class="maxiview" id="apps-maxiview"> 143 <div id="apps-promo"> 144 <button id="apps-promo-hide" i18n-content="appspromohide"></button> 145 <h3 i18n-content="appspromoheader"></h3> 146 <p id="apps-promo-text1" i18n-values=".innerHTML:appspromotext1"></p> 147 <p id="apps-promo-text2" i18n-content="appspromotext2"></p> 148 </div> 149 <div id="apps-content"></div> 150 </div> 151 <div class="maxiview" id="most-visited-maxiview"></div> 152 153 <div class="sections"> 154 <!-- Start disabled. We only enable once we have installed default apps. --> 155 <div id="apps" class="section disabled" section="APPS"> 156 <h2> 157 <img class="disclosure" img src="ntp/ntp_disclosure_triangle.png"> 158 <div class="back"></div> 159 <span i18n-content="apps"></span> 160 <button class="section-close-button"></button> 161 </h2> 162 <div class="miniview"></div> 163 </div> 164 165 <div id="most-visited" class="section" section="THUMB"> 166 <h2> 167 <img class="disclosure" src="ntp/ntp_disclosure_triangle.png"> 168 <div class="back"></div> 169 <span i18n-content="mostvisited"></span> 170 <button id="most-visited-settings" i18n-content="restorethumbnails"> 171 </button> 172 <button class="section-close-button"></button> 173 </h2> 174 <div class="miniview"></div> 175 </div> 176 177 <!-- Start this section disabled because it might not have data, and looks 178 silly without any. --> 179 <div id="recently-closed" class="section hidden disabled" section="RECENT" 180 noexpand="true"> 181 <h2> 182 <div class="back"></div> 183 <span i18n-content="recentlyclosed"></span> 184 <button class="section-close-button"></button> 185 </h2> 186 <div class="miniview"></div> 187 </div> 188 189 <!-- Start disabled until sync is enabled and foreign sessions are 190 available. --> 191 <div id="foreign-sessions" class="section hidden disabled" section="SYNC"> 192 <h2> 193 <div class="back"></div> 194 <span i18n-content="foreignsessions"></span> 195 </h2> 196 <div class="miniview"></div> 197 </div> 198 199 <div id="sync-status" class="section disabled"> 200 <div> 201 <h3></h3> 202 <span></span> 203 </div> 204 </div> 205 </div> 206 207 <div id="closed-sections-bar"> 208 <!-- The default visibility of these buttons needs to be the opposite of the 209 default visibility of the corresponding sections. --> 210 <button id="apps-button" 211 menu="#apps-menu"> 212 <span i18n-content="apps"></span> 213 <img src="ntp/ntp_disclosure_triangle.png"> 214 </button> 215 <button id="most-visited-button" 216 class="disabled" 217 menu="#most-visited-menu"> 218 <span i18n-content="mostvisited"></span> 219 <img src="ntp/ntp_disclosure_triangle.png"> 220 </button> 221 <button id="recently-closed-button" 222 menu="#recently-closed-menu"> 223 <span i18n-content="recentlyclosed"></span> 224 <img src="ntp/ntp_disclosure_triangle.png"> 225 </button> 226 </div> 227</div> <!-- main --> 228 229<div class="window-menu" id="window-tooltip"></div> 230 231<command id="clear-all-blacklisted" i18n-values=".label:restorethumbnails"> 232<command id="apps-launch-command"> 233<command id="apps-options-command" i18n-values=".label:appoptions"> 234<command id="apps-uninstall-command" i18n-values=".label:appuninstall"> 235<command id="apps-create-shortcut-command" 236 i18n-values=".label:appcreateshortcut"> 237<command id="apps-launch-type-pinned" i18n-values=".label:applaunchtypepinned" 238 launch-type="0"> 239<command id="apps-launch-type-regular" i18n-values=".label:applaunchtyperegular" 240 launch-type="1"> 241<command id="apps-launch-type-window" 242 i18n-values=".label:applaunchtypewindow" launch-type="3"> 243<command id="apps-launch-type-fullscreen" 244 i18n-values=".label:applaunchtypefullscreen" launch-type="2"> 245 246<!-- These are populated dynamically --> 247<menu id="apps-menu"></menu> 248<menu id="most-visited-menu"></menu> 249<menu id="recently-closed-menu"></menu> 250 251<menu id="app-context-menu"> 252 <button class="default" command="#apps-launch-command"></button> 253 <hr> 254 <button command="#apps-launch-type-regular" launch-type="1"></button> 255 <button command="#apps-launch-type-pinned" launch-type="0"></button> 256 <button id="apps-launch-type-window-menu-item" 257 command="#apps-launch-type-window" launch-type="3"></button> 258 <button command="#apps-launch-type-fullscreen" launch-type="2"></button> 259 <hr> 260 <button command="#apps-options-command"></button> 261 <button command="#apps-uninstall-command"></button> 262 <hr> 263 <button id="apps-create-shortcut-command-menu-item" 264 command="#apps-create-shortcut-command"></button> 265</menu> 266 267</body> 268 269<script src="shared/js/i18n_template.js"></script> 270<script> 271i18nTemplate.process(document, templateData); 272</script> 273<script src="shared/js/local_strings.js"></script> 274<script src="shared/js/parse_html_subset.js"></script> 275 276<script src="shared/js/cr.js"></script> 277<script src="shared/js/cr/ui.js"></script> 278<script src="shared/js/cr/ui/command.js"></script> 279<script src="shared/js/cr/ui/menu_item.js"></script> 280<script src="shared/js/cr/ui/menu.js"></script> 281<script src="shared/js/cr/ui/position_util.js"></script> 282<script src="shared/js/cr/ui/menu_button.js"></script> 283<script src="shared/js/cr/ui/context_menu_button.js"></script> 284<script src="shared/js/cr/ui/context_menu_handler.js"></script> 285 286<script src="ntp/util.js"></script> 287<script src="ntp/most_visited.js"></script> 288<script src="new_new_tab.js"></script> 289<script src="ntp/apps.js"></script> 290 291<script> 292 cr.ui.decorate('menu', cr.ui.Menu); 293 cr.ui.decorate('command', cr.ui.Command); 294 cr.ui.decorate('button[menu]', cr.ui.MenuButton); 295 296 if (cr.isChromeOS) 297 $('closed-sections-bar').setAttribute('chromeos', true); 298 299 initializeLogin(); 300 301 initializeSection('apps', MINIMIZED_APPS, Section.APPS); 302 initializeSection('most-visited', MINIMIZED_THUMB, Section.THUMB); 303 initializeSection('recently-closed', MINIMIZED_RECENT); 304 305 updateSimpleSection('apps', Section.APPS); 306 updateSimpleSection('most-visited', Section.THUMB); 307 var appsInitiallyVisible = !(shownSections & MINIMIZED_APPS); 308 var mostVisitedInitiallyVisible = !(shownSections & MINIMIZED_THUMB); 309 var recentlyClosedInitiallyVisible = !(shownSections & MINIMIZED_RECENT); 310 // Apps and recently closed start as hidden in the HTML, most visited is 311 // initially visible. Adapt to the change received from the prefs by forcing 312 // all three sections to update. 313 shownSections &= ~MINIMIZED_THUMB; 314 shownSections |= MINIMIZED_APPS | MINIMIZED_RECENT; 315 setSectionVisible('apps', Section.APPS, appsInitiallyVisible, MINIMIZED_APPS); 316 setSectionVisible( 317 'most-visited', Section.THUMB, 318 mostVisitedInitiallyVisible, MINIMIZED_THUMB); 319 setSectionVisible( 320 'recently-closed', undefined, 321 recentlyClosedInitiallyVisible, MINIMIZED_RECENT); 322 323 // This is insane, but we use the CSS class 'disabled' for both 'minimized' 324 // sections and sections that are actually disabled, as in not accessible in 325 // any way. 326 // 327 // The above code syncs up the DOM and shownSection wrt minimized. But we 328 // don't know until we receive the apps data whether the apps section will be 329 // disabled or not. So we need to add the 'disabled' class back to the apps 330 // section here. We remove it later, once we know for sure we want it to be 331 // enabled. 332 // 333 // See also: crbug.com/67273. 334 $('apps').classList.add('disabled'); 335 336 layoutSections(); 337</script> 338</html> 339