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.
|
+ |