diff options
28 files changed, 29 insertions, 1302 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index c066fd0..7ac99c1 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -46,9 +46,9 @@ #include "chrome/browser/extensions/updater/extension_updater.h" #include "chrome/browser/google/google_brand.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/thumbnail_source.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/ui/webui/favicon_source.h" -#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" #include "chrome/browser/ui/webui/theme_source.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/crash_keys.h" diff --git a/chrome/browser/history/DEPS b/chrome/browser/history/DEPS index 9ebef2a..fc79fa5 100644 --- a/chrome/browser/history/DEPS +++ b/chrome/browser/history/DEPS @@ -53,6 +53,7 @@ specific_include_rules = { "+chrome/browser/ui/profile_error_dialog.h", "+components/bookmarks/browser", "+components/keyed_service/content", + "+components/pref_registry", ], # Those files will move to //components/history/content/browser and thus # can depend on //content even indirectly. diff --git a/chrome/browser/history/top_sites_factory.cc b/chrome/browser/history/top_sites_factory.cc index 0c56d8c..114d9c9 100644 --- a/chrome/browser/history/top_sites_factory.cc +++ b/chrome/browser/history/top_sites_factory.cc @@ -17,6 +17,7 @@ #include "components/history/core/browser/history_constants.h" #include "components/history/core/browser/top_sites_impl.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "components/pref_registry/pref_registry_syncable.h" #include "content/public/browser/browser_thread.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -115,6 +116,11 @@ scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( return BuildTopSites(context, prepopulated_pages); } +void TopSitesFactory::RegisterProfilePrefs( + user_prefs::PrefRegistrySyncable* registry) { + registry->RegisterDictionaryPref(prefs::kNtpMostVisitedURLsBlacklist); +} + bool TopSitesFactory::ServiceIsNULLWhileTesting() const { return true; } diff --git a/chrome/browser/history/top_sites_factory.h b/chrome/browser/history/top_sites_factory.h index 0f1e811..8794a11 100644 --- a/chrome/browser/history/top_sites_factory.h +++ b/chrome/browser/history/top_sites_factory.h @@ -47,6 +47,8 @@ class TopSitesFactory : public RefcountedBrowserContextKeyedServiceFactory { // Overridden from BrowserContextKeyedServiceFactory. scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( content::BrowserContext* context) const override; + void RegisterProfilePrefs( + user_prefs::PrefRegistrySyncable* registry) override; bool ServiceIsNULLWhileTesting() const override; DISALLOW_COPY_AND_ASSIGN(TopSitesFactory); diff --git a/chrome/browser/resources/ntp4/apps_page.js b/chrome/browser/resources/ntp4/apps_page.js index bdbefcb..6fbff6b 100644 --- a/chrome/browser/resources/ntp4/apps_page.js +++ b/chrome/browser/resources/ntp4/apps_page.js @@ -20,8 +20,8 @@ cr.define('ntp', function() { var DRAG_SOURCE = { SAME_APPS_PANE: 0, OTHER_APPS_PANE: 1, - MOST_VISITED_PANE: 2, - BOOKMARKS_PANE: 3, + MOST_VISITED_PANE: 2, // Deprecated. + BOOKMARKS_PANE: 3, // Deprecated. OUTSIDE_NTP: 4 }; var DRAG_SOURCE_LIMIT = DRAG_SOURCE.OUTSIDE_NTP + 1; @@ -683,9 +683,6 @@ cr.define('ntp', function() { originalPage.fireRemovedEvent(currentlyDraggingTile, index, true); this.fireAddedEvent(currentlyDraggingTile, index, true); } - } else if (currentlyDraggingTile.querySelector('.most-visited')) { - this.generateAppForLink(tileContents.data); - sourceId = DRAG_SOURCE.MOST_VISITED_PANE; } } else { this.addOutsideData_(dataTransfer); diff --git a/chrome/browser/resources/ntp4/compiled_resources.gyp b/chrome/browser/resources/ntp4/compiled_resources.gyp index 7a0a597..ce10d49 100644 --- a/chrome/browser/resources/ntp4/compiled_resources.gyp +++ b/chrome/browser/resources/ntp4/compiled_resources.gyp @@ -33,7 +33,6 @@ 'logging.js', 'tile_page.js', 'dot_list.js', - 'most_visited_page.js', 'trash.js', 'page_switcher.js', 'page_list_view.js', diff --git a/chrome/browser/resources/ntp4/most_visited_page.css b/chrome/browser/resources/ntp4/most_visited_page.css deleted file mode 100644 index 0bc0abc..0000000 --- a/chrome/browser/resources/ntp4/most_visited_page.css +++ /dev/null @@ -1,186 +0,0 @@ -/* Copyright (c) 2012 The Chromium Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. */ - -.most-visited { - position: absolute; - z-index: 0; -} - -.most-visited { - -webkit-box-orient: vertical; - display: -webkit-box; - position: absolute; - text-decoration: none; -} - -.most-visited:focus { - outline: none; -} - -.fills-parent { - bottom: 0; - display: -webkit-box; - left: 0; - position: absolute; - right: 0; - top: 0; -} - -/* filler mode: hide everything except the thumbnail --- leave a grey rectangle - * in its place. */ -.filler * { - visibility: hidden; -} - -.filler { - pointer-events: none; -} - -.most-visited .close-button { - -webkit-transition: opacity 150ms; - opacity: 0; - position: absolute; - right: 0; - top: 0; - z-index: 5; -} - -html[dir=rtl] .most-visited .close-button { - left: 0; - right: auto; -} - -.most-visited:hover .close-button { - -webkit-transition-delay: 500ms; - opacity: 1; -} - -.most-visited .close-button:hover { - -webkit-transition: none; -} - -.most-visited .favicon { - -webkit-margin-start: 5px; - background: no-repeat left 50%; - background-size: 16px; - bottom: 7px; - box-sizing: border-box; - display: block; - height: 16px; - position: absolute; - width: 16px; -} - -html[dir='rtl'] .most-visited .favicon { - background-position-x: right; -} - -.most-visited .color-stripe { - border-bottom-left-radius: 3px 3px; - border-bottom-right-radius: 3px 3px; - /* Matches height of title. */ - bottom: 23px; - height: 3px; - /* Matches padding-top of the title. */ - margin-bottom: 8px; - position: absolute; - width: 100%; - z-index: 10; -} - -.most-visited .title { - display: block; - height: 23px; - overflow: hidden; - padding-top: 8px; - text-align: center; - text-overflow: ellipsis; - white-space: nowrap; -} - -.thumbnail { - -webkit-transition: opacity 150ms; - background: no-repeat; - /* This shows for missing thumbnails. */ - background-color: #eee; - background-size: 100%; - border-radius: 3px; - /* These max dimensions are not necessary, as the sizing logic in the .js - * should be sufficient, but they're here for extra insurance. We never want - * to scale a thumbnail larger than this size. */ - max-height: 132px; - max-width: 212px; -} - -.filler .thumbnail { - /* TODO(estade): there seems to be a webkit bug where this border is not - * always removed when it should be. Investigate. */ - border: 1px solid; - visibility: visible; -} - -.thumbnail-shield { - background: -webkit-linear-gradient(rgba(255, 255, 255, 0), - rgba(255, 255, 255, 0) 50%, - rgba(255, 255, 255, 0.9)); - border-radius: 3px; -} - -/* TODO(dbeam): Remove this when printing of -webkit-linear-gradient() works. */ -@media print { - .thumbnail-shield { - background: none; - } -} - -.most-visited:focus .thumbnail, -.most-visited:hover .thumbnail { - opacity: 0.95; -} - -.most-visited:focus .thumbnail-shield, -.most-visited:hover .thumbnail-shield, -.most-visited:active .thumbnail-shield { - background: -webkit-linear-gradient(rgba(255, 255, 255, 0), - rgba(255, 255, 255, 0) 80%, - rgba(255, 255, 255, 0.9)); -} - -/* The thumbnail gets lighter when clicked, but not when the click is on the - * close button. */ -.most-visited:active .close-button:not(:active) + .thumbnail { - opacity: 0.9; -} - -/* The thumbnail gets a shadow when clicked, but not when the click is on the - * close button. */ -.most-visited:active .close-button:not(:active) + .thumbnail .thumbnail-shield { - box-shadow: inset 0 1px 10px rgba(0, 0, 0, 0.2); -} - -.thumbnail-wrapper { - -webkit-box-flex: 1; - -webkit-transition: background-color 150ms; - border: 1px solid transparent; - border-radius: 3px; - display: block; - position: relative; - z-index: 5; -} - -.filler .thumbnail-wrapper { - visibility: visible; -} - -/* 'finishing-drag' is the state we are in after dropping on the trash can. - * Override opacity of the tile to 1, so that the new tile animation - * occurs simultaneously with the trash animation. */ -.tile.dragging.finishing-drag { - opacity: 1; -} - -/* Don't display the new tile until there's something to show. */ -.blacklisted { - opacity: 0; -} diff --git a/chrome/browser/resources/ntp4/most_visited_page.js b/chrome/browser/resources/ntp4/most_visited_page.js deleted file mode 100644 index 4f6cbd1..0000000 --- a/chrome/browser/resources/ntp4/most_visited_page.js +++ /dev/null @@ -1,495 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -cr.define('ntp', function() { - 'use strict'; - - var TilePage = ntp.TilePage; - - /** - * A counter for generating unique tile IDs. - */ - var tileID = 0; - - /** - * Creates a new Most Visited object for tiling. - * @constructor - * @extends {HTMLAnchorElement} - */ - function MostVisited() { - var el = cr.doc.createElement('a'); - el.__proto__ = MostVisited.prototype; - el.initialize(); - - return el; - } - - MostVisited.prototype = { - __proto__: HTMLAnchorElement.prototype, - - initialize: function() { - this.reset(); - - this.addEventListener('click', this.handleClick_); - this.addEventListener('keydown', this.handleKeyDown_); - this.addEventListener('mouseover', this.handleMouseOver_); - }, - - get index() { - assert(this.tile); - return this.tile.index; - }, - - get data() { - return this.data_; - }, - - /** - * Clears the DOM hierarchy for this node, setting it back to the default - * for a blank thumbnail. - */ - reset: function() { - this.className = 'most-visited filler real'; - this.innerHTML = - '<span class="thumbnail-wrapper fills-parent">' + - '<div class="close-button"></div>' + - '<span class="thumbnail fills-parent">' + - // thumbnail-shield provides a gradient fade effect. - '<div class="thumbnail-shield fills-parent"></div>' + - '</span>' + - '<span class="favicon"></span>' + - '</span>' + - '<div class="color-stripe"></div>' + - '<span class="title"></span>'; - - this.querySelector('.close-button').title = - loadTimeData.getString('removethumbnailtooltip'); - - this.tabIndex = -1; - this.data_ = null; - this.removeAttribute('id'); - this.title = ''; - }, - - /** - * Update the appearance of this tile according to |data|. - * @param {PageData} data A dictionary of relevant data for the page. - */ - updateForData: function(data) { - if (this.classList.contains('blacklisted') && data) { - // Animate appearance of new tile. - this.classList.add('new-tile-contents'); - } - this.classList.remove('blacklisted'); - - if (!data || data.filler) { - if (this.data_) - this.reset(); - return; - } - - var id = tileID++; - this.id = 'most-visited-tile-' + id; - this.data_ = data; - this.classList.add('focusable'); - - var faviconDiv = this.querySelector('.favicon'); - faviconDiv.style.backgroundImage = getFaviconImageSet(data.url); - - // The favicon should have the same dominant color regardless of the - // device pixel ratio the favicon is requested for. - chrome.send('getFaviconDominantColor', - [getFaviconUrlForCurrentDevicePixelRatio(data.url), this.id]); - - var title = this.querySelector('.title'); - title.textContent = data.title; - title.dir = data.direction; - - // Sets the tooltip. - this.title = data.title; - - var thumbnailUrl = 'chrome://thumb/' + data.url; - this.querySelector('.thumbnail').style.backgroundImage = - url(thumbnailUrl); - - this.href = data.url; - - this.classList.remove('filler'); - }, - - /** - * Sets the color of the favicon dominant color bar. - * @param {string} color The css-parsable value for the color. - */ - set stripeColor(color) { - this.querySelector('.color-stripe').style.backgroundColor = color; - }, - - /** - * Handles a click on the tile. - * @param {Event} e The click event. - */ - handleClick_: function(e) { - if (e.target.classList.contains('close-button')) { - this.blacklist_(); - e.preventDefault(); - } else { - ntp.logTimeToClick('MostVisited'); - // Records an app launch from the most visited page (Chrome will decide - // whether the url is an app). TODO(estade): this only works for clicks; - // other actions like "open in new tab" from the context menu won't be - // recorded. Can this be fixed? - chrome.send('recordAppLaunchByURL', - [encodeURIComponent(this.href), - ntp.APP_LAUNCH.NTP_MOST_VISITED]); - // Records the index of this tile. - chrome.send('metricsHandler:recordInHistogram', - ['NewTabPage.MostVisited', this.index, 8]); - // Records the action. This will be available as a time-stamped stream - // server-side and can be used to compute time-to-long-dwell. - chrome.send('metricsHandler:recordAction', ['MostVisited_Clicked']); - chrome.send('mostVisitedAction', - [ntp.NtpFollowAction.CLICKED_TILE]); - } - }, - - /** - * Allow blacklisting most visited site using the keyboard. - */ - handleKeyDown_: function(e) { - if (!cr.isMac && e.keyCode == 46 || // Del - cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace - this.blacklist_(); - } - }, - - /** - * The mouse has entered a Most Visited tile div. Only log the first - * mouseover event. By doing this we solve the issue with the mouseover - * event listener that bubbles up to the parent, which would cause it to - * fire multiple times even if the mouse stays within one tile. - */ - handleMouseOver_: function(e) { - var self = this; - var ancestor = findAncestor(e.relatedTarget, function(node) { - return node == self; - }); - // If ancestor is null, mouse is entering the parent element. - if (ancestor == null) - chrome.send('metricsHandler:logMouseover'); - }, - - /** - * Permanently removes a page from Most Visited. - */ - blacklist_: function() { - this.showUndoNotification_(); - chrome.send('blacklistURLFromMostVisited', [this.data_.url]); - this.reset(); - chrome.send('getMostVisited'); - this.classList.add('blacklisted'); - }, - - showUndoNotification_: function() { - var data = this.data_; - var self = this; - var doUndo = function() { - chrome.send('removeURLsFromMostVisitedBlacklist', [data.url]); - self.updateForData(data); - }; - - var undo = { - action: doUndo, - text: loadTimeData.getString('undothumbnailremove'), - }; - - var undoAll = { - action: function() { - chrome.send('clearMostVisitedURLsBlacklist'); - }, - text: loadTimeData.getString('restoreThumbnailsShort'), - }; - - ntp.showNotification( - loadTimeData.getString('thumbnailremovednotification'), - [undo, undoAll]); - }, - - /** - * Set the size and position of the most visited tile. - * @param {number} size The total size of |this|. - * @param {number} x The x-position. - * @param {number} y The y-position. - * animate. - */ - setBounds: function(size, x, y) { - this.style.width = toCssPx(size); - this.style.height = toCssPx(heightForWidth(size)); - - this.style.left = toCssPx(x); - this.style.right = toCssPx(x); - this.style.top = toCssPx(y); - }, - - /** - * Returns whether this element can be 'removed' from chrome (i.e. whether - * the user can drag it onto the trash and expect something to happen). - * @return {boolean} True, since most visited pages can always be - * blacklisted. - */ - canBeRemoved: function() { - return true; - }, - - /** - * Removes this element from chrome, i.e. blacklists it. - */ - removeFromChrome: function() { - this.blacklist_(); - this.parentNode.classList.add('finishing-drag'); - }, - - /** - * Called when a drag of this tile has ended (after all animations have - * finished). - */ - finalizeDrag: function() { - this.parentNode.classList.remove('finishing-drag'); - }, - - /** - * Called when a drag is starting on the tile. Updates dataTransfer with - * data for this tile (for dragging outside of the NTP). - */ - setDragData: function(dataTransfer) { - dataTransfer.setData('Text', this.data_.title); - dataTransfer.setData('URL', this.data_.url); - }, - }; - - var mostVisitedPageGridValues = { - // The fewest tiles we will show in a row. - minColCount: 2, - // The most tiles we will show in a row. - maxColCount: 4, - - // The smallest a tile can be. - minTileWidth: 122, - // The biggest a tile can be. 212 (max thumbnail width) + 2. - maxTileWidth: 214, - - // The padding between tiles, as a fraction of the tile width. - tileSpacingFraction: 1 / 8, - }; - TilePage.initGridValues(mostVisitedPageGridValues); - - /** - * Calculates the height for a Most Visited tile for a given width. The size - * is based on the thumbnail, which should have a 212:132 ratio. - * @return {number} The height. - */ - function heightForWidth(width) { - // The 2s are for borders, the 31 is for the title. - return (width - 2) * 132 / 212 + 2 + 31; - } - - var THUMBNAIL_COUNT = 8; - - /** - * Creates a new MostVisitedPage object. - * @constructor - * @extends {ntp.TilePage} - */ - function MostVisitedPage() { - var el = new TilePage(mostVisitedPageGridValues); - el.__proto__ = MostVisitedPage.prototype; - el.initialize(); - - return el; - } - - MostVisitedPage.prototype = { - __proto__: TilePage.prototype, - - initialize: function() { - this.classList.add('most-visited-page'); - this.data_ = null; - this.mostVisitedTiles_ = this.getElementsByClassName('most-visited real'); - - this.addEventListener('carddeselected', this.handleCardDeselected_); - this.addEventListener('cardselected', this.handleCardSelected_); - }, - - /** - * Create blank (filler) tiles. - * @private - */ - createTiles_: function() { - for (var i = 0; i < THUMBNAIL_COUNT; i++) { - this.appendTile(new MostVisited(), false); - } - }, - - /** - * Update the tiles after a change to |data_|. - */ - updateTiles_: function() { - for (var i = 0; i < THUMBNAIL_COUNT; i++) { - var page = this.data_[i]; - var tile = this.mostVisitedTiles_[i]; - - if (i >= this.data_.length) - tile.reset(); - else - tile.updateForData(page); - } - }, - - /** - * Handles the 'card deselected' event (i.e. the user clicked to another - * pane). - * @param {Event} e The CardChanged event. - */ - handleCardDeselected_: function(e) { - if (!document.documentElement.classList.contains('starting-up')) { - chrome.send('mostVisitedAction', - [ntp.NtpFollowAction.CLICKED_OTHER_NTP_PANE]); - } - }, - - /** - * Handles the 'card selected' event (i.e. the user clicked to select the - * Most Visited pane). - * @param {Event} e The CardChanged event. - */ - handleCardSelected_: function(e) { - if (!document.documentElement.classList.contains('starting-up')) - chrome.send('mostVisitedSelected'); - }, - - /** - * Array of most visited data objects. - * @type {Array<PageData>} - */ - get data() { - return this.data_; - }, - set data(data) { - var startTime = Date.now(); - - // The first time data is set, create the tiles. - if (!this.data_) { - this.createTiles_(); - this.data_ = data.slice(0, THUMBNAIL_COUNT); - } else { - this.data_ = refreshData(this.data_, data); - } - - this.updateTiles_(); - this.updateFocusableElement(); - logEvent('mostVisited.layout: ' + (Date.now() - startTime)); - }, - - /** @override */ - shouldAcceptDrag: function(e) { - return false; - }, - - /** @override */ - heightForWidth: heightForWidth, - }; - - /** - * Executed once the NTP has loaded. Checks if the Most Visited pane is - * shown or not. If it is shown, the 'mostVisitedSelected' message is sent - * to the C++ code, to record the fact that the user has seen this pane. - */ - MostVisitedPage.onLoaded = function() { - if (ntp.getCardSlider() && - ntp.getCardSlider().currentCardValue && - ntp.getCardSlider().currentCardValue.classList - .contains('most-visited-page')) { - chrome.send('mostVisitedSelected'); - } - }; - - /** - * We've gotten additional Most Visited data. Update our old data with the - * new data. The ordering of the new data is not important, except when a - * page is pinned. Thus we try to minimize re-ordering. - * @param {Array} oldData The current Most Visited page list. - * @param {Array} newData The new Most Visited page list. - * @return {Array} The merged page list that should replace the current page - * list. - */ - function refreshData(oldData, newData) { - oldData = oldData.slice(0, THUMBNAIL_COUNT); - newData = newData.slice(0, THUMBNAIL_COUNT); - - // Copy over pinned sites directly. - for (var j = 0; j < newData.length; j++) { - if (newData[j].pinned) { - oldData[j] = newData[j]; - // Mark the entry as 'updated' so we don't try to update again. - oldData[j].updated = true; - // Mark the newData page as 'used' so we don't try to re-use it. - newData[j].used = true; - } - } - - // Look through old pages; if they exist in the newData list, keep them - // where they are. - for (var i = 0; i < oldData.length; i++) { - if (!oldData[i] || oldData[i].updated) - continue; - - for (var j = 0; j < newData.length; j++) { - if (newData[j].used) - continue; - - if (newData[j].url == oldData[i].url) { - // The background image and other data may have changed. - oldData[i] = newData[j]; - oldData[i].updated = true; - newData[j].used = true; - break; - } - } - } - - // Look through old pages that haven't been updated yet; replace them. - for (var i = 0; i < oldData.length; i++) { - if (oldData[i] && oldData[i].updated) - continue; - - for (var j = 0; j < newData.length; j++) { - if (newData[j].used) - continue; - - oldData[i] = newData[j]; - oldData[i].updated = true; - newData[j].used = true; - break; - } - - if (oldData[i] && !oldData[i].updated) - oldData[i] = null; - } - - // Clear 'updated' flags so this function will work next time it's called. - for (var i = 0; i < THUMBNAIL_COUNT; i++) { - if (oldData[i]) - oldData[i].updated = false; - } - - return oldData; - }; - - return { - MostVisitedPage: MostVisitedPage, - refreshData: refreshData, - }; -}); - -document.addEventListener('ntpLoaded', ntp.MostVisitedPage.onLoaded); diff --git a/chrome/browser/resources/ntp4/new_tab.html b/chrome/browser/resources/ntp4/new_tab.html index cc0e668..9bceb41 100644 --- a/chrome/browser/resources/ntp4/new_tab.html +++ b/chrome/browser/resources/ntp4/new_tab.html @@ -27,7 +27,6 @@ <link rel="stylesheet" href="../../../../ui/webui/resources/css/trash.css"> <link rel="stylesheet" href="../../../../ui/webui/resources/css/widgets.css"> <link rel="stylesheet" href="apps_page.css"> -<link rel="stylesheet" href="most_visited_page.css"> <link rel="stylesheet" href="nav_dot.css"> <link rel="stylesheet" href="new_tab.css"> <link rel="stylesheet" href="footer_menu.css"> @@ -58,7 +57,6 @@ <script src="tile_page.js"></script> <script src="apps_page.js"></script> <script src="dot_list.js"></script> -<script src="most_visited_page.js"></script> <script src="trash.js"></script> <script src="page_list_view.js"></script> <script src="page_switcher.js"></script> diff --git a/chrome/browser/resources/ntp4/new_tab.js b/chrome/browser/resources/ntp4/new_tab.js index b127c69..678be69 100644 --- a/chrome/browser/resources/ntp4/new_tab.js +++ b/chrome/browser/resources/ntp4/new_tab.js @@ -8,15 +8,6 @@ * browsers. For now this is still a prototype. */ -/** - * @typedef {{direction: string, - * filler: (boolean|undefined), - * title: string, - * url: string}} - * @see chrome/browser/ui/webui/ntp/most_visited_handler.cc - */ -var PageData; - // Use an anonymous function to enable strict mode just for this file (which // will be concatenated with other files when embedded in Chrome cr.define('ntp', function() { @@ -120,8 +111,6 @@ cr.define('ntp', function() { */ function onLoad() { sectionsToWaitFor = 0; - if (loadTimeData.getBoolean('showMostvisited')) - sectionsToWaitFor++; if (loadTimeData.getBoolean('showApps')) { sectionsToWaitFor++; if (loadTimeData.getBoolean('showAppLauncherPromo')) { @@ -142,18 +131,6 @@ cr.define('ntp', function() { notificationContainer.addEventListener( 'webkitTransitionEnd', onNotificationTransitionEnd); - if (loadTimeData.getBoolean('showMostvisited')) { - var mostVisited = new ntp.MostVisitedPage(); - // Move the footer into the most visited page if we are in "bare minimum" - // mode. - if (document.body.classList.contains('bare-minimum')) - mostVisited.appendFooter(getRequiredElement('footer')); - newTabView.appendTilePage(mostVisited, - loadTimeData.getString('mostvisited'), - false); - chrome.send('getMostVisited'); - } - if (!loadTimeData.getBoolean('showWebStoreIcon')) { var webStoreIcon = $('chrome-web-store-link'); // Not all versions of the NTP have a footer, so this may not exist. @@ -326,14 +303,11 @@ cr.define('ntp', function() { * its length may be measured and the nav dots sized accordingly. */ function measureNavDots() { - var pxWidth = measureNavDot('appDefaultPageName'); - if (loadTimeData.getBoolean('showMostvisited')) - pxWidth = Math.max(measureNavDot('mostvisited'), pxWidth); - var styleElement = document.createElement('style'); styleElement.type = 'text/css'; // max-width is used because if we run out of space, the nav dots will be // shrunk. + var pxWidth = measureNavDot('appDefaultPageName'); styleElement.textContent = '.dot { max-width: ' + pxWidth + 'px; }'; document.querySelector('head').appendChild(styleElement); } @@ -507,15 +481,6 @@ cr.define('ntp', function() { } /** - * @param {Array<PageData>} data - * @param {boolean} hasBlacklistedUrls - */ - function setMostVisitedPages(data, hasBlacklistedUrls) { - newTabView.mostVisitedPage.data = data; - cr.dispatchSimpleEvent(document, 'sectionready', true, true); - } - - /** * Set the dominant color for a node. This will be called in response to * getFaviconDominantColor. The node represented by |id| better have a setter * for stripeColor. @@ -574,16 +539,6 @@ cr.define('ntp', function() { } /** - * Logs the time to click for the specified item. - * @param {string} item The item to log the time-to-click. - */ - function logTimeToClick(item) { - var timeToClick = Date.now() - startTime; - chrome.send('logTimeToClick', - ['NewTabPage.TimeToClick' + item, timeToClick]); - } - - /** * Wrappers to forward the callback to corresponding PageListView member. */ @@ -706,12 +661,10 @@ cr.define('ntp', function() { getCardSlider: getCardSlider, onLoad: onLoad, leaveRearrangeMode: leaveRearrangeMode, - logTimeToClick: logTimeToClick, NtpFollowAction: NtpFollowAction, saveAppPageName: saveAppPageName, setAppToBeHighlighted: setAppToBeHighlighted, setBookmarkBarAttached: setBookmarkBarAttached, - setMostVisitedPages: setMostVisitedPages, setFaviconDominantColor: setFaviconDominantColor, showNotification: showNotification, themeChanged: themeChanged, diff --git a/chrome/browser/resources/ntp4/new_tab_theme.css b/chrome/browser/resources/ntp4/new_tab_theme.css index a7b1888..52281e8 100644 --- a/chrome/browser/resources/ntp4/new_tab_theme.css +++ b/chrome/browser/resources/ntp4/new_tab_theme.css @@ -90,18 +90,6 @@ body { background-color: rgba($23, 0.85); /* COLOR_NTP_TEXT */ } -/* Most Visited ***************************************************************/ - -.most-visited, -.most-visited > .title { - color: $8; /* COLOR_NTP_TEXT */ -} - -.most-visited:focus:not(.filler) .thumbnail-wrapper, -.most-visited:hover:not(.filler) .thumbnail-wrapper { - background-color: $6; /* COLOR_NTP_HEADER */ -} - .thumbnail-wrapper { /* This shows through at the (rounded) thumbnail's corners. */ background-color: $11; /* COLOR_NTP_SECTION_BORDER */ diff --git a/chrome/browser/resources/ntp4/page_list_view.js b/chrome/browser/resources/ntp4/page_list_view.js index fa1513b..a13a424 100644 --- a/chrome/browser/resources/ntp4/page_list_view.js +++ b/chrome/browser/resources/ntp4/page_list_view.js @@ -86,12 +86,6 @@ cr.define('ntp', function() { appsPages: undefined, /** - * The Most Visited page. - * @type {!Element|undefined} - */ - mostVisitedPage: undefined, - - /** * The 'dots-list' element. * @type {!Element|undefined} */ @@ -174,20 +168,13 @@ cr.define('ntp', function() { this.shownPage = loadTimeData.getInteger('shown_page_type'); this.shownPageIndex = loadTimeData.getInteger('shown_page_index'); - if (loadTimeData.getBoolean('showApps')) { - // Request data on the apps so we can fill them in. - // Note that this is kicked off asynchronously. 'getAppsCallback' will - // be invoked at some point after this function returns. - chrome.send('getApps'); - } else { - // No apps page. - if (this.shownPage == loadTimeData.getInteger('apps_page_id')) { - this.setShownPage_( - loadTimeData.getInteger('most_visited_page_id'), 0); - } + // TODO(dbeam): remove showApps and everything that says if (apps). + assert(loadTimeData.getBoolean('showApps')); - document.body.classList.add('bare-minimum'); - } + // Request data on the apps so we can fill them in. + // Note that this is kicked off asynchronously. 'getAppsCallback' will + // be invoked at some point after this function returns. + chrome.send('getApps'); document.addEventListener('keydown', this.onDocKeyDown_.bind(this)); @@ -259,14 +246,6 @@ cr.define('ntp', function() { this.cardSlider.appendCard(page); } - // Remember special MostVisitedPage. - if (typeof ntp.MostVisitedPage != 'undefined' && - page instanceof ntp.MostVisitedPage) { - assert(this.tilePages.length == 1, - 'MostVisitedPage should be added as first tile page'); - this.mostVisitedPage = page; - } - // If we're appending an AppsPage and it's a temporary page, animate it. var animate = page instanceof ntp.AppsPage && page.classList.contains('temporary'); @@ -489,11 +468,10 @@ cr.define('ntp', function() { $(data.apps[i].id).appData = data.apps[i]; } - // Set the App dot names. Skip the first dot (Most Visited). + // Set the App dot names. var dots = this.dotList.getElementsByClassName('dot'); - var start = this.mostVisitedPage ? 1 : 0; - for (var i = start; i < dots.length; ++i) { - dots[i].displayTitle = data.appPageNames[i - start] || ''; + for (var i = 0; i < dots.length; ++i) { + dots[i].displayTitle = data.appPageNames[i] || ''; } }, @@ -525,20 +503,11 @@ cr.define('ntp', function() { this.tilePages.length - 1)); this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), pageNo); - if (this.shownPage == loadTimeData.getInteger('most_visited_page_id')) { - if (this.mostVisitedPage) - this.cardSlider.selectCardByValue(this.mostVisitedPage); - else - this.shownPage = loadTimeData.getInteger('apps_page_id'); - } if (this.shownPage == loadTimeData.getInteger('apps_page_id') && loadTimeData.getBoolean('showApps')) { this.cardSlider.selectCardByValue( this.appsPages[Math.min(this.shownPageIndex, this.appsPages.length - 1)]); - } else if (this.mostVisitedPage) { - this.shownPage = loadTimeData.getInteger('most_visited_page_id'); - this.cardSlider.selectCardByValue(this.mostVisitedPage); } }, @@ -665,9 +634,6 @@ cr.define('ntp', function() { if (page.classList.contains('apps-page')) { this.setShownPage_(loadTimeData.getInteger('apps_page_id'), this.getAppsPageIndex(page)); - } else if (page.classList.contains('most-visited-page')) { - this.setShownPage_( - loadTimeData.getInteger('most_visited_page_id'), 0); } else { console.error('unknown page selected'); } diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc index 573c415..986808d7 100644 --- a/chrome/browser/search/instant_service.cc +++ b/chrome/browser/search/instant_service.cc @@ -14,6 +14,7 @@ #include "chrome/browser/search/most_visited_iframe_source.h" #include "chrome/browser/search/search.h" #include "chrome/browser/search/suggestions/suggestions_source.h" +#include "chrome/browser/search/thumbnail_source.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "chrome/browser/thumbnails/thumbnail_list_source.h" @@ -21,7 +22,6 @@ #include "chrome/browser/ui/webui/fallback_icon_source.h" #include "chrome/browser/ui/webui/favicon_source.h" #include "chrome/browser/ui/webui/large_icon_source.h" -#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" #include "chrome/browser/ui/webui/theme_source.h" #include "chrome/common/render_messages.h" #include "components/favicon/core/fallback_icon_service.h" diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.cc b/chrome/browser/search/thumbnail_source.cc index 15fb29a..e2023c2 100644 --- a/chrome/browser/ui/webui/ntp/thumbnail_source.cc +++ b/chrome/browser/search/thumbnail_source.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" +#include "chrome/browser/search/thumbnail_source.h" #include "base/callback.h" #include "base/memory/ref_counted_memory.h" diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.h b/chrome/browser/search/thumbnail_source.h index 7a331686..4bf5072 100644 --- a/chrome/browser/ui/webui/ntp/thumbnail_source.h +++ b/chrome/browser/search/thumbnail_source.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_SOURCE_H_ -#define CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_SOURCE_H_ +#ifndef CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ +#define CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ #include <string> @@ -62,4 +62,4 @@ class ThumbnailSource : public content::URLDataSource { DISALLOW_COPY_AND_ASSIGN(ThumbnailSource); }; -#endif // CHROME_BROWSER_UI_WEBUI_NTP_THUMBNAIL_SOURCE_H_ +#endif // CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ diff --git a/chrome/browser/ui/webui/app_launcher_page_ui.cc b/chrome/browser/ui/webui/app_launcher_page_ui.cc index c95cdf2..3476b90 100644 --- a/chrome/browser/ui/webui/app_launcher_page_ui.cc +++ b/chrome/browser/ui/webui/app_launcher_page_ui.cc @@ -99,7 +99,6 @@ void AppLauncherPageUI::HTMLSource::StartDataRequest( DCHECK_CURRENTLY_ON(BrowserThread::UI); NTPResourceCache* resource = AppResourceCacheFactory::GetForProfile(profile_); - resource->set_should_show_most_visited_page(false); resource->set_should_show_other_devices_menu(false); content::RenderProcessHost* render_host = diff --git a/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc b/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc deleted file mode 100644 index 363473d..0000000 --- a/chrome/browser/ui/webui/ntp/most_visited_browsertest.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/files/file_path.h" -#include "chrome/common/url_constants.h" -#include "chrome/test/base/ui_test_utils.h" -#include "chrome/test/base/web_ui_browser_test.h" -#include "url/gurl.h" - -class MostVisitedWebUITest : public WebUIBrowserTest { - public: - ~MostVisitedWebUITest() override {} - - void SetUpInProcessBrowserTestFixture() override { - WebUIBrowserTest::SetUpInProcessBrowserTestFixture(); - AddLibrary(base::FilePath(FILE_PATH_LITERAL("most_visited_page_test.js"))); - } - - void SetUpOnMainThread() override { - WebUIBrowserTest::SetUpOnMainThread(); - ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); - } -}; - -// TODO(samarth): delete along with the rest of the NTP4 code. -WEB_UI_UNITTEST_F(MostVisitedWebUITest, DISABLED_refreshDataBasic); -WEB_UI_UNITTEST_F(MostVisitedWebUITest, DISABLED_refreshDataOrdering); -WEB_UI_UNITTEST_F(MostVisitedWebUITest, DISABLED_refreshDataPinning); diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.cc b/chrome/browser/ui/webui/ntp/most_visited_handler.cc deleted file mode 100644 index 9deda8c..0000000 --- a/chrome/browser/ui/webui/ntp/most_visited_handler.cc +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/ntp/most_visited_handler.h" - -#include <set> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/md5.h" -#include "base/memory/scoped_vector.h" -#include "base/memory/singleton.h" -#include "base/metrics/histogram.h" -#include "base/prefs/pref_service.h" -#include "base/prefs/scoped_user_pref_update.h" -#include "base/strings/string16.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread.h" -#include "base/values.h" -#include "chrome/browser/favicon/fallback_icon_service_factory.h" -#include "chrome/browser/favicon/large_icon_service_factory.h" -#include "chrome/browser/history/top_sites_factory.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/thumbnails/thumbnail_list_source.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/tabs/tab_strip_model_utils.h" -#include "chrome/browser/ui/webui/fallback_icon_source.h" -#include "chrome/browser/ui/webui/favicon_source.h" -#include "chrome/browser/ui/webui/large_icon_source.h" -#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" -#include "chrome/browser/ui/webui/ntp/ntp_stats.h" -#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "components/favicon/core/fallback_icon_service.h" -#include "components/favicon/core/large_icon_service.h" -#include "components/history/core/browser/page_usage_data.h" -#include "components/history/core/browser/top_sites.h" -#include "components/keyed_service/core/service_access_type.h" -#include "components/pref_registry/pref_registry_syncable.h" -#include "content/public/browser/navigation_controller.h" -#include "content/public/browser/navigation_entry.h" -#include "content/public/browser/url_data_source.h" -#include "content/public/browser/user_metrics.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_ui.h" -#include "url/gurl.h" - -using base::UserMetricsAction; - -MostVisitedHandler::MostVisitedHandler() - : scoped_observer_(this), - got_first_most_visited_request_(false), - most_visited_viewed_(false), - user_action_logged_(false), - weak_ptr_factory_(this) { -} - -MostVisitedHandler::~MostVisitedHandler() { - if (!user_action_logged_ && most_visited_viewed_) { - const GURL ntp_url = GURL(chrome::kChromeUINewTabURL); - int action_id = NTP_FOLLOW_ACTION_OTHER; - content::NavigationEntry* entry = - web_ui()->GetWebContents()->GetController().GetLastCommittedEntry(); - if (entry && (entry->GetURL() != ntp_url)) { - action_id = - ui::PageTransitionStripQualifier(entry->GetTransitionType()); - } - - UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisitedAction", action_id, - NUM_NTP_FOLLOW_ACTIONS); - } -} - -void MostVisitedHandler::RegisterMessages() { - Profile* profile = Profile::FromWebUI(web_ui()); - // Set up our sources for thumbnail and favicon data. - content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); - content::URLDataSource::Add(profile, new ThumbnailSource(profile, true)); - - // Set up our sources for top-sites data. - content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); - - favicon::FallbackIconService* fallback_icon_service = - FallbackIconServiceFactory::GetForBrowserContext(profile); - favicon::LargeIconService* large_icon_service = - LargeIconServiceFactory::GetForBrowserContext(profile); - - // Register chrome://fallback-icon as a data source for fallback icons. - content::URLDataSource::Add(profile, - new FallbackIconSource(fallback_icon_service)); - - // Register chrome://favicon as a data source for favicons. - content::URLDataSource::Add( - profile, new FaviconSource(profile, FaviconSource::FAVICON)); - - // Register chrome://large-icon as a data source for large icons. - content::URLDataSource::Add( - profile, new LargeIconSource(fallback_icon_service, large_icon_service)); - - scoped_refptr<history::TopSites> top_sites = - TopSitesFactory::GetForProfile(profile); - if (top_sites) { - // TopSites updates itself after a delay. This is especially noticable when - // your profile is empty. Ask TopSites to update itself when we're about to - // show the new tab page. - top_sites->SyncWithHistory(); - - // Register as TopSitesObserver so that we can update ourselves when the - // TopSites changes. - scoped_observer_.Add(top_sites.get()); - } - - // We pre-emptively make a fetch for the most visited pages so we have the - // results sooner. - StartQueryForMostVisited(); - - web_ui()->RegisterMessageCallback("getMostVisited", - base::Bind(&MostVisitedHandler::HandleGetMostVisited, - base::Unretained(this))); - - // Register ourselves for any most-visited item blacklisting. - web_ui()->RegisterMessageCallback("blacklistURLFromMostVisited", - base::Bind(&MostVisitedHandler::HandleBlacklistUrl, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("removeURLsFromMostVisitedBlacklist", - base::Bind(&MostVisitedHandler::HandleRemoveUrlsFromBlacklist, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("clearMostVisitedURLsBlacklist", - base::Bind(&MostVisitedHandler::HandleClearBlacklist, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("mostVisitedAction", - base::Bind(&MostVisitedHandler::HandleMostVisitedAction, - base::Unretained(this))); - web_ui()->RegisterMessageCallback("mostVisitedSelected", - base::Bind(&MostVisitedHandler::HandleMostVisitedSelected, - base::Unretained(this))); -} - -void MostVisitedHandler::HandleGetMostVisited(const base::ListValue* args) { - if (!got_first_most_visited_request_) { - // If our initial data is already here, return it. - SendPagesValue(); - got_first_most_visited_request_ = true; - } else { - StartQueryForMostVisited(); - } -} - -void MostVisitedHandler::SendPagesValue() { - if (pages_value_) { - Profile* profile = Profile::FromWebUI(web_ui()); - const base::DictionaryValue* url_blacklist = - profile->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); - bool has_blacklisted_urls = !url_blacklist->empty(); - scoped_refptr<history::TopSites> ts = - TopSitesFactory::GetForProfile(profile); - if (ts) - has_blacklisted_urls = ts->HasBlacklistedItems(); - - base::FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls); - web_ui()->CallJavascriptFunction("ntp.setMostVisitedPages", - *pages_value_, - has_blacklisted_urls_value); - pages_value_.reset(); - } -} - -void MostVisitedHandler::StartQueryForMostVisited() { - scoped_refptr<history::TopSites> ts = - TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui())); - if (ts) { - ts->GetMostVisitedURLs( - base::Bind(&MostVisitedHandler::OnMostVisitedUrlsAvailable, - weak_ptr_factory_.GetWeakPtr()), false); - } -} - -void MostVisitedHandler::HandleBlacklistUrl(const base::ListValue* args) { - std::string url = base::UTF16ToUTF8(ExtractStringValue(args)); - BlacklistUrl(GURL(url)); -} - -void MostVisitedHandler::HandleRemoveUrlsFromBlacklist( - const base::ListValue* args) { - DCHECK(args->GetSize() != 0); - - for (base::ListValue::const_iterator iter = args->begin(); - iter != args->end(); ++iter) { - std::string url; - bool r = (*iter)->GetAsString(&url); - if (!r) { - NOTREACHED(); - return; - } - content::RecordAction(UserMetricsAction("MostVisited_UrlRemoved")); - scoped_refptr<history::TopSites> ts = - TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui())); - if (ts) - ts->RemoveBlacklistedURL(GURL(url)); - } -} - -void MostVisitedHandler::HandleClearBlacklist(const base::ListValue* args) { - content::RecordAction(UserMetricsAction("MostVisited_BlacklistCleared")); - - scoped_refptr<history::TopSites> ts = - TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui())); - if (ts) - ts->ClearBlacklistedURLs(); -} - -void MostVisitedHandler::HandleMostVisitedAction(const base::ListValue* args) { - DCHECK(args); - - double action_id; - if (!args->GetDouble(0, &action_id)) - NOTREACHED(); - - UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisitedAction", - static_cast<int>(action_id), - NUM_NTP_FOLLOW_ACTIONS); - most_visited_viewed_ = true; - user_action_logged_ = true; -} - -void MostVisitedHandler::HandleMostVisitedSelected( - const base::ListValue* args) { - most_visited_viewed_ = true; -} - -void MostVisitedHandler::SetPagesValueFromTopSites( - const history::MostVisitedURLList& data) { - pages_value_.reset(new base::ListValue); - - history::MostVisitedURLList top_sites(data); - for (size_t i = 0; i < top_sites.size(); i++) { - const history::MostVisitedURL& url = top_sites[i]; - - // The items which are to be written into |page_value| are also described in - // chrome/browser/resources/ntp4/new_tab.js in @typedef for PageData. Please - // update it whenever you add or remove any keys here. - base::DictionaryValue* page_value = new base::DictionaryValue(); - if (url.url.is_empty()) { - page_value->SetBoolean("filler", true); - pages_value_->Append(page_value); - continue; - } - - NewTabUI::SetUrlTitleAndDirection(page_value, - url.title, - url.url); - pages_value_->Append(page_value); - } -} - -void MostVisitedHandler::OnMostVisitedUrlsAvailable( - const history::MostVisitedURLList& data) { - SetPagesValueFromTopSites(data); - if (got_first_most_visited_request_) { - SendPagesValue(); - } -} - -void MostVisitedHandler::TopSitesLoaded(history::TopSites* top_sites) { -} - -void MostVisitedHandler::TopSitesChanged(history::TopSites* top_sites) { - // Most visited urls changed, query again. - StartQueryForMostVisited(); -} - -void MostVisitedHandler::BlacklistUrl(const GURL& url) { - scoped_refptr<history::TopSites> ts = - TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui())); - if (ts) - ts->AddBlacklistedURL(url); - content::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); -} - -std::string MostVisitedHandler::GetDictionaryKeyForUrl(const std::string& url) { - return base::MD5String(url); -} - -// static -void MostVisitedHandler::RegisterProfilePrefs( - user_prefs::PrefRegistrySyncable* registry) { - registry->RegisterDictionaryPref(prefs::kNtpMostVisitedURLsBlacklist); -} diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.h b/chrome/browser/ui/webui/ntp/most_visited_handler.h deleted file mode 100644 index 7e04d42..0000000 --- a/chrome/browser/ui/webui/ntp/most_visited_handler.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ -#define CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ - -#include <string> -#include <vector> - -#include "base/memory/weak_ptr.h" -#include "base/scoped_observer.h" -#include "components/history/core/browser/history_types.h" -#include "components/history/core/browser/top_sites_observer.h" -#include "content/public/browser/web_ui_message_handler.h" - -class GURL; - -namespace base { -class ListValue; -class Value; -} - -namespace user_prefs { -class PrefRegistrySyncable; -} - -// The handler for Javascript messages related to the "most visited" view. -// -// This class manages one preference: -// - The URL blacklist: URLs we do not want to show in the thumbnails list. It -// is a dictionary for quick access (it associates a dummy boolean to the URL -// string). -class MostVisitedHandler : public content::WebUIMessageHandler, - public history::TopSitesObserver { - public: - - MostVisitedHandler(); - ~MostVisitedHandler() override; - - // WebUIMessageHandler override and implementation. - void RegisterMessages() override; - - // Callback for the "getMostVisited" message. - void HandleGetMostVisited(const base::ListValue* args); - - // Callback for the "blacklistURLFromMostVisited" message. - void HandleBlacklistUrl(const base::ListValue* args); - - // Callback for the "removeURLsFromMostVisitedBlacklist" message. - void HandleRemoveUrlsFromBlacklist(const base::ListValue* args); - - // Callback for the "clearMostVisitedURLsBlacklist" message. - void HandleClearBlacklist(const base::ListValue* args); - - // Callback for the "mostVisitedAction" message. - void HandleMostVisitedAction(const base::ListValue* args); - - // Callback for the "mostVisitedSelected" message. - void HandleMostVisitedSelected(const base::ListValue* args); - - const std::vector<GURL>& most_visited_urls() const { - return most_visited_urls_; - } - - static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); - - private: - struct MostVisitedPage; - - // Send a request to the HistoryService to get the most visited pages. - void StartQueryForMostVisited(); - - // Sets pages_value_ from a format produced by TopSites. - void SetPagesValueFromTopSites(const history::MostVisitedURLList& data); - - // Callback for TopSites. - void OnMostVisitedUrlsAvailable(const history::MostVisitedURLList& data); - - // Puts the passed URL in the blacklist (so it does not show as a thumbnail). - void BlacklistUrl(const GURL& url); - - // Returns the key used in url_blacklist_ for the passed |url|. - std::string GetDictionaryKeyForUrl(const std::string& url); - - // Sends pages_value_ to the javascript side and resets page_value_. - void SendPagesValue(); - - // history::TopSitesObserver implementation. - void TopSitesLoaded(history::TopSites* top_sites) override; - void TopSitesChanged(history::TopSites* top_sites) override; - - // Scoped observer to help with TopSitesObserver registration. - ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_; - - // The most visited URLs, in priority order. - // Only used for matching up clicks on the page to which most visited entry - // was clicked on for metrics purposes. - std::vector<GURL> most_visited_urls_; - - // We pre-fetch the first set of result pages. This variable is false until - // we get the first getMostVisited() call. - bool got_first_most_visited_request_; - - // Keep the results of the db query here. - scoped_ptr<base::ListValue> pages_value_; - - // Whether the user has viewed the 'most visited' pane. - bool most_visited_viewed_; - - // Whether the user has performed a "tracked" action to leave the page or not. - bool user_action_logged_; - - // For callbacks which may be run after destruction. - base::WeakPtrFactory<MostVisitedHandler> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ diff --git a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc index d908496..a07e340 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc @@ -68,9 +68,6 @@ void NewTabPageHandler::RegisterMessages() { web_ui()->RegisterMessageCallback("pageSelected", base::Bind(&NewTabPageHandler::HandlePageSelected, base::Unretained(this))); - web_ui()->RegisterMessageCallback("logTimeToClick", - base::Bind(&NewTabPageHandler::HandleLogTimeToClick, - base::Unretained(this))); } void NewTabPageHandler::HandleNotificationPromoClosed( @@ -143,26 +140,6 @@ void NewTabPageHandler::HandlePageSelected(const base::ListValue* args) { shown_page_type, kHistogramEnumerationMax); } -void NewTabPageHandler::HandleLogTimeToClick(const base::ListValue* args) { - std::string histogram_name; - double duration; - if (!args->GetString(0, &histogram_name) || !args->GetDouble(1, &duration)) { - NOTREACHED(); - return; - } - - base::TimeDelta delta = base::TimeDelta::FromMilliseconds(duration); - - if (histogram_name == "NewTabPage.TimeToClickMostVisited") { - UMA_HISTOGRAM_LONG_TIMES("NewTabPage.TimeToClickMostVisited", delta); - } else if (histogram_name == "ExtendedNewTabPage.TimeToClickMostVisited") { - UMA_HISTOGRAM_LONG_TIMES( - "ExtendedNewTabPage.TimeToClickMostVisited", delta); - } else { - NOTREACHED(); - } -} - // static void NewTabPageHandler::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { @@ -173,7 +150,6 @@ void NewTabPageHandler::RegisterProfilePrefs( // static void NewTabPageHandler::GetLocalizedValues(Profile* profile, base::DictionaryValue* values) { - values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); values->SetInteger("apps_page_id", APPS_PAGE_ID); PrefService* prefs = profile->GetPrefs(); diff --git a/chrome/browser/ui/webui/ntp/new_tab_page_handler.h b/chrome/browser/ui/webui/ntp/new_tab_page_handler.h index d822354..ec2b291 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_page_handler.h +++ b/chrome/browser/ui/webui/ntp/new_tab_page_handler.h @@ -58,9 +58,6 @@ class NewTabPageHandler : public content::WebUIMessageHandler, // Callback for "pageSelected". void HandlePageSelected(const base::ListValue* args); - // Callback for "logTimeToClick". - void HandleLogTimeToClick(const base::ListValue* args); - // Tracks the number of times the user has switches pages (for UMA). size_t page_switch_count_; @@ -71,7 +68,6 @@ class NewTabPageHandler : public content::WebUIMessageHandler, static const int kPageIdOffset = 10; enum { INDEX_MASK = (1 << kPageIdOffset) - 1, - MOST_VISITED_PAGE_ID = 1 << kPageIdOffset, APPS_PAGE_ID = 2 << kPageIdOffset, LAST_PAGE_ID = APPS_PAGE_ID, }; diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index 8671b41..4685578 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -18,7 +18,6 @@ #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" -#include "chrome/browser/ui/webui/ntp/most_visited_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" @@ -93,7 +92,6 @@ NewTabUI::NewTabUI(content::WebUI* web_ui) Profile* profile = GetProfile(); if (!profile->IsOffTheRecord()) { web_ui->AddMessageHandler(new MetricsHandler()); - web_ui->AddMessageHandler(new MostVisitedHandler()); web_ui->AddMessageHandler(new FaviconWebUIHandler()); web_ui->AddMessageHandler(new NewTabPageHandler()); web_ui->AddMessageHandler(new CoreAppLauncherHandler()); @@ -213,7 +211,6 @@ void NewTabUI::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { CoreAppLauncherHandler::RegisterProfilePrefs(registry); NewTabPageHandler::RegisterProfilePrefs(registry); - MostVisitedHandler::RegisterProfilePrefs(registry); } // static diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 1a27e73..7b06422 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -165,7 +165,6 @@ std::string GetNewTabBackgroundTilingCSS( NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false), should_show_apps_page_(NewTabUI::ShouldShowApps()), - should_show_most_visited_page_(true), should_show_other_devices_menu_(true) { registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, content::Source<ThemeService>( @@ -414,27 +413,16 @@ void NTPResourceCache::CreateNewTabHTML() { load_time_data.SetBoolean("hasattribution", ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( IDR_THEME_NTP_ATTRIBUTION)); - load_time_data.SetBoolean("showMostvisited", should_show_most_visited_page_); load_time_data.SetBoolean("showAppLauncherPromo", ShouldShowAppLauncherPromo()); load_time_data.SetString("title", l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); - load_time_data.SetString("mostvisited", - l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); - load_time_data.SetString("restoreThumbnailsShort", - l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); load_time_data.SetString("webStoreTitle", l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); load_time_data.SetString("webStoreTitleShort", l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); load_time_data.SetString("attributionintro", l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); - load_time_data.SetString("thumbnailremovednotification", - l10n_util::GetStringUTF16(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION)); - load_time_data.SetString("undothumbnailremove", - l10n_util::GetStringUTF16(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE)); - load_time_data.SetString("removethumbnailtooltip", - l10n_util::GetStringUTF16(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP)); load_time_data.SetString("appuninstall", l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); load_time_data.SetString("appoptions", diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h index 056955b..211a5e1 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.h +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.h @@ -45,9 +45,6 @@ class NTPResourceCache : public content::NotificationObserver, void set_should_show_apps_page(bool should_show_apps_page) { should_show_apps_page_ = should_show_apps_page; } - void set_should_show_most_visited_page(bool should_show_most_visited_page) { - should_show_most_visited_page_ = should_show_most_visited_page; - } void set_should_show_other_devices_menu(bool should_show_other_devices_menu) { should_show_other_devices_menu_ = should_show_other_devices_menu; } @@ -103,9 +100,6 @@ class NTPResourceCache : public content::NotificationObserver, bool is_swipe_tracking_from_scroll_events_enabled_; // Set based on NewTabUI::ShouldShowApps. bool should_show_apps_page_; - // The next three all default to true and can be manually set, e.g., by the - // chrome://apps page. - bool should_show_most_visited_page_; bool should_show_other_devices_menu_; DISALLOW_COPY_AND_ASSIGN(NTPResourceCache); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f759cb1..dfefe5d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -685,6 +685,8 @@ 'browser/search/suggestions/suggestions_service_factory.h', 'browser/search/suggestions/suggestions_source.cc', 'browser/search/suggestions/suggestions_source.h', + 'browser/search/thumbnail_source.cc', + 'browser/search/thumbnail_source.h', 'browser/searuch/most_visited_iframe_source.h', 'browser/shell_integration.cc', 'browser/shell_integration.h', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 8fc1ca4..609dc13 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1781,8 +1781,6 @@ 'browser/ui/webui/ntp/core_app_launcher_handler.h', 'browser/ui/webui/ntp/favicon_webui_handler.cc', 'browser/ui/webui/ntp/favicon_webui_handler.h', - 'browser/ui/webui/ntp/most_visited_handler.cc', - 'browser/ui/webui/ntp/most_visited_handler.h', 'browser/ui/webui/ntp/new_tab_page_handler.cc', 'browser/ui/webui/ntp/new_tab_page_handler.h', 'browser/ui/webui/ntp/new_tab_page_sync_handler.cc', @@ -1796,8 +1794,6 @@ 'browser/ui/webui/ntp/ntp_resource_cache_factory.cc', 'browser/ui/webui/ntp/ntp_resource_cache_factory.h', 'browser/ui/webui/ntp/ntp_stats.h', - 'browser/ui/webui/ntp/thumbnail_source.cc', - 'browser/ui/webui/ntp/thumbnail_source.h', 'browser/ui/webui/options/advanced_options_utils.h', 'browser/ui/webui/options/advanced_options_utils_linux.cc', 'browser/ui/webui/options/advanced_options_utils_mac.mm', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 73e039d..c2cd811 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -527,7 +527,6 @@ 'browser/ui/webui/interstitials/interstitial_ui_browsertest.cc', 'browser/ui/webui/net_internals/net_internals_ui_browsertest.cc', 'browser/ui/webui/net_internals/net_internals_ui_browsertest.h', - 'browser/ui/webui/ntp/most_visited_browsertest.cc', 'browser/ui/webui/ntp/new_tab_page_sync_handler_browsertest.cc', 'browser/ui/webui/ntp/new_tab_ui_browsertest.cc', 'browser/ui/webui/options/clear_browser_data_browsertest.cc', diff --git a/chrome/test/base/web_ui_browser_test.h b/chrome/test/base/web_ui_browser_test.h index ab9223e..0bc0d5f 100644 --- a/chrome/test/base/web_ui_browser_test.h +++ b/chrome/test/base/web_ui_browser_test.h @@ -25,12 +25,6 @@ class WebUIMessageHandler; class TestChromeWebUIControllerFactory; class WebUITestHandler; -// This macro simplifies the declaration of simple javascript unit tests. -// Use: -// WEB_UI_UNITTEST_F(MyWebUIPageTest, myJavascriptUnittest); -#define WEB_UI_UNITTEST_F(x, y) \ - IN_PROC_BROWSER_TEST_F(x, y) { ASSERT_TRUE(RunJavascriptTest(#y)); } - // The runner of WebUI javascript based tests. // See chrome/test/data/webui/test_api.js for the javascript side test API's. // |