OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ |
6 #define COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "components/dom_distiller/core/distiller_page.h" | 12 #include "components/dom_distiller/core/distiller_page.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_delegate.h" | 14 #include "content/public/browser/web_contents_delegate.h" |
14 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 namespace dom_distiller { | 18 namespace dom_distiller { |
18 | 19 |
19 class SourcePageHandleWebContents : public SourcePageHandle { | 20 class SourcePageHandleWebContents : public SourcePageHandle { |
20 public: | 21 public: |
21 explicit SourcePageHandleWebContents( | 22 explicit SourcePageHandleWebContents( |
22 scoped_ptr<content::WebContents> web_contents); | 23 scoped_ptr<content::WebContents> web_contents); |
23 ~SourcePageHandleWebContents() override; | 24 ~SourcePageHandleWebContents() override; |
24 | 25 |
25 scoped_ptr<content::WebContents> GetWebContents(); | 26 content::WebContents* GetWebContents() const override; |
26 | 27 |
27 private: | 28 private: |
28 // The WebContents this class owns. | 29 // The WebContents this class owns. |
29 scoped_ptr<content::WebContents> web_contents_; | 30 scoped_ptr<content::WebContents> web_contents_; |
30 }; | 31 }; |
31 | 32 |
| 33 class SourcePageHandleWebContentsWeakPtr : public SourcePageHandle { |
| 34 public: |
| 35 explicit SourcePageHandleWebContentsWeakPtr( |
| 36 content::WebContents* web_contents); |
| 37 ~SourcePageHandleWebContentsWeakPtr() override; |
| 38 |
| 39 content::WebContents* GetWebContents() const override; |
| 40 |
| 41 private: |
| 42 base::WeakPtrFactory<content::WebContents> weak_factory_; |
| 43 |
| 44 // The WebContents this class refs. |
| 45 base::WeakPtr<content::WebContents> web_contents_; |
| 46 }; |
| 47 |
32 class DistillerPageWebContentsFactory : public DistillerPageFactory { | 48 class DistillerPageWebContentsFactory : public DistillerPageFactory { |
33 public: | 49 public: |
34 explicit DistillerPageWebContentsFactory( | 50 explicit DistillerPageWebContentsFactory( |
35 content::BrowserContext* browser_context) | 51 content::BrowserContext* browser_context) |
36 : DistillerPageFactory(), browser_context_(browser_context) {} | 52 : DistillerPageFactory(), browser_context_(browser_context) {} |
37 ~DistillerPageWebContentsFactory() override {} | 53 ~DistillerPageWebContentsFactory() override {} |
38 | 54 |
39 scoped_ptr<DistillerPage> CreateDistillerPage( | 55 scoped_ptr<DistillerPage> CreateDistillerPage( |
40 const gfx::Size& render_view_size) const override; | 56 const gfx::Size& render_view_size) const override; |
41 scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( | 57 scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( |
42 scoped_ptr<SourcePageHandle> handle) const override; | 58 scoped_ptr<SourcePageHandle> handle) const override; |
43 | 59 |
44 private: | 60 private: |
45 content::BrowserContext* browser_context_; | 61 content::BrowserContext* browser_context_; |
46 }; | 62 }; |
47 | 63 |
48 class DistillerPageWebContents : public DistillerPage, | 64 class DistillerPageWebContents : public DistillerPage, |
49 public content::WebContentsDelegate, | 65 public content::WebContentsDelegate, |
50 public content::WebContentsObserver { | 66 public content::WebContentsObserver { |
51 public: | 67 public: |
52 DistillerPageWebContents( | 68 DistillerPageWebContents( |
53 content::BrowserContext* browser_context, | 69 content::BrowserContext* browser_context, |
| 70 const gfx::Size& render_view_size); |
| 71 DistillerPageWebContents( |
| 72 content::BrowserContext* browser_context, |
54 const gfx::Size& render_view_size, | 73 const gfx::Size& render_view_size, |
55 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle); | 74 scoped_ptr<SourcePageHandle> optional_web_contents_handle); |
56 ~DistillerPageWebContents() override; | 75 ~DistillerPageWebContents() override; |
57 | 76 |
58 // content::WebContentsDelegate implementation. | 77 // content::WebContentsDelegate implementation. |
59 gfx::Size GetSizeForNewRenderView( | 78 gfx::Size GetSizeForNewRenderView( |
60 content::WebContents* web_contents) const override; | 79 content::WebContents* web_contents) const override; |
61 | 80 |
62 // content::WebContentsObserver implementation. | 81 // content::WebContentsObserver implementation. |
63 void DocumentLoadedInFrame( | 82 void DocumentLoadedInFrame( |
64 content::RenderFrameHost* render_frame_host) override; | 83 content::RenderFrameHost* render_frame_host) override; |
65 | 84 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Called when the distillation is done or if the page load failed. | 118 // Called when the distillation is done or if the page load failed. |
100 void OnWebContentsDistillationDone(const GURL& page_url, | 119 void OnWebContentsDistillationDone(const GURL& page_url, |
101 const base::Value* value); | 120 const base::Value* value); |
102 | 121 |
103 // The current state of the |DistillerPage|, initially |IDLE|. | 122 // The current state of the |DistillerPage|, initially |IDLE|. |
104 State state_; | 123 State state_; |
105 | 124 |
106 // The JavaScript to inject to extract content. | 125 // The JavaScript to inject to extract content. |
107 std::string script_; | 126 std::string script_; |
108 | 127 |
109 scoped_ptr<content::WebContents> web_contents_; | 128 scoped_ptr<SourcePageHandle> web_contents_handle_; |
110 content::BrowserContext* browser_context_; | 129 content::BrowserContext* browser_context_; |
111 gfx::Size render_view_size_; | 130 gfx::Size render_view_size_; |
| 131 base::WeakPtrFactory<DistillerPageWebContents> weak_factory_; |
| 132 |
112 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents); | 133 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents); |
113 }; | 134 }; |
114 | 135 |
115 } // namespace dom_distiller | 136 } // namespace dom_distiller |
116 | 137 |
117 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ | 138 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ |
OLD | NEW |