Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / dom_distiller / core / distiller_page.h
blob21c037fd507dcf7023148596468d38a0fef96166
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_
6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/values.h"
14 #include "third_party/dom_distiller_js/dom_distiller.pb.h"
15 #include "ui/gfx/size.h"
16 #include "url/gurl.h"
18 namespace dom_distiller {
20 struct DistilledPageInfo {
21 struct MarkupArticle {
22 std::string published_time;
23 std::string modified_time;
24 std::string expiration_time;
25 std::string section;
26 std::vector<std::string> authors;
28 MarkupArticle();
29 ~MarkupArticle();
32 struct MarkupImage {
33 std::string url;
34 std::string secure_url;
35 std::string type;
36 std::string caption;
37 int width;
38 int height;
40 MarkupImage();
41 ~MarkupImage();
44 struct MarkupInfo {
45 std::string title;
46 std::string type;
47 std::string url;
48 std::string description;
49 std::string publisher;
50 std::string copyright;
51 std::string author;
52 MarkupArticle article;
53 std::vector<MarkupImage> images;
55 MarkupInfo();
56 ~MarkupInfo();
59 std::string title;
60 std::string html;
61 std::string next_page_url;
62 std::string prev_page_url;
63 std::vector<std::string> image_urls;
64 MarkupInfo markup_info;
66 DistilledPageInfo();
67 ~DistilledPageInfo();
69 private:
70 DISALLOW_COPY_AND_ASSIGN(DistilledPageInfo);
73 class SourcePageHandle {
74 public:
75 virtual ~SourcePageHandle() {}
78 // Injects JavaScript into a page, and uses it to extract and return long-form
79 // content. The class can be reused to load and distill multiple pages,
80 // following the state transitions described along with the class's states.
81 // Constructing a DistillerPage should be cheap, as some of the instances can be
82 // thrown away without ever being used.
83 class DistillerPage {
84 public:
85 typedef base::Callback<void(scoped_ptr<DistilledPageInfo> distilled_page,
86 bool distillation_successful)>
87 DistillerPageCallback;
89 DistillerPage();
90 virtual ~DistillerPage();
92 // Loads a URL. |OnDistillationDone| is called when the load completes or
93 // fails. May be called when the distiller is idle. Callers can assume that,
94 // for a given |url| and |options|, any DistillerPage implementation will
95 // extract the same content.
96 void DistillPage(const GURL& url,
97 const dom_distiller::proto::DomDistillerOptions options,
98 const DistillerPageCallback& callback);
100 // Called when the JavaScript execution completes. |page_url| is the url of
101 // the distilled page. |value| contains data returned by the script.
102 virtual void OnDistillationDone(const GURL& page_url,
103 const base::Value* value);
105 protected:
106 // Called by |DistillPage| to carry out platform-specific instructions to load
107 // and distill the |url| using the provided |script|. The extracted content
108 // should be the same regardless of the DistillerPage implementation.
109 virtual void DistillPageImpl(const GURL& url, const std::string& script) = 0;
111 private:
112 bool ready_;
113 DistillerPageCallback distiller_page_callback_;
114 DISALLOW_COPY_AND_ASSIGN(DistillerPage);
117 // Factory for generating a |DistillerPage|.
118 class DistillerPageFactory {
119 public:
120 virtual ~DistillerPageFactory();
122 // Constructs and returns a new DistillerPage. The implementation of this
123 // should be very cheap, since the pages can be thrown away without being
124 // used.
125 virtual scoped_ptr<DistillerPage> CreateDistillerPage(
126 const gfx::Size& render_view_size) const = 0;
127 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle(
128 scoped_ptr<SourcePageHandle> handle) const = 0;
131 } // namespace dom_distiller
133 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_