| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ | 6 #define COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_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/core/distiller_page.h" | 12 #include "components/dom_distiller/core/distiller_page.h" |
| 13 #include "components/dom_distiller/ios/web_state_pool.h" |
| 13 #include "ios/web/public/web_state/web_state_observer.h" | 14 #include "ios/web/public/web_state/web_state_observer.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace ios { | |
| 17 class WebControllerProvider; | |
| 18 } | |
| 19 | |
| 20 namespace web { | |
| 21 class BrowserState; | |
| 22 } | |
| 23 | |
| 24 namespace dom_distiller { | 17 namespace dom_distiller { |
| 25 | 18 |
| 26 class DistillerWebStateObserver; | 19 class DistillerWebStateObserver; |
| 27 | 20 |
| 28 // Loads URLs and injects JavaScript into a page, extracting the distilled page | 21 // Loads URLs and injects JavaScript into a page, extracting the distilled page |
| 29 // content. | 22 // content. |
| 30 class DistillerPageIOS : public DistillerPage { | 23 class DistillerPageIOS : public DistillerPage, WebStatePoolDelegate { |
| 31 public: | 24 public: |
| 32 explicit DistillerPageIOS(web::BrowserState* browser_state); | 25 explicit DistillerPageIOS(WebStatePool* web_state_pool); |
| 33 ~DistillerPageIOS() override; | 26 ~DistillerPageIOS() override; |
| 34 | 27 |
| 28 void OnWebStateAvailable(web::WebState* web_state) override; |
| 29 |
| 35 protected: | 30 protected: |
| 36 bool StringifyOutput() override; | 31 bool StringifyOutput() override; |
| 37 void DistillPageImpl(const GURL& url, const std::string& script) override; | 32 void DistillPageImpl(const GURL& url, const std::string& script) override; |
| 38 | 33 |
| 39 private: | 34 private: |
| 40 friend class DistillerWebStateObserver; | 35 friend class DistillerWebStateObserver; |
| 41 | 36 |
| 42 // Called by |web_state_observer_| once the page has finished loading. | 37 // Called by |web_state_observer_| once the page has finished loading. |
| 43 void OnLoadURLDone(web::PageLoadCompletionStatus load_completion_status); | 38 void OnLoadURLDone(web::PageLoadCompletionStatus load_completion_status); |
| 44 | 39 |
| 45 // Called once the |script_| has been evaluated on the page. | 40 // Called once the |script_| has been evaluated on the page. |
| 46 void HandleJavaScriptResult(id result); | 41 void HandleJavaScriptResult(id result); |
| 47 | 42 |
| 48 // Converts result of WKWebView script evaluation to base::Value | 43 // Converts result of WKWebView script evaluation to base::Value |
| 49 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result); | 44 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result); |
| 50 | 45 |
| 51 web::BrowserState* browser_state_; | |
| 52 GURL url_; | 46 GURL url_; |
| 53 std::string script_; | 47 std::string script_; |
| 54 std::unique_ptr<ios::WebControllerProvider> provider_; | 48 web::WebState* web_state_; |
| 49 WebStatePool* web_state_pool_; |
| 55 std::unique_ptr<DistillerWebStateObserver> web_state_observer_; | 50 std::unique_ptr<DistillerWebStateObserver> web_state_observer_; |
| 56 base::WeakPtrFactory<DistillerPageIOS> weak_ptr_factory_; | 51 base::WeakPtrFactory<DistillerPageIOS> weak_ptr_factory_; |
| 57 }; | 52 }; |
| 58 | 53 |
| 59 } // namespace dom_distiller | 54 } // namespace dom_distiller |
| 60 | 55 |
| 61 #endif // COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ | 56 #endif // COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ |
| OLD | NEW |