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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/dom_distiller/core/viewer.h" 5 #include "components/dom_distiller/core/viewer.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "components/dom_distiller/core/dom_distiller_service.h" 13 #include "components/dom_distiller/core/dom_distiller_service.h"
14 #include "components/dom_distiller/core/proto/distilled_article.pb.h" 14 #include "components/dom_distiller/core/proto/distilled_article.pb.h"
15 #include "components/dom_distiller/core/proto/distilled_page.pb.h" 15 #include "components/dom_distiller/core/proto/distilled_page.pb.h"
16 #include "components/dom_distiller/core/reader_mode_preferences.h"
16 #include "components/dom_distiller/core/task_tracker.h" 17 #include "components/dom_distiller/core/task_tracker.h"
17 #include "components/dom_distiller/core/url_constants.h" 18 #include "components/dom_distiller/core/url_constants.h"
18 #include "components/dom_distiller/core/url_utils.h" 19 #include "components/dom_distiller/core/url_utils.h"
19 #include "grit/component_resources.h" 20 #include "grit/component_resources.h"
20 #include "grit/components_strings.h" 21 #include "grit/components_strings.h"
21 #include "net/base/escape.h" 22 #include "net/base/escape.h"
22 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 namespace dom_distiller { 28 namespace dom_distiller {
28 29
29 namespace { 30 namespace {
30 31
32 std::string GetBodyInsertionText(ReaderModePrefs* reader_mode_prefs) {
33 if (reader_mode_prefs->GetHighContrastPref()) {
34 return "background-color: #000;\ncolor: #FFF;"; // White on black.
35 }
36 else {
battre 2014/06/24 07:46:40 Nit: } else {
smaslo 2014/06/24 18:11:18 Done.
37 return "background-color: #FFF;\ncolor: #000;"; // Black on white.
38 }
39 }
40
31 std::string ReplaceHtmlTemplateValues( 41 std::string ReplaceHtmlTemplateValues(
32 const std::string& title, 42 const std::string& title,
33 const std::string& content, 43 const std::string& content,
34 const std::string& loading_indicator_class, 44 const std::string& loading_indicator_class,
35 const std::string& original_url) { 45 const std::string& original_url) {
36 base::StringPiece html_template = 46 base::StringPiece html_template =
37 ResourceBundle::GetSharedInstance().GetRawDataResource( 47 ResourceBundle::GetSharedInstance().GetRawDataResource(
38 IDR_DOM_DISTILLER_VIEWER_HTML); 48 IDR_DOM_DISTILLER_VIEWER_HTML);
39 std::vector<std::string> substitutions; 49 std::vector<std::string> substitutions;
40 substitutions.push_back(title); // $1 50 substitutions.push_back(title); // $1
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 130 }
121 131
122 const std::string GetErrorPageHtml() { 132 const std::string GetErrorPageHtml() {
123 std::string title = l10n_util::GetStringUTF8( 133 std::string title = l10n_util::GetStringUTF8(
124 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); 134 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE);
125 std::string content = l10n_util::GetStringUTF8( 135 std::string content = l10n_util::GetStringUTF8(
126 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); 136 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT);
127 return ReplaceHtmlTemplateValues(title, content, "hidden", ""); 137 return ReplaceHtmlTemplateValues(title, content, "hidden", "");
128 } 138 }
129 139
130 const std::string GetCss() { 140 const std::string GetCss(ReaderModePrefs* reader_mode_prefs) {
131 return ResourceBundle::GetSharedInstance() 141 std::vector<std::string> substitutions;
132 .GetRawDataResource(IDR_DISTILLER_CSS) 142 substitutions.push_back(GetBodyInsertionText(reader_mode_prefs));
133 .as_string(); 143 base::StringPiece css_template =
144 ResourceBundle::GetSharedInstance().GetRawDataResource(
145 IDR_DISTILLER_CSS);
146 return ReplaceStringPlaceholders(css_template, substitutions, NULL);
134 } 147 }
135 148
136 const std::string GetJavaScript() { 149 const std::string GetJavaScript() {
137 return ResourceBundle::GetSharedInstance() 150 return ResourceBundle::GetSharedInstance()
138 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) 151 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS)
139 .as_string(); 152 .as_string();
140 } 153 }
141 154
142 scoped_ptr<ViewerHandle> CreateViewRequest( 155 scoped_ptr<ViewerHandle> CreateViewRequest(
143 DomDistillerServiceInterface* dom_distiller_service, 156 DomDistillerServiceInterface* dom_distiller_service,
(...skipping 27 matching lines...) Expand all
171 requested_url).Pass(); 184 requested_url).Pass();
172 } 185 }
173 186
174 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. 187 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|.
175 return scoped_ptr<ViewerHandle>(); 188 return scoped_ptr<ViewerHandle>();
176 } 189 }
177 190
178 } // namespace viewer 191 } // namespace viewer
179 192
180 } // namespace dom_distiller 193 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698