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

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

Issue 14685004: Add finch flag for rendering a recently closed link on the local ntp. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 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 42a91740bccf0b0d14aa307f91593595a10f4af6..de54cdb524f4f36998fb7763dd45c23fe0bc89bd 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -8,12 +8,17 @@
#include "base/memory/ref_counted_memory.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
+#include "base/values.h"
+#include "chrome/browser/search/search.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
#include "grit/ui_resources.h"
#include "net/url_request/url_request.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/webui/jstemplate_builder.h"
namespace {
@@ -50,6 +55,13 @@ std::string StripParameters(const std::string& path) {
return path.substr(0, path.find("?"));
}
+// Adds a localized string keyed by resource id to the dictionary.
+void AddString(base::DictionaryValue* dictionary,
+ const std::string& key,
+ int resource_id) {
+ dictionary->SetString(key, l10n_util::GetStringUTF16(resource_id));
+}
+
} // namespace
LocalNtpSource::LocalNtpSource() {
@@ -70,10 +82,23 @@ void LocalNtpSource::StartDataRequest(
const std::string stripped_path = StripParameters(path);
for (size_t i = 0; i < arraysize(kResources); ++i) {
if (stripped_path == kResources[i].filename) {
- scoped_refptr<base::RefCountedStaticMemory> response(
- ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
- kResources[i].identifier));
- callback.Run(response);
+ if (strcmp(kResources[i].mime_type, "text/html") == 0) {
samarth 2013/05/03 04:52:45 Check the IDR or filename instead of relying on a
samarth 2013/05/03 04:52:45 Some sort of test for the new code could be nice.
jeremycho 2013/05/03 06:30:29 Done.
jeremycho 2013/05/03 06:30:29 Will work on this.
+ base::DictionaryValue translated_strings;
+ if (chrome::IsRecentlyClosedNTPLinkEnabled()) {
+ AddString(&translated_strings, "recentlyClosed",
+ IDS_NEW_TAB_RECENTLY_CLOSED);
+ }
+ static const base::StringPiece html(ResourceBundle::GetSharedInstance()
samarth 2013/05/03 04:52:45 Does this (static stringpiece) work? Is the memor
jeremycho 2013/05/03 06:30:29 This idiom is used in other StartDataRequest funct
+ .GetRawDataResource(kResources[i].identifier));
+ std::string i18n_html =
+ webui::GetI18nTemplateHtml(html, &translated_strings);
+ callback.Run(base::RefCountedString::TakeString(&i18n_html));
+ } else {
+ scoped_refptr<base::RefCountedStaticMemory> response(
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
+ kResources[i].identifier));
+ callback.Run(response);
+ }
return;
}
}
@@ -105,6 +130,10 @@ bool LocalNtpSource::ShouldServiceRequest(
return false;
}
+bool LocalNtpSource::ShouldAddContentSecurityPolicy() const {
samarth 2013/05/03 04:52:45 Umm, this is almost certainly a bad idea. I assum
jeremycho 2013/05/03 06:30:29 This is needed for webui::GetI18nTemplateHtml, whi
+ return false;
+}
+
std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const {
// Allow embedding of chrome search suggestion host.
return base::StringPrintf("frame-src %s://%s/;",

Powered by Google App Engine
This is Rietveld 408576698