| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 l10n_util::GetStringUTF8( | 142 l10n_util::GetStringUTF8( |
| 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() { | |
| 153 base::Value question_val( | |
| 154 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_QUESTION)); | |
| 155 base::Value no_val( | |
| 156 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_NO)); | |
| 157 base::Value yes_val( | |
| 158 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_QUALITY_ANSWER_YES)); | |
| 159 | |
| 160 std::string question; | |
| 161 std::string yes; | |
| 162 std::string no; | |
| 163 | |
| 164 base::JSONWriter::Write(question_val, &question); | |
| 165 base::JSONWriter::Write(yes_val, &yes); | |
| 166 base::JSONWriter::Write(no_val, &no); | |
| 167 | |
| 168 return "showFeedbackForm(" + question + ", " + yes + ", " + no + ");"; | |
| 169 } | |
| 170 | |
| 171 const std::string GetUnsafeIncrementalDistilledPageJs( | 152 const std::string GetUnsafeIncrementalDistilledPageJs( |
| 172 const DistilledPageProto* page_proto, | 153 const DistilledPageProto* page_proto, |
| 173 const bool is_last_page) { | 154 const bool is_last_page) { |
| 174 std::string output(page_proto->html()); | 155 std::string output(page_proto->html()); |
| 175 EnsureNonEmptyContent(&output); | 156 EnsureNonEmptyContent(&output); |
| 176 base::Value value(output); | 157 base::Value value(output); |
| 177 base::JSONWriter::Write(value, &output); | 158 base::JSONWriter::Write(value, &output); |
| 178 std::string page_update("addToPage("); | 159 std::string page_update("addToPage("); |
| 179 page_update += output + ");"; | 160 page_update += output + ");"; |
| 180 return page_update + GetToggleLoadingIndicatorJs( | 161 return page_update + GetToggleLoadingIndicatorJs( |
| 181 is_last_page); | 162 is_last_page); |
| 182 | 163 |
| 183 } | 164 } |
| 184 | 165 |
| 185 const std::string GetErrorPageJs() { | 166 const std::string GetErrorPageJs() { |
| 186 std::string title(l10n_util::GetStringUTF8( | 167 std::string title(l10n_util::GetStringUTF8( |
| 187 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE)); | 168 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_TITLE)); |
| 188 std::string page_update(GetSetTitleJs(title)); | 169 std::string page_update(GetSetTitleJs(title)); |
| 189 | 170 |
| 190 base::Value value(l10n_util::GetStringUTF8( | 171 base::Value value(l10n_util::GetStringUTF8( |
| 191 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); | 172 IDS_DOM_DISTILLER_VIEWER_FAILED_TO_FIND_ARTICLE_CONTENT)); |
| 192 std::string output; | 173 std::string output; |
| 193 base::JSONWriter::Write(value, &output); | 174 base::JSONWriter::Write(value, &output); |
| 194 page_update += "addToPage(" + output + ");"; | 175 page_update += "addToPage(" + output + ");"; |
| 195 page_update += GetSetTextDirectionJs(std::string("auto")); | 176 page_update += GetSetTextDirectionJs(std::string("auto")); |
| 196 page_update += GetToggleLoadingIndicatorJs(true); | 177 page_update += GetToggleLoadingIndicatorJs(true); |
| 197 if (ShouldShowFeedbackForm()) { | |
| 198 page_update += GetShowFeedbackFormJs(); | |
| 199 } | |
| 200 return page_update; | 178 return page_update; |
| 201 } | 179 } |
| 202 | 180 |
| 203 const std::string GetSetTitleJs(std::string title) { | 181 const std::string GetSetTitleJs(std::string title) { |
| 204 base::Value value(title); | 182 base::Value value(title); |
| 205 std::string output; | 183 std::string output; |
| 206 base::JSONWriter::Write(value, &output); | 184 base::JSONWriter::Write(value, &output); |
| 207 return "setTitle(" + output + ");"; | 185 return "setTitle(" + output + ");"; |
| 208 } | 186 } |
| 209 | 187 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; | 291 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; |
| 314 } | 292 } |
| 315 | 293 |
| 316 const std::string GetDistilledPageFontScalingJs(float scaling) { | 294 const std::string GetDistilledPageFontScalingJs(float scaling) { |
| 317 return "useFontScaling(" + base::DoubleToString(scaling) + ");"; | 295 return "useFontScaling(" + base::DoubleToString(scaling) + ");"; |
| 318 } | 296 } |
| 319 | 297 |
| 320 } // namespace viewer | 298 } // namespace viewer |
| 321 | 299 |
| 322 } // namespace dom_distiller | 300 } // namespace dom_distiller |
| OLD | NEW |