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 16 matching lines...) Expand all Loading... |
27 // following the state transitions described along with the class's states. | 27 // following the state transitions described along with the class's states. |
28 // 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 |
29 // thrown away without ever being used. | 29 // thrown away without ever being used. |
30 class DistillerPage { | 30 class DistillerPage { |
31 public: | 31 public: |
32 typedef base::Callback< | 32 typedef base::Callback< |
33 void(scoped_ptr<proto::DomDistillerResult> distilled_page, | 33 void(scoped_ptr<proto::DomDistillerResult> distilled_page, |
34 bool distillation_successful)> DistillerPageCallback; | 34 bool distillation_successful)> DistillerPageCallback; |
35 | 35 |
36 DistillerPage(); | 36 DistillerPage(); |
| 37 // Use this constructor to override the JS that comes packaged with Chrome. |
| 38 // It should contain the string $$OPTIONS, which will be replaced with options |
| 39 // passed in as proto::DomDistillerOptions before it is executed in the page |
| 40 // context. |
| 41 DistillerPage(std::string distiller_js_script); |
37 virtual ~DistillerPage(); | 42 virtual ~DistillerPage(); |
38 | 43 |
39 // Loads a URL. |OnDistillationDone| is called when the load completes or | 44 // Loads a URL. |OnDistillationDone| is called when the load completes or |
40 // fails. May be called when the distiller is idle. Callers can assume that, | 45 // fails. May be called when the distiller is idle. Callers can assume that, |
41 // for a given |url| and |options|, any DistillerPage implementation will | 46 // for a given |url| and |options|, any DistillerPage implementation will |
42 // extract the same content. | 47 // extract the same content. |
43 void DistillPage(const GURL& url, | 48 void DistillPage(const GURL& url, |
44 const proto::DomDistillerOptions options, | 49 const proto::DomDistillerOptions options, |
45 const DistillerPageCallback& callback); | 50 const DistillerPageCallback& callback); |
46 | 51 |
47 // Called when the JavaScript execution completes. |page_url| is the url of | 52 // Called when the JavaScript execution completes. |page_url| is the url of |
48 // the distilled page. |value| contains data returned by the script. | 53 // the distilled page. |value| contains data returned by the script. |
49 virtual void OnDistillationDone(const GURL& page_url, | 54 virtual void OnDistillationDone(const GURL& page_url, |
50 const base::Value* value); | 55 const base::Value* value); |
51 | 56 |
52 protected: | 57 protected: |
53 // Called by |DistillPage| to carry out platform-specific instructions to load | 58 // Called by |DistillPage| to carry out platform-specific instructions to load |
54 // and distill the |url| using the provided |script|. The extracted content | 59 // and distill the |url| using the provided |script|. The extracted content |
55 // should be the same regardless of the DistillerPage implementation. | 60 // should be the same regardless of the DistillerPage implementation. |
56 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0; | 61 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0; |
57 | 62 |
58 private: | 63 private: |
59 bool ready_; | 64 bool ready_; |
| 65 // Contains the script which will be injected into the page which is |
| 66 // being distilled. It should contain the string $$OPTIONS, which will be |
| 67 // replaced with options passed in as proto::DomDistillerOptions before |
| 68 // it is executed in the page context. |
| 69 std::string distiller_js_script_; |
60 DistillerPageCallback distiller_page_callback_; | 70 DistillerPageCallback distiller_page_callback_; |
61 DISALLOW_COPY_AND_ASSIGN(DistillerPage); | 71 DISALLOW_COPY_AND_ASSIGN(DistillerPage); |
62 }; | 72 }; |
63 | 73 |
64 // Factory for generating a |DistillerPage|. | 74 // Factory for generating a |DistillerPage|. |
65 class DistillerPageFactory { | 75 class DistillerPageFactory { |
66 public: | 76 public: |
67 virtual ~DistillerPageFactory(); | 77 virtual ~DistillerPageFactory(); |
68 | 78 |
69 // Constructs and returns a new DistillerPage. The implementation of this | 79 // Constructs and returns a new DistillerPage. The implementation of this |
70 // should be very cheap, since the pages can be thrown away without being | 80 // should be very cheap, since the pages can be thrown away without being |
71 // used. | 81 // used. |
72 virtual scoped_ptr<DistillerPage> CreateDistillerPage( | 82 virtual scoped_ptr<DistillerPage> CreateDistillerPage( |
73 const gfx::Size& render_view_size) const = 0; | 83 const gfx::Size& render_view_size) const = 0; |
74 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( | 84 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( |
75 scoped_ptr<SourcePageHandle> handle) const = 0; | 85 scoped_ptr<SourcePageHandle> handle) const = 0; |
76 }; | 86 }; |
77 | 87 |
78 } // namespace dom_distiller | 88 } // namespace dom_distiller |
79 | 89 |
80 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 90 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
OLD | NEW |