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

Side by Side Diff: components/dom_distiller/core/viewer.cc

Issue 667323002: Update protobuff and template to handle text direction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Text directionality fix Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « components/dom_distiller/core/proto/distilled_page.proto ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 *title = l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE); 95 *title = l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE);
96 UMA_HISTOGRAM_BOOLEAN("DomDistiller.PageHasDistilledData", !content->empty()); 96 UMA_HISTOGRAM_BOOLEAN("DomDistiller.PageHasDistilledData", !content->empty());
97 if (content->empty()) { 97 if (content->empty()) {
98 *content = l10n_util::GetStringUTF8( 98 *content = l10n_util::GetStringUTF8(
99 IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT); 99 IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT);
100 } 100 }
101 } 101 }
102 102
103 std::string ReplaceHtmlTemplateValues( 103 std::string ReplaceHtmlTemplateValues(
104 const std::string& title, 104 const std::string& title,
105 const std::string& textDirection,
105 const std::string& content, 106 const std::string& content,
106 const std::string& loading_indicator_class, 107 const std::string& loading_indicator_class,
107 const std::string& original_url, 108 const std::string& original_url,
108 const DistilledPagePrefs::Theme theme, 109 const DistilledPagePrefs::Theme theme,
109 const DistilledPagePrefs::FontFamily font_family) { 110 const DistilledPagePrefs::FontFamily font_family) {
110 base::StringPiece html_template = 111 base::StringPiece html_template =
111 ResourceBundle::GetSharedInstance().GetRawDataResource( 112 ResourceBundle::GetSharedInstance().GetRawDataResource(
112 IDR_DOM_DISTILLER_VIEWER_HTML); 113 IDR_DOM_DISTILLER_VIEWER_HTML);
113 std::vector<std::string> substitutions; 114 std::vector<std::string> substitutions;
114 substitutions.push_back(title); // $1 115 substitutions.push_back(title); // $1
115 substitutions.push_back(kViewerCssPath); // $2 116 substitutions.push_back(kViewerCssPath); // $2
116 substitutions.push_back(kViewerJsPath); // $3 117 substitutions.push_back(kViewerJsPath); // $3
117 substitutions.push_back(GetThemeCssClass(theme) + " " + 118 substitutions.push_back(GetThemeCssClass(theme) + " " +
118 GetFontCssClass(font_family)); // $4 119 GetFontCssClass(font_family)); // $4
119 substitutions.push_back(content); // $5 120 substitutions.push_back(content); // $5
120 substitutions.push_back(loading_indicator_class); // $6 121 substitutions.push_back(loading_indicator_class); // $6
121 substitutions.push_back(original_url); // $7 122 substitutions.push_back(original_url); // $7
122 substitutions.push_back( 123 substitutions.push_back(
123 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $8 124 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $8
125 substitutions.push_back(textDirection); // $9
124 return ReplaceStringPlaceholders(html_template, substitutions, NULL); 126 return ReplaceStringPlaceholders(html_template, substitutions, NULL);
125 } 127 }
126 128
127 } // namespace 129 } // namespace
128 130
129 namespace viewer { 131 namespace viewer {
130 132
131 const std::string GetUnsafeIncrementalDistilledPageJs( 133 const std::string GetUnsafeIncrementalDistilledPageJs(
132 const DistilledPageProto* page_proto, 134 const DistilledPageProto* page_proto,
133 const bool is_last_page) { 135 const bool is_last_page) {
(...skipping 19 matching lines...) Expand all
153 const DistilledPagePrefs::Theme theme, 155 const DistilledPagePrefs::Theme theme,
154 const DistilledPagePrefs::FontFamily font_family) { 156 const DistilledPagePrefs::FontFamily font_family) {
155 DCHECK(page_proto); 157 DCHECK(page_proto);
156 std::string title = net::EscapeForHTML(page_proto->title()); 158 std::string title = net::EscapeForHTML(page_proto->title());
157 std::ostringstream unsafe_output_stream; 159 std::ostringstream unsafe_output_stream;
158 unsafe_output_stream << page_proto->html(); 160 unsafe_output_stream << page_proto->html();
159 std::string unsafe_article_html = unsafe_output_stream.str(); 161 std::string unsafe_article_html = unsafe_output_stream.str();
160 EnsureNonEmptyTitleAndContent(&title, &unsafe_article_html); 162 EnsureNonEmptyTitleAndContent(&title, &unsafe_article_html);
161 std::string original_url = page_proto->url(); 163 std::string original_url = page_proto->url();
162 return ReplaceHtmlTemplateValues( 164 return ReplaceHtmlTemplateValues(
163 title, unsafe_article_html, "visible", original_url, theme, font_family); 165 title, page_proto->text_direction(), unsafe_article_html, "visible",
166 original_url, theme, font_family);
164 } 167 }
165 168
166 const std::string GetUnsafeArticleHtml( 169 const std::string GetUnsafeArticleHtml(
167 const DistilledArticleProto* article_proto, 170 const DistilledArticleProto* article_proto,
168 const DistilledPagePrefs::Theme theme, 171 const DistilledPagePrefs::Theme theme,
169 const DistilledPagePrefs::FontFamily font_family) { 172 const DistilledPagePrefs::FontFamily font_family) {
170 DCHECK(article_proto); 173 DCHECK(article_proto);
171 std::string title; 174 std::string title;
172 std::string unsafe_article_html; 175 std::string unsafe_article_html;
176 std::string text_direction = "";
173 if (article_proto->has_title() && article_proto->pages_size() > 0 && 177 if (article_proto->has_title() && article_proto->pages_size() > 0 &&
174 article_proto->pages(0).has_html()) { 178 article_proto->pages(0).has_html()) {
175 title = net::EscapeForHTML(article_proto->title()); 179 title = net::EscapeForHTML(article_proto->title());
176 std::ostringstream unsafe_output_stream; 180 std::ostringstream unsafe_output_stream;
177 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) { 181 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) {
178 unsafe_output_stream << article_proto->pages(page_num).html(); 182 unsafe_output_stream << article_proto->pages(page_num).html();
179 } 183 }
180 unsafe_article_html = unsafe_output_stream.str(); 184 unsafe_article_html = unsafe_output_stream.str();
185 text_direction = article_proto->pages(0).text_direction();
181 } 186 }
182 187
183 EnsureNonEmptyTitleAndContent(&title, &unsafe_article_html); 188 EnsureNonEmptyTitleAndContent(&title, &unsafe_article_html);
184 189
185 std::string original_url; 190 std::string original_url;
186 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_url()) { 191 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_url()) {
187 original_url = article_proto->pages(0).url(); 192 original_url = article_proto->pages(0).url();
188 } 193 }
189 194
190 return ReplaceHtmlTemplateValues( 195 return ReplaceHtmlTemplateValues(
191 title, unsafe_article_html, "hidden", original_url, theme, font_family); 196 title, text_direction, unsafe_article_html, "hidden", original_url,
197 theme, font_family);
192 } 198 }
193 199
194 const std::string GetErrorPageHtml( 200 const std::string GetErrorPageHtml(
195 const DistilledPagePrefs::Theme theme, 201 const DistilledPagePrefs::Theme theme,
196 const DistilledPagePrefs::FontFamily font_family) { 202 const DistilledPagePrefs::FontFamily font_family) {
197 std::string title = l10n_util::GetStringUTF8( 203 std::string title = l10n_util::GetStringUTF8(
198 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); 204 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE);
199 std::string content = l10n_util::GetStringUTF8( 205 std::string content = l10n_util::GetStringUTF8(
200 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT); 206 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT);
201 return ReplaceHtmlTemplateValues( 207 return ReplaceHtmlTemplateValues(
202 title, content, "hidden", "", theme, font_family); 208 title, "", content, "hidden", "", theme, font_family);
203 } 209 }
204 210
205 const std::string GetCss() { 211 const std::string GetCss() {
206 return ResourceBundle::GetSharedInstance().GetRawDataResource( 212 return ResourceBundle::GetSharedInstance().GetRawDataResource(
207 IDR_DISTILLER_CSS).as_string(); 213 IDR_DISTILLER_CSS).as_string();
208 } 214 }
209 215
210 const std::string GetJavaScript() { 216 const std::string GetJavaScript() {
211 return ResourceBundle::GetSharedInstance() 217 return ResourceBundle::GetSharedInstance()
212 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) 218 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 261 }
256 262
257 const std::string GetDistilledPageFontFamilyJs( 263 const std::string GetDistilledPageFontFamilyJs(
258 DistilledPagePrefs::FontFamily font_family) { 264 DistilledPagePrefs::FontFamily font_family) {
259 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; 265 return "useFontFamily('" + GetJsFontFamily(font_family) + "');";
260 } 266 }
261 267
262 } // namespace viewer 268 } // namespace viewer
263 269
264 } // namespace dom_distiller 270 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/proto/distilled_page.proto ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698