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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/DefaultBrowserInfo.java

Issue 2663373003: [Android] Add options in the context menu of CCT to open in a new Chrome tab or incoginto tab (Closed)
Patch Set: Fix for Ted's comments. Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/DefaultBrowserInfo.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/DefaultBrowserInfo.java b/chrome/android/java/src/org/chromium/chrome/browser/DefaultBrowserInfo.java
new file mode 100644
index 0000000000000000000000000000000000000000..598bb18fb4cfd2bee68b60bc3f404fef0874e217
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/DefaultBrowserInfo.java
@@ -0,0 +1,59 @@
+// Copyright 2017 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;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
+import android.os.AsyncTask;
+
+import org.chromium.base.BuildInfo;
+import org.chromium.chrome.R;
+
+import java.util.concurrent.ExecutionException;
+
+/**
+ * A utility class for querying information about the default browser setting.
+ */
+public class DefaultBrowserInfo {
+ private static final String SAMPLE_URL = "https://www.google.com";
Ted C 2017/02/14 19:02:00 I would use the one from cacheIsChromeDefaultBrows
ltian 2017/02/16 05:05:10 Done.
+
+ /**
+ * @return Title of menu item for opening tab in the default browser.
+ * @param activity The activity to open the menu.
+ * @param isOpenedByChrome Whether the menu is opened by Chrome.
+ * @throws ExecutionException
+ * @throws InterruptedException
+ */
+ public static String getTitleOpenInDefaultBrowser(final Activity activity,
+ final Boolean isOpenedByChrome) throws InterruptedException, ExecutionException {
Ted C 2017/02/14 19:02:00 Why capital B boolean? Also, do you need Activity
ltian 2017/02/16 05:05:10 Done.
+ AsyncTask<Void, Void, String> defaultBrowserFetcher = new AsyncTask<Void, Void, String>() {
Ted C 2017/02/14 19:02:00 Creating an AsyncTask and then calling get on it i
+ @Override
+ protected String doInBackground(Void... params) {
+ String packageLabel = null;
+ if (isOpenedByChrome) {
+ // If the Custom Tab was created by Chrome, Chrome should open it.
+ packageLabel = BuildInfo.getPackageLabel(activity);
+ } else {
+ // Check if there is a default handler for the Intent. If so, grab its label.
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(SAMPLE_URL));
+ PackageManager pm = activity.getPackageManager();
+ ResolveInfo info = pm.resolveActivity(intent, 0);
+ if (info != null && info.match != 0) {
+ packageLabel = info.loadLabel(pm).toString();
+ }
+ }
+
+ return packageLabel == null
+ ? activity.getString(R.string.menu_open_in_product_default)
+ : activity.getString(R.string.menu_open_in_product, packageLabel);
+ }
+ };
+ defaultBrowserFetcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ return defaultBrowserFetcher.get();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698