OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DISTILLER_PAGE_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "third_party/dom_distiller_js/dom_distiller.pb.h" | 14 #include "third_party/dom_distiller_js/dom_distiller.pb.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace dom_distiller { | 18 namespace dom_distiller { |
19 | 19 |
20 struct DistilledPageInfo { | |
21 struct MarkupArticle { | |
22 std::string published_time; | |
23 std::string modified_time; | |
24 std::string expiration_time; | |
25 std::string section; | |
26 std::vector<std::string> authors; | |
27 | |
28 MarkupArticle(); | |
29 ~MarkupArticle(); | |
30 }; | |
31 | |
32 struct MarkupImage { | |
33 std::string url; | |
34 std::string secure_url; | |
35 std::string type; | |
36 std::string caption; | |
37 int width; | |
38 int height; | |
39 | |
40 MarkupImage(); | |
41 ~MarkupImage(); | |
42 }; | |
43 | |
44 struct MarkupInfo { | |
45 std::string title; | |
46 std::string type; | |
47 std::string url; | |
48 std::string description; | |
49 std::string publisher; | |
50 std::string copyright; | |
51 std::string author; | |
52 MarkupArticle article; | |
53 std::vector<MarkupImage> images; | |
54 | |
55 MarkupInfo(); | |
56 ~MarkupInfo(); | |
57 }; | |
58 | |
59 std::string title; | |
60 std::string html; | |
61 std::string next_page_url; | |
62 std::string prev_page_url; | |
63 std::vector<std::string> image_urls; | |
64 MarkupInfo markup_info; | |
65 | |
66 DistilledPageInfo(); | |
67 ~DistilledPageInfo(); | |
68 | |
69 private: | |
70 DISALLOW_COPY_AND_ASSIGN(DistilledPageInfo); | |
71 }; | |
72 | |
73 class SourcePageHandle { | 20 class SourcePageHandle { |
74 public: | 21 public: |
75 virtual ~SourcePageHandle() {} | 22 virtual ~SourcePageHandle() {} |
76 }; | 23 }; |
77 | 24 |
78 // Injects JavaScript into a page, and uses it to extract and return long-form | 25 // Injects JavaScript into a page, and uses it to extract and return long-form |
79 // content. The class can be reused to load and distill multiple pages, | 26 // content. The class can be reused to load and distill multiple pages, |
80 // following the state transitions described along with the class's states. | 27 // following the state transitions described along with the class's states. |
81 // Constructing a DistillerPage should be cheap, as some of the instances can be | 28 // Constructing a DistillerPage should be cheap, as some of the instances can be |
82 // thrown away without ever being used. | 29 // thrown away without ever being used. |
83 class DistillerPage { | 30 class DistillerPage { |
84 public: | 31 public: |
85 typedef base::Callback<void(scoped_ptr<DistilledPageInfo> distilled_page, | 32 typedef base::Callback< |
86 bool distillation_successful)> | 33 void(scoped_ptr<proto::DomDistillerResult> distilled_page, |
87 DistillerPageCallback; | 34 bool distillation_successful)> DistillerPageCallback; |
88 | 35 |
89 DistillerPage(); | 36 DistillerPage(); |
90 virtual ~DistillerPage(); | 37 virtual ~DistillerPage(); |
91 | 38 |
92 // Loads a URL. |OnDistillationDone| is called when the load completes or | 39 // Loads a URL. |OnDistillationDone| is called when the load completes or |
93 // fails. May be called when the distiller is idle. Callers can assume that, | 40 // fails. May be called when the distiller is idle. Callers can assume that, |
94 // for a given |url| and |options|, any DistillerPage implementation will | 41 // for a given |url| and |options|, any DistillerPage implementation will |
95 // extract the same content. | 42 // extract the same content. |
96 void DistillPage(const GURL& url, | 43 void DistillPage(const GURL& url, |
97 const dom_distiller::proto::DomDistillerOptions options, | 44 const proto::DomDistillerOptions options, |
98 const DistillerPageCallback& callback); | 45 const DistillerPageCallback& callback); |
99 | 46 |
100 // Called when the JavaScript execution completes. |page_url| is the url of | 47 // Called when the JavaScript execution completes. |page_url| is the url of |
101 // the distilled page. |value| contains data returned by the script. | 48 // the distilled page. |value| contains data returned by the script. |
102 virtual void OnDistillationDone(const GURL& page_url, | 49 virtual void OnDistillationDone(const GURL& page_url, |
103 const base::Value* value); | 50 const base::Value* value); |
104 | 51 |
105 protected: | 52 protected: |
106 // Called by |DistillPage| to carry out platform-specific instructions to load | 53 // Called by |DistillPage| to carry out platform-specific instructions to load |
107 // and distill the |url| using the provided |script|. The extracted content | 54 // and distill the |url| using the provided |script|. The extracted content |
(...skipping 16 matching lines...) Expand all Loading... |
124 // used. | 71 // used. |
125 virtual scoped_ptr<DistillerPage> CreateDistillerPage( | 72 virtual scoped_ptr<DistillerPage> CreateDistillerPage( |
126 const gfx::Size& render_view_size) const = 0; | 73 const gfx::Size& render_view_size) const = 0; |
127 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( | 74 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( |
128 scoped_ptr<SourcePageHandle> handle) const = 0; | 75 scoped_ptr<SourcePageHandle> handle) const = 0; |
129 }; | 76 }; |
130 | 77 |
131 } // namespace dom_distiller | 78 } // namespace dom_distiller |
132 | 79 |
133 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 80 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
OLD | NEW |