Commit a00f27b6 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[gIRA] Replace URI (deprecated) with GURL.

Bug: 1077676
Change-Id: I85b7348546782b01db54e7c75b90cd17c50f8afa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2182653
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766560}
parent cb523d85
...@@ -8,9 +8,7 @@ import org.chromium.chrome.browser.instantapps.InstantAppsHandler; ...@@ -8,9 +8,7 @@ import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
import org.chromium.content_public.browser.RenderFrameHost; import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.installedapp.mojom.InstalledAppProvider; import org.chromium.installedapp.mojom.InstalledAppProvider;
import org.chromium.services.service_manager.InterfaceFactory; import org.chromium.services.service_manager.InterfaceFactory;
import org.chromium.url.URI; import org.chromium.url.GURL;
import java.net.URISyntaxException;
/** Factory to create instances of the InstalledAppProvider Mojo service. */ /** Factory to create instances of the InstalledAppProvider Mojo service. */
public class InstalledAppProviderFactory implements InterfaceFactory<InstalledAppProvider> { public class InstalledAppProviderFactory implements InterfaceFactory<InstalledAppProvider> {
...@@ -25,15 +23,10 @@ public class InstalledAppProviderFactory implements InterfaceFactory<InstalledAp ...@@ -25,15 +23,10 @@ public class InstalledAppProviderFactory implements InterfaceFactory<InstalledAp
} }
@Override @Override
public URI getUrl() { public GURL getUrl() {
String url = mRenderFrameHost.getLastCommittedURL(); String url = mRenderFrameHost.getLastCommittedURL();
if (url == null) return null; if (url == null) return GURL.emptyGURL();
return new GURL(url);
try {
return new URI(url);
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
} }
@Override @Override
......
...@@ -32,11 +32,10 @@ import org.chromium.content_public.browser.UiThreadTaskTraits; ...@@ -32,11 +32,10 @@ import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.installedapp.mojom.InstalledAppProvider; import org.chromium.installedapp.mojom.InstalledAppProvider;
import org.chromium.installedapp.mojom.RelatedApplication; import org.chromium.installedapp.mojom.RelatedApplication;
import org.chromium.mojo.system.MojoException; import org.chromium.mojo.system.MojoException;
import org.chromium.url.URI; import org.chromium.url.GURL;
import org.chromium.url.mojom.Url; import org.chromium.url.mojom.Url;
import org.chromium.webapk.lib.client.WebApkValidator; import org.chromium.webapk.lib.client.WebApkValidator;
import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -81,7 +80,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -81,7 +80,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
/** /**
* Gets the URL of the current frame. Can return null (if the frame has disappeared). * Gets the URL of the current frame. Can return null (if the frame has disappeared).
*/ */
public URI getUrl(); public GURL getUrl();
/** /**
* Checks if we're in incognito. If the frame has disappeared this returns true. * Checks if we're in incognito. If the frame has disappeared this returns true.
...@@ -144,7 +143,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -144,7 +143,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
@UiThread @UiThread
public void filterInstalledApps(final RelatedApplication[] relatedApps, final Url manifestUrl, public void filterInstalledApps(final RelatedApplication[] relatedApps, final Url manifestUrl,
final FilterInstalledAppsResponse callback) { final FilterInstalledAppsResponse callback) {
final URI frameUrl = mFrameUrlDelegate.getUrl(); final GURL frameUrl = mFrameUrlDelegate.getUrl();
int delayMillis = 0; int delayMillis = 0;
int numTasks = Math.min(relatedApps.length, MAX_ALLOWED_RELATED_APPS); int numTasks = Math.min(relatedApps.length, MAX_ALLOWED_RELATED_APPS);
ResultHolder resultHolder = new ResultHolder(numTasks, (resultPair) -> { ResultHolder resultHolder = new ResultHolder(numTasks, (resultPair) -> {
...@@ -207,10 +206,10 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -207,10 +206,10 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
@WorkerThread @WorkerThread
private void checkInstantApp( private void checkInstantApp(
ResultHolder resultHolder, int taskIdx, RelatedApplication app, URI frameUrl) { ResultHolder resultHolder, int taskIdx, RelatedApplication app, GURL frameUrl) {
int delayMs = calculateDelayForPackageMs(app.id); int delayMs = calculateDelayForPackageMs(app.id);
if (!mInstantAppsHandler.isInstantAppAvailable(frameUrl.toString(), if (!mInstantAppsHandler.isInstantAppAvailable(frameUrl.getSpec(),
INSTANT_APP_HOLDBACK_ID_STRING.equals(app.id), INSTANT_APP_HOLDBACK_ID_STRING.equals(app.id),
true /* includeUserPrefersBrowser */)) { true /* includeUserPrefersBrowser */)) {
delayThenRun(() -> resultHolder.onResult(null, taskIdx, delayMs), 0); delayThenRun(() -> resultHolder.onResult(null, taskIdx, delayMs), 0);
...@@ -223,7 +222,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -223,7 +222,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
@WorkerThread @WorkerThread
private void checkPlayApp( private void checkPlayApp(
ResultHolder resultHolder, int taskIdx, RelatedApplication app, URI frameUrl) { ResultHolder resultHolder, int taskIdx, RelatedApplication app, GURL frameUrl) {
int delayMs = calculateDelayForPackageMs(app.id); int delayMs = calculateDelayForPackageMs(app.id);
if (!isAppInstalledAndAssociatedWithOrigin(app.id, frameUrl, mPackageManagerDelegate)) { if (!isAppInstalledAndAssociatedWithOrigin(app.id, frameUrl, mPackageManagerDelegate)) {
...@@ -352,7 +351,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -352,7 +351,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
*/ */
@WorkerThread @WorkerThread
public static boolean isAppInstalledAndAssociatedWithOrigin( public static boolean isAppInstalledAndAssociatedWithOrigin(
String packageName, URI frameUrl, PackageManagerDelegate pm) { String packageName, GURL frameUrl, PackageManagerDelegate pm) {
// TODO(yusufo): Move this to a better/shared location before crbug.com/749876 is closed. // TODO(yusufo): Move this to a better/shared location before crbug.com/749876 is closed.
if (frameUrl == null) return false; if (frameUrl == null) return false;
...@@ -376,7 +375,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -376,7 +375,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
continue; continue;
} }
URI site = getSiteForWebAsset(statement); GURL site = getSiteForWebAsset(statement);
// The URI is considered equivalent if the scheme, host, and port match, according // The URI is considered equivalent if the scheme, host, and port match, according
// to the DigitalAssetLinks v1 spec. // to the DigitalAssetLinks v1 spec.
...@@ -448,7 +447,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -448,7 +447,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
* could be because: the JSON string was invalid, there was no "target" field, this was * could be because: the JSON string was invalid, there was no "target" field, this was
* not a web asset, there was no "site" field, or the "site" field was invalid. * not a web asset, there was no "site" field, or the "site" field was invalid.
*/ */
private static URI getSiteForWebAsset(JSONObject statement) { private static GURL getSiteForWebAsset(JSONObject statement) {
JSONObject target; JSONObject target;
try { try {
// Ignore the "relation" field and allow an asset with any relation to this origin. // Ignore the "relation" field and allow an asset with any relation to this origin.
...@@ -465,8 +464,8 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -465,8 +464,8 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
} }
try { try {
return new URI(target.getString(ASSET_STATEMENT_FIELD_SITE)); return new GURL(target.getString(ASSET_STATEMENT_FIELD_SITE));
} catch (JSONException | URISyntaxException e) { } catch (JSONException e) {
return null; return null;
} }
} }
...@@ -487,7 +486,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -487,7 +486,7 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
return namespace.equals(ASSET_STATEMENT_NAMESPACE_WEB); return namespace.equals(ASSET_STATEMENT_NAMESPACE_WEB);
} }
private static boolean statementTargetMatches(URI frameUrl, URI assetUrl) { private static boolean statementTargetMatches(GURL frameUrl, GURL assetUrl) {
if (assetUrl.getScheme() == null || assetUrl.getHost() == null) return false; if (assetUrl.getScheme() == null || assetUrl.getHost() == null) return false;
return assetUrl.getScheme().equals(frameUrl.getScheme()) return assetUrl.getScheme().equals(frameUrl.getScheme())
......
...@@ -23,10 +23,9 @@ import org.chromium.chrome.browser.instantapps.InstantAppsHandler; ...@@ -23,10 +23,9 @@ import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.installedapp.mojom.InstalledAppProvider; import org.chromium.installedapp.mojom.InstalledAppProvider;
import org.chromium.installedapp.mojom.RelatedApplication; import org.chromium.installedapp.mojom.RelatedApplication;
import org.chromium.url.URI; import org.chromium.url.GURL;
import org.chromium.url.mojom.Url; import org.chromium.url.mojom.Url;
import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -269,24 +268,24 @@ public class InstalledAppProviderTest { ...@@ -269,24 +268,24 @@ public class InstalledAppProviderTest {
private static final class FakeFrameUrlDelegate private static final class FakeFrameUrlDelegate
implements InstalledAppProviderImpl.FrameUrlDelegate { implements InstalledAppProviderImpl.FrameUrlDelegate {
private URI mFrameUrl; private GURL mFrameUrl;
private boolean mIncognito; private boolean mIncognito;
public FakeFrameUrlDelegate(String frameUrl) throws URISyntaxException { public FakeFrameUrlDelegate(String frameUrl) {
setFrameUrl(frameUrl); setFrameUrl(frameUrl);
} }
public void setFrameUrl(String frameUrl) throws URISyntaxException { public void setFrameUrl(String frameUrl) {
if (frameUrl == null) { if (frameUrl == null) {
mFrameUrl = null; mFrameUrl = GURL.emptyGURL();
return; return;
} }
mFrameUrl = new URI(frameUrl); mFrameUrl = new GURL(frameUrl);
} }
@Override @Override
public URI getUrl() { public GURL getUrl() {
return mFrameUrl; return mFrameUrl;
} }
...@@ -405,11 +404,7 @@ public class InstalledAppProviderTest { ...@@ -405,11 +404,7 @@ public class InstalledAppProviderTest {
setAssetStatement(PACKAGE_NAME_1, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN); setAssetStatement(PACKAGE_NAME_1, NAMESPACE_WEB, RELATION_HANDLE_ALL_URLS, ORIGIN);
RelatedApplication[] expectedInstalledRelatedApps = new RelatedApplication[] {}; RelatedApplication[] expectedInstalledRelatedApps = new RelatedApplication[] {};
try { mFrameUrlDelegate.setFrameUrl(ORIGIN_MISSING_SCHEME);
mFrameUrlDelegate.setFrameUrl(ORIGIN_MISSING_SCHEME);
} catch (URISyntaxException e) {
mFrameUrlDelegate.setFrameUrl(null);
}
verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps); verifyInstalledApps(manifestRelatedApps, expectedInstalledRelatedApps);
mFrameUrlDelegate.setFrameUrl(ORIGIN_MISSING_HOST); mFrameUrlDelegate.setFrameUrl(ORIGIN_MISSING_HOST);
......
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