| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenManager.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/AddToHomescreenManager.java
|
| similarity index 40%
|
| rename from chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenDialogHelper.java
|
| rename to chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenManager.java
|
| index 15da5bdd548b683ebb09406aa809f62022566a90..ffec6c8fee258c240d3a8e8ec98952d9f7abb08d 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenDialogHelper.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenManager.java
|
| @@ -1,10 +1,10 @@
|
| -// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Copyright 2016 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.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 AddToHomescreenManager {
|
|
|
| - /** Observes the data fetching pipeline. */
|
| + /** Interface for tracking fetch of add-to-homescreen data. */
|
| public interface Observer {
|
| /** 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 mNativeAddToHomescreenManager;
|
|
|
| - public AddToHomescreenDialogHelper(Context appContext, Tab tab) {
|
| - mAppContext = appContext;
|
| + public AddToHomescreenManager(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() {
|
| + mNativeAddToHomescreenManager = nativeInitializeAndStart(mTab.getWebContents());
|
| }
|
|
|
| - /**
|
| - * Returns whether the object is initialized.
|
| - */
|
| - public boolean isInitialized() {
|
| - return mIsInitialized;
|
| + /** Sets the add-to-homescreen observer tracking the add-to-homescreen data fetch. */
|
| + public void setObserver(Observer observer) {
|
| + mObserver = observer;
|
| }
|
|
|
| /**
|
| * Puts the object in a state where it is safe to be destroyed.
|
| */
|
| public void destroy() {
|
| - nativeDestroy(mNativeAddToHomescreenDialogHelper);
|
| + nativeDestroy(mNativeAddToHomescreenManager);
|
|
|
| - // Make sure the callback isn't run if the tear down happens before
|
| - // onInitialized() is called.
|
| mObserver = null;
|
| - mNativeAddToHomescreenDialogHelper = 0;
|
| + mNativeAddToHomescreenManager = 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(mNativeAddToHomescreenManager, userRequestedTitle);
|
| }
|
|
|
| - @CalledByNative
|
| - private void onIconAvailable(Bitmap icon) {
|
| - mIsInitialized = true;
|
| - mObserver.onIconAvailable(icon);
|
| + 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);
|
| + setObserver(dialog);
|
| + }
|
| +
|
| + @CalledByNative
|
| + private void onUserTitleAvailable(String title) {
|
| + mObserver.onUserTitleAvailable(title);
|
| + }
|
| +
|
| + @CalledByNative
|
| + private void onReadyToAdd(Bitmap icon) {
|
| + mObserver.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 nativeAddToHomescreenManager, String userRequestedTitle);
|
| + private native void nativeDestroy(long nativeAddToHomescreenManager);
|
| }
|
|
|