Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
| index f0eda8d0722c5b98f886d6974ec1acdccec2fba1..baf97eecdc0ae1cdf51d98b7449adb7ecedd96f9 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
| @@ -10,22 +10,26 @@ import android.content.pm.ApplicationInfo; |
| import android.content.pm.PackageManager; |
| import android.content.pm.PackageManager.NameNotFoundException; |
| import android.net.Uri; |
| +import android.provider.Browser; |
| import android.util.Log; |
| import org.chromium.base.CalledByNative; |
| +import org.chromium.content_public.browser.WebContents; |
| /** |
| * Tab Launcher to be used to launch new tabs from background Android Services, when it is not |
| - * known whether an activity is available. It will send an intent to launch the activity. |
| - * |
| - * TODO(peter): Have the activity confirm that the tab has been launched. |
| + * known whether an activity is available. It will send an intent to launch the activity, after |
| + * which the activity will report back that the tab has actually been created. |
| */ |
| public class ServiceTabLauncher { |
| private static final String TAG = ServiceTabLauncher.class.getSimpleName(); |
| - |
| private static final String BROWSER_ACTIVITY_KEY = |
| "org.chromium.chrome.browser.BROWSER_ACTIVITY"; |
| + // Name of the extra containing the Id of a tab launch request id. |
| + public static final String LAUNCH_REQUEST_ID_EXTRA = |
| + "org.chromium.chrome.browser.ServiceTabLauncher.LAUNCH_REQUEST_ID"; |
| + |
| private final long mNativeServiceTabLauncher; |
| private final Context mContext; |
| @@ -42,17 +46,25 @@ public class ServiceTabLauncher { |
| /** |
| * Launches the browser activity and launches a tab for |url|. |
| * |
| + * @param requestId Id of the tab creation request, enabling the activity to feed back |
| + * that the tab has been created. |
| * @param url The URL to be opened in a new tab. |
| */ |
| @CalledByNative |
| - private void launchTab(String url) { |
| + private void launchTab(int requestId, String url) { |
| Intent intent = new Intent(mContext, getBrowserActivityClassFromManifest()); |
| intent.setAction(Intent.ACTION_MAIN); |
| intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| intent.setData(Uri.parse(url)); |
| - // TODO(peter): Add the referer. |
| + // Tell the browser to open a new tab, rather than re-use an existing tab. |
| + intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); |
| + |
| + // Include the launch request id so that it can inform to launcher when done. |
| + intent.putExtra(LAUNCH_REQUEST_ID_EXTRA, requestId); |
|
Ted C
2015/02/06 01:18:18
for chrome to actually act on this, we'll probably
Peter Beverloo
2015/02/19 16:03:06
Done.
|
| + |
| + // TODO(peter): Add the referrer. |
| mContext.startActivity(intent); |
| } |
| @@ -78,4 +90,19 @@ public class ServiceTabLauncher { |
| return null; |
| } |
| + |
| + /** |
| + * To be called by the activity when the WebContents for |requestId| has been created, or has |
| + * been recycled from previous use. The |webContents| must not yet have started provisional |
| + * load for the main frame. |
| + * |
| + * @param requestId Id of the tab launching request which has been fulfilled. |
| + * @param webContents The WebContents instance associated with this request. |
| + */ |
| + public static void onWebContentsForRequestAvailable(int requestId, WebContents webContents) { |
| + nativeOnWebContentsForRequestAvailable(requestId, webContents); |
| + } |
| + |
| + private static native void nativeOnWebContentsForRequestAvailable( |
| + int requestId, WebContents webContents); |
| } |