| Index: components/dom_distiller/content/browser/distillability_driver.cc
|
| diff --git a/components/dom_distiller/content/browser/distillability_driver.cc b/components/dom_distiller/content/browser/distillability_driver.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1dc3757e184f69a0da69f02fbd32d1050582e7d4
|
| --- /dev/null
|
| +++ b/components/dom_distiller/content/browser/distillability_driver.cc
|
| @@ -0,0 +1,76 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/dom_distiller/content/browser/distillability_driver.h"
|
| +#include "components/dom_distiller/content/common/distiller_messages.h"
|
| +
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/web_contents_observer.h"
|
| +#include "content/public/browser/web_contents_user_data.h"
|
| +
|
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(
|
| + dom_distiller::WebContentsDistillabilityDriver);
|
| +
|
| +namespace dom_distiller {
|
| +
|
| +WebContentsDistillabilityDriver::WebContentsDistillabilityDriver(
|
| + content::WebContents* web_contents)
|
| + : content::WebContentsObserver(web_contents),
|
| + callback_id_(0) {
|
| +}
|
| +
|
| +WebContentsDistillabilityDriver::~WebContentsDistillabilityDriver() {
|
| + CleanUp();
|
| +}
|
| +
|
| +bool WebContentsDistillabilityDriver::OnMessageReceived(const IPC::Message &msg,
|
| + content::RenderFrameHost* render_frame_host) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(WebContentsDistillabilityDriver, msg)
|
| + IPC_MESSAGE_HANDLER(FrameHostMsg_ExtractFeatureResponse,
|
| + OnExtractFeatureResponse)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::OnExtractFeatureResponse(int id,
|
| + FrameHostMsg_ExtractFeatureResponse_Params results) {
|
| + std::map<int, ExtractFeatureCallback>::iterator it =
|
| + callbacks_.find(id);
|
| + if (it != callbacks_.end()) {
|
| + it->second.Run(
|
| + results.isOGArticle,
|
| + results.url,
|
| + results.numElements,
|
| + results.numAnchors,
|
| + results.numForms,
|
| + results.innerText,
|
| + results.textContent,
|
| + results.innerHTML);
|
| + callbacks_.erase(it);
|
| + } else {
|
| + NOTREACHED() << "Received ExtractFeature response for unknown request";
|
| + }
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::RenderProcessGone(
|
| + base::TerminationStatus status) {
|
| + CleanUp();
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::ExtractFeatures(
|
| + const ExtractFeatureCallback& callback) {
|
| + int key = callback_id_++;
|
| + callbacks_.insert(std::make_pair(key, callback));
|
| +
|
| + content::RenderFrameHost* rfh = web_contents()->GetMainFrame();
|
| + rfh->Send(new FrameMsg_ExtractFeatureRequest(rfh->GetRoutingID(), key));
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::CleanUp() {
|
| + content::WebContentsObserver::Observe(NULL);
|
| +}
|
| +
|
| +} // namespace dom_distiller
|
|
|