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

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

Issue 901793002: Add support for providing an external file for extracting content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved injection to constructor 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..759b7851ce6b9bd0a470d8f4ccf97eb3e9056dae 100644
--- a/components/dom_distiller/core/distiller_page.cc
+++ b/components/dom_distiller/core/distiller_page.cc
@@ -25,10 +25,8 @@ namespace {
const char* kOptionsPlaceholder = "$$OPTIONS";
std::string GetDistillerScriptWithOptions(
+ const std::string& script,
const dom_distiller::proto::DomDistillerOptions& options) {
- std::string script = ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_DISTILLER_JS)
- .as_string();
if (script.empty()) {
return "";
}
@@ -43,16 +41,20 @@ std::string GetDistillerScriptWithOptions(
DCHECK_NE(std::string::npos, options_offset);
DCHECK_EQ(std::string::npos,
script.find(kOptionsPlaceholder, options_offset + 1));
- script =
- script.replace(options_offset, strlen(kOptionsPlaceholder), options_json);
- return script;
+ // Make a copy of |script| so the options can be applied.
+ std::string script_with_options = script;
+ script_with_options = script_with_options.replace(
+ options_offset, strlen(kOptionsPlaceholder), options_json);
+ return script_with_options;
}
}
DistillerPageFactory::~DistillerPageFactory() {}
-DistillerPage::DistillerPage() : ready_(true) {}
+DistillerPage::DistillerPage(const std::string& distiller_js_script)
+ : ready_(true), distiller_js_script_(distiller_js_script) {
+}
DistillerPage::~DistillerPage() {}
@@ -65,7 +67,8 @@ void DistillerPage::DistillPage(
// the callback to OnDistillationDone happens.
ready_ = false;
distiller_page_callback_ = callback;
- DistillPageImpl(gurl, GetDistillerScriptWithOptions(options));
+ DistillPageImpl(gurl,
+ GetDistillerScriptWithOptions(distiller_js_script_, options));
}
void DistillerPage::OnDistillationDone(const GURL& page_url,

Powered by Google App Engine
This is Rietveld 408576698