1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
<!DOCTYPE html>
<html i18n-values="
dir:textdirection;
bookmarkbarattached:bookmarkbarattached;
hasattribution:hasattribution;
anim:anim;
syncispresent:syncispresent;
haspromo:haspromo">
<meta charset="utf-8">
<title i18n-content="title"></title>
<script>
// Logging info for benchmarking purposes.
var log = [];
function logEvent(name, shouldLogTime) {
if (shouldLogTime) {
chrome.send('logEventTime', [name]);
}
log.push([name, Date.now()]);
}
logEvent('Tab.NewTabScriptStart', true);
var global = this;
/**
* Registers a callback function so that if the backend calls it too early it
* will get delayed until DOMContentLoaded is fired.
* @param {string} name The name of the global function that the backend calls.
*/
function registerCallback(name) {
var f = function(var_args) {
var args = Array.prototype.slice.call(arguments);
// If we still have the temporary function we delay until the dom is ready.
if (global[name] == f) {
logEvent(name + ' is not yet ready. Waiting for DOMContentLoaded');
document.addEventListener('DOMContentLoaded', function() {
logEvent('Calling the new ' + name);
global[name].apply(null, args);
});
}
};
global[name] = f;
}
chrome.send('getMostVisited');
chrome.send('getRecentlyClosedTabs');
chrome.send('getTips');
chrome.send('getApps');
registerCallback('onShownSections');
registerCallback('mostVisitedPages');
registerCallback('recentlyClosedTabs');
registerCallback('syncMessageChanged');
registerCallback('tips');
registerCallback('onHomePageSet');
registerCallback('getAppsCallback');
</script>
<!-- template data placeholder -->
<link rel="stylesheet" href="new_new_tab.css">
<script>
/**
* Bitmask for the different UI sections.
* This matches the Section enum in ../dom_ui/shown_sections_handler.h
* @enum {number}
*/
var Section = {
THUMB: 1,
// LIST is no longer used
RECENT: 4,
TIPS: 8,
SYNC: 16,
DEBUG: 32
};
var shownSections = templateData['shown_sections'];
function $(id) {
return document.getElementById(id);
}
// Until themes can clear the cache, force-reload the theme stylesheet.
document.write('<link id="themecss" rel="stylesheet" ' +
'href="chrome://theme/css/newtab.css?' +
(new Date()).getTime() + '">');
function useSmallGrid() {
return window.innerWidth <= 920;
}
function isRtl() {
return templateData['textdirection'] == 'rtl';
}
// Keep track of the last small state so we can ensure that we are using the
// right mode. This is a workaround for http://crbug.com/25329
var wasSmallGrid;
function getMostVisitedLayoutRects() {
var small = useSmallGrid();
wasSmallGrid = small;
var cols = 4;
var rows = 2;
var marginWidth = 10;
var marginHeight = 7;
var borderWidth = 4;
var thumbWidth = small ? 150 : 207;
var thumbHeight = small ? 93 : 129;
var w = thumbWidth + 2 * borderWidth + 2 * marginWidth;
var h = thumbHeight + 40 + 2 * marginHeight;
var sumWidth = cols * w - 2 * marginWidth;
var rtl = isRtl();
var rects = [];
if (shownSections & Section.THUMB) {
for (var i = 0; i < rows * cols; i++) {
var row = Math.floor(i / cols);
var col = i % cols;
var left = rtl ? sumWidth - col * w - thumbWidth - 2 * borderWidth :
col * w;
var top = row * h;
rects[i] = {left: left, top: top};
}
}
return rects;
}
function applyMostVisitedRects() {
if (shownSections & Section.THUMB) {
var rects = getMostVisitedLayoutRects();
var children = $('most-visited').children;
for (var i = 0; i < 8; i++) {
var t = children[i];
t.style.left = rects[i].left + 'px';
t.style.top = rects[i].top + 'px';
t.style.right = '';
var innerStyle = t.firstElementChild.style;
innerStyle.left = innerStyle.top = '';
}
}
}
// TODO(arv): Remove these when classList is available in HTML5.
// https://bugs.webkit.org/show_bug.cgi?id=20709
function hasClass(el, name) {
return el.nodeType == 1 && el.className.split(/\s+/).indexOf(name) != -1;
}
function addClass(el, name) {
var names = el.className.split(/\s+/);
if (names.indexOf(name) == -1) {
el.className += ' ' + name;
}
}
function removeClass(el, name) {
var names = el.className.split(/\s+/);
el.className = names.filter(function(n) {
return name != n;
}).join(' ');
}
function updateSimpleSection(id, section) {
if (shownSections & section)
removeClass($(id), 'hidden');
else
addClass($(id), 'hidden');
}
</script>
</head>
<body class="loading"
i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
<div id="container">
<div id="main">
<div id=top-bar>
<div id="tip-line"></div>
<script>updateSimpleSection('tip-line', Section.TIPS)</script>
<input type="button" id="option-button"
i18n-values="title:pagedisplaytooltip">
</div>
<div id="option-menu" class="window-menu">
<div command="hide" section="TIPS" i18n-content="tips"></div>
<div command="hide" section="THUMB" i18n-content="mostvisited"></div>
<div command="hide" section="RECENT" i18n-content="recentlyclosed"></div>
<hr>
<div command="clear-all-blacklisted"
i18n-content="restorethumbnails"></div>
</div>
<div id="notification">
<span> </span>
<span class="link"><span class="link-color"></span></span>
</div>
<div class="section disabled" id="apps-section"></div>
<div id="most-visited-section" class="section" section="THUMB">
<h2 i18n-content="mostvisited"></h2>
<div id="most-visited">
<a class="thumbnail-container filler" tabindex="1" id="t0">
<div class="edit-mode-border">
<div class="edit-bar">
<div class="pin"></div>
<div class="spacer"></div>
<div class="remove"></div>
</div>
<span class="thumbnail-wrapper">
<span class="thumbnail"></span>
</span>
</div>
<div class="title">
<div></div>
</div>
</a>
</div>
</div>
<div id="recently-closed" class="section" section="RECENT">
<h2 i18n-content="recentlyclosed"></h2>
<span>
<span class="nav">
<a href="chrome://history/" class="item"
i18n-content="viewfullhistory"></a>
</span>
</span>
</div>
<div id="debug" class="section disabled" section="DEBUG">
<h2>Debug</h2>
<div id="apps-launch-control">
Open apps in:<label
><input type="radio" name="launch-container-type" value=""
checked="true">Default</label
><label><input type="radio" name="launch-container-type" value="tab"
>Tab</label
><label><input type="radio" name="launch-container-type" value="window"
>Window</label
><label><input type="radio" name="launch-container-type" value="panel"
>Panel</label>
</div>
</div>
<script>
(function() {
updateSimpleSection('recently-closed', Section.RECENT);
updateSimpleSection('most-visited-section', Section.THUMB);
updateSimpleSection('debug', Section.DEBUG);
var el = $('most-visited');
for (var i = 1; i < 8; i++) {
el.appendChild(el.firstElementChild.cloneNode(true)).id = 't' + i;
}
applyMostVisitedRects();
})();
</script>
<div id="sync-status">
<h2></h2>
<span></span>
</div>
<div id="attribution" class="attribution">
<div i18n-content="attributionintro"></div>
<img id="attribution-img">
</div>
</div> <!-- main -->
<div id="footer">
<div id="promo-line">
<span id="promo-new" i18n-content="promonew"></span>
<span id="promo-message" i18n-values=".innerHTML:promomessage"></span>
<button class="link" id="promo-close"></button>
</div>
<div id="bottom-right-promo">
<a i18n-values="href:extensionslink">
<img id="promo-image" src="chrome://theme/newtab_extensions_promo">
</a>
</div>
</div>
</div> <!-- container -->
<div class="window-menu" id="window-tooltip"></div>
</body>
<script src="i18n_template.js"></script>
<script src="local_strings.js"></script>
<script src="new_new_tab.js"></script>
</html>
|