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

The following examples show how to use org.chromium.webapk.lib.client.WebApkValidator. 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 File: WebappLauncherActivity.java    From delion with 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 File: WebappLauncherActivity.java    From AndroidChromium with 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 File: WebappLauncherActivity.java    From 365browser with 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 File: ExternalNavigationDelegateImpl.java    From delion with 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
Source File: NotificationPlatformBridge.java    From AndroidChromium with 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(mAppContext, url);
    return webApkPackage == null ? "" : webApkPackage;
}
 
Example #6
Source File: NotificationPlatformBridge.java    From 365browser with 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 File: AppMenuPropertiesDelegate.java    From 365browser with 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 File: ChromeWebApkHost.java    From delion with Apache License 2.0 4 votes vote down vote up
public static void init() {
    WebApkValidator.initWithBrowserHostSignature(EXPECTED_SIGNATURE);
}
 
Example #9
Source File: ShortcutHelper.java    From AndroidChromium with 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 File: ChromeWebApkHost.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public static void init() {
    WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.EXPECTED_SIGNATURE);
}
 
Example #11
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public String findWebApkPackageName(List<ResolveInfo> infos) {
    return WebApkValidator.findWebApkPackage(mApplicationContext, infos);
}
 
Example #12
Source File: ShortcutHelper.java    From 365browser with 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 File: ShortcutHelper.java    From 365browser with 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 File: ChromeWebApkHost.java    From 365browser with 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 File: ExternalNavigationDelegateImpl.java    From 365browser with 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 File: NotificationPlatformBridge.java    From delion with 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;
}