Commit 2d61dc7b authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: move incognito assertion checks

The current checks mean WebLayer has to be loaded sooner then we would
like. This moves the checks to a later point. I wanted to keep the
exception as it seems very important to ensure that if code thinks it
is creating an incognito profile, it actually gets one.

BUG=1142989

Change-Id: Ic57304a8c3cfaeeba06e231f32b8dbf50456788e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527624
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825642}
parent c6948711
......@@ -11,6 +11,7 @@ import android.os.RemoteException;
import androidx.annotation.NonNull;
import org.chromium.weblayer_private.interfaces.APICallException;
import org.chromium.weblayer_private.interfaces.BrowserFragmentArgs;
import org.chromium.weblayer_private.interfaces.IBrowserFragment;
import org.chromium.weblayer_private.interfaces.IRemoteFragment;
......@@ -67,12 +68,24 @@ public final class BrowserFragment extends RemoteFragment {
@Override
protected IRemoteFragment createRemoteFragment(Context appContext) {
Bundle args = getArguments();
if (args == null) {
throw new RuntimeException("BrowserFragment was created without arguments.");
}
try {
Bundle args = getArguments();
if (args == null) {
throw new RuntimeException("BrowserFragment was created without arguments.");
}
mWebLayer = WebLayer.loadSync(appContext);
} catch (Exception e) {
throw new RuntimeException("Failed to initialize WebLayer", e);
}
// Ideally this would be in WebLayer when the fragment is created, but at that time we don't
// want to trigger loading WebLayer.
if (args.getBoolean(BrowserFragmentArgs.IS_INCOGNITO, false)) {
String name = args.getString(BrowserFragmentArgs.PROFILE_NAME);
if (!"".equals(name) && WebLayer.getSupportedMajorVersionInternal() < 88) {
throw new UnsupportedOperationException("Named incognito profile requires 88");
}
}
try {
mImpl = mWebLayer.connectFragment(getRemoteFragmentClient(), args);
return mImpl.asRemoteFragment();
} catch (Exception e) {
......
......@@ -544,7 +544,8 @@ public class WebLayer {
* state.
*
* @throws UnsupportedOperationException If {@link params} is incognito and name is not empty
* and <= 88.
* and <= 88. In order for this function not to trigger loading of WebLayer the
* exception is thrown later on.
*
* @since 88
*/
......@@ -557,12 +558,8 @@ public class WebLayer {
private static Fragment createBrowserFragmentImpl(
@NonNull String profileName, @Nullable String persistenceId, boolean isIncognito) {
ThreadCheck.ensureOnUiThread();
if (WebLayer.getSupportedMajorVersionInternal() < 88 && isIncognito
&& !"".equals(profileName)) {
// Incognito profiles are only allowed to have non-empty names in >= 88.
throw new UnsupportedOperationException();
}
// Support for named incognito profiles was added in 88. Checking is done in
// BrowserFragment, as this code should not trigger loading WebLayer.
Bundle args = new Bundle();
args.putString(BrowserFragmentArgs.PROFILE_NAME, profileName);
if (persistenceId != null) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment