| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/browser/reading_list/reading_list_distiller_page.h" | 5 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 ReadingListDistillerPage::~ReadingListDistillerPage() {} | 47 ReadingListDistillerPage::~ReadingListDistillerPage() {} |
| 48 | 48 |
| 49 void ReadingListDistillerPage::DistillPageImpl(const GURL& url, | 49 void ReadingListDistillerPage::DistillPageImpl(const GURL& url, |
| 50 const std::string& script) { | 50 const std::string& script) { |
| 51 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); | 51 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); |
| 52 if (old_web_state) { | 52 if (old_web_state) { |
| 53 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); | 53 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| 54 } | 54 } |
| 55 std::unique_ptr<web::WebState> new_web_state = | 55 std::unique_ptr<web::WebState> new_web_state = |
| 56 web_state_dispatcher_->RequestWebState(); | 56 web_state_dispatcher_->RequestWebState(); |
| 57 if (new_web_state) { | |
| 58 favicon::WebFaviconDriver* favicon_driver = | |
| 59 favicon::WebFaviconDriver::FromWebState(new_web_state.get()); | |
| 60 favicon_driver->FetchFavicon(url); | |
| 61 } | |
| 62 AttachWebState(std::move(new_web_state)); | 57 AttachWebState(std::move(new_web_state)); |
| 63 original_url_ = url; | 58 original_url_ = url; |
| 59 FetchFavicon(url); |
| 64 | 60 |
| 65 DistillerPageIOS::DistillPageImpl(url, script); | 61 DistillerPageIOS::DistillPageImpl(url, script); |
| 66 } | 62 } |
| 67 | 63 |
| 64 void ReadingListDistillerPage::FetchFavicon(const GURL& page_url) { |
| 65 if (!CurrentWebState() || !page_url.is_valid()) { |
| 66 return; |
| 67 } |
| 68 favicon::WebFaviconDriver* favicon_driver = |
| 69 favicon::WebFaviconDriver::FromWebState(CurrentWebState()); |
| 70 DCHECK(favicon_driver); |
| 71 favicon_driver->FetchFavicon(page_url); |
| 72 } |
| 73 |
| 68 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, | 74 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, |
| 69 const base::Value* value) { | 75 const base::Value* value) { |
| 70 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); | 76 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); |
| 71 if (old_web_state) { | 77 if (old_web_state) { |
| 72 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); | 78 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| 73 } | 79 } |
| 74 DistillerPageIOS::OnDistillationDone(page_url, value); | 80 DistillerPageIOS::OnDistillationDone(page_url, value); |
| 75 } | 81 } |
| 76 | 82 |
| 77 bool ReadingListDistillerPage::IsLoadingSuccess( | 83 bool ReadingListDistillerPage::IsLoadingSuccess( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 116 } |
| 111 delegate_->DistilledPageHasMimeType(original_url_, | 117 delegate_->DistilledPageHasMimeType(original_url_, |
| 112 CurrentWebState()->GetContentsMimeType()); | 118 CurrentWebState()->GetContentsMimeType()); |
| 113 if (!CurrentWebState()->ContentIsHTML()) { | 119 if (!CurrentWebState()->ContentIsHTML()) { |
| 114 // If content is not HTML, distillation will fail immediatly. | 120 // If content is not HTML, distillation will fail immediatly. |
| 115 // Call the handler to make sure cleaning methods are called correctly. | 121 // Call the handler to make sure cleaning methods are called correctly. |
| 116 // There is no need to wait for rendering either. | 122 // There is no need to wait for rendering either. |
| 117 DistillerPageIOS::OnLoadURLDone(load_completion_status); | 123 DistillerPageIOS::OnLoadURLDone(load_completion_status); |
| 118 return; | 124 return; |
| 119 } | 125 } |
| 126 FetchFavicon(CurrentWebState()->GetVisibleURL()); |
| 127 |
| 120 // Page is loaded but rendering may not be done yet. Give a delay to the page. | 128 // Page is loaded but rendering may not be done yet. Give a delay to the page. |
| 121 base::WeakPtr<ReadingListDistillerPage> weak_this = | 129 base::WeakPtr<ReadingListDistillerPage> weak_this = |
| 122 weak_ptr_factory_.GetWeakPtr(); | 130 weak_ptr_factory_.GetWeakPtr(); |
| 123 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 131 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 124 FROM_HERE, | 132 FROM_HERE, |
| 125 base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone, weak_this), | 133 base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone, weak_this), |
| 126 base::TimeDelta::FromSeconds(kPageLoadDelayInSeconds)); | 134 base::TimeDelta::FromSeconds(kPageLoadDelayInSeconds)); |
| 127 } | 135 } |
| 128 | 136 |
| 129 void ReadingListDistillerPage::DelayedOnLoadURLDone() { | 137 void ReadingListDistillerPage::DelayedOnLoadURLDone() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 bool is_cdn_ampproject_subdomain = | 214 bool is_cdn_ampproject_subdomain = |
| 207 [[new_url host] hasSuffix:@".cdn.ampproject.org"]; | 215 [[new_url host] hasSuffix:@".cdn.ampproject.org"]; |
| 208 | 216 |
| 209 if (!is_cdn_ampproject && !is_cdn_ampproject_subdomain) { | 217 if (!is_cdn_ampproject && !is_cdn_ampproject_subdomain) { |
| 210 return false; | 218 return false; |
| 211 } | 219 } |
| 212 GURL new_gurl = net::GURLWithNSURL(new_url); | 220 GURL new_gurl = net::GURLWithNSURL(new_url); |
| 213 if (!new_gurl.is_valid()) { | 221 if (!new_gurl.is_valid()) { |
| 214 return false; | 222 return false; |
| 215 } | 223 } |
| 224 FetchFavicon(new_gurl); |
| 216 web::NavigationManager::WebLoadParams params(new_gurl); | 225 web::NavigationManager::WebLoadParams params(new_gurl); |
| 217 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); | 226 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); |
| 218 return true; | 227 return true; |
| 219 } | 228 } |
| 220 | 229 |
| 221 } // namespace reading_list | 230 } // namespace reading_list |
| OLD | NEW |