| 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/favicon_web_state_dispatcher.h" | |
| 14 #include "ios/web/public/web_state/web_state_observer.h" | 13 #include "ios/web/public/web_state/web_state_observer.h" |
| 15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 16 | 15 |
| 17 namespace dom_distiller { | 16 namespace dom_distiller { |
| 18 | 17 |
| 19 class DistillerWebStateObserver; | 18 class DistillerWebStateObserver; |
| 20 | 19 |
| 21 // Loads URLs and injects JavaScript into a page, extracting the distilled page | 20 // Loads URLs and injects JavaScript into a page, extracting the distilled page |
| 22 // content. | 21 // content. |
| 23 class DistillerPageIOS : public DistillerPage { | 22 class DistillerPageIOS : public DistillerPage { |
| 24 public: | 23 public: |
| 25 explicit DistillerPageIOS(FaviconWebStateDispatcher* web_state_dispatcher); | 24 explicit DistillerPageIOS(std::unique_ptr<web::WebState> web_state); |
| 26 ~DistillerPageIOS() override; | 25 ~DistillerPageIOS() override; |
| 27 | 26 |
| 28 protected: | 27 protected: |
| 29 bool StringifyOutput() override; | 28 bool StringifyOutput() override; |
| 30 void DistillPageImpl(const GURL& url, const std::string& script) override; | 29 void DistillPageImpl(const GURL& url, const std::string& script) override; |
| 31 | 30 |
| 31 std::unique_ptr<web::WebState> ReplaceWebState( |
| 32 std::unique_ptr<web::WebState> web_state); |
| 33 |
| 34 // Called by |web_state_observer_| once the page has finished loading. |
| 35 virtual void OnLoadURLDone( |
| 36 web::PageLoadCompletionStatus load_completion_status); |
| 37 |
| 32 private: | 38 private: |
| 33 friend class DistillerWebStateObserver; | 39 friend class DistillerWebStateObserver; |
| 34 | |
| 35 // Called by |web_state_observer_| once the page has finished loading. | |
| 36 void OnLoadURLDone(web::PageLoadCompletionStatus load_completion_status); | |
| 37 | |
| 38 // Called once the |script_| has been evaluated on the page. | 40 // Called once the |script_| has been evaluated on the page. |
| 39 void HandleJavaScriptResult(id result); | 41 void HandleJavaScriptResult(id result); |
| 40 | 42 |
| 41 // Converts result of WKWebView script evaluation to base::Value | 43 // Converts result of WKWebView script evaluation to base::Value |
| 42 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result); | 44 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result); |
| 43 | 45 |
| 44 GURL url_; | 46 GURL url_; |
| 45 std::string script_; | 47 std::string script_; |
| 46 web::WebState* web_state_; | 48 std::unique_ptr<web::WebState> web_state_; |
| 47 FaviconWebStateDispatcher* web_state_dispatcher_; | |
| 48 std::unique_ptr<DistillerWebStateObserver> web_state_observer_; | 49 std::unique_ptr<DistillerWebStateObserver> web_state_observer_; |
| 49 base::WeakPtrFactory<DistillerPageIOS> weak_ptr_factory_; | 50 base::WeakPtrFactory<DistillerPageIOS> weak_ptr_factory_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 } // namespace dom_distiller | 53 } // namespace dom_distiller |
| 53 | 54 |
| 54 #endif // COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ | 55 #endif // COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ |
| OLD | NEW |