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

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: Respond to comments. 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
« no previous file with comments | « chrome/browser/search/local_ntp_source.h ('k') | chrome/browser/search/search.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3eb2288a01cb71de19ff6aa0238e63c52acc4303 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,
Jered 2013/05/03 14:38:01 deindent
jeremycho 2013/05/03 21:57:17 Done.
+ 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 (stripped_path == "local-ntp.html") {
Jered 2013/05/03 14:38:01 Make this a const char* and reference it here and
jeremycho 2013/05/03 21:57:17 Done.
+ base::DictionaryValue translated_strings;
+ if (chrome::ShouldShowRecentlyClosedOnNTP()) {
+ AddString(&translated_strings, "recentlyClosed",
+ IDS_NEW_TAB_RECENTLY_CLOSED);
+ }
+ static const base::StringPiece html(ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(kResources[i].identifier));
+ std::string i18n_html =
+ webui::GetI18nTemplateHtml(html, &translated_strings);
Jered 2013/05/03 14:38:01 Ah, I bet you're running into a restriction agains
jeremycho 2013/05/03 21:57:17 Yup, thanks for the pointer. Done.
+ 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 {
+ return false;
Jered 2013/05/03 14:38:01 Don't do this. We're using CSP as a layer of defen
jeremycho 2013/05/03 21:57:17 Removed
+}
+
std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const {
// Allow embedding of chrome search suggestion host.
return base::StringPrintf("frame-src %s://%s/;",
« no previous file with comments | « chrome/browser/search/local_ntp_source.h ('k') | chrome/browser/search/search.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698