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