| OLD | NEW | 
|---|
| 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   /** | 
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 134         // Records an app launch from the most visited page (Chrome will decide | 134         // 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; | 135         // 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 | 136         // other actions like "open in new tab" from the context menu won't be | 
| 137         // recorded. Can this be fixed? | 137         // recorded. Can this be fixed? | 
| 138         chrome.send('recordAppLaunchByURL', | 138         chrome.send('recordAppLaunchByURL', | 
| 139                     [encodeURIComponent(this.href), | 139                     [encodeURIComponent(this.href), | 
| 140                      ntp.APP_LAUNCH.NTP_MOST_VISITED]); | 140                      ntp.APP_LAUNCH.NTP_MOST_VISITED]); | 
| 141         // Records the index of this tile. | 141         // Records the index of this tile. | 
| 142         chrome.send('metricsHandler:recordInHistogram', | 142         chrome.send('metricsHandler:recordInHistogram', | 
| 143                     ['NewTabPage.MostVisited', this.index, 8]); | 143                     ['NewTabPage.MostVisited', this.index, 8]); | 
|  | 144         chrome.send('mostVisitedAction', | 
|  | 145                     [ntp.NtpFollowAction.CLICKED_TILE]); | 
| 144       } | 146       } | 
| 145     }, | 147     }, | 
| 146 | 148 | 
| 147     /** | 149     /** | 
| 148      * Allow blacklisting most visited site using the keyboard. | 150      * Allow blacklisting most visited site using the keyboard. | 
| 149      */ | 151      */ | 
| 150     handleKeyDown_: function(e) { | 152     handleKeyDown_: function(e) { | 
| 151       if (!cr.isMac && e.keyCode == 46 || // Del | 153       if (!cr.isMac && e.keyCode == 46 || // Del | 
| 152           cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 154           cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 
| 153         this.blacklist_(); | 155         this.blacklist_(); | 
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 282     return el; | 284     return el; | 
| 283   } | 285   } | 
| 284 | 286 | 
| 285   MostVisitedPage.prototype = { | 287   MostVisitedPage.prototype = { | 
| 286     __proto__: TilePage.prototype, | 288     __proto__: TilePage.prototype, | 
| 287 | 289 | 
| 288     initialize: function() { | 290     initialize: function() { | 
| 289       this.classList.add('most-visited-page'); | 291       this.classList.add('most-visited-page'); | 
| 290       this.data_ = null; | 292       this.data_ = null; | 
| 291       this.mostVisitedTiles_ = this.getElementsByClassName('most-visited real'); | 293       this.mostVisitedTiles_ = this.getElementsByClassName('most-visited real'); | 
|  | 294 | 
|  | 295       this.addEventListener('carddeselected', this.handleCardDeselected_); | 
|  | 296       this.addEventListener('cardselected', this.handleCardSelected_); | 
| 292     }, | 297     }, | 
| 293 | 298 | 
| 294     /** | 299     /** | 
| 295      * Create blank (filler) tiles. | 300      * Create blank (filler) tiles. | 
| 296      * @private | 301      * @private | 
| 297      */ | 302      */ | 
| 298     createTiles_: function() { | 303     createTiles_: function() { | 
| 299       for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 304       for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 
| 300         this.appendTile(new MostVisited()); | 305         this.appendTile(new MostVisited()); | 
| 301       } | 306       } | 
| 302     }, | 307     }, | 
| 303 | 308 | 
| 304     /** | 309     /** | 
| 305      * Update the tiles after a change to |data_|. | 310      * Update the tiles after a change to |data_|. | 
| 306      */ | 311      */ | 
| 307     updateTiles_: function() { | 312     updateTiles_: function() { | 
| 308       for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 313       for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 
| 309         var page = this.data_[i]; | 314         var page = this.data_[i]; | 
| 310         var tile = this.mostVisitedTiles_[i]; | 315         var tile = this.mostVisitedTiles_[i]; | 
| 311 | 316 | 
| 312         if (i >= this.data_.length) | 317         if (i >= this.data_.length) | 
| 313           tile.reset(); | 318           tile.reset(); | 
| 314         else | 319         else | 
| 315           tile.updateForData(page); | 320           tile.updateForData(page); | 
| 316       } | 321       } | 
| 317     }, | 322     }, | 
| 318 | 323 | 
| 319     /** | 324     /** | 
|  | 325      * Handles the 'card deselected' event (i.e. the user clicked to another | 
|  | 326      * pane). | 
|  | 327      * @param {Event} e The CardChanged event. | 
|  | 328      */ | 
|  | 329     handleCardDeselected_: function(e) { | 
|  | 330       if (!document.documentElement.classList.contains('starting-up')) { | 
|  | 331         chrome.send('mostVisitedAction', | 
|  | 332                     [ntp.NtpFollowAction.CLICKED_OTHER_NTP_PANE]); | 
|  | 333       } | 
|  | 334     }, | 
|  | 335 | 
|  | 336     /** | 
|  | 337      * Handles the 'card selected' event (i.e. the user clicked to select the | 
|  | 338      * Most Visited pane). | 
|  | 339      * @param {Event} e The CardChanged event. | 
|  | 340      */ | 
|  | 341     handleCardSelected_: function(e) { | 
|  | 342       if (!document.documentElement.classList.contains('starting-up')) | 
|  | 343         chrome.send('mostVisitedSelected'); | 
|  | 344     }, | 
|  | 345 | 
|  | 346     /** | 
| 320      * Array of most visited data objects. | 347      * Array of most visited data objects. | 
| 321      * @type {Array} | 348      * @type {Array} | 
| 322      */ | 349      */ | 
| 323     get data() { | 350     get data() { | 
| 324       return this.data_; | 351       return this.data_; | 
| 325     }, | 352     }, | 
| 326     set data(data) { | 353     set data(data) { | 
| 327       var startTime = Date.now(); | 354       var startTime = Date.now(); | 
| 328 | 355 | 
| 329       // The first time data is set, create the tiles. | 356       // The first time data is set, create the tiles. | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 341     /** @inheritDoc */ | 368     /** @inheritDoc */ | 
| 342     shouldAcceptDrag: function(e) { | 369     shouldAcceptDrag: function(e) { | 
| 343       return false; | 370       return false; | 
| 344     }, | 371     }, | 
| 345 | 372 | 
| 346     /** @inheritDoc */ | 373     /** @inheritDoc */ | 
| 347     heightForWidth: heightForWidth, | 374     heightForWidth: heightForWidth, | 
| 348   }; | 375   }; | 
| 349 | 376 | 
| 350   /** | 377   /** | 
|  | 378    * Executed once the NTP has loaded. Checks if the Most Visited pane is | 
|  | 379    * shown or not. If it is shown, the 'mostVisitedSelected' message is sent | 
|  | 380    * to the C++ code, to record the fact that the user has seen this pane. | 
|  | 381    */ | 
|  | 382   MostVisitedPage.onLoaded = function() { | 
|  | 383     if (ntp.getCardSlider() && | 
|  | 384         ntp.getCardSlider().currentCardValue && | 
|  | 385         ntp.getCardSlider().currentCardValue.classList | 
|  | 386         .contains('most-visited-page')) { | 
|  | 387       chrome.send('mostVisitedSelected'); | 
|  | 388     } | 
|  | 389   } | 
|  | 390 | 
|  | 391   /** | 
| 351    * We've gotten additional Most Visited data. Update our old data with the | 392    * 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 | 393    * 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. | 394    * page is pinned. Thus we try to minimize re-ordering. | 
| 354    * @param {Array} oldData The current Most Visited page list. | 395    * @param {Array} oldData The current Most Visited page list. | 
| 355    * @param {Array} newData The new Most Visited page list. | 396    * @param {Array} newData The new Most Visited page list. | 
| 356    * @return {Array} The merged page list that should replace the current page | 397    * @return {Array} The merged page list that should replace the current page | 
| 357    *     list. | 398    *     list. | 
| 358    */ | 399    */ | 
| 359   function refreshData(oldData, newData) { | 400   function refreshData(oldData, newData) { | 
| 360     oldData = oldData.slice(0, THUMBNAIL_COUNT); | 401     oldData = oldData.slice(0, THUMBNAIL_COUNT); | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 417     } | 458     } | 
| 418 | 459 | 
| 419     return oldData; | 460     return oldData; | 
| 420   }; | 461   }; | 
| 421 | 462 | 
| 422   return { | 463   return { | 
| 423     MostVisitedPage: MostVisitedPage, | 464     MostVisitedPage: MostVisitedPage, | 
| 424     refreshData: refreshData, | 465     refreshData: refreshData, | 
| 425   }; | 466   }; | 
| 426 }); | 467 }); | 
|  | 468 | 
|  | 469 document.addEventListener('ntpLoaded', ntp.MostVisitedPage.onLoaded); | 
| OLD | NEW | 
|---|