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
3 // found in the LICENSE file.
7 * @fileoverview Rendering for iframed most visited thumbnails.
10 window
.addEventListener('DOMContentLoaded', function() {
13 fillMostVisited(document
.location
, function(params
, data
) {
14 function logEvent(eventName
) {
15 chrome
.embeddedSearch
.newTabPage
.logEvent(eventName
);
17 function logMostVisitedImpression(tileIndex
, provider
) {
18 chrome
.embeddedSearch
.newTabPage
.logMostVisitedImpression(
21 function displayLink(link
) {
22 document
.body
.appendChild(link
);
23 window
.parent
.postMessage('linkDisplayed', '{{ORIGIN}}');
25 function showDomainElement() {
26 var link
= createMostVisitedLink(
27 params
, data
.url
, data
.title
, undefined, data
.provider
);
28 var domain
= document
.createElement('div');
29 domain
.textContent
= data
.domain
;
30 link
.appendChild(domain
);
33 // Called on intentionally empty tiles for which the visuals are handled
34 // externally by the page itself.
35 function showEmptyTile() {
36 displayLink(createMostVisitedLink(
37 params
, data
.url
, data
.title
, undefined, data
.provider
));
39 // Creates and adds an image.
40 function createThumbnail(src
) {
41 var image
= document
.createElement('img');
42 image
.onload = function() {
43 var shadow
= document
.createElement('span');
44 shadow
.className
= 'shadow';
45 var link
= createMostVisitedLink(
46 params
, data
.url
, data
.title
, undefined, data
.provider
);
47 link
.appendChild(shadow
);
48 link
.appendChild(image
);
51 image
.onerror = function() {
54 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_GRAY_TILE_FALLBACK
);
57 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_EXTERNAL_TILE_FALLBACK
);
59 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_THUMBNAIL_ERROR
);
64 if (data
.thumbnailUrl
) {
65 createThumbnail(data
.thumbnailUrl
);
66 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_THUMBNAIL_TILE
);
67 } else if (data
.domain
) {
69 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_GRAY_TILE
);
72 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_EXTERNAL_TILE
);
74 logEvent(NTP_LOGGING_EVENT_TYPE
.NTP_TILE
);
76 // Log an impression if we know the position of the tile.
77 if (isFinite(params
.pos
) && data
.provider
) {
78 logMostVisitedImpression(parseInt(params
.pos
, 10), data
.provider
);