| 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 16 matching lines...) Expand all Loading... |
| 27 DCHECK(web_contents_); | 27 DCHECK(web_contents_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SourcePageHandleWebContents::~SourcePageHandleWebContents() { | 30 SourcePageHandleWebContents::~SourcePageHandleWebContents() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 scoped_ptr<content::WebContents> SourcePageHandleWebContents::GetWebContents() { | 33 scoped_ptr<content::WebContents> SourcePageHandleWebContents::GetWebContents() { |
| 34 return web_contents_.Pass(); | 34 return web_contents_.Pass(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 DistillerPageWebContentsFactory::DistillerPageWebContentsFactory( |
| 38 content::BrowserContext* browser_context, |
| 39 const std::string& distiller_js_script) |
| 40 : DistillerPageFactory(), |
| 41 browser_context_(browser_context), |
| 42 distiller_js_script_(distiller_js_script) { |
| 43 } |
| 44 |
| 37 scoped_ptr<DistillerPage> DistillerPageWebContentsFactory::CreateDistillerPage( | 45 scoped_ptr<DistillerPage> DistillerPageWebContentsFactory::CreateDistillerPage( |
| 38 const gfx::Size& render_view_size) const { | 46 const gfx::Size& render_view_size) const { |
| 39 DCHECK(browser_context_); | 47 DCHECK(browser_context_); |
| 40 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( | 48 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( |
| 41 browser_context_, render_view_size, | 49 browser_context_, render_view_size, distiller_js_script_, |
| 42 scoped_ptr<SourcePageHandleWebContents>())); | 50 scoped_ptr<SourcePageHandleWebContents>())); |
| 43 } | 51 } |
| 44 | 52 |
| 45 scoped_ptr<DistillerPage> | 53 scoped_ptr<DistillerPage> |
| 46 DistillerPageWebContentsFactory::CreateDistillerPageWithHandle( | 54 DistillerPageWebContentsFactory::CreateDistillerPageWithHandle( |
| 47 scoped_ptr<SourcePageHandle> handle) const { | 55 scoped_ptr<SourcePageHandle> handle) const { |
| 48 DCHECK(browser_context_); | 56 DCHECK(browser_context_); |
| 49 scoped_ptr<SourcePageHandleWebContents> web_contents_handle = | 57 scoped_ptr<SourcePageHandleWebContents> web_contents_handle = |
| 50 scoped_ptr<SourcePageHandleWebContents>( | 58 scoped_ptr<SourcePageHandleWebContents>( |
| 51 static_cast<SourcePageHandleWebContents*>(handle.release())); | 59 static_cast<SourcePageHandleWebContents*>(handle.release())); |
| 52 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( | 60 return scoped_ptr<DistillerPage>(new DistillerPageWebContents( |
| 53 browser_context_, gfx::Size(), web_contents_handle.Pass())); | 61 browser_context_, gfx::Size(), distiller_js_script_, |
| 62 web_contents_handle.Pass())); |
| 54 } | 63 } |
| 55 | 64 |
| 56 DistillerPageWebContents::DistillerPageWebContents( | 65 DistillerPageWebContents::DistillerPageWebContents( |
| 57 content::BrowserContext* browser_context, | 66 content::BrowserContext* browser_context, |
| 58 const gfx::Size& render_view_size, | 67 const gfx::Size& render_view_size, |
| 68 const std::string& distiller_js_script, |
| 59 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle) | 69 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle) |
| 60 : state_(IDLE), browser_context_(browser_context), | 70 : DistillerPage(distiller_js_script), |
| 71 state_(IDLE), |
| 72 browser_context_(browser_context), |
| 61 render_view_size_(render_view_size) { | 73 render_view_size_(render_view_size) { |
| 62 if (optional_web_contents_handle) { | 74 if (optional_web_contents_handle) { |
| 63 web_contents_ = optional_web_contents_handle->GetWebContents().Pass(); | 75 web_contents_ = optional_web_contents_handle->GetWebContents().Pass(); |
| 64 if (render_view_size.IsEmpty()) | 76 if (render_view_size.IsEmpty()) |
| 65 render_view_size_ = web_contents_->GetContainerBounds().size(); | 77 render_view_size_ = web_contents_->GetContainerBounds().size(); |
| 66 } | 78 } |
| 67 } | 79 } |
| 68 | 80 |
| 69 DistillerPageWebContents::~DistillerPageWebContents() { | 81 DistillerPageWebContents::~DistillerPageWebContents() { |
| 70 if (web_contents_) | 82 if (web_contents_) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 181 |
| 170 void DistillerPageWebContents::OnWebContentsDistillationDone( | 182 void DistillerPageWebContents::OnWebContentsDistillationDone( |
| 171 const GURL& page_url, | 183 const GURL& page_url, |
| 172 const base::Value* value) { | 184 const base::Value* value) { |
| 173 DCHECK(state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); | 185 DCHECK(state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); |
| 174 state_ = IDLE; | 186 state_ = IDLE; |
| 175 DistillerPage::OnDistillationDone(page_url, value); | 187 DistillerPage::OnDistillationDone(page_url, value); |
| 176 } | 188 } |
| 177 | 189 |
| 178 } // namespace dom_distiller | 190 } // namespace dom_distiller |
| OLD | NEW |