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
|
<!DOCTYPE html>
<html i18n-values="
dir:textdirection;
firstview:firstview;
bookmarkbarattached:bookmarkbarattached;
hasattribution:hasattribution;
anim:anim;
syncispresent:syncispresent;
showsetashomepage:showsetashomepage">
<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');
registerCallback('onShownSections');
registerCallback('mostVisitedPages');
registerCallback('recentlyClosedTabs');
registerCallback('syncMessageChanged');
registerCallback('tips');
registerCallback('onHomePageSet');
</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: 2,
RECENT: 4,
TIPS: 8,
SYNC: 16
};
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';
}
function getMostVisitedLayoutRects() {
var small = useSmallGrid();
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;
// Since the list mode does not have a toolbar move it down a little to add
// some spacing at the top.
var LIST_TOP_SPACING = 22;
if (shownSections & Section.LIST) {
h = 34;
rows = 8;
cols = 1;
}
var rtl = isRtl();
var rects = [];
if (shownSections & Section.THUMB || shownSections & Section.LIST) {
for (var i = 0; i < rows * cols; i++) {
var row, col, left, top;
if (shownSections & Section.THUMB) {
row = Math.floor(i / cols);
col = i % cols;
} else {
col = Math.floor(i / rows);
row = i % rows;
}
if (shownSections & Section.THUMB) {
left = rtl ? sumWidth - col * w - thumbWidth - 2 * borderWidth :
col * w;
} else {
left = rtl ? sumWidth - col * w - w + 2 * marginWidth : col * w;
}
top = row * h;
if (shownSections & Section.LIST) {
top += LIST_TOP_SPACING;
}
rects[i] = {left: left, top: top};
}
}
return rects;
}
function applyMostVisitedRects() {
var isList = shownSections & Section.LIST;
if (shownSections & Section.THUMB || isList) {
var rects = getMostVisitedLayoutRects();
var rtlList = isRtl() && isList;
var children = $('most-visited').children;
for (var i = 0; i < 8; i++) {
var t = children[i];
t.style.left = rtlList ? '' : rects[i].left + 'px';
t.style.top = rects[i].top + 'px';
t.style.right = '';
var innerStyle = t.firstElementChild.style;
innerStyle.left = innerStyle.top = '';
}
}
}
function updateSimpleSection(id, section) {
$(id).style.display = shownSections & section ? '' : 'none';
}
</script>
</head>
<body class="loading"
i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
<div id="bottom-right-promo">
<a i18n-values="href:extensionslink">
<img src="chrome://theme/newtab_extensions_promo">
</a>
</div>
<div id="main">
<div id="view-toolbar"
><input type=checkbox id="thumb-checkbox" checked
i18n-values="title:showhidethumbnailtooltip"
><input type=checkbox id="list-checkbox"
i18n-values="title:showhidelisttooltip"
><input type="button" id="option-button"
i18n-values="title:pagedisplaytooltip"></div>
<div id="option-menu" class="window-menu">
<div command="hide" section="THUMB" i18n-content="mostvisited"></div>
<div command="hide" section="RECENT" i18n-content="recentlyclosed"></div>
<div command="hide" section="TIPS" i18n-content="tips"></div>
<div command="hide" section="SYNC" i18n-content="sync"
id="sync-menu-item"></div>
<hr>
<div command="clear-all-blacklisted"
i18n-content="restorethumbnails"></div>
</div>
<script>
$('thumb-checkbox').checked = shownSections & Section.THUMB;
$('list-checkbox').checked = shownSections & Section.LIST;
$('sync-menu-item').style.display =
templateData['syncispresent'] == 'true' ? '' : 'none';
</script>
<div id="notification">
<span> </span>
<span class="link"><span class="link-color"></span></span>
</div>
<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>
<script>
(function() {
var el = $('most-visited');
if (shownSections & Section.LIST) {
el.className += ' list';
} else if (!(shownSections & Section.THUMB)) {
el.className += ' collapsed';
}
for (var i = 1; i < 8; i++) {
el.appendChild(el.firstElementChild.cloneNode(true)).id = 't' + i;
}
applyMostVisitedRects();
})();
</script>
<div id="recently-closed">
<h2 i18n-content="recentlyclosed"></h2>
<span class="nav">
<a href="chrome://history/" class="item"
i18n-content="viewfullhistory"></a>
</span>
</div>
<script>updateSimpleSection('recently-closed', Section.RECENT);</script>
<div id="sync-status">
<h2></h2>
<span></span>
</div>
<script>updateSimpleSection('sync-status', Section.SYNC);</script>
<div id="set-as-home-page">
<button class="link">
<span class="link-color" i18n-content="makethishomepage"></span>
</button>
</div>
<div id="tip-line"></div>
<script>updateSimpleSection('tip-line', Section.TIPS);</script>
<div id="attribution" class="attribution">
<div i18n-content="attributionintro"></div>
<img id="attribution-img">
</div>
<div id="footer">
<div id="promo-line">
<span id="promo-new" i18n-content="promonew"></span>
<span i18n-values=".innerHTML:promomessage"></span>
<button id="promo-close">
</div>
</div>
</div> <!-- main -->
<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>
|