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

Unified Diff: components/dom_distiller/content/distiller_page_web_contents.cc

Issue 396503003: DomDistiller: fix 0 document width (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/content/distiller_page_web_contents.cc
diff --git a/components/dom_distiller/content/distiller_page_web_contents.cc b/components/dom_distiller/content/distiller_page_web_contents.cc
index 41187eb2b88cd63044797c7e10f6e3be814f4025..0967fac90873cd4bf893e7674927effcb517826b 100644
--- a/components/dom_distiller/content/distiller_page_web_contents.cc
+++ b/components/dom_distiller/content/distiller_page_web_contents.cc
@@ -33,11 +33,12 @@ scoped_ptr<content::WebContents> SourcePageHandleWebContents::GetWebContents() {
return web_contents_.Pass();
}
-scoped_ptr<DistillerPage> DistillerPageWebContentsFactory::CreateDistillerPage()
- const {
+scoped_ptr<DistillerPage> DistillerPageWebContentsFactory::CreateDistillerPage(
+ const gfx::Size& render_view_size) const {
DCHECK(browser_context_);
return scoped_ptr<DistillerPage>(new DistillerPageWebContents(
- browser_context_, scoped_ptr<SourcePageHandleWebContents>()));
+ browser_context_, render_view_size,
+ scoped_ptr<SourcePageHandleWebContents>()));
}
scoped_ptr<DistillerPage>
@@ -48,19 +49,25 @@ DistillerPageWebContentsFactory::CreateDistillerPageWithHandle(
scoped_ptr<SourcePageHandleWebContents>(
static_cast<SourcePageHandleWebContents*>(handle.release()));
return scoped_ptr<DistillerPage>(new DistillerPageWebContents(
- browser_context_, web_contents_handle.Pass()));
+ browser_context_, gfx::Size(), web_contents_handle.Pass()));
}
DistillerPageWebContents::DistillerPageWebContents(
content::BrowserContext* browser_context,
+ const gfx::Size& render_view_size,
scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle)
- : state_(IDLE), browser_context_(browser_context) {
+ : state_(IDLE), browser_context_(browser_context),
+ render_view_size_(render_view_size) {
if (optional_web_contents_handle) {
web_contents_ = optional_web_contents_handle->GetWebContents().Pass();
+ if (render_view_size.IsEmpty())
+ render_view_size_ = web_contents_->GetContainerBounds().size();
}
}
DistillerPageWebContents::~DistillerPageWebContents() {
+ if (web_contents_)
+ web_contents_->SetDelegate(NULL);
}
void DistillerPageWebContents::DistillPageImpl(const GURL& url,
@@ -101,12 +108,28 @@ void DistillerPageWebContents::CreateNewWebContents(const GURL& url) {
web_contents_.reset(content::WebContents::Create(create_params));
DCHECK(web_contents_.get());
+ web_contents_->SetDelegate(this);
+
// Start observing WebContents and load the requested URL.
content::WebContentsObserver::Observe(web_contents_.get());
content::NavigationController::LoadURLParams params(url);
web_contents_->GetController().LoadURLWithParams(params);
}
+gfx::Size DistillerPageWebContents::GetSizeForNewRenderView(
+ content::WebContents* web_contents) const {
+ gfx::Size size(render_view_size_);
+ if (size.IsEmpty())
+ 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.
+ // If size is still empty, set an arbitary size so that document.offsetWidth
+ // in the executed domdistiller.js won't be 0.
+ if (size.IsEmpty()) {
+ 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.
+ size = gfx::Size(800, 600);
+ }
+ return size;
+}
+
void DistillerPageWebContents::DocumentLoadedInFrame(
content::RenderFrameHost* render_frame_host) {
if (render_frame_host == web_contents_->GetMainFrame()) {

Powered by Google App Engine
This is Rietveld 408576698