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

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

Issue 2754803003: Reading List iOS: Handle multiple pages. (Closed)
Patch Set: rebase Created 3 years, 9 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
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/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 " document.head.appendChild(s);" 48 " document.head.appendChild(s);"
49 "})()"; 49 "})()";
50 } // namespace 50 } // namespace
51 51
52 namespace reading_list { 52 namespace reading_list {
53 53
54 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {} 54 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {}
55 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {} 55 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {}
56 56
57 ReadingListDistillerPage::ReadingListDistillerPage( 57 ReadingListDistillerPage::ReadingListDistillerPage(
58 const GURL& url,
58 web::BrowserState* browser_state, 59 web::BrowserState* browser_state,
59 FaviconWebStateDispatcher* web_state_dispatcher, 60 FaviconWebStateDispatcher* web_state_dispatcher,
60 ReadingListDistillerPageDelegate* delegate) 61 ReadingListDistillerPageDelegate* delegate)
61 : dom_distiller::DistillerPageIOS(browser_state), 62 : dom_distiller::DistillerPageIOS(browser_state),
63 original_url_(url),
62 web_state_dispatcher_(web_state_dispatcher), 64 web_state_dispatcher_(web_state_dispatcher),
63 delegate_(delegate), 65 delegate_(delegate),
64 delayed_task_id_(0), 66 delayed_task_id_(0),
65 weak_ptr_factory_(this) { 67 weak_ptr_factory_(this) {
66 DCHECK(delegate); 68 DCHECK(delegate);
67 } 69 }
68 70
69 ReadingListDistillerPage::~ReadingListDistillerPage() {} 71 ReadingListDistillerPage::~ReadingListDistillerPage() {}
70 72
71 void ReadingListDistillerPage::DistillPageImpl(const GURL& url, 73 void ReadingListDistillerPage::DistillPageImpl(const GURL& url,
72 const std::string& script) { 74 const std::string& script) {
73 std::unique_ptr<web::WebState> old_web_state = DetachWebState(); 75 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
74 if (old_web_state) { 76 if (old_web_state) {
75 web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); 77 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
76 } 78 }
77 std::unique_ptr<web::WebState> new_web_state = 79 std::unique_ptr<web::WebState> new_web_state =
78 web_state_dispatcher_->RequestWebState(); 80 web_state_dispatcher_->RequestWebState();
79 AttachWebState(std::move(new_web_state)); 81 AttachWebState(std::move(new_web_state));
80 original_url_ = url; 82
81 delayed_task_id_++; 83 delayed_task_id_++;
84 distilling_main_page_ = url == original_url_;
82 FetchFavicon(url); 85 FetchFavicon(url);
83 86
84 DistillerPageIOS::DistillPageImpl(url, script); 87 DistillerPageIOS::DistillPageImpl(url, script);
85 88
86 // WKWebView sets the document.hidden property to true and the 89 // WKWebView sets the document.hidden property to true and the
87 // document.visibilityState to prerender if the page is not added to a view 90 // document.visibilityState to prerender if the page is not added to a view
88 // hierarchy. Some pages may not render their content in these conditions. 91 // hierarchy. Some pages may not render their content in these conditions.
89 // Add the view and move it out of the screen far in the top left corner of 92 // Add the view and move it out of the screen far in the top left corner of
90 // the coordinate space. 93 // the coordinate space.
91 CGRect frame = [[[UIApplication sharedApplication] keyWindow] frame]; 94 CGRect frame = [[[UIApplication sharedApplication] keyWindow] frame];
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 149 }
147 return true; 150 return true;
148 } 151 }
149 152
150 void ReadingListDistillerPage::OnLoadURLDone( 153 void ReadingListDistillerPage::OnLoadURLDone(
151 web::PageLoadCompletionStatus load_completion_status) { 154 web::PageLoadCompletionStatus load_completion_status) {
152 if (!IsLoadingSuccess(load_completion_status)) { 155 if (!IsLoadingSuccess(load_completion_status)) {
153 DistillerPageIOS::OnLoadURLDone(load_completion_status); 156 DistillerPageIOS::OnLoadURLDone(load_completion_status);
154 return; 157 return;
155 } 158 }
156 delegate_->DistilledPageHasMimeType(original_url_, 159 if (distilling_main_page_) {
157 CurrentWebState()->GetContentsMimeType()); 160 delegate_->DistilledPageHasMimeType(
161 original_url_, CurrentWebState()->GetContentsMimeType());
162 }
158 if (!CurrentWebState()->ContentIsHTML()) { 163 if (!CurrentWebState()->ContentIsHTML()) {
159 // If content is not HTML, distillation will fail immediatly. 164 // If content is not HTML, distillation will fail immediatly.
160 // Call the handler to make sure cleaning methods are called correctly. 165 // Call the handler to make sure cleaning methods are called correctly.
161 // There is no need to wait for rendering either. 166 // There is no need to wait for rendering either.
162 DistillerPageIOS::OnLoadURLDone(load_completion_status); 167 DistillerPageIOS::OnLoadURLDone(load_completion_status);
163 return; 168 return;
164 } 169 }
165 FetchFavicon(CurrentWebState()->GetVisibleURL()); 170 FetchFavicon(CurrentWebState()->GetVisibleURL());
166 171
167 // Page is loaded but rendering may not be done yet. Give a delay to the page. 172 // Page is loaded but rendering may not be done yet. Give a delay to the page.
(...skipping 30 matching lines...) Expand all
198 void ReadingListDistillerPage::ContinuePageDistillation() { 203 void ReadingListDistillerPage::ContinuePageDistillation() {
199 if (!CurrentWebState()) { 204 if (!CurrentWebState()) {
200 // Something interrupted the distillation. 205 // Something interrupted the distillation.
201 // Abort here. 206 // Abort here.
202 return; 207 return;
203 } 208 }
204 // The page is ready to be distilled. 209 // The page is ready to be distilled.
205 // If the visible URL is not the original URL, notify the caller that URL 210 // If the visible URL is not the original URL, notify the caller that URL
206 // changed. 211 // changed.
207 GURL redirected_url = CurrentWebState()->GetVisibleURL(); 212 GURL redirected_url = CurrentWebState()->GetVisibleURL();
208 if (redirected_url != original_url_ && delegate_) { 213 if (redirected_url != original_url_ && delegate_ && distilling_main_page_) {
209 delegate_->DistilledPageRedirectedToURL(original_url_, redirected_url); 214 delegate_->DistilledPageRedirectedToURL(original_url_, redirected_url);
210 } 215 }
211 DistillerPageIOS::OnLoadURLDone(web::PageLoadCompletionStatus::SUCCESS); 216 DistillerPageIOS::OnLoadURLDone(web::PageLoadCompletionStatus::SUCCESS);
212 } 217 }
213 218
214 bool ReadingListDistillerPage::IsGoogleCachedAMPPage() { 219 bool ReadingListDistillerPage::IsGoogleCachedAMPPage() {
215 // All google AMP pages have URL in the form "https://google_domain/amp/..." 220 // All google AMP pages have URL in the form "https://google_domain/amp/..."
216 // and a valid certificate. 221 // and a valid certificate.
217 // This method checks that this is strictly the case. 222 // This method checks that this is strictly the case.
218 const GURL& url = CurrentWebState()->GetLastCommittedURL(); 223 const GURL& url = CurrentWebState()->GetLastCommittedURL();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 [CurrentWebState()->GetJSInjectionReceiver() 298 [CurrentWebState()->GetJSInjectionReceiver()
294 executeJavaScript:@(kWikipediaWorkaround) 299 executeJavaScript:@(kWikipediaWorkaround)
295 completionHandler:^(id result, NSError* error) { 300 completionHandler:^(id result, NSError* error) {
296 if (weak_this) { 301 if (weak_this) {
297 weak_this->ContinuePageDistillation(); 302 weak_this->ContinuePageDistillation();
298 } 303 }
299 }]; 304 }];
300 } 305 }
301 306
302 } // namespace reading_list 307 } // namespace reading_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698