summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/local_ntp/most_visited_single.js
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-07-14 17:41:05 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-08-04 12:37:36 +0000
commit399c965b6064c440ddcf4015f5f8e9d131c7a0a6 (patch)
tree6b06b60ff365abef0e13b3503d593a0df48d20e8 /chromium/chrome/browser/resources/local_ntp/most_visited_single.js
parent7366110654eec46f21b6824f302356426f48cd74 (diff)
BASELINE: Update Chromium to 52.0.2743.76 and Ninja to 1.7.1
Change-Id: I382f51b959689505a60f8b707255ecb344f7d8b4 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/chrome/browser/resources/local_ntp/most_visited_single.js')
-rw-r--r--chromium/chrome/browser/resources/local_ntp/most_visited_single.js148
1 files changed, 89 insertions, 59 deletions
diff --git a/chromium/chrome/browser/resources/local_ntp/most_visited_single.js b/chromium/chrome/browser/resources/local_ntp/most_visited_single.js
index 5a7350ac7e2..a17d779578c 100644
--- a/chromium/chrome/browser/resources/local_ntp/most_visited_single.js
+++ b/chromium/chrome/browser/resources/local_ntp/most_visited_single.js
@@ -67,6 +67,19 @@ var USE_ICONS = false;
*/
var NUM_TITLE_LINES = 1;
+/**
+ * Type of the impression provider for a generic client-provided suggestion.
+ * @type {string}
+ * @const
+ */
+var CLIENT_PROVIDER_NAME = 'client';
+
+/**
+ * Type of the impression provider for a generic server-provided suggestion.
+ * @type {string}
+ * @const
+ */
+var SERVER_PROVIDER_NAME = 'server';
/**
* The origin of this request.
@@ -110,6 +123,27 @@ var logEvent = function(eventType) {
chrome.embeddedSearch.newTabPage.logEvent(eventType);
};
+/**
+ * Log impression of a most visited tile on the NTP.
+ * @param {number} tileIndex position of the tile, >= 0 and < NUMBER_OF_TILES
+ * @param {string} provider specifies the UMA histogram to be reported
+ * (NewTabPage.SuggestionsImpression.{provider})
+ */
+function logMostVisitedImpression(tileIndex, provider) {
+ chrome.embeddedSearch.newTabPage.logMostVisitedImpression(tileIndex,
+ provider);
+}
+
+/**
+ * Log click on a most visited tile on the NTP.
+ * @param {number} tileIndex position of the tile, >= 0 and < NUMBER_OF_TILES
+ * @param {string} provider specifies the UMA histogram to be reported
+ * (NewTabPage.SuggestionsImpression.{provider})
+ */
+function logMostVisitedNavigation(tileIndex, provider) {
+ chrome.embeddedSearch.newTabPage.logMostVisitedNavigation(tileIndex,
+ provider);
+}
/**
* Down counts the DOM elements that we are waiting for the page to load.
@@ -284,22 +318,35 @@ var showTiles = function() {
* @param {object} args Data for the tile to be rendered.
*/
var addTile = function(args) {
- if (args.rid) {
+ if (isFinite(args.rid)) {
+ // If a valid number passed in |args.rid|: a local chrome suggestion.
var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid);
+ if (!data)
+ return;
+
data.tid = data.rid;
+ data.provider = CLIENT_PROVIDER_NAME;
if (!data.faviconUrl) {
data.faviconUrl = 'chrome-search://favicon/size/16@' +
window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid;
}
+ logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION);
tiles.appendChild(renderTile(data));
- } else if (args.id) {
+ } else if (args.url) {
+ // If a URL is passed: a server-side suggestion.
+ args.provider = args.provider || SERVER_PROVIDER_NAME;
+ // check sanity of the arguments
+ if (/^javascript:/i.test(args.url) ||
+ /^javascript:/i.test(args.thumbnailUrl) ||
+ !/^[a-z0-9]{0,8}$/i.test(args.provider))
+ return;
+ logEvent(LOG_TYPE.NTP_SERVER_SIDE_SUGGESTION);
tiles.appendChild(renderTile(args));
- } else {
+ } else { // an empty tile
tiles.appendChild(renderTile(null));
}
};
-
/**
* Called when the user decided to add a tile to the blacklist.
* It sets of the animation for the blacklist and sends the blacklisted id
@@ -343,6 +390,11 @@ var renderTile = function(data) {
}
logEvent(LOG_TYPE.NTP_TILE);
+ // The tile will be appended to tiles.
+ var position = tiles.children.length;
+ if (data.provider) {
+ logMostVisitedImpression(position, data.provider);
+ }
tile.className = 'mv-tile';
tile.setAttribute('data-tid', data.tid);
@@ -367,10 +419,15 @@ var renderTile = function(data) {
navigator.sendBeacon(data.pingUrl);
});
}
- // For local suggestions, we use navigateContentWindow instead of the default
- // action, since it includes support for file:// urls.
- if (data.rid) {
- tile.addEventListener('click', function(ev) {
+
+ tile.addEventListener('click', function(ev) {
+ if (data.provider) {
+ logMostVisitedNavigation(position, data.provider);
+ }
+
+ // For local suggestions, we use navigateContentWindow instead of the
+ // default action, since it includes support for file:// urls.
+ if (data.rid) {
ev.preventDefault();
var disp = chrome.embeddedSearch.newTabPage.getDispositionFromClick(
ev.button == 1, // MIDDLE BUTTON
@@ -378,8 +435,8 @@ var renderTile = function(data) {
window.chrome.embeddedSearch.newTabPage.navigateContentWindow(data.rid,
disp);
- });
- }
+ }
+ });
tile.addEventListener('keydown', function(event) {
if (event.keyCode == 46 /* DELETE */ ||
@@ -392,58 +449,31 @@ var renderTile = function(data) {
event.preventDefault();
this.click();
} else if (event.keyCode >= 37 && event.keyCode <= 40 /* ARROWS */) {
- var tiles = document.querySelectorAll('#mv-tiles .mv-tile');
+ // specify the direction of movement
+ var inArrowDirection = function(origin, target) {
+ return (event.keyCode == 37 /* LEFT */ &&
+ origin.offsetTop == target.offsetTop &&
+ origin.offsetLeft > target.offsetLeft) ||
+ (event.keyCode == 38 /* UP */ &&
+ origin.offsetTop > target.offsetTop &&
+ origin.offsetLeft == target.offsetLeft) ||
+ (event.keyCode == 39 /* RIGHT */ &&
+ origin.offsetTop == target.offsetTop &&
+ origin.offsetLeft < target.offsetLeft) ||
+ (event.keyCode == 40 /* DOWN */ &&
+ origin.offsetTop < target.offsetTop &&
+ origin.offsetLeft == target.offsetLeft);
+ };
+
+ var nonEmptyTiles = document.querySelectorAll('#mv-tiles .mv-tile');
var nextTile = null;
- // Use the location of the tile to find the next one in the
- // appropriate direction.
- // For LEFT and UP we keep iterating until we find the last element
- // that fulfills the conditions.
- // For RIGHT and DOWN we accept the first element that works.
- if (event.keyCode == 37 /* LEFT */) {
- for (var i = 0; i < tiles.length; i++) {
- var tile = tiles[i];
- if (tile.offsetTop == this.offsetTop &&
- tile.offsetLeft < this.offsetLeft) {
- if (!nextTile || tile.offsetLeft > nextTile.offsetLeft) {
- nextTile = tile;
- }
- }
- }
- }
- if (event.keyCode == 38 /* UP */) {
- for (var i = 0; i < tiles.length; i++) {
- var tile = tiles[i];
- if (tile.offsetTop < this.offsetTop &&
- tile.offsetLeft == this.offsetLeft) {
- if (!nextTile || tile.offsetTop > nextTile.offsetTop) {
- nextTile = tile;
- }
- }
- }
- }
- if (event.keyCode == 39 /* RIGHT */) {
- for (var i = 0; i < tiles.length; i++) {
- var tile = tiles[i];
- if (tile.offsetTop == this.offsetTop &&
- tile.offsetLeft > this.offsetLeft) {
- if (!nextTile || tile.offsetLeft < nextTile.offsetLeft) {
- nextTile = tile;
- }
- }
- }
- }
- if (event.keyCode == 40 /* DOWN */) {
- for (var i = 0; i < tiles.length; i++) {
- var tile = tiles[i];
- if (tile.offsetTop > this.offsetTop &&
- tile.offsetLeft == this.offsetLeft) {
- if (!nextTile || tile.offsetTop < nextTile.offsetTop) {
- nextTile = tile;
- }
- }
+ // Find the closest tile in the appropriate direction.
+ for (var i = 0; i < nonEmptyTiles.length; i++) {
+ if (inArrowDirection(this, nonEmptyTiles[i]) &&
+ (!nextTile || inArrowDirection(nonEmptyTiles[i], nextTile))) {
+ nextTile = nonEmptyTiles[i];
}
}
-
if (nextTile) {
nextTile.focus();
}