| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (old_web_state) { | 65 if (old_web_state) { |
| 66 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); | 66 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| 67 } | 67 } |
| 68 std::unique_ptr<web::WebState> new_web_state = | 68 std::unique_ptr<web::WebState> new_web_state = |
| 69 web_state_dispatcher_->RequestWebState(); | 69 web_state_dispatcher_->RequestWebState(); |
| 70 AttachWebState(std::move(new_web_state)); | 70 AttachWebState(std::move(new_web_state)); |
| 71 original_url_ = url; | 71 original_url_ = url; |
| 72 FetchFavicon(url); | 72 FetchFavicon(url); |
| 73 | 73 |
| 74 DistillerPageIOS::DistillPageImpl(url, script); | 74 DistillerPageIOS::DistillPageImpl(url, script); |
| 75 |
| 76 // WKWebView sets the document.hidden property to true and the |
| 77 // document.visibilityState to prerender if the page is not added to a view |
| 78 // hierarchy. Some pages may not render their content in these conditions. |
| 79 // Add the view and move it out of the screen far in the top left corner of |
| 80 // the coordinate space. |
| 81 CGRect frame = [[[UIApplication sharedApplication] keyWindow] frame]; |
| 82 frame.origin.x = -5 * std::max(frame.size.width, frame.size.height); |
| 83 frame.origin.y = frame.origin.x; |
| 84 DCHECK(![CurrentWebState()->GetView() superview]); |
| 85 [CurrentWebState()->GetView() setFrame:frame]; |
| 86 [[[UIApplication sharedApplication] keyWindow] |
| 87 insertSubview:CurrentWebState()->GetView() |
| 88 atIndex:0]; |
| 75 } | 89 } |
| 76 | 90 |
| 77 void ReadingListDistillerPage::FetchFavicon(const GURL& page_url) { | 91 void ReadingListDistillerPage::FetchFavicon(const GURL& page_url) { |
| 78 if (!CurrentWebState() || !page_url.is_valid()) { | 92 if (!CurrentWebState() || !page_url.is_valid()) { |
| 79 return; | 93 return; |
| 80 } | 94 } |
| 81 favicon::WebFaviconDriver* favicon_driver = | 95 favicon::WebFaviconDriver* favicon_driver = |
| 82 favicon::WebFaviconDriver::FromWebState(CurrentWebState()); | 96 favicon::WebFaviconDriver::FromWebState(CurrentWebState()); |
| 83 DCHECK(favicon_driver); | 97 DCHECK(favicon_driver); |
| 84 favicon_driver->FetchFavicon(page_url); | 98 favicon_driver->FetchFavicon(page_url); |
| 85 } | 99 } |
| 86 | 100 |
| 87 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, | 101 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, |
| 88 const base::Value* value) { | 102 const base::Value* value) { |
| 89 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); | 103 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); |
| 90 if (old_web_state) { | 104 if (old_web_state) { |
| 105 [old_web_state->GetView() removeFromSuperview]; |
| 91 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); | 106 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| 92 } | 107 } |
| 93 DistillerPageIOS::OnDistillationDone(page_url, value); | 108 DistillerPageIOS::OnDistillationDone(page_url, value); |
| 94 } | 109 } |
| 95 | 110 |
| 96 bool ReadingListDistillerPage::IsLoadingSuccess( | 111 bool ReadingListDistillerPage::IsLoadingSuccess( |
| 97 web::PageLoadCompletionStatus load_completion_status) { | 112 web::PageLoadCompletionStatus load_completion_status) { |
| 98 if (load_completion_status != web::PageLoadCompletionStatus::SUCCESS) { | 113 if (load_completion_status != web::PageLoadCompletionStatus::SUCCESS) { |
| 99 return false; | 114 return false; |
| 100 } | 115 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (!new_gurl.is_valid()) { | 242 if (!new_gurl.is_valid()) { |
| 228 return false; | 243 return false; |
| 229 } | 244 } |
| 230 FetchFavicon(new_gurl); | 245 FetchFavicon(new_gurl); |
| 231 web::NavigationManager::WebLoadParams params(new_gurl); | 246 web::NavigationManager::WebLoadParams params(new_gurl); |
| 232 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); | 247 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); |
| 233 return true; | 248 return true; |
| 234 } | 249 } |
| 235 | 250 |
| 236 } // namespace reading_list | 251 } // namespace reading_list |
| OLD | NEW |