Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3476)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReporter.java

Issue 197473006: Add FeedbackReporter for reporting distillation quality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed disableUI again and comment Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReporter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReporter.java b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReporter.java
new file mode 100644
index 0000000000000000000000000000000000000000..072d6a47c75c0283a4a0bbc853a777c0ac55eb47
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReporter.java
@@ -0,0 +1,150 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.dom_distiller;
+
+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.content.browser.ContentView;
+import org.chromium.content_public.browser.WebContents;
+
+/**
+ * Java implementation of FeedbackReporterAndroid.
+ */
+@JNINamespace("dom_distiller::android")
+public final class FeedbackReporter implements FeedbackReportingView.FeedbackObserver {
+
+ private final long mNativePointer;
+ private final Tab mTab;
+ private ContentView mContentView;
+ private FeedbackReportingView mFeedbackReportingView;
+ private String mOverlayUrl;
+
+ /**
+ * @return whether the DOM Distiller feature is enabled.
+ */
+ public static boolean isEnabled() {
+ return nativeIsEnabled();
+ }
+
+ /**
+ * Records feedback for the distilled content.
+ *
+ * @param good whether the perceived quality of the distillation of a web page was good.
+ */
+ private static void recordQuality(boolean good) {
+ nativeReportQuality(good);
+ }
+
+ /**
+ * Creates the FeedbackReporter, adds itself as a TabObserver, and ensures
+ * references to ContentView and WebContents are up to date.
+ *
+ * @param tab the tab where the overlay should be displayed.
+ */
+ public FeedbackReporter(Tab tab) {
+ mNativePointer = nativeInit();
+ mTab = tab;
+ mTab.addObserver(createTabObserver());
+ updatePointers();
+ }
+
+ @Override
+ public void onYesPressed(FeedbackReportingView view) {
+ if (view != mFeedbackReportingView) return;
+ recordQuality(true);
+ dismissOverlay();
+ }
+
+ @Override
+ public void onNoPressed(FeedbackReportingView view) {
+ if (view != mFeedbackReportingView) return;
+ recordQuality(false);
+ dismissOverlay();
+ }
+
+ /**
+ * Start showing the overlay.
+ */
+ private void showOverlay() {
+ mFeedbackReportingView = FeedbackReportingView.create(mContentView, this);
+ }
+
+ @CalledByNative
+ private void dismissOverlay() {
+ if (mFeedbackReportingView != null) mFeedbackReportingView.dismiss();
+ mOverlayUrl = null;
+ mFeedbackReportingView = null;
+ }
+
+ /**
+ * Dismiss the overlay which is currently being displayed.
+ */
+ @CalledByNative
+ private String getCurrentOverlayUrl() {
+ return mOverlayUrl;
+ }
+
+ /**
+ * Updates which ContentView and WebContents the FeedbackReporter is monitoring.
+ */
+ private void updatePointers() {
+ mContentView = mTab.getContentView();
+ nativeReplaceWebContents(mNativePointer, mTab.getWebContents());
+ }
+
+ /**
+ * Creates a TabObserver for monitoring a Tab, used to react to changes in the ContentView
+ * or to trigger its own destruction.
+ *
+ * @return TabObserver that can be used to monitor a Tab.
+ */
+ 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 onUpdateUrl(Tab tab, String url) {
+ boolean reportable = nativeIsReportableUrl(url);
+ if (reportable) {
+ mOverlayUrl = url;
+ showOverlay();
+ } else {
+ dismissOverlay();
+ }
+ }
+
+ @Override
+ public void onDestroyed(Tab tab) {
+ nativeDestroy(mNativePointer);
+ mContentView = null;
+ }
+ };
+ }
+
+ private static native boolean nativeIsEnabled();
+
+ private static native boolean nativeIsReportableUrl(String url);
+
+ 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);
+}

Powered by Google App Engine
This is Rietveld 408576698