This source file includes following definitions.
- JNINamespace
- setExternalFeedbackReporter
- reportFeedback
- isEnabled
- onYesPressed
- onNoPressed
- recordQuality
- showOverlay
- dismissOverlay
- updatePointers
- createTabObserver
- nativeIsEnabled
- nativeReportQuality
- nativeInit
- nativeDestroy
- nativeReplaceWebContents
package org.chromium.chrome.browser.dom_distiller;
import android.app.Activity;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.chrome.browser.EmptyTabObserver;
import org.chromium.chrome.browser.Tab;
import org.chromium.chrome.browser.TabObserver;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
import org.chromium.content.browser.ContentView;
import org.chromium.content_public.browser.WebContents;
@JNINamespace("dom_distiller::android")
public final class DomDistillerFeedbackReporter implements
DomDistillerFeedbackReportingView.FeedbackObserver {
private static ExternalFeedbackReporter sExternalFeedbackReporter =
new NoOpExternalFeedbackReporter();
public static void setExternalFeedbackReporter(ExternalFeedbackReporter reporter) {
sExternalFeedbackReporter = reporter;
}
private static class NoOpExternalFeedbackReporter implements ExternalFeedbackReporter {
@Override
public void reportFeedback(Activity activity, String url, boolean good) {
}
}
private final long mNativePointer;
private final Tab mTab;
private ContentView mContentView;
private DomDistillerFeedbackReportingView mReportingView;
public static boolean isEnabled() {
return nativeIsEnabled();
}
public DomDistillerFeedbackReporter(Tab tab) {
mNativePointer = nativeInit();
mTab = tab;
mTab.addObserver(createTabObserver());
updatePointers();
}
@Override
public void onYesPressed(DomDistillerFeedbackReportingView view) {
if (view != mReportingView) return;
recordQuality(true);
dismissOverlay();
}
@Override
public void onNoPressed(DomDistillerFeedbackReportingView view) {
if (view != mReportingView) return;
recordQuality(false);
dismissOverlay();
}
private void recordQuality(boolean good) {
nativeReportQuality(good);
if (!good) {
Activity activity = mTab.getWindowAndroid().getActivity().get();
String url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(mContentView.getUrl());
sExternalFeedbackReporter.reportFeedback(activity, url, good);
}
}
@CalledByNative
private void showOverlay() {
mReportingView = DomDistillerFeedbackReportingView.create(mContentView, this);
}
@CalledByNative
private void dismissOverlay() {
if (mReportingView != null) {
mReportingView.dismiss(true);
mReportingView = null;
}
}
private void updatePointers() {
mContentView = mTab.getContentView();
nativeReplaceWebContents(mNativePointer, mTab.getWebContents());
}
private TabObserver createTabObserver() {
return new EmptyTabObserver() {
@Override
public void onWebContentsSwapped(Tab tab, boolean didStartLoad,
boolean didFinishLoad) {
updatePointers();
}
@Override
public void onContentChanged(Tab tab) {
updatePointers();
}
@Override
public void onDestroyed(Tab tab) {
nativeDestroy(mNativePointer);
mContentView = null;
}
};
}
private static native boolean nativeIsEnabled();
private static native void nativeReportQuality(boolean good);
private native long nativeInit();
private native void nativeDestroy(long nativeFeedbackReporterAndroid);
private native void nativeReplaceWebContents(
long nativeFeedbackReporterAndroid, WebContents webContents);
}