Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / components / dom_distiller / content / distiller_page_web_contents.h
blobaed9789cf55249188c0d0460aa68e7804e04774e
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 SourcePageHandleWebContents : public SourcePageHandle {
25 public:
26 explicit SourcePageHandleWebContents(
27 scoped_ptr<content::WebContents> web_contents);
28 virtual ~SourcePageHandleWebContents();
30 scoped_ptr<content::WebContents> GetWebContents();
32 private:
33 // The WebContents this class owns.
34 scoped_ptr<content::WebContents> web_contents_;
37 class DistillerPageWebContentsFactory : public DistillerPageFactory {
38 public:
39 explicit DistillerPageWebContentsFactory(
40 content::BrowserContext* browser_context)
41 : DistillerPageFactory(), browser_context_(browser_context) {}
42 virtual ~DistillerPageWebContentsFactory() {}
44 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const OVERRIDE;
45 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle(
46 scoped_ptr<SourcePageHandle> handle) const OVERRIDE;
48 private:
49 content::BrowserContext* browser_context_;
52 class DistillerPageWebContents : public DistillerPage,
53 public content::WebContentsObserver {
54 public:
55 DistillerPageWebContents(
56 content::BrowserContext* browser_context,
57 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle);
58 virtual ~DistillerPageWebContents();
60 // content::WebContentsObserver implementation.
61 virtual void DocumentLoadedInFrame(int64 frame_id,
62 RenderViewHost* render_view_host) OVERRIDE;
64 virtual void DidFailLoad(int64 frame_id,
65 const GURL& validated_url,
66 bool is_main_frame,
67 int error_code,
68 const base::string16& error_description,
69 RenderViewHost* render_view_host) OVERRIDE;
71 protected:
72 virtual void DistillPageImpl(const GURL& url,
73 const std::string& script) OVERRIDE;
75 private:
76 friend class TestDistillerPageWebContents;
78 enum State {
79 // The page distiller is idle.
80 IDLE,
81 // A page is currently loading.
82 LOADING_PAGE,
83 // There was an error processing the page.
84 PAGELOAD_FAILED,
85 // JavaScript is executing within the context of the page. When the
86 // JavaScript completes, the state will be returned to |IDLE|.
87 EXECUTING_JAVASCRIPT
90 // Creates a new WebContents, adds |this| as an observer, and loads the
91 // |url|.
92 virtual void CreateNewWebContents(const GURL& url);
94 // Injects and executes JavaScript in the context of a loaded page. This
95 // must only be called after the page has successfully loaded.
96 void ExecuteJavaScript();
98 // Called when the distillation is done or if the page load failed.
99 void OnWebContentsDistillationDone(const GURL& page_url,
100 const base::Value* value);
102 // The current state of the |DistillerPage|, initially |IDLE|.
103 State state_;
105 // The JavaScript to inject to extract content.
106 std::string script_;
108 scoped_ptr<content::WebContents> web_contents_;
109 content::BrowserContext* browser_context_;
110 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents);
113 } // namespace dom_distiller
115 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_