| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CORE_DISTILLER_PAGE_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace dom_distiller { | 14 namespace dom_distiller { |
| 15 | 15 |
| 16 // Injects JavaScript into a page, and uses it to extract and return long-form | 16 // Injects JavaScript into a page, and uses it to extract and return long-form |
| 17 // content. The class can be reused to load and distill multiple pages, | 17 // content. The class can be reused to load and distill multiple pages, |
| 18 // following the state transitions described along with the class's states. | 18 // following the state transitions described along with the class's states. |
| 19 class DistillerPage { | 19 class DistillerPage { |
| 20 public: | 20 public: |
| 21 class Delegate { | 21 class Delegate { |
| 22 public: | 22 public: |
| 23 virtual ~Delegate() {} | 23 virtual ~Delegate() {} |
| 24 virtual void OnLoadURLDone() {} | 24 virtual void OnLoadURLDone() {} |
| 25 virtual void OnExecuteJavaScriptDone(const base::Value* value) {} | 25 virtual void OnExecuteJavaScriptDone(const GURL& page_url, |
| 26 const base::Value* value) {} |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 explicit DistillerPage(Delegate* delegate); | 29 explicit DistillerPage(Delegate* delegate); |
| 29 | 30 |
| 30 virtual ~DistillerPage(); | 31 virtual ~DistillerPage(); |
| 31 | 32 |
| 32 | 33 |
| 33 // Initializes a |DistillerPage|. It must be called before any | 34 // Initializes a |DistillerPage|. It must be called before any |
| 34 // other functions, and must only be called once. | 35 // other functions, and must only be called once. |
| 35 void Init(); | 36 void Init(); |
| 36 | 37 |
| 37 // Loads a URL. |OnLoadURLDone| is called when the load completes or fails. | 38 // Loads a URL. |OnLoadURLDone| is called when the load completes or fails. |
| 38 // May be called when the distiller is idle or a page is available. | 39 // May be called when the distiller is idle or a page is available. |
| 39 void LoadURL(const GURL& url); | 40 void LoadURL(const GURL& url); |
| 40 virtual void OnLoadURLDone(); | 41 virtual void OnLoadURLDone(); |
| 41 virtual void OnLoadURLFailed(); | 42 virtual void OnLoadURLFailed(); |
| 42 | 43 |
| 43 // Injects and executes JavaScript in the context of a loaded page. |LoadURL| | 44 // Injects and executes JavaScript in the context of a loaded page. |LoadURL| |
| 44 // must complete before this function is called. May be called only when | 45 // must complete before this function is called. May be called only when |
| 45 // a page is available. | 46 // a page is available. |
| 46 void ExecuteJavaScript(const std::string& script); | 47 void ExecuteJavaScript(const std::string& script); |
| 47 | 48 |
| 48 // Called when the JavaScript execution completes. |value| contains data | 49 // Called when the JavaScript execution completes. |page_url| is the url of |
| 49 // returned by the script. | 50 // the distilled page. |value| contains data returned by the script. |
| 50 virtual void OnExecuteJavaScriptDone(const base::Value* value); | 51 virtual void OnExecuteJavaScriptDone(const GURL& page_url, |
| 52 const base::Value* value); |
| 51 | 53 |
| 52 protected: | 54 protected: |
| 53 enum State { | 55 enum State { |
| 54 // No context has yet been set in which to load or distill a page. | 56 // No context has yet been set in which to load or distill a page. |
| 55 NO_CONTEXT, | 57 NO_CONTEXT, |
| 56 // The page distiller has been initialized and is idle. | 58 // The page distiller has been initialized and is idle. |
| 57 IDLE, | 59 IDLE, |
| 58 // A page is currently loading. | 60 // A page is currently loading. |
| 59 LOADING_PAGE, | 61 LOADING_PAGE, |
| 60 // A page has loaded within the specified context. | 62 // A page has loaded within the specified context. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 public: | 95 public: |
| 94 virtual ~DistillerPageFactory(); | 96 virtual ~DistillerPageFactory(); |
| 95 | 97 |
| 96 virtual scoped_ptr<DistillerPage> CreateDistillerPage( | 98 virtual scoped_ptr<DistillerPage> CreateDistillerPage( |
| 97 DistillerPage::Delegate* delegate) const = 0; | 99 DistillerPage::Delegate* delegate) const = 0; |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 } // namespace dom_distiller | 102 } // namespace dom_distiller |
| 101 | 103 |
| 102 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ | 104 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_PAGE_H_ |
| OLD | NEW |