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

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: Created 5 years, 10 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..577be4a60129f59c855aa613829ce65d0dde6720 100644
--- a/components/dom_distiller/core/distiller_page.cc
+++ b/components/dom_distiller/core/distiller_page.cc
@@ -25,11 +25,11 @@ 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()) {
+ // Make a copy of |script| so the options can be applied.
+ std::string script_with_options = script;
+ if (script_with_options.empty()) {
cjhopman 2015/02/05 02:09:40 this could just check script.empty() rather than w
nyquist 2015/02/06 18:50:32 Done.
return "";
}
@@ -39,20 +39,28 @@ std::string GetDistillerScriptWithOptions(
if (!base::JSONWriter::Write(options_value.get(), &options_json)) {
NOTREACHED();
}
- size_t options_offset = script.find(kOptionsPlaceholder);
+ size_t options_offset = script_with_options.find(kOptionsPlaceholder);
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;
+ script_with_options.find(kOptionsPlaceholder, options_offset + 1));
+ script_with_options = script_with_options.replace(
cjhopman 2015/02/05 02:09:40 I'd move the copy down here where it's needed.
nyquist 2015/02/06 18:50:32 Done.
+ options_offset, strlen(kOptionsPlaceholder), options_json);
+ return script_with_options;
}
}
DistillerPageFactory::~DistillerPageFactory() {}
-DistillerPage::DistillerPage() : ready_(true) {}
+DistillerPage::DistillerPage() : ready_(true) {
+ distiller_js_script_ = ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_DISTILLER_JS)
+ .as_string();
+}
+
+DistillerPage::DistillerPage(std::string distiller_js_script)
+ : ready_(true), distiller_js_script_(distiller_js_script) {
+}
DistillerPage::~DistillerPage() {}
@@ -65,7 +73,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