Bug 1423587 - PWA with expired security certificate should open in browser. r?maliu
MozReview-Commit-ID: 1XR3OcP2PpY
--- 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() {