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 // Use blocker to prevent context menu from showing image-related items.
49 var blocker = document.createElement('span');
50 blocker.className = 'blocker';
51 link.appendChild(blocker);
52 link.appendChild(image);
55 image.onerror = function() {
56 // If no external thumbnail fallback (etfb), and have domain.
57 if (!params.etfb && data.domain) {
59 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK);
62 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE_FALLBACK);
64 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ERROR);
71 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE);
72 } else if (data.thumbnailUrl) {
73 createThumbnail(data.thumbnailUrl);
74 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_TILE);
75 } else if (data.domain) {
77 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE);
80 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE);
82 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE);
84 // Log an impression if we know the position of the tile.
85 if (isFinite(params.pos) && data.provider) {
86 logMostVisitedImpression(parseInt(params.pos, 10), data.provider);