Java Code Examples for org.chromium.chrome.browser.webapps.WebappRegistry

The following examples show how to use org.chromium.chrome.browser.webapps.WebappRegistry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AndroidChromium   Source File: ShortcutHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source Project: 365browser   Source File: ShortcutHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source Project: delion   Source File: ShortcutHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
                }

            });
}
 
Example 4
Source Project: AndroidChromium   Source File: NotificationService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 5
Source Project: 365browser   Source File: NotificationService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 6
Source Project: 365browser   Source File: ShortcutHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}