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