Bug 1423587 - PWA with expired security certificate should open in browser. r=maliu
authorNevin Chen <cnevinchen@gmail.com>
Sat, 06 Jan 2018 18:56:36 +0800
changeset 453251 07d782c8eb49a26702241461f7144b1741b922da
parent 453250 3453a38c05a3fbcb1935283233d23984d88ea2ef
child 453252 9f05450f256c8a9006a8473b3bee5bde214890e7
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaliu
bugs1423587
milestone59.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 1423587 - PWA with expired security certificate should open in browser. r=maliu MozReview-Commit-ID: 1XR3OcP2PpY
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -23,16 +23,17 @@ import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.view.ActionMode;
 import android.support.v7.widget.Toolbar;
 import android.util.Log;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import org.mozilla.gecko.ActivityHandlerHelper;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.DoorHangerPopup;
 import org.mozilla.gecko.FormAssistPopup;
 import org.mozilla.gecko.GeckoAccessibility;
 import org.mozilla.gecko.GeckoScreenOrientation;
@@ -99,16 +100,55 @@ public class WebAppActivity extends AppC
         setContentView(R.layout.webapp_activity);
         mGeckoView = (GeckoView) findViewById(R.id.pwa_gecko_view);
 
         mGeckoSession = new GeckoSession();
         mGeckoView.setSession(mGeckoSession);
 
         mGeckoSession.setNavigationListener(this);
         mGeckoSession.setContentListener(this);
+        mGeckoSession.setProgressListener(new GeckoSession.ProgressListener() {
+            @Override
+            public void onPageStart(GeckoSession session, String url) {
+
+            }
+
+            @Override
+            public void onPageStop(GeckoSession session, boolean success) {
+
+            }
+
+            @Override
+            public void onSecurityChange(GeckoSession session, SecurityInformation security) {
+                int message;
+                if (!security.isSecure) {
+                    if (SecurityInformation.CONTENT_LOADED == security.mixedModeActive) {
+                        // Active Mixed Content loaded because user has disabled blocking.
+                        message = R.string.mixed_content_protection_disabled;
+                    } else if (SecurityInformation.CONTENT_LOADED == security.mixedModePassive) {
+                        // Passive Mixed Content loaded.
+                        if (SecurityInformation.CONTENT_BLOCKED == security.mixedModeActive) {
+                            message = R.string.mixed_content_blocked_some;
+                        } else {
+                            message = R.string.mixed_content_display_loaded;
+                        }
+                    } else {
+                        // Unencrypted connection with no mixed content.
+                        message = R.string.identity_connection_insecure;
+                    }
+                    fallbackToFennec(getString(message));
+                } else {
+                    if (security.isException) {
+                        message = R.string.identity_connection_insecure;
+                        fallbackToFennec(getString(message));
+                    }
+                }
+
+            }
+        });
 
         GeckoAccessibility.setDelegate(mGeckoView);
 
         mPromptService = new PromptService(this, mGeckoView.getEventDispatcher());
         mDoorHangerPopup = new DoorHangerPopup(this, mGeckoView.getEventDispatcher());
 
         mTextSelection = TextSelection.Factory.create(mGeckoView, this);
         mTextSelection.create();
@@ -119,43 +159,51 @@ public class WebAppActivity extends AppC
             GeckoSessionSettings.USE_REMOTE_DEBUGGER,
             GeckoSharedPrefs.forApp(this).getBoolean(
                 GeckoPreferences.PREFS_DEVTOOLS_REMOTE_USB_ENABLED, false));
 
         try {
             mManifest = WebAppManifest.fromFile(getIntent().getStringExtra(MANIFEST_URL),
                                                 getIntent().getStringExtra(MANIFEST_PATH));
         } catch (Exception e) {
-            Log.w(LOGTAG, "Cannot retrieve manifest, launching in Firefox");
-            try {
-                Intent intent = new Intent(this, BrowserApp.class);
-                intent.setAction(Intent.ACTION_VIEW);
-                if (getIntent().getData() != null) {
-                    intent.setData(getIntent().getData());
-                    intent.setPackage(getPackageName());
-                    startActivity(intent);
-                }
-            } catch (Exception e2) {
-                Log.e(LOGTAG, "Failed to fall back to launching in Firefox");
-            }
-            finish();
+            Log.w(LOGTAG, "Cannot retrieve manifest, launching in Firefox:" + e);
+            fallbackToFennec(null);
             return;
         }
 
         updateFromManifest();
 
         mGeckoSession.loadUri(mManifest.getStartUri().toString());
 
         mFormAssistPopup = (FormAssistPopup) findViewById(R.id.pwa_form_assist_popup);
         mFormAssistPopup.create(mGeckoView);
 
 
 
     }
 
+    private void fallbackToFennec(String message) {
+        if (message != null) {
+            Toast.makeText(this, message, Toast.LENGTH_LONG).show();
+        }
+
+        try {
+            Intent intent = new Intent(this, BrowserApp.class);
+            intent.setAction(Intent.ACTION_VIEW);
+            if (getIntent().getData() != null) {
+                intent.setData(getIntent().getData());
+                intent.setPackage(getPackageName());
+                startActivity(intent);
+            }
+        } catch (Exception e2) {
+            Log.e(LOGTAG, "Failed to fall back to launching in Firefox");
+        }
+        finish();
+    }
+
     @Override
     public void onResume() {
         mGeckoSession.setActive(true);
         super.onResume();
     }
 
     @Override
     public void onPause() {