| 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..f9203465a4d8d0a57412ee3651a6231210d84a86
|
| --- /dev/null
|
| +++ b/components/dom_distiller/content/browser/distillability_driver.cc
|
| @@ -0,0 +1,58 @@
|
| +// 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) {
|
| +}
|
| +
|
| +WebContentsDistillabilityDriver::~WebContentsDistillabilityDriver() {
|
| + CleanUp();
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::SetDelegate(
|
| + const base::Callback<void(bool, bool)>& delegate) {
|
| + m_delegate_ = delegate;
|
| +}
|
| +
|
| +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_Distillability,
|
| + OnDistillability)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::OnDistillability(
|
| + bool distillable, bool is_last) {
|
| + if (m_delegate_.is_null()) return;
|
| +
|
| + m_delegate_.Run(distillable, is_last);
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::RenderProcessGone(
|
| + base::TerminationStatus status) {
|
| + CleanUp();
|
| +}
|
| +
|
| +void WebContentsDistillabilityDriver::CleanUp() {
|
| + content::WebContentsObserver::Observe(NULL);
|
| +}
|
| +
|
| +} // namespace dom_distiller
|
|
|