Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: components/dom_distiller/content/browser/distillable_page_utils.cc

Issue 1248643004: Test distillability without JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@early
Patch Set: fix browsertest, merge webkit CL, merge http://crrev.com/1403413004 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c37fa32ec2ee148c227ce4925f859d1e410e833b 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"
@@ -19,83 +21,15 @@
#include "ui/base/resource/resource_bundle.h"
namespace dom_distiller {
-namespace {
-void OnOGArticleJsResult(base::Callback<void(bool)> callback,
- const base::Value* result) {
- bool success = false;
- if (result) {
- result->GetAsBoolean(&success);
- }
- callback.Run(success);
-}
-
-void OnExtractFeaturesJsResult(const DistillablePageDetector* detector,
- base::Callback<void(bool)> callback,
- const base::Value* result) {
- callback.Run(detector->Classify(CalculateDerivedFeaturesFromJSON(result)));
-}
-} // namespace
-void IsOpenGraphArticle(content::WebContents* web_contents,
- base::Callback<void(bool)> callback) {
- content::RenderFrameHost* main_frame = web_contents->GetMainFrame();
- if (!main_frame) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, false));
- return;
- }
- std::string og_article_js = ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_IS_DISTILLABLE_JS)
- .as_string();
- RunIsolatedJavaScript(main_frame, og_article_js,
- base::Bind(OnOGArticleJsResult, callback));
-}
-
-void IsDistillablePage(content::WebContents* web_contents,
- bool is_mobile_optimized,
- base::Callback<void(bool)> callback) {
- switch (GetDistillerHeuristicsType()) {
- case DistillerHeuristicsType::ALWAYS_TRUE:
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, true));
- return;
- case DistillerHeuristicsType::OG_ARTICLE:
- IsOpenGraphArticle(web_contents, callback);
- return;
- case DistillerHeuristicsType::ADABOOST_MODEL:
- // The adaboost model is only applied to non-mobile pages.
- if (is_mobile_optimized) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, false));
- return;
- }
- IsDistillablePageForDetector(
- web_contents, DistillablePageDetector::GetDefault(), callback);
- return;
- case DistillerHeuristicsType::NONE:
- default:
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, false));
- return;
- }
-}
+void setCallback(content::WebContents* web_contents,
+ base::Callback<void(bool, bool)> callback) {
+ WebContentsDistillabilityDriver::CreateForWebContents(web_contents);
-void IsDistillablePageForDetector(content::WebContents* web_contents,
- const DistillablePageDetector* detector,
- base::Callback<void(bool)> callback) {
- content::RenderFrameHost* main_frame = web_contents->GetMainFrame();
- if (!main_frame) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, false));
- return;
- }
- std::string extract_features_js =
- ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_EXTRACT_PAGE_FEATURES_JS)
- .as_string();
- RunIsolatedJavaScript(
- main_frame, extract_features_js,
- base::Bind(OnExtractFeaturesJsResult, detector, callback));
+ WebContentsDistillabilityDriver *driver =
+ WebContentsDistillabilityDriver::FromWebContents(web_contents);
+ CHECK(driver);
+ driver->SetCallback(callback);
}
} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698