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

Unified Diff: chrome/browser/search/local_ntp_source.cc

Issue 19054012: Reload Local NTP on default search provider change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 7 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
Index: chrome/browser/search/local_ntp_source.cc
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc
index 84f63817ae5e5c1ee3c4b6d38976e7a9a926ecab..b387255e62ea8b5e8a7e09b47dbf0b122c44c039 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/search/local_ntp_source.h"
+#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_util.h"
@@ -26,7 +27,7 @@ namespace {
// Signifies a locally constructed resource, i.e. not from grit/.
const int kLocalResource = -1;
-const char kTranslatedStringsFilename[] = "translated-strings.js";
+const char kConfigDataFilename[] = "config.js";
const struct Resource{
const char* filename;
@@ -35,7 +36,7 @@ const struct Resource{
} kResources[] = {
{ "local-ntp.html", IDR_LOCAL_NTP_HTML, "text/html" },
{ "local-ntp.js", IDR_LOCAL_NTP_JS, "application/javascript" },
- { kTranslatedStringsFilename, kLocalResource, "application/javascript" },
+ { kConfigDataFilename, kLocalResource, "application/javascript" },
{ "local-ntp.css", IDR_LOCAL_NTP_CSS, "text/css" },
{ "images/close_2.png", IDR_CLOSE_2, "image/png" },
{ "images/close_2_hover.png", IDR_CLOSE_2_H, "image/png" },
@@ -67,30 +68,50 @@ void AddString(base::DictionaryValue* dictionary,
dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id));
}
-// Returns a JS dictionary of translated strings for the local NTP.
-std::string GetTranslatedStrings() {
- base::DictionaryValue translated_strings;
+// Populates |translated_strings| dictionary for the local NTP.
+void GetTranslatedStrings(base::DictionaryValue* translated_strings) {
if (chrome::ShouldShowRecentTabsOnNTP())
- AddString(&translated_strings, "recentTabs", IDS_RECENT_TABS_MENU);
- AddString(&translated_strings, "thumbnailRemovedNotification",
+ AddString(translated_strings, "recentTabs", IDS_RECENT_TABS_MENU);
+
+ AddString(translated_strings, "thumbnailRemovedNotification",
IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION);
- AddString(&translated_strings, "removeThumbnailTooltip",
+ AddString(translated_strings, "removeThumbnailTooltip",
IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP);
- AddString(&translated_strings, "undoThumbnailRemove",
+ AddString(translated_strings, "undoThumbnailRemove",
IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE);
- AddString(&translated_strings, "restoreThumbnailsShort",
+ AddString(translated_strings, "restoreThumbnailsShort",
IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK);
- AddString(&translated_strings, "attributionIntro",
+ AddString(translated_strings, "attributionIntro",
IDS_NEW_TAB_ATTRIBUTION_INTRO);
- AddString(&translated_strings, "title", IDS_NEW_TAB_TITLE);
- std::string translated_strings_js;
- webui::AppendJsonJS(&translated_strings, &translated_strings_js);
- return translated_strings_js;
+ AddString(translated_strings, "title", IDS_NEW_TAB_TITLE);
+}
+
+// Returns a JS dictionary of configuration data for the local NTP.
+std::string GetConfigData(Profile* profile) {
+ base::DictionaryValue* translated_strings = new base::DictionaryValue();
samarth 2013/07/17 16:39:45 Use a scoped_ptr here and then use .release() when
kmadhusu 2013/07/17 17:58:03 Done.
+ GetTranslatedStrings(translated_strings);
+
+ // Configuration data.
+ base::DictionaryValue config_data;
+ config_data.Set("translatedStrings", translated_strings);
+ config_data.SetBoolean("isGooglePage",
+ chrome::DefaultSearchProviderIsGoogle(profile));
+
+ // Serialize the dictionary.
+ std::string js_text;
+ JSONStringValueSerializer serializer(&js_text);
+ serializer.Serialize(config_data);
+
+ std::string config_data_js;
+ config_data_js.append("var configData = ");
+ config_data_js.append(js_text);
+ config_data_js.append(";");
+ return config_data_js;
}
} // namespace
-LocalNtpSource::LocalNtpSource() {
+LocalNtpSource::LocalNtpSource(Profile* profile) : profile_(profile) {
}
LocalNtpSource::~LocalNtpSource() {
@@ -106,9 +127,9 @@ void LocalNtpSource::StartDataRequest(
int render_view_id,
const content::URLDataSource::GotDataCallback& callback) {
const std::string stripped_path = StripParameters(path);
- if (stripped_path == kTranslatedStringsFilename) {
- std::string translated_strings_js = GetTranslatedStrings();
- callback.Run(base::RefCountedString::TakeString(&translated_strings_js));
+ if (stripped_path == kConfigDataFilename) {
+ std::string config_data_js = GetConfigData(profile_);
+ callback.Run(base::RefCountedString::TakeString(&config_data_js));
return;
}
for (size_t i = 0; i < arraysize(kResources); ++i) {

Powered by Google App Engine
This is Rietveld 408576698