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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 base::StringPiece html_template = | 110 base::StringPiece html_template = |
111 ResourceBundle::GetSharedInstance().GetRawDataResource( | 111 ResourceBundle::GetSharedInstance().GetRawDataResource( |
112 IDR_DOM_DISTILLER_VIEWER_HTML); | 112 IDR_DOM_DISTILLER_VIEWER_HTML); |
113 std::vector<std::string> substitutions; | 113 std::vector<std::string> substitutions; |
114 | 114 |
115 std::ostringstream css; | 115 std::ostringstream css; |
116 std::ostringstream script; | 116 std::ostringstream script; |
117 #if defined(OS_IOS) | 117 #if defined(OS_IOS) |
118 // On iOS the content is inlined as there is no API to detect those requests | 118 // On iOS the content is inlined as there is no API to detect those requests |
119 // and return the local data once a page is loaded. | 119 // and return the local data once a page is loaded. |
120 css << "<style>" << viewer::GetCss() << "</style>"; | 120 css << "<style>" << viewer::GetCss() << viewer::GetIOSCss() << "</style>"; |
121 script << "<script>\n" << viewer::GetJavaScript() << "\n</script>"; | 121 script << "<script>\n" << viewer::GetJavaScript() << "\n</script>"; |
122 #else | 122 #else |
123 css << "<link rel=\"stylesheet\" href=\"/" << kViewerCssPath << "\">"; | 123 css << "<link rel=\"stylesheet\" href=\"/" << kViewerCssPath << "\">"; |
124 script << "<script src=\"" << kViewerJsPath << "\"></script>"; | 124 script << "<script src=\"" << kViewerJsPath << "\"></script>"; |
125 #endif // defined(OS_IOS) | 125 #endif // defined(OS_IOS) |
126 | 126 |
127 substitutions.push_back( | 127 substitutions.push_back( |
128 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_LOADING_TITLE)); // $1 | 128 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_LOADING_TITLE)); // $1 |
129 | 129 |
130 substitutions.push_back(css.str()); // $2 | 130 substitutions.push_back(css.str()); // $2 |
131 substitutions.push_back(GetThemeCssClass(theme) + " " + | 131 substitutions.push_back(GetThemeCssClass(theme) + " " + |
132 GetFontCssClass(font_family)); // $3 | 132 GetFontCssClass(font_family)); // $3 |
133 | 133 |
134 substitutions.push_back( | 134 substitutions.push_back( |
135 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE)); // $4 | 135 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE)); // $4 |
136 substitutions.push_back( | 136 substitutions.push_back( |
137 l10n_util::GetStringUTF8( | 137 l10n_util::GetStringUTF8( |
138 IDS_DOM_DISTILLER_JAVASCRIPT_DISABLED_CONTENT)); // $5 | 138 IDS_DOM_DISTILLER_JAVASCRIPT_DISABLED_CONTENT)); // $5 |
139 | 139 |
140 substitutions.push_back(original_url); // $6 | 140 substitutions.push_back(original_url); // $6 |
141 substitutions.push_back( | 141 substitutions.push_back( |
142 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_VIEW_ORIGINAL)); // $7 | 142 l10n_util::GetStringUTF8( |
| 143 IDS_DOM_DISTILLER_VIEWER_CLOSE_READER_VIEW)); // $7 |
143 | 144 |
144 substitutions.push_back(script.str()); // $8 | 145 substitutions.push_back(script.str()); // $8 |
145 | 146 |
146 return ReplaceStringPlaceholders(html_template, substitutions, NULL); | 147 return ReplaceStringPlaceholders(html_template, substitutions, NULL); |
147 } | 148 } |
148 | 149 |
149 } // namespace | 150 } // namespace |
150 | 151 |
151 namespace viewer { | 152 namespace viewer { |
152 | 153 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 std::string page_update("addToPage("); | 239 std::string page_update("addToPage("); |
239 page_update += output + ");"; | 240 page_update += output + ");"; |
240 return page_update + GetToggleLoadingIndicatorJs(true); | 241 return page_update + GetToggleLoadingIndicatorJs(true); |
241 } | 242 } |
242 | 243 |
243 const std::string GetCss() { | 244 const std::string GetCss() { |
244 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 245 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
245 IDR_DISTILLER_CSS).as_string(); | 246 IDR_DISTILLER_CSS).as_string(); |
246 } | 247 } |
247 | 248 |
| 249 const std::string GetIOSCss() { |
| 250 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 251 IDR_DISTILLER_IOS_CSS).as_string(); |
| 252 } |
| 253 |
248 const std::string GetJavaScript() { | 254 const std::string GetJavaScript() { |
249 return ResourceBundle::GetSharedInstance() | 255 return ResourceBundle::GetSharedInstance() |
250 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) | 256 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) |
251 .as_string(); | 257 .as_string(); |
252 } | 258 } |
253 | 259 |
254 scoped_ptr<ViewerHandle> CreateViewRequest( | 260 scoped_ptr<ViewerHandle> CreateViewRequest( |
255 DomDistillerServiceInterface* dom_distiller_service, | 261 DomDistillerServiceInterface* dom_distiller_service, |
256 const std::string& path, | 262 const std::string& path, |
257 ViewRequestDelegate* view_request_delegate, | 263 ViewRequestDelegate* view_request_delegate, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 299 } |
294 | 300 |
295 const std::string GetDistilledPageFontFamilyJs( | 301 const std::string GetDistilledPageFontFamilyJs( |
296 DistilledPagePrefs::FontFamily font_family) { | 302 DistilledPagePrefs::FontFamily font_family) { |
297 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; | 303 return "useFontFamily('" + GetJsFontFamily(font_family) + "');"; |
298 } | 304 } |
299 | 305 |
300 } // namespace viewer | 306 } // namespace viewer |
301 | 307 |
302 } // namespace dom_distiller | 308 } // namespace dom_distiller |
OLD | NEW |