| 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 "components/dom_distiller/core/distiller_page.h" | 11 #include "components/dom_distiller/core/distiller_page.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 class RenderViewHost; | 17 class RenderViewHost; |
| 18 } | 18 } |
| 19 | 19 |
| 20 using content::RenderViewHost; | 20 using content::RenderViewHost; |
| 21 | 21 |
| 22 namespace dom_distiller { | 22 namespace dom_distiller { |
| 23 | 23 |
| 24 class DistillerContext; | 24 class SourcePageHandleWebContents : public SourcePageHandle { |
| 25 public: |
| 26 explicit SourcePageHandleWebContents( |
| 27 scoped_ptr<content::WebContents> web_contents); |
| 28 virtual ~SourcePageHandleWebContents(); |
| 29 |
| 30 scoped_ptr<content::WebContents> GetWebContents(); |
| 31 |
| 32 private: |
| 33 // The WebContents this class owns. |
| 34 scoped_ptr<content::WebContents> web_contents_; |
| 35 }; |
| 25 | 36 |
| 26 class DistillerPageWebContentsFactory : public DistillerPageFactory { | 37 class DistillerPageWebContentsFactory : public DistillerPageFactory { |
| 27 public: | 38 public: |
| 28 explicit DistillerPageWebContentsFactory( | 39 explicit DistillerPageWebContentsFactory( |
| 29 content::BrowserContext* browser_context) | 40 content::BrowserContext* browser_context) |
| 30 : DistillerPageFactory(), browser_context_(browser_context) {} | 41 : DistillerPageFactory(), browser_context_(browser_context) {} |
| 31 virtual ~DistillerPageWebContentsFactory() {} | 42 virtual ~DistillerPageWebContentsFactory() {} |
| 32 | 43 |
| 33 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const OVERRIDE; | 44 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const OVERRIDE; |
| 45 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle( |
| 46 scoped_ptr<SourcePageHandle> handle) const OVERRIDE; |
| 34 | 47 |
| 35 private: | 48 private: |
| 36 content::BrowserContext* browser_context_; | 49 content::BrowserContext* browser_context_; |
| 37 }; | 50 }; |
| 38 | 51 |
| 39 class DistillerPageWebContents : public DistillerPage, | 52 class DistillerPageWebContents : public DistillerPage, |
| 40 public content::WebContentsObserver { | 53 public content::WebContentsObserver { |
| 41 public: | 54 public: |
| 42 DistillerPageWebContents(content::BrowserContext* browser_context); | 55 DistillerPageWebContents( |
| 56 content::BrowserContext* browser_context, |
| 57 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle); |
| 43 virtual ~DistillerPageWebContents(); | 58 virtual ~DistillerPageWebContents(); |
| 44 | 59 |
| 45 // content::WebContentsObserver implementation. | 60 // content::WebContentsObserver implementation. |
| 46 virtual void DocumentLoadedInFrame(int64 frame_id, | 61 virtual void DocumentLoadedInFrame(int64 frame_id, |
| 47 RenderViewHost* render_view_host) OVERRIDE; | 62 RenderViewHost* render_view_host) OVERRIDE; |
| 48 | 63 |
| 49 virtual void DidFailLoad(int64 frame_id, | 64 virtual void DidFailLoad(int64 frame_id, |
| 50 const GURL& validated_url, | 65 const GURL& validated_url, |
| 51 bool is_main_frame, | 66 bool is_main_frame, |
| 52 int error_code, | 67 int error_code, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 IDLE, | 78 IDLE, |
| 64 // A page is currently loading. | 79 // A page is currently loading. |
| 65 LOADING_PAGE, | 80 LOADING_PAGE, |
| 66 // There was an error processing the page. | 81 // There was an error processing the page. |
| 67 PAGELOAD_FAILED, | 82 PAGELOAD_FAILED, |
| 68 // JavaScript is executing within the context of the page. When the | 83 // JavaScript is executing within the context of the page. When the |
| 69 // JavaScript completes, the state will be returned to |IDLE|. | 84 // JavaScript completes, the state will be returned to |IDLE|. |
| 70 EXECUTING_JAVASCRIPT | 85 EXECUTING_JAVASCRIPT |
| 71 }; | 86 }; |
| 72 | 87 |
| 88 // Creates a new WebContents, adds |this| as an observer, and loads the |
| 89 // |url|. |
| 90 void CreateNewWebContents(const GURL& url); |
| 91 |
| 73 // Injects and executes JavaScript in the context of a loaded page. This | 92 // Injects and executes JavaScript in the context of a loaded page. This |
| 74 // must only be called after the page has successfully loaded. | 93 // must only be called after the page has successfully loaded. |
| 75 void ExecuteJavaScript(); | 94 void ExecuteJavaScript(); |
| 76 | 95 |
| 77 // Called when the distillation is done or if the page load failed. | 96 // Called when the distillation is done or if the page load failed. |
| 78 void OnWebContentsDistillationDone(const GURL& page_url, | 97 void OnWebContentsDistillationDone(const GURL& page_url, |
| 79 const base::Value* value); | 98 const base::Value* value); |
| 80 | 99 |
| 81 // The current state of the |DistillerPage|, initially |IDLE|. | 100 // The current state of the |DistillerPage|, initially |IDLE|. |
| 82 State state_; | 101 State state_; |
| 83 | 102 |
| 84 // The JavaScript to inject to extract content. | 103 // The JavaScript to inject to extract content. |
| 85 std::string script_; | 104 std::string script_; |
| 86 | 105 |
| 87 scoped_ptr<content::WebContents> web_contents_; | 106 scoped_ptr<content::WebContents> web_contents_; |
| 88 content::BrowserContext* browser_context_; | 107 content::BrowserContext* browser_context_; |
| 89 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents); | 108 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents); |
| 90 }; | 109 }; |
| 91 | 110 |
| 92 } // namespace dom_distiller | 111 } // namespace dom_distiller |
| 93 | 112 |
| 94 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ | 113 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ |
| OLD | NEW |