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; |
} |
} |