Skip to content

Commit

Permalink
Add the ability to start chrome:// pages via an intent.
Browse files Browse the repository at this point in the history
BUG=481801

Review URL: https://codereview.chromium.org/1126983005

Cr-Commit-Position: refs/heads/master@{#328821}
  • Loading branch information
tedchoc authored and Commit bot committed May 7, 2015
1 parent 5b3723e commit 3f375f3
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ private static ComponentName getFakeComponentName(String packageName) {
public static final String GOOGLECHROME_NAVIGATE_PREFIX =
GOOGLECHROME_SCHEME + "://navigate?url=";

/**
* The class name to be specified in the ComponentName for Intents that are creating a new
* tab (regardless of whether the user is in document or tabbed mode).
*/
// TODO(tedchoc): Remove this and directly reference the Launcher activity when that becomes
// publicly available.
private static final String TAB_ACTIVITY_COMPONENT_CLASS_NAME =
"com.google.android.apps.chrome.Main";

private static boolean sTestIntentsEnabled;

private final IntentHandlerDelegate mDelegate;
Expand Down Expand Up @@ -342,8 +351,38 @@ private static PendingIntent getAuthenticationToken(Context appContext) {
* token.
*/
public static void startActivityForTrustedIntent(Intent intent, Context context) {
startActivityForTrustedIntentInternal(intent, context, null);
}

/**
* Start the activity that handles launching tabs in Chrome given the trusted intent.
*
* This allows specifying URLs that chrome:// handles internally, but does not expose in
* intent-filters for global use.
*
* To make sure the intent is not dropped by Chrome, we send along an authentication token to
* identify ourselves as a trusted sender. The method {@link #shouldIgnoreIntent} validates the
* token.
*/
public static void startChromeLauncherActivityForTrustedIntent(Intent intent, Context context) {
// Specify the exact component that will handle creating a new tab. This allows specifying
// URLs that are not exposed in the intent filters (i.e. chrome://).
startActivityForTrustedIntentInternal(intent, context, new ComponentName(
context.getPackageName(), TAB_ACTIVITY_COMPONENT_CLASS_NAME));
}

private static void startActivityForTrustedIntentInternal(
Intent intent, Context context, ComponentName componentName) {
// The caller might want to re-use the Intent, so we'll use a copy.
Intent copiedIntent = new Intent(intent);

if (componentName != null) {
assert copiedIntent.getComponent() == null;
// Specify the exact component that will handle creating a new tab. This allows
// specifying URLs that are not exposed in the intent filters (i.e. chrome://).
copiedIntent.setComponent(componentName);
}

addTrustedIntentExtras(copiedIntent, context);

// Make sure we use the application context.
Expand Down

0 comments on commit 3f375f3

Please sign in to comment.