Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: components/dom_distiller/core/dom_distiller_request_view_base.h

Issue 1130703003: Show template before distiller finishes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ios-superclass
Patch Set: Fix flaky test Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/dom_distiller/core/distilled_page_prefs.h" 15 #include "components/dom_distiller/core/distilled_page_prefs.h"
16 #include "components/dom_distiller/core/dom_distiller_service.h" 16 #include "components/dom_distiller/core/dom_distiller_service.h"
17 #include "components/dom_distiller/core/task_tracker.h" 17 #include "components/dom_distiller/core/task_tracker.h"
18 #include "components/dom_distiller/core/viewer.h" 18 #include "components/dom_distiller/core/viewer.h"
19 #include "content/public/browser/url_data_source.h" 19 #include "content/public/browser/url_data_source.h"
20 #include "net/base/url_util.h" 20 #include "net/base/url_util.h"
21 21
22 namespace dom_distiller { 22 namespace dom_distiller {
23 23
24 // This interface is used to abstract the data callback from the distiller. The
25 // callbacks for different platforms have different numbers of parameters
26 // (namely iOS and Android) which makes this necessary.
27 class DistillerDataCallback {
28 public:
29 virtual ~DistillerDataCallback(){};
30 virtual void RunCallback(std::string& data) = 0;
31 };
32
33 // Handles receiving data asynchronously for a specific entry, and passing 24 // Handles receiving data asynchronously for a specific entry, and passing
34 // it along to the data callback for the data source. Lifetime matches that of 25 // it along to the data callback for the data source. Lifetime matches that of
35 // the current main frame's page in the Viewer instance. 26 // the current main frame's page in the Viewer instance.
36 class DomDistillerRequestViewBase 27 class DomDistillerRequestViewBase : public ViewRequestDelegate,
37 : public ViewRequestDelegate, 28 public DistilledPagePrefs::Observer {
38 public DistilledPagePrefs::Observer {
39 public: 29 public:
40 explicit DomDistillerRequestViewBase( 30 explicit DomDistillerRequestViewBase(
41 scoped_ptr<DistillerDataCallback> callback,
42 DistilledPagePrefs* distilled_page_prefs); 31 DistilledPagePrefs* distilled_page_prefs);
43 ~DomDistillerRequestViewBase() override; 32 ~DomDistillerRequestViewBase() override;
44 33
45 // Flag this request as an error and send the error page template. 34 // Flag this request as an error and send the error page template.
46 void FlagAsErrorPage(); 35 void FlagAsErrorPage();
47 // Get if this viewer is in an error state. 36 // Get if this viewer is in an error state.
48 bool IsErrorPage(); 37 bool IsErrorPage();
49 38
50 // ViewRequestDelegate implementation: 39 // ViewRequestDelegate implementation:
51 void OnArticleReady(const DistilledArticleProto* article_proto) override; 40 void OnArticleReady(const DistilledArticleProto* article_proto) override;
52 41
53 void OnArticleUpdated(ArticleDistillationUpdate article_update) override; 42 void OnArticleUpdated(ArticleDistillationUpdate article_update) override;
54 43
55 void TakeViewerHandle(scoped_ptr<ViewerHandle> viewer_handle); 44 void TakeViewerHandle(scoped_ptr<ViewerHandle> viewer_handle);
56 45
57 protected: 46 protected:
58 // DistilledPagePrefs::Observer implementation: 47 // DistilledPagePrefs::Observer implementation:
59 void OnChangeFontFamily( 48 void OnChangeFontFamily(
60 DistilledPagePrefs::FontFamily new_font_family) override; 49 DistilledPagePrefs::FontFamily new_font_family) override;
61 void OnChangeTheme(DistilledPagePrefs::Theme new_theme) override; 50 void OnChangeTheme(DistilledPagePrefs::Theme new_theme) override;
62 51
63 // Sends JavaScript to the attached Viewer, buffering data if the viewer isn't 52 // Sends JavaScript to the attached Viewer, buffering data if the viewer isn't
64 // ready. 53 // ready.
65 virtual void SendJavaScript(const std::string& buffer) = 0; 54 virtual void SendJavaScript(const std::string& buffer) = 0;
66 55
67 // The handle to the view request towards the DomDistillerService. It 56 // The handle to the view request towards the DomDistillerService. It
68 // needs to be kept around to ensure the distillation request finishes. 57 // needs to be kept around to ensure the distillation request finishes.
69 scoped_ptr<ViewerHandle> viewer_handle_; 58 scoped_ptr<ViewerHandle> viewer_handle_;
70 59
71 // Holds the callback to where the data retrieved is sent back.
72 scoped_ptr<DistillerDataCallback> callback_;
73
74 // Number of pages of the distilled article content that have been rendered by 60 // Number of pages of the distilled article content that have been rendered by
75 // the viewer. 61 // the viewer.
76 int page_count_; 62 int page_count_;
77 63
78 // Interface for accessing preferences for distilled pages. 64 // Interface for accessing preferences for distilled pages.
79 DistilledPagePrefs* distilled_page_prefs_; 65 DistilledPagePrefs* distilled_page_prefs_;
80 66
81 // Flag to tell this observer that the web contents are in an error state. 67 // Flag to tell this observer that the web contents are in an error state.
82 bool is_error_page_; 68 bool is_error_page_;
83 }; 69 };
84 70
85 } // namespace dom_distiller 71 } // namespace dom_distiller
86 72
87 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_REQUEST_VIEW_BASE_H_ 73 #endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_REQUEST_VIEW_BASE_H_
OLDNEW
« no previous file with comments | « components/dom_distiller/core/BUILD.gn ('k') | components/dom_distiller/core/dom_distiller_request_view_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698