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

Unified Diff: chrome/browser/dom_distiller/tab_utils.cc

Issue 1125343004: Add a "Simplify Page" option to the print preview dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update AUTHORS file to reflect the correct HP name used in the CLA Created 5 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 side-by-side diff with in-line comments
Download patch
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());
}

Powered by Google App Engine
This is Rietveld 408576698