Chromium Code Reviews| 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 logMostVisitedImpression(tileIndex, provider) { | 17 function logMostVisitedImpression(tileIndex, provider) { |
| 18 chrome.embeddedSearch.newTabPage.logMostVisitedImpression( | 18 chrome.embeddedSearch.newTabPage.logMostVisitedImpression( |
| 19 tileIndex, provider); | 19 tileIndex, provider); |
| 20 } | 20 } |
| 21 function displayLink(link) { | 21 function displayLink(link) { |
| 22 document.body.appendChild(link); | 22 document.body.appendChild(link); |
| 23 window.parent.postMessage('linkDisplayed', '{{ORIGIN}}'); | 23 window.parent.postMessage('linkDisplayed', '{{ORIGIN}}'); |
| 24 } | 24 } |
| 25 function showDomainElement() { | 25 function showDomainElement() { |
| 26 var link = createMostVisitedLink( | 26 var link = createMostVisitedLink( |
| 27 params, data.url, data.title, undefined, data.provider); | 27 params, data.url, data.title, undefined, data.direciton, |
|
huangs
2014/08/06 20:17:43
TYPO: direciton
Mathieu
2014/08/06 20:19:20
Done.
| |
| 28 data.provider); | |
| 28 var domain = document.createElement('div'); | 29 var domain = document.createElement('div'); |
| 29 domain.textContent = data.domain; | 30 domain.textContent = data.domain; |
| 30 link.appendChild(domain); | 31 link.appendChild(domain); |
| 31 displayLink(link); | 32 displayLink(link); |
| 32 } | 33 } |
| 33 // Called on intentionally empty tiles for which the visuals are handled | 34 // Called on intentionally empty tiles for which the visuals are handled |
| 34 // externally by the page itself. | 35 // externally by the page itself. |
| 35 function showEmptyTile() { | 36 function showEmptyTile() { |
| 36 displayLink(createMostVisitedLink( | 37 displayLink(createMostVisitedLink( |
| 37 params, data.url, data.title, undefined, data.provider)); | 38 params, data.url, data.title, undefined, data.direction, |
| 39 data.provider)); | |
| 38 } | 40 } |
| 39 // Creates and adds an image. | 41 // Creates and adds an image. |
| 40 function createThumbnail(src) { | 42 function createThumbnail(src) { |
| 41 var image = document.createElement('img'); | 43 var image = document.createElement('img'); |
| 42 image.onload = function() { | 44 image.onload = function() { |
| 43 var shadow = document.createElement('span'); | 45 var shadow = document.createElement('span'); |
| 44 shadow.className = 'shadow'; | 46 shadow.className = 'shadow'; |
| 45 var link = createMostVisitedLink( | 47 var link = createMostVisitedLink( |
| 46 params, data.url, data.title, undefined, data.provider); | 48 params, data.url, data.title, undefined, data.direction, |
| 49 data.provider); | |
| 47 link.appendChild(shadow); | 50 link.appendChild(shadow); |
| 48 link.appendChild(image); | 51 link.appendChild(image); |
| 49 displayLink(link); | 52 displayLink(link); |
| 50 }; | 53 }; |
| 51 image.onerror = function() { | 54 image.onerror = function() { |
| 52 if (data.domain) { | 55 if (data.domain) { |
| 53 showDomainElement(); | 56 showDomainElement(); |
| 54 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK); | 57 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK); |
| 55 } else { | 58 } else { |
| 56 showEmptyTile(); | 59 showEmptyTile(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 72 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE); | 75 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE); |
| 73 } | 76 } |
| 74 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE); | 77 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE); |
| 75 | 78 |
| 76 // Log an impression if we know the position of the tile. | 79 // Log an impression if we know the position of the tile. |
| 77 if (isFinite(params.pos) && data.provider) { | 80 if (isFinite(params.pos) && data.provider) { |
| 78 logMostVisitedImpression(parseInt(params.pos, 10), data.provider); | 81 logMostVisitedImpression(parseInt(params.pos, 10), data.provider); |
| 79 } | 82 } |
| 80 }); | 83 }); |
| 81 }); | 84 }); |
| OLD | NEW |