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

Unified Diff: components/dom_distiller/standalone/content_extractor_browsertest.cc

Issue 901793002: Add support for providing an external file for extracting content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved injection to constructor Created 5 years, 9 months 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/standalone/content_extractor_browsertest.cc
diff --git a/components/dom_distiller/standalone/content_extractor_browsertest.cc b/components/dom_distiller/standalone/content_extractor_browsertest.cc
index b9766f6885fa2d005197fa5d2d1a3fbdbe7f3f05..ee5be4ce3c24b5b72003cd8d3db8786dee91da9d 100644
--- a/components/dom_distiller/standalone/content_extractor_browsertest.cc
+++ b/components/dom_distiller/standalone/content_extractor_browsertest.cc
@@ -5,6 +5,8 @@
#include <sstream>
#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/id_map.h"
#include "base/message_loop/message_loop.h"
@@ -30,6 +32,7 @@
#include "content/shell/browser/shell.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
+#include "grit/components_resources.h"
#include "net/dns/mock_host_resolver.h"
#include "third_party/dom_distiller_js/dom_distiller.pb.h"
#include "ui/base/resource/resource_bundle.h"
@@ -111,6 +114,11 @@ const char* kOriginalUrls = "original-urls";
// Maximum number of concurrent started extractor requests.
const int kMaxExtractorTasks = 8;
+// A path to a script for extracting content (domdistiller.js). If this argument
+// is passed in, the script will be used instead of using the bundled version
+// of the script.
+const char* kExternalDomDistillerJs = "external-dom-distiller-js";
+
scoped_ptr<DomDistillerService> CreateDomDistillerService(
content::BrowserContext* context,
const base::FilePath& db_path,
@@ -127,8 +135,29 @@ scoped_ptr<DomDistillerService> CreateDomDistillerService(
scoped_ptr<DomDistillerStore> dom_distiller_store(
new DomDistillerStore(db.Pass(), db_path));
- scoped_ptr<DistillerPageFactory> distiller_page_factory(
- new DistillerPageWebContentsFactory(context));
+ scoped_ptr<DistillerPageFactory> distiller_page_factory;
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ kExternalDomDistillerJs)) {
+ std::string external_script_path =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ kExternalDomDistillerJs);
+ std::string script_content;
+ if (!base::ReadFileToString(base::FilePath(external_script_path),
+ &script_content)) {
+ ADD_FAILURE() << "Failed to read external script for distillation.";
+ return nullptr;
+ }
+ distiller_page_factory.reset(
+ new DistillerPageWebContentsFactory(context, script_content));
+ } else {
+ const std::string distiller_js_script =
+ ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_DISTILLER_JS)
+ .as_string();
+ distiller_page_factory.reset(
+ new DistillerPageWebContentsFactory(context, distiller_js_script));
+ }
+
scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory(
new DistillerURLFetcherFactory(context->GetRequestContext()));

Powered by Google App Engine
This is Rietveld 408576698