| Index: chrome/browser/dom_distiller/tab_utils.cc
|
| diff --git a/chrome/browser/dom_distiller/tab_utils.cc b/chrome/browser/dom_distiller/tab_utils.cc
|
| index 94fb24e04b7f223fceb42651c0bca22b267603eb..c58e043daaa341cafcb5c1db1d02c942100aef04 100644
|
| --- a/chrome/browser/dom_distiller/tab_utils.cc
|
| +++ b/chrome/browser/dom_distiller/tab_utils.cc
|
| @@ -25,11 +25,10 @@ using dom_distiller::ViewRequestDelegate;
|
| using dom_distiller::DistilledArticleProto;
|
| using dom_distiller::ArticleDistillationUpdate;
|
| using dom_distiller::ViewerHandle;
|
| -using dom_distiller::SourcePageHandleWebContents;
|
| +using dom_distiller::SourcePageHandleWebContentsWeakPtr;
|
| using dom_distiller::DomDistillerService;
|
| using dom_distiller::DomDistillerServiceFactory;
|
| using dom_distiller::DistillerPage;
|
| -using dom_distiller::SourcePageHandle;
|
|
|
| // An no-op ViewRequestDelegate which holds a ViewerHandle and deletes itself
|
| // after the WebContents navigates or goes away. This class is a band-aid to
|
| @@ -110,20 +109,19 @@ void StartNavigationToDistillerViewer(content::WebContents* web_contents,
|
| web_contents->GetController().LoadURLWithParams(params);
|
| }
|
|
|
| +} // namespace
|
| +
|
| void MaybeStartDistillation(content::WebContents* web_contents) {
|
| const GURL& last_committed_url = web_contents->GetLastCommittedURL();
|
| - if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) {
|
| - delete web_contents;
|
| + if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url))
|
| return;
|
| - }
|
|
|
| // Start distillation using |web_contents|, and ensure ViewerHandle stays
|
| // around until the viewer requests distillation.
|
| SelfDeletingRequestDelegate* view_request_delegate =
|
| new SelfDeletingRequestDelegate(web_contents);
|
| - scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents);
|
| - scoped_ptr<SourcePageHandleWebContents> source_page_handle(
|
| - new SourcePageHandleWebContents(old_web_contents_sptr.Pass()));
|
| + scoped_ptr<SourcePageHandleWebContentsWeakPtr> source_page_handle(
|
| + new SourcePageHandleWebContentsWeakPtr(web_contents));
|
| DomDistillerService* dom_distiller_service =
|
| DomDistillerServiceFactory::GetForBrowserContext(
|
| web_contents->GetBrowserContext());
|
| @@ -136,30 +134,14 @@ void MaybeStartDistillation(content::WebContents* web_contents) {
|
| view_request_delegate->TakeViewerHandle(viewer_handle.Pass());
|
| }
|
|
|
| -} // namespace
|
| -
|
| -void DistillCurrentPageAndView(content::WebContents* old_web_contents) {
|
| - DCHECK(old_web_contents);
|
| +void DistillCurrentPageAndView(content::WebContents* web_contents) {
|
| + DCHECK(web_contents);
|
| // Create new WebContents.
|
| content::WebContents::CreateParams create_params(
|
| - old_web_contents->GetBrowserContext());
|
| - content::WebContents* new_web_contents =
|
| - content::WebContents::Create(create_params);
|
| - DCHECK(new_web_contents);
|
| -
|
| - // Copy all navigation state from the old WebContents to the new one.
|
| - new_web_contents->GetController().CopyStateFrom(
|
| - old_web_contents->GetController());
|
| -
|
| - // StartNavigationToDistillerViewer must come before swapping the tab contents
|
| - // to avoid triggering a reload of the page. This reloadmakes it very
|
| - // difficult to distinguish between the intermediate reload and a user hitting
|
| - // the back button.
|
| - StartNavigationToDistillerViewer(new_web_contents,
|
| - old_web_contents->GetLastCommittedURL());
|
| -
|
| - CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents(
|
| - old_web_contents, new_web_contents, false, false);
|
| -
|
| - MaybeStartDistillation(old_web_contents);
|
| + web_contents->GetBrowserContext());
|
| +
|
| + MaybeStartDistillation(web_contents);
|
| +
|
| + StartNavigationToDistillerViewer(web_contents,
|
| + web_contents->GetLastCommittedURL());
|
| }
|
|
|