OLD | NEW |
---|---|
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. | |
nyquist
2014/06/24 23:08:49
Could you have this as a CSS class on the document
smaslo
2014/06/26 20:05:38
Done.
| |
35 } else { | |
36 return "background-color: #FFF;\ncolor: #000;"; // Black on white. | |
37 } | |
38 } | |
39 | |
31 std::string ReplaceHtmlTemplateValues( | 40 std::string ReplaceHtmlTemplateValues( |
32 const std::string& title, | 41 const std::string& title, |
33 const std::string& content, | 42 const std::string& content, |
34 const std::string& loading_indicator_class, | 43 const std::string& loading_indicator_class, |
35 const std::string& original_url) { | 44 const std::string& original_url) { |
36 base::StringPiece html_template = | 45 base::StringPiece html_template = |
37 ResourceBundle::GetSharedInstance().GetRawDataResource( | 46 ResourceBundle::GetSharedInstance().GetRawDataResource( |
38 IDR_DOM_DISTILLER_VIEWER_HTML); | 47 IDR_DOM_DISTILLER_VIEWER_HTML); |
39 std::vector<std::string> substitutions; | 48 std::vector<std::string> substitutions; |
40 substitutions.push_back(title); // $1 | 49 substitutions.push_back(title); // $1 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 129 } |
121 | 130 |
122 const std::string GetErrorPageHtml() { | 131 const std::string GetErrorPageHtml() { |
123 std::string title = l10n_util::GetStringUTF8( | 132 std::string title = l10n_util::GetStringUTF8( |
124 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); | 133 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); |
125 std::string content = l10n_util::GetStringUTF8( | 134 std::string content = l10n_util::GetStringUTF8( |
126 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); | 135 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); |
127 return ReplaceHtmlTemplateValues(title, content, "hidden", ""); | 136 return ReplaceHtmlTemplateValues(title, content, "hidden", ""); |
128 } | 137 } |
129 | 138 |
130 const std::string GetCss() { | 139 const std::string GetCss(ReaderModePrefs* reader_mode_prefs) { |
131 return ResourceBundle::GetSharedInstance() | 140 std::vector<std::string> substitutions; |
132 .GetRawDataResource(IDR_DISTILLER_CSS) | 141 substitutions.push_back(GetBodyInsertionText(reader_mode_prefs)); |
133 .as_string(); | 142 base::StringPiece css_template = |
143 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
144 IDR_DISTILLER_CSS); | |
145 return ReplaceStringPlaceholders(css_template, substitutions, NULL); | |
134 } | 146 } |
135 | 147 |
136 const std::string GetJavaScript() { | 148 const std::string GetJavaScript() { |
137 return ResourceBundle::GetSharedInstance() | 149 return ResourceBundle::GetSharedInstance() |
138 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) | 150 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) |
139 .as_string(); | 151 .as_string(); |
140 } | 152 } |
141 | 153 |
142 scoped_ptr<ViewerHandle> CreateViewRequest( | 154 scoped_ptr<ViewerHandle> CreateViewRequest( |
143 DomDistillerServiceInterface* dom_distiller_service, | 155 DomDistillerServiceInterface* dom_distiller_service, |
(...skipping 27 matching lines...) Expand all Loading... | |
171 requested_url).Pass(); | 183 requested_url).Pass(); |
172 } | 184 } |
173 | 185 |
174 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. | 186 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. |
175 return scoped_ptr<ViewerHandle>(); | 187 return scoped_ptr<ViewerHandle>(); |
176 } | 188 } |
177 | 189 |
178 } // namespace viewer | 190 } // namespace viewer |
179 | 191 |
180 } // namespace dom_distiller | 192 } // namespace dom_distiller |
OLD | NEW |