Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: chrome/browser/resources/local_ntp/most_visited_single.js

Issue 1011393004: Fast NTP support for themes, dark themes, favicons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright 2015 The Chromium Authors. All rights reserved. 1 /* Copyright 2015 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 // Single iframe for NTP tiles. 5 // Single iframe for NTP tiles.
6 (function() { 6 (function() {
7 'use strict'; 7 'use strict';
8 8
9 9
10 /** 10 /**
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 * functions. 110 * functions.
111 **/ 111 **/
112 var handlePostMessage = function(event) { 112 var handlePostMessage = function(event) {
113 var cmd = event.data.cmd; 113 var cmd = event.data.cmd;
114 114
115 if (cmd == 'tile') { 115 if (cmd == 'tile') {
116 addTile(event.data); 116 addTile(event.data);
117 } else if (cmd == 'show') { 117 } else if (cmd == 'show') {
118 showTiles(); 118 showTiles();
119 countLoad(); 119 countLoad();
120 } else if (cmd == 'updateTheme') {
121 updateTheme(event.data);
120 } else { 122 } else {
121 console.error('Unknown command: ' + event.data); 123 console.error('Unknown command: ' + event.data);
122 } 124 }
123 }; 125 };
124 126
125 127
128 var updateTheme = function(info) {
129 var themeStyle = [];
130
131 if (info.tileBorderColor) {
132 themeStyle.push('.mv-tile {' +
133 'border: 1px solid ' + info.tileBorderColor + '; }');
134 }
135 if (info.tileHoverBorderColor) {
136 themeStyle.push('.mv-tile:hover {' +
137 'border-color: ' + info.tileHoverBorderColor + '; }');
138 }
139 if (info.isThemeDark) {
140 themeStyle.push('.mv-tile, .mv-empty-tile { background: rgb(51,51,51); }');
141 themeStyle.push('.mv-thumb.failed-img { background-color: #555; }');
142 themeStyle.push('.mv-thumb.failed-img::after { border-color: #333; }');
143 themeStyle.push('.mv-x { ' +
144 'background: linear-gradient(to left, ' +
145 'rgb(51,51,51) 60%, transparent); }');
146 themeStyle.push('html[dir=rtl] .mv-x { ' +
147 'background: linear-gradient(to right, ' +
148 'rgb(51,51,51) 60%, transparent); }');
149 themeStyle.push('.mv-x::after { ' +
150 'background-color: rgba(255,255,255,0.7); }');
151 themeStyle.push('.mv-x:hover::after { background-color: #fff; }');
152 themeStyle.push('.mv-x:active::after { ' +
153 'background-color: rgba(255,255,255,0.5); }');
154 }
155 if (info.tileTitleColor) {
156 themeStyle.push('body { color: ' + info.tileTitleColor + '; }');
157 }
158
159 document.querySelector('#custom-theme').textContent = themeStyle.join('\n');
160 };
161
162
126 /** 163 /**
127 * Called when the host page has finished sending us tile information and 164 * Called when the host page has finished sending us tile information and
128 * we are ready to show the new tiles and drop the old ones. 165 * we are ready to show the new tiles and drop the old ones.
129 */ 166 */
130 var showTiles = function() { 167 var showTiles = function() {
131 // Store the tiles on the current closure. 168 // Store the tiles on the current closure.
132 var cur = tiles; 169 var cur = tiles;
133 170
134 // Create empty tiles until we have NUMBER_OF_TILES. 171 // Create empty tiles until we have NUMBER_OF_TILES.
135 while (cur.childNodes.length < NUMBER_OF_TILES) { 172 while (cur.childNodes.length < NUMBER_OF_TILES) {
(...skipping 29 matching lines...) Expand all
165 202
166 /** 203 /**
167 * Called when the host page wants to add a suggestion tile. 204 * Called when the host page wants to add a suggestion tile.
168 * For Most Visited, it grabs the data from Chrome and pass on. 205 * For Most Visited, it grabs the data from Chrome and pass on.
169 * For host page generated it just passes the data. 206 * For host page generated it just passes the data.
170 * @param {object} args Data for the tile to be rendered. 207 * @param {object} args Data for the tile to be rendered.
171 */ 208 */
172 var addTile = function(args) { 209 var addTile = function(args) {
173 if (args.rid) { 210 if (args.rid) {
174 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid); 211 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid);
212 data.faviconUrl = 'chrome-search://favicon/size/16@' +
213 window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.rid;
175 tiles.appendChild(renderTile(data)); 214 tiles.appendChild(renderTile(data));
176 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION); 215 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION);
177 } else { 216 } else {
178 tiles.appendChild(renderTile(null)); 217 tiles.appendChild(renderTile(null));
179 } 218 }
180 }; 219 };
181 220
182 221
183 /** 222 /**
184 * Called when the user decided to add a tile to the blacklist. 223 * Called when the user decided to add a tile to the blacklist.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 var html = document.querySelector('html'); 346 var html = document.querySelector('html');
308 html.dir = 'rtl'; 347 html.dir = 'rtl';
309 } 348 }
310 349
311 window.addEventListener('message', handlePostMessage); 350 window.addEventListener('message', handlePostMessage);
312 }; 351 };
313 352
314 353
315 window.addEventListener('DOMContentLoaded', init); 354 window.addEventListener('DOMContentLoaded', init);
316 })(); 355 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698