Java源码示例:org.chromium.chrome.browser.webapps.WebappRegistry
示例1
/**
* Stores the specified bitmap as the splash screen for a web app.
* @param id ID of the web app which is storing data.
* @param splashImage Image which should be displayed on the splash screen of
* the web app. This can be null of there is no image to show.
*/
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
final WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(id);
if (storage != null) {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... args0) {
return encodeBitmapAsString(splashImage);
}
@Override
protected void onPostExecute(String encodedImage) {
storage.updateSplashScreenImage(encodedImage);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
示例2
/**
* Stores the specified bitmap as the splash screen for a web app.
* @param id ID of the web app which is storing data.
* @param splashImage Image which should be displayed on the splash screen of
* the web app. This can be null of there is no image to show.
*/
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
final WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(id);
if (storage != null) {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... args0) {
return encodeBitmapAsString(splashImage);
}
@Override
protected void onPostExecute(String encodedImage) {
storage.updateSplashScreenImage(encodedImage);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
示例3
/**
* Creates a storage location and stores the data for a web app using {@link WebappDataStorage}.
* @param id ID of the webapp which is storing data.
* @param splashImage Image which should be displayed on the splash screen of
* the webapp. This can be null of there is no image to show.
*/
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
WebappRegistry.getWebappDataStorage(ContextUtils.getApplicationContext(), id,
new WebappRegistry.FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
if (storage == null) return;
storage.updateSplashScreenImage(splashImage);
}
});
}
示例4
/**
* Initializes Chrome and starts the browser process if it's not running as of yet, and
* dispatch |intent| to the NotificationPlatformBridge once this is done.
*
* @param intent The intent containing the notification's information.
*/
@SuppressFBWarnings("DM_EXIT")
private void dispatchIntentOnUIThread(Intent intent) {
try {
ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
// Warm up the WebappRegistry, as we need to check if this notification should launch a
// standalone web app. This no-ops if the registry is already initialized and warmed,
// but triggers a strict mode violation otherwise (i.e. the browser isn't running).
// Temporarily disable strict mode to work around the violation.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
WebappRegistry.getInstance();
WebappRegistry.warmUpSharedPrefs();
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
// Now that the browser process is initialized, we pass forward the call to the
// NotificationPlatformBridge which will take care of delivering the appropriate events.
if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) {
Log.w(TAG, "Unable to dispatch the notification event to Chrome.");
}
// TODO(peter): Verify that the lifetime of the NotificationService is sufficient
// when a notification event could be dispatched successfully.
} catch (ProcessInitException e) {
Log.e(TAG, "Unable to start the browser process.", e);
System.exit(-1);
}
}
示例5
/**
* Initializes Chrome and starts the browser process if it's not running as of yet, and
* dispatch |intent| to the NotificationPlatformBridge once this is done.
*
* @param intent The intent containing the notification's information.
*/
@SuppressFBWarnings("DM_EXIT")
static void dispatchIntentOnUIThread(Context context, Intent intent) {
try {
ChromeBrowserInitializer.getInstance(context).handleSynchronousStartup();
// Warm up the WebappRegistry, as we need to check if this notification should launch a
// standalone web app. This no-ops if the registry is already initialized and warmed,
// but triggers a strict mode violation otherwise (i.e. the browser isn't running).
// Temporarily disable strict mode to work around the violation.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
WebappRegistry.getInstance();
WebappRegistry.warmUpSharedPrefs();
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
// Now that the browser process is initialized, we pass forward the call to the
// NotificationPlatformBridge which will take care of delivering the appropriate events.
if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) {
Log.w(TAG, "Unable to dispatch the notification event to Chrome.");
}
// TODO(peter): Verify that the lifetime of the NotificationService is sufficient
// when a notification event could be dispatched successfully.
} catch (ProcessInitException e) {
Log.e(TAG, "Unable to start the browser process.", e);
System.exit(-1);
}
}
示例6
/**
* Adds home screen shortcut which opens in a {@link WebappActivity}. Creates web app
* home screen shortcut and registers web app asynchronously. Calls
* ShortcutHelper::OnWebappDataStored() when done.
*/
@SuppressWarnings("unused")
@CalledByNative
private static void addWebapp(final String id, final String url, final String scopeUrl,
final String userTitle, final String name, final String shortName, final String iconUrl,
final Bitmap icon, final int displayMode, final int orientation, final int source,
final long themeColor, final long backgroundColor, final long callbackPointer) {
new AsyncTask<Void, Void, Intent>() {
@Override
protected Intent doInBackground(Void... args0) {
// Encoding {@link icon} as a string and computing the mac are expensive.
Context context = ContextUtils.getApplicationContext();
String nonEmptyScopeUrl =
TextUtils.isEmpty(scopeUrl) ? getScopeFromUrl(url) : scopeUrl;
Intent shortcutIntent = createWebappShortcutIntent(id,
sDelegate.getFullscreenAction(), url, nonEmptyScopeUrl, name, shortName,
icon, WEBAPP_SHORTCUT_VERSION, displayMode, orientation, themeColor,
backgroundColor, iconUrl.isEmpty());
shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url));
shortcutIntent.putExtra(EXTRA_SOURCE, source);
shortcutIntent.setPackage(context.getPackageName());
return shortcutIntent;
}
@Override
protected void onPostExecute(final Intent resultIntent) {
sDelegate.addShortcutToHomescreen(userTitle, icon, resultIntent);
// Store the webapp data so that it is accessible without the intent. Once this
// process is complete, call back to native code to start the splash image
// download.
WebappRegistry.getInstance().register(
id, new WebappRegistry.FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
storage.updateFromShortcutIntent(resultIntent);
nativeOnWebappDataStored(callbackPointer);
}
});
if (shouldShowToastWhenAddingShortcut()) {
showAddedToHomescreenToast(userTitle);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}