Java Code Examples for org.chromium.webapk.lib.client.WebApkValidator

The following examples show how to use org.chromium.webapk.lib.client.WebApkValidator. 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: delion   Source File: WebappLauncherActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the package being targeted is a valid WebAPK and whether the url supplied
 * can be fulfilled by that WebAPK.
 *
 * @param webApkPackage The package name of the requested WebAPK.
 * @param url The url to navigate to.
 * @return true iff all validation criteria are met.
 */
private boolean isValidWebApk(String webApkPackage, String url) {
    if (!CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)
            || webApkPackage == null) {
        return false;
    }
    if (!WebApkValidator.isValidWebApk(this, webApkPackage)) {
        Log.d(TAG, "%s is not valid WebAPK", webApkPackage);
        return false;
    }
    if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url))) {
        Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage);
        return false;
    }
    return true;
}
 
Example 2
Source Project: AndroidChromium   Source File: WebappLauncherActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the WebAPK package specified in the intent is a valid WebAPK and whether the
 * url specified in the intent can be fulfilled by the WebAPK.
 *
 * @param intent The intent
 * @return true iff all validation criteria are met.
 */
private boolean isValidWebApk(Intent intent) {
    if (!ChromeWebApkHost.isEnabled()) return false;

    String webApkPackage = IntentUtils.safeGetStringExtra(intent,
            ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME);
    if (TextUtils.isEmpty(webApkPackage)) return false;

    String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_URL);
    if (TextUtils.isEmpty(url)) return false;

    if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url))) {
        Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage);
        return false;
    }
    return true;
}
 
Example 3
Source Project: 365browser   Source File: WebappLauncherActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the WebAPK package specified in the intent is a valid WebAPK and whether the
 * url specified in the intent can be fulfilled by the WebAPK.
 *
 * @param intent The intent
 * @return true iff all validation criteria are met.
 */
private boolean isValidWebApk(Intent intent) {
    if (!ChromeWebApkHost.isEnabled()) return false;

    String webApkPackage =
            IntentUtils.safeGetStringExtra(intent, WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME);
    if (TextUtils.isEmpty(webApkPackage)) return false;

    String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_URL);
    if (TextUtils.isEmpty(url)) return false;

    if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url))) {
        Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage);
        return false;
    }
    return true;
}
 
Example 4
Source Project: delion   Source File: ExternalNavigationDelegateImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String findValidWebApkPackageName(List<ResolveInfo> infos) {
    String webApkPackageName = WebApkValidator.findWebApkPackage(infos);
    return WebApkValidator.isValidWebApk(mApplicationContext, webApkPackageName)
            ? webApkPackageName
            : null;
}
 
Example 5
/**
 * Returns the package for the WebAPK which should handle the URL.
 *
 * @param url The url to check.
 * @return Package name of the WebAPK which should handle the URL. Returns empty string if the
 *         URL should not be handled by a WebAPK.
 */
@CalledByNative
private String queryWebApkPackage(String url) {
    if (!ChromeWebApkHost.isEnabled()) return "";

    String webApkPackage =
            WebApkValidator.queryWebApkPackage(mAppContext, url);
    return webApkPackage == null ? "" : webApkPackage;
}
 
Example 6
Source Project: 365browser   Source File: NotificationPlatformBridge.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the package for the WebAPK which should handle the URL.
 *
 * @param url The url to check.
 * @return Package name of the WebAPK which should handle the URL. Returns empty string if the
 *         URL should not be handled by a WebAPK.
 */
@CalledByNative
private String queryWebApkPackage(String url) {
    if (!ChromeWebApkHost.isEnabled()) return "";

    String webApkPackage =
            WebApkValidator.queryWebApkPackage(ContextUtils.getApplicationContext(), url);
    return webApkPackage == null ? "" : webApkPackage;
}
 
Example 7
Source Project: 365browser   Source File: AppMenuPropertiesDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the visibility and labels of the "Add to Home screen" and "Open WebAPK" menu items.
 */
protected void prepareAddToHomescreenMenuItem(
        Menu menu, Tab currentTab, boolean canShowHomeScreenMenuItem) {
    // Record whether or not we have finished installability checks for this page when we're
    // preparing the menu to be displayed. This will let us determine if it is feasible to
    // change the add to homescreen menu item based on whether a site is a PWA.
    currentTab.getAppBannerManager().recordMenuOpen();

    MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id);
    MenuItem openWebApkItem = menu.findItem(R.id.open_webapk_id);
    if (canShowHomeScreenMenuItem) {
        Context context = ContextUtils.getApplicationContext();
        long addToHomeScreenStart = SystemClock.elapsedRealtime();
        ResolveInfo resolveInfo =
                WebApkValidator.queryResolveInfo(context, currentTab.getUrl());
        RecordHistogram.recordTimesHistogram("Android.PrepareMenu.OpenWebApkVisibilityCheck",
                SystemClock.elapsedRealtime() - addToHomeScreenStart, TimeUnit.MILLISECONDS);

        boolean openWebApkItemVisible =
                resolveInfo != null && resolveInfo.activityInfo.packageName != null;

        if (openWebApkItemVisible) {
            String appName = resolveInfo.loadLabel(context.getPackageManager()).toString();
            openWebApkItem.setTitle(context.getString(R.string.menu_open_webapk, appName));

            homescreenItem.setVisible(false);
            openWebApkItem.setVisible(true);
        } else {
            homescreenItem.setTitle(AppBannerManager.getHomescreenLanguageOption());
            homescreenItem.setVisible(true);
            openWebApkItem.setVisible(false);
        }
    } else {
        homescreenItem.setVisible(false);
        openWebApkItem.setVisible(false);
    }
}
 
Example 8
Source Project: delion   Source File: ChromeWebApkHost.java    License: Apache License 2.0 4 votes vote down vote up
public static void init() {
    WebApkValidator.initWithBrowserHostSignature(EXPECTED_SIGNATURE);
}
 
Example 9
Source Project: AndroidChromium   Source File: ShortcutHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the package name of the WebAPK if WebAPKs are enabled and there is an installed
 * WebAPK which can handle {@link url}. Returns null otherwise.
 */
@CalledByNative
private static String queryWebApkPackage(String url) {
    if (!ChromeWebApkHost.isEnabled()) return null;
    return WebApkValidator.queryWebApkPackage(ContextUtils.getApplicationContext(), url);
}
 
Example 10
Source Project: AndroidChromium   Source File: ChromeWebApkHost.java    License: Apache License 2.0 4 votes vote down vote up
public static void init() {
    WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.EXPECTED_SIGNATURE);
}
 
Example 11
@Override
public String findWebApkPackageName(List<ResolveInfo> infos) {
    return WebApkValidator.findWebApkPackage(mApplicationContext, infos);
}
 
Example 12
Source Project: 365browser   Source File: ShortcutHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the package name of the WebAPK if WebAPKs are enabled and there is an installed
 * WebAPK which can handle {@link url}. Returns null otherwise.
 */
@CalledByNative
private static String queryWebApkPackage(String url) {
    if (!ChromeWebApkHost.isEnabled()) return null;
    return WebApkValidator.queryWebApkPackage(ContextUtils.getApplicationContext(), url);
}
 
Example 13
Source Project: 365browser   Source File: ShortcutHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Calls the native |callbackPointer| with lists of information on all installed WebAPKs.
 *
 * @param callbackPointer Callback to call with the information on the WebAPKs found.
 */
@CalledByNative
public static void retrieveWebApks(long callbackPointer) {
    List<String> names = new ArrayList<>();
    List<String> shortNames = new ArrayList<>();
    List<String> packageNames = new ArrayList<>();
    List<Integer> shellApkVersions = new ArrayList<>();
    List<Integer> versionCodes = new ArrayList<>();
    List<String> uris = new ArrayList<>();
    List<String> scopes = new ArrayList<>();
    List<String> manifestUrls = new ArrayList<>();
    List<String> manifestStartUrls = new ArrayList<>();
    List<Integer> displayModes = new ArrayList<>();
    List<Integer> orientations = new ArrayList<>();
    List<Long> themeColors = new ArrayList<>();
    List<Long> backgroundColors = new ArrayList<>();

    Context context = ContextUtils.getApplicationContext();
    PackageManager packageManager = context.getPackageManager();
    for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) {
        if (WebApkValidator.isValidWebApk(context, packageInfo.packageName)) {
            // Pass non-null URL parameter so that {@link WebApkInfo#create()}
            // return value is non-null
            WebApkInfo webApkInfo = WebApkInfo.create(packageInfo.packageName, "",
                    ShortcutSource.UNKNOWN, false /* forceNavigation */);
            if (webApkInfo != null) {
                names.add(webApkInfo.name());
                shortNames.add(webApkInfo.shortName());
                packageNames.add(webApkInfo.webApkPackageName());
                shellApkVersions.add(webApkInfo.shellApkVersion());
                versionCodes.add(packageInfo.versionCode);
                uris.add(webApkInfo.uri().toString());
                scopes.add(webApkInfo.scopeUri().toString());
                manifestUrls.add(webApkInfo.manifestUrl());
                manifestStartUrls.add(webApkInfo.manifestStartUrl());
                displayModes.add(webApkInfo.displayMode());
                orientations.add(webApkInfo.orientation());
                themeColors.add(webApkInfo.themeColor());
                backgroundColors.add(webApkInfo.backgroundColor());
            }
        }
    }
    nativeOnWebApksRetrieved(callbackPointer, names.toArray(new String[0]),
            shortNames.toArray(new String[0]), packageNames.toArray(new String[0]),
            integerListToIntArray(shellApkVersions), integerListToIntArray(versionCodes),
            uris.toArray(new String[0]), scopes.toArray(new String[0]),
            manifestUrls.toArray(new String[0]), manifestStartUrls.toArray(new String[0]),
            integerListToIntArray(displayModes), integerListToIntArray(orientations),
            longListToLongArray(themeColors), longListToLongArray(backgroundColors));
}
 
Example 14
Source Project: 365browser   Source File: ChromeWebApkHost.java    License: Apache License 2.0 4 votes vote down vote up
public static void init() {
    WebApkValidator.init(
            ChromeWebApkHostSignature.EXPECTED_SIGNATURE, ChromeWebApkHostSignature.PUBLIC_KEY);
}
 
Example 15
Source Project: 365browser   Source File: ExternalNavigationDelegateImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String findWebApkPackageName(List<ResolveInfo> infos) {
    return WebApkValidator.findWebApkPackage(mApplicationContext, infos);
}
 
Example 16
Source Project: delion   Source File: NotificationPlatformBridge.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Returns the package for the WebAPK which should handle the URL.
 *
 * @param url The url to check.
 * @return Package name of the WebAPK which should handle the URL. Returns empty string if the
 *         URL should not be handled by a WebAPK.
 */
@CalledByNative
private String queryWebApkPackage(String url) {
    String webApkPackage =
            WebApkValidator.queryWebApkPackage(mAppContext, url);
    return webApkPackage == null ? "" : webApkPackage;
}