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

Side by Side Diff: chrome/browser/resources/ntp4/most_visited_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 ntp_stats.h.
12 * @enum {number}
13 */
14 var NtpFollowAction = {
Evan Stade 2012/04/24 20:29:44 this doesn't need to be defined twice, put it in n
macourteau 2012/04/26 19:10:14 Done.
15 CLICKED_TILE: 11,
16 CLICKED_OTHER_NTP_PANE: 12,
17 OTHER: 13
18 };
19
20 /**
11 * A counter for generating unique tile IDs. 21 * A counter for generating unique tile IDs.
12 */ 22 */
13 var tileID = 0; 23 var tileID = 0;
14 24
15 /** 25 /**
16 * Creates a new Most Visited object for tiling. 26 * Creates a new Most Visited object for tiling.
17 * @constructor 27 * @constructor
18 * @extends {HTMLAnchorElement} 28 * @extends {HTMLAnchorElement}
19 */ 29 */
20 function MostVisited() { 30 function MostVisited() {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Records an app launch from the most visited page (Chrome will decide 144 // Records an app launch from the most visited page (Chrome will decide
135 // whether the url is an app). TODO(estade): this only works for clicks; 145 // whether the url is an app). TODO(estade): this only works for clicks;
136 // other actions like "open in new tab" from the context menu won't be 146 // other actions like "open in new tab" from the context menu won't be
137 // recorded. Can this be fixed? 147 // recorded. Can this be fixed?
138 chrome.send('recordAppLaunchByURL', 148 chrome.send('recordAppLaunchByURL',
139 [encodeURIComponent(this.href), 149 [encodeURIComponent(this.href),
140 ntp.APP_LAUNCH.NTP_MOST_VISITED]); 150 ntp.APP_LAUNCH.NTP_MOST_VISITED]);
141 // Records the index of this tile. 151 // Records the index of this tile.
142 chrome.send('metricsHandler:recordInHistogram', 152 chrome.send('metricsHandler:recordInHistogram',
143 ['NewTabPage.MostVisited', this.index, 8]); 153 ['NewTabPage.MostVisited', this.index, 8]);
154 chrome.send('mostVisitedAction',
155 [NtpFollowAction.CLICKED_TILE]);
144 } 156 }
145 }, 157 },
146 158
147 /** 159 /**
148 * Allow blacklisting most visited site using the keyboard. 160 * Allow blacklisting most visited site using the keyboard.
149 */ 161 */
150 handleKeyDown_: function(e) { 162 handleKeyDown_: function(e) {
151 if (!cr.isMac && e.keyCode == 46 || // Del 163 if (!cr.isMac && e.keyCode == 46 || // Del
152 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace 164 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace
153 this.blacklist_(); 165 this.blacklist_();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return el; 294 return el;
283 } 295 }
284 296
285 MostVisitedPage.prototype = { 297 MostVisitedPage.prototype = {
286 __proto__: TilePage.prototype, 298 __proto__: TilePage.prototype,
287 299
288 initialize: function() { 300 initialize: function() {
289 this.classList.add('most-visited-page'); 301 this.classList.add('most-visited-page');
290 this.data_ = null; 302 this.data_ = null;
291 this.mostVisitedTiles_ = this.getElementsByClassName('most-visited real'); 303 this.mostVisitedTiles_ = this.getElementsByClassName('most-visited real');
304
305 this.addEventListener('carddeselected', this.handleCardDeselected_);
306 this.addEventListener('cardselected', this.handleCardSelected_);
292 }, 307 },
293 308
294 /** 309 /**
295 * Create blank (filler) tiles. 310 * Create blank (filler) tiles.
296 * @private 311 * @private
297 */ 312 */
298 createTiles_: function() { 313 createTiles_: function() {
299 for (var i = 0; i < THUMBNAIL_COUNT; i++) { 314 for (var i = 0; i < THUMBNAIL_COUNT; i++) {
300 this.appendTile(new MostVisited()); 315 this.appendTile(new MostVisited());
301 } 316 }
302 }, 317 },
303 318
304 /** 319 /**
305 * Update the tiles after a change to |data_|. 320 * Update the tiles after a change to |data_|.
306 */ 321 */
307 updateTiles_: function() { 322 updateTiles_: function() {
308 for (var i = 0; i < THUMBNAIL_COUNT; i++) { 323 for (var i = 0; i < THUMBNAIL_COUNT; i++) {
309 var page = this.data_[i]; 324 var page = this.data_[i];
310 var tile = this.mostVisitedTiles_[i]; 325 var tile = this.mostVisitedTiles_[i];
311 326
312 if (i >= this.data_.length) 327 if (i >= this.data_.length)
313 tile.reset(); 328 tile.reset();
314 else 329 else
315 tile.updateForData(page); 330 tile.updateForData(page);
316 } 331 }
317 }, 332 },
318 333
319 /** 334 /**
335 * Handles the 'card deselected' event (i.e. the user clicked to another
336 * pane).
337 * @param {Event} e The CardChanged event.
338 */
339 handleCardDeselected_: function(e) {
340 if (!document.documentElement.classList.contains('starting-up')) {
341 chrome.send('mostVisitedAction',
342 [NtpFollowAction.CLICKED_OTHER_NTP_PANE]);
343 }
344 },
345
346 /**
347 * Handles the 'card selected' event (i.e. the user clicked to select the
348 * Most Visited pane).
349 * @param {Event} e The CardChanged event.
350 */
351 handleCardSelected_: function(e) {
352 if (!document.documentElement.classList.contains('starting-up')) {
353 chrome.send('mostVisitedSelected');
354 }
355 },
356
357 /**
320 * Array of most visited data objects. 358 * Array of most visited data objects.
321 * @type {Array} 359 * @type {Array}
322 */ 360 */
323 get data() { 361 get data() {
324 return this.data_; 362 return this.data_;
325 }, 363 },
326 set data(data) { 364 set data(data) {
327 var startTime = Date.now(); 365 var startTime = Date.now();
328 366
329 // The first time data is set, create the tiles. 367 // The first time data is set, create the tiles.
(...skipping 11 matching lines...) Expand all
341 /** @inheritDoc */ 379 /** @inheritDoc */
342 shouldAcceptDrag: function(e) { 380 shouldAcceptDrag: function(e) {
343 return false; 381 return false;
344 }, 382 },
345 383
346 /** @inheritDoc */ 384 /** @inheritDoc */
347 heightForWidth: heightForWidth, 385 heightForWidth: heightForWidth,
348 }; 386 };
349 387
350 /** 388 /**
389 * Executed once the NTP has loaded. Checks if the Most Visited pane is
390 * shown or not.
391 */
392 MostVisitedPage.onLoaded = function() {
393 if (ntp.getCardSlider() && ntp.getCardSlider().currentCardValue) {
394 if (ntp.getCardSlider().currentCardValue.classList
395 .contains('most-visited-page')) {
396 chrome.send('mostVisitedSelected');
397 }
398 }
399 }
400
401 /**
351 * We've gotten additional Most Visited data. Update our old data with the 402 * We've gotten additional Most Visited data. Update our old data with the
352 * new data. The ordering of the new data is not important, except when a 403 * new data. The ordering of the new data is not important, except when a
353 * page is pinned. Thus we try to minimize re-ordering. 404 * page is pinned. Thus we try to minimize re-ordering.
354 * @param {Array} oldData The current Most Visited page list. 405 * @param {Array} oldData The current Most Visited page list.
355 * @param {Array} newData The new Most Visited page list. 406 * @param {Array} newData The new Most Visited page list.
356 * @return {Array} The merged page list that should replace the current page 407 * @return {Array} The merged page list that should replace the current page
357 * list. 408 * list.
358 */ 409 */
359 function refreshData(oldData, newData) { 410 function refreshData(oldData, newData) {
360 oldData = oldData.slice(0, THUMBNAIL_COUNT); 411 oldData = oldData.slice(0, THUMBNAIL_COUNT);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 468 }
418 469
419 return oldData; 470 return oldData;
420 }; 471 };
421 472
422 return { 473 return {
423 MostVisitedPage: MostVisitedPage, 474 MostVisitedPage: MostVisitedPage,
424 refreshData: refreshData, 475 refreshData: refreshData,
425 }; 476 };
426 }); 477 });
478
479 document.addEventListener('ntploaded', ntp.MostVisitedPage.onLoaded);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/ntp4/new_tab.js » ('j') | chrome/browser/ui/webui/ntp/ntp_stats.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698