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

Side by Side Diff: chrome/browser/resources/ntp4/suggestions_page.js

Issue 10182006: Adds the MostVisitedAction stat. This stat will provide a baseline to compare (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Sync'ed. Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('ntp', function() { 5 cr.define('ntp', function() {
6 'use strict'; 6 'use strict';
7 7
8 var TilePage = ntp.TilePage; 8 var TilePage = ntp.TilePage;
9 9
10 /** 10 /**
11 * See description for these values in suggestions_page_handler.h. 11 * See description for these values in ntp_stats.h.
12 * @enum {number} 12 * @enum {number}
13 */ 13 */
14 var SuggestedSitesAction = { 14 var NtpFollowAction = {
15 CLICKED_SUGGESTED_TILE: 11, 15 CLICKED_TILE: 11,
16 CLICKED_OTHER_NTP_PANE: 12, 16 CLICKED_OTHER_NTP_PANE: 12,
17 OTHER: 13 17 OTHER: 13
18 }; 18 };
19 19
20 /** 20 /**
21 * A counter for generating unique tile IDs. 21 * A counter for generating unique tile IDs.
22 */ 22 */
23 var tileID = 0; 23 var tileID = 0;
24 24
25 /** 25 /**
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 */ 138 */
139 handleClick_: function(e) { 139 handleClick_: function(e) {
140 if (e.target.classList.contains('close-button')) { 140 if (e.target.classList.contains('close-button')) {
141 this.blacklist_(); 141 this.blacklist_();
142 e.preventDefault(); 142 e.preventDefault();
143 } else { 143 } else {
144 // Records the index of this tile. 144 // Records the index of this tile.
145 chrome.send('metricsHandler:recordInHistogram', 145 chrome.send('metricsHandler:recordInHistogram',
146 ['NewTabPage.SuggestedSite', this.index, 8]); 146 ['NewTabPage.SuggestedSite', this.index, 8]);
147 chrome.send('suggestedSitesAction', 147 chrome.send('suggestedSitesAction',
148 [SuggestedSitesAction.CLICKED_SUGGESTED_TILE]); 148 [NtpFollowAction.CLICKED_TILE]);
149 } 149 }
150 }, 150 },
151 151
152 /** 152 /**
153 * Allow blacklisting suggestions site using the keyboard. 153 * Allow blacklisting suggestions site using the keyboard.
154 * @param {Event} e The keydown event. 154 * @param {Event} e The keydown event.
155 */ 155 */
156 handleKeyDown_: function(e) { 156 handleKeyDown_: function(e) {
157 if (!cr.isMac && e.keyCode == 46 || // Del 157 if (!cr.isMac && e.keyCode == 46 || // Del
158 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace 158 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 tile.updateForData(page); 327 tile.updateForData(page);
328 } 328 }
329 }, 329 },
330 330
331 /** 331 /**
332 * Handles the 'card deselected' event (i.e. the user clicked to another 332 * Handles the 'card deselected' event (i.e. the user clicked to another
333 * pane). 333 * pane).
334 * @param {Event} e The CardChanged event. 334 * @param {Event} e The CardChanged event.
335 */ 335 */
336 handleCardDeselected_: function(e) { 336 handleCardDeselected_: function(e) {
337 chrome.send('suggestedSitesAction', 337 if (!document.documentElement.classList.contains('starting-up')) {
338 [SuggestedSitesAction.CLICKED_OTHER_NTP_PANE]); 338 chrome.send('suggestedSitesAction',
339 [NtpFollowAction.CLICKED_OTHER_NTP_PANE]);
340 }
339 }, 341 },
340 342
341 /** 343 /**
342 * Handles the 'card selected' event (i.e. the user clicked to select the 344 * Handles the 'card selected' event (i.e. the user clicked to select the
343 * Suggested pane). 345 * Suggested pane).
344 * @param {Event} e The CardChanged event. 346 * @param {Event} e The CardChanged event.
345 */ 347 */
346 handleCardSelected_: function(e) { 348 handleCardSelected_: function(e) {
347 chrome.send('suggestedSitesSelected'); 349 if (!document.documentElement.classList.contains('starting-up')) {
350 chrome.send('suggestedSitesSelected');
351 }
348 }, 352 },
349 353
350 /** 354 /**
351 * Array of suggestions data objects. 355 * Array of suggestions data objects.
352 * @type {Array} 356 * @type {Array}
353 */ 357 */
354 get data() { 358 get data() {
355 return this.data_; 359 return this.data_;
356 }, 360 },
357 set data(data) { 361 set data(data) {
(...skipping 14 matching lines...) Expand all
372 /** @inheritDoc */ 376 /** @inheritDoc */
373 shouldAcceptDrag: function(e) { 377 shouldAcceptDrag: function(e) {
374 return false; 378 return false;
375 }, 379 },
376 380
377 /** @inheritDoc */ 381 /** @inheritDoc */
378 heightForWidth: heightForWidth, 382 heightForWidth: heightForWidth,
379 }; 383 };
380 384
381 /** 385 /**
386 * Executed once the NTP has loaded. Checks if the Suggested pane is
387 * shown or not.
388 */
389 SuggestionsPage.onLoaded = function() {
390 if (ntp.getCardSlider() && ntp.getCardSlider().currentCardValue) {
391 if (ntp.getCardSlider().currentCardValue.classList
392 .contains('suggestions-page')) {
393 chrome.send('suggestedSitesSelected');
394 }
395 }
396 }
397
398 /**
382 * We've gotten additional data for Suggestions page. Update our old data with 399 * We've gotten additional data for Suggestions page. Update our old data with
383 * the new data. The ordering of the new data is not important, except when a 400 * the new data. The ordering of the new data is not important, except when a
384 * page is pinned. Thus we try to minimize re-ordering. 401 * page is pinned. Thus we try to minimize re-ordering.
385 * @param {Array} oldData The current Suggestions page list. 402 * @param {Array} oldData The current Suggestions page list.
386 * @param {Array} newData The new Suggestions page list. 403 * @param {Array} newData The new Suggestions page list.
387 * @return {Array} The merged page list that should replace the current page 404 * @return {Array} The merged page list that should replace the current page
388 * list. 405 * list.
389 */ 406 */
390 function refreshData(oldData, newData) { 407 function refreshData(oldData, newData) {
391 oldData = oldData.slice(0, THUMBNAIL_COUNT); 408 oldData = oldData.slice(0, THUMBNAIL_COUNT);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 465 }
449 466
450 return oldData; 467 return oldData;
451 } 468 }
452 469
453 return { 470 return {
454 SuggestionsPage: SuggestionsPage, 471 SuggestionsPage: SuggestionsPage,
455 refreshData: refreshData, 472 refreshData: refreshData,
456 }; 473 };
457 }); 474 });
475
476 document.addEventListener('ntploaded', ntp.SuggestionsPage.onLoaded);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698