summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-25 01:37:00 +0000
committerarv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-25 01:37:00 +0000
commitf7d17b2ecc119c27673e8cc8c858761d253277f3 (patch)
tree5f17de5d80a832a0ce07aee13557f6e929ade11c
parentdf407eaf9bad2ca4e4d2099904d0a35d11caec3e (diff)
downloadchromium_src-f7d17b2ecc119c27673e8cc8c858761d253277f3.zip
chromium_src-f7d17b2ecc119c27673e8cc8c858761d253277f3.tar.gz
chromium_src-f7d17b2ecc119c27673e8cc8c858761d253277f3.tar.bz2
, INNTP: Adds 2 hard coded thumbnails.
This code needs to be rewritten after beta to handle localized content. BUG=15079 TEST=Start chrome with a new profile. There should be 2 thumbnails on the new tab page. Review URL: http://codereview.chromium.org/160126 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21608 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd12
-rw-r--r--chrome/app/resources/locale_settings.grd12
-rw-r--r--chrome/app/theme/theme_resources.grd4
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc73
-rw-r--r--chrome/browser/resources/new_new_tab.js5
5 files changed, 99 insertions, 7 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index af5d8f4..9813ca4 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -3634,7 +3634,17 @@ each locale. -->
desc="Action text for link that closes the first run notification.">
Close
</message>
-
+ <!-- TODO: Should this be something none Chrome for Chromium? -->
+ <message name="IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE"
+ desc="Title for the hard coded thumbnail that represents the Google Chrome Welcome page. This is used on the NTP when there aren't enough thumbnails to show.">
+ Google Chrome
+ </message>
+ <!-- TODO: Should this be something none Chrome for Chromium? -->
+ <message name="IDS_NEW_TAB_THEMES_GALLERY_PAGE_TITLE"
+ desc="Title for the hard coded thumbnail that represents the Google Chrome Themes Gallery page. This is used on the NTP when there aren't enough thumbnails to show.">
+ Google Chrome Themes Gallery
+ </message>
+
<!-- SafeBrowsing -->
<message name="IDS_SAFE_BROWSING_MALWARE_TITLE" desc="SafeBrowsing Malware HTML title">
Malware Detected!
diff --git a/chrome/app/resources/locale_settings.grd b/chrome/app/resources/locale_settings.grd
index 3bac605..427210f 100644
--- a/chrome/app/resources/locale_settings.grd
+++ b/chrome/app/resources/locale_settings.grd
@@ -554,11 +554,19 @@
<message name="IDS_LINUX_PROXY_CONFIG_URL" translateable="false">
http://code.google.com/p/chromium/wiki/LinuxProxyConfig
</message>
-
+
<!-- The URL for the themes gallery. -->
+ <!-- TODO(arv): Use GRITLANGCODE -->
<message name="IDS_THEMES_GALLERY_URL" translateable="false">
- https://tools.google.com/chrome/intl/en/themes/index.html
+ https://tools.google.com/chrome/intl/en/themes/
+ </message>
+ <!-- The URL for Google Chrome welcome page. This is used for the pre -->
+ <!-- populated thumbnails. -->
+ <!-- TODO(arv): Use GRITLANGCODE -->
+ <message name="IDS_CHROME_WELCOME_URL" translateable="false">
+ http://www.google.com/chrome/intl/en/welcome.html
</message>
+
</messages>
</release>
</grit>
diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd
index 6e6d996..73ef87f 100644
--- a/chrome/app/theme/theme_resources.grd
+++ b/chrome/app/theme/theme_resources.grd
@@ -184,6 +184,10 @@
<include name="IDR_NEWTAB_OPTION" file="ntp_option.png" type="BINDATA" />
<include name="IDR_NEWTAB_OPTION_H" file="ntp_option_h.png" type="BINDATA" />
<include name="IDR_NEWTAB_OPTION_P" file="ntp_option_p.png" type="BINDATA" />
+ <include name="IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL" file="ntp_welcome_thumb.png" type="BINDATA" />
+ <include name="IDR_NEWTAB_CHROME_WELCOME_PAGE_FAVICON" file="ntp_welcome_favicon.png" type="BINDATA" />
+ <include name="IDR_NEWTAB_THEMES_GALLERY_THUMBNAIL" file="ntp_themes_gallery_thumb.png" type="BINDATA" />
+ <include name="IDR_NEWTAB_THEMES_GALLERY_FAVICON" file="ntp_themes_gallery_favicon.png" type="BINDATA" />
<include name="IDR_ARROW_RIGHT" file="arrow_right.png" type="BINDATA" />
<include name="IDR_SAD_TAB" file="sadtab.png" type="BINDATA" />
<include name="IDR_OTR_ICON" file="otr_icon.png" type="BINDATA" />
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index 75a3272..50f5ec0 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -6,6 +6,8 @@
#include "chrome/browser/dom_ui/new_tab_ui.h"
+#include <set>
+
#include "app/animation.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
@@ -52,7 +54,10 @@
namespace {
// The number of most visited pages we show.
-const size_t kMostVisitedPages = 9;
+const size_t kMostVisitedPages = 8;
+
+// The number of most visited pages we show on the old new tab page.
+const size_t kOldMostVisitedPages = 9;
// The number of days of history we consider for most visited entries.
const int kMostVisitedScope = 90;
@@ -474,6 +479,18 @@ void IncognitoTabHTMLSource::StartDataRequest(const std::string& path,
}
///////////////////////////////////////////////////////////////////////////////
+// MostVisitedPage
+
+// This struct is used when getting the prepopulated pages in case the user
+// hasn't filled up his most visited pages.
+struct MostVisitedPage {
+ std::wstring title;
+ GURL url;
+ GURL thumbnail_url;
+ GURL favicon_url;
+};
+
+///////////////////////////////////////////////////////////////////////////////
// MostVisitedHandler
// The handler for Javascript messages related to the "most visited" view.
@@ -536,6 +553,8 @@ class MostVisitedHandler : public DOMMessageHandler,
void AddPinnedURL(const GURL& url, const std::string& title, int index);
void RemovePinnedURL(const GURL& url);
+ static std::vector<MostVisitedPage> GetPrePopulatedPages();
+
NotificationRegistrar registrar_;
// Our consumer for the history service.
@@ -773,10 +792,13 @@ void MostVisitedHandler::OnSegmentUsageAvailable(
std::vector<PageUsageData*>* data) {
most_visited_urls_.clear();
ListValue pages_value;
+ std::set<GURL> seen_urls;
size_t data_index = 0;
size_t output_index = 0;
- while (output_index < kMostVisitedPages && data_index < data->size()) {
+ const size_t pages_count = NewTabUI::UseOldNewTabPage() ?
+ kOldMostVisitedPages : kMostVisitedPages;
+ while (output_index < pages_count && data_index < data->size()) {
bool pinned = false;
GURL url;
string16 title;
@@ -808,6 +830,7 @@ void MostVisitedHandler::OnSegmentUsageAvailable(
pages_value.Append(page_value);
output_index++;
most_visited_urls_.push_back(url);
+ seen_urls.insert(url);
}
// If we found no pages we treat this as the first run.
@@ -816,9 +839,55 @@ void MostVisitedHandler::OnSegmentUsageAvailable(
// but first_run should only be true once.
NewTabHTMLSource::set_first_run(false);
+ // If we have less than pages_count we add some predetermined pages.
+ if (pages_value.GetSize() < pages_count) {
+ static std::vector<MostVisitedPage> pages =
+ MostVisitedHandler::GetPrePopulatedPages();
+ for (std::vector<MostVisitedPage>::const_iterator it = pages.begin();
+ it != pages.end() && pages_value.GetSize() < pages_count;
+ ++it) {
+ MostVisitedPage page = *it;
+ std::wstring key = GetDictionaryKeyForURL(page.url.spec());
+ if (!pinned_urls_->HasKey(key) && !url_blacklist_->HasKey(key) &&
+ seen_urls.find(page.url) == seen_urls.end()) {
+ DictionaryValue* page_value = new DictionaryValue();
+ SetURLTitleAndDirection(page_value, WideToUTF16(page.title), page.url);
+ page_value->SetBoolean(L"pinned", false);
+ page_value->SetString(L"thumbnailUrl", page.thumbnail_url.spec());
+ page_value->SetString(L"faviconUrl", page.favicon_url.spec());
+ pages_value.Append(page_value);
+ most_visited_urls_.push_back(page.url);
+ seen_urls.insert(page.url);
+ }
+ }
+ }
+
dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value, first_run);
}
+// static
+std::vector<MostVisitedPage> MostVisitedHandler::GetPrePopulatedPages() {
+ // TODO(arv): This needs to get the data from some configurable place.
+ // http://crbug.com/17630
+ std::vector<MostVisitedPage> pages;
+
+ MostVisitedPage welcome_page = {
+ l10n_util::GetString(IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE),
+ GURL(WideToUTF8(l10n_util::GetString(IDS_CHROME_WELCOME_URL))),
+ GURL("chrome://theme/newtab_chrome_welcome_page_thumbnail"),
+ GURL("chrome://theme/newtab_chrome_welcome_page_favicon")};
+ pages.push_back(welcome_page);
+
+ MostVisitedPage gallery_page = {
+ l10n_util::GetString(IDS_NEW_TAB_THEMES_GALLERY_PAGE_TITLE),
+ GURL(WideToUTF8(l10n_util::GetString(IDS_THEMES_GALLERY_URL))),
+ GURL("chrome://theme/newtab_themes_gallery_thumbnail"),
+ GURL("chrome://theme/newtab_themes_gallery_favicon")};
+ pages.push_back(gallery_page);
+
+ return pages;
+}
+
void MostVisitedHandler::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js
index a7adfd6e..034d862 100644
--- a/chrome/browser/resources/new_new_tab.js
+++ b/chrome/browser/resources/new_new_tab.js
@@ -246,10 +246,11 @@ function renderMostVisited(data) {
// attack but setting style.backgroundImage = 'url(javascript:...)' does
// not execute the JavaScript in WebKit.
t.querySelector('.thumbnail-wrapper').style.backgroundImage =
- 'url("chrome://thumb/' + d.url + '")';
+ 'url("' + (d.thumbnailUrl || 'chrome://thumb/' + d.url) + '")';
var titleDiv = t.querySelector('.title > div');
titleDiv.xtitle = titleDiv.textContent = d.title;
- titleDiv.style.backgroundImage = 'url("chrome://favicon/' + d.url + '")';
+ titleDiv.style.backgroundImage = 'url("' +
+ (d.faviconUrl || 'chrome://favicon/' + d.url) + '")';
titleDiv.dir = d.direction;
}
}