| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/dom_distiller/tab_utils.h" | 5 #include "chrome/browser/dom_distiller/tab_utils.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 8 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 9 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 9 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 10 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 10 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Start loading the viewer URL of the current page in |web_contents|. | 103 // Start loading the viewer URL of the current page in |web_contents|. |
| 104 void StartNavigationToDistillerViewer(content::WebContents* web_contents, | 104 void StartNavigationToDistillerViewer(content::WebContents* web_contents, |
| 105 const GURL& url) { | 105 const GURL& url) { |
| 106 GURL viewer_url = dom_distiller::url_utils::GetDistillerViewUrlFromUrl( | 106 GURL viewer_url = dom_distiller::url_utils::GetDistillerViewUrlFromUrl( |
| 107 dom_distiller::kDomDistillerScheme, url); | 107 dom_distiller::kDomDistillerScheme, url); |
| 108 content::NavigationController::LoadURLParams params(viewer_url); | 108 content::NavigationController::LoadURLParams params(viewer_url); |
| 109 params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; | 109 params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 110 web_contents->GetController().LoadURLWithParams(params); | 110 web_contents->GetController().LoadURLWithParams(params); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void StartDistillation(content::WebContents* web_contents) { | 113 void MaybeStartDistillation(content::WebContents* web_contents) { |
| 114 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); |
| 115 if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) { |
| 116 delete web_contents; |
| 117 return; |
| 118 } |
| 119 |
| 114 // Start distillation using |web_contents|, and ensure ViewerHandle stays | 120 // Start distillation using |web_contents|, and ensure ViewerHandle stays |
| 115 // around until the viewer requests distillation. | 121 // around until the viewer requests distillation. |
| 116 SelfDeletingRequestDelegate* view_request_delegate = | 122 SelfDeletingRequestDelegate* view_request_delegate = |
| 117 new SelfDeletingRequestDelegate(web_contents); | 123 new SelfDeletingRequestDelegate(web_contents); |
| 118 scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents); | 124 scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents); |
| 119 scoped_ptr<SourcePageHandleWebContents> source_page_handle( | 125 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
| 120 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); | 126 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); |
| 121 DomDistillerService* dom_distiller_service = | 127 DomDistillerService* dom_distiller_service = |
| 122 DomDistillerServiceFactory::GetForBrowserContext( | 128 DomDistillerServiceFactory::GetForBrowserContext( |
| 123 web_contents->GetBrowserContext()); | 129 web_contents->GetBrowserContext()); |
| 124 scoped_ptr<DistillerPage> distiller_page = | 130 scoped_ptr<DistillerPage> distiller_page = |
| 125 dom_distiller_service->CreateDefaultDistillerPageWithHandle( | 131 dom_distiller_service->CreateDefaultDistillerPageWithHandle( |
| 126 source_page_handle.Pass()).Pass(); | 132 source_page_handle.Pass()).Pass(); |
| 127 | 133 |
| 128 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); | |
| 129 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( | 134 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( |
| 130 view_request_delegate, distiller_page.Pass(), last_committed_url); | 135 view_request_delegate, distiller_page.Pass(), last_committed_url); |
| 131 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); | 136 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); |
| 132 } | 137 } |
| 133 | 138 |
| 134 } // namespace | 139 } // namespace |
| 135 | 140 |
| 136 void DistillCurrentPageAndView(content::WebContents* old_web_contents) { | 141 void DistillCurrentPageAndView(content::WebContents* old_web_contents) { |
| 137 DCHECK(old_web_contents); | 142 DCHECK(old_web_contents); |
| 138 // Create new WebContents. | 143 // Create new WebContents. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 149 // StartNavigationToDistillerViewer must come before swapping the tab contents | 154 // StartNavigationToDistillerViewer must come before swapping the tab contents |
| 150 // to avoid triggering a reload of the page. This reloadmakes it very | 155 // to avoid triggering a reload of the page. This reloadmakes it very |
| 151 // difficult to distinguish between the intermediate reload and a user hitting | 156 // difficult to distinguish between the intermediate reload and a user hitting |
| 152 // the back button. | 157 // the back button. |
| 153 StartNavigationToDistillerViewer(new_web_contents, | 158 StartNavigationToDistillerViewer(new_web_contents, |
| 154 old_web_contents->GetLastCommittedURL()); | 159 old_web_contents->GetLastCommittedURL()); |
| 155 | 160 |
| 156 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( | 161 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( |
| 157 old_web_contents, new_web_contents, false, false); | 162 old_web_contents, new_web_contents, false, false); |
| 158 | 163 |
| 159 StartDistillation(old_web_contents); | 164 MaybeStartDistillation(old_web_contents); |
| 160 } | 165 } |
| OLD | NEW |