Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/resources/local_ntp/most_visited_thumbnail.js

Issue 2429523002: Cleanup desktop NTP metrics recording (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) {
15 chrome.embeddedSearch.newTabPage.logEvent(eventName);
16 }
17 function logMostVisitedImpression(tileIndex, tileSource) {
18 chrome.embeddedSearch.newTabPage.logMostVisitedImpression(tileIndex,
19 tileSource);
20 }
21 function displayLink(link) { 14 function displayLink(link) {
22 document.body.appendChild(link); 15 document.body.appendChild(link);
23 window.parent.postMessage('linkDisplayed', '{{ORIGIN}}'); 16 window.parent.postMessage('linkDisplayed', '{{ORIGIN}}');
24 } 17 }
25 function showDomainElement() { 18 function showDomainElement() {
26 var link = createMostVisitedLink( 19 var link = createMostVisitedLink(
27 params, data.url, data.title, undefined, data.direction, 20 params, data.url, data.title, undefined, data.direction);
28 data.tileSource);
29 var domain = document.createElement('div'); 21 var domain = document.createElement('div');
30 domain.textContent = data.domain; 22 domain.textContent = data.domain;
31 link.appendChild(domain); 23 link.appendChild(domain);
32 displayLink(link); 24 displayLink(link);
33 } 25 }
34 // Called on intentionally empty tiles for which the visuals are handled 26 // Called on intentionally empty tiles for which the visuals are handled
35 // externally by the page itself. 27 // externally by the page itself.
36 function showEmptyTile() { 28 function showEmptyTile() {
37 displayLink(createMostVisitedLink( 29 displayLink(createMostVisitedLink(
38 params, data.url, data.title, undefined, data.direction, 30 params, data.url, data.title, undefined, data.direction));
39 data.tileSource));
40 } 31 }
41 // Creates and adds an image. 32 // Creates and adds an image.
42 function createThumbnail(src, imageClass) { 33 function createThumbnail(src, imageClass) {
43 var image = document.createElement('img'); 34 var image = document.createElement('img');
44 if (imageClass) { 35 if (imageClass) {
45 image.classList.add(imageClass); 36 image.classList.add(imageClass);
46 } 37 }
47 image.onload = function() { 38 image.onload = function() {
48 var link = createMostVisitedLink( 39 var link = createMostVisitedLink(
49 params, data.url, data.title, undefined, data.direction, 40 params, data.url, data.title, undefined, data.direction);
50 data.tileSource);
51 // Use blocker to prevent context menu from showing image-related items. 41 // Use blocker to prevent context menu from showing image-related items.
52 var blocker = document.createElement('span'); 42 var blocker = document.createElement('span');
53 blocker.className = 'blocker'; 43 blocker.className = 'blocker';
54 link.appendChild(blocker); 44 link.appendChild(blocker);
55 link.appendChild(image); 45 link.appendChild(image);
56 displayLink(link); 46 displayLink(link);
57 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE_LOADED);
58 }; 47 };
59 image.onerror = function() { 48 image.onerror = function() {
60 // If no external thumbnail fallback (etfb), and have domain. 49 // If no external thumbnail fallback (etfb), and have domain.
61 if (!params.etfb && data.domain) { 50 if (!params.etfb && data.domain) {
62 showDomainElement(); 51 showDomainElement();
63 } else { 52 } else {
64 showEmptyTile(); 53 showEmptyTile();
65 } 54 }
66 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE_LOADED);
67 }; 55 };
68 image.src = src; 56 image.src = src;
69 } 57 }
70 58
71 var useIcons = params['icons'] == '1'; 59 var useIcons = params['icons'] == '1';
72 if (data.dummy) { 60 if (data.dummy) {
73 showEmptyTile(); 61 showEmptyTile();
74 } else if (useIcons && data.largeIconUrl) { 62 } else if (useIcons && data.largeIconUrl) {
75 createThumbnail(data.largeIconUrl, 'large-icon'); 63 createThumbnail(data.largeIconUrl, 'large-icon');
76 // TODO(huangs): Log event for large icons.
77 } else if (!useIcons && data.thumbnailUrls && data.thumbnailUrls.length) { 64 } else if (!useIcons && data.thumbnailUrls && data.thumbnailUrls.length) {
78 createThumbnail(data.thumbnailUrls[0], 'thumbnail'); 65 createThumbnail(data.thumbnailUrls[0], 'thumbnail');
79 } else if (data.domain) { 66 } else if (data.domain) {
80 showDomainElement(); 67 showDomainElement();
81 } else { 68 } else {
82 showEmptyTile(); 69 showEmptyTile();
83 } 70 }
84 logEvent(NTP_LOGGING_EVENT_TYPE.NTP_TILE);
85
86 // Log an impression if we know the position of the tile.
87 if (isFinite(params.pos)) {
88 logMostVisitedImpression(parseInt(params.pos, 10), data.tileSource);
89 }
90 }); 71 });
91 }); 72 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/local_ntp/most_visited_single.js ('k') | chrome/browser/resources/local_ntp/most_visited_title.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698