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

Unified Diff: chrome/browser/dom_ui/most_visited_handler.cc

Issue 3001003: NTP: Use the store as the last thumbnail in case we have no apps installed.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/dom_ui/most_visited_handler.h ('k') | chrome/browser/dom_ui/ntp_resource_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/dom_ui/most_visited_handler.cc
===================================================================
--- chrome/browser/dom_ui/most_visited_handler.cc (revision 52778)
+++ chrome/browser/dom_ui/most_visited_handler.cc (working copy)
@@ -20,6 +20,8 @@
#include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
#include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/google_util.h"
#include "chrome/browser/history/page_usage_data.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/top_sites.h"
@@ -27,6 +29,7 @@
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/pref_names.h"
@@ -361,6 +364,7 @@
size_t pre_populated_index = 0;
const std::vector<MostVisitedPage> pre_populated_pages =
MostVisitedHandler::GetPrePopulatedPages();
+ bool add_chrome_store = !HasApps();
while (output_index < kMostVisitedPages) {
bool found = false;
@@ -398,6 +402,16 @@
found = true;
}
+ if (!found && add_chrome_store) {
+ mvp = GetChromeStorePage();
+ std::wstring key = GetDictionaryKeyForURL(mvp.url.spec());
+ if (!pinned_urls_->HasKey(key) && !url_blacklist_->HasKey(key) &&
+ seen_urls.find(mvp.url) == seen_urls.end()) {
+ found = true;
+ }
+ add_chrome_store = false;
+ }
+
if (found) {
// Add fillers as needed.
while (pages_value_->GetSize() < output_index) {
@@ -415,6 +429,30 @@
}
output_index++;
}
+
+ // If we still need to show the Chrome Store go backwards until we find a non
+ // pinned item we can replace.
+ if (add_chrome_store) {
+ MostVisitedPage chrome_store_page = GetChromeStorePage();
+ if (seen_urls.find(chrome_store_page.url) != seen_urls.end())
+ return;
+
+ std::wstring key = GetDictionaryKeyForURL(chrome_store_page.url.spec());
+ if (url_blacklist_->HasKey(key))
+ return;
+
+ for (int i = kMostVisitedPages - 1; i >= 0; --i) {
+ GURL url = most_visited_urls_[i];
+ std::wstring key = GetDictionaryKeyForURL(url.spec());
+ if (!pinned_urls_->HasKey(key)) {
+ // Not pinned, replace.
+ DictionaryValue* page_value = new DictionaryValue();
+ SetMostVisistedPage(page_value, chrome_store_page);
+ pages_value_->Set(i, page_value);
+ return;
+ }
+ }
+ }
}
// Converts a MostVisitedURLList into a vector of PageUsageData to be
@@ -477,6 +515,16 @@
return pages;
}
+// static
+MostVisitedHandler::MostVisitedPage MostVisitedHandler::GetChromeStorePage() {
+ MostVisitedHandler::MostVisitedPage page = {
+ l10n_util::GetString(IDS_EXTENSION_WEB_STORE_TITLE),
+ google_util::AppendGoogleLocaleParam(GURL(Extension::ChromeStoreURL())),
+ GURL("chrome://theme/IDR_NEWTAB_CHROME_STORE_PAGE_THUMBNAIL"),
+ GURL("chrome://theme/IDR_NEWTAB_CHROME_STORE_PAGE_FAVICON")};
+ return page;
+}
+
void MostVisitedHandler::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -508,3 +556,11 @@
prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist);
prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs);
}
+
+bool MostVisitedHandler::HasApps() const {
+ ExtensionsService* service = dom_ui_->GetProfile()->GetExtensionsService();
+ if (!service)
+ return false;
+
+ return service->HasApps();
+}
« no previous file with comments | « chrome/browser/dom_ui/most_visited_handler.h ('k') | chrome/browser/dom_ui/ntp_resource_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698