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

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

Issue 1288903002: Refactor ShortcutHelper and merge in BookmarkUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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/ShortcutHelper.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
index 128138290de6f34fdc95594345517f268ce4af3d..c5023a9f33bee8952a9353a03582392e48b0d52f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
@@ -16,9 +16,7 @@ import org.chromium.base.ApplicationStatus;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
-import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebappLauncherActivity;
-import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.common.ScreenOrientationConstants;
import java.io.ByteArrayOutputStream;
@@ -43,15 +41,6 @@ public class ShortcutHelper {
// This value is equal to kInvalidOrMissingThemeColor in the C++ content::Manifest struct.
public static final long THEME_COLOR_INVALID_OR_MISSING = ((long) Integer.MAX_VALUE) + 1;
- /** Observes the data fetching pipeline. */
- public interface ShortcutHelperObserver {
- /** 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);
- }
-
/** Broadcasts Intents out Android for adding the shortcut. */
public static class Delegate {
/**
@@ -73,47 +62,6 @@ public class ShortcutHelper {
private static Delegate sDelegate = new Delegate();
- private final Context mAppContext;
- private final Tab mTab;
-
- private ShortcutHelperObserver mObserver;
- private boolean mIsInitialized;
- private long mNativeShortcutHelper;
-
- public ShortcutHelper(Context appContext, Tab tab) {
- mAppContext = appContext;
- 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(ShortcutHelperObserver observer) {
- mObserver = observer;
- mNativeShortcutHelper = nativeInitialize(mTab.getWebContents());
- }
-
- /**
- * Returns whether the object is initialized.
- */
- public boolean isInitialized() {
- return mIsInitialized;
- }
-
- /**
- * Puts the object in a state where it is safe to be destroyed.
- */
- public void destroy() {
- nativeDestroy(mNativeShortcutHelper);
-
- // Make sure the callback isn't run if the tear down happens before
- // onInitialized() is called.
- mObserver = null;
- mNativeShortcutHelper = 0;
- }
-
/**
* Sets the delegate to use.
*/
@@ -122,35 +70,6 @@ public class ShortcutHelper {
sDelegate = delegate;
}
- @CalledByNative
- private void onUserTitleAvailable(String title) {
- mObserver.onUserTitleAvailable(title);
- }
-
- @CalledByNative
- private void onIconAvailable(Bitmap icon) {
- mObserver.onIconAvailable(icon);
- mIsInitialized = true;
- }
-
- /**
- * Adds a shortcut for the current Tab.
- * @param userRequestedTitle Updated title for the shortcut.
- */
- public void addShortcut(String userRequestedTitle) {
- nativeAddShortcut(mNativeShortcutHelper, userRequestedTitle);
- }
-
- /**
- * Creates an icon that is acceptable to show on the launcher.
- */
- @CalledByNative
- private static Bitmap finalizeLauncherIcon(
- String url, Bitmap icon, int red, int green, int blue) {
- return BookmarkUtils.createLauncherIcon(
- ApplicationStatus.getApplicationContext(), icon, url, red, green, blue);
- }
-
/**
* Called when we have to fire an Intent to add a shortcut to the homescreen.
* If the webpage indicated that it was capable of functioning as a webapp, it is added as a
@@ -221,8 +140,4 @@ public class ShortcutHelper {
byte[] mac = WebappAuthenticator.getMacForUrl(context, url);
return Base64.encodeToString(mac, Base64.DEFAULT);
}
-
- private native long nativeInitialize(WebContents webContents);
- private native void nativeAddShortcut(long nativeShortcutHelper, String userRequestedTitle);
- private native void nativeDestroy(long nativeShortcutHelper);
}

Powered by Google App Engine
This is Rietveld 408576698