| 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();
|
| +}
|
|
|