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_
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"
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
;
26 std::vector
<std::string
> authors
;
34 std::string secure_url
;
48 std::string description
;
49 std::string publisher
;
50 std::string copyright
;
52 MarkupArticle article
;
53 std::vector
<MarkupImage
> images
;
61 std::string next_page_url
;
62 std::string prev_page_url
;
63 std::vector
<std::string
> image_urls
;
64 MarkupInfo markup_info
;
70 DISALLOW_COPY_AND_ASSIGN(DistilledPageInfo
);
73 class SourcePageHandle
{
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.
85 typedef base::Callback
<void(scoped_ptr
<DistilledPageInfo
> distilled_page
,
86 bool distillation_successful
)>
87 DistillerPageCallback
;
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
);
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;
113 DistillerPageCallback distiller_page_callback_
;
114 DISALLOW_COPY_AND_ASSIGN(DistillerPage
);
117 // Factory for generating a |DistillerPage|.
118 class DistillerPageFactory
{
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
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_