Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_distiller_page.mm

Issue 2695313004: [iOS Reading List] Add distilling WKWebView to the view hierarchy. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Some pages require that the WKWebView is in the view hierarchy to be
marq (ping after 24h) 2017/02/16 14:28:18 I don't suppose there's any way to determine which
Olivier 2017/02/16 14:43:41 I don't think we can. But we can do it only on sec
wychen 2017/02/16 16:38:59 You mean if it distills nothing, then distill it a
Olivier 2017/02/16 20:02:27 We always try multiple time to distill as some net
wychen 2017/02/17 00:59:55 Makes sense. Thanks!
77 // rendered.
78 // Add the view and move it out of the screen.
79 CGRect frame = [[[UIApplication sharedApplication] keyWindow] frame];
80 frame.origin.x = 2 * std::max(frame.size.width, frame.size.height);
stkhapugin 2017/02/16 12:53:59 2 can be too small for iPad multitasking: if you s
Olivier 2017/02/16 13:04:18 I don't know if it prerendering is still done that
marq (ping after 24h) 2017/02/16 14:28:18 It might be safer to position the offscreen view i
Olivier 2017/02/16 14:43:41 Done.
81 [CurrentWebState()->GetView() setFrame:frame];
marq (ping after 24h) 2017/02/16 14:28:18 DCHECK that the webstate's view doesn't already ha
Olivier 2017/02/16 14:43:41 Done.
82 [[[UIApplication sharedApplication] keyWindow]
83 addSubview:CurrentWebState()->GetView()];
marq (ping after 24h) 2017/02/16 14:28:18 Maybe insert at index 0, so it's behind everything
Olivier 2017/02/16 14:43:40 Done.
75 } 84 }
76 85
77 void ReadingListDistillerPage::FetchFavicon(const GURL& page_url) { 86 void ReadingListDistillerPage::FetchFavicon(const GURL& page_url) {
78 if (!CurrentWebState() || !page_url.is_valid()) { 87 if (!CurrentWebState() || !page_url.is_valid()) {
79 return; 88 return;
80 } 89 }
81 favicon::WebFaviconDriver* favicon_driver = 90 favicon::WebFaviconDriver* favicon_driver =
82 favicon::WebFaviconDriver::FromWebState(CurrentWebState()); 91 favicon::WebFaviconDriver::FromWebState(CurrentWebState());
83 DCHECK(favicon_driver); 92 DCHECK(favicon_driver);
84 favicon_driver->FetchFavicon(page_url); 93 favicon_driver->FetchFavicon(page_url);
85 } 94 }
86 95
87 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, 96 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url,
88 const base::Value* value) { 97 const base::Value* value) {
89 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); 98 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
90 if (old_web_state) { 99 if (old_web_state) {
100 [old_web_state->GetView() removeFromSuperview];
91 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); 101 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
92 } 102 }
93 DistillerPageIOS::OnDistillationDone(page_url, value); 103 DistillerPageIOS::OnDistillationDone(page_url, value);
94 } 104 }
95 105
96 bool ReadingListDistillerPage::IsLoadingSuccess( 106 bool ReadingListDistillerPage::IsLoadingSuccess(
97 web::PageLoadCompletionStatus load_completion_status) { 107 web::PageLoadCompletionStatus load_completion_status) {
98 if (load_completion_status != web::PageLoadCompletionStatus::SUCCESS) { 108 if (load_completion_status != web::PageLoadCompletionStatus::SUCCESS) {
99 return false; 109 return false;
100 } 110 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!new_gurl.is_valid()) { 237 if (!new_gurl.is_valid()) {
228 return false; 238 return false;
229 } 239 }
230 FetchFavicon(new_gurl); 240 FetchFavicon(new_gurl);
231 web::NavigationManager::WebLoadParams params(new_gurl); 241 web::NavigationManager::WebLoadParams params(new_gurl);
232 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); 242 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params);
233 return true; 243 return true;
234 } 244 }
235 245
236 } // namespace reading_list 246 } // namespace reading_list
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698