Index: chrome/android/java/src/org/chromium/chrome/browser/ChromeServiceTabLauncher.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeServiceTabLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeServiceTabLauncher.java |
index c8f7a54f2defa9c9d5d7dc0d1a89863a3f408e7f..cc360064e19e14ea5f616fb50363bb04bf65d943 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeServiceTabLauncher.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeServiceTabLauncher.java |
@@ -9,7 +9,7 @@ import android.content.Intent; |
import android.os.AsyncTask; |
import org.chromium.base.CommandLine; |
-import org.chromium.base.annotations.UsedByReflection; |
+import org.chromium.base.annotations.CalledByNative; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
@@ -17,8 +17,8 @@ import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
import org.chromium.chrome.browser.webapps.WebappDataStorage; |
import org.chromium.chrome.browser.webapps.WebappRegistry; |
import org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorageCallback; |
-import org.chromium.components.service_tab_launcher.ServiceTabLauncher; |
import org.chromium.content_public.browser.LoadUrlParams; |
+import org.chromium.content_public.browser.WebContents; |
import org.chromium.content_public.common.Referrer; |
import org.chromium.content_public.common.ResourceRequestBody; |
import org.chromium.ui.base.PageTransition; |
@@ -26,23 +26,34 @@ import org.chromium.webapk.lib.client.WebApkNavigationClient; |
import org.chromium.webapk.lib.client.WebApkValidator; |
/** |
- * Service Tab Launcher implementation for Chrome. Provides the ability for Android Services |
- * running in Chrome to launch URLs, without having access to an activity. |
- * |
- * This class is referred to from the ServiceTabLauncher implementation in Chromium using a |
- * meta-data value in the Android manifest file. The ServiceTabLauncher class has more |
- * documentation about why this is necessary. |
+ * 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. |
* |
* URLs within the scope of a recently launched standalone-capable web app on the Android home |
* screen are launched in the standalone web app frame. |
- * |
- * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove reflection calls |
- * in ServiceTabLauncher. |
*/ |
-@UsedByReflection("ServiceTabLauncher.java") |
-public class ChromeServiceTabLauncher extends ServiceTabLauncher { |
- @Override |
- @UsedByReflection("ServiceTabLauncher.java") |
+public class ChromeServiceTabLauncher { |
+ // Name of the extra containing the Id of a tab launch request id. |
+ public static final String LAUNCH_REQUEST_ID_EXTRA = |
+ "org.chromium.components.service_tab_launcher.ServiceTabLauncher.LAUNCH_REQUEST_ID"; |
Peter Beverloo
2016/07/05 11:23:04
nit: org.chromium.chrome.browser.ServiceTabLaunche
|
+ |
+ private static ChromeServiceTabLauncher sInstance; |
+ |
+ /** |
+ * Launches the browser activity and launches a tab for |url|. |
+ * |
+ * @param context The context using which the URL is being loaded. |
+ * @param requestId Id of the request for launching this tab. |
+ * @param incognito Whether the tab should be launched in incognito mode. |
+ * @param url The URL which should be launched in a tab. |
+ * @param disposition The disposition requested by the navigation source. |
+ * @param referrerUrl URL of the referrer which is opening the page. |
+ * @param referrerPolicy The referrer policy to consider when applying the referrer. |
+ * @param extraHeaders Extra headers to apply when requesting the tab's URL. |
+ * @param postData Post-data to include in the tab URL's request body. |
+ */ |
+ @CalledByNative |
public void launchTab(final Context context, final int requestId, final boolean incognito, |
Peter Beverloo
2016/07/05 11:23:04
Could we get rid of the instance altogether and ju
pkotwicz
2016/07/05 17:09:59
Done. Making the method static makes things nicer.
|
final String url, final int disposition, final String referrerUrl, |
final int referrerPolicy, final String extraHeaders, |
@@ -106,4 +117,33 @@ public class ChromeServiceTabLauncher extends ServiceTabLauncher { |
}; |
WebappRegistry.getWebappDataStorageForUrl(context, url, callback); |
} |
+ |
+ /** |
+ * Returns the active instance of the ChromeServiceTabLauncher. |
+ * |
+ * @param Context The application context for the running service. |
+ */ |
+ @CalledByNative |
+ private static ChromeServiceTabLauncher getInstance(Context context) throws Exception { |
+ if (sInstance == null) { |
+ sInstance = new ChromeServiceTabLauncher(); |
+ } |
+ |
+ return sInstance; |
+ } |
+ |
+ /** |
+ * 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); |
} |