summaryrefslogtreecommitdiffstats
path: root/components/dom_distiller
diff options
context:
space:
mode:
authornyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-29 11:25:26 +0000
committernyquist@chromium.org <nyquist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-29 11:25:26 +0000
commit0493190979fa7c4e6ec5bf8dc5067975a60cb371 (patch)
tree7fac2098016862559a1e9904269116731d5884dc /components/dom_distiller
parent07fe275de8629a032af6b0745ed4a146a9ec447e (diff)
downloadchromium_src-0493190979fa7c4e6ec5bf8dc5067975a60cb371.zip
chromium_src-0493190979fa7c4e6ec5bf8dc5067975a60cb371.tar.gz
chromium_src-0493190979fa7c4e6ec5bf8dc5067975a60cb371.tar.bz2
Add support for showing CSS with distilled articles.
Adds the Readability CSS and also makes the DOM Distiller viewer load it. BUG=319881 Review URL: https://codereview.chromium.org/138923002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/dom_distiller')
-rw-r--r--components/dom_distiller/content/dom_distiller_viewer_source.cc32
-rw-r--r--components/dom_distiller/content/dom_distiller_viewer_source.h1
-rw-r--r--components/dom_distiller/content/resources/dom_distiller_viewer.html5
3 files changed, 30 insertions, 8 deletions
diff --git a/components/dom_distiller/content/dom_distiller_viewer_source.cc b/components/dom_distiller/content/dom_distiller_viewer_source.cc
index c9fa6df..ec1751d 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
diff --git a/components/dom_distiller/content/dom_distiller_viewer_source.h b/components/dom_distiller/content/dom_distiller_viewer_source.h
index e2b168a..eb7559b 100644
--- a/components/dom_distiller/content/dom_distiller_viewer_source.h
+++ b/components/dom_distiller/content/dom_distiller_viewer_source.h
@@ -33,6 +33,7 @@ class DomDistillerViewerSource : public content::URLDataSource {
const OVERRIDE;
virtual void WillServiceRequest(const net::URLRequest* request,
std::string* path) const OVERRIDE;
+ virtual std::string GetContentSecurityPolicyObjectSrc() const OVERRIDE;
// The scheme this URLDataSource is hosted under.
std::string scheme_;
diff --git a/components/dom_distiller/content/resources/dom_distiller_viewer.html b/components/dom_distiller/content/resources/dom_distiller_viewer.html
index 996cabd6..709e76c 100644
--- a/components/dom_distiller/content/resources/dom_distiller_viewer.html
+++ b/components/dom_distiller/content/resources/dom_distiller_viewer.html
@@ -8,15 +8,16 @@ found in the LICENSE file.
<head>
<meta charset="utf-8">
<title>$1</title>
+ <link rel="stylesheet" type="text/css" href="$2">
</head>
<body>
<div id="mainContent">
<div id="article">
<article>
<header>
- <h1>$2</h1>
+ <h1>$3</h1>
</header>
- <div id="content">$3</div>
+ <div id="content">$4</div>
</article>
</div>
</div>