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

Unified Diff: components/dom_distiller/core/viewer.cc

Issue 1125343004: Add a "Simplify Page" option to the print preview dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update AUTHORS file to reflect the correct HP name used in the CLA Created 5 years, 7 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/viewer.cc
diff --git a/components/dom_distiller/core/viewer.cc b/components/dom_distiller/core/viewer.cc
index e19f3785f71b92c2243e8c07be8ea3b0429ace9f..8bc49587218a65d713983c8322f4ee42b1e9bfc2 100644
--- a/components/dom_distiller/core/viewer.cc
+++ b/components/dom_distiller/core/viewer.cc
@@ -143,6 +143,26 @@ std::string ReplaceHtmlTemplateValues(
return ReplaceStringPlaceholders(html_template, substitutions, NULL);
}
+std::string ReplacePrintPreviewHtmlTemplateValues(
+ const std::string& title,
+ const std::string& textDirection,
+ const std::string& content,
+ const DistilledPagePrefs::Theme theme,
+ const DistilledPagePrefs::FontFamily font_family) {
+ base::StringPiece html_template =
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DOM_DISTILLER_PRINT_PREVIEW_HTML);
+
+ std::vector<std::string> substitutions;
+ substitutions.push_back(title); // $1
+ substitutions.push_back(kPrintPreviewViewerCssPath); // $2
+ substitutions.push_back(GetThemeCssClass(theme) + " " +
+ GetFontCssClass(font_family)); // $3
+ substitutions.push_back(content); // $4
+ substitutions.push_back(textDirection); // $9
+ return ReplaceStringPlaceholders(html_template, substitutions, NULL);
+}
+
} // namespace
namespace viewer {
@@ -242,11 +262,48 @@ const std::string GetErrorPageHtml(
font_family);
}
+const std::string GetUnsafePrintPreviewHtml(
+ const DistilledArticleProto* article_proto,
+ const DistilledPagePrefs::Theme theme,
+ const DistilledPagePrefs::FontFamily font_family) {
+ DCHECK(article_proto);
+ std::string title;
+ std::string unsafe_article_html;
+ std::string text_direction = "";
+ if (article_proto->has_title() && article_proto->pages_size() > 0 &&
+ article_proto->pages(0).has_html()) {
+ title = net::EscapeForHTML(article_proto->title());
+ std::ostringstream unsafe_output_stream;
+ for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) {
+ unsafe_output_stream << article_proto->pages(page_num).html();
+ }
+ unsafe_article_html = unsafe_output_stream.str();
+ text_direction = article_proto->pages(0).text_direction();
+ }
+
+ EnsureNonEmptyTitle(&title);
+ EnsureNonEmptyContent(&unsafe_article_html);
+
+ std::string original_url;
+ if (article_proto->pages_size() > 0 && article_proto->pages(0).has_url()) {
+ original_url = article_proto->pages(0).url();
+ }
+
+ return ReplacePrintPreviewHtmlTemplateValues(
+ title, text_direction, unsafe_article_html,
+ theme, font_family);
+}
+
const std::string GetCss() {
return ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_DISTILLER_CSS).as_string();
}
+const std::string GetPrintPreviewCss() {
+ return ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DISTILLER_PRINT_PREVIEW_CSS).as_string();
+}
+
const std::string GetJavaScript() {
return ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS)

Powered by Google App Engine
This is Rietveld 408576698