diff --git a/components/speedreader/speedreader_rewriter_service.cc b/components/speedreader/speedreader_rewriter_service.cc
index ca0fe331c5c..4db586be093 100644
--- a/components/speedreader/speedreader_rewriter_service.cc
+++ b/components/speedreader/speedreader_rewriter_service.cc
@@ -29,6 +29,16 @@ namespace speedreader {
namespace {
+std::string WrapStylesheetWithCSP(const std::string &stylesheet) {
+ const std::string style_hash = crypto::SHA256HashString(stylesheet);
+ const std::string style_hash_b64 =
+ base::Base64Encode(base::as_bytes(base::make_span(style_hash)));
+
+ return "\n"
+ "";
+}
+
std::string GetDistilledPageStylesheet(const base::FilePath& stylesheet_path) {
std::string stylesheet;
const bool success = base::ReadFileToString(stylesheet_path, &stylesheet);
@@ -39,13 +49,7 @@ std::string GetDistilledPageStylesheet(const base::FilePath& stylesheet_path) {
IDR_SPEEDREADER_STYLE_DESKTOP);
}
- const std::string style_hash = crypto::SHA256HashString(stylesheet);
- const std::string style_hash_b64 =
- base::Base64Encode(base::as_bytes(base::make_span(style_hash)));
-
- return "\n"
- "";
+ return WrapStylesheetWithCSP(stylesheet);
}
} // namespace
@@ -55,11 +59,9 @@ SpeedreaderRewriterService::SpeedreaderRewriterService(
: component_(new speedreader::SpeedreaderComponent(delegate)),
speedreader_(new speedreader::SpeedReader) {
// Load the built-in stylesheet as the default
- content_stylesheet_ =
- "";
+ IDR_SPEEDREADER_STYLE_DESKTOP));
// Check the paths from the component as observer may register
// later than the paths were available in the component.