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.direction,
29 var domain = document.createElement('div');
30 domain.textContent = data.domain;
31 link.appendChild(domain);
34 // Called on intentionally empty tiles for which the visuals are handled
35 // externally by the page itself.
36 function showEmptyTile() {
37 displayLink(createMostVisitedLink(
38 params, data.url, data.title, undefined, data.direction,
41 // Creates and adds an image.
42 function createThumbnail(src) {
43 var image = document.createElement('img');
44 image.onload = function() {
45 var link = createMostVisitedLink(
46 params, data.url, data.title, undefined, data.direction,
48 link.appendChild(image);
51 image.onerror = function() {
52 // If no external thumbnail fallback (etfb), and have domain.
53 if (!params.etfb && data.domain) {
55 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK);
58 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE_FALLBACK);
60 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ERROR);
65 if (data.thumbnailUrl) {
66 createThumbnail(data.thumbnailUrl);
67 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_TILE);
68 } else if (data.domain) {
70 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE);
73 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE);
75 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE);
77 // Log an impression if we know the position of the tile.
78 if (isFinite(params.pos) && data.provider) {
79 logMostVisitedImpression(parseInt(params.pos, 10), data.provider);