Chromium Code Reviews| Index: components/dom_distiller/content/browser/distillable_page_utils.cc |
| diff --git a/components/dom_distiller/content/browser/distillable_page_utils.cc b/components/dom_distiller/content/browser/distillable_page_utils.cc |
| index 5487c62e87dc4e0eda1daecad009f9dd20463709..d60e7f7982660a143748d89cbffeff3f884c5657 100644 |
| --- a/components/dom_distiller/content/browser/distillable_page_utils.cc |
| +++ b/components/dom_distiller/content/browser/distillable_page_utils.cc |
| @@ -10,7 +10,9 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "base/values.h" |
| +#include "components/dom_distiller/content/browser/distillability_driver.h" |
| #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" |
| +#include "components/dom_distiller/content/common/distiller_messages.h" |
| #include "components/dom_distiller/core/distillable_page_detector.h" |
| #include "components/dom_distiller/core/experiments.h" |
| #include "components/dom_distiller/core/page_features.h" |
| @@ -20,6 +22,7 @@ |
| namespace dom_distiller { |
| namespace { |
| + |
| void OnOGArticleJsResult(base::Callback<void(bool)> callback, |
| const base::Value* result) { |
| bool success = false; |
| @@ -29,11 +32,45 @@ void OnOGArticleJsResult(base::Callback<void(bool)> callback, |
| callback.Run(success); |
| } |
| +#if defined(OS_IOS) |
|
mdjones
2015/09/29 17:31:42
I don't think we need this for code in the dom_dis
wychen
2015/09/29 21:46:57
Done.
|
| void OnExtractFeaturesJsResult(const DistillablePageDetector* detector, |
| base::Callback<void(bool)> callback, |
| const base::Value* result) { |
| callback.Run(detector->Classify(CalculateDerivedFeaturesFromJSON(result))); |
| } |
| +#else // defined(OS_IOS) |
| +void OnExtractFeaturesNativeResult( |
| + const DistillablePageDetector* detector, |
| + base::Callback<void(bool)> callback, |
| + bool isOGArticle, |
| + const std::string& url, |
| + int numElements, |
| + int numAnchors, |
| + int numForms, |
| + const std::string& innerText, |
| + const std::string& textContent, |
| + const std::string& innerHTML) { |
| + |
| + GURL parsed_url(url); |
| + if (!parsed_url.is_valid()) { |
| + callback.Run(false); |
| + return; |
| + } |
| + |
| + auto res = CalculateDerivedFeatures( |
| + isOGArticle, |
| + parsed_url, |
| + numElements, |
| + numAnchors, |
| + numForms, |
| + innerText, |
| + textContent, |
| + innerHTML |
| + ); |
| + callback.Run(detector->Classify(res)); |
| +} |
| +#endif // defined(OS_IOS) |
| + |
| } // namespace |
| void IsOpenGraphArticle(content::WebContents* web_contents, |
| @@ -89,6 +126,8 @@ void IsDistillablePageForDetector(content::WebContents* web_contents, |
| base::Bind(callback, false)); |
| return; |
| } |
| + |
| +#if defined(OS_IOS) |
|
mdjones
2015/09/29 17:31:42
Same as above (not needed for content).
wychen
2015/09/29 21:46:57
Done.
|
| std::string extract_features_js = |
| ResourceBundle::GetSharedInstance() |
| .GetRawDataResource(IDR_EXTRACT_PAGE_FEATURES_JS) |
| @@ -96,6 +135,14 @@ void IsDistillablePageForDetector(content::WebContents* web_contents, |
| RunIsolatedJavaScript( |
| main_frame, extract_features_js, |
| base::Bind(OnExtractFeaturesJsResult, detector, callback)); |
| +#else |
| + WebContentsDistillabilityDriver::CreateForWebContents(web_contents); |
| + WebContentsDistillabilityDriver *driver = |
| + WebContentsDistillabilityDriver::FromWebContents(web_contents); |
| + CHECK(driver); |
| + driver->ExtractFeatures( |
| + base::Bind(OnExtractFeaturesNativeResult, detector, callback)); |
| +#endif |
| } |
| } // namespace dom_distiller |