OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/dom_distiller/content/browser/distillability_driver.h" |
| 6 #include "components/dom_distiller/content/common/distiller_messages.h" |
| 7 |
| 8 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/web_contents_observer.h" |
| 10 #include "content/public/browser/web_contents_user_data.h" |
| 11 |
| 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 13 dom_distiller::DistillabilityDriver); |
| 14 |
| 15 namespace dom_distiller { |
| 16 |
| 17 DistillabilityDriver::DistillabilityDriver( |
| 18 content::WebContents* web_contents) |
| 19 : content::WebContentsObserver(web_contents) { |
| 20 } |
| 21 |
| 22 DistillabilityDriver::~DistillabilityDriver() { |
| 23 CleanUp(); |
| 24 } |
| 25 |
| 26 void DistillabilityDriver::SetDelegate( |
| 27 const base::Callback<void(bool, bool)>& delegate) { |
| 28 m_delegate_ = delegate; |
| 29 } |
| 30 |
| 31 bool DistillabilityDriver::OnMessageReceived(const IPC::Message &msg, |
| 32 content::RenderFrameHost* render_frame_host) { |
| 33 bool handled = true; |
| 34 IPC_BEGIN_MESSAGE_MAP(DistillabilityDriver, msg) |
| 35 IPC_MESSAGE_HANDLER(FrameHostMsg_Distillability, |
| 36 OnDistillability) |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) |
| 38 IPC_END_MESSAGE_MAP() |
| 39 return handled; |
| 40 } |
| 41 |
| 42 void DistillabilityDriver::OnDistillability( |
| 43 bool distillable, bool is_last) { |
| 44 if (m_delegate_.is_null()) return; |
| 45 |
| 46 m_delegate_.Run(distillable, is_last); |
| 47 } |
| 48 |
| 49 void DistillabilityDriver::RenderProcessGone( |
| 50 base::TerminationStatus status) { |
| 51 CleanUp(); |
| 52 } |
| 53 |
| 54 void DistillabilityDriver::CleanUp() { |
| 55 content::WebContentsObserver::Observe(NULL); |
| 56 } |
| 57 |
| 58 } // namespace dom_distiller |
OLD | NEW |