OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_DOM_DISTILLER_CONTENT_BROWSER_DISTILLIBILITY_DRIVER_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_CONTENT_BROWSER_DISTILLIBILITY_DRIVER_H_ |
| 7 |
| 8 #include "content/public/browser/web_contents_observer.h" |
| 9 #include "content/public/browser/web_contents_user_data.h" |
| 10 |
| 11 struct FrameHostMsg_ExtractFeatureResponse_Params; |
| 12 |
| 13 namespace dom_distiller { |
| 14 |
| 15 // Extract the features of a page for DOM distiller. |
| 16 typedef base::Callback<void(bool isOGArticle, |
| 17 const std::string& url, |
| 18 int numElements, |
| 19 int numAnchors, |
| 20 int numForms, |
| 21 const std::string& innerText, |
| 22 const std::string& textContent, |
| 23 const std::string& innerHTML)> |
| 24 ExtractFeatureCallback; |
| 25 |
| 26 // This is an IPC helper for determining whether a page should be distilled. |
| 27 class WebContentsDistillabilityDriver |
| 28 : public content::WebContentsObserver, |
| 29 public content::WebContentsUserData<WebContentsDistillabilityDriver> { |
| 30 public: |
| 31 ~WebContentsDistillabilityDriver() override; |
| 32 |
| 33 // content::WebContentsObserver implementation. |
| 34 bool OnMessageReceived(const IPC::Message& message, |
| 35 content::RenderFrameHost* rfh) override; |
| 36 void RenderProcessGone(base::TerminationStatus status) override; |
| 37 |
| 38 void OnExtractFeatureResponse(int id, |
| 39 FrameHostMsg_ExtractFeatureResponse_Params results); |
| 40 |
| 41 void ExtractFeatures(const ExtractFeatureCallback& callback); |
| 42 |
| 43 private: |
| 44 explicit WebContentsDistillabilityDriver(content::WebContents* web_contents); |
| 45 friend class content::WebContentsUserData<WebContentsDistillabilityDriver>; |
| 46 |
| 47 // Removes the observer and clears the WebContents member. |
| 48 void CleanUp(); |
| 49 |
| 50 int callback_id_; |
| 51 std::map<int, ExtractFeatureCallback> callbacks_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(WebContentsDistillabilityDriver); |
| 54 }; |
| 55 |
| 56 } // namespace dom_distiller |
| 57 |
| 58 #endif // COMPONENTS_DOM_DISTILLER_CONTENT_BROWSER_DISTILLIBILITY_DRIVER_H_ |
OLD | NEW |