Bug 1173147 - Explicitly show Android chooser when there is more than one intent URI match in pb. r=sebastian
☠☠ backed out by 9d8432afaf64 ☠ ☠
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 23 Sep 2015 14:48:28 -0700
changeset 266927 e0db94364c19e09a6bb8ac8a8b2c3ca49c97e0c0
parent 266926 afd881fc08a25c38a57343434ba58becb836ffa0
child 266928 b830ba785dfe4c6bdf7ee6fb2a83f19497163fe2
push id29503
push usercbook@mozilla.com
push dateFri, 09 Oct 2015 09:36:47 +0000
treeherdermozilla-central@462074ffada4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1173147
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1173147 - Explicitly show Android chooser when there is more than one intent URI match in pb. r=sebastian After this changeset series, the expected flow for web links is: * If not pb, open the Intent URI * If pb and no matching applications, open about:neterror * If pb and one matching application, show this dialog * If pb and > 1 matching application, show the Android system chooser When the user explicitly chooses to share (and thus should infer they're exiting Private Browsing), we don't show the dialog. Custom URIs sort of work: I tested `mailto` and it worked as expected but `tel` does not work as expected (i.e. it doesn't show the dialog). Perhaps there's an explicit "Open dialer" code path. To figure this out, I tested this patch against my Intent URI test page [1]. Decisions around explicitly showing the Android chooser: When there are multiple application matches to an Intent URI, we want to show the Android Intent Chooser. However, we have no way of distinguishing regular tabs from private tabs to the chooser. Thus, if a user chooses "Always" in regular browsing mode, the chooser will not be shown and the URL will be opened. Therefore we explicitly show the chooser (which notably does not have an "Always" option). [1]: https://people.mozilla.org/~mcomella/test/uri.html
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
mobile/android/base/widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -705,16 +705,24 @@ just addresses the organization to follo
 <!ENTITY find_matchcase "Aa">
 
 <!ENTITY intent_uri_cannot_open "Cannot open link">
 <!-- LOCALIZATION NOTE (intent_uri_private_browsing_prompt): This string will
      appear in an alert when a user, who is currently in private browsing,
      clicks a link that will open an external Android application. "&formatS;"
      will be replaced with the name of the application that will be opened. -->
 <!ENTITY intent_uri_private_browsing_prompt "This link will open in &formatS;. Are you sure you want to exit Private Browsing?">
+<!-- LOCALIZATION NOTE (intent_uri_private_browsing_multiple_match_title): This
+     string will appear as the title of an alert when a user, who is currently
+     in private browsing, clicks a link that will open an external Android
+     application and more than one application is available to open that link.
+     We don't have control over the style of this dialog and it looks
+     unpolished when this string is longer than one line so ideally keep it
+     short! -->
+<!ENTITY intent_uri_private_browsing_multiple_match_title "Exit Private Browsing?">
 
 <!-- DevTools Authentication -->
 <!-- LOCALIZATION NOTE (devtools_auth_scan_header): This header text appears
      above a QR reader that is actively scanning for QR codes.  The expected QR
      code has already been displayed by the client trying to connect (such as
      desktop Firefox via WebIDE), so you just need to aim this device at the QR
      code. -->
 <!ENTITY devtools_auth_scan_header "Scanning for the QR code displayed on your other device">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -591,11 +591,12 @@
   <string name="colon">&colon;</string>
 
   <string name="percent">&percent;</string>
 
   <string name="remote_tabs_last_synced">&remote_tabs_last_synced;</string>
 
   <string name="intent_uri_cannot_open">&intent_uri_cannot_open;</string>
   <string name="intent_uri_private_browsing_prompt">&intent_uri_private_browsing_prompt;</string>
+  <string name="intent_uri_private_browsing_multiple_match_title">&intent_uri_private_browsing_multiple_match_title;</string>
 
   <string name="devtools_auth_scan_header">&devtools_auth_scan_header;</string>
 </resources>
--- a/mobile/android/base/widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java
+++ b/mobile/android/base/widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java
@@ -75,19 +75,24 @@ public class ExternalIntentDuringPrivate
             args.putCharSequence(KEY_APPLICATION_NAME, matchingActivities.get(0).loadLabel(pm));
             args.putParcelable(KEY_INTENT, intent);
             fragment.setArguments(args);
 
             fragment.show(fragmentManager, FRAGMENT_TAG);
             // We don't know the results of the user interaction with the fragment so just return true.
             return true;
         } else if (matchingActivities.size() > 1) {
-            // Android chooser dialog will be shown, which should make the users
-            // aware they're entering a new application from private browsing.
-            return ActivityHandlerHelper.startIntentAndCatch(LOGTAG, context, intent);
+            // We want to show the Android Intent Chooser. However, we have no way of distinguishing regular tabs from
+            // private tabs to the chooser. Thus, if a user chooses "Always" in regular browsing mode, the chooser will
+            // not be shown and the URL will be opened. Therefore we explicitly show the chooser (which notably does not
+            // have an "Always" option).
+            final String androidChooserTitle =
+                    context.getResources().getString(R.string.intent_uri_private_browsing_multiple_match_title);
+            final Intent chooserIntent = Intent.createChooser(intent, androidChooserTitle);
+            return ActivityHandlerHelper.startIntentAndCatch(LOGTAG, context, chooserIntent);
         } else {
             // Normally, we show about:neterror when an Intent does not resolve
             // but we don't have the references here to do that so log instead.
             Log.w(LOGTAG, "showDialogOrAndroidChooser unexpectedly called with Intent that does not resolve");
             return false;
         }
     }
 }