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

Unified Diff: components/dom_distiller/core/viewer.cc

Issue 341563002: Theme Preferences for Distilled Pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor changes Created 6 years, 6 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/core/viewer.cc
diff --git a/components/dom_distiller/core/viewer.cc b/components/dom_distiller/core/viewer.cc
index e3c77962dce2a522e0c6ae5ccf016f09629151eb..c06becb426cd5d6f5a89ad805d095fb4132a0b3c 100644
--- a/components/dom_distiller/core/viewer.cc
+++ b/components/dom_distiller/core/viewer.cc
@@ -13,6 +13,7 @@
#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"
+#include "components/dom_distiller/core/reader_mode_preferences.h"
#include "components/dom_distiller/core/task_tracker.h"
#include "components/dom_distiller/core/url_constants.h"
#include "components/dom_distiller/core/url_utils.h"
@@ -28,11 +29,17 @@ namespace dom_distiller {
namespace {
+// CSS class names - must agree with css/distilledpage.css.
+const char kDarkClassName[] = "dark";
+const char kLightClassName[] = "light";
+const char kSepiaClassName[] = "sepia";
+
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 ReaderModePrefs::Theme theme) {
base::StringPiece html_template =
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_DOM_DISTILLER_VIEWER_HTML);
@@ -40,7 +47,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(viewer::GetBodyCssClass(theme)); // $4
substitutions.push_back(content); // $5
substitutions.push_back(loading_indicator_class); // $6
substitutions.push_back(
@@ -76,7 +83,8 @@ const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) {
}
const std::string GetUnsafePartialArticleHtml(
- const DistilledPageProto* page_proto) {
+ const DistilledPageProto* page_proto,
+ const ReaderModePrefs::Theme theme) {
DCHECK(page_proto);
std::string title = net::EscapeForHTML(page_proto->title());
std::ostringstream unsafe_output_stream;
@@ -86,11 +94,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 ReaderModePrefs::Theme theme) {
DCHECK(article_proto);
std::string title;
std::string unsafe_article_html;
@@ -116,21 +126,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 ReaderModePrefs::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 +185,16 @@ scoped_ptr<ViewerHandle> CreateViewRequest(
return scoped_ptr<ViewerHandle>();
}
+const char* GetBodyCssClass(ReaderModePrefs::Theme theme) {
nyquist 2014/06/27 20:48:27 I guess this could be added a unittest for?
smaslo 2014/06/30 17:57:15 Done.
+ if (theme == ReaderModePrefs::Theme::kDark) {
+ return kDarkClassName;
+ } else if (theme == ReaderModePrefs::Theme::kSepia) {
+ return kSepiaClassName;
+ } else {
+ return kLightClassName;
nyquist 2014/06/27 20:48:27 Remove the else block and just return kLightClassN
smaslo 2014/06/30 17:57:15 Done.
+ }
+}
+
} // namespace viewer
} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698