dom_distiller_request_view_base.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015 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_DOM_DISTILLER_REQUEST_VIEW_BASE_H_
  5. #define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_REQUEST_VIEW_BASE_H_
  6. #include <memory>
  7. #include <sstream>
  8. #include <string>
  9. #include "base/memory/raw_ptr.h"
  10. #include "components/dom_distiller/core/distilled_page_prefs.h"
  11. #include "components/dom_distiller/core/dom_distiller_service.h"
  12. #include "components/dom_distiller/core/task_tracker.h"
  13. namespace dom_distiller {
  14. // Handles receiving data asynchronously for a specific entry, and passing
  15. // it along to the data callback for the data source. Lifetime matches that of
  16. // the current main frame's page in the Viewer instance.
  17. class DomDistillerRequestViewBase : public ViewRequestDelegate,
  18. public DistilledPagePrefs::Observer {
  19. public:
  20. explicit DomDistillerRequestViewBase(
  21. DistilledPagePrefs* distilled_page_prefs);
  22. ~DomDistillerRequestViewBase() override;
  23. // Flag this request as an error and send the error page template.
  24. void FlagAsErrorPage();
  25. // Get if this viewer is in an error state.
  26. bool IsErrorPage();
  27. // ViewRequestDelegate implementation:
  28. void OnArticleReady(const DistilledArticleProto* article_proto) override;
  29. void OnArticleUpdated(ArticleDistillationUpdate article_update) override;
  30. void TakeViewerHandle(std::unique_ptr<ViewerHandle> viewer_handle);
  31. protected:
  32. // DistilledPagePrefs::Observer implementation:
  33. void OnChangeTheme(mojom::Theme new_theme) override;
  34. void OnChangeFontFamily(mojom::FontFamily new_font_family) override;
  35. void OnChangeFontScaling(float scaling) override;
  36. // Sends JavaScript to the attached Viewer, buffering data if the viewer isn't
  37. // ready.
  38. virtual void SendJavaScript(const std::string& buffer) = 0;
  39. // Sends JavaScript common to normal and error pages.
  40. void SendCommonJavaScript();
  41. // The handle to the view request towards the DomDistillerService. It
  42. // needs to be kept around to ensure the distillation request finishes.
  43. std::unique_ptr<ViewerHandle> viewer_handle_;
  44. // Number of pages of the distilled article content that have been rendered by
  45. // the viewer.
  46. int page_count_;
  47. // Interface for accessing preferences for distilled pages.
  48. raw_ptr<DistilledPagePrefs> distilled_page_prefs_;
  49. // Flag to tell this observer that the web contents are in an error state.
  50. bool is_error_page_;
  51. };
  52. } // namespace dom_distiller
  53. #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_REQUEST_VIEW_BASE_H_