Bug 1395841 - Part 2: Support creating a shortcut from page option in menu. r=snorp
authorJing-wei Wu <topwu.tw@gmail.com>
Thu, 28 Sep 2017 10:57:48 +0800
changeset 683964 8bfc3d92c6ef95c2c7e22ca6f89e9d6a9b4359c7
parent 683963 e12e4ab70862611b6e7b12d9837dc100adbc9175
child 683965 f8f8312e68b67ef1128b2d9ac1194c320f6efa52
push id85526
push userbmo:mozilla@hocat.ca
push dateFri, 20 Oct 2017 17:29:17 +0000
reviewerssnorp
bugs1395841
milestone58.0a1
Bug 1395841 - Part 2: Support creating a shortcut from page option in menu. r=snorp When page option 'add page shortcut' is clicked, creating a shortcut(not PWA) on launcher. Also make sure that heavy tasks are executed in background thread. MozReview-Commit-ID: 8KtwdXENtEd
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.java
mobile/android/base/java/org/mozilla/gecko/delegates/BookmarkStateChangeDelegate.java
mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -1501,17 +1501,17 @@ public class BrowserApp extends GeckoApp
             final String title = tab.getDisplayTitle();
             if (url == null || title == null) {
                 return true;
             }
 
             ThreadUtils.postToBackgroundThread(new Runnable() {
                 @Override
                 public void run() {
-                    GeckoApplication.createShortcut(title, url);
+                    GeckoApplication.createBrowserShortcut(title, url);
                 }
             });
 
             Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.CONTEXT_MENU,
                 getResources().getResourceEntryName(itemId));
             return true;
         }
 
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -42,16 +42,17 @@ import org.mozilla.gecko.util.ActivityUt
 import org.mozilla.gecko.telemetry.TelemetryBackgroundReceiver;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.PRNGFixes;
 import org.mozilla.gecko.util.ShortcutUtils;
 import org.mozilla.gecko.util.ThreadUtils;
+import org.mozilla.gecko.util.UIAsyncTask;
 
 import java.io.File;
 import java.lang.reflect.Method;
 import java.util.UUID;
 
 public class GeckoApplication extends Application
                               implements HapticFeedbackDelegate {
     private static final String LOG_TAG = "GeckoApplication";
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.java
@@ -279,17 +279,22 @@ public abstract class ActivityStreamCont
                 });
                 break;
 
             case R.id.copy_url:
                 Clipboard.setText(item.getUrl());
                 break;
 
             case R.id.add_homescreen:
-                GeckoApplication.createShortcut(item.getTitle(), item.getUrl());
+                ThreadUtils.postToBackgroundThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        GeckoApplication.createBrowserShortcut(item.getTitle(), item.getUrl());
+                    }
+                });
                 break;
 
             case R.id.open_new_tab:
                 onUrlOpenInBackgroundListener.onUrlOpenInBackgroundWithReferrer(item.getUrl(), referrerUri,
                         EnumSet.noneOf(HomePager.OnUrlOpenInBackgroundListener.Flags.class));
                 break;
 
             case R.id.open_new_private_tab:
--- a/mobile/android/base/java/org/mozilla/gecko/delegates/BookmarkStateChangeDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/delegates/BookmarkStateChangeDelegate.java
@@ -179,17 +179,17 @@ public class BookmarkStateChangeDelegate
 
                     final String url = tab.getURL();
                     final String title = tab.getDisplayTitle();
 
                     if (url != null && title != null) {
                         ThreadUtils.postToBackgroundThread(new Runnable() {
                             @Override
                             public void run() {
-                                GeckoApplication.createShortcut(title, url);
+                                GeckoApplication.createBrowserShortcut(title, url);
                             }
                         });
                     }
                 }
             }
         });
 
         final PromptListItem[] items = new PromptListItem[2];
--- a/mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
@@ -304,18 +304,17 @@ public abstract class HomeFragment exten
                 return false;
             }
 
             // Fetch an icon big enough for use as a home screen icon.
             final String displayTitle = info.getDisplayTitle();
             ThreadUtils.postToBackgroundThread(new Runnable() {
                 @Override
                 public void run() {
-                    GeckoApplication.createShortcut(displayTitle, info.url);
-
+                    GeckoApplication.createBrowserShortcut(displayTitle, info.url);
                 }
             });
 
             Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.CONTEXT_MENU, "home_add_to_launcher");
             return true;
         }
 
         if (itemId == R.id.home_open_private_tab || itemId == R.id.home_open_new_tab) {
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
@@ -115,29 +115,27 @@ public class HomeScreenPrompt extends Lo
             }
         });
     }
 
     private void addToHomeScreen() {
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
-                GeckoApplication.createShortcut(title, url);
+                GeckoApplication.createBrowserShortcut(title, url);
 
                 Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, TELEMETRY_EXTRA);
 
                 ActivityUtils.goToHomeScreen(HomeScreenPrompt.this);
 
                 finish();
             }
         });
     }
 
-
-
     private void loadShortcutIcon() {
         Icons.with(this)
                 .pageUrl(url)
                 .skipNetwork()
                 .skipMemory()
                 .forLauncherIcon()
                 .build()
                 .execute(this);