Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / components / dom_distiller / content / distiller_page_web_contents.h
blob52509f502804a79ae61d2c1bb1dd08d6f621008b
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_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_
6 #define COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_
8 #include <string>
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"
16 namespace content {
17 class RenderViewHost;
20 using content::RenderViewHost;
22 namespace dom_distiller {
24 class DistillerContext;
26 class DistillerPageWebContentsFactory : public DistillerPageFactory {
27 public:
28 explicit DistillerPageWebContentsFactory(
29 content::BrowserContext* browser_context)
30 : DistillerPageFactory(), browser_context_(browser_context) {}
31 virtual ~DistillerPageWebContentsFactory() {}
33 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const OVERRIDE;
35 private:
36 content::BrowserContext* browser_context_;
39 class DistillerPageWebContents : public DistillerPage,
40 public content::WebContentsObserver {
41 public:
42 DistillerPageWebContents(content::BrowserContext* browser_context);
43 virtual ~DistillerPageWebContents();
45 // content::WebContentsObserver implementation.
46 virtual void DocumentLoadedInFrame(int64 frame_id,
47 RenderViewHost* render_view_host) OVERRIDE;
49 virtual void DidFailLoad(int64 frame_id,
50 const GURL& validated_url,
51 bool is_main_frame,
52 int error_code,
53 const base::string16& error_description,
54 RenderViewHost* render_view_host) OVERRIDE;
56 protected:
57 virtual void DistillPageImpl(const GURL& url,
58 const std::string& script) OVERRIDE;
60 private:
61 enum State {
62 // The page distiller is idle.
63 IDLE,
64 // A page is currently loading.
65 LOADING_PAGE,
66 // There was an error processing the page.
67 PAGELOAD_FAILED,
68 // JavaScript is executing within the context of the page. When the
69 // JavaScript completes, the state will be returned to |IDLE|.
70 EXECUTING_JAVASCRIPT
73 // Injects and executes JavaScript in the context of a loaded page. This
74 // must only be called after the page has successfully loaded.
75 void ExecuteJavaScript();
77 // Called when the distillation is done or if the page load failed.
78 void OnWebContentsDistillationDone(const GURL& page_url,
79 const base::Value* value);
81 // The current state of the |DistillerPage|, initially |IDLE|.
82 State state_;
84 // The JavaScript to inject to extract content.
85 std::string script_;
87 scoped_ptr<content::WebContents> web_contents_;
88 content::BrowserContext* browser_context_;
89 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents);
92 } // namespace dom_distiller
94 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_