Skip to content

Commit

Permalink
[GURL] Remove references to Tab.getUrlString()
Browse files Browse the repository at this point in the history
Took care of ~1/3 of remaining references.
Bug: 783819

Change-Id: Ib72a5d5a82337b9329e38f6f3b21e98f3290d83c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2787166
Commit-Queue: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#868303}
  • Loading branch information
yfriedman authored and Chromium LUCI CQ committed Mar 31, 2021
1 parent cdd9d66 commit b10c4fb
Show file tree
Hide file tree
Showing 33 changed files with 137 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1809,8 +1809,7 @@ public void terminateIncognitoSession() {
@Override
public boolean onMenuOrKeyboardAction(final int id, boolean fromMenu) {
final Tab currentTab = getActivityTab();
boolean currentTabIsNtp =
currentTab != null && UrlUtilities.isNTPUrl(currentTab.getUrlString());
boolean currentTabIsNtp = currentTab != null && UrlUtilities.isNTPUrl(currentTab.getUrl());
if (id == R.id.new_tab_menu_id) {
getTabModelSelector().getModel(false).commitAllTabClosures();
RecordUserAction.record("MobileMenuNewTab");
Expand Down Expand Up @@ -1963,7 +1962,7 @@ public boolean handleBackPressed() {
// get back to the previous state. The reason for startsWith check is that the
// actual redirected URL is a different system language based help url.
final @TabLaunchType int type = currentTab.getLaunchType();
final boolean helpUrl = currentTab.getUrlString().startsWith(HELP_URL_PREFIX);
final boolean helpUrl = currentTab.getUrl().getSpec().startsWith(HELP_URL_PREFIX);
if (type == TabLaunchType.FROM_CHROME_UI && helpUrl) {
getCurrentTabModel().closeTab(currentTab);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private void updateTabText() {
String url = null;
if (mTab != null && mTab.isInitialized()) {
title = mTab.getTitle();
url = mTab.getUrlString();
url = mTab.getUrl().getSpec();
if (TextUtils.isEmpty(title)) title = url;
}
if (TextUtils.isEmpty(title)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ public void onProvideAssistContent(AssistContent outContent) {

// No information is provided in incognito mode and overview mode.
if (tab != null && !tab.isIncognito() && !inOverviewMode) {
outContent.setWebUri(Uri.parse(tab.getUrlString()));
outContent.setWebUri(Uri.parse(tab.getUrl().getSpec()));
if (structuredData != null) {
outContent.setStructuredData(structuredData);
}
Expand Down Expand Up @@ -2230,7 +2230,7 @@ public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) {
final Tab currentTab = getActivityTab();

if (id == R.id.help_id) {
String url = currentTab != null ? currentTab.getUrlString() : "";
String url = currentTab != null ? currentTab.getUrl().getSpec() : "";
Profile profile = getTabModelSelector().isIncognitoSelected()
? Profile.getLastUsedRegularProfile().getPrimaryOTRProfile()
: Profile.getLastUsedRegularProfile();
Expand All @@ -2242,7 +2242,7 @@ public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) {
// 'currentTab' could only be null when opening history from start surface, which is
// not available on tablet.
assert (isTablet() && currentTab != null) || !isTablet();
if (currentTab != null && UrlUtilities.isNTPUrl(currentTab.getUrlString())) {
if (currentTab != null && UrlUtilities.isNTPUrl(currentTab.getUrl())) {
NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_HISTORY_MANAGER);
}
RecordUserAction.record("MobileMenuHistory");
Expand Down Expand Up @@ -2340,9 +2340,9 @@ public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) {
if (id == R.id.open_webapk_id) {
Context context = ContextUtils.getApplicationContext();
String packageName =
WebApkValidator.queryFirstWebApkPackage(context, currentTab.getUrlString());
WebApkValidator.queryFirstWebApkPackage(context, currentTab.getUrl().getSpec());
Intent launchIntent = WebApkNavigationClient.createLaunchWebApkIntent(
packageName, currentTab.getUrlString(), false);
packageName, currentTab.getUrl().getSpec(), false);
try {
context.startActivity(launchIntent);
RecordUserAction.record("MobileMenuOpenWebApk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
Expand Down Expand Up @@ -65,6 +64,7 @@
import org.chromium.components.webapps.WebappsUtils;
import org.chromium.net.ConnectionType;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.url.GURL;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -237,11 +237,11 @@ public void prepareMenu(Menu menu, AppMenuHandler handler) {

private void preparePageMenu(
Menu menu, Tab currentTab, AppMenuHandler handler, boolean isIncognito) {
String url = currentTab.getUrlString();
boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX)
|| url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
boolean isFileScheme = url.startsWith(UrlConstants.FILE_URL_PREFIX);
boolean isContentScheme = url.startsWith(UrlConstants.CONTENT_URL_PREFIX);
GURL url = currentTab.getUrl();
boolean isChromeScheme = url.getScheme().equals(UrlConstants.CHROME_SCHEME)
|| url.getScheme().equals(UrlConstants.CHROME_NATIVE_SCHEME);
boolean isFileScheme = url.getScheme().equals(UrlConstants.FILE_SCHEME);
boolean isContentScheme = url.getScheme().equals(UrlConstants.CONTENT_SCHEME);

// Update the icon row items (shown in narrow form factors).
boolean shouldShowIconRow = shouldShowIconRow();
Expand Down Expand Up @@ -413,7 +413,7 @@ private void prepareCommonMenuItems(Menu menu, @MenuGroup int menuGroup, boolean
*/
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public boolean shouldShowReaderModePrefs(@NonNull Tab currentTab) {
return DomDistillerUrlUtils.isDistilledPage(currentTab.getUrlString());
return DomDistillerUrlUtils.isDistilledPage(currentTab.getUrl());
}

/**
Expand Down Expand Up @@ -501,7 +501,7 @@ public boolean shouldShowTranslateMenuItem(@NonNull Tab currentTab) {
* @return Whether the homescreen menu item should be displayed.
*/
protected boolean shouldShowHomeScreenMenuItem(boolean isChromeScheme, boolean isFileScheme,
boolean isContentScheme, boolean isIncognito, String url) {
boolean isContentScheme, boolean isIncognito, @NonNull GURL url) {
// Hide 'Add to homescreen' for the following:
// * chrome:// pages - Android doesn't know how to direct those URLs.
// * incognito pages - To avoid problems where users create shortcuts in incognito
Expand All @@ -513,7 +513,7 @@ protected boolean shouldShowHomeScreenMenuItem(boolean isChromeScheme, boolean i
// is not persisted when adding to the homescreen.
// * If creating shortcuts it not supported by the current home screen.
return WebappsUtils.isAddToHomeIntentSupported() && !isChromeScheme && !isFileScheme
&& !isContentScheme && !isIncognito && !TextUtils.isEmpty(url);
&& !isContentScheme && !isIncognito && !url.isEmpty();
}

/**
Expand All @@ -535,8 +535,8 @@ protected void prepareAddToHomescreenMenuItem(
if (shouldShowHomeScreenMenuItem) {
Context context = ContextUtils.getApplicationContext();
long addToHomeScreenStart = SystemClock.elapsedRealtime();
ResolveInfo resolveInfo =
WebApkValidator.queryFirstWebApkResolveInfo(context, currentTab.getUrlString());
ResolveInfo resolveInfo = WebApkValidator.queryFirstWebApkResolveInfo(
context, currentTab.getUrl().getSpec());
RecordHistogram.recordTimesHistogram("Android.PrepareMenu.OpenWebApkVisibilityCheck",
SystemClock.elapsedRealtime() - addToHomeScreenStart);

Expand Down Expand Up @@ -707,9 +707,9 @@ protected void updateRequestDesktopSiteMenuItem(
MenuItem requestMenuCheck = menu.findItem(R.id.request_desktop_site_check_id);

// Hide request desktop site on all chrome:// pages except for the NTP.
String url = currentTab.getUrlString();
boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX)
|| url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
GURL url = currentTab.getUrl();
boolean isChromeScheme = url.getScheme().equals(UrlConstants.CHROME_SCHEME)
|| url.getScheme().equals(UrlConstants.CHROME_NATIVE_SCHEME);

boolean itemVisible = canShowRequestDesktopSite
&& (!isChromeScheme || currentTab.isNativePage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.components.embedder_support.util.UrlUtilities;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.url.GURL;

/** Constructs delegates needed for reparenting tabs. */
public class ReparentingDelegateFactory {
Expand Down Expand Up @@ -50,7 +51,7 @@ public TabModelSelector getTabModelSelector() {
}

@Override
public boolean isNTPUrl(String url) {
public boolean isNTPUrl(GURL url) {
return UrlUtilities.isNTPUrl(url);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabReparentingParams;
import org.chromium.url.GURL;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,7 +31,7 @@ public interface Delegate {
TabModelSelector getTabModelSelector();

/** @return Whether the given Url is an NTP url, exists solely to support unit testing. */
boolean isNTPUrl(String url);
boolean isNTPUrl(GURL url);
}

private final Delegate mDelegate;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void prepareTabsForReparenting() {
if (mAsyncTabParamsManager.hasParamsForTabId(tab.getId())) continue;
// Intentionally skip new tab pages and allow them to reload and restore scroll
// state themselves.
if (mDelegate.isNTPUrl(tab.getUrlString())) continue;
if (mDelegate.isNTPUrl(tab.getUrl())) continue;

TabReparentingParams params = new TabReparentingParams(tab, null);
mAsyncTabParamsManager.add(tab.getId(), params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.chromium.ui.resources.ResourceManager;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
import org.chromium.ui.util.TokenHolder;
import org.chromium.url.GURL;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -794,9 +795,9 @@ public void initLayoutTabFromHost(final int tabId) {
LayoutTab layoutTab = mTabCache.get(tabId);
if (layoutTab == null) return;

String url = tab.getUrlString();
boolean isNativePage = tab.isNativePage()
|| (url != null && url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX));
GURL url = tab.getUrl();
boolean isNativePage =
tab.isNativePage() || url.getScheme().equals(UrlConstants.CHROME_NATIVE_SCHEME);

boolean canUseLiveTexture = tab.getWebContents() != null && !SadTab.isShowing(tab)
&& !isNativePage && !tab.isHidden();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ private void updateStaticTab(Tab tab) {
mModel.set(LayoutTab.SHOULD_STALL, shouldStall(tab));
mModel.set(LayoutTab.TEXT_BOX_BACKGROUND_COLOR, getToolbarTextBoxBackgroundColor(tab));

String url = tab.getUrlString();
boolean isNativePage = tab.isNativePage()
|| (url != null && url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX));
GURL url = tab.getUrl();
boolean isNativePage =
tab.isNativePage() || url.getScheme().equals(UrlConstants.CHROME_NATIVE_SCHEME);
boolean canUseLiveTexture =
tab.getWebContents() != null && !SadTab.isShowing(tab) && !isNativePage;
mModel.set(LayoutTab.CAN_USE_LIVE_TEXTURE, canUseLiveTexture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.chromium.chrome.browser.ui.native_page.NativePage;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.display.DisplayAndroid;
import org.chromium.url.GURL;

import java.io.File;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -577,7 +578,7 @@ private void captureThumbnail(
* @param tabId The id of the {@link Tab} thumbnail to check.
* @param url The current URL of the {@link Tab}.
*/
public void invalidateIfChanged(int tabId, String url) {
public void invalidateIfChanged(int tabId, GURL url) {
if (mNativeTabContentManager != 0) {
TabContentManagerJni.get().invalidateIfChanged(
mNativeTabContentManager, TabContentManager.this, tabId, url);
Expand All @@ -589,7 +590,7 @@ public void invalidateIfChanged(int tabId, String url) {
* @param id The id of the {@link Tab} thumbnail to check.
* @param url The current URL of the {@link Tab}.
*/
public void invalidateTabThumbnail(int id, String url) {
public void invalidateTabThumbnail(int id, GURL url) {
invalidateIfChanged(id, url);
}

Expand Down Expand Up @@ -663,7 +664,7 @@ void captureThumbnail(long nativeTabContentManager, TabContentManager caller, Ob
void cacheTabWithBitmap(long nativeTabContentManager, TabContentManager caller, Object tab,
Object bitmap, float thumbnailScale);
void invalidateIfChanged(
long nativeTabContentManager, TabContentManager caller, int tabId, String url);
long nativeTabContentManager, TabContentManager caller, int tabId, GURL url);
void updateVisibleIds(long nativeTabContentManager, TabContentManager caller,
int[] priority, int primaryTabId);
void removeTabThumbnail(long nativeTabContentManager, TabContentManager caller, int tabId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -35,6 +34,7 @@
import org.chromium.chrome.browser.ui.appmenu.AppMenuHandler;
import org.chromium.chrome.browser.ui.appmenu.CustomViewBinder;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.url.GURL;

import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -101,7 +101,7 @@ public int getAppMenuLayoutId() {
public void prepareMenu(Menu menu, AppMenuHandler handler) {
Tab currentTab = mActivityTabProvider.get();
if (currentTab != null) {
String url = currentTab.getUrlString();
GURL url = currentTab.getUrl();

MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id);
forwardMenuItem.setEnabled(currentTab.canGoForward());
Expand Down Expand Up @@ -151,7 +151,7 @@ public void prepareMenu(Menu menu, AppMenuHandler handler) {
requestDesktopSiteVisible = false;
// For Webapps & WebAPKs Verifier#wasPreviouslyVerified() performs verification
// (instead of looking up cached value).
addToHomeScreenVisible = !mVerifier.wasPreviouslyVerified(url);
addToHomeScreenVisible = !mVerifier.wasPreviouslyVerified(url.getSpec());
downloadItemVisible = false;
bookmarkItemVisible = false;
} else if (mUiType == CustomTabsUiType.OFFLINE_PAGE) {
Expand All @@ -175,9 +175,9 @@ public void prepareMenu(Menu menu, AppMenuHandler handler) {
openInChromeItemVisible = false;
}

boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX)
|| url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
if (isChromeScheme || TextUtils.isEmpty(url)) {
boolean isChromeScheme = url.getScheme().equals(UrlConstants.CHROME_SCHEME)
|| url.getScheme().equals(UrlConstants.CHROME_NATIVE_SCHEME);
if (isChromeScheme || url.isEmpty()) {
addToHomeScreenVisible = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.PageTransition;
import org.chromium.url.GURL;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -258,10 +259,11 @@ public boolean openCurrentUrlInBrowser(boolean forceReparenting) {
Tab tab = mTabProvider.getTab();
if (tab == null) return false;

String url = tab.getUrlString();
if (DomDistillerUrlUtils.isDistilledPage(url)) {
url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
GURL gurl = tab.getUrl();
if (DomDistillerUrlUtils.isDistilledPage(gurl)) {
gurl = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(gurl);
}
String url = gurl.getSpec();
if (TextUtils.isEmpty(url)) url = mIntentDataProvider.getUrlToLoad();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ public void didStartNavigation(NavigationHandle navigation) {
int index = controller.getLastCommittedEntryIndex();
NavigationEntry entry = controller.getEntryAtIndex(index);

if (entry != null
&& DomDistillerUrlUtils.isDistilledPage(entry.getUrl().getSpec())) {
if (entry != null && DomDistillerUrlUtils.isDistilledPage(entry.getUrl())) {
mShouldRemovePreviousNavigation = true;
mLastDistillerPageIndex = index;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void recordContentSuggestionsDisplayStatus(Profile profile) {
private static class TabCreationRecorder implements TabModelSelectorObserver {
@Override
public void onNewTabCreated(Tab tab, @TabCreationState int creationState) {
if (!UrlUtilities.isNTPUrl(tab.getUrlString())) return;
if (!UrlUtilities.isNTPUrl(tab.getUrl())) return;
RecordUserAction.record("MobileNTPOpenedInNewTab");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,12 @@ public void set(LocationBarMediator object, Float value) {
}

if (currentTab != null
&& (currentTab.isNativePage()
|| UrlUtilities.isNTPUrl(currentTab.getUrlString()))) {
&& (currentTab.isNativePage() || UrlUtilities.isNTPUrl(currentTab.getUrl()))) {
NewTabPageUma.recordOmniboxNavigation(url, transition);
// Passing in an empty string should not do anything unless the user is at the NTP.
// Since the NTP has no url, pressing enter while clicking on the URL bar should refresh
// the page as it does when you click and press enter on any other site.
if (url.isEmpty()) url = currentTab.getUrlString();
if (url.isEmpty()) url = currentTab.getUrl().getSpec();
}

// Loads the |url| in a new tab or the current ContentView and gives focus to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.chromium.chrome.browser.tab.Tab;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.url.GURL;

/**
* A collection of helper functions for sharing in a non static context.
Expand All @@ -23,10 +24,10 @@ public boolean shouldEnableShare(@Nullable Tab tab) {
return false;
}

String url = tab.getUrlString();
boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX)
|| url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
boolean isDataScheme = url.startsWith(UrlConstants.DATA_SCHEME);
GURL url = tab.getUrl();
boolean isChromeScheme = url.getScheme().equals(UrlConstants.CHROME_SCHEME)
|| url.getScheme().equals(UrlConstants.CHROME_NATIVE_SCHEME);
boolean isDataScheme = url.getScheme().equals(UrlConstants.DATA_SCHEME);

return !isChromeScheme && !isDataScheme;
}
Expand Down

0 comments on commit b10c4fb

Please sign in to comment.