| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/dom_distiller/content/browser/distiller_javascript_service_
impl.h" | 5 #include "components/dom_distiller/content/browser/distiller_javascript_service_
impl.h" |
| 6 #include "components/dom_distiller/content/browser/external_feedback_reporter.h" | 6 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" |
| 7 #include "components/dom_distiller/core/feedback_reporter.h" | 7 #include "components/dom_distiller/core/feedback_reporter.h" |
| 8 #include "content/public/browser/user_metrics.h" | 8 #include "content/public/browser/user_metrics.h" |
| 9 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h" | 9 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h" |
| 10 | 10 |
| 11 namespace dom_distiller { | 11 namespace dom_distiller { |
| 12 | 12 |
| 13 DistillerJavaScriptServiceImpl::DistillerJavaScriptServiceImpl( | 13 DistillerJavaScriptServiceImpl::DistillerJavaScriptServiceImpl( |
| 14 content::RenderFrameHost* render_frame_host, | 14 content::RenderFrameHost* render_frame_host, |
| 15 ExternalFeedbackReporter* external_feedback_reporter, | 15 DistillerUIHandle* distiller_ui_handle, |
| 16 mojo::InterfaceRequest<DistillerJavaScriptService> request) | 16 mojo::InterfaceRequest<DistillerJavaScriptService> request) |
| 17 : binding_(this, request.Pass()), | 17 : binding_(this, request.Pass()), |
| 18 render_frame_host_(render_frame_host), | 18 render_frame_host_(render_frame_host), |
| 19 external_feedback_reporter_(external_feedback_reporter) {} | 19 distiller_ui_handle_(distiller_ui_handle) {} |
| 20 | 20 |
| 21 DistillerJavaScriptServiceImpl::~DistillerJavaScriptServiceImpl() {} | 21 DistillerJavaScriptServiceImpl::~DistillerJavaScriptServiceImpl() {} |
| 22 | 22 |
| 23 void DistillerJavaScriptServiceImpl::HandleDistillerEchoCall( | 23 void DistillerJavaScriptServiceImpl::HandleDistillerEchoCall( |
| 24 const mojo::String& message) {} | 24 const mojo::String& message) {} |
| 25 | 25 |
| 26 void DistillerJavaScriptServiceImpl::HandleDistillerFeedbackCall( | 26 void DistillerJavaScriptServiceImpl::HandleDistillerFeedbackCall( |
| 27 bool good) { | 27 bool good) { |
| 28 FeedbackReporter::ReportQuality(good); | 28 FeedbackReporter::ReportQuality(good); |
| 29 if (good) { | 29 if (good) { |
| 30 return; | 30 return; |
| 31 } | 31 } |
| 32 | 32 |
| 33 // If feedback is bad try to start up external feedback. | 33 // If feedback is bad try to start up external feedback. |
| 34 if (!external_feedback_reporter_) { | 34 if (!distiller_ui_handle_) { |
| 35 return; | 35 return; |
| 36 } | 36 } |
| 37 content::WebContents* contents = | 37 content::WebContents* contents = |
| 38 content::WebContents::FromRenderFrameHost(render_frame_host_); | 38 content::WebContents::FromRenderFrameHost(render_frame_host_); |
| 39 external_feedback_reporter_->ReportExternalFeedback( | 39 distiller_ui_handle_->ReportExternalFeedback( |
| 40 contents, contents->GetURL(), false); | 40 contents, contents->GetURL(), false); |
| 41 return; | 41 return; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void DistillerJavaScriptServiceImpl::HandleDistillerClosePanelCall() { | 44 void DistillerJavaScriptServiceImpl::HandleDistillerClosePanelCall() { |
| 45 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); | 45 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void DistillerJavaScriptServiceImpl::HandleDistillerOpenSettingsCall() { |
| 49 if (!distiller_ui_handle_) { |
| 50 return; |
| 51 } |
| 52 content::WebContents* contents = |
| 53 content::WebContents::FromRenderFrameHost(render_frame_host_); |
| 54 distiller_ui_handle_->OpenSettings(contents); |
| 55 } |
| 56 |
| 48 void CreateDistillerJavaScriptService( | 57 void CreateDistillerJavaScriptService( |
| 49 content::RenderFrameHost* render_frame_host, | 58 content::RenderFrameHost* render_frame_host, |
| 50 ExternalFeedbackReporter* feedback_reporter, | 59 DistillerUIHandle* distiller_ui_handle, |
| 51 mojo::InterfaceRequest<DistillerJavaScriptService> request) { | 60 mojo::InterfaceRequest<DistillerJavaScriptService> request) { |
| 52 // This is strongly bound and owned by the pipe. | 61 // This is strongly bound and owned by the pipe. |
| 53 new DistillerJavaScriptServiceImpl(render_frame_host, feedback_reporter, | 62 new DistillerJavaScriptServiceImpl(render_frame_host, distiller_ui_handle, |
| 54 request.Pass()); | 63 request.Pass()); |
| 55 } | 64 } |
| 56 | 65 |
| 57 } // namespace dom_distiller | 66 } // namespace dom_distiller |
| OLD | NEW |