Bug 1367079 - 2. Move Share:Text listener to GeckoApplication; r=snorp
authorJim Chen <nchen@mozilla.com>
Thu, 14 Sep 2017 17:50:58 -0400
changeset 665156 1af8aae9f13783e8497f9a0ca91a07e0524503de
parent 665155 58e575edf398a9657282842eb798512b023f16df
child 665157 7f1d3a461631ba73c54fc3079dbc933889a711b3
push id79943
push userbmo:tchiovoloni@mozilla.com
push dateThu, 14 Sep 2017 23:59:48 +0000
reviewerssnorp
bugs1367079
milestone57.0a1
Bug 1367079 - 2. Move Share:Text listener to GeckoApplication; r=snorp Move the "Share:Text" event listener from GeckoApp to GeckoApplication, so ActionBarHandler.js can use it for the Share action from any window. MozReview-Commit-ID: 8w1llJy4pwy
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -734,28 +734,16 @@ public abstract class GeckoApp extends G
 
         } else if ("Permissions:Data".equals(event)) {
             final GeckoBundle[] permissions = message.getBundleArray("permissions");
             showSiteSettingsDialog(permissions);
 
         } else if ("PrivateBrowsing:Data".equals(event)) {
             mPrivateBrowsingSession = message.getString("session");
 
-        } else if ("Share:Text".equals(event)) {
-            final String text = message.getString("text");
-            final Tab tab = Tabs.getInstance().getSelectedTab();
-            String title = "";
-            if (tab != null) {
-                title = tab.getDisplayTitle();
-            }
-            IntentHelper.openUriExternal(text, "text/plain", "", "", Intent.ACTION_SEND, title, false);
-
-            // Context: Sharing via chrome list (no explicit session is active)
-            Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.LIST, "text");
-
         } else if ("SystemUI:Visibility".equals(event)) {
             if (message.getBoolean("visible", true)) {
                 mMainLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
             } else {
                 mMainLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
             }
 
         } else if ("ToggleChrome:Focus".equals(event)) {
@@ -1223,17 +1211,16 @@ public abstract class GeckoApp extends G
             "DevToolsAuth:Scan",
             "DOMFullScreen:Start",
             "DOMFullScreen:Stop",
             "Mma:reader_available",
             "Mma:web_save_image",
             "Mma:web_save_media",
             "Permissions:Data",
             "PrivateBrowsing:Data",
-            "Share:Text",
             "SystemUI:Visibility",
             "ToggleChrome:Focus",
             "ToggleChrome:Hide",
             "ToggleChrome:Show",
             null);
 
         Tabs.getInstance().attachToContext(this, mLayerView, getAppEventDispatcher());
         Tabs.registerOnTabsChangedListener(this);
@@ -2224,17 +2211,16 @@ public abstract class GeckoApp extends G
             "DevToolsAuth:Scan",
             "DOMFullScreen:Start",
             "DOMFullScreen:Stop",
             "Mma:reader_available",
             "Mma:web_save_image",
             "Mma:web_save_media",
             "Permissions:Data",
             "PrivateBrowsing:Data",
-            "Share:Text",
             "SystemUI:Visibility",
             "ToggleChrome:Focus",
             "ToggleChrome:Hide",
             "ToggleChrome:Show",
             null);
 
         if (mPromptService != null) {
             mPromptService.destroy();
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -282,16 +282,17 @@ public class GeckoApplication extends Ap
 
         IntentHelper.init();
 
         final EventListener listener = new EventListener();
         EventDispatcher.getInstance().registerUiThreadListener(listener,
                 "Gecko:Exited",
                 "RuntimePermissions:Check",
                 "Snackbar:Show",
+                "Share:Text",
                 null);
         EventDispatcher.getInstance().registerBackgroundThreadListener(listener,
                 "Profile:Create",
                 null);
 
         super.onCreate();
     }
 
@@ -441,16 +442,26 @@ public class GeckoApplication extends Ap
                            })
                            .run(new Runnable() {
                                @Override
                                public void run() {
                                    callback.sendSuccess(true);
                                }
                            });
 
+            } else if ("Share:Text".equals(event)) {
+                final String text = message.getString("text");
+                final String title = message.getString("title", "");
+                IntentHelper.openUriExternal(text, "text/plain", "", "",
+                                             Intent.ACTION_SEND, title, false);
+
+                // Context: Sharing via chrome list (no explicit session is active)
+                Telemetry.sendUIEvent(TelemetryContract.Event.SHARE,
+                                      TelemetryContract.Method.LIST, "text");
+
             } else if ("Snackbar:Show".equals(event)) {
                 final Activity currentActivity =
                         GeckoActivityMonitor.getInstance().getCurrentActivity();
                 if (currentActivity == null) {
                     if (callback != null) {
                         callback.sendError("No activity");
                     }
                     return;