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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..ce9900ae09bd58c3aa8dbf8f3a98be028e5d863e
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java
@@ -0,0 +1,76 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.multiwindow;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Build;
+import android.text.TextUtils;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.chrome.browser.ChromeMobileApplication;
+import org.chromium.chrome.browser.ChromeTabbedActivity;
+import org.chromium.chrome.browser.document.ChromeLauncherActivity;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Utilities for detecting multi-window/multi-instance support.
+ *
+ * Thread-safe: This class may be accessed from any thread.
+ */
+public class MultiWindowUtils {
+
+ private static AtomicReference<MultiWindowUtils> sInstance =
+ new AtomicReference<MultiWindowUtils>();
+
+ /**
+ * Returns the singleton instance of MultiWindowUtils, creating it if needed.
+ */
+ public static MultiWindowUtils getInstance() {
+ if (sInstance.get() == null) {
+ ChromeMobileApplication application =
+ (ChromeMobileApplication) ApplicationStatus.getApplicationContext();
+ sInstance.compareAndSet(null, application.createMultiWindowUtils());
+ }
+ return sInstance.get();
+ }
+
+ /**
+ * @param activity The {@link Activity} to check.
+ * @return Whether or not {@code activity} is currently in multi-window mode.
+ */
+ public boolean isMultiWindow(Activity activity) {
+ // This logic is overridden in a subclass.
+ return false;
+ }
+
+ /**
+ * @param activity The {@link Activity} to check.
+ * @return Whether or not {@code activity} should run in multi-instance mode.
+ */
+ public boolean shouldRunInMultiInstanceMode(ChromeLauncherActivity activity) {
+ return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
+ && TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
+ && isMultiWindow(activity)
+ && activity.isChromeBrowserActivityRunning();
+ }
+
+ /**
+ * Makes |intent| able to support multi-instance in multi-window mode.
+ */
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public void makeMultiInstanceIntent(Activity activity, Intent intent) {
+ if (activity instanceof ChromeLauncherActivity && isMultiWindow(activity)) {
+ if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
+ intent.getComponent().getClassName())) {
+ intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
+ }
+ intent.setFlags(intent.getFlags()
+ & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698