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

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

Issue 1376243005: Enabling included files when reloading local NTP with --local-ntp-reload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « no previous file | no next file » | 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 7fecfbfbe1274de97ae4bccf153a81c60e229ef4..888d4a6b4994d118fb487f5d84d19297da180dc0 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -26,6 +26,8 @@
#include "grit/browser_resources.h"
#include "grit/theme_resources.h"
#include "net/url_request/url_request.h"
+#include "third_party/re2/re2/re2.h"
+#include "third_party/re2/re2/stringpiece.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
@@ -41,6 +43,8 @@ const int kLocalResource = -1;
const char kConfigDataFilename[] = "config.js";
+const std::string kInlineResouceRegex = "<include.*?src\\=[\"'](.+?)[\"'].*?>";
fserb 2015/10/06 15:53:17 add a comment saying what you want to match with t
+
const struct Resource{
const char* filename;
int identifier;
@@ -174,6 +178,44 @@ std::string LocalNtpSource::GetSource() const {
return chrome::kChromeSearchLocalNtpHost;
}
+void FlattenLocalInclude(
fserb 2015/10/06 15:53:17 can you add a comment here explaining the flow of
Mathieu 2015/10/09 15:10:38 should be a private method and you wouldn't need t
+ const content::URLDataSource::GotDataCallback& callback,
+ std::string topLevelResource,
+ base::RefCountedMemory* inlineResource);
+
+void CheckLocalIncludesHelper(
+ const content::URLDataSource::GotDataCallback& callback,
+ std::string resource) {
+ std::string filename;
+ re2::StringPiece resourceWrapper(resource);
+ if (re2::RE2::FindAndConsume(&resourceWrapper, kInlineResouceRegex,
+ &filename)) {
+ content::URLDataSource::GotDataCallback wrapper =
+ base::Bind(&FlattenLocalInclude, callback, resource);
+ local_ntp::SendLocalFileResource(filename, wrapper);
+ // FlattenLocalInclude(callback, resource,
fserb 2015/10/06 15:53:17 remove those lines?
+ // base::RefCountedString::TakeString(new std::string("foobar")));
+ } else {
+ callback.Run(base::RefCountedString::TakeString(&resource));
+ }
+}
+
+void CheckLocalIncludes(const content::URLDataSource::GotDataCallback& callback,
fserb 2015/10/06 15:53:17 couldn't this and FlattenLocalInclude be the same
tmartino 2015/10/15 20:54:16 This doesn't really work, actually. We have two pl
+ base::RefCountedMemory* resource) {
+ std::string resourceAsStr(resource->front_as<char>(), resource->size());
+ CheckLocalIncludesHelper(callback, resourceAsStr);
+}
+
+void FlattenLocalInclude(
+ const content::URLDataSource::GotDataCallback& callback,
+ std::string topLevelResource,
+ base::RefCountedMemory* inlineResource) {
+ std::string inlineAsStr(inlineResource->front_as<char>(),
+ inlineResource->size());
+ re2::RE2::Replace(&topLevelResource, kInlineResouceRegex, inlineAsStr);
+ CheckLocalIncludesHelper(callback, topLevelResource);
+}
+
void LocalNtpSource::StartDataRequest(
const std::string& path,
int render_process_id,
@@ -192,7 +234,9 @@ void LocalNtpSource::StartDataRequest(
if (stripped_path == "local-ntp.html" || stripped_path == "local-ntp.js" ||
stripped_path == "local-ntp.css") {
base::ReplaceChars(stripped_path, "-", "_", &stripped_path);
- local_ntp::SendLocalFileResource(stripped_path, callback);
+ content::URLDataSource::GotDataCallback wrapper =
+ base::Bind(&CheckLocalIncludes, callback);
+ local_ntp::SendLocalFileResource(stripped_path, wrapper);
return;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698