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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerUIUtils.java

Issue 2883643002: Clean up ReaderMode OverlayPanel classes (Closed)
Patch Set: remove extra enum Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.dom_distiller; 5 package org.chromium.chrome.browser.dom_distiller;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.support.v7.app.AlertDialog; 8 import android.support.v7.app.AlertDialog;
9 9
10 import org.chromium.base.annotations.CalledByNative; 10 import org.chromium.base.annotations.CalledByNative;
11 import org.chromium.base.annotations.JNINamespace; 11 import org.chromium.base.annotations.JNINamespace;
12 import org.chromium.base.metrics.RecordUserAction; 12 import org.chromium.base.metrics.RecordUserAction;
13 import org.chromium.chrome.R; 13 import org.chromium.chrome.R;
14 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason;
15 import org.chromium.content_public.browser.WebContents; 14 import org.chromium.content_public.browser.WebContents;
16 import org.chromium.ui.base.WindowAndroid; 15 import org.chromium.ui.base.WindowAndroid;
17 16
18 /** 17 /**
19 * Java implementation of dom_distiller::android::DistillerUIHandleAndroid. 18 * Java implementation of dom_distiller::android::DistillerUIHandleAndroid.
20 */ 19 */
21 @JNINamespace("dom_distiller::android") 20 @JNINamespace("dom_distiller::android")
22 public final class DomDistillerUIUtils { 21 public final class DomDistillerUIUtils {
23 // Static handle to Reader Mode's manager. 22 // Static handle to Reader Mode's manager.
24 private static ReaderModeManagerDelegate sManagerDelegate; 23 private static ReaderModeManager sManagerManager;
wychen 2017/06/28 21:32:37 Do we still need this?
mdjones 2017/06/29 15:38:35 Guess not, kept it around for the settings util bu
25 24
26 /** 25 /**
27 * Set the delegate to the ReaderModeManager. 26 * Set the delegate to the ReaderModeManager.
28 * @param delegate The delegate for the ReaderModeManager. 27 * @param manager The class managing Reader Mode.
29 */ 28 */
30 public static void setReaderModeManagerDelegate(ReaderModeManagerDelegate de legate) { 29 public static void setReaderModeManagerDelegate(ReaderModeManager manager) {
31 sManagerDelegate = delegate; 30 sManagerManager = manager;
32 } 31 }
33 32
34 /** 33 /**
35 * A static method for native code to call to open the distiller UI settings . 34 * A static method for native code to call to open the distiller UI settings .
36 * @param webContents The WebContents containing the distilled content. 35 * @param webContents The WebContents containing the distilled content.
37 */ 36 */
38 @CalledByNative 37 @CalledByNative
39 public static void openSettings(WebContents webContents) { 38 public static void openSettings(WebContents webContents) {
40 Activity activity = getActivityFromWebContents(webContents); 39 Activity activity = getActivityFromWebContents(webContents);
41 if (webContents != null && activity != null) { 40 if (webContents != null && activity != null) {
42 RecordUserAction.record("DomDistiller_DistilledPagePrefsOpened"); 41 RecordUserAction.record("DomDistiller_DistilledPagePrefsOpened");
43 AlertDialog.Builder builder = 42 AlertDialog.Builder builder =
44 new AlertDialog.Builder(activity, R.style.AlertDialogTheme); 43 new AlertDialog.Builder(activity, R.style.AlertDialogTheme);
45 builder.setView(DistilledPagePrefsView.create(activity)); 44 builder.setView(DistilledPagePrefsView.create(activity));
46 builder.show(); 45 builder.show();
47 } 46 }
48 } 47 }
49 48
50 /** 49 /**
51 * A static method for native code to close the current Reader Mode panel. T his should be 50 * Clear static references to objects.
52 * some usage of a "close" button. 51 * @param manager The manager requesting the destoy. This prevents different managers in
53 * @param animate If the panel should animate closed. 52 * document mode from accidentally clearing a reference it doesn't own.
54 */ 53 */
55 @CalledByNative 54 public static void destroy(ReaderModeManager manager) {
56 public static void closePanel(boolean animate) { 55 if (manager != sManagerManager) return;
57 if (sManagerDelegate == null) return; 56 sManagerManager = null;
58 sManagerDelegate.closeReaderPanel(StateChangeReason.CLOSE_BUTTON, animat e);
59 } 57 }
60 58
61 /** 59 /**
62 * Clear static references to objects.
63 * @param delegate The delegate requesting the destoy. This prevents differe nt managers in
64 * document mode from accidentally clearing a reference it doesn't own.
65 */
66 public static void destroy(ReaderModeManagerDelegate delegate) {
67 if (delegate != sManagerDelegate) return;
68 sManagerDelegate = null;
69 }
70
71 /**
72 * @param webContents The WebContents to get the Activity from. 60 * @param webContents The WebContents to get the Activity from.
73 * @return The Activity associated with the WebContents. 61 * @return The Activity associated with the WebContents.
74 */ 62 */
75 private static Activity getActivityFromWebContents(WebContents webContents) { 63 private static Activity getActivityFromWebContents(WebContents webContents) {
76 if (webContents == null) return null; 64 if (webContents == null) return null;
77 65
78 WindowAndroid window = webContents.getTopLevelNativeWindow(); 66 WindowAndroid window = webContents.getTopLevelNativeWindow();
79 if (window == null) return null; 67 if (window == null) return null;
80 68
81 return window.getActivity().get(); 69 return window.getActivity().get();
82 } 70 }
83 71
84 private DomDistillerUIUtils() {} 72 private DomDistillerUIUtils() {}
85 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698