Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 console.log(info); | |
|
huangs
2015/03/19 19:13:13
console.log()
fserb
2015/03/19 20:02:52
Done.
| |
| 130 var themeStyle = []; | |
| 131 | |
| 132 if (info.tileBorderColor) { | |
| 133 themeStyle.push('.mv-tile {' + | |
| 134 'border: 1px solid ' + info.tileBorderColor + '; }'); | |
| 135 } | |
| 136 if (info.tileHoverBorderColor) { | |
| 137 themeStyle.push('.mv-tile:hover {' + | |
| 138 'border-color: ' + info.tileHoverBorderColor + '; }'); | |
| 139 } | |
| 140 if (info.isThemeDark) { | |
| 141 themeStyle.push('.mv-tile, .mv-empty-tile { background: rgb(51,51,51); }'); | |
| 142 themeStyle.push('.mv-thumb.failed-img { background-color: #555; }'); | |
| 143 themeStyle.push('.mv-thumb.failed-img::after { border-color: #333; }'); | |
| 144 themeStyle.push('.mv-x { ' + | |
| 145 'background: linear-gradient(to left, ' + | |
| 146 'rgb(51,51,51) 60%, transparent); }'); | |
| 147 themeStyle.push('html[dir=rtl] .mv-x { ' + | |
| 148 'background: linear-gradient(to right, ' + | |
| 149 'rgb(51,51,51) 60%, transparent); }'); | |
| 150 themeStyle.push('.mv-x::after { ' + | |
| 151 'background-color: rgba(255,255,255,0.7); }'); | |
| 152 themeStyle.push('.mv-x:hover::after { background-color: #FFF; }'); | |
|
huangs
2015/03/19 19:13:13
NIT: #fff
fserb
2015/03/19 20:02:52
Done.
| |
| 153 themeStyle.push('.mv-x:active::after { ' + | |
| 154 'background-color: rgba(255,255,255,0.5); }'); | |
|
huangs
2015/03/19 19:13:13
A bit odd that in the CSS file we have
backgroun
fserb
2015/03/19 20:02:52
that's for the non-dark theme
| |
| 155 } | |
| 156 if (info.tileTitleColor) { | |
| 157 themeStyle.push('body { color: ' + info.tileTitleColor + '; }'); | |
| 158 } | |
| 159 | |
| 160 document.querySelector('#custom-theme').textContent = themeStyle.join('\n'); | |
| 161 }; | |
| 162 | |
| 163 | |
| 126 /** | 164 /** |
| 127 * Called when the host page has finished sending us tile information and | 165 * 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. | 166 * we are ready to show the new tiles and drop the old ones. |
| 129 */ | 167 */ |
| 130 var showTiles = function() { | 168 var showTiles = function() { |
| 131 // Store the tiles on the current closure. | 169 // Store the tiles on the current closure. |
| 132 var cur = tiles; | 170 var cur = tiles; |
| 133 | 171 |
| 134 // Create empty tiles until we have NUMBER_OF_TILES. | 172 // Create empty tiles until we have NUMBER_OF_TILES. |
| 135 while (cur.childNodes.length < NUMBER_OF_TILES) { | 173 while (cur.childNodes.length < NUMBER_OF_TILES) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 165 | 203 |
| 166 /** | 204 /** |
| 167 * Called when the host page wants to add a suggestion tile. | 205 * Called when the host page wants to add a suggestion tile. |
| 168 * For Most Visited, it grabs the data from Chrome and pass on. | 206 * For Most Visited, it grabs the data from Chrome and pass on. |
| 169 * For host page generated it just passes the data. | 207 * For host page generated it just passes the data. |
| 170 * @param {object} args Data for the tile to be rendered. | 208 * @param {object} args Data for the tile to be rendered. |
| 171 */ | 209 */ |
| 172 var addTile = function(args) { | 210 var addTile = function(args) { |
| 173 if (args.rid) { | 211 if (args.rid) { |
| 174 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid); | 212 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid); |
| 213 data.faviconUrl = 'chrome-search://favicon/size/16@' + | |
| 214 window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.rid; | |
| 175 tiles.appendChild(renderTile(data)); | 215 tiles.appendChild(renderTile(data)); |
| 176 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION); | 216 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION); |
| 177 } else { | 217 } else { |
| 178 tiles.appendChild(renderTile(null)); | 218 tiles.appendChild(renderTile(null)); |
| 179 } | 219 } |
| 180 }; | 220 }; |
| 181 | 221 |
| 182 | 222 |
| 183 /** | 223 /** |
| 184 * Called when the user decided to add a tile to the blacklist. | 224 * Called when the user decided to add a tile to the blacklist. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 var html = document.querySelector('html'); | 347 var html = document.querySelector('html'); |
| 308 html.dir = 'rtl'; | 348 html.dir = 'rtl'; |
| 309 } | 349 } |
| 310 | 350 |
| 311 window.addEventListener('message', handlePostMessage); | 351 window.addEventListener('message', handlePostMessage); |
| 312 }; | 352 }; |
| 313 | 353 |
| 314 | 354 |
| 315 window.addEventListener('DOMContentLoaded', init); | 355 window.addEventListener('DOMContentLoaded', init); |
| 316 })(); | 356 })(); |
| OLD | NEW |