OLD | NEW |
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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 IDS_DOM_DISTILLER_VIEWER_CLOSE_READER_VIEW)); // $8 | 143 IDS_DOM_DISTILLER_VIEWER_CLOSE_READER_VIEW)); // $8 |
144 | 144 |
145 return base::ReplaceStringPlaceholders(html_template, substitutions, NULL); | 145 return base::ReplaceStringPlaceholders(html_template, substitutions, NULL); |
146 } | 146 } |
147 | 147 |
148 } // namespace | 148 } // namespace |
149 | 149 |
150 namespace viewer { | 150 namespace viewer { |
151 | 151 |
152 const std::string GetShowFeedbackFormJs() { | 152 const std::string GetShowFeedbackFormJs() { |
153 base::StringValue question_val( | 153 base::Value question_val( |
154 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); | 154 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); |
155 base::StringValue no_val( | 155 base::Value no_val( |
156 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); | 156 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); |
157 base::StringValue yes_val( | 157 base::Value yes_val( |
158 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_YES)); | 158 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_YES)); |
159 | 159 |
160 std::string question; | 160 std::string question; |
161 std::string yes; | 161 std::string yes; |
162 std::string no; | 162 std::string no; |
163 | 163 |
164 base::JSONWriter::Write(question_val, &question); | 164 base::JSONWriter::Write(question_val, &question); |
165 base::JSONWriter::Write(yes_val, &yes); | 165 base::JSONWriter::Write(yes_val, &yes); |
166 base::JSONWriter::Write(no_val, &no); | 166 base::JSONWriter::Write(no_val, &no); |
167 | 167 |
168 return "showFeedbackForm(" + question + ", " + yes + ", " + no + ");"; | 168 return "showFeedbackForm(" + question + ", " + yes + ", " + no + ");"; |
169 } | 169 } |
170 | 170 |
171 const std::string GetUnsafeIncrementalDistilledPageJs( | 171 const std::string GetUnsafeIncrementalDistilledPageJs( |
172 const DistilledPageProto* page_proto, | 172 const DistilledPageProto* page_proto, |
173 const bool is_last_page) { | 173 const bool is_last_page) { |
174 std::string output(page_proto->html()); | 174 std::string output(page_proto->html()); |
175 EnsureNonEmptyContent(&output); | 175 EnsureNonEmptyContent(&output); |
176 base::StringValue value(output); | 176 base::Value value(output); |
177 base::JSONWriter::Write(value, &output); | 177 base::JSONWriter::Write(value, &output); |
178 std::string page_update("addToPage("); | 178 std::string page_update("addToPage("); |
179 page_update += output + ");"; | 179 page_update += output + ");"; |
180 return page_update + GetToggleLoadingIndicatorJs( | 180 return page_update + GetToggleLoadingIndicatorJs( |
181 is_last_page); | 181 is_last_page); |
182 | 182 |
183 } | 183 } |
184 | 184 |
185 const std::string GetErrorPageJs() { | 185 const std::string GetErrorPageJs() { |
186 std::string title(l10n_util::GetStringUTF8( | 186 std::string title(l10n_util::GetStringUTF8( |
187 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE)); | 187 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE)); |
188 std::string page_update(GetSetTitleJs(title)); | 188 std::string page_update(GetSetTitleJs(title)); |
189 | 189 |
190 base::StringValue value(l10n_util::GetStringUTF8( | 190 base::Value value(l10n_util::GetStringUTF8( |
191 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); | 191 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); |
192 std::string output; | 192 std::string output; |
193 base::JSONWriter::Write(value, &output); | 193 base::JSONWriter::Write(value, &output); |
194 page_update += "addToPage(" + output + ");"; | 194 page_update += "addToPage(" + output + ");"; |
195 page_update += GetSetTextDirectionJs(std::string("auto")); | 195 page_update += GetSetTextDirectionJs(std::string("auto")); |
196 page_update += GetToggleLoadingIndicatorJs(true); | 196 page_update += GetToggleLoadingIndicatorJs(true); |
197 if (ShouldShowFeedbackForm()) { | 197 if (ShouldShowFeedbackForm()) { |
198 page_update += GetShowFeedbackFormJs(); | 198 page_update += GetShowFeedbackFormJs(); |
199 } | 199 } |
200 return page_update; | 200 return page_update; |
201 } | 201 } |
202 | 202 |
203 const std::string GetSetTitleJs(std::string title) { | 203 const std::string GetSetTitleJs(std::string title) { |
204 base::StringValue value(title); | 204 base::Value value(title); |
205 std::string output; | 205 std::string output; |
206 base::JSONWriter::Write(value, &output); | 206 base::JSONWriter::Write(value, &output); |
207 return "setTitle(" + output + ");"; | 207 return "setTitle(" + output + ");"; |
208 } | 208 } |
209 | 209 |
210 const std::string GetSetTextDirectionJs(const std::string& direction) { | 210 const std::string GetSetTextDirectionJs(const std::string& direction) { |
211 base::StringValue value(direction); | 211 base::Value value(direction); |
212 std::string output; | 212 std::string output; |
213 base::JSONWriter::Write(value, &output); | 213 base::JSONWriter::Write(value, &output); |
214 return "setTextDirection(" + output + ");"; | 214 return "setTextDirection(" + output + ");"; |
215 } | 215 } |
216 | 216 |
217 const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { | 217 const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { |
218 if (is_last_page) | 218 if (is_last_page) |
219 return "showLoadingIndicator(true);"; | 219 return "showLoadingIndicator(true);"; |
220 else | 220 else |
221 return "showLoadingIndicator(false);"; | 221 return "showLoadingIndicator(false);"; |
(...skipping 11 matching lines...) Expand all Loading... |
233 DCHECK(article_proto); | 233 DCHECK(article_proto); |
234 std::ostringstream unsafe_output_stream; | 234 std::ostringstream unsafe_output_stream; |
235 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_html()) { | 235 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_html()) { |
236 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) { | 236 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) { |
237 unsafe_output_stream << article_proto->pages(page_num).html(); | 237 unsafe_output_stream << article_proto->pages(page_num).html(); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 std::string output(unsafe_output_stream.str()); | 241 std::string output(unsafe_output_stream.str()); |
242 EnsureNonEmptyContent(&output); | 242 EnsureNonEmptyContent(&output); |
243 base::JSONWriter::Write(base::StringValue(output), &output); | 243 base::JSONWriter::Write(base::Value(output), &output); |
244 std::string page_update("addToPage("); | 244 std::string page_update("addToPage("); |
245 page_update += output + ");"; | 245 page_update += output + ");"; |
246 return page_update + GetToggleLoadingIndicatorJs(true); | 246 return page_update + GetToggleLoadingIndicatorJs(true); |
247 } | 247 } |
248 | 248 |
249 const std::string GetCss() { | 249 const std::string GetCss() { |
250 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 250 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
251 IDR_DISTILLER_CSS).as_string(); | 251 IDR_DISTILLER_CSS).as_string(); |
252 } | 252 } |
253 | 253 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; | 313 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; |
314 } | 314 } |
315 | 315 |
316 const std::string GetDistilledPageFontScalingJs(float scaling) { | 316 const std::string GetDistilledPageFontScalingJs(float scaling) { |
317 return "useFontScaling(" + base::DoubleToString(scaling) + ");"; | 317 return "useFontScaling(" + base::DoubleToString(scaling) + ");"; |
318 } | 318 } |
319 | 319 |
320 } // namespace viewer | 320 } // namespace viewer |
321 | 321 |
322 } // namespace dom_distiller | 322 } // namespace dom_distiller |
OLD | NEW |