Commit 2b7c4c7e authored by Jarryd's avatar Jarryd Committed by Commit Bot

WebInstall: Add method to get all origins with installed app.

Storage site settings will need information about which origins
have an associated installed app so that when a user is clearing data,
the browser can conditionally warn about the clearing of data from the
installed app.

Bug: 1068710
Change-Id: I69d3684803bb64a03b0e41858b1f2c6bf14b22b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2140615Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759853}
parent 0dd4f5fd
...@@ -125,7 +125,7 @@ public class TrustedWebActivityPermissionStore { ...@@ -125,7 +125,7 @@ public class TrustedWebActivityPermissionStore {
} }
/** Gets all the origins of registered TWAs. */ /** Gets all the origins of registered TWAs. */
Set<String> getStoredOrigins() { public Set<String> getStoredOrigins() {
// In case the pre-emptive disk read in initStorage hasn't occurred by the time we actually // In case the pre-emptive disk read in initStorage hasn't occurred by the time we actually
// need the value. // need the value.
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
......
...@@ -25,12 +25,14 @@ import org.chromium.chrome.browser.browsing_data.UrlFilter; ...@@ -25,12 +25,14 @@ import org.chromium.chrome.browser.browsing_data.UrlFilter;
import org.chromium.chrome.browser.browsing_data.UrlFilterBridge; import org.chromium.chrome.browser.browsing_data.UrlFilterBridge;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.components.embedder_support.util.Origin;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.webapk.lib.common.WebApkConstants; import org.chromium.webapk.lib.common.WebApkConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -195,6 +197,23 @@ public class WebappRegistry { ...@@ -195,6 +197,23 @@ public class WebappRegistry {
return bestMatch; return bestMatch;
} }
/**
* Returns a string representation of the WebApk origin.
* @param storage The WebappDataStorage to extract origin for.
*/
private String getScopeFromStorage(WebappDataStorage storage) {
if (!storage.getId().startsWith(WebApkConstants.WEBAPK_ID_PREFIX)) {
return "";
}
String scope = storage.getScope();
// Scope shouldn't be empty.
assert (!scope.isEmpty());
return scope;
}
/** /**
* Returns true if a WebAPK is found whose scope matches |origin|. * Returns true if a WebAPK is found whose scope matches |origin|.
* @param origin The origin to search a WebAPK for. * @param origin The origin to search a WebAPK for.
...@@ -202,18 +221,41 @@ public class WebappRegistry { ...@@ -202,18 +221,41 @@ public class WebappRegistry {
public boolean hasAtLeastOneWebApkForOrigin(String origin) { public boolean hasAtLeastOneWebApkForOrigin(String origin) {
for (HashMap.Entry<String, WebappDataStorage> entry : mStorages.entrySet()) { for (HashMap.Entry<String, WebappDataStorage> entry : mStorages.entrySet()) {
WebappDataStorage storage = entry.getValue(); WebappDataStorage storage = entry.getValue();
if (!storage.getId().startsWith(WebApkConstants.WEBAPK_ID_PREFIX)) continue;
String scope = storage.getScope();
// Scope shouldn't be empty. String scope = getScopeFromStorage(storage);
assert (!scope.isEmpty()); if (scope.isEmpty()) continue;
if (scope.startsWith(origin)) return true; if (scope.startsWith(origin)) return true;
} }
return false; return false;
} }
/**
* Returns a Set of all origins that have an installed WebAPK.
*/
Set<String> getOriginsWithWebApk() {
HashSet<String> origins = new HashSet<String>();
for (HashMap.Entry<String, WebappDataStorage> entry : mStorages.entrySet()) {
WebappDataStorage storage = entry.getValue();
String scope = getScopeFromStorage(storage);
if (scope.isEmpty()) continue;
origins.add(Origin.create(scope).toString());
}
return origins;
}
/**
* Returns all origins that have a WebAPK or TWA installed.
*/
public Set<String> getOriginsWithInstalledApp() {
HashSet<String> origins = new HashSet<String>();
origins.addAll(getOriginsWithWebApk());
origins.addAll(mTrustedWebActivityPermissionStore.getStoredOrigins());
return origins;
}
/** /**
* Returns the list of WebAPK IDs with pending updates. Filters out WebAPKs which have been * Returns the list of WebAPK IDs with pending updates. Filters out WebAPKs which have been
* uninstalled. * uninstalled.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment