Chromium Code Reviews| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 StartDistillation(content::WebContents* web_contents) { |
| 114 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); | |
| 115 if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) { | |
|
nyquist
2015/03/13 21:21:20
If the distillation is not started here, wouldn't
nyquist
2015/03/13 23:46:08
Please remove the curly braces.
nyquist
2015/03/14 00:49:57
Also; I guess at that point we would have to renam
| |
| 116 return; | |
| 117 } | |
| 118 | |
| 114 // Start distillation using |web_contents|, and ensure ViewerHandle stays | 119 // Start distillation using |web_contents|, and ensure ViewerHandle stays |
| 115 // around until the viewer requests distillation. | 120 // around until the viewer requests distillation. |
| 116 SelfDeletingRequestDelegate* view_request_delegate = | 121 SelfDeletingRequestDelegate* view_request_delegate = |
| 117 new SelfDeletingRequestDelegate(web_contents); | 122 new SelfDeletingRequestDelegate(web_contents); |
| 118 scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents); | 123 scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents); |
| 119 scoped_ptr<SourcePageHandleWebContents> source_page_handle( | 124 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
| 120 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); | 125 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); |
| 121 DomDistillerService* dom_distiller_service = | 126 DomDistillerService* dom_distiller_service = |
| 122 DomDistillerServiceFactory::GetForBrowserContext( | 127 DomDistillerServiceFactory::GetForBrowserContext( |
| 123 web_contents->GetBrowserContext()); | 128 web_contents->GetBrowserContext()); |
| 124 scoped_ptr<DistillerPage> distiller_page = | 129 scoped_ptr<DistillerPage> distiller_page = |
| 125 dom_distiller_service->CreateDefaultDistillerPageWithHandle( | 130 dom_distiller_service->CreateDefaultDistillerPageWithHandle( |
| 126 source_page_handle.Pass()).Pass(); | 131 source_page_handle.Pass()).Pass(); |
| 127 | 132 |
| 128 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); | |
| 129 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( | 133 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( |
| 130 view_request_delegate, distiller_page.Pass(), last_committed_url); | 134 view_request_delegate, distiller_page.Pass(), last_committed_url); |
| 131 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); | 135 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 } // namespace | 138 } // namespace |
| 135 | 139 |
| 136 void DistillCurrentPageAndView(content::WebContents* old_web_contents) { | 140 void DistillCurrentPageAndView(content::WebContents* old_web_contents) { |
| 137 DCHECK(old_web_contents); | 141 DCHECK(old_web_contents); |
| 138 // Create new WebContents. | 142 // Create new WebContents. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 151 // difficult to distinguish between the intermediate reload and a user hitting | 155 // difficult to distinguish between the intermediate reload and a user hitting |
| 152 // the back button. | 156 // the back button. |
| 153 StartNavigationToDistillerViewer(new_web_contents, | 157 StartNavigationToDistillerViewer(new_web_contents, |
| 154 old_web_contents->GetLastCommittedURL()); | 158 old_web_contents->GetLastCommittedURL()); |
| 155 | 159 |
| 156 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( | 160 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( |
| 157 old_web_contents, new_web_contents, false, false); | 161 old_web_contents, new_web_contents, false, false); |
| 158 | 162 |
| 159 StartDistillation(old_web_contents); | 163 StartDistillation(old_web_contents); |
| 160 } | 164 } |
| OLD | NEW |