Commit a58ef569 authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

cct example: add option to launch in incognito

While this now only works for 1p, I'm assuming eventually we'll open up
cct incognito to all, so that this will just work.

BUG=1023759
TEST=none

Change-Id: I21672e863ed5dc2d2d9174ee09295f0cb3c54439
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2581447
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835674}
parent 2966c7f8
...@@ -63,6 +63,7 @@ public class MainActivity ...@@ -63,6 +63,7 @@ public class MainActivity
private Button mWarmupButton; private Button mWarmupButton;
private Button mMayLaunchButton; private Button mMayLaunchButton;
private Button mLaunchButton; private Button mLaunchButton;
private Button mLaunchIncognitoButton;
private MediaPlayer mMediaPlayer; private MediaPlayer mMediaPlayer;
/** /**
...@@ -108,12 +109,14 @@ public class MainActivity ...@@ -108,12 +109,14 @@ public class MainActivity
mWarmupButton = (Button) findViewById(R.id.warmup_button); mWarmupButton = (Button) findViewById(R.id.warmup_button);
mMayLaunchButton = (Button) findViewById(R.id.may_launch_button); mMayLaunchButton = (Button) findViewById(R.id.may_launch_button);
mLaunchButton = (Button) findViewById(R.id.launch_button); mLaunchButton = (Button) findViewById(R.id.launch_button);
mLaunchIncognitoButton = findViewById(R.id.launch_incognito_button);
Spinner spinner = (Spinner) findViewById(R.id.spinner); Spinner spinner = (Spinner) findViewById(R.id.spinner);
mEditText.requestFocus(); mEditText.requestFocus();
mConnectButton.setOnClickListener(this); mConnectButton.setOnClickListener(this);
mWarmupButton.setOnClickListener(this); mWarmupButton.setOnClickListener(this);
mMayLaunchButton.setOnClickListener(this); mMayLaunchButton.setOnClickListener(this);
mLaunchButton.setOnClickListener(this); mLaunchButton.setOnClickListener(this);
mLaunchIncognitoButton.setOnClickListener(this);
mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace); mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace);
findViewById(R.id.register_twa_service).setOnClickListener(this); findViewById(R.id.register_twa_service).setOnClickListener(this);
...@@ -227,7 +230,7 @@ public class MainActivity ...@@ -227,7 +230,7 @@ public class MainActivity
boolean success = false; boolean success = false;
if (mClient != null) success = session.mayLaunchUrl(Uri.parse(url), null, null); if (mClient != null) success = session.mayLaunchUrl(Uri.parse(url), null, null);
if (!success) mMayLaunchButton.setEnabled(false); if (!success) mMayLaunchButton.setEnabled(false);
} else if (viewId == R.id.launch_button) { } else if (viewId == R.id.launch_button || viewId == R.id.launch_incognito_button) {
CustomTabsSession session = getSession(); CustomTabsSession session = getSession();
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session);
builder.setToolbarColor(Color.parseColor(TOOLBAR_COLOR)).setShowTitle(true); builder.setToolbarColor(Color.parseColor(TOOLBAR_COLOR)).setShowTitle(true);
...@@ -239,6 +242,10 @@ public class MainActivity ...@@ -239,6 +242,10 @@ public class MainActivity
builder.setCloseButtonIcon( builder.setCloseButtonIcon(
BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back)); BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back));
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
// NOTE: opening in incognito may be restricted. This assumes it is not.
customTabsIntent.intent.putExtra(
"com.google.android.apps.chrome.EXTRA_OPEN_NEW_INCOGNITO_TAB",
viewId == R.id.launch_incognito_button);
if (session != null) { if (session != null) {
CustomTabsHelper.addKeepAliveExtra(this, customTabsIntent.intent); CustomTabsHelper.addKeepAliveExtra(this, customTabsIntent.intent);
} else { } else {
...@@ -285,6 +292,7 @@ public class MainActivity ...@@ -285,6 +292,7 @@ public class MainActivity
mWarmupButton.setEnabled(true); mWarmupButton.setEnabled(true);
mMayLaunchButton.setEnabled(true); mMayLaunchButton.setEnabled(true);
mLaunchButton.setEnabled(true); mLaunchButton.setEnabled(true);
mLaunchIncognitoButton.setEnabled(true);
} }
@Override @Override
...@@ -293,6 +301,7 @@ public class MainActivity ...@@ -293,6 +301,7 @@ public class MainActivity
mWarmupButton.setEnabled(false); mWarmupButton.setEnabled(false);
mMayLaunchButton.setEnabled(false); mMayLaunchButton.setEnabled(false);
mLaunchButton.setEnabled(false); mLaunchButton.setEnabled(false);
mLaunchIncognitoButton.setEnabled(false);
mClient = null; mClient = null;
} }
} }
...@@ -95,6 +95,15 @@ ...@@ -95,6 +95,15 @@
android:text="@string/launch_button_text" android:text="@string/launch_button_text"
android:enabled="true" /> android:enabled="true" />
<Button
android:id="@+id/launch_incognito_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textAllCaps="false"
android:text="@string/launch_incognito_button_text"
android:enabled="true" />
<Button <Button
android:id="@+id/launch_browser_actions_button" android:id="@+id/launch_browser_actions_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
<string name="warmup_button_text">Warmup Chrome</string> <string name="warmup_button_text">Warmup Chrome</string>
<string name="may_launch_button_text">May Launch URL</string> <string name="may_launch_button_text">May Launch URL</string>
<string name="launch_button_text">Launch URL in a Chrome Custom Tab</string> <string name="launch_button_text">Launch URL in a Chrome Custom Tab</string>
<string name="launch_incognito_button_text">Launch URL in an incognito Chrome Custom Tab</string>
<string name="connect_button_text">Connect to the service</string> <string name="connect_button_text">Connect to the service</string>
<string name="launch_browser_actions_button_text">Launch URL in Browser Actions Context Menu</string> <string name="launch_browser_actions_button_text">Launch URL in Browser Actions Context Menu</string>
<string name="register_twa_service">Register TrustedWebActivityService</string> <string name="register_twa_service">Register TrustedWebActivityService</string>
......
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