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

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

Issue 2717483003: [Reading List] Check web state after the distillation delay. (Closed)
Patch Set: add task_id 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 | « ios/chrome/browser/reading_list/reading_list_distiller_page.h ('k') | 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {} 46 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {}
47 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {} 47 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {}
48 48
49 ReadingListDistillerPage::ReadingListDistillerPage( 49 ReadingListDistillerPage::ReadingListDistillerPage(
50 web::BrowserState* browser_state, 50 web::BrowserState* browser_state,
51 FaviconWebStateDispatcher* web_state_dispatcher, 51 FaviconWebStateDispatcher* web_state_dispatcher,
52 ReadingListDistillerPageDelegate* delegate) 52 ReadingListDistillerPageDelegate* delegate)
53 : dom_distiller::DistillerPageIOS(browser_state), 53 : dom_distiller::DistillerPageIOS(browser_state),
54 web_state_dispatcher_(web_state_dispatcher), 54 web_state_dispatcher_(web_state_dispatcher),
55 delegate_(delegate), 55 delegate_(delegate),
56 delayed_task_id_(0),
56 weak_ptr_factory_(this) { 57 weak_ptr_factory_(this) {
57 DCHECK(delegate); 58 DCHECK(delegate);
58 } 59 }
59 60
60 ReadingListDistillerPage::~ReadingListDistillerPage() {} 61 ReadingListDistillerPage::~ReadingListDistillerPage() {}
61 62
62 void ReadingListDistillerPage::DistillPageImpl(const GURL& url, 63 void ReadingListDistillerPage::DistillPageImpl(const GURL& url,
63 const std::string& script) { 64 const std::string& script) {
64 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); 65 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
65 if (old_web_state) { 66 if (old_web_state) {
66 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); 67 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
67 } 68 }
68 std::unique_ptr<web::WebState> new_web_state = 69 std::unique_ptr<web::WebState> new_web_state =
69 web_state_dispatcher_->RequestWebState(); 70 web_state_dispatcher_->RequestWebState();
70 AttachWebState(std::move(new_web_state)); 71 AttachWebState(std::move(new_web_state));
71 original_url_ = url; 72 original_url_ = url;
73 delayed_task_id_++;
72 FetchFavicon(url); 74 FetchFavicon(url);
73 75
74 DistillerPageIOS::DistillPageImpl(url, script); 76 DistillerPageIOS::DistillPageImpl(url, script);
75 77
76 // WKWebView sets the document.hidden property to true and the 78 // WKWebView sets the document.hidden property to true and the
77 // document.visibilityState to prerender if the page is not added to a view 79 // 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. 80 // 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 81 // Add the view and move it out of the screen far in the top left corner of
80 // the coordinate space. 82 // the coordinate space.
81 CGRect frame = [[[UIApplication sharedApplication] keyWindow] frame]; 83 CGRect frame = [[[UIApplication sharedApplication] keyWindow] frame];
(...skipping 16 matching lines...) Expand all
98 favicon_driver->FetchFavicon(page_url); 100 favicon_driver->FetchFavicon(page_url);
99 } 101 }
100 102
101 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, 103 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url,
102 const base::Value* value) { 104 const base::Value* value) {
103 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); 105 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
104 if (old_web_state) { 106 if (old_web_state) {
105 [old_web_state->GetView() removeFromSuperview]; 107 [old_web_state->GetView() removeFromSuperview];
106 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); 108 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
107 } 109 }
110 delayed_task_id_++;
108 DistillerPageIOS::OnDistillationDone(page_url, value); 111 DistillerPageIOS::OnDistillationDone(page_url, value);
109 } 112 }
110 113
111 bool ReadingListDistillerPage::IsLoadingSuccess( 114 bool ReadingListDistillerPage::IsLoadingSuccess(
112 web::PageLoadCompletionStatus load_completion_status) { 115 web::PageLoadCompletionStatus load_completion_status) {
113 if (load_completion_status != web::PageLoadCompletionStatus::SUCCESS) { 116 if (load_completion_status != web::PageLoadCompletionStatus::SUCCESS) {
114 return false; 117 return false;
115 } 118 }
116 if (!CurrentWebState() || !CurrentWebState()->GetNavigationManager() || 119 if (!CurrentWebState() || !CurrentWebState()->GetNavigationManager() ||
117 !CurrentWebState()->GetNavigationManager()->GetLastCommittedItem()) { 120 !CurrentWebState()->GetNavigationManager()->GetLastCommittedItem()) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 DistillerPageIOS::OnLoadURLDone(load_completion_status); 154 DistillerPageIOS::OnLoadURLDone(load_completion_status);
152 return; 155 return;
153 } 156 }
154 FetchFavicon(CurrentWebState()->GetVisibleURL()); 157 FetchFavicon(CurrentWebState()->GetVisibleURL());
155 158
156 // Page is loaded but rendering may not be done yet. Give a delay to the page. 159 // Page is loaded but rendering may not be done yet. Give a delay to the page.
157 base::WeakPtr<ReadingListDistillerPage> weak_this = 160 base::WeakPtr<ReadingListDistillerPage> weak_this =
158 weak_ptr_factory_.GetWeakPtr(); 161 weak_ptr_factory_.GetWeakPtr();
159 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 162 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
160 FROM_HERE, 163 FROM_HERE,
161 base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone, weak_this), 164 base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone, weak_this,
165 delayed_task_id_),
162 base::TimeDelta::FromSeconds(kPageLoadDelayInSeconds)); 166 base::TimeDelta::FromSeconds(kPageLoadDelayInSeconds));
163 } 167 }
164 168
165 void ReadingListDistillerPage::DelayedOnLoadURLDone() { 169 void ReadingListDistillerPage::DelayedOnLoadURLDone(int delayed_task_id) {
170 if (!CurrentWebState() || delayed_task_id != delayed_task_id_) {
171 // Something interrupted the distillation.
172 // Abort here.
173 return;
174 }
166 if (IsGoogleCachedAMPPage()) { 175 if (IsGoogleCachedAMPPage()) {
167 // Workaround for Google AMP pages. 176 // Workaround for Google AMP pages.
168 HandleGoogleCachedAMPPage(); 177 HandleGoogleCachedAMPPage();
169 } else { 178 } else {
170 ContinuePageDistillation(); 179 ContinuePageDistillation();
171 } 180 }
172 } 181 }
173 182
174 void ReadingListDistillerPage::ContinuePageDistillation() { 183 void ReadingListDistillerPage::ContinuePageDistillation() {
175 // The page is ready to be distilled. 184 // The page is ready to be distilled.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (!new_gurl.is_valid()) { 251 if (!new_gurl.is_valid()) {
243 return false; 252 return false;
244 } 253 }
245 FetchFavicon(new_gurl); 254 FetchFavicon(new_gurl);
246 web::NavigationManager::WebLoadParams params(new_gurl); 255 web::NavigationManager::WebLoadParams params(new_gurl);
247 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); 256 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params);
248 return true; 257 return true;
249 } 258 }
250 259
251 } // namespace reading_list 260 } // namespace reading_list
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_distiller_page.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698