Skip to content

Commit

Permalink
Preemptive null checks to avoid crashes in the TitleBar widget (#2643)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Jan 14, 2020
1 parent 3177b95 commit 5797d75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
@@ -1,6 +1,5 @@
package org.mozilla.vrbrowser.browser.engine;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
Expand All @@ -10,20 +9,15 @@
import androidx.annotation.Nullable;

import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoRuntimeSettings;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.browser.BookmarksStore;
import org.mozilla.vrbrowser.browser.HistoryStore;
import org.mozilla.vrbrowser.browser.PermissionDelegate;
import org.mozilla.vrbrowser.browser.Services;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.crashreporting.CrashReporterService;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.security.KeyStore;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -73,6 +67,7 @@ public void initializeStores(Context context) {
mHistoryStore = new HistoryStore(context);
}

@NonNull
private Session addSession(@NonNull Session aSession) {
aSession.setPermissionDelegate(this);
aSession.addNavigationListener(mServices);
Expand All @@ -81,19 +76,23 @@ private Session addSession(@NonNull Session aSession) {
return aSession;
}

@NonNull
public Session createSession(boolean aPrivateMode) {
SessionSettings settings = new SessionSettings(new SessionSettings.Builder().withDefaultSettings(mContext).withPrivateBrowsing(aPrivateMode));
return createSession(settings, Session.SESSION_OPEN);
}

@NonNull
/* package */ Session createSession(@NonNull SessionSettings aSettings, @Session.SessionOpenModeFlags int aOpenMode) {
return addSession(new Session(mContext, mRuntime, aSettings, aOpenMode));
}

@NonNull
public Session createSuspendedSession(SessionState aRestoreState) {
return addSession(new Session(mContext, mRuntime, aRestoreState));
}

@NonNull
public Session createSuspendedSession(final String aUri, final boolean aPrivateMode) {
SessionState state = new SessionState();
state.mUri = aUri;
Expand Down
Expand Up @@ -167,7 +167,8 @@ public void setURL(String urlString) {
}

public void setIsInsecure(boolean aIsInsecure) {
if (mAttachedWindow.getSession().getCurrentUri() != null &&
if (mAttachedWindow != null && mAttachedWindow.getSession() != null &&
mAttachedWindow.getSession().getCurrentUri() != null &&
!(mAttachedWindow.getSession().getCurrentUri().startsWith("data") &&
mAttachedWindow.getSession().isPrivateMode())) {
mBinding.insecureIcon.setVisibility(aIsInsecure ? View.VISIBLE : View.GONE);
Expand All @@ -182,7 +183,7 @@ public void mediaAvailabilityChanged(boolean available) {
if (mMedia != null) {
mMedia.removeMediaListener(mMediaDelegate);
}
if (available) {
if (available && mAttachedWindow != null && mAttachedWindow.getSession() != null) {
mMedia = mAttachedWindow.getSession().getFullScreenVideo();
if (mMedia != null) {
mMedia.addMediaListener(mMediaDelegate);
Expand Down
Expand Up @@ -681,6 +681,7 @@ public void updateTitleBarMediaStatus() {
}
}

@Nullable
public Session getSession() {
return mSession;
}
Expand Down

0 comments on commit 5797d75

Please sign in to comment.