summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 04:18:50 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 04:18:50 +0000
commit377011dcdc66ff873954283e42c854949c755e15 (patch)
tree01f9cb638073908cd1e6bbac48d619bb92dd4f8f
parent8869eb8930fefcf3f413f83566cc6c1c88b040c7 (diff)
downloadchromium_src-377011dcdc66ff873954283e42c854949c755e15.zip
chromium_src-377011dcdc66ff873954283e42c854949c755e15.tar.gz
chromium_src-377011dcdc66ff873954283e42c854949c755e15.tar.bz2
NTP: Use the store as the last thumbnail in case we have no apps installed.
1. If no apps are installed we add an item for the store to the most visited section. 2. No longer hide the most visited by default. 3. This removes the default apps on non ChromeOS BUG=46028, 47700 TEST=With a clean profile without any apps installed you should see the store thumbnail unless you blacklist it or pin 8 ohter pages. Review URL: http://codereview.chromium.org/3001003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52998 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.cc56
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.h5
-rw-r--r--chrome/browser/dom_ui/ntp_resource_cache.cc21
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler.cc20
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler.h3
-rw-r--r--chrome/browser/extensions/extensions_service.cc12
-rw-r--r--chrome/browser/extensions/extensions_service.h3
-rw-r--r--chrome/browser/profile.cc6
-rw-r--r--chrome/browser/resources/ntp/apps.css4
-rw-r--r--chrome/browser/resources/ntp/apps.js21
-rw-r--r--chrome/browser/resources/ntp/web_store_icon.pngbin0 -> 6497 bytes
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
13 files changed, 112 insertions, 43 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,
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 9c509d4..cc168d5 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -1145,6 +1145,18 @@ void ExtensionsService::Observe(NotificationType type,
}
}
+bool ExtensionsService::HasApps() {
+ if (!extensions_enabled_)
+ return false;
+
+ for (ExtensionList::const_iterator it = extensions_.begin();
+ it != extensions_.end(); ++it) {
+ if ((*it)->is_app())
+ return true;
+ }
+
+ return false;
+}
// ExtensionsServicesBackend
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index fa4e260..8c779cd 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -351,6 +351,9 @@ class ExtensionsService
const NotificationSource& source,
const NotificationDetails& details);
+ // Whether there are any apps installed.
+ bool HasApps();
+
private:
virtual ~ExtensionsService();
friend class ChromeThread;
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index acf4802..af54776 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -169,11 +169,7 @@ void PostExtensionUnloadedToContextGetter(ChromeURLRequestContextGetter* getter,
// Returns true if the default apps should be loaded (so that the app panel is
// not empty).
bool IncludeDefaultApps() {
-#if defined(OS_WIN)
- std::string user_domain;
- return base::EnvVarGetter::Create()->GetEnv("USERDOMAIN", &user_domain) &&
- user_domain == "GOOGLE";
-#elif defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
+#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
return true;
#endif
return false;
diff --git a/chrome/browser/resources/ntp/apps.css b/chrome/browser/resources/ntp/apps.css
index 73a13b8..67c7b70 100644
--- a/chrome/browser/resources/ntp/apps.css
+++ b/chrome/browser/resources/ntp/apps.css
@@ -121,6 +121,10 @@
-webkit-transition: opacity .5s;
}
+#web-store-entry {
+ background-image: url("web_store_icon.png");
+}
+
/* Make items on the wrong side non focusable by hiding them. */
.app:not(.config) > .back button,
.app.config > .front button,
diff --git a/chrome/browser/resources/ntp/apps.js b/chrome/browser/resources/ntp/apps.js
index 9a5cc19..41c2e6e 100644
--- a/chrome/browser/resources/ntp/apps.js
+++ b/chrome/browser/resources/ntp/apps.js
@@ -12,7 +12,6 @@ function getAppsCallback(data) {
appsSection.appendChild(apps.createElement(app));
});
-
// TODO(aa): Figure out what to do with the debug mode when we turn apps on
// for everyone.
if (appsSection.hasChildNodes()) {
@@ -20,6 +19,8 @@ function getAppsCallback(data) {
if (data.showDebugLink) {
debugSection.classList.remove('disabled');
}
+
+ appsSection.appendChild(apps.createWebStoreElement());
} else {
appsSection.classList.add('disabled');
debugSection.classList.add('disabled');
@@ -58,7 +59,7 @@ var apps = {
return false;
},
- createElement: function(app) {
+ createElement_: function(app) {
var div = document.createElement('div');
div.className = 'app';
@@ -70,6 +71,14 @@ var apps = {
a.xtitle = a.textContent = app['name'];
a.href = app['launch_url'];
+ return div;
+ },
+
+ createElement: function(app) {
+ var div = this.createElement_(app);
+ var front = div.firstChild;
+ var a = front.firstChild;
+
a.onclick = apps.handleClick_;
a.style.backgroundImage = url(app['icon']);
if (hashParams['app-id'] == app['id']) {
@@ -112,5 +121,13 @@ var apps = {
};
return div;
+ },
+
+ createWebStoreElement: function() {
+ return this.createElement_({
+ 'id': 'web-store-entry',
+ 'name': localStrings.getString('web_store_title'),
+ 'launch_url': localStrings.getString('web_store_url')
+ });
}
};
diff --git a/chrome/browser/resources/ntp/web_store_icon.png b/chrome/browser/resources/ntp/web_store_icon.png
new file mode 100644
index 0000000..d45242d
--- /dev/null
+++ b/chrome/browser/resources/ntp/web_store_icon.png
Binary files differ
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index c605887b..ad60dec 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -849,9 +849,6 @@ const wchar_t kNTPTipsServer[] = L"ntp.tips_server";
// 16 - show sync status
const wchar_t kNTPShownSections[] = L"ntp.shown_sections";
-// Whether the user has first run the app launcher.
-const wchar_t kNTPAppLauncherFirstRun[] = L"ntp.app_launcher_first_run";
-
// This pref is used for migrating the prefs for the NTP
const wchar_t kNTPPrefVersion[] = L"ntp.pref_version";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 9ccc2bd..27b0451 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -305,7 +305,6 @@ extern const wchar_t kNTPTipsCache[];
extern const wchar_t kNTPTipsCacheUpdate[];
extern const wchar_t kNTPTipsServer[];
extern const wchar_t kNTPShownSections[];
-extern const wchar_t kNTPAppLauncherFirstRun[];
extern const wchar_t kNTPPrefVersion[];
extern const wchar_t kDevToolsOpenDocked[];