| OLD | NEW |
| 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; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.pm.ApplicationInfo; | 8 import android.content.pm.ApplicationInfo; |
| 9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
| 10 import android.content.pm.PackageManager.NameNotFoundException; | 10 import android.content.pm.PackageManager.NameNotFoundException; |
| 11 import android.util.Log; | 11 import android.util.Log; |
| 12 | 12 |
| 13 import org.chromium.base.CalledByNative; | 13 import org.chromium.base.CalledByNative; |
| 14 import org.chromium.content_public.browser.WebContents; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * Tab Launcher to be used to launch new tabs from background Android Services,
when it is not | 17 * Tab Launcher to be used to launch new tabs from background Android Services,
when it is not |
| 17 * known whether an activity is available. It will send an intent to launch the
activity. | 18 * known whether an activity is available. It will send an intent to launch the
activity. |
| 18 * | 19 * |
| 19 * TODO(peter): Have the activity confirm that the tab has been launched. | 20 * TODO(peter): Have the activity confirm that the tab has been launched. |
| 20 */ | 21 */ |
| 21 public abstract class ServiceTabLauncher { | 22 public abstract class ServiceTabLauncher { |
| 22 private static final String TAG = ServiceTabLauncher.class.getSimpleName(); | 23 private static final String TAG = ServiceTabLauncher.class.getSimpleName(); |
| 23 private static final String SERVICE_TAB_LAUNCHER_KEY = | 24 private static final String SERVICE_TAB_LAUNCHER_KEY = |
| 24 "org.chromium.chrome.browser.SERVICE_TAB_LAUNCHER"; | 25 "org.chromium.chrome.browser.SERVICE_TAB_LAUNCHER"; |
| 25 | 26 |
| 27 // Name of the extra containing the Id of a tab launch request id. |
| 28 public static final String LAUNCH_REQUEST_ID_EXTRA = |
| 29 "org.chromium.chrome.browser.ServiceTabLauncher.LAUNCH_REQUEST_ID"; |
| 30 |
| 26 private static ServiceTabLauncher sInstance; | 31 private static ServiceTabLauncher sInstance; |
| 27 | 32 |
| 28 /** | 33 /** |
| 29 * Launches the browser activity and launches a tab for |url|. | 34 * Launches the browser activity and launches a tab for |url|. |
| 30 * | 35 * |
| 31 * @param context The context using which the URL is being loaded. | 36 * @param context The context using which the URL is being loaded. |
| 32 * @param requestId Id of the request for launching this tab. | 37 * @param requestId Id of the request for launching this tab. |
| 33 * @param incognito Whether the tab should be launched in incognito mode. | 38 * @param incognito Whether the tab should be launched in incognito mode. |
| 34 * @param url The URL which should be launched in a tab. | 39 * @param url The URL which should be launched in a tab. |
| 35 * @param disposition The disposition requested by the navigation source. | 40 * @param disposition The disposition requested by the navigation source. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 86 |
| 82 return Class.forName(className); | 87 return Class.forName(className); |
| 83 } catch (NameNotFoundException e) { | 88 } catch (NameNotFoundException e) { |
| 84 Log.e(TAG, "Context.getPackage() refers to an invalid package name."
); | 89 Log.e(TAG, "Context.getPackage() refers to an invalid package name."
); |
| 85 } catch (ClassNotFoundException e) { | 90 } catch (ClassNotFoundException e) { |
| 86 Log.e(TAG, "Invalid value for SERVICE_TAB_LAUNCHER in the Android ma
nifest file."); | 91 Log.e(TAG, "Invalid value for SERVICE_TAB_LAUNCHER in the Android ma
nifest file."); |
| 87 } | 92 } |
| 88 | 93 |
| 89 return null; | 94 return null; |
| 90 } | 95 } |
| 96 |
| 97 /** |
| 98 * To be called by the activity when the WebContents for |requestId| has bee
n created, or has |
| 99 * been recycled from previous use. The |webContents| must not yet have star
ted provisional |
| 100 * load for the main frame. |
| 101 * |
| 102 * @param requestId Id of the tab launching request which has been fulfilled
. |
| 103 * @param webContents The WebContents instance associated with this request. |
| 104 */ |
| 105 public static void onWebContentsForRequestAvailable(int requestId, WebConten
ts webContents) { |
| 106 nativeOnWebContentsForRequestAvailable(requestId, webContents); |
| 107 } |
| 108 |
| 109 private static native void nativeOnWebContentsForRequestAvailable( |
| 110 int requestId, WebContents webContents); |
| 91 } | 111 } |
| OLD | NEW |