Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / components / dom_distiller / content / distiller_page_web_contents.h
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.
4
5 #ifndef COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_
6 #define COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "components/dom_distiller/core/distiller_page.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "url/gurl.h"
15
16 namespace content {
17 class RenderViewHost;
18 }
19
20 using content::RenderViewHost;
21
22 namespace dom_distiller {
23
24 class DistillerContext;
25
26 class DistillerPageWebContentsFactory : public DistillerPageFactory {
27  public:
28   explicit DistillerPageWebContentsFactory(
29       content::BrowserContext* browser_context)
30       : DistillerPageFactory(), browser_context_(browser_context) {}
31   virtual ~DistillerPageWebContentsFactory() {}
32
33   virtual scoped_ptr<DistillerPage> CreateDistillerPage(
34       const base::WeakPtr<DistillerPage::Delegate>& delegate) const OVERRIDE;
35
36  private:
37   content::BrowserContext* browser_context_;
38 };
39
40
41 class DistillerPageWebContents : public DistillerPage,
42                                  public content::WebContentsObserver {
43  public:
44   DistillerPageWebContents(const base::WeakPtr<Delegate>& delegate,
45                            content::BrowserContext* browser_context);
46   virtual ~DistillerPageWebContents();
47
48   // content::WebContentsObserver implementation.
49   virtual void DocumentLoadedInFrame(int64 frame_id,
50                                      RenderViewHost* render_view_host) OVERRIDE;
51
52   virtual void DidFailLoad(int64 frame_id,
53                            const GURL& validated_url,
54                            bool is_main_frame,
55                            int error_code,
56                            const base::string16& error_description,
57                            RenderViewHost* render_view_host) OVERRIDE;
58
59  protected:
60   virtual void InitImpl() OVERRIDE;
61   virtual void LoadURLImpl(const GURL& gurl) OVERRIDE;
62   virtual void ExecuteJavaScriptImpl(const std::string& script) OVERRIDE;
63
64  private:
65   scoped_ptr<content::WebContents> web_contents_;
66   content::BrowserContext* browser_context_;
67   DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents);
68 };
69
70 }  // namespace dom_distiller
71
72 #endif  // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_