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" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 GetFontCssClass(font_family)); // $4 | 136 GetFontCssClass(font_family)); // $4 |
137 substitutions.push_back(loading_indicator_class); // $5 | 137 substitutions.push_back(loading_indicator_class); // $5 |
138 substitutions.push_back(original_url); // $6 | 138 substitutions.push_back(original_url); // $6 |
139 substitutions.push_back( | 139 substitutions.push_back( |
140 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $7 | 140 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $7 |
141 substitutions.push_back(textDirection); // $8 | 141 substitutions.push_back(textDirection); // $8 |
142 | 142 |
143 return ReplaceStringPlaceholders(html_template, substitutions, NULL); | 143 return ReplaceStringPlaceholders(html_template, substitutions, NULL); |
144 } | 144 } |
145 | 145 |
| 146 std::string ReplacePrintPreviewHtmlTemplateValues( |
| 147 const std::string& title, |
| 148 const std::string& textDirection, |
| 149 const std::string& content, |
| 150 const DistilledPagePrefs::Theme theme, |
| 151 const DistilledPagePrefs::FontFamily font_family) { |
| 152 base::StringPiece html_template = |
| 153 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 154 IDR_DOM_DISTILLER_PRINT_PREVIEW_HTML); |
| 155 |
| 156 std::vector<std::string> substitutions; |
| 157 substitutions.push_back(title); // $1 |
| 158 substitutions.push_back(kPrintPreviewViewerCssPath); // $2 |
| 159 substitutions.push_back(GetThemeCssClass(theme) + " " + |
| 160 GetFontCssClass(font_family)); // $3 |
| 161 substitutions.push_back(content); // $4 |
| 162 substitutions.push_back(textDirection); // $9 |
| 163 return ReplaceStringPlaceholders(html_template, substitutions, NULL); |
| 164 } |
| 165 |
146 } // namespace | 166 } // namespace |
147 | 167 |
148 namespace viewer { | 168 namespace viewer { |
149 | 169 |
150 const std::string GetShowFeedbackFormJs() { | 170 const std::string GetShowFeedbackFormJs() { |
151 base::StringValue question_val( | 171 base::StringValue question_val( |
152 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); | 172 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); |
153 base::StringValue no_val( | 173 base::StringValue no_val( |
154 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); | 174 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); |
155 base::StringValue yes_val( | 175 base::StringValue yes_val( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 255 |
236 const std::string GetErrorPageHtml( | 256 const std::string GetErrorPageHtml( |
237 const DistilledPagePrefs::Theme theme, | 257 const DistilledPagePrefs::Theme theme, |
238 const DistilledPagePrefs::FontFamily font_family) { | 258 const DistilledPagePrefs::FontFamily font_family) { |
239 std::string title = l10n_util::GetStringUTF8( | 259 std::string title = l10n_util::GetStringUTF8( |
240 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); | 260 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); |
241 return ReplaceHtmlTemplateValues(title, "auto", "hidden", "", theme, | 261 return ReplaceHtmlTemplateValues(title, "auto", "hidden", "", theme, |
242 font_family); | 262 font_family); |
243 } | 263 } |
244 | 264 |
| 265 const std::string GetUnsafePrintPreviewHtml( |
| 266 const DistilledArticleProto* article_proto, |
| 267 const DistilledPagePrefs::Theme theme, |
| 268 const DistilledPagePrefs::FontFamily font_family) { |
| 269 DCHECK(article_proto); |
| 270 std::string title; |
| 271 std::string unsafe_article_html; |
| 272 std::string text_direction = ""; |
| 273 if (article_proto->has_title() && article_proto->pages_size() > 0 && |
| 274 article_proto->pages(0).has_html()) { |
| 275 title = net::EscapeForHTML(article_proto->title()); |
| 276 std::ostringstream unsafe_output_stream; |
| 277 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) { |
| 278 unsafe_output_stream << article_proto->pages(page_num).html(); |
| 279 } |
| 280 unsafe_article_html = unsafe_output_stream.str(); |
| 281 text_direction = article_proto->pages(0).text_direction(); |
| 282 } |
| 283 |
| 284 EnsureNonEmptyTitle(&title); |
| 285 EnsureNonEmptyContent(&unsafe_article_html); |
| 286 |
| 287 std::string original_url; |
| 288 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_url()) { |
| 289 original_url = article_proto->pages(0).url(); |
| 290 } |
| 291 |
| 292 return ReplacePrintPreviewHtmlTemplateValues( |
| 293 title, text_direction, unsafe_article_html, |
| 294 theme, font_family); |
| 295 } |
| 296 |
245 const std::string GetCss() { | 297 const std::string GetCss() { |
246 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 298 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
247 IDR_DISTILLER_CSS).as_string(); | 299 IDR_DISTILLER_CSS).as_string(); |
248 } | 300 } |
249 | 301 |
| 302 const std::string GetPrintPreviewCss() { |
| 303 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 304 IDR_DISTILLER_PRINT_PREVIEW_CSS).as_string(); |
| 305 } |
| 306 |
250 const std::string GetJavaScript() { | 307 const std::string GetJavaScript() { |
251 return ResourceBundle::GetSharedInstance() | 308 return ResourceBundle::GetSharedInstance() |
252 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) | 309 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) |
253 .as_string(); | 310 .as_string(); |
254 } | 311 } |
255 | 312 |
256 scoped_ptr<ViewerHandle> CreateViewRequest( | 313 scoped_ptr<ViewerHandle> CreateViewRequest( |
257 DomDistillerServiceInterface* dom_distiller_service, | 314 DomDistillerServiceInterface* dom_distiller_service, |
258 const std::string& path, | 315 const std::string& path, |
259 ViewRequestDelegate* view_request_delegate, | 316 ViewRequestDelegate* view_request_delegate, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 352 } |
296 | 353 |
297 const std::string GetDistilledPageFontFamilyJs( | 354 const std::string GetDistilledPageFontFamilyJs( |
298 DistilledPagePrefs::FontFamily font_family) { | 355 DistilledPagePrefs::FontFamily font_family) { |
299 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; | 356 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; |
300 } | 357 } |
301 | 358 |
302 } // namespace viewer | 359 } // namespace viewer |
303 | 360 |
304 } // namespace dom_distiller | 361 } // namespace dom_distiller |
OLD | NEW |