OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 package org.chromium.chrome.browser.dom_distiller; | |
6 | |
7 import org.chromium.base.CalledByNative; | |
8 import org.chromium.base.JNINamespace; | |
9 import org.chromium.chrome.browser.EmptyTabObserver; | |
10 import org.chromium.chrome.browser.Tab; | |
11 import org.chromium.chrome.browser.TabObserver; | |
12 import org.chromium.content.browser.ContentView; | |
13 import org.chromium.content_public.browser.WebContents; | |
14 | |
15 /** | |
16 * Java implementation of FeedbackReporterAndroid. | |
17 */ | |
18 @JNINamespace("dom_distiller::android") | |
19 public final class FeedbackReporter implements FeedbackReportingView.Observer { | |
20 | |
21 private final long mNativePointer; | |
22 private final Tab mTab; | |
23 private ContentView mContentView; | |
24 private FeedbackReportingView mFeedbackReportingView; | |
25 private String mOverlayUrl; | |
26 | |
27 /** | |
28 * @return whether the DOM Distiller feature is enabled. | |
29 */ | |
30 public static boolean isEnabled() { | |
31 return nativeIsEnabled(); | |
32 } | |
33 | |
34 /** | |
35 * Records feedback for the distilled content. | |
36 * | |
37 * @param good whether the perceived quality of the distillation of a web pa ge was good. | |
38 */ | |
39 private static void recordQuality(boolean good) { | |
40 nativeReportQuality(good); | |
41 } | |
42 | |
43 /** | |
44 * Created the FeedbackReporter, adds itself as a TabObserver, and ensures | |
newt (away)
2014/03/17 18:19:19
Created -> Creates
nyquist
2014/03/17 20:13:42
Done.
| |
45 * references to ContentView and WebContents are up to date. | |
46 * | |
47 * @param tab the tab where the overlay should be displayed. | |
48 */ | |
49 public FeedbackReporter(Tab tab) { | |
50 mNativePointer = nativeInit(); | |
51 mTab = tab; | |
52 mTab.addObserver(createTabObserver()); | |
53 updatePointers(); | |
54 } | |
55 | |
56 @Override | |
57 public void onYesPressed(FeedbackReportingView view) { | |
58 if (view != mFeedbackReportingView) return; | |
59 recordQuality(true); | |
60 dismissOverlay(); | |
61 } | |
62 | |
63 @Override | |
64 public void onNoPressed(FeedbackReportingView view) { | |
65 if (view != mFeedbackReportingView) return; | |
66 recordQuality(false); | |
67 dismissOverlay(); | |
68 } | |
69 | |
70 /** | |
71 * Start showing the overlay. | |
72 */ | |
73 private void showOverlay() { | |
74 mFeedbackReportingView = FeedbackReportingView.create(mContentView, this ); | |
75 } | |
76 | |
77 /** | |
78 * Dismiss the overlay which is currently being displayed, if any. | |
79 */ | |
80 @CalledByNative | |
81 private void dismissOverlay() { | |
82 if (mFeedbackReportingView != null) mFeedbackReportingView.dismiss(); | |
83 mOverlayUrl = null; | |
84 mFeedbackReportingView = null; | |
85 } | |
86 | |
87 /** | |
88 * Dismiss the overlay which is currently being displayed. | |
shashi
2014/03/14 20:33:24
remove this javadoc.
nyquist
2014/03/17 20:13:42
Done.
| |
89 */ | |
90 @CalledByNative | |
91 private String getCurrentOverlayUrl() { | |
92 return mOverlayUrl; | |
93 } | |
94 | |
95 /** | |
96 * Updates which ContentView and WebContents the FeedbackReporter is monitor ing. | |
97 */ | |
98 private void updatePointers() { | |
99 if (mContentView != mTab.getContentView()) mContentView = mTab.getConten tView(); | |
newt (away)
2014/03/17 18:19:19
What's the point of this if statement? Do you mean
nyquist
2014/03/17 20:13:42
Done.
| |
100 nativeReplaceWebContents(mNativePointer, mTab.getWebContents()); | |
101 } | |
102 | |
103 /** | |
104 * Creates a TabObserver for monitoring a Tab, used to react to changes in t he ContentView | |
105 * or to trigger its own destruction. | |
106 * | |
107 * @return TabObserver that can be used to monitor a Tab. | |
108 */ | |
109 private TabObserver createTabObserver() { | |
110 return new EmptyTabObserver() { | |
111 @Override | |
112 public void onWebContentsSwapped(Tab tab, boolean didStartLoad, | |
113 boolean didFinishLoad) { | |
114 updatePointers(); | |
115 } | |
116 | |
117 @Override | |
118 public void onContentChanged(Tab tab) { | |
119 updatePointers(); | |
120 } | |
121 | |
122 @Override | |
123 public void onUpdateUrl(Tab tab, String url) { | |
124 boolean reportable = nativeIsReportableUrl(url); | |
125 if (reportable) { | |
126 mOverlayUrl = url; | |
127 showOverlay(); | |
128 } else { | |
129 dismissOverlay(); | |
130 } | |
131 } | |
132 | |
133 @Override | |
134 public void onDestroyed(Tab tab) { | |
135 nativeDestroy(mNativePointer); | |
136 mContentView = null; | |
137 } | |
138 }; | |
139 } | |
140 | |
141 private static native boolean nativeIsEnabled(); | |
142 private static native boolean nativeIsReportableUrl(String url); | |
143 private static native void nativeReportQuality(boolean good); | |
144 private native long nativeInit(); | |
145 private native void nativeDestroy(long nativeFeedbackReporterAndroid); | |
146 private native void nativeReplaceWebContents( | |
147 long nativeFeedbackReporterAndroid, WebContents webContents); | |
148 } | |
OLD | NEW |