| 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 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DISTILLER_PAGE_H_ | 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DISTILLER_PAGE_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DISTILLER_PAGE_H_ | 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DISTILLER_PAGE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/dom_distiller/ios/distiller_page_ios.h" | 12 #include "components/dom_distiller/ios/distiller_page_ios.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace web { | 15 namespace web { |
| 16 class BrowserState; | 16 class BrowserState; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace reading_list { | 19 namespace reading_list { |
| 20 | 20 |
| 21 class FaviconWebStateDispatcher; | 21 class FaviconWebStateDispatcher; |
| 22 | 22 |
| 23 // An DistillerPageIOS that will retain WebState to allow favicon download and | 23 // An DistillerPageIOS that will retain WebState to allow favicon download and |
| 24 // and add a 2 seconds delay between loading and distillation. | 24 // and add a 2 seconds delay between loading and distillation. |
| 25 class ReadingListDistillerPage : public dom_distiller::DistillerPageIOS { | 25 class ReadingListDistillerPage : public dom_distiller::DistillerPageIOS { |
| 26 public: | 26 public: |
| 27 typedef base::Callback<void(const GURL&, const GURL&)> RedirectionCallback; |
| 28 |
| 27 explicit ReadingListDistillerPage( | 29 explicit ReadingListDistillerPage( |
| 28 web::BrowserState* browser_state, | 30 web::BrowserState* browser_state, |
| 29 FaviconWebStateDispatcher* web_state_dispatcher); | 31 FaviconWebStateDispatcher* web_state_dispatcher); |
| 30 ~ReadingListDistillerPage() override; | 32 ~ReadingListDistillerPage() override; |
| 31 | 33 |
| 34 // Sets a callback that will be called just before distillation happen with |
| 35 // the URL of the page that will effectively be distilled. |
| 36 void SetRedirectionCallback(RedirectionCallback redirection_callback); |
| 37 |
| 32 protected: | 38 protected: |
| 33 void DistillPageImpl(const GURL& url, const std::string& script) override; | 39 void DistillPageImpl(const GURL& url, const std::string& script) override; |
| 34 void OnDistillationDone(const GURL& page_url, | 40 void OnDistillationDone(const GURL& page_url, |
| 35 const base::Value* value) override; | 41 const base::Value* value) override; |
| 36 void OnLoadURLDone( | 42 void OnLoadURLDone( |
| 37 web::PageLoadCompletionStatus load_completion_status) override; | 43 web::PageLoadCompletionStatus load_completion_status) override; |
| 38 | 44 |
| 39 private: | 45 private: |
| 40 // Returns wether there is the loading has no error and if the distillation | 46 // Returns wether there is the loading has no error and if the distillation |
| 41 // can continue. | 47 // can continue. |
| 42 bool IsLoadingSuccess(web::PageLoadCompletionStatus load_completion_status); | 48 bool IsLoadingSuccess(web::PageLoadCompletionStatus load_completion_status); |
| 43 // Work around the fact that articles opened from Google Search page and | 49 // Work around the fact that articles opened from Google Search page and |
| 44 // Google News are presented in an iframe. This method detects if the current | 50 // Google News are presented in an iframe. This method detects if the current |
| 45 // page is a Google AMP and navigate to the iframe in that case. | 51 // page is a Google AMP and navigate to the iframe in that case. |
| 46 // Returns whether the current page is a Google AMP page. | 52 // Returns whether the current page is a Google AMP page. |
| 47 // IsGoogleCachedAMPPage will determine if the current page is a Google AMP | 53 // IsGoogleCachedAMPPage will determine if the current page is a Google AMP |
| 48 // page. | 54 // page. |
| 49 bool IsGoogleCachedAMPPage(); | 55 bool IsGoogleCachedAMPPage(); |
| 50 // HandleGoogleCachedAMPPage will navigate to the iframe containing the actual | 56 // HandleGoogleCachedAMPPage will navigate to the iframe containing the actual |
| 51 // article page. | 57 // article page. |
| 52 void HandleGoogleCachedAMPPage(); | 58 void HandleGoogleCachedAMPPage(); |
| 53 // Handles the JavaScript response. If the URL of the iframe is returned, | 59 // Handles the JavaScript response. If the URL of the iframe is returned, |
| 54 // triggers a navigation to it. Stop distillation of the page there as the new | 60 // triggers a navigation to it. Stop distillation of the page there as the new |
| 55 // load will trigger a new distillation. | 61 // load will trigger a new distillation. |
| 56 bool HandleGoogleCachedAMPPageJavaScriptResult(id result, NSError* error); | 62 bool HandleGoogleCachedAMPPageJavaScriptResult(id result, id error); |
| 57 | 63 |
| 58 // Waits a delay then calls DelayedOnLoadURLDone. | 64 // Waits a delay then calls DelayedOnLoadURLDone. |
| 59 void WaitForPageLoadCompletion(); | 65 void WaitForPageLoadCompletion(); |
| 60 | 66 |
| 61 // Continues distillation by calling superclass |OnLoadURLDone|. | 67 // Continues distillation by calling superclass |OnLoadURLDone|. |
| 62 void DelayedOnLoadURLDone(); | 68 void DelayedOnLoadURLDone(); |
| 63 | 69 |
| 70 RedirectionCallback redirection_callback_; |
| 71 GURL original_url_; |
| 72 |
| 64 FaviconWebStateDispatcher* web_state_dispatcher_; | 73 FaviconWebStateDispatcher* web_state_dispatcher_; |
| 65 base::WeakPtrFactory<ReadingListDistillerPage> weak_ptr_factory_; | 74 base::WeakPtrFactory<ReadingListDistillerPage> weak_ptr_factory_; |
| 66 }; | 75 }; |
| 67 | 76 |
| 68 } // namespace reading_list | 77 } // namespace reading_list |
| 69 | 78 |
| 70 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DISTILLER_PAGE_H_ | 79 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DISTILLER_PAGE_H_ |
| OLD | NEW |