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, |