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 <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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); | 152 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); |
153 base::StringValue no_val( | 153 base::StringValue no_val( |
154 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); | 154 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); |
155 base::StringValue yes_val( | 155 base::StringValue yes_val( |
156 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_YES)); | 156 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_YES)); |
157 | 157 |
158 std::string question; | 158 std::string question; |
159 std::string yes; | 159 std::string yes; |
160 std::string no; | 160 std::string no; |
161 | 161 |
162 base::JSONWriter::Write(&question_val, &question); | 162 base::JSONWriter::Write(question_val, &question); |
163 base::JSONWriter::Write(&yes_val, &yes); | 163 base::JSONWriter::Write(yes_val, &yes); |
164 base::JSONWriter::Write(&no_val, &no); | 164 base::JSONWriter::Write(no_val, &no); |
165 | 165 |
166 return "showFeedbackForm(" + question + ", " + yes + ", " + no + ");"; | 166 return "showFeedbackForm(" + question + ", " + yes + ", " + no + ");"; |
167 } | 167 } |
168 | 168 |
169 const std::string GetUnsafeIncrementalDistilledPageJs( | 169 const std::string GetUnsafeIncrementalDistilledPageJs( |
170 const DistilledPageProto* page_proto, | 170 const DistilledPageProto* page_proto, |
171 const bool is_last_page) { | 171 const bool is_last_page) { |
172 std::string output(page_proto->html()); | 172 std::string output(page_proto->html()); |
173 EnsureNonEmptyContent(&output); | 173 EnsureNonEmptyContent(&output); |
174 base::StringValue value(output); | 174 base::StringValue value(output); |
175 base::JSONWriter::Write(&value, &output); | 175 base::JSONWriter::Write(value, &output); |
176 std::string page_update("addToPage("); | 176 std::string page_update("addToPage("); |
177 page_update += output + ");"; | 177 page_update += output + ");"; |
178 return page_update + GetToggleLoadingIndicatorJs( | 178 return page_update + GetToggleLoadingIndicatorJs( |
179 is_last_page); | 179 is_last_page); |
180 | 180 |
181 } | 181 } |
182 | 182 |
183 const std::string GetErrorPageJs() { | 183 const std::string GetErrorPageJs() { |
184 base::StringValue value(l10n_util::GetStringUTF8( | 184 base::StringValue value(l10n_util::GetStringUTF8( |
185 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); | 185 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); |
186 std::string output; | 186 std::string output; |
187 base::JSONWriter::Write(&value, &output); | 187 base::JSONWriter::Write(value, &output); |
188 std::string page_update("addToPage("); | 188 std::string page_update("addToPage("); |
189 page_update += output + ");"; | 189 page_update += output + ");"; |
190 return page_update; | 190 return page_update; |
191 } | 191 } |
192 | 192 |
193 const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { | 193 const std::string GetToggleLoadingIndicatorJs(const bool is_last_page) { |
194 if (is_last_page) | 194 if (is_last_page) |
195 return "showLoadingIndicator(true);"; | 195 return "showLoadingIndicator(true);"; |
196 else | 196 else |
197 return "showLoadingIndicator(false);"; | 197 return "showLoadingIndicator(false);"; |
(...skipping 21 matching lines...) Expand all Loading... |
219 DCHECK(article_proto); | 219 DCHECK(article_proto); |
220 std::ostringstream unsafe_output_stream; | 220 std::ostringstream unsafe_output_stream; |
221 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_html()) { | 221 if (article_proto->pages_size() > 0 && article_proto->pages(0).has_html()) { |
222 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) { | 222 for (int page_num = 0; page_num < article_proto->pages_size(); ++page_num) { |
223 unsafe_output_stream << article_proto->pages(page_num).html(); | 223 unsafe_output_stream << article_proto->pages(page_num).html(); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 std::string output(unsafe_output_stream.str()); | 227 std::string output(unsafe_output_stream.str()); |
228 EnsureNonEmptyContent(&output); | 228 EnsureNonEmptyContent(&output); |
229 base::StringValue value(output); | 229 base::JSONWriter::Write(base::StringValue(output), &output); |
230 base::JSONWriter::Write(&value, &output); | |
231 std::string page_update("addToPage("); | 230 std::string page_update("addToPage("); |
232 page_update += output + ");"; | 231 page_update += output + ");"; |
233 return page_update + GetToggleLoadingIndicatorJs(true); | 232 return page_update + GetToggleLoadingIndicatorJs(true); |
234 } | 233 } |
235 | 234 |
236 const std::string GetErrorPageHtml( | 235 const std::string GetErrorPageHtml( |
237 const DistilledPagePrefs::Theme theme, | 236 const DistilledPagePrefs::Theme theme, |
238 const DistilledPagePrefs::FontFamily font_family) { | 237 const DistilledPagePrefs::FontFamily font_family) { |
239 std::string title = l10n_util::GetStringUTF8( | 238 std::string title = l10n_util::GetStringUTF8( |
240 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); | 239 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 294 } |
296 | 295 |
297 const std::string GetDistilledPageFontFamilyJs( | 296 const std::string GetDistilledPageFontFamilyJs( |
298 DistilledPagePrefs::FontFamily font_family) { | 297 DistilledPagePrefs::FontFamily font_family) { |
299 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; | 298 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; |
300 } | 299 } |
301 | 300 |
302 } // namespace viewer | 301 } // namespace viewer |
303 | 302 |
304 } // namespace dom_distiller | 303 } // namespace dom_distiller |
OLD | NEW |