Index: components/dom_distiller/core/viewer.cc |
diff --git a/components/dom_distiller/core/viewer.cc b/components/dom_distiller/core/viewer.cc |
index 6ae11a91ca0e9be0eb048e7c87126a9e47a7c607..6ae039e3df88243c0481d587a1bc94fcd40fac63 100644 |
--- a/components/dom_distiller/core/viewer.cc |
+++ b/components/dom_distiller/core/viewer.cc |
@@ -90,9 +90,12 @@ const std::string GetFontCssClass(DistilledPagePrefs::FontFamily font_family) { |
return kSansSerifCssClass; |
} |
-void EnsureNonEmptyTitleAndContent(std::string* title, std::string* content) { |
+void EnsureNonEmptyTitle(std::string* title) { |
if (title->empty()) |
*title = l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE); |
+} |
+ |
+void EnsureNonEmptyContent(std::string* content) { |
UMA_HISTOGRAM_BOOLEAN("DomDistiller.PageHasDistilledData", !content->empty()); |
if (content->empty()) { |
*content = l10n_util::GetStringUTF8( |
@@ -103,11 +106,11 @@ void EnsureNonEmptyTitleAndContent(std::string* title, std::string* content) { |
std::string ReplaceHtmlTemplateValues( |
const std::string& title, |
const std::string& textDirection, |
- const std::string& content, |
const std::string& loading_indicator_class, |
const std::string& original_url, |
const DistilledPagePrefs::Theme theme, |
- const DistilledPagePrefs::FontFamily font_family) { |
+ const DistilledPagePrefs::FontFamily font_family, |
+ const std::string& htmlContent) { |
base::StringPiece html_template = |
ResourceBundle::GetSharedInstance().GetRawDataResource( |
IDR_DOM_DISTILLER_VIEWER_HTML); |
@@ -130,12 +133,12 @@ std::string ReplaceHtmlTemplateValues( |
substitutions.push_back(GetThemeCssClass(theme) + " " + |
GetFontCssClass(font_family)); // $4 |
- substitutions.push_back(content); // $5 |
- substitutions.push_back(loading_indicator_class); // $6 |
- substitutions.push_back(original_url); // $7 |
+ substitutions.push_back(loading_indicator_class); // $5 |
+ substitutions.push_back(original_url); // $6 |
substitutions.push_back( |
- l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $8 |
- substitutions.push_back(textDirection); // $9 |
+ l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $7 |
+ substitutions.push_back(textDirection); // $8 |
+ substitutions.push_back(htmlContent); // $9 |
return ReplaceStringPlaceholders(html_template, substitutions, NULL); |
} |
@@ -149,6 +152,7 @@ const std::string GetUnsafeIncrementalDistilledPageJs( |
std::string output; |
base::StringValue value(page_proto->html()); |
base::JSONWriter::Write(&value, &output); |
+ EnsureNonEmptyContent(&output); |
std::string page_update("addToPage("); |
page_update += output + ");"; |
return page_update + GetToggleLoadingIndicatorJs( |
@@ -156,6 +160,16 @@ const std::string GetUnsafeIncrementalDistilledPageJs( |
} |
+const std::string GetErrorPageJs() { |
+ base::StringValue value(l10n_util::GetStringUTF8( |
+ IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); |
+ std::string output; |
+ base::JSONWriter::Write(&value, &output); |
+ std::string page_update("addToPage("); |
+ page_update += output + ");"; |
+ return page_update; |
+} |
+ |
const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { |
if (is_last_page) |
return "showLoadingIndicator(true);"; |
@@ -163,20 +177,51 @@ const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { |
return "showLoadingIndicator(false);"; |
} |
-const std::string GetUnsafePartialArticleHtml( |
+const std::string GetUnsafeArticleTemplateHtml( |
const DistilledPageProto* page_proto, |
const DistilledPagePrefs::Theme theme, |
const DistilledPagePrefs::FontFamily font_family) { |
DCHECK(page_proto); |
+ |
std::string title = net::EscapeForHTML(page_proto->title()); |
- 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); |
+ |
+ EnsureNonEmptyTitle(&title); |
+ |
+ std::string text_direction = page_proto->text_direction(); |
std::string original_url = page_proto->url(); |
- return ReplaceHtmlTemplateValues( |
- title, page_proto->text_direction(), unsafe_article_html, "visible", |
- original_url, theme, font_family); |
+ |
+ return ReplaceHtmlTemplateValues(title, text_direction, "hidden", |
+ original_url, theme, font_family, ""); |
+} |
+ |
+const std::string GetUnsafeArticleContentJs( |
+ const DistilledArticleProto* article_proto) { |
+ DCHECK(article_proto); |
+ if (article_proto->pages_size() == 0 || !article_proto->pages(0).has_html()) { |
+ return ""; |
+ } |
+ |
+ 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(); |
+ } |
+ |
+ std::string output; |
+ base::StringValue value(unsafe_output_stream.str()); |
+ base::JSONWriter::Write(&value, &output); |
+ EnsureNonEmptyContent(&output); |
+ std::string page_update("addToPage("); |
+ page_update += output + ");"; |
+ return page_update + GetToggleLoadingIndicatorJs(true); |
+} |
+ |
+const std::string GetErrorPageHtml( |
+ const DistilledPagePrefs::Theme theme, |
+ const DistilledPagePrefs::FontFamily font_family) { |
+ std::string title = l10n_util::GetStringUTF8( |
+ IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); |
+ return ReplaceHtmlTemplateValues(title, "auto", "hidden", "", theme, |
+ font_family, ""); |
} |
const std::string GetUnsafeArticleHtml( |
@@ -198,7 +243,8 @@ const std::string GetUnsafeArticleHtml( |
text_direction = article_proto->pages(0).text_direction(); |
} |
- EnsureNonEmptyTitleAndContent(&title, &unsafe_article_html); |
+ EnsureNonEmptyTitle(&title); |
+ EnsureNonEmptyContent(&unsafe_article_html); |
std::string original_url; |
if (article_proto->pages_size() > 0 && article_proto->pages(0).has_url()) { |
@@ -206,19 +252,8 @@ const std::string GetUnsafeArticleHtml( |
} |
return ReplaceHtmlTemplateValues( |
- title, text_direction, unsafe_article_html, "hidden", original_url, |
- theme, font_family); |
-} |
- |
-const std::string GetErrorPageHtml( |
- const DistilledPagePrefs::Theme theme, |
- const DistilledPagePrefs::FontFamily font_family) { |
- std::string title = l10n_util::GetStringUTF8( |
- IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); |
- std::string content = l10n_util::GetStringUTF8( |
- IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); |
- return ReplaceHtmlTemplateValues( |
- title, "", content, "hidden", "", theme, font_family); |
+ title, text_direction, "hidden", original_url, theme, font_family, |
+ unsafe_article_html); |
} |
const std::string GetCss() { |