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

Unified Diff: components/dom_distiller/core/distiller_page.cc

Issue 1004223002: Pass more information by argument to the dom_distiller script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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: components/dom_distiller/core/distiller_page.cc
diff --git a/components/dom_distiller/core/distiller_page.cc b/components/dom_distiller/core/distiller_page.cc
index 1e70b83a2a51906811a7b6a879bd5a3ffb51644f..b8bcd28ff8ea524faed199e3a185be1c86dfd71c 100644
--- a/components/dom_distiller/core/distiller_page.cc
+++ b/components/dom_distiller/core/distiller_page.cc
@@ -23,9 +23,13 @@ namespace dom_distiller {
namespace {
const char* kOptionsPlaceholder = "$$OPTIONS";
+const char* kStringifyPlaceholder = "$$STRINGIFY";
+const char* kNewContextPlaceholder = "$$NEW_CONTEXT";
std::string GetDistillerScriptWithOptions(
- const dom_distiller::proto::DomDistillerOptions& options) {
+ const dom_distiller::proto::DomDistillerOptions& options,
+ bool stringify_output,
+ bool create_new_context) {
std::string script = ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_DISTILLER_JS)
.as_string();
@@ -45,6 +49,25 @@ std::string GetDistillerScriptWithOptions(
script.find(kOptionsPlaceholder, options_offset + 1));
script =
script.replace(options_offset, strlen(kOptionsPlaceholder), options_json);
+
+ std::string stringify = stringify_output ? "true" : "false";
+ size_t stringify_offset = script.find(kStringifyPlaceholder);
+ DCHECK_NE(std::string::npos, stringify_offset);
+ DCHECK_EQ(std::string::npos,
+ script.find(kStringifyPlaceholder, stringify_offset + 1));
+ script = script.replace(stringify_offset,
+ strlen(kStringifyPlaceholder),
+ stringify);
+
+ std::string new_context = create_new_context ? "true" : "false";
+ size_t new_context_offset = script.find(kNewContextPlaceholder);
+ DCHECK_NE(std::string::npos, new_context_offset);
+ DCHECK_EQ(std::string::npos,
+ script.find(kNewContextPlaceholder, new_context_offset + 1));
+ script = script.replace(new_context_offset,
+ strlen(kNewContextPlaceholder),
+ new_context);
+
return script;
}
@@ -65,7 +88,9 @@ void DistillerPage::DistillPage(
// the callback to OnDistillationDone happens.
ready_ = false;
distiller_page_callback_ = callback;
- DistillPageImpl(gurl, GetDistillerScriptWithOptions(options));
+ DistillPageImpl(gurl, GetDistillerScriptWithOptions(options,
+ StringifyOutput(),
+ CreateNewContext()));
}
void DistillerPage::OnDistillationDone(const GURL& page_url,

Powered by Google App Engine
This is Rietveld 408576698