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

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: Added browsertest, changed to use CSP object-src instead of frame-src 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 d83252b5433babb0b0d03d7dc377bb78dfc4a863..aa150d7604da61996bc2bf09b570f19ed27dc63a 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,8 +117,17 @@ 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;
+ }
+
scoped_ptr<RequestViewerHandle> request_viewer_handle(
new RequestViewerHandle(callback));
+
std::string entry_id = StringToUpperASCII(path);
scoped_ptr<ViewerHandle> viewer_handle =
dom_distiller_service_->ViewEntry(request_viewer_handle.get(), entry_id);
@@ -125,7 +137,7 @@ void DomDistillerViewerSource::StartDataRequest(
// request is not cancelled. The |RequestViewerHandle| will delete itself
// after receiving the callback.
request_viewer_handle.get()->TakeViewerHandle(viewer_handle.Pass());
- (void) request_viewer_handle.release();
+ (void)request_viewer_handle.release();
} else {
std::string title = l10n_util::GetStringUTF8(
IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE);
@@ -138,6 +150,8 @@ void DomDistillerViewerSource::StartDataRequest(
std::string DomDistillerViewerSource::GetMimeType(const std::string& path)
const {
+ if (path == kCssPath)
+ return "text/css";
return "text/html";
}
@@ -149,9 +163,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