Commit 3d4397ee authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Chromium LUCI CQ

Set CCT remote views' id to View.NO_ID

Replace remote view's id with View.NO_ID before they are added to
chrome's view hierarchy. This is to prevent the resources from clashing
with chrome's resource ids. Store the old id in a tag to be returned to
the application on clicks.

Bug: 1061872
Change-Id: I69c6c01c2d9fc6be6dc72f10c56a22f32506eb19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584903
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Auto-Submit: Mohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836167}
parent 3b00f4a4
......@@ -110,4 +110,7 @@
<!-- Enhanced Protection Promo -->
<item type="id" name="enhanced_protection_promo" />
<!-- Custom Tabs -->
<item type="id" name="view_id_tag_key" />
</resources>
......@@ -52,6 +52,7 @@ public class ChromeCachedFlags {
ChromeFeatureList.ANDROID_MANAGED_BY_MENU_ITEM,
ChromeFeatureList.ANDROID_PARTNER_CUSTOMIZATION_PHENOTYPE,
ChromeFeatureList.CCT_INCOGNITO_AVAILABLE_TO_THIRD_PARTY,
ChromeFeatureList.CCT_REMOVE_REMOTE_VIEW_IDS,
ChromeFeatureList.CHROME_STARTUP_DELEGATE,
ChromeFeatureList.CLOSE_TAB_SUGGESTIONS,
ChromeFeatureList.CRITICAL_PERSISTED_TAB_DATA,
......
......@@ -30,6 +30,8 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager.OverlayPanelManagerObserver;
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerImpl;
import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.night_mode.RemoteViewsWithNightModeInflater;
import org.chromium.chrome.browser.night_mode.SystemNightModeMonitor;
import org.chromium.chrome.browser.tab.Tab;
......@@ -70,7 +72,11 @@ public class CustomTabBottomBarDelegate implements BrowserControlsStateProvider.
public void onClick(View v) {
if (mClickPendingIntent == null) return;
Intent extraIntent = new Intent();
extraIntent.putExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_CLICKED_ID, v.getId());
int originalId = v.getId();
if (CachedFeatureFlags.isEnabled(ChromeFeatureList.CCT_REMOVE_REMOTE_VIEW_IDS)) {
originalId = (Integer) v.getTag(R.id.view_id_tag_key);
}
extraIntent.putExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_CLICKED_ID, originalId);
sendPendingIntentWithUrl(mClickPendingIntent, extraIntent, mActivity);
}
};
......@@ -276,6 +282,21 @@ public class CustomTabBottomBarDelegate implements BrowserControlsStateProvider.
mBrowserControlsSizer.setBottomControlsHeight(0, 0);
}
private void transformViewIds(View view) {
// Store the old id in a tag. The tag key here does not matter as long
// as it is unique across all tags.
view.setTag(R.id.view_id_tag_key, view.getId());
view.setId(View.NO_ID);
if (view instanceof ViewGroup) {
final ViewGroup group = (ViewGroup) view;
final int childCount = group.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = group.getChildAt(i);
transformViewIds(child);
}
}
}
private boolean showRemoteViews(RemoteViews remoteViews) {
final View inflatedView = RemoteViewsWithNightModeInflater.inflate(remoteViews,
getBottomBarView(), mNightModeStateController.isInNightMode(),
......@@ -290,6 +311,11 @@ public class CustomTabBottomBarDelegate implements BrowserControlsStateProvider.
if (view != null) view.setOnClickListener(mBottomBarClickListener);
}
}
if (CachedFeatureFlags.isEnabled(ChromeFeatureList.CCT_REMOVE_REMOTE_VIEW_IDS)) {
// Set all views' ids to be View.NO_ID to prevent them clashing with
// chrome's resource ids. See http://crbug.com/1061872
transformViewIds(inflatedView);
}
getBottomBarView().addView(inflatedView, 1);
inflatedView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
......
......@@ -140,6 +140,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&kCCTIncognitoAvailableToThirdParty,
&kCCTPostMessageAPI,
&kCCTRedirectPreconnect,
&kCCTRemoveRemoteViewIds,
&kCCTReportParallelRequestStatus,
&kCCTResourcePrefetch,
&kDarkenWebsitesCheckboxInThemesSetting,
......@@ -384,6 +385,9 @@ const base::Feature kCCTPostMessageAPI{"CCTPostMessageAPI",
const base::Feature kCCTRedirectPreconnect{"CCTRedirectPreconnect",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kCCTRemoveRemoteViewIds{"CCTRemoveRemoteViewIds",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kCCTReportParallelRequestStatus{
"CCTReportParallelRequestStatus", base::FEATURE_DISABLED_BY_DEFAULT};
......
......@@ -36,6 +36,7 @@ extern const base::Feature kCCTIncognito;
extern const base::Feature kCCTIncognitoAvailableToThirdParty;
extern const base::Feature kCCTPostMessageAPI;
extern const base::Feature kCCTRedirectPreconnect;
extern const base::Feature kCCTRemoveRemoteViewIds;
extern const base::Feature kCCTReportParallelRequestStatus;
extern const base::Feature kCCTResourcePrefetch;
extern const base::Feature kDontAutoHideBrowserControls;
......
......@@ -83,6 +83,7 @@ public class CachedFeatureFlags {
put(ChromeFeatureList.USE_CHIME_ANDROID_SDK, false);
put(ChromeFeatureList.CCT_INCOGNITO_AVAILABLE_TO_THIRD_PARTY, false);
put(ChromeFeatureList.READ_LATER, false);
put(ChromeFeatureList.CCT_REMOVE_REMOTE_VIEW_IDS, true);
}
};
......
......@@ -244,6 +244,7 @@ public abstract class ChromeFeatureList {
public static final String CCT_EXTERNAL_LINK_HANDLING = "CCTExternalLinkHandling";
public static final String CCT_POST_MESSAGE_API = "CCTPostMessageAPI";
public static final String CCT_REDIRECT_PRECONNECT = "CCTRedirectPreconnect";
public static final String CCT_REMOVE_REMOTE_VIEW_IDS = "CCTRemoveRemoteViewIds";
public static final String CCT_RESOURCE_PREFETCH = "CCTResourcePrefetch";
public static final String CCT_REPORT_PARALLEL_REQUEST_STATUS =
"CCTReportParallelRequestStatus";
......
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