Index: components/dom_distiller/core/viewer.cc |
diff --git a/components/dom_distiller/core/viewer.cc b/components/dom_distiller/core/viewer.cc |
index e3c77962dce2a522e0c6ae5ccf016f09629151eb..7b61b063f6a39fdae60943e36b8ce559bf679421 100644 |
--- a/components/dom_distiller/core/viewer.cc |
+++ b/components/dom_distiller/core/viewer.cc |
@@ -10,6 +10,7 @@ |
#include "base/json/json_writer.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/strings/string_util.h" |
+#include "components/dom_distiller/core/distilled_page_prefs.h" |
#include "components/dom_distiller/core/dom_distiller_service.h" |
#include "components/dom_distiller/core/proto/distilled_article.pb.h" |
#include "components/dom_distiller/core/proto/distilled_page.pb.h" |
@@ -28,11 +29,28 @@ namespace dom_distiller { |
namespace { |
+// JS Themes. |
+const char kDarkJsTheme[] = "dark"; |
+const char kLightJsTheme[] = "light"; |
+const char kSepiaJsTheme[] = "sepia"; |
+ |
+// Maps themes to CSS classes. Text returned must agree with themes in |
+// css/distilledpage.css. |
+const std::string GetJsTheme(DistilledPagePrefs::Theme theme) { |
+ if (theme == DistilledPagePrefs::Theme::kDark) { |
+ return kDarkJsTheme; |
+ } else if (theme == DistilledPagePrefs::Theme::kSepia) { |
+ return kSepiaJsTheme; |
+ } |
+ return kLightJsTheme; |
+} |
+ |
std::string ReplaceHtmlTemplateValues( |
const std::string& title, |
const std::string& content, |
const std::string& loading_indicator_class, |
- const std::string& original_url) { |
+ const std::string& original_url, |
+ const DistilledPagePrefs::Theme theme) { |
base::StringPiece html_template = |
ResourceBundle::GetSharedInstance().GetRawDataResource( |
IDR_DOM_DISTILLER_VIEWER_HTML); |
@@ -40,7 +58,7 @@ std::string ReplaceHtmlTemplateValues( |
substitutions.push_back(title); // $1 |
substitutions.push_back(kViewerCssPath); // $2 |
substitutions.push_back(kViewerJsPath); // $3 |
- substitutions.push_back(title); // $4 |
+ substitutions.push_back(GetJsTheme(theme)); // $4 |
substitutions.push_back(content); // $5 |
substitutions.push_back(loading_indicator_class); // $6 |
substitutions.push_back( |
@@ -76,7 +94,8 @@ const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { |
} |
const std::string GetUnsafePartialArticleHtml( |
- const DistilledPageProto* page_proto) { |
+ const DistilledPageProto* page_proto, |
+ const DistilledPagePrefs::Theme theme) { |
DCHECK(page_proto); |
std::string title = net::EscapeForHTML(page_proto->title()); |
std::ostringstream unsafe_output_stream; |
@@ -86,11 +105,13 @@ const std::string GetUnsafePartialArticleHtml( |
return ReplaceHtmlTemplateValues(title, |
unsafe_article_html, |
"visible", |
- original_url); |
+ original_url, |
+ theme); |
} |
const std::string GetUnsafeArticleHtml( |
- const DistilledArticleProto* article_proto) { |
+ const DistilledArticleProto* article_proto, |
+ const DistilledPagePrefs::Theme theme) { |
DCHECK(article_proto); |
std::string title; |
std::string unsafe_article_html; |
@@ -116,21 +137,21 @@ const std::string GetUnsafeArticleHtml( |
return ReplaceHtmlTemplateValues(title, |
unsafe_article_html, |
"hidden", |
- original_url); |
+ original_url, |
+ theme); |
} |
-const std::string GetErrorPageHtml() { |
+const std::string GetErrorPageHtml(const DistilledPagePrefs::Theme theme) { |
std::string title = l10n_util::GetStringUTF8( |
IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); |
std::string content = l10n_util::GetStringUTF8( |
IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); |
- return ReplaceHtmlTemplateValues(title, content, "hidden", ""); |
+ return ReplaceHtmlTemplateValues(title, content, "hidden", "", theme); |
} |
const std::string GetCss() { |
- return ResourceBundle::GetSharedInstance() |
- .GetRawDataResource(IDR_DISTILLER_CSS) |
- .as_string(); |
+ return ResourceBundle::GetSharedInstance().GetRawDataResource( |
+ IDR_DISTILLER_CSS).as_string(); |
} |
const std::string GetJavaScript() { |
@@ -175,6 +196,13 @@ scoped_ptr<ViewerHandle> CreateViewRequest( |
return scoped_ptr<ViewerHandle>(); |
} |
+const std::string GetDistilledPageThemeJs(DistilledPagePrefs::Theme theme) { |
+ std::ostringstream js; |
+ js << "document.body.className='" << |
nyquist
2014/07/07 19:12:49
Instead of doing this, could you instead call a Ja
smaslo
2014/07/08 19:58:11
Done.
|
+ GetJsTheme(theme) << "';"; |
+ return js.str(); |
+} |
+ |
} // namespace viewer |
} // namespace dom_distiller |