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

Unified Diff: components/dom_distiller/content/dom_distiller_viewer_source.cc

Issue 138923002: Add support for showing CSS with distilled articles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nit from cjhopman@ Created 6 years, 11 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/content/dom_distiller_viewer_source.cc
diff --git a/components/dom_distiller/content/dom_distiller_viewer_source.cc b/components/dom_distiller/content/dom_distiller_viewer_source.cc
index c9fa6df11a46f2c5fb4a52da53193f0ffd88ae1f..ec1751dd7466aaac618a94a5446ca639aed9b9c1 100644
--- a/components/dom_distiller/content/dom_distiller_viewer_source.cc
+++ b/components/dom_distiller/content/dom_distiller_viewer_source.cc
@@ -26,14 +26,17 @@
namespace {
+const char kCssPath[] = "readability.css";
+
std::string ReplaceHtmlTemplateValues(std::string title, std::string content) {
base::StringPiece html_template =
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_DOM_DISTILLER_VIEWER_HTML);
std::vector<std::string> substitutions;
- substitutions.push_back(title); // $1
- substitutions.push_back(title); // $2
- substitutions.push_back(content); // $3
+ substitutions.push_back(title); // $1
+ substitutions.push_back(kCssPath); // $2
+ substitutions.push_back(title); // $3
+ substitutions.push_back(content); // $4
return ReplaceStringPlaceholders(html_template, substitutions, NULL);
}
@@ -114,6 +117,14 @@ void DomDistillerViewerSource::StartDataRequest(
DCHECK(render_view_host);
CHECK_EQ(0, render_view_host->GetEnabledBindings());
+ if (kCssPath == path) {
+ std::string css = ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_DISTILLER_CSS)
+ .as_string();
+ callback.Run(base::RefCountedString::TakeString(&css));
+ return;
+ }
+
RequestViewerHandle* request_viewer_handle =
new RequestViewerHandle(callback);
std::string entry_id = StringToUpperASCII(path);
@@ -141,6 +152,8 @@ void DomDistillerViewerSource::StartDataRequest(
std::string DomDistillerViewerSource::GetMimeType(const std::string& path)
const {
+ if (path == kCssPath)
+ return "text/css";
return "text/html";
}
@@ -152,9 +165,16 @@ bool DomDistillerViewerSource::ShouldServiceRequest(
void DomDistillerViewerSource::WillServiceRequest(
const net::URLRequest* request,
std::string* path) const {
- // Since the full request is not available to StartDataRequest, replace the
- // path to contain the data needed.
- *path = request->url().host();
+ if (*path != kCssPath) {
+ // Since the full request is not available to StartDataRequest, replace the
+ // path to contain the data needed.
+ *path = request->url().host();
+ }
};
+std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc()
+ const {
+ return "object-src 'none'; style-src 'self'";
+}
+
} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698