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

Unified Diff: components/dom_distiller/core/reader_mode_preferences.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/reader_mode_preferences.cc
diff --git a/components/dom_distiller/core/reader_mode_preferences.cc b/components/dom_distiller/core/reader_mode_preferences.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed41065e4811fc3fc495253fec01b428e4386d24
--- /dev/null
+++ b/components/dom_distiller/core/reader_mode_preferences.cc
@@ -0,0 +1,78 @@
+// Copyright 2014 The Chromium Authros. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/core/reader_mode_preferences.h"
+
+#include <string>
+#include <vector>
+
+#include "base/prefs/pref_service.h"
+#include "base/strings/string_util.h"
+#include "components/dom_distiller/core/url_constants.h"
+#include "components/pref_registry/pref_registry_syncable.h"
+#include "grit/component_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace prefs {
+ const char kHigh_Contrast_Pref[] = "reader_mode.high_contrast";
+}
+
+namespace dom_distiller {
+
+namespace {
+ const char WHITE[] = "#FFF";
+ const char BLACK[] = "#000";
+} // namespace
+
+ReaderModePrefs::ReaderModePrefs(PrefService* current_pref_service) {
robliao 2014/06/17 18:01:49 Consistency: pref_service as a name should work fi
smaslo 2014/06/17 22:44:07 Done.
+ DCHECK(current_pref_service);
+ ReaderModePrefs::pref_service = current_pref_service;
robliao 2014/06/17 18:01:49 Put this in a constructor initializer list. http:/
smaslo 2014/06/17 22:44:08 Done.
+}
+
robliao 2014/06/17 18:01:49 Remove extra line.
smaslo 2014/06/17 22:44:08 Done.
+
+std::string ReaderModePrefs::ReplaceCSSTemplateValues() {
robliao 2014/06/17 18:01:50 This should really go into the viewer code near Ge
smaslo 2014/06/17 22:44:07 Done.
+ std::vector<std::string> substitutions;
+ substitutions.push_back(GetBodyInsertionText());
+ base::StringPiece css_template =
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DISTILLER_CSS);
+ return ReplaceStringPlaceholders(css_template, substitutions, NULL);
+}
+
+void ReaderModePrefs::OnChangeHighContrast(bool new_value) {
+ pref_service->SetBoolean(prefs::kHigh_Contrast_Pref, new_value);
+}
+
+void ReaderModePrefs::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterBooleanPref(prefs::kHigh_Contrast_Pref,
+ false,
+ user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+ }
+
+bool ReaderModePrefs::GetHighContrastPref() {
+ return pref_service->GetBoolean(prefs::kHigh_Contrast_Pref);
+}
+
+std::string ReaderModePrefs::GetBodyInsertionText() {
+ if (pref_service->GetBoolean(prefs::kHigh_Contrast_Pref)) {
+ std::string body_insertion_text = "background-color: ";
+ body_insertion_text += BLACK;
+ body_insertion_text += ";\ncolor: ";
+ body_insertion_text += WHITE;
+ body_insertion_text += ";";
+ return body_insertion_text;
+ }
+ else {
+ std::string body_insertion_text = "background-color: ";
+ body_insertion_text += WHITE;
+ body_insertion_text += ";\ncolor: ";
+ body_insertion_text += BLACK;
+ body_insertion_text += ";";
+ return body_insertion_text;
+ }
+}
+
+} // namespace dom_distiller
robliao 2014/06/17 18:01:49 One more space required between } and //
smaslo 2014/06/17 22:44:07 Done.
+

Powered by Google App Engine
This is Rietveld 408576698