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::WebContentsDistillabilityDriver); |
| 14 |
| 15 namespace dom_distiller { |
| 16 |
| 17 WebContentsDistillabilityDriver::WebContentsDistillabilityDriver( |
| 18 content::WebContents* web_contents) |
| 19 : content::WebContentsObserver(web_contents) { |
| 20 } |
| 21 |
| 22 WebContentsDistillabilityDriver::~WebContentsDistillabilityDriver() { |
| 23 CleanUp(); |
| 24 } |
| 25 |
| 26 void WebContentsDistillabilityDriver::SetCallback( |
| 27 const base::Callback<void(bool, bool)>& callback) { |
| 28 LOG(ERROR) << "ReaderMode WebContentsDistillabilityDriver::SetCallback " |
| 29 << &callback; |
| 30 m_callback_ = callback; |
| 31 } |
| 32 |
| 33 bool WebContentsDistillabilityDriver::OnMessageReceived(const IPC::Message &msg, |
| 34 content::RenderFrameHost* render_frame_host) { |
| 35 bool handled = true; |
| 36 IPC_BEGIN_MESSAGE_MAP(WebContentsDistillabilityDriver, msg) |
| 37 IPC_MESSAGE_HANDLER(FrameHostMsg_Distillability, |
| 38 OnDistillability) |
| 39 IPC_MESSAGE_UNHANDLED(handled = false) |
| 40 IPC_END_MESSAGE_MAP() |
| 41 return handled; |
| 42 } |
| 43 |
| 44 void WebContentsDistillabilityDriver::OnDistillability( |
| 45 bool distillable, bool is_last) { |
| 46 LOG(ERROR) << "ReaderMode WebContentsDistillabilityDriver::OnDistillability " |
| 47 << distillable << " " << is_last; |
| 48 LOG(ERROR) << "ReaderMode m_callback_.is_null = " << m_callback_.is_null(); |
| 49 if (m_callback_.is_null()) return; |
| 50 |
| 51 m_callback_.Run(distillable, is_last); |
| 52 if (is_last) { |
| 53 m_callback_ = base::Callback<void(bool, bool)>(); |
| 54 } |
| 55 } |
| 56 |
| 57 void WebContentsDistillabilityDriver::RenderProcessGone( |
| 58 base::TerminationStatus status) { |
| 59 CleanUp(); |
| 60 } |
| 61 |
| 62 void WebContentsDistillabilityDriver::CleanUp() { |
| 63 content::WebContentsObserver::Observe(NULL); |
| 64 } |
| 65 |
| 66 } // namespace dom_distiller |
OLD | NEW |