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