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

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

Issue 563923002: display error message for empty distilled content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move test to browsertest to bypass missing resources on ios/android Created 6 years, 3 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 57d547320558cdde5e4f44f212c234aa658fa6ee..5ed4cb4f4984cfebd10cca8b43aadb48c8eedfc0 100644
--- a/components/dom_distiller/core/viewer.cc
+++ b/components/dom_distiller/core/viewer.cc
@@ -89,6 +89,15 @@ const std::string GetFontCssClass(DistilledPagePrefs::FontFamily font_family) {
return kSansSerifCssClass;
}
+void EnsureNonEmptyTitleAndContent(std::string* title, std::string* content) {
+ if (title->empty())
+ *title = l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE);
+ if (content->empty()) {
+ *content = l10n_util::GetStringUTF8(
+ IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT);
+ }
+}
+
std::string ReplaceHtmlTemplateValues(
const std::string& title,
const std::string& content,
@@ -146,6 +155,7 @@ const std::string GetUnsafePartialArticleHtml(
std::ostringstream unsafe_output_stream;
unsafe_output_stream << page_proto->html();
std::string unsafe_article_html = unsafe_output_stream.str();
+ EnsureNonEmptyTitleAndContent(&title, &unsafe_article_html);
std::string original_url = page_proto->url();
return ReplaceHtmlTemplateValues(
title, unsafe_article_html, "visible", original_url, theme, font_family);
@@ -166,12 +176,10 @@ const std::string GetUnsafeArticleHtml(
unsafe_output_stream << article_proto->pages(page_num).html();
}
unsafe_article_html = unsafe_output_stream.str();
- } else {
- title = l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE);
- unsafe_article_html =
- l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT);
}
+ EnsureNonEmptyTitleAndContent(&title, &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();

Powered by Google App Engine
This is Rietveld 408576698