Chromium Code Reviews| 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 DistillerPage(std::string distiller_js_script); | |
| 37 virtual ~DistillerPage(); | 39 virtual ~DistillerPage(); |
| 38 | 40 |
| 39 // Loads a URL. |OnDistillationDone| is called when the load completes or | 41 // 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, | 42 // fails. May be called when the distiller is idle. Callers can assume that, |
| 41 // for a given |url| and |options|, any DistillerPage implementation will | 43 // for a given |url| and |options|, any DistillerPage implementation will |
| 42 // extract the same content. | 44 // extract the same content. |
| 43 void DistillPage(const GURL& url, | 45 void DistillPage(const GURL& url, |
| 44 const proto::DomDistillerOptions options, | 46 const proto::DomDistillerOptions options, |
| 45 const DistillerPageCallback& callback); | 47 const DistillerPageCallback& callback); |
| 46 | 48 |
| 47 // Called when the JavaScript execution completes. |page_url| is the url of | 49 // Called when the JavaScript execution completes. |page_url| is the url of |
| 48 // the distilled page. |value| contains data returned by the script. | 50 // the distilled page. |value| contains data returned by the script. |
| 49 virtual void OnDistillationDone(const GURL& page_url, | 51 virtual void OnDistillationDone(const GURL& page_url, |
| 50 const base::Value* value); | 52 const base::Value* value); |
| 51 | 53 |
| 52 protected: | 54 protected: |
| 53 // Called by |DistillPage| to carry out platform-specific instructions to load | 55 // Called by |DistillPage| to carry out platform-specific instructions to load |
| 54 // and distill the |url| using the provided |script|. The extracted content | 56 // and distill the |url| using the provided |script|. The extracted content |
| 55 // should be the same regardless of the DistillerPage implementation. | 57 // should be the same regardless of the DistillerPage implementation. |
| 56 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0; | 58 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0; |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 bool ready_; | 61 bool ready_; |
| 62 // An optional script for overriding the JS that comes packaged with Chrome. | |
|
cjhopman
2015/02/05 02:09:40
This isn't really optional, it will always hold th
nyquist
2015/02/06 18:50:32
Done.
Also updated the comment above the construct
| |
| 63 std::string distiller_js_script_; | |
| 60 DistillerPageCallback distiller_page_callback_; | 64 DistillerPageCallback distiller_page_callback_; |
| 61 DISALLOW_COPY_AND_ASSIGN(DistillerPage); | 65 DISALLOW_COPY_AND_ASSIGN(DistillerPage); |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 // Factory for generating a |DistillerPage|. | 68 // Factory for generating a |DistillerPage|. |
| 65 class DistillerPageFactory { | 69 class DistillerPageFactory { |
| 66 public: | 70 public: |
| 67 virtual ~DistillerPageFactory(); | 71 virtual ~DistillerPageFactory(); |
| 68 | 72 |
| 69 // Constructs and returns a new DistillerPage. The implementation of this | 73 // Constructs and returns a new DistillerPage. The implementation of this |
| 70 // should be very cheap, since the pages can be thrown away without being | 74 // should be very cheap, since the pages can be thrown away without being |
| 71 // used. | 75 // used. |
| 72 virtual scoped_ptr<DistillerPage> CreateDistillerPage( | 76 virtual scoped_ptr<DistillerPage> CreateDistillerPage( |
| 73 const gfx::Size& render_view_size) const = 0; | 77 const gfx::Size& render_view_size) const = 0; |
| 74 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( | 78 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( |
| 75 scoped_ptr<SourcePageHandle> handle) const = 0; | 79 scoped_ptr<SourcePageHandle> handle) const = 0; |
| 76 }; | 80 }; |
| 77 | 81 |
| 78 } // namespace dom_distiller | 82 } // namespace dom_distiller |
| 79 | 83 |
| 80 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 84 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
| OLD | NEW |