| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview Rendering for iframed most visited thumbnails. | 7 * @fileoverview Rendering for iframed most visited thumbnails. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 window.addEventListener('DOMContentLoaded', function() { | 10 window.addEventListener('DOMContentLoaded', function() { |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 fillMostVisited(document.location, function(params, data) { | 13 fillMostVisited(document.location, function(params, data) { |
| 14 function logEvent(eventName) { | 14 function logEvent(eventName) { |
| 15 chrome.embeddedSearch.newTabPage.logEvent(eventName); | 15 chrome.embeddedSearch.newTabPage.logEvent(eventName); |
| 16 } | 16 } |
| 17 function logImpression(tileIndex, provider) { | 17 function logImpression(tileIndex, provider) { |
| 18 chrome.embeddedSearch.newTabPage.logImpression(tileIndex, provider); | 18 chrome.embeddedSearch.newTabPage.logImpression(tileIndex, provider); |
| 19 } | 19 } |
| 20 function showDomainElement() { | 20 function showDomainElement() { |
| 21 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ERROR); | 21 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ERROR); |
| 22 var link = createMostVisitedLink( | 22 var link = createMostVisitedLink( |
| 23 params, data.url, data.title, undefined, data.ping); | 23 params, data.url, data.title, undefined, data.ping, data.provider); |
| 24 var domain = document.createElement('div'); | 24 var domain = document.createElement('div'); |
| 25 domain.textContent = data.domain; | 25 domain.textContent = data.domain; |
| 26 link.appendChild(domain); | 26 link.appendChild(domain); |
| 27 document.body.appendChild(link); | 27 document.body.appendChild(link); |
| 28 } | 28 } |
| 29 // Called on intentionally empty tiles for which the visuals are handled | 29 // Called on intentionally empty tiles for which the visuals are handled |
| 30 // externally by the page itself. | 30 // externally by the page itself. |
| 31 function showEmptyTile() { | 31 function showEmptyTile() { |
| 32 var link = createMostVisitedLink( | 32 var link = createMostVisitedLink( |
| 33 params, data.url, data.title, undefined, data.ping); | 33 params, data.url, data.title, undefined, data.ping, data.provider); |
| 34 document.body.appendChild(link); | 34 document.body.appendChild(link); |
| 35 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE); | 35 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE); |
| 36 } | 36 } |
| 37 function createAndAppendThumbnail(isVisible) { | 37 function createAndAppendThumbnail(isVisible) { |
| 38 var image = new Image(); | 38 var image = new Image(); |
| 39 image.onload = function() { | 39 image.onload = function() { |
| 40 var shadow = document.createElement('span'); | 40 var shadow = document.createElement('span'); |
| 41 shadow.classList.add('shadow'); | 41 shadow.classList.add('shadow'); |
| 42 var link = createMostVisitedLink( | 42 var link = createMostVisitedLink( |
| 43 params, data.url, data.title, undefined, data.ping); | 43 params, data.url, data.title, undefined, data.ping, data.provider); |
| 44 link.appendChild(shadow); | 44 link.appendChild(shadow); |
| 45 link.appendChild(image); | 45 link.appendChild(image); |
| 46 // We add 'position: absolute' in anticipation that there could be more | 46 // We add 'position: absolute' in anticipation that there could be more |
| 47 // than one thumbnail. This will superpose the elements. | 47 // than one thumbnail. This will superpose the elements. |
| 48 link.style.position = 'absolute'; | 48 link.style.position = 'absolute'; |
| 49 document.body.appendChild(link); | 49 document.body.appendChild(link); |
| 50 }; | 50 }; |
| 51 if (!isVisible) { | 51 if (!isVisible) { |
| 52 image.style.visibility = 'hidden'; | 52 image.style.visibility = 'hidden'; |
| 53 } | 53 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 image.src = data.thumbnailUrl; | 95 image.src = data.thumbnailUrl; |
| 96 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ATTEMPT); | 96 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ATTEMPT); |
| 97 } else if (data.domain) { | 97 } else if (data.domain) { |
| 98 showDomainElement(); | 98 showDomainElement(); |
| 99 } else { | 99 } else { |
| 100 showEmptyTile(); | 100 showEmptyTile(); |
| 101 } | 101 } |
| 102 }); | 102 }); |
| 103 }); | 103 }); |
| OLD | NEW |