viewer.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_DOM_DISTILLER_CORE_VIEWER_H_
  5. #define COMPONENTS_DOM_DISTILLER_CORE_VIEWER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/compiler_specific.h"
  9. #include "components/dom_distiller/core/distilled_page_prefs.h"
  10. #include "ui/gfx/geometry/size.h"
  11. #include "url/gurl.h"
  12. namespace dom_distiller {
  13. class DistilledArticleProto;
  14. class DistilledPageProto;
  15. class DomDistillerServiceInterface;
  16. class ViewerHandle;
  17. class ViewRequestDelegate;
  18. namespace viewer {
  19. // Assembles a platform-specific HTML template page based on the given
  20. // parameters. Information from the original article has not yet been inserted,
  21. // so the returned HTML should be safe.
  22. const std::string GetArticleTemplateHtml(mojom::Theme theme,
  23. mojom::FontFamily font_family,
  24. const std::string& csp_nonce);
  25. // Returns the JavaScript to place a full article's HTML on the page. The
  26. // returned HTML should be considered unsafe, so callers must ensure
  27. // rendering it does not compromise Chrome.
  28. const std::string GetUnsafeArticleContentJs(
  29. const DistilledArticleProto* article_proto);
  30. // Returns a JavaScript blob for updating a partial view request with additional
  31. // distilled content. Meant for use when viewing a slow or long multi-page
  32. // article. |is_last_page| indicates whether this is the last page of the
  33. // article.
  34. const std::string GetUnsafeIncrementalDistilledPageJs(
  35. const DistilledPageProto* page_proto,
  36. bool is_last_page);
  37. // Returns the JavaScript to set the title of the distilled article page.
  38. const std::string GetSetTitleJs(std::string title);
  39. // Return the JavaScript to set the text direction of the distiller page.
  40. const std::string GetSetTextDirectionJs(const std::string& direction);
  41. // Returns a JavaScript blob for updating a view request with error page
  42. // contents.
  43. const std::string GetErrorPageJs();
  44. // Returns a JavaScript blob for controlling the "in-progress" indicator when
  45. // viewing a partially-distilled page. |is_last_page| indicates whether this is
  46. // the last page of the article (i.e. loading indicator should be removed).
  47. const std::string GetToggleLoadingIndicatorJs(bool is_last_page);
  48. // Returns the CSS to use for a viewer.
  49. const std::string GetCss();
  50. // Returns the animated SVG loading image for a viewer.
  51. const std::string GetLoadingImage();
  52. // Returns the default JS to be used for a viewer.
  53. const std::string GetJavaScript();
  54. // Based on the given path, calls into the DomDistillerServiceInterface for
  55. // viewing distilled content based on the |path|.
  56. std::unique_ptr<ViewerHandle> CreateViewRequest(
  57. DomDistillerServiceInterface* dom_distiller_service,
  58. const GURL& url,
  59. ViewRequestDelegate* view_request_delegate,
  60. const gfx::Size& render_view_size);
  61. // Returns JavaScript corresponding to setting the font family.
  62. const std::string GetDistilledPageFontFamilyJs(mojom::FontFamily font);
  63. // Returns JavaScript corresponding to setting a specific theme.
  64. const std::string GetDistilledPageThemeJs(mojom::Theme theme);
  65. // Returns JavaScript corresponding to setting the font scaling.
  66. const std::string GetDistilledPageFontScalingJs(float scaling);
  67. } // namespace viewer
  68. } // namespace dom_distiller
  69. #endif // COMPONENTS_DOM_DISTILLER_CORE_VIEWER_H_