OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_PAGE_DISTILLER_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_CORE_PAGE_DISTILLER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" |
| 14 #include "components/dom_distiller/core/distiller_page.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace dom_distiller { |
| 18 |
| 19 class DistillerImpl; |
| 20 |
| 21 struct DistilledPageInfo { |
| 22 std::string title; |
| 23 std::string html; |
| 24 std::string next_page_url; |
| 25 std::vector<std::string> image_urls; |
| 26 DistilledPageInfo(); |
| 27 ~DistilledPageInfo(); |
| 28 |
| 29 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(DistilledPageInfo); |
| 31 }; |
| 32 |
| 33 // Distills a single page of an article. |
| 34 class PageDistiller : public DistillerPage::Delegate { |
| 35 public: |
| 36 typedef base::Callback<void(scoped_ptr<DistilledPageInfo> distilled_page, |
| 37 bool distillation_successful)> |
| 38 PageDistillerCallback; |
| 39 explicit PageDistiller(const DistillerPageFactory& distiller_page_factory); |
| 40 virtual ~PageDistiller(); |
| 41 |
| 42 // Creates an execution context. This must be called once before any calls are |
| 43 // made to distill the page. |
| 44 virtual void Init(); |
| 45 |
| 46 // Distills the |url| and posts the |callback| with results. |
| 47 virtual void DistillPage(const GURL& url, |
| 48 const PageDistillerCallback& callback); |
| 49 |
| 50 // DistillerPage::Delegate |
| 51 virtual void OnLoadURLDone() OVERRIDE; |
| 52 virtual void OnExecuteJavaScriptDone(const GURL& page_url, |
| 53 const base::Value* value) OVERRIDE; |
| 54 |
| 55 private: |
| 56 virtual void LoadURL(const GURL& url); |
| 57 |
| 58 // Injects JavaScript to distill a loaded page down to its important content, |
| 59 // e.g., extracting a news article from its surrounding boilerplate. |
| 60 void GetDistilledContent(); |
| 61 |
| 62 scoped_ptr<DistillerPage> distiller_page_; |
| 63 PageDistillerCallback page_distiller_callback_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(PageDistiller); |
| 66 }; |
| 67 |
| 68 } // namespace dom_distiller |
| 69 |
| 70 #endif // COMPONENTS_DOM_DISTILLER_CORE_PAGE_DISTILLER_H_ |
OLD | NEW |