Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / resources / local_ntp / most_visited_thumbnail.js
blob789f754650e8dcecd02a0a80ccca17e9b0dc7922
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.
6 /**
7 * @fileoverview Rendering for iframed most visited thumbnails.
8 */
10 window.addEventListener('DOMContentLoaded', function() {
11 'use strict';
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(
19 tileIndex, provider);
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);
31 displayLink(link);
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);
49 displayLink(link);
51 image.onerror = function() {
52 if (data.domain) {
53 showDomainElement();
54 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK);
55 } else {
56 showEmptyTile();
57 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_EXTERNAL_TILE_FALLBACK);
59 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_ERROR);
61 image.src = src;
64 if (data.thumbnailUrl) {
65 createThumbnail(data.thumbnailUrl);
66 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_THUMBNAIL_TILE);
67 } else if (data.domain) {
68 showDomainElement();
69 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE);
70 } else {
71 showEmptyTile();
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);
80 });
81 });