| 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 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" | 10 #include "components/dom_distiller/content/browser/distiller_ui_handle.h" |
| 11 #include "components/dom_distiller/core/feedback_reporter.h" | 11 #include "components/dom_distiller/core/feedback_reporter.h" |
| 12 #include "content/public/browser/user_metrics.h" | 12 #include "content/public/browser/user_metrics.h" |
| 13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 14 | 14 |
| 15 namespace dom_distiller { | 15 namespace dom_distiller { |
| 16 | 16 |
| 17 DistillerJavaScriptServiceImpl::DistillerJavaScriptServiceImpl( | 17 DistillerJavaScriptServiceImpl::DistillerJavaScriptServiceImpl( |
| 18 content::RenderFrameHost* render_frame_host, | 18 content::RenderFrameHost* render_frame_host, |
| 19 DistillerUIHandle* distiller_ui_handle) | 19 DistillerUIHandle* distiller_ui_handle) |
| 20 : render_frame_host_(render_frame_host), | 20 : render_frame_host_(render_frame_host), |
| 21 distiller_ui_handle_(distiller_ui_handle) {} | 21 distiller_ui_handle_(distiller_ui_handle) {} |
| 22 | 22 |
| 23 DistillerJavaScriptServiceImpl::~DistillerJavaScriptServiceImpl() {} | 23 DistillerJavaScriptServiceImpl::~DistillerJavaScriptServiceImpl() {} |
| 24 | 24 |
| 25 void DistillerJavaScriptServiceImpl::HandleDistillerFeedbackCall( | |
| 26 bool good) { | |
| 27 FeedbackReporter::ReportQuality(good); | |
| 28 if (good) { | |
| 29 return; | |
| 30 } | |
| 31 | |
| 32 // If feedback is bad try to start up external feedback. | |
| 33 if (!distiller_ui_handle_) { | |
| 34 return; | |
| 35 } | |
| 36 content::WebContents* contents = | |
| 37 content::WebContents::FromRenderFrameHost(render_frame_host_); | |
| 38 distiller_ui_handle_->ReportExternalFeedback( | |
| 39 contents, contents->GetURL(), false); | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 void DistillerJavaScriptServiceImpl::HandleDistillerClosePanelCall( | 25 void DistillerJavaScriptServiceImpl::HandleDistillerClosePanelCall( |
| 44 bool animate) { | 26 bool animate) { |
| 45 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); | 27 content::RecordAction(base::UserMetricsAction("DomDistiller_ViewOriginal")); |
| 46 if (!distiller_ui_handle_) { | 28 if (!distiller_ui_handle_) { |
| 47 return; | 29 return; |
| 48 } | 30 } |
| 49 distiller_ui_handle_->ClosePanel(animate); | 31 distiller_ui_handle_->ClosePanel(animate); |
| 50 } | 32 } |
| 51 | 33 |
| 52 void DistillerJavaScriptServiceImpl::HandleDistillerOpenSettingsCall() { | 34 void DistillerJavaScriptServiceImpl::HandleDistillerOpenSettingsCall() { |
| 53 if (!distiller_ui_handle_) { | 35 if (!distiller_ui_handle_) { |
| 54 return; | 36 return; |
| 55 } | 37 } |
| 56 content::WebContents* contents = | 38 content::WebContents* contents = |
| 57 content::WebContents::FromRenderFrameHost(render_frame_host_); | 39 content::WebContents::FromRenderFrameHost(render_frame_host_); |
| 58 distiller_ui_handle_->OpenSettings(contents); | 40 distiller_ui_handle_->OpenSettings(contents); |
| 59 } | 41 } |
| 60 | 42 |
| 61 void CreateDistillerJavaScriptService( | 43 void CreateDistillerJavaScriptService( |
| 62 content::RenderFrameHost* render_frame_host, | 44 content::RenderFrameHost* render_frame_host, |
| 63 DistillerUIHandle* distiller_ui_handle, | 45 DistillerUIHandle* distiller_ui_handle, |
| 64 mojo::InterfaceRequest<mojom::DistillerJavaScriptService> request) { | 46 mojo::InterfaceRequest<mojom::DistillerJavaScriptService> request) { |
| 65 mojo::MakeStrongBinding(base::MakeUnique<DistillerJavaScriptServiceImpl>( | 47 mojo::MakeStrongBinding(base::MakeUnique<DistillerJavaScriptServiceImpl>( |
| 66 render_frame_host, distiller_ui_handle), | 48 render_frame_host, distiller_ui_handle), |
| 67 std::move(request)); | 49 std::move(request)); |
| 68 } | 50 } |
| 69 | 51 |
| 70 } // namespace dom_distiller | 52 } // namespace dom_distiller |
| OLD | NEW |