| 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 <string> | 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "components/dom_distiller/core/distilled_page_prefs.h" | 16 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 17 #include "components/dom_distiller/core/dom_distiller_service.h" | 17 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 18 #include "components/dom_distiller/core/experiments.h" | 18 #include "components/dom_distiller/core/experiments.h" |
| 19 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 19 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| 20 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 20 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
| 21 #include "components/dom_distiller/core/task_tracker.h" | 21 #include "components/dom_distiller/core/task_tracker.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 260 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 261 IDR_DISTILLER_IOS_CSS).as_string(); | 261 IDR_DISTILLER_IOS_CSS).as_string(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 const std::string GetJavaScript() { | 264 const std::string GetJavaScript() { |
| 265 return ResourceBundle::GetSharedInstance() | 265 return ResourceBundle::GetSharedInstance() |
| 266 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) | 266 .GetRawDataResource(IDR_DOM_DISTILLER_VIEWER_JS) |
| 267 .as_string(); | 267 .as_string(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 scoped_ptr<ViewerHandle> CreateViewRequest( | 270 std::unique_ptr<ViewerHandle> CreateViewRequest( |
| 271 DomDistillerServiceInterface* dom_distiller_service, | 271 DomDistillerServiceInterface* dom_distiller_service, |
| 272 const std::string& path, | 272 const std::string& path, |
| 273 ViewRequestDelegate* view_request_delegate, | 273 ViewRequestDelegate* view_request_delegate, |
| 274 const gfx::Size& render_view_size) { | 274 const gfx::Size& render_view_size) { |
| 275 std::string entry_id = | 275 std::string entry_id = |
| 276 url_utils::GetValueForKeyInUrlPathQuery(path, kEntryIdKey); | 276 url_utils::GetValueForKeyInUrlPathQuery(path, kEntryIdKey); |
| 277 bool has_valid_entry_id = !entry_id.empty(); | 277 bool has_valid_entry_id = !entry_id.empty(); |
| 278 entry_id = base::ToUpperASCII(entry_id); | 278 entry_id = base::ToUpperASCII(entry_id); |
| 279 | 279 |
| 280 std::string requested_url_str = | 280 std::string requested_url_str = |
| 281 url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey); | 281 url_utils::GetValueForKeyInUrlPathQuery(path, kUrlKey); |
| 282 GURL requested_url(requested_url_str); | 282 GURL requested_url(requested_url_str); |
| 283 bool has_valid_url = url_utils::IsUrlDistillable(requested_url); | 283 bool has_valid_url = url_utils::IsUrlDistillable(requested_url); |
| 284 | 284 |
| 285 if (has_valid_entry_id && has_valid_url) { | 285 if (has_valid_entry_id && has_valid_url) { |
| 286 // It is invalid to specify a query param for both |kEntryIdKey| and | 286 // It is invalid to specify a query param for both |kEntryIdKey| and |
| 287 // |kUrlKey|. | 287 // |kUrlKey|. |
| 288 return scoped_ptr<ViewerHandle>(); | 288 return std::unique_ptr<ViewerHandle>(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 if (has_valid_entry_id) { | 291 if (has_valid_entry_id) { |
| 292 return dom_distiller_service->ViewEntry( | 292 return dom_distiller_service->ViewEntry( |
| 293 view_request_delegate, | 293 view_request_delegate, |
| 294 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), | 294 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), |
| 295 entry_id); | 295 entry_id); |
| 296 } else if (has_valid_url) { | 296 } else if (has_valid_url) { |
| 297 return dom_distiller_service->ViewUrl( | 297 return dom_distiller_service->ViewUrl( |
| 298 view_request_delegate, | 298 view_request_delegate, |
| 299 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), | 299 dom_distiller_service->CreateDefaultDistillerPage(render_view_size), |
| 300 requested_url); | 300 requested_url); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. | 303 // It is invalid to not specify a query param for |kEntryIdKey| or |kUrlKey|. |
| 304 return scoped_ptr<ViewerHandle>(); | 304 return std::unique_ptr<ViewerHandle>(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 const std::string GetDistilledPageThemeJs(DistilledPagePrefs::Theme theme) { | 307 const std::string GetDistilledPageThemeJs(DistilledPagePrefs::Theme theme) { |
| 308 return "useTheme('" + GetJsTheme(theme) + "');"; | 308 return "useTheme('" + GetJsTheme(theme) + "');"; |
| 309 } | 309 } |
| 310 | 310 |
| 311 const std::string GetDistilledPageFontFamilyJs( | 311 const std::string GetDistilledPageFontFamilyJs( |
| 312 DistilledPagePrefs::FontFamily font_family) { | 312 DistilledPagePrefs::FontFamily font_family) { |
| 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 |