Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(899)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/document/ChromeLauncherActivity.java

Issue 1683533002: Herb: Show an icon allowing the user to open a tab in Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix back button Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.document; 5 package org.chromium.chrome.browser.document;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.app.ActivityManager; 10 import android.app.ActivityManager;
11 import android.app.ActivityManager.AppTask; 11 import android.app.ActivityManager.AppTask;
12 import android.app.ActivityManager.RecentTaskInfo; 12 import android.app.ActivityManager.RecentTaskInfo;
13 import android.app.ActivityOptions; 13 import android.app.ActivityOptions;
14 import android.app.Notification; 14 import android.app.Notification;
15 import android.app.PendingIntent; 15 import android.app.PendingIntent;
16 import android.app.SearchManager; 16 import android.app.SearchManager;
17 import android.content.ClipData; 17 import android.content.ClipData;
18 import android.content.Context; 18 import android.content.Context;
19 import android.content.Intent; 19 import android.content.Intent;
20 import android.content.pm.PackageManager; 20 import android.content.pm.PackageManager;
21 import android.graphics.Bitmap;
22 import android.graphics.BitmapFactory;
21 import android.net.Uri; 23 import android.net.Uri;
22 import android.os.Build; 24 import android.os.Build;
23 import android.os.Bundle; 25 import android.os.Bundle;
24 import android.os.TransactionTooLargeException; 26 import android.os.TransactionTooLargeException;
25 import android.provider.Browser; 27 import android.provider.Browser;
26 import android.support.customtabs.CustomTabsIntent; 28 import android.support.customtabs.CustomTabsIntent;
27 import android.text.TextUtils; 29 import android.text.TextUtils;
28 30
29 import org.chromium.base.ApiCompatibilityUtils; 31 import org.chromium.base.ApiCompatibilityUtils;
30 import org.chromium.base.ApplicationStatus; 32 import org.chromium.base.ApplicationStatus;
31 import org.chromium.base.CommandLineInitUtil; 33 import org.chromium.base.CommandLineInitUtil;
32 import org.chromium.base.Log; 34 import org.chromium.base.Log;
33 import org.chromium.base.TraceEvent; 35 import org.chromium.base.TraceEvent;
36 import org.chromium.chrome.R;
34 import org.chromium.chrome.browser.ChromeApplication; 37 import org.chromium.chrome.browser.ChromeApplication;
35 import org.chromium.chrome.browser.ChromeSwitches; 38 import org.chromium.chrome.browser.ChromeSwitches;
36 import org.chromium.chrome.browser.ChromeTabbedActivity; 39 import org.chromium.chrome.browser.ChromeTabbedActivity;
37 import org.chromium.chrome.browser.IntentHandler; 40 import org.chromium.chrome.browser.IntentHandler;
38 import org.chromium.chrome.browser.IntentHandler.TabOpenType; 41 import org.chromium.chrome.browser.IntentHandler.TabOpenType;
39 import org.chromium.chrome.browser.ShortcutHelper; 42 import org.chromium.chrome.browser.ShortcutHelper;
40 import org.chromium.chrome.browser.ShortcutSource; 43 import org.chromium.chrome.browser.ShortcutSource;
41 import org.chromium.chrome.browser.UrlConstants; 44 import org.chromium.chrome.browser.UrlConstants;
42 import org.chromium.chrome.browser.WarmupManager; 45 import org.chromium.chrome.browser.WarmupManager;
43 import org.chromium.chrome.browser.customtabs.CustomTabActivity; 46 import org.chromium.chrome.browser.customtabs.CustomTabActivity;
47 import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
44 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; 48 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler;
45 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; 49 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
46 import org.chromium.chrome.browser.metrics.LaunchMetrics; 50 import org.chromium.chrome.browser.metrics.LaunchMetrics;
47 import org.chromium.chrome.browser.metrics.StartupMetrics; 51 import org.chromium.chrome.browser.metrics.StartupMetrics;
48 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; 52 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
49 import org.chromium.chrome.browser.notifications.NotificationUIManager; 53 import org.chromium.chrome.browser.notifications.NotificationUIManager;
50 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; 54 import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
51 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza tions; 55 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza tions;
52 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 56 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
53 import org.chromium.chrome.browser.preferences.DocumentModeManager; 57 import org.chromium.chrome.browser.preferences.DocumentModeManager;
(...skipping 20 matching lines...) Expand all
74 */ 78 */
75 public class ChromeLauncherActivity extends Activity 79 public class ChromeLauncherActivity extends Activity
76 implements IntentHandler.IntentHandlerDelegate { 80 implements IntentHandler.IntentHandlerDelegate {
77 /** 81 /**
78 * Extra indicating launch mode used. 82 * Extra indicating launch mode used.
79 */ 83 */
80 public static final String EXTRA_LAUNCH_MODE = 84 public static final String EXTRA_LAUNCH_MODE =
81 "com.google.android.apps.chrome.EXTRA_LAUNCH_MODE"; 85 "com.google.android.apps.chrome.EXTRA_LAUNCH_MODE";
82 86
83 /** 87 /**
88 * Whether or not the toolbar should indicate that a tab was spawned by anot her Activity.
89 */
90 public static final String EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT =
Ian Wen 2016/02/09 20:30:49 So if this extra is set to false, when the user hi
gone 2016/02/09 21:21:32 Changed the behavior according to Chris' comment o
91 "org.chromium.chrome.browser.document.IS_ALLOWED_TO_RETURN_TO_PARENT ";
92
93 /**
84 * Action fired when the user selects the "Close all incognito tabs" notific ation. 94 * Action fired when the user selects the "Close all incognito tabs" notific ation.
85 */ 95 */
86 static final String ACTION_CLOSE_ALL_INCOGNITO = 96 static final String ACTION_CLOSE_ALL_INCOGNITO =
87 "com.google.android.apps.chrome.document.CLOSE_ALL_INCOGNITO"; 97 "com.google.android.apps.chrome.document.CLOSE_ALL_INCOGNITO";
88 98
89 private static final String TAG = "document_CLActivity"; 99 private static final String TAG = "document_CLActivity";
90 100
91 /** New instance should be launched in the foreground. */ 101 /** New instance should be launched in the foreground. */
92 public static final int LAUNCH_MODE_FOREGROUND = 0; 102 public static final int LAUNCH_MODE_FOREGROUND = 0;
93 103
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return false; 317 return false;
308 } else if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_DILL)) { 318 } else if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_DILL)) {
309 // Dill always opens View Intents in Custom Tabs -- even home screen shortcuts. 319 // Dill always opens View Intents in Custom Tabs -- even home screen shortcuts.
310 return true; 320 return true;
311 } else { 321 } else {
312 assert false; 322 assert false;
313 return false; 323 return false;
314 } 324 }
315 } 325 }
316 326
327 private void addHerbIntentExtras(Intent newIntent, Uri uri) {
328 Bundle herbBundle = new Bundle();
329
330 Bitmap herbIcon =
331 BitmapFactory.decodeResource(getResources(), R.drawable.btn_open _in_chrome);
332 herbBundle.putParcelable(CustomTabsIntent.KEY_ICON, herbIcon);
333
334 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
335 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
336 intent.putExtra(EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
337
338 PendingIntent pendingIntent =
339 PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ON E_SHOT);
340 herbBundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pendingInt ent);
341
342 herbBundle.putString(CustomTabsIntent.KEY_DESCRIPTION,
343 getResources().getString(R.string.menu_open_in_chrome));
344
345 newIntent.putExtra(CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE, herbBund le);
346 newIntent.putExtra(CustomTabIntentDataProvider.EXTRA_FINISH_ACTIVITY_ON_ ACTION, true);
347 }
348
317 /** 349 /**
318 * @return Whether the intent sent is for launching a Custom Tab. 350 * @return Whether the intent sent is for launching a Custom Tab.
319 */ 351 */
320 private boolean isCustomTabIntent() { 352 private boolean isCustomTabIntent() {
321 if (getIntent() == null || (!getIntent().hasExtra(CustomTabsIntent.EXTRA _SESSION) 353 if (getIntent() == null || (!getIntent().hasExtra(CustomTabsIntent.EXTRA _SESSION)
322 && !isIntentHandledByHerb())) { 354 && !isIntentHandledByHerb())) {
323 return false; 355 return false;
324 } 356 }
325 357
326 String url = IntentHandler.getUrlFromIntent(getIntent()); 358 String url = IntentHandler.getUrlFromIntent(getIntent());
327 if (url == null) return false; 359 if (url == null) return false;
328 360
329 if (!ChromePreferenceManager.getInstance(this).getCustomTabsEnabled()) r eturn false; 361 if (!ChromePreferenceManager.getInstance(this).getCustomTabsEnabled()) r eturn false;
330 return true; 362 return true;
331 } 363 }
332 364
333 /** 365 /**
334 * Handles launching a {@link CustomTabActivity}, which will sit on top of a client's activity 366 * Handles launching a {@link CustomTabActivity}, which will sit on top of a client's activity
335 * in the same task. 367 * in the same task.
336 */ 368 */
337 private void launchCustomTabActivity() { 369 private void launchCustomTabActivity() {
338 boolean handled = CustomTabActivity.handleInActiveContentIfNeeded(getInt ent()); 370 boolean handled = CustomTabActivity.handleInActiveContentIfNeeded(getInt ent());
339 if (handled) return; 371 if (handled) return;
340 372
341 // Create and fire a launch intent. Use the copy constructor to carry ov er the myriad of 373 // Create and fire a launch intent. Use the copy constructor to carry ov er the myriad of
342 // extras. 374 // extras.
375 Uri uri = Uri.parse(IntentHandler.getUrlFromIntent(getIntent()));
376
343 Intent newIntent = new Intent(getIntent()); 377 Intent newIntent = new Intent(getIntent());
344 newIntent.setAction(Intent.ACTION_VIEW); 378 newIntent.setAction(Intent.ACTION_VIEW);
345 newIntent.setClassName(this, CustomTabActivity.class.getName()); 379 newIntent.setClassName(this, CustomTabActivity.class.getName());
346 newIntent.setData(Uri.parse(IntentHandler.getUrlFromIntent(getIntent())) ); 380 newIntent.setData(uri);
381 if (isIntentHandledByHerb()) addHerbIntentExtras(newIntent, uri);
382
347 startActivity(newIntent); 383 startActivity(newIntent);
348 } 384 }
349 385
350 /** 386 /**
351 * Handles the launching of a DocumentActivity from the current Intent. Rou ting Intents to 387 * Handles the launching of a DocumentActivity from the current Intent. Rou ting Intents to
352 * other types of Activities must be handled from onCreate() instead. 388 * other types of Activities must be handled from onCreate() instead.
353 */ 389 */
354 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 390 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
355 private void handleDocumentActivityIntent() { 391 private void handleDocumentActivityIntent() {
356 if (getIntent() == null || mIntentHandler.shouldIgnoreIntent(this, getIn tent())) { 392 if (getIntent() == null || mIntentHandler.shouldIgnoreIntent(this, getIn tent())) {
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 Intent intent = getIntent(); 907 Intent intent = getIntent();
872 IntentHandler.ExternalAppId source = 908 IntentHandler.ExternalAppId source =
873 IntentHandler.determineExternalIntentSource(getPackageName(), in tent); 909 IntentHandler.determineExternalIntentSource(getPackageName(), in tent);
874 if (intent.getPackage() == null && source != IntentHandler.ExternalAppId .CHROME) { 910 if (intent.getPackage() == null && source != IntentHandler.ExternalAppId .CHROME) {
875 int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_AC TIVITY_NEW_DOCUMENT; 911 int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_AC TIVITY_NEW_DOCUMENT;
876 int maskedFlags = intent.getFlags() & flagsOfInterest; 912 int maskedFlags = intent.getFlags() & flagsOfInterest;
877 sIntentFlagsHistogram.record(maskedFlags); 913 sIntentFlagsHistogram.record(maskedFlags);
878 } 914 }
879 } 915 }
880 } 916 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698