Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1064)

Side by Side Diff: trunk/src/components/dom_distiller/content/distiller_page_web_contents.h

Issue 297163003: Revert 272611 "Add support for distilling current WebContents" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 SourcePageHandleWebContents : public SourcePageHandle { 24 class DistillerContext;
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 };
36 25
37 class DistillerPageWebContentsFactory : public DistillerPageFactory { 26 class DistillerPageWebContentsFactory : public DistillerPageFactory {
38 public: 27 public:
39 explicit DistillerPageWebContentsFactory( 28 explicit DistillerPageWebContentsFactory(
40 content::BrowserContext* browser_context) 29 content::BrowserContext* browser_context)
41 : DistillerPageFactory(), browser_context_(browser_context) {} 30 : DistillerPageFactory(), browser_context_(browser_context) {}
42 virtual ~DistillerPageWebContentsFactory() {} 31 virtual ~DistillerPageWebContentsFactory() {}
43 32
44 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const OVERRIDE; 33 virtual scoped_ptr<DistillerPage> CreateDistillerPage() const OVERRIDE;
45 virtual scoped_ptr<DistillerPage> CreateDistillerPageWithHandle(
46 scoped_ptr<SourcePageHandle> handle) const OVERRIDE;
47 34
48 private: 35 private:
49 content::BrowserContext* browser_context_; 36 content::BrowserContext* browser_context_;
50 }; 37 };
51 38
52 class DistillerPageWebContents : public DistillerPage, 39 class DistillerPageWebContents : public DistillerPage,
53 public content::WebContentsObserver { 40 public content::WebContentsObserver {
54 public: 41 public:
55 DistillerPageWebContents( 42 DistillerPageWebContents(content::BrowserContext* browser_context);
56 content::BrowserContext* browser_context,
57 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle);
58 virtual ~DistillerPageWebContents(); 43 virtual ~DistillerPageWebContents();
59 44
60 // content::WebContentsObserver implementation. 45 // content::WebContentsObserver implementation.
61 virtual void DocumentLoadedInFrame(int64 frame_id, 46 virtual void DocumentLoadedInFrame(int64 frame_id,
62 RenderViewHost* render_view_host) OVERRIDE; 47 RenderViewHost* render_view_host) OVERRIDE;
63 48
64 virtual void DidFailLoad(int64 frame_id, 49 virtual void DidFailLoad(int64 frame_id,
65 const GURL& validated_url, 50 const GURL& validated_url,
66 bool is_main_frame, 51 bool is_main_frame,
67 int error_code, 52 int error_code,
68 const base::string16& error_description, 53 const base::string16& error_description,
69 RenderViewHost* render_view_host) OVERRIDE; 54 RenderViewHost* render_view_host) OVERRIDE;
70 55
71 protected: 56 protected:
72 virtual void DistillPageImpl(const GURL& url, 57 virtual void DistillPageImpl(const GURL& url,
73 const std::string& script) OVERRIDE; 58 const std::string& script) OVERRIDE;
74 59
75 private: 60 private:
76 friend class TestDistillerPageWebContents;
77
78 enum State { 61 enum State {
79 // The page distiller is idle. 62 // The page distiller is idle.
80 IDLE, 63 IDLE,
81 // A page is currently loading. 64 // A page is currently loading.
82 LOADING_PAGE, 65 LOADING_PAGE,
83 // There was an error processing the page. 66 // There was an error processing the page.
84 PAGELOAD_FAILED, 67 PAGELOAD_FAILED,
85 // JavaScript is executing within the context of the page. When the 68 // JavaScript is executing within the context of the page. When the
86 // JavaScript completes, the state will be returned to |IDLE|. 69 // JavaScript completes, the state will be returned to |IDLE|.
87 EXECUTING_JAVASCRIPT 70 EXECUTING_JAVASCRIPT
88 }; 71 };
89 72
90 // Creates a new WebContents, adds |this| as an observer, and loads the
91 // |url|.
92 virtual void CreateNewWebContents(const GURL& url);
93
94 // Injects and executes JavaScript in the context of a loaded page. This 73 // Injects and executes JavaScript in the context of a loaded page. This
95 // must only be called after the page has successfully loaded. 74 // must only be called after the page has successfully loaded.
96 void ExecuteJavaScript(); 75 void ExecuteJavaScript();
97 76
98 // Called when the distillation is done or if the page load failed. 77 // Called when the distillation is done or if the page load failed.
99 void OnWebContentsDistillationDone(const GURL& page_url, 78 void OnWebContentsDistillationDone(const GURL& page_url,
100 const base::Value* value); 79 const base::Value* value);
101 80
102 // The current state of the |DistillerPage|, initially |IDLE|. 81 // The current state of the |DistillerPage|, initially |IDLE|.
103 State state_; 82 State state_;
104 83
105 // The JavaScript to inject to extract content. 84 // The JavaScript to inject to extract content.
106 std::string script_; 85 std::string script_;
107 86
108 scoped_ptr<content::WebContents> web_contents_; 87 scoped_ptr<content::WebContents> web_contents_;
109 content::BrowserContext* browser_context_; 88 content::BrowserContext* browser_context_;
110 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents); 89 DISALLOW_COPY_AND_ASSIGN(DistillerPageWebContents);
111 }; 90 };
112 91
113 } // namespace dom_distiller 92 } // namespace dom_distiller
114 93
115 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_ 94 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLER_PAGE_WEB_CONTENTS_H_
OLDNEW
« no previous file with comments | « trunk/src/components/dom_distiller.gypi ('k') | trunk/src/components/dom_distiller/content/distiller_page_web_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698