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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 std::string next_page_url; | 22 std::string next_page_url; |
23 std::string prev_page_url; | 23 std::string prev_page_url; |
24 std::vector<std::string> image_urls; | 24 std::vector<std::string> image_urls; |
25 DistilledPageInfo(); | 25 DistilledPageInfo(); |
26 ~DistilledPageInfo(); | 26 ~DistilledPageInfo(); |
27 | 27 |
28 private: | 28 private: |
29 DISALLOW_COPY_AND_ASSIGN(DistilledPageInfo); | 29 DISALLOW_COPY_AND_ASSIGN(DistilledPageInfo); |
30 }; | 30 }; |
31 | 31 |
| 32 class SourcePageHandle { |
| 33 public: |
| 34 virtual ~SourcePageHandle() {} |
| 35 }; |
| 36 |
32 // Injects JavaScript into a page, and uses it to extract and return long-form | 37 // Injects JavaScript into a page, and uses it to extract and return long-form |
33 // content. The class can be reused to load and distill multiple pages, | 38 // content. The class can be reused to load and distill multiple pages, |
34 // following the state transitions described along with the class's states. | 39 // following the state transitions described along with the class's states. |
35 // Constructing a DistillerPage should be cheap, as some of the instances can be | 40 // Constructing a DistillerPage should be cheap, as some of the instances can be |
36 // thrown away without ever being used. | 41 // thrown away without ever being used. |
37 class DistillerPage { | 42 class DistillerPage { |
38 public: | 43 public: |
39 typedef base::Callback<void(scoped_ptr<DistilledPageInfo> distilled_page, | 44 typedef base::Callback<void(scoped_ptr<DistilledPageInfo> distilled_page, |
40 bool distillation_successful)> | 45 bool distillation_successful)> |
41 DistillerPageCallback; | 46 DistillerPageCallback; |
(...skipping 13 matching lines...) Expand all Loading... |
55 // the distilled page. |value| contains data returned by the script. | 60 // the distilled page. |value| contains data returned by the script. |
56 virtual void OnDistillationDone(const GURL& page_url, | 61 virtual void OnDistillationDone(const GURL& page_url, |
57 const base::Value* value); | 62 const base::Value* value); |
58 | 63 |
59 protected: | 64 protected: |
60 // Called by |DistillPage| to carry out platform-specific instructions to load | 65 // Called by |DistillPage| to carry out platform-specific instructions to load |
61 // and distill the |url| using the provided |script|. The extracted content | 66 // and distill the |url| using the provided |script|. The extracted content |
62 // should be the same regardless of the DistillerPage implementation. | 67 // should be the same regardless of the DistillerPage implementation. |
63 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0; | 68 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0; |
64 | 69 |
65 // Called by |ExecuteJavaScript| to carry out platform-specific instructions | |
66 // to inject and execute JavaScript within the context of the loaded page. | |
67 //virtual void ExecuteJavaScriptImpl() = 0; | |
68 | |
69 private: | 70 private: |
70 bool ready_; | 71 bool ready_; |
71 DistillerPageCallback distiller_page_callback_; | 72 DistillerPageCallback distiller_page_callback_; |
72 DISALLOW_COPY_AND_ASSIGN(DistillerPage); | 73 DISALLOW_COPY_AND_ASSIGN(DistillerPage); |
73 }; | 74 }; |
74 | 75 |
75 // Factory for generating a |DistillerPage|. | 76 // Factory for generating a |DistillerPage|. |
76 class DistillerPageFactory { | 77 class DistillerPageFactory { |
77 public: | 78 public: |
78 virtual ~DistillerPageFactory(); | 79 virtual ~DistillerPageFactory(); |
79 | 80 |
80 // Constructs and returns a new DistillerPage. The implementation of this | 81 // Constructs and returns a new DistillerPage. The implementation of this |
81 // should be very cheap, since the pages can be thrown away without being | 82 // should be very cheap, since the pages can be thrown away without being |
82 // used. | 83 // used. |
83 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const = 0; | 84 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const = 0; |
| 85 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( |
| 86 scoped_ptr<SourcePageHandle> handle) const = 0; |
84 }; | 87 }; |
85 | 88 |
86 } // namespace dom_distiller | 89 } // namespace dom_distiller |
87 | 90 |
88 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 91 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
OLD | NEW |