1 // Copyright 2014 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.
5 #include "chrome/browser/android/dom_distiller/feedback_reporter_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/command_line.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/url_constants.h"
11 #include "components/dom_distiller/core/feedback_reporter.h"
12 #include "components/dom_distiller/core/url_utils.h"
13 #include "content/public/browser/navigation_details.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/frame_navigate_params.h"
17 #include "jni/DomDistillerFeedbackReporter_jni.h"
20 namespace dom_distiller
{
25 jboolean
IsEnabled(JNIEnv
* env
, jclass clazz
) {
26 return CommandLine::ForCurrentProcess()->HasSwitch(
27 switches::kEnableDomDistiller
);
31 void ReportQuality(JNIEnv
* env
, jclass clazz
, jboolean j_good
) {
32 FeedbackReporter::ReportQuality(j_good
);
35 FeedbackReporterAndroid::FeedbackReporterAndroid(JNIEnv
* env
, jobject obj
)
36 : weak_java_feedback_reporter_(env
, obj
) {}
38 FeedbackReporterAndroid::~FeedbackReporterAndroid() {}
40 void FeedbackReporterAndroid::Destroy(JNIEnv
* env
, jobject obj
) { delete this; }
42 void FeedbackReporterAndroid::ReplaceWebContents(JNIEnv
* env
,
44 jobject jweb_contents
) {
45 content::WebContents
* web_contents
=
46 content::WebContents::FromJavaWebContents(jweb_contents
);
47 Observe(web_contents
);
50 void FeedbackReporterAndroid::DidNavigateMainFrame(
51 const content::LoadCommittedDetails
& details
,
52 const content::FrameNavigateParams
& params
) {
53 JNIEnv
* env
= base::android::AttachCurrentThread();
54 ScopedJavaLocalRef
<jobject
> jobj
= weak_java_feedback_reporter_
.get(env
);
57 Java_DomDistillerFeedbackReporter_dismissOverlay(env
, jobj
.obj());
58 GURL url
= details
.entry
->GetURL();
59 if (dom_distiller::url_utils::IsUrlReportable(
60 chrome::kDomDistillerScheme
, url
)) {
61 Java_DomDistillerFeedbackReporter_showOverlay(env
, jobj
.obj());
65 jlong
Init(JNIEnv
* env
, jobject obj
) {
66 FeedbackReporterAndroid
* reporter
= new FeedbackReporterAndroid(env
, obj
);
67 return reinterpret_cast<intptr_t>(reporter
);
71 bool RegisterFeedbackReporter(JNIEnv
* env
) { return RegisterNativesImpl(env
); }
73 } // namespace android
75 } // namespace dom_distiller