From 3c5fb368e1e3606015bee801e019a9727367aa1d Mon Sep 17 00:00:00 2001 From: Peter Snyder Date: Fri, 10 Dec 2021 15:06:52 -0600 Subject: [PATCH] move CSP code to a helper funciton, apply to stylesheet property --- .../speedreader_rewriter_service.cc | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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.