EME test page application.
[chromium-blink-merge.git] / chrome / browser / android / dom_distiller / feedback_reporter_android.cc
blob81590a86777e90731d35ab39a4fe82f577a21ee9
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"
18 #include "url/gurl.h"
20 namespace dom_distiller {
22 namespace android {
24 // static
25 jboolean IsEnabled(JNIEnv* env, jclass clazz) {
26 return CommandLine::ForCurrentProcess()->HasSwitch(
27 switches::kEnableDomDistiller);
30 // static
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,
43 jobject obj,
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);
55 if (jobj.is_null())
56 return;
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);
70 // static
71 bool RegisterFeedbackReporter(JNIEnv* env) { return RegisterNativesImpl(env); }
73 } // namespace android
75 } // namespace dom_distiller