| 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" |
| 11 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h
" | 11 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h
" |
| 12 #include "components/dom_distiller/core/distiller_page.h" | 12 #include "components/dom_distiller/core/distiller_page.h" |
| 13 #include "components/dom_distiller/core/dom_distiller_service.h" | 13 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 14 #include "components/dom_distiller/core/task_tracker.h" | 14 #include "components/dom_distiller/core/task_tracker.h" |
| 15 #include "components/dom_distiller/core/url_constants.h" | 15 #include "components/dom_distiller/core/url_constants.h" |
| 16 #include "components/dom_distiller/core/url_utils.h" | 16 #include "components/dom_distiller/core/url_utils.h" |
| 17 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/browser/web_contents_source.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 using dom_distiller::ViewRequestDelegate; | 25 using dom_distiller::ViewRequestDelegate; |
| 25 using dom_distiller::DistilledArticleProto; | 26 using dom_distiller::DistilledArticleProto; |
| 26 using dom_distiller::ArticleDistillationUpdate; | 27 using dom_distiller::ArticleDistillationUpdate; |
| 27 using dom_distiller::ViewerHandle; | 28 using dom_distiller::ViewerHandle; |
| 28 using dom_distiller::SourcePageHandleWebContents; | 29 using dom_distiller::SourcePageHandleWebContents; |
| 29 using dom_distiller::DomDistillerService; | 30 using dom_distiller::DomDistillerService; |
| 30 using dom_distiller::DomDistillerServiceFactory; | 31 using dom_distiller::DomDistillerServiceFactory; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } // namespace | 137 } // namespace |
| 137 | 138 |
| 138 void DistillCurrentPageAndView(content::WebContents* old_web_contents) { | 139 void DistillCurrentPageAndView(content::WebContents* old_web_contents) { |
| 139 DCHECK(old_web_contents); | 140 DCHECK(old_web_contents); |
| 140 // Create new WebContents. | 141 // Create new WebContents. |
| 141 content::WebContents::CreateParams create_params( | 142 content::WebContents::CreateParams create_params( |
| 142 old_web_contents->GetBrowserContext()); | 143 old_web_contents->GetBrowserContext()); |
| 143 content::WebContents* new_web_contents = | 144 content::WebContents* new_web_contents = |
| 144 content::WebContents::Create(create_params); | 145 content::WebContents::Create(create_params); |
| 145 DCHECK(new_web_contents); | 146 DCHECK(new_web_contents); |
| 147 WebContentsSource::CreateForWebContentsAndLocation(new_web_contents, |
| 148 FROM_HERE); |
| 146 | 149 |
| 147 // Copy all navigation state from the old WebContents to the new one. | 150 // Copy all navigation state from the old WebContents to the new one. |
| 148 new_web_contents->GetController().CopyStateFrom( | 151 new_web_contents->GetController().CopyStateFrom( |
| 149 old_web_contents->GetController()); | 152 old_web_contents->GetController()); |
| 150 | 153 |
| 151 // StartNavigationToDistillerViewer must come before swapping the tab contents | 154 // StartNavigationToDistillerViewer must come before swapping the tab contents |
| 152 // 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 |
| 153 // difficult to distinguish between the intermediate reload and a user hitting | 156 // difficult to distinguish between the intermediate reload and a user hitting |
| 154 // the back button. | 157 // the back button. |
| 155 StartNavigationToDistillerViewer(new_web_contents, | 158 StartNavigationToDistillerViewer(new_web_contents, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 169 DCHECK(source_web_contents); | 172 DCHECK(source_web_contents); |
| 170 DCHECK(destination_web_contents); | 173 DCHECK(destination_web_contents); |
| 171 | 174 |
| 172 scoped_ptr<SourcePageHandleWebContents> source_page_handle( | 175 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
| 173 new SourcePageHandleWebContents(source_web_contents, false)); | 176 new SourcePageHandleWebContents(source_web_contents, false)); |
| 174 | 177 |
| 175 MaybeStartDistillation(source_page_handle.Pass()); | 178 MaybeStartDistillation(source_page_handle.Pass()); |
| 176 StartNavigationToDistillerViewer(destination_web_contents, | 179 StartNavigationToDistillerViewer(destination_web_contents, |
| 177 source_web_contents->GetLastCommittedURL()); | 180 source_web_contents->GetLastCommittedURL()); |
| 178 } | 181 } |
| OLD | NEW |