| 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 MaybeStartDistillation(content::WebContents* web_contents) { | 113 void MaybeStartDistillation( |
| 114 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); | 114 scoped_ptr<SourcePageHandleWebContents> source_page_handle) { |
| 115 if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) { | 115 const GURL& last_committed_url = |
| 116 delete web_contents; | 116 source_page_handle->web_contents()->GetLastCommittedURL(); |
| 117 if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) |
| 117 return; | 118 return; |
| 118 } | |
| 119 | 119 |
| 120 // Start distillation using |web_contents|, and ensure ViewerHandle stays | 120 // Start distillation using |source_page_handle|, and ensure ViewerHandle |
| 121 // around until the viewer requests distillation. | 121 // stays around until the viewer requests distillation. |
| 122 SelfDeletingRequestDelegate* view_request_delegate = | 122 SelfDeletingRequestDelegate* view_request_delegate = |
| 123 new SelfDeletingRequestDelegate(web_contents); | 123 new SelfDeletingRequestDelegate(source_page_handle->web_contents()); |
| 124 scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents); | |
| 125 scoped_ptr<SourcePageHandleWebContents> source_page_handle( | |
| 126 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); | |
| 127 DomDistillerService* dom_distiller_service = | 124 DomDistillerService* dom_distiller_service = |
| 128 DomDistillerServiceFactory::GetForBrowserContext( | 125 DomDistillerServiceFactory::GetForBrowserContext( |
| 129 web_contents->GetBrowserContext()); | 126 source_page_handle->web_contents()->GetBrowserContext()); |
| 130 scoped_ptr<DistillerPage> distiller_page = | 127 scoped_ptr<DistillerPage> distiller_page = |
| 131 dom_distiller_service->CreateDefaultDistillerPageWithHandle( | 128 dom_distiller_service->CreateDefaultDistillerPageWithHandle( |
| 132 source_page_handle.Pass()).Pass(); | 129 source_page_handle.Pass()).Pass(); |
| 133 | 130 |
| 134 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( | 131 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( |
| 135 view_request_delegate, distiller_page.Pass(), last_committed_url); | 132 view_request_delegate, distiller_page.Pass(), last_committed_url); |
| 136 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); | 133 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); |
| 137 } | 134 } |
| 138 | 135 |
| 139 } // namespace | 136 } // namespace |
| (...skipping 14 matching lines...) Expand all Loading... |
| 154 // StartNavigationToDistillerViewer must come before swapping the tab contents | 151 // StartNavigationToDistillerViewer must come before swapping the tab contents |
| 155 // to avoid triggering a reload of the page. This reloadmakes it very | 152 // to avoid triggering a reload of the page. This reloadmakes it very |
| 156 // difficult to distinguish between the intermediate reload and a user hitting | 153 // difficult to distinguish between the intermediate reload and a user hitting |
| 157 // the back button. | 154 // the back button. |
| 158 StartNavigationToDistillerViewer(new_web_contents, | 155 StartNavigationToDistillerViewer(new_web_contents, |
| 159 old_web_contents->GetLastCommittedURL()); | 156 old_web_contents->GetLastCommittedURL()); |
| 160 | 157 |
| 161 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( | 158 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( |
| 162 old_web_contents, new_web_contents, false, false); | 159 old_web_contents, new_web_contents, false, false); |
| 163 | 160 |
| 164 MaybeStartDistillation(old_web_contents); | 161 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
| 162 new SourcePageHandleWebContents(old_web_contents, true)); |
| 163 |
| 164 MaybeStartDistillation(source_page_handle.Pass()); |
| 165 } | 165 } |
| 166 |
| 167 void DistillAndView(content::WebContents* source_web_contents, |
| 168 content::WebContents* destination_web_contents) { |
| 169 DCHECK(source_web_contents); |
| 170 DCHECK(destination_web_contents); |
| 171 |
| 172 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
| 173 new SourcePageHandleWebContents(source_web_contents, false)); |
| 174 |
| 175 MaybeStartDistillation(source_page_handle.Pass()); |
| 176 StartNavigationToDistillerViewer(destination_web_contents, |
| 177 source_web_contents->GetLastCommittedURL()); |
| 178 } |
| OLD | NEW |