| 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 |
| 16 namespace web { |
| 17 class BrowserState; |
| 18 class WebState; |
| 19 } |
| 20 |
| 17 namespace dom_distiller { | 21 namespace dom_distiller { |
| 18 | 22 |
| 19 class DistillerWebStateObserver; | 23 class DistillerWebStateObserver; |
| 20 | 24 |
| 21 // Loads URLs and injects JavaScript into a page, extracting the distilled page | 25 // Loads URLs and injects JavaScript into a page, extracting the distilled page |
| 22 // content. | 26 // content. |
| 23 class DistillerPageIOS : public DistillerPage { | 27 class DistillerPageIOS : public DistillerPage { |
| 24 public: | 28 public: |
| 25 explicit DistillerPageIOS(FaviconWebStateDispatcher* web_state_dispatcher); | 29 explicit DistillerPageIOS(web::BrowserState* browser_state); |
| 26 ~DistillerPageIOS() override; | 30 ~DistillerPageIOS() override; |
| 27 | 31 |
| 28 protected: | 32 protected: |
| 29 bool StringifyOutput() override; | 33 bool StringifyOutput() override; |
| 30 void DistillPageImpl(const GURL& url, const std::string& script) override; | 34 void DistillPageImpl(const GURL& url, const std::string& script) override; |
| 31 | 35 |
| 36 // Sets the WebState that will be used for the distillation. Do not call |
| 37 // between |DistillPageImpl| and |OnDistillationDone|. |
| 38 virtual void AttachWebState(std::unique_ptr<web::WebState> web_state); |
| 39 |
| 40 // Release the WebState used for distillation. Do not call between |
| 41 // |DistillPageImpl| and |OnDistillationDone|. |
| 42 virtual std::unique_ptr<web::WebState> DetachWebState(); |
| 43 |
| 44 // Called by |web_state_observer_| once the page has finished loading. |
| 45 virtual void OnLoadURLDone( |
| 46 web::PageLoadCompletionStatus load_completion_status); |
| 47 |
| 32 private: | 48 private: |
| 33 friend class DistillerWebStateObserver; | 49 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. | 50 // Called once the |script_| has been evaluated on the page. |
| 39 void HandleJavaScriptResult(id result); | 51 void HandleJavaScriptResult(id result); |
| 40 | 52 |
| 41 // Converts result of WKWebView script evaluation to base::Value | 53 // Converts result of WKWebView script evaluation to base::Value |
| 42 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result); | 54 std::unique_ptr<base::Value> ValueResultFromScriptResult(id wk_result); |
| 43 | 55 |
| 44 GURL url_; | 56 GURL url_; |
| 45 std::string script_; | 57 std::string script_; |
| 46 web::WebState* web_state_; | 58 web::BrowserState* browser_state_; |
| 47 FaviconWebStateDispatcher* web_state_dispatcher_; | 59 std::unique_ptr<web::WebState> web_state_; |
| 48 std::unique_ptr<DistillerWebStateObserver> web_state_observer_; | 60 std::unique_ptr<DistillerWebStateObserver> web_state_observer_; |
| 49 base::WeakPtrFactory<DistillerPageIOS> weak_ptr_factory_; | 61 base::WeakPtrFactory<DistillerPageIOS> weak_ptr_factory_; |
| 50 }; | 62 }; |
| 51 | 63 |
| 52 } // namespace dom_distiller | 64 } // namespace dom_distiller |
| 53 | 65 |
| 54 #endif // COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ | 66 #endif // COMPONENTS_DOM_DISTILLER_IOS_DISTILLER_PAGE_IOS_H_ |
| OLD | NEW |