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

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

Issue 2013883002: ✈ Remove unnecessary flag and DocumentModeManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and review. Created 4 years, 7 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;
9 import android.app.Activity; 8 import android.app.Activity;
10 import android.app.ActivityManager;
11 import android.app.ActivityManager.AppTask;
12 import android.app.ActivityManager.RecentTaskInfo;
13 import android.app.Notification; 9 import android.app.Notification;
14 import android.app.PendingIntent; 10 import android.app.PendingIntent;
15 import android.app.SearchManager; 11 import android.app.SearchManager;
16 import android.content.Context; 12 import android.content.Context;
17 import android.content.Intent; 13 import android.content.Intent;
18 import android.content.pm.PackageManager;
19 import android.graphics.Bitmap; 14 import android.graphics.Bitmap;
20 import android.graphics.BitmapFactory; 15 import android.graphics.BitmapFactory;
21 import android.net.Uri; 16 import android.net.Uri;
22 import android.os.Build; 17 import android.os.Build;
23 import android.os.Bundle; 18 import android.os.Bundle;
24 import android.provider.Browser; 19 import android.provider.Browser;
25 import android.support.customtabs.CustomTabsIntent; 20 import android.support.customtabs.CustomTabsIntent;
26 import android.text.TextUtils; 21 import android.text.TextUtils;
27 22
28 import org.chromium.base.ApiCompatibilityUtils; 23 import org.chromium.base.ApiCompatibilityUtils;
(...skipping 16 matching lines...) Expand all
45 import org.chromium.chrome.browser.customtabs.CustomTabActivity; 40 import org.chromium.chrome.browser.customtabs.CustomTabActivity;
46 import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider; 41 import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
47 import org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity; 42 import org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity;
48 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; 43 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
49 import org.chromium.chrome.browser.metrics.LaunchMetrics; 44 import org.chromium.chrome.browser.metrics.LaunchMetrics;
50 import org.chromium.chrome.browser.metrics.MediaNotificationUma; 45 import org.chromium.chrome.browser.metrics.MediaNotificationUma;
51 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; 46 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
52 import org.chromium.chrome.browser.notifications.NotificationPlatformBridge; 47 import org.chromium.chrome.browser.notifications.NotificationPlatformBridge;
53 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza tions; 48 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza tions;
54 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 49 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
55 import org.chromium.chrome.browser.preferences.DocumentModeManager;
56 import org.chromium.chrome.browser.tab.Tab; 50 import org.chromium.chrome.browser.tab.Tab;
57 import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin; 51 import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin;
58 import org.chromium.chrome.browser.upgrade.UpgradeActivity; 52 import org.chromium.chrome.browser.upgrade.UpgradeActivity;
59 import org.chromium.chrome.browser.util.FeatureUtilities; 53 import org.chromium.chrome.browser.util.FeatureUtilities;
60 import org.chromium.chrome.browser.util.IntentUtils; 54 import org.chromium.chrome.browser.util.IntentUtils;
61 import org.chromium.chrome.browser.util.UrlUtilities; 55 import org.chromium.chrome.browser.util.UrlUtilities;
62 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; 56 import org.chromium.chrome.browser.webapps.WebappLauncherActivity;
63 57
64 import java.lang.ref.WeakReference; 58 import java.lang.ref.WeakReference;
65 import java.net.URI; 59 import java.net.URI;
66 import java.util.List;
67 import java.util.UUID; 60 import java.util.UUID;
68 61
69 /** 62 /**
70 * Dispatches incoming intents to the appropriate activity based on the current configuration and 63 * Dispatches incoming intents to the appropriate activity based on the current configuration and
71 * Intent fired. 64 * Intent fired.
72 */ 65 */
73 public class ChromeLauncherActivity extends Activity 66 public class ChromeLauncherActivity extends Activity
74 implements IntentHandler.IntentHandlerDelegate { 67 implements IntentHandler.IntentHandlerDelegate {
75 /** 68 /**
76 * Extra indicating launch mode used. 69 * Extra indicating launch mode used.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // time at which the intent was received. 137 // time at which the intent was received.
145 IntentHandler.addTimestampToIntent(getIntent()); 138 IntentHandler.addTimestampToIntent(getIntent());
146 // Initialize the command line in case we've disabled document mode from there. 139 // Initialize the command line in case we've disabled document mode from there.
147 CommandLineInitUtil.initCommandLine(this, ChromeApplication.COMMAND_LINE _FILE); 140 CommandLineInitUtil.initCommandLine(this, ChromeApplication.COMMAND_LINE _FILE);
148 141
149 // Read partner browser customizations information asynchronously. 142 // Read partner browser customizations information asynchronously.
150 // We want to initialize early because when there is no tabs to restore, we should possibly 143 // We want to initialize early because when there is no tabs to restore, we should possibly
151 // show homepage, which might require reading PartnerBrowserCustomizatio ns provider. 144 // show homepage, which might require reading PartnerBrowserCustomizatio ns provider.
152 PartnerBrowserCustomizations.initializeAsync(getApplicationContext(), 145 PartnerBrowserCustomizations.initializeAsync(getApplicationContext(),
153 PARTNER_BROWSER_CUSTOMIZATIONS_TIMEOUT_MS); 146 PARTNER_BROWSER_CUSTOMIZATIONS_TIMEOUT_MS);
154 maybePerformMigrationTasks();
155 recordIntentMetrics(); 147 recordIntentMetrics();
156 148
157 mIsInLegacyMultiInstanceMode = 149 mIsInLegacyMultiInstanceMode =
158 MultiWindowUtils.getInstance().shouldRunInLegacyMultiInstanceMod e(this); 150 MultiWindowUtils.getInstance().shouldRunInLegacyMultiInstanceMod e(this);
159 mIntentHandler = new IntentHandler(this, getPackageName()); 151 mIntentHandler = new IntentHandler(this, getPackageName());
160 mIsCustomTabIntent = isCustomTabIntent(); 152 mIsCustomTabIntent = isCustomTabIntent();
161 if (!mIsCustomTabIntent) { 153 if (!mIsCustomTabIntent) {
162 mIsHerbIntent = isHerbIntent(); 154 mIsHerbIntent = isHerbIntent();
163 mIsCustomTabIntent = mIsHerbIntent; 155 mIsCustomTabIntent = mIsHerbIntent;
164 } 156 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 finish(); 247 finish();
256 } 248 }
257 return; 249 return;
258 } 250 }
259 251
260 // TODO(aruslan): FAIL. 252 // TODO(aruslan): FAIL.
261 ApiCompatibilityUtils.finishAndRemoveTask(this); 253 ApiCompatibilityUtils.finishAndRemoveTask(this);
262 } 254 }
263 } 255 }
264 256
265 /**
266 * If we have just opted in or opted out of document mode, perform pending m igration tasks
267 * such as cleaning up the recents.
268 */
269 private void maybePerformMigrationTasks() {
270 if (DocumentModeManager.getInstance(this).isOptOutCleanUpPending()) {
271 cleanUpChromeRecents(
272 DocumentModeManager.getInstance(this).isOptedOutOfDocumentMo de());
273 DocumentModeManager.getInstance(this).setOptOutCleanUpPending(false) ;
274 }
275 }
276
277 @Override 257 @Override
278 public void processWebSearchIntent(String query) { 258 public void processWebSearchIntent(String query) {
279 Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH); 259 Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
280 searchIntent.putExtra(SearchManager.QUERY, query); 260 searchIntent.putExtra(SearchManager.QUERY, query);
281 startActivity(searchIntent); 261 startActivity(searchIntent);
282 } 262 }
283 263
284 @Override 264 @Override
285 public void processUrlViewIntent(String url, String referer, String headers, 265 public void processUrlViewIntent(String url, String referer, String headers,
286 IntentHandler.TabOpenType tabOpenType, String externalAppId, 266 IntentHandler.TabOpenType tabOpenType, String externalAppId,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (uri != null && "content".equals(uri.getScheme())) { 456 if (uri != null && "content".equals(uri.getScheme())) {
477 newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 457 newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
478 } 458 }
479 if (mIsInLegacyMultiInstanceMode) { 459 if (mIsInLegacyMultiInstanceMode) {
480 MultiWindowUtils.getInstance().makeLegacyMultiInstanceIntent(this, n ewIntent); 460 MultiWindowUtils.getInstance().makeLegacyMultiInstanceIntent(this, n ewIntent);
481 } 461 }
482 startActivity(newIntent); 462 startActivity(newIntent);
483 } 463 }
484 464
485 /** 465 /**
486 * On opting out, remove all the old tasks from the recents.
487 * @param fromDocument Whether any possible migration was from document mode to classic.
488 */
489 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
490 private void cleanUpChromeRecents(boolean fromDocument) {
491 ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY _SERVICE);
492 List<ActivityManager.AppTask> taskList = am.getAppTasks();
493 PackageManager pm = getPackageManager();
494 for (int i = 0; i < taskList.size(); i++) {
495 AppTask task = taskList.get(i);
496 String className = DocumentUtils.getTaskClassName(task, pm);
497 if (className == null) continue;
498
499 RecentTaskInfo taskInfo = DocumentUtils.getTaskInfoFromTask(task);
500 if (taskInfo == null) continue;
501
502 // Skip the document activities if we are migrating from classic to document.
503 boolean skip = !fromDocument && DocumentActivity.isDocumentActivity( className);
504 if (!skip && (taskInfo.id != getTaskId())) {
505 taskList.get(i).finishAndRemoveTask();
506 }
507 }
508 }
509
510 /**
511 * @return Whether there is already an browser instance of Chrome already ru nning. 466 * @return Whether there is already an browser instance of Chrome already ru nning.
512 */ 467 */
513 public boolean isChromeBrowserActivityRunning() { 468 public boolean isChromeBrowserActivityRunning() {
514 for (WeakReference<Activity> reference : ApplicationStatus.getRunningAct ivities()) { 469 for (WeakReference<Activity> reference : ApplicationStatus.getRunningAct ivities()) {
515 Activity activity = reference.get(); 470 Activity activity = reference.get();
516 if (activity == null) continue; 471 if (activity == null) continue;
517 472
518 String className = activity.getClass().getName(); 473 String className = activity.getClass().getName();
519 if (TextUtils.equals(className, ChromeTabbedActivity.class.getName() )) { 474 if (TextUtils.equals(className, ChromeTabbedActivity.class.getName() )) {
520 return true; 475 return true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 IntentHandler.ExternalAppId source = 510 IntentHandler.ExternalAppId source =
556 IntentHandler.determineExternalIntentSource(getPackageName(), in tent); 511 IntentHandler.determineExternalIntentSource(getPackageName(), in tent);
557 if (intent.getPackage() == null && source != IntentHandler.ExternalAppId .CHROME) { 512 if (intent.getPackage() == null && source != IntentHandler.ExternalAppId .CHROME) {
558 int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_AC TIVITY_NEW_DOCUMENT; 513 int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_AC TIVITY_NEW_DOCUMENT;
559 int maskedFlags = intent.getFlags() & flagsOfInterest; 514 int maskedFlags = intent.getFlags() & flagsOfInterest;
560 sIntentFlagsHistogram.record(maskedFlags); 515 sIntentFlagsHistogram.record(maskedFlags);
561 } 516 }
562 MediaNotificationUma.recordClickSource(intent); 517 MediaNotificationUma.recordClickSource(intent);
563 } 518 }
564 } 519 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698