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 #include "components/dom_distiller/content/distiller_page_web_contents.h" | 5 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" | 10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 DCHECK(web_contents_); | 26 DCHECK(web_contents_); |
27 } | 27 } |
28 | 28 |
29 SourcePageHandleWebContents::~SourcePageHandleWebContents() { | 29 SourcePageHandleWebContents::~SourcePageHandleWebContents() { |
30 } | 30 } |
31 | 31 |
32 scoped_ptr<content::WebContents> SourcePageHandleWebContents::GetWebContents() { | 32 scoped_ptr<content::WebContents> SourcePageHandleWebContents::GetWebContents() { |
33 return web_contents_.Pass(); | 33 return web_contents_.Pass(); |
34 } | 34 } |
35 | 35 |
36 scoped_ptr<DistillerPage> DistillerPageWebContentsFactory::CreateDistillerPage() | 36 scoped_ptr<DistillerPage> DistillerPageWebContentsFactory::CreateDistillerPage( |
37 const { | 37 const gfx::Size& render_view_size) const { |
38 DCHECK(browser_context_); | 38 DCHECK(browser_context_); |
39 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( | 39 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( |
40 browser_context_, scoped_ptr<SourcePageHandleWebContents>())); | 40 browser_context_, render_view_size, |
41 scoped_ptr<SourcePageHandleWebContents>())); | |
41 } | 42 } |
42 | 43 |
43 scoped_ptr<DistillerPage> | 44 scoped_ptr<DistillerPage> |
44 DistillerPageWebContentsFactory::CreateDistillerPageWithHandle( | 45 DistillerPageWebContentsFactory::CreateDistillerPageWithHandle( |
45 scoped_ptr<SourcePageHandle> handle) const { | 46 scoped_ptr<SourcePageHandle> handle) const { |
46 DCHECK(browser_context_); | 47 DCHECK(browser_context_); |
47 scoped_ptr<SourcePageHandleWebContents> web_contents_handle = | 48 scoped_ptr<SourcePageHandleWebContents> web_contents_handle = |
48 scoped_ptr<SourcePageHandleWebContents>( | 49 scoped_ptr<SourcePageHandleWebContents>( |
49 static_cast<SourcePageHandleWebContents*>(handle.release())); | 50 static_cast<SourcePageHandleWebContents*>(handle.release())); |
50 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( | 51 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( |
51 browser_context_, web_contents_handle.Pass())); | 52 browser_context_, gfx::Size(), web_contents_handle.Pass())); |
52 } | 53 } |
53 | 54 |
54 DistillerPageWebContents::DistillerPageWebContents( | 55 DistillerPageWebContents::DistillerPageWebContents( |
55 content::BrowserContext* browser_context, | 56 content::BrowserContext* browser_context, |
57 const gfx::Size& render_view_size, | |
56 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle) | 58 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle) |
57 : state_(IDLE), browser_context_(browser_context) { | 59 : state_(IDLE), browser_context_(browser_context), |
60 render_view_size_(render_view_size) { | |
58 if (optional_web_contents_handle) { | 61 if (optional_web_contents_handle) { |
59 web_contents_ = optional_web_contents_handle->GetWebContents().Pass(); | 62 web_contents_ = optional_web_contents_handle->GetWebContents().Pass(); |
63 if (render_view_size.IsEmpty()) | |
64 render_view_size_ = web_contents_->GetContainerBounds().size(); | |
60 } | 65 } |
61 } | 66 } |
62 | 67 |
63 DistillerPageWebContents::~DistillerPageWebContents() { | 68 DistillerPageWebContents::~DistillerPageWebContents() { |
69 if (web_contents_) | |
70 web_contents_->SetDelegate(NULL); | |
64 } | 71 } |
65 | 72 |
66 void DistillerPageWebContents::DistillPageImpl(const GURL& url, | 73 void DistillerPageWebContents::DistillPageImpl(const GURL& url, |
67 const std::string& script) { | 74 const std::string& script) { |
68 DCHECK(browser_context_); | 75 DCHECK(browser_context_); |
69 DCHECK(state_ == IDLE); | 76 DCHECK(state_ == IDLE); |
70 state_ = LOADING_PAGE; | 77 state_ = LOADING_PAGE; |
71 script_ = script; | 78 script_ = script; |
72 | 79 |
73 if (web_contents_ && web_contents_->GetLastCommittedURL() == url) { | 80 if (web_contents_ && web_contents_->GetLastCommittedURL() == url) { |
(...skipping 16 matching lines...) Expand all Loading... | |
90 CreateNewWebContents(url); | 97 CreateNewWebContents(url); |
91 } | 98 } |
92 } else { | 99 } else { |
93 CreateNewWebContents(url); | 100 CreateNewWebContents(url); |
94 } | 101 } |
95 } | 102 } |
96 | 103 |
97 void DistillerPageWebContents::CreateNewWebContents(const GURL& url) { | 104 void DistillerPageWebContents::CreateNewWebContents(const GURL& url) { |
98 // Create new WebContents to use for distilling the content. | 105 // Create new WebContents to use for distilling the content. |
99 content::WebContents::CreateParams create_params(browser_context_); | 106 content::WebContents::CreateParams create_params(browser_context_); |
100 create_params.initially_hidden = true; | 107 create_params.initially_hidden = true; |
Yaron
2014/07/15 01:46:27
I think you can do this more easily by just settin
kuan
2014/07/15 16:52:51
that was the first thing i tried, but it didn't wo
| |
101 web_contents_.reset(content::WebContents::Create(create_params)); | 108 web_contents_.reset(content::WebContents::Create(create_params)); |
102 DCHECK(web_contents_.get()); | 109 DCHECK(web_contents_.get()); |
103 | 110 |
111 web_contents_->SetDelegate(this); | |
112 | |
104 // Start observing WebContents and load the requested URL. | 113 // Start observing WebContents and load the requested URL. |
105 content::WebContentsObserver::Observe(web_contents_.get()); | 114 content::WebContentsObserver::Observe(web_contents_.get()); |
106 content::NavigationController::LoadURLParams params(url); | 115 content::NavigationController::LoadURLParams params(url); |
107 web_contents_->GetController().LoadURLWithParams(params); | 116 web_contents_->GetController().LoadURLWithParams(params); |
108 } | 117 } |
109 | 118 |
119 gfx::Size DistillerPageWebContents::GetSizeForNewRenderView( | |
120 content::WebContents* web_contents) const { | |
121 gfx::Size size(render_view_size_); | |
122 if (size.IsEmpty()) | |
123 web_contents->GetContainerBounds().size(); | |
nyquist
2014/07/15 17:13:02
was this supposed to say |size = wc->GCB().size()|
Yaron
2014/07/16 17:46:28
+1 (or early return but I think Tommy's suggestion
kuan
2014/07/17 09:57:25
Done. gd catch!
kuan
2014/07/17 09:57:25
Done.
| |
124 // If size is still empty, set an arbitary size so that document.offsetWidth | |
125 // in the executed domdistiller.js won't be 0. | |
126 if (size.IsEmpty()) { | |
127 DVLOG(1) << "Using default RenderView size 800x600"; | |
Yaron
2014/07/15 01:46:27
Can this actually happen?
kuan
2014/07/15 16:52:51
i hope not, but i figured i shld handle and log it
Yaron
2014/07/16 17:46:28
Hmm. Maybe just do a fullscreen result in that cas
kuan
2014/07/17 09:57:26
Done.
| |
128 size = gfx::Size(800, 600); | |
129 } | |
130 return size; | |
131 } | |
132 | |
110 void DistillerPageWebContents::DocumentLoadedInFrame( | 133 void DistillerPageWebContents::DocumentLoadedInFrame( |
111 content::RenderFrameHost* render_frame_host) { | 134 content::RenderFrameHost* render_frame_host) { |
112 if (render_frame_host == web_contents_->GetMainFrame()) { | 135 if (render_frame_host == web_contents_->GetMainFrame()) { |
113 ExecuteJavaScript(); | 136 ExecuteJavaScript(); |
114 } | 137 } |
115 } | 138 } |
116 | 139 |
117 void DistillerPageWebContents::DidFailLoad( | 140 void DistillerPageWebContents::DidFailLoad( |
118 content::RenderFrameHost* render_frame_host, | 141 content::RenderFrameHost* render_frame_host, |
119 const GURL& validated_url, | 142 const GURL& validated_url, |
(...skipping 25 matching lines...) Expand all Loading... | |
145 | 168 |
146 void DistillerPageWebContents::OnWebContentsDistillationDone( | 169 void DistillerPageWebContents::OnWebContentsDistillationDone( |
147 const GURL& page_url, | 170 const GURL& page_url, |
148 const base::Value* value) { | 171 const base::Value* value) { |
149 DCHECK(state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); | 172 DCHECK(state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); |
150 state_ = IDLE; | 173 state_ = IDLE; |
151 DistillerPage::OnDistillationDone(page_url, value); | 174 DistillerPage::OnDistillationDone(page_url, value); |
152 } | 175 } |
153 | 176 |
154 } // namespace dom_distiller | 177 } // namespace dom_distiller |
OLD | NEW |