OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/dom_distiller/content/distillable_page_utils.h" | 5 #include "components/dom_distiller/content/distillable_page_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "components/dom_distiller/core/distillable_page_detector.h" | 11 #include "components/dom_distiller/core/distillable_page_detector.h" |
| 12 #include "components/dom_distiller/core/experiments.h" |
12 #include "components/dom_distiller/core/page_features.h" | 13 #include "components/dom_distiller/core/page_features.h" |
13 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
14 #include "grit/components_resources.h" | 15 #include "grit/components_resources.h" |
15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
16 | 17 |
17 namespace dom_distiller { | 18 namespace dom_distiller { |
18 namespace { | 19 namespace { |
19 void OnOGArticleJsResult(base::Callback<void(bool)> callback, | 20 void OnOGArticleJsResult(base::Callback<void(bool)> callback, |
20 const base::Value* result) { | 21 const base::Value* result) { |
21 bool success = false; | 22 bool success = false; |
(...skipping 20 matching lines...) Expand all Loading... |
42 } | 43 } |
43 std::string og_article_js = ResourceBundle::GetSharedInstance() | 44 std::string og_article_js = ResourceBundle::GetSharedInstance() |
44 .GetRawDataResource(IDR_IS_DISTILLABLE_JS) | 45 .GetRawDataResource(IDR_IS_DISTILLABLE_JS) |
45 .as_string(); | 46 .as_string(); |
46 main_frame->ExecuteJavaScript(base::UTF8ToUTF16(og_article_js), | 47 main_frame->ExecuteJavaScript(base::UTF8ToUTF16(og_article_js), |
47 base::Bind(OnOGArticleJsResult, callback)); | 48 base::Bind(OnOGArticleJsResult, callback)); |
48 } | 49 } |
49 | 50 |
50 void IsDistillablePage(content::WebContents* web_contents, | 51 void IsDistillablePage(content::WebContents* web_contents, |
51 base::Callback<void(bool)> callback) { | 52 base::Callback<void(bool)> callback) { |
52 IsDistillablePageForDetector(web_contents, | 53 switch (GetDistillerHeuristicsType()) { |
53 DistillablePageDetector::GetDefault(), callback); | 54 case DistillerHeuristicsType::NONE: |
| 55 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 56 base::Bind(callback, false)); |
| 57 return; |
| 58 case DistillerHeuristicsType::OG_ARTICLE: |
| 59 IsOpenGraphArticle(web_contents, callback); |
| 60 return; |
| 61 case DistillerHeuristicsType::ADABOOST_MODEL: |
| 62 IsDistillablePageForDetector( |
| 63 web_contents, DistillablePageDetector::GetDefault(), callback); |
| 64 return; |
| 65 } |
54 } | 66 } |
55 | 67 |
56 void IsDistillablePageForDetector(content::WebContents* web_contents, | 68 void IsDistillablePageForDetector(content::WebContents* web_contents, |
57 const DistillablePageDetector* detector, | 69 const DistillablePageDetector* detector, |
58 base::Callback<void(bool)> callback) { | 70 base::Callback<void(bool)> callback) { |
59 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 71 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
60 if (!main_frame) { | 72 if (!main_frame) { |
61 base::MessageLoop::current()->PostTask(FROM_HERE, | 73 base::MessageLoop::current()->PostTask(FROM_HERE, |
62 base::Bind(callback, false)); | 74 base::Bind(callback, false)); |
63 return; | 75 return; |
64 } | 76 } |
65 std::string extract_features_js = | 77 std::string extract_features_js = |
66 ResourceBundle::GetSharedInstance() | 78 ResourceBundle::GetSharedInstance() |
67 .GetRawDataResource(IDR_EXTRACT_PAGE_FEATURES_JS) | 79 .GetRawDataResource(IDR_EXTRACT_PAGE_FEATURES_JS) |
68 .as_string(); | 80 .as_string(); |
69 main_frame->ExecuteJavaScript( | 81 main_frame->ExecuteJavaScript( |
70 base::UTF8ToUTF16(extract_features_js), | 82 base::UTF8ToUTF16(extract_features_js), |
71 base::Bind(OnExtractFeaturesJsResult, detector, callback)); | 83 base::Bind(OnExtractFeaturesJsResult, detector, callback)); |
72 } | 84 } |
73 | 85 |
74 } // namespace dom_distiller | 86 } // namespace dom_distiller |
OLD | NEW |