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(content::WebContents* web_contents, bool owned) { |
114 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); | 114 const GURL& last_committed_url = web_contents->GetLastCommittedURL(); |
115 if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) { | 115 if (!dom_distiller::url_utils::IsUrlDistillable(last_committed_url)) { |
116 delete web_contents; | 116 if (owned) |
117 delete web_contents; | |
117 return; | 118 return; |
118 } | 119 } |
119 | 120 |
120 // Start distillation using |web_contents|, and ensure ViewerHandle stays | 121 // Start distillation using |web_contents|, and ensure ViewerHandle stays |
121 // around until the viewer requests distillation. | 122 // around until the viewer requests distillation. |
122 SelfDeletingRequestDelegate* view_request_delegate = | 123 SelfDeletingRequestDelegate* view_request_delegate = |
123 new SelfDeletingRequestDelegate(web_contents); | 124 new SelfDeletingRequestDelegate(web_contents); |
124 scoped_ptr<content::WebContents> old_web_contents_sptr(web_contents); | |
125 scoped_ptr<SourcePageHandleWebContents> source_page_handle( | 125 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
126 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); | 126 new SourcePageHandleWebContents(web_contents, owned)); |
cjhopman
2015/05/12 21:18:42
If you wrap this in the sourcepagehandle at the be
nyquist
2015/05/13 00:06:52
Done.
| |
127 DomDistillerService* dom_distiller_service = | 127 DomDistillerService* dom_distiller_service = |
128 DomDistillerServiceFactory::GetForBrowserContext( | 128 DomDistillerServiceFactory::GetForBrowserContext( |
129 web_contents->GetBrowserContext()); | 129 web_contents->GetBrowserContext()); |
130 scoped_ptr<DistillerPage> distiller_page = | 130 scoped_ptr<DistillerPage> distiller_page = |
131 dom_distiller_service->CreateDefaultDistillerPageWithHandle( | 131 dom_distiller_service->CreateDefaultDistillerPageWithHandle( |
132 source_page_handle.Pass()).Pass(); | 132 source_page_handle.Pass()).Pass(); |
133 | 133 |
134 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( | 134 scoped_ptr<ViewerHandle> viewer_handle = dom_distiller_service->ViewUrl( |
135 view_request_delegate, distiller_page.Pass(), last_committed_url); | 135 view_request_delegate, distiller_page.Pass(), last_committed_url); |
136 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); | 136 view_request_delegate->TakeViewerHandle(viewer_handle.Pass()); |
(...skipping 17 matching lines...) Expand all Loading... | |
154 // StartNavigationToDistillerViewer must come before swapping the tab contents | 154 // StartNavigationToDistillerViewer must come before swapping the tab contents |
155 // 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 |
156 // difficult to distinguish between the intermediate reload and a user hitting | 156 // difficult to distinguish between the intermediate reload and a user hitting |
157 // the back button. | 157 // the back button. |
158 StartNavigationToDistillerViewer(new_web_contents, | 158 StartNavigationToDistillerViewer(new_web_contents, |
159 old_web_contents->GetLastCommittedURL()); | 159 old_web_contents->GetLastCommittedURL()); |
160 | 160 |
161 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( | 161 CoreTabHelper::FromWebContents(old_web_contents)->delegate()->SwapTabContents( |
162 old_web_contents, new_web_contents, false, false); | 162 old_web_contents, new_web_contents, false, false); |
163 | 163 |
164 MaybeStartDistillation(old_web_contents); | 164 MaybeStartDistillation(old_web_contents, true); |
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 MaybeStartDistillation(source_web_contents, false); | |
173 StartNavigationToDistillerViewer(destination_web_contents, | |
174 source_web_contents->GetLastCommittedURL()); | |
175 } | |
OLD | NEW |