diff options
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.cc | 56 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.h | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/ntp_resource_cache.cc | 21 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 20 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 3 |
5 files changed, 73 insertions, 32 deletions
diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc index c4974eb..690beb2 100644 --- a/chrome/browser/dom_ui/most_visited_handler.cc +++ b/chrome/browser/dom_ui/most_visited_handler.cc @@ -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 @@ void MostVisitedHandler::SetPagesValue(std::vector<PageUsageData*>* data) { 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 @@ void MostVisitedHandler::SetPagesValue(std::vector<PageUsageData*>* data) { 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 @@ void MostVisitedHandler::SetPagesValue(std::vector<PageUsageData*>* data) { } 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 @@ const std::vector<MostVisitedHandler::MostVisitedPage>& 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 @@ void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { 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(); +} diff --git a/chrome/browser/dom_ui/most_visited_handler.h b/chrome/browser/dom_ui/most_visited_handler.h index 0b9ee66..507cb7d1 100644 --- a/chrome/browser/dom_ui/most_visited_handler.h +++ b/chrome/browser/dom_ui/most_visited_handler.h @@ -106,6 +106,11 @@ class MostVisitedHandler : public DOMMessageHandler, static const std::vector<MostVisitedPage>& GetPrePopulatedPages(); + static MostVisitedPage GetChromeStorePage(); + + // Whether we have any apps installed. + bool HasApps() const; + NotificationRegistrar registrar_; // Our consumer for the history service. diff --git a/chrome/browser/dom_ui/ntp_resource_cache.cc b/chrome/browser/dom_ui/ntp_resource_cache.cc index 1a76937..e9f046d 100644 --- a/chrome/browser/dom_ui/ntp_resource_cache.cc +++ b/chrome/browser/dom_ui/ntp_resource_cache.cc @@ -19,7 +19,6 @@ #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" -#include "chrome/browser/dom_ui/shown_sections_handler.h" #include "chrome/browser/google_util.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" @@ -49,19 +48,19 @@ namespace { // The URL for the the Learn More page shown on incognito new tab. -const char* const kLearnMoreIncognitoUrl = +const char kLearnMoreIncognitoUrl[] = "http://www.google.com/support/chrome/bin/answer.py?answer=95464"; // The URL for bookmark sync service help. -const char* const kSyncServiceHelpUrl = +const char kSyncServiceHelpUrl[] = "http://www.google.com/support/chrome/bin/answer.py?answer=165139"; // The URL to be loaded to display Help. -const char* const kHelpContentUrl = +const char kHelpContentUrl[] = "http://www.google.com/support/chrome/"; -std::wstring GetUrlWithLang(const char* const url) { - return ASCIIToWide(google_util::AppendGoogleLocaleParam(GURL(url)).spec()); +std::wstring GetUrlWithLang(const GURL& url) { + return ASCIIToWide(google_util::AppendGoogleLocaleParam(url).spec()); } std::string SkColorToRGBAString(SkColor color) { @@ -195,7 +194,7 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { l10n_util::GetString(IDS_NEW_TAB_TITLE)); localized_strings.SetString(L"content", l10n_util::GetStringF(IDS_NEW_TAB_OTR_MESSAGE, - GetUrlWithLang(kLearnMoreIncognitoUrl))); + GetUrlWithLang(GURL(kLearnMoreIncognitoUrl)))); localized_strings.SetString(L"extensionsmessage", l10n_util::GetStringF(IDS_NEW_TAB_OTR_EXTENSIONS_MESSAGE, l10n_util::GetString(IDS_PRODUCT_NAME), @@ -273,13 +272,18 @@ void NTPResourceCache::CreateNewTabHTML() { l10n_util::GetString(IDS_NEW_TAB_DOWNLOADS)); localized_strings.SetString(L"help", l10n_util::GetString(IDS_NEW_TAB_HELP)); - localized_strings.SetString(L"helpurl", GetUrlWithLang(kHelpContentUrl)); + localized_strings.SetString(L"helpurl", + GetUrlWithLang(GURL(kHelpContentUrl))); localized_strings.SetString(L"appsettings", l10n_util::GetString(IDS_NEW_TAB_APP_SETTINGS)); localized_strings.SetString(L"appuninstall", l10n_util::GetString(IDS_NEW_TAB_APP_UNINSTALL)); localized_strings.SetString(L"appoptions", l10n_util::GetString(IDS_NEW_TAB_APP_OPTIONS)); + localized_strings.SetString(L"web_store_title", + l10n_util::GetString(IDS_EXTENSION_WEB_STORE_TITLE)); + localized_strings.SetString(L"web_store_url", + GetUrlWithLang(GURL(Extension::ChromeStoreURL()))); // Don't initiate the sync related message passing with the page if the sync // code is not present. @@ -301,7 +305,6 @@ void NTPResourceCache::CreateNewTabHTML() { localized_strings.SetString(L"has_3d", has_3d ? "true" : "false"); // Pass the shown_sections pref early so that we can prevent flicker. - ShownSectionsHandler::SetFirstAppLauncherRunPref(profile_->GetPrefs()); const int shown_sections = profile_->GetPrefs()->GetInteger( prefs::kNTPShownSections); localized_strings.SetInteger(L"shown_sections", shown_sections); diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc index aad15014..9bfd22e 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.cc +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -70,7 +70,6 @@ void ShownSectionsHandler::Observe(NotificationType type, } void ShownSectionsHandler::HandleGetShownSections(const Value* value) { - SetFirstAppLauncherRunPref(pref_service_); int sections = pref_service_->GetInteger(prefs::kNTPShownSections); FundamentalValue sections_value(sections); dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value); @@ -103,28 +102,9 @@ void ShownSectionsHandler::HandleSetShownSections(const Value* value) { } // static -void ShownSectionsHandler::SetFirstAppLauncherRunPref( - PrefService* pref_service) { - // If we have turned on Apps we want to hide most visited and recent to give - // more focus to the Apps section. We do not do this in MigrateUserPrefs - // because the pref version should not depend on command line switches. - if (Extension::AppsAreEnabled() && - !pref_service->GetBoolean(prefs::kNTPAppLauncherFirstRun)) { - int sections = pref_service->GetInteger(prefs::kNTPShownSections); - sections &= ~THUMB; - sections &= ~RECENT; - pref_service->SetInteger(prefs::kNTPShownSections, sections); - pref_service->SetBoolean(prefs::kNTPAppLauncherFirstRun, true); - } -} - -// static void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { pref_service->RegisterIntegerPref(prefs::kNTPShownSections, THUMB | RECENT | TIPS | SYNC); - if (Extension::AppsAreEnabled()) { - pref_service->RegisterBooleanPref(prefs::kNTPAppLauncherFirstRun, false); - } } // static diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h index 804c368..8bdbd52 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.h +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -42,9 +42,6 @@ class ShownSectionsHandler : public DOMMessageHandler, // Callback for "setShownSections" message. void HandleSetShownSections(const Value* value); - // Sets the prefs for first run of the App Launcher. - static void SetFirstAppLauncherRunPref(PrefService* pref_service); - static void RegisterUserPrefs(PrefService* pref_service); static void MigrateUserPrefs(PrefService* pref_service, |