| Index: components/dom_distiller/core/viewer.cc
|
| diff --git a/components/dom_distiller/core/viewer.cc b/components/dom_distiller/core/viewer.cc
|
| index 00e05ca447e2a8665bdffd1376ef9a5a590d91c5..4e74d2b4d789b5e223c468005b1ac98ec2fb1eb8 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,7 +106,6 @@ 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,
|
| @@ -117,12 +119,11 @@ std::string ReplaceHtmlTemplateValues(
|
| substitutions.push_back(kViewerJsPath); // $3
|
| 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
|
| return ReplaceStringPlaceholders(html_template, substitutions, NULL);
|
| }
|
|
|
| @@ -136,6 +137,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(
|
| @@ -143,6 +145,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);";
|
| @@ -150,51 +162,42 @@ 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 GetUnsafeArticleHtml(
|
| - const DistilledArticleProto* article_proto,
|
| - const DistilledPagePrefs::Theme theme,
|
| - const DistilledPagePrefs::FontFamily font_family) {
|
| +const std::string GetUnsafeArticleContentJs(
|
| + const DistilledArticleProto* article_proto) {
|
| 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();
|
| + if (article_proto->pages_size() == 0 || !article_proto->pages(0).has_html()) {
|
| + return "";
|
| }
|
|
|
| - 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();
|
| + 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();
|
| }
|
|
|
| - return ReplaceHtmlTemplateValues(
|
| - title, text_direction, unsafe_article_html, "hidden", original_url,
|
| - theme, font_family);
|
| + 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(
|
| @@ -202,10 +205,8 @@ const std::string GetErrorPageHtml(
|
| 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);
|
| + return ReplaceHtmlTemplateValues(title, "auto", "hidden", "", theme,
|
| + font_family);
|
| }
|
|
|
| const std::string GetCss() {
|
|
|