Chromium Code Reviews| 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, |