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, tileSource) { |
18 chrome.embeddedSearch.newTabPage.logMostVisitedImpression( | 18 chrome.embeddedSearch.newTabPage.logMostVisitedImpression(tileIndex, |
19 tileIndex, provider); | 19 tileSource); |
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.direction, | 27 params, data.url, data.title, undefined, data.direction, |
28 data.provider); | 28 data.tileSource); |
29 var domain = document.createElement('div'); | 29 var domain = document.createElement('div'); |
30 domain.textContent = data.domain; | 30 domain.textContent = data.domain; |
31 link.appendChild(domain); | 31 link.appendChild(domain); |
32 displayLink(link); | 32 displayLink(link); |
33 } | 33 } |
34 // Called on intentionally empty tiles for which the visuals are handled | 34 // Called on intentionally empty tiles for which the visuals are handled |
35 // externally by the page itself. | 35 // externally by the page itself. |
36 function showEmptyTile() { | 36 function showEmptyTile() { |
37 displayLink(createMostVisitedLink( | 37 displayLink(createMostVisitedLink( |
38 params, data.url, data.title, undefined, data.direction, | 38 params, data.url, data.title, undefined, data.direction, |
39 data.provider)); | 39 data.tileSource)); |
40 } | 40 } |
41 // Creates and adds an image. | 41 // Creates and adds an image. |
42 function createThumbnail(src, imageClass) { | 42 function createThumbnail(src, imageClass) { |
43 var image = document.createElement('img'); | 43 var image = document.createElement('img'); |
44 if (imageClass) { | 44 if (imageClass) { |
45 image.classList.add(imageClass); | 45 image.classList.add(imageClass); |
46 } | 46 } |
47 image.onload = function() { | 47 image.onload = function() { |
48 var link = createMostVisitedLink( | 48 var link = createMostVisitedLink( |
49 params, data.url, data.title, undefined, data.direction, | 49 params, data.url, data.title, undefined, data.direction, |
50 data.provider); | 50 data.tileSource); |
51 // Use blocker to prevent context menu from showing image-related items. | 51 // Use blocker to prevent context menu from showing image-related items. |
52 var blocker = document.createElement('span'); | 52 var blocker = document.createElement('span'); |
53 blocker.className = 'blocker'; | 53 blocker.className = 'blocker'; |
54 link.appendChild(blocker); | 54 link.appendChild(blocker); |
55 link.appendChild(image); | 55 link.appendChild(image); |
56 displayLink(link); | 56 displayLink(link); |
57 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE_LOADED); | 57 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE_LOADED); |
58 }; | 58 }; |
59 image.onerror = function() { | 59 image.onerror = function() { |
60 // If no external thumbnail fallback (etfb), and have domain. | 60 // If no external thumbnail fallback (etfb), and have domain. |
(...skipping 23 matching lines...) Expand all Loading... |
84 } else if (data.domain) { | 84 } else if (data.domain) { |
85 showDomainElement(); | 85 showDomainElement(); |
86 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE); | 86 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE); |
87 } else { | 87 } else { |
88 showEmptyTile(); | 88 showEmptyTile(); |
89 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE); | 89 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE); |
90 } | 90 } |
91 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE); | 91 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE); |
92 | 92 |
93 // Log an impression if we know the position of the tile. | 93 // Log an impression if we know the position of the tile. |
94 if (isFinite(params.pos) && data.provider) { | 94 if (isFinite(params.pos)) { |
95 logMostVisitedImpression(parseInt(params.pos, 10), data.provider); | 95 logMostVisitedImpression(parseInt(params.pos, 10), data.tileSource); |
96 } | 96 } |
97 }); | 97 }); |
98 }); | 98 }); |
OLD | NEW |