Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenProcess.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenDialogHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenProcess.java |
similarity index 37% |
rename from chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenDialogHelper.java |
rename to chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenProcess.java |
index 6abd100e2b5407692c468c7f34e7bb9679d4e931..a8df1ed22472f8b51be7d1fdbf02b2eeb973a50f 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenDialogHelper.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenProcess.java |
@@ -4,7 +4,7 @@ |
package org.chromium.chrome.browser.webapps; |
-import android.content.Context; |
+import android.app.Activity; |
import android.graphics.Bitmap; |
import org.chromium.base.annotations.CalledByNative; |
@@ -12,81 +12,88 @@ import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.content_public.browser.WebContents; |
/** |
- * This class acts as a proxy for AddToHomescreenDialog to interact with C++. |
+ * Manages the add-to-homescreen process. |
*/ |
-public class AddToHomescreenDialogHelper { |
+public class AddToHomescreenProcess implements AddToHomescreenDelegate { |
- /** Observes the data fetching pipeline. */ |
- public interface Observer { |
+ /** Interface so that add-to-homescreen UI can track fetch of add-to-homescreen data. */ |
+ public interface Ui { |
Xi Han
2016/08/19 14:11:06
UiObserver? I feel "Ui" is a concept way to wide.
|
/** Called when the title of the page is available. */ |
void onUserTitleAvailable(String title); |
- /** Called when the icon to use in the launcher is available. */ |
- void onIconAvailable(Bitmap icon); |
+ /** |
+ * Called once native has finished fetching the homescreen shortcut's data (like the Web |
+ * Manifest) and is ready for {@link AddToHomescreenDelegate#addShortcut()} to be called. |
+ * @param icon Icon to use in the launcher. |
+ */ |
+ void onReadyToAdd(Bitmap icon); |
} |
- private final Context mAppContext; |
+ private final Activity mActivity; |
private final Tab mTab; |
- private Observer mObserver; |
- private boolean mIsInitialized; |
- private long mNativeAddToHomescreenDialogHelper; |
+ private long mNativeAddToHomescreenProcess; |
+ private Ui mUi; |
- public AddToHomescreenDialogHelper(Context appContext, Tab tab) { |
- mAppContext = appContext; |
+ public AddToHomescreenProcess(Activity activity, Tab tab) { |
+ mActivity = activity; |
mTab = tab; |
} |
- /** |
- * Gets all the information required to initialize the UI. The observer will be notified as |
- * information required for the shortcut become available. |
- * @param observer Observer to notify. |
- */ |
- public void initialize(Observer observer) { |
- mObserver = observer; |
- mNativeAddToHomescreenDialogHelper = nativeInitialize(mTab.getWebContents()); |
+ /** Starts add-to-homescreen process. */ |
+ public void start() { |
+ mNativeAddToHomescreenProcess = nativeInitializeAndStart(mTab.getWebContents()); |
} |
- /** |
- * Returns whether the object is initialized. |
- */ |
- public boolean isInitialized() { |
- return mIsInitialized; |
+ /** Sets the add-to-homescreen UI tracking the add-to-homescreen data fetch. */ |
+ public void setUi(Ui ui) { |
+ mUi = ui; |
} |
/** |
* Puts the object in a state where it is safe to be destroyed. |
*/ |
public void destroy() { |
- nativeDestroy(mNativeAddToHomescreenDialogHelper); |
+ nativeDestroy(mNativeAddToHomescreenProcess); |
- // Make sure the callback isn't run if the tear down happens before |
- // onInitialized() is called. |
- mObserver = null; |
- mNativeAddToHomescreenDialogHelper = 0; |
+ mUi = null; |
+ mNativeAddToHomescreenProcess = 0; |
} |
- @CalledByNative |
- private void onUserTitleAvailable(String title) { |
- mObserver.onUserTitleAvailable(title); |
+ /** |
+ * Adds a shortcut for the current Tab. |
+ * @param userRequestedTitle Title of the shortcut displayed on the homescreen. |
+ */ |
+ public void addShortcut(String userRequestedTitle) { |
+ nativeAddShortcut(mNativeAddToHomescreenProcess, userRequestedTitle); |
} |
- @CalledByNative |
- private void onIconAvailable(Bitmap icon) { |
- mObserver.onIconAvailable(icon); |
- mIsInitialized = true; |
+ public void onDismissed() { |
+ destroy(); |
} |
/** |
- * Adds a shortcut for the current Tab. |
- * @param userRequestedTitle Title of the shortcut displayed on the homescreen. |
+ * Shows alert to prompt user for name of home screen shortcut. |
*/ |
- public void addShortcut(String userRequestedTitle) { |
- nativeAddShortcut(mNativeAddToHomescreenDialogHelper, userRequestedTitle); |
+ @CalledByNative |
+ public void showDialog() { |
+ AddToHomescreenDialog dialog = new AddToHomescreenDialog(this); |
+ dialog.show(mActivity); |
+ setUi(dialog); |
+ } |
+ |
+ @CalledByNative |
+ private void onUserTitleAvailable(String title) { |
+ mUi.onUserTitleAvailable(title); |
+ } |
+ |
+ @CalledByNative |
+ private void onReadyToAdd(Bitmap icon) { |
+ mUi.onReadyToAdd(icon); |
} |
- private native long nativeInitialize(WebContents webContents); |
- private native void nativeAddShortcut(long nativeAddToHomescreenDialogHelper, |
- String userRequestedTitle); |
- private native void nativeDestroy(long nativeAddToHomescreenDialogHelper); |
+ private native long nativeInitializeAndStart(WebContents webContents); |
+ private native void nativeAddShortcut( |
+ long nativeAddToHomescreenProcess, String userRequestedTitle); |
+ private native void nativeDestroy(long nativeAddToHomescreenProcess); |
} |