Commit 58bd32a4 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Chromium LUCI CQ

[iOS] Add multiple options for the ContextMenu flag

This CL change the context menu flag to add another options.
This allows to have the following options:
- The Web context menu
- The System context menu (but still using our implementation)

It will be decided later which implementation yields the best results.

Bug: 1140387
Change-Id: I92cf9fbb5be8214e295851a9293daba804b0e546
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584963
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841533}
parent 9ca289f6
...@@ -222,6 +222,19 @@ const FeatureEntry::FeatureVariation kDiscoverFeedInNtpVariations[] = { ...@@ -222,6 +222,19 @@ const FeatureEntry::FeatureVariation kDiscoverFeedInNtpVariations[] = {
{"Native UI", kDiscoverFeedInNtpEnableNativeUI, {"Native UI", kDiscoverFeedInNtpEnableNativeUI,
base::size(kDiscoverFeedInNtpEnableNativeUI), nullptr}}; base::size(kDiscoverFeedInNtpEnableNativeUI), nullptr}};
const FeatureEntry::FeatureParam kWebViewNativeContextMenuWeb[] = {
{web::features::kWebViewNativeContextMenuName,
web::features::kWebViewNativeContextMenuParameterWeb}};
const FeatureEntry::FeatureParam kWebViewNativeContextMenuSystem[] = {
{web::features::kWebViewNativeContextMenuName,
web::features::kWebViewNativeContextMenuParameterSystem}};
const FeatureEntry::FeatureVariation kWebViewNativeContextMenuVariations[] = {
{"Web", kWebViewNativeContextMenuWeb,
base::size(kWebViewNativeContextMenuWeb), nullptr},
{"System", kWebViewNativeContextMenuSystem,
base::size(kWebViewNativeContextMenuSystem), nullptr}};
// To add a new entry, add to the end of kFeatureEntries. There are four // To add a new entry, add to the end of kFeatureEntries. There are four
// distinct types of entries: // distinct types of entries:
// . ENABLE_DISABLE_VALUE: entry is either enabled, disabled, or uses the // . ENABLE_DISABLE_VALUE: entry is either enabled, disabled, or uses the
...@@ -562,7 +575,9 @@ const flags_ui::FeatureEntry kFeatureEntries[] = { ...@@ -562,7 +575,9 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
{"web-view-native-context-menu", {"web-view-native-context-menu",
flag_descriptions::kWebViewNativeContextMenuName, flag_descriptions::kWebViewNativeContextMenuName,
flag_descriptions::kWebViewNativeContextMenuDescription, flags_ui::kOsIos, flag_descriptions::kWebViewNativeContextMenuDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(web::features::kWebViewNativeContextMenu)}, FEATURE_WITH_PARAMS_VALUE_TYPE(web::features::kWebViewNativeContextMenu,
kWebViewNativeContextMenuVariations,
"WebViewNativeContextMenu")},
{"location-permissions-prompt", {"location-permissions-prompt",
flag_descriptions::kLocationPermissionsPromptName, flag_descriptions::kLocationPermissionsPromptName,
flag_descriptions::kLocationPermissionsPromptDescription, flags_ui::kOsIos, flag_descriptions::kLocationPermissionsPromptDescription, flags_ui::kOsIos,
......
...@@ -3294,7 +3294,8 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3294,7 +3294,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
handleContextMenu:(const web::ContextMenuParams&)params { handleContextMenu:(const web::ContextMenuParams&)params {
DCHECK(!web::features::UseWebViewNativeContextMenu()); DCHECK(!web::features::UseWebViewNativeContextMenuWeb() &&
!web::features::UseWebViewNativeContextMenuSystem());
// Prevent context menu from displaying for a tab which is no longer the // Prevent context menu from displaying for a tab which is no longer the
// current one. // current one.
if (webState != self.currentWebState) { if (webState != self.currentWebState) {
......
...@@ -62,6 +62,7 @@ class ChromeWebClient : public web::WebClient { ...@@ -62,6 +62,7 @@ class ChromeWebClient : public web::WebClient {
base::OnceCallback<void(NSString*)> callback) override; base::OnceCallback<void(NSString*)> callback) override;
UIView* GetWindowedContainer() override; UIView* GetWindowedContainer() override;
bool EnableLongPressAndForceTouchHandling() const override; bool EnableLongPressAndForceTouchHandling() const override;
bool EnableLongPressUIContextMenu() const override;
bool ForceMobileVersionByDefault(const GURL& url) override; bool ForceMobileVersionByDefault(const GURL& url) override;
web::UserAgentType GetDefaultUserAgent(id<UITraitEnvironment> web_view, web::UserAgentType GetDefaultUserAgent(id<UITraitEnvironment> web_view,
const GURL& url) override; const GURL& url) override;
......
...@@ -397,7 +397,11 @@ UIView* ChromeWebClient::GetWindowedContainer() { ...@@ -397,7 +397,11 @@ UIView* ChromeWebClient::GetWindowedContainer() {
} }
bool ChromeWebClient::EnableLongPressAndForceTouchHandling() const { bool ChromeWebClient::EnableLongPressAndForceTouchHandling() const {
return !web::features::UseWebViewNativeContextMenu(); return !web::features::UseWebViewNativeContextMenuWeb();
}
bool ChromeWebClient::EnableLongPressUIContextMenu() const {
return web::features::UseWebViewNativeContextMenuSystem();
} }
bool ChromeWebClient::ForceMobileVersionByDefault(const GURL& url) { bool ChromeWebClient::ForceMobileVersionByDefault(const GURL& url) {
......
...@@ -60,22 +60,31 @@ extern const base::Feature kScrollToTextIOS; ...@@ -60,22 +60,31 @@ extern const base::Feature kScrollToTextIOS;
// When enabled, display an interstitial on legacy TLS connections. // When enabled, display an interstitial on legacy TLS connections.
extern const base::Feature kIOSLegacyTLSInterstitial; extern const base::Feature kIOSLegacyTLSInterstitial;
// When enabled, use the native context menu in web content, for the iOS version
// that supports it.
extern const base::Feature kWebViewNativeContextMenu;
// Records snapshot size of image (IOS.Snapshots.ImageSize histogram) and PDF // Records snapshot size of image (IOS.Snapshots.ImageSize histogram) and PDF
// (IOS.Snapshots.PDFSize histogram) if enabled. Enabling this flag will // (IOS.Snapshots.PDFSize histogram) if enabled. Enabling this flag will
// generate PDF when Page Snapshot is taken just to record PDF size. // generate PDF when Page Snapshot is taken just to record PDF size.
extern const base::Feature kRecordSnapshotSize; extern const base::Feature kRecordSnapshotSize;
// When enabled, use the native context menu in web content, for the iOS version
// that supports it.
extern const base::Feature kWebViewNativeContextMenu;
// Parameter name and values for the native context menu.
extern const char kWebViewNativeContextMenuName[];
extern const char kWebViewNativeContextMenuParameterSystem[];
extern const char kWebViewNativeContextMenuParameterWeb[];
// When true, for each navigation, the default user agent is chosen by the // When true, for each navigation, the default user agent is chosen by the
// WebClient GetDefaultUserAgent() method. If it is false, the mobile version // WebClient GetDefaultUserAgent() method. If it is false, the mobile version
// is requested by default. // is requested by default.
bool UseWebClientDefaultUserAgent(); bool UseWebClientDefaultUserAgent();
// When true, the native context menu for the web content are used. // When true, the native context menu for the web content are used.
bool UseWebViewNativeContextMenu(); bool UseWebViewNativeContextMenuWeb();
// When true, the custom implementation of context menu using native ContextMenu
// for the web content is used.
bool UseWebViewNativeContextMenuSystem();
} // namespace features } // namespace features
} // namespace web } // namespace web
......
...@@ -46,11 +46,15 @@ const base::Feature kScrollToTextIOS{"ScrollToTextIOS", ...@@ -46,11 +46,15 @@ const base::Feature kScrollToTextIOS{"ScrollToTextIOS",
const base::Feature kIOSLegacyTLSInterstitial{"IOSLegacyTLSInterstitial", const base::Feature kIOSLegacyTLSInterstitial{"IOSLegacyTLSInterstitial",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kRecordSnapshotSize{"RecordSnapshotSize",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kWebViewNativeContextMenu{ const base::Feature kWebViewNativeContextMenu{
"WebViewNativeContextMenu", base::FEATURE_DISABLED_BY_DEFAULT}; "WebViewNativeContextMenu", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kRecordSnapshotSize{"RecordSnapshotSize", const char kWebViewNativeContextMenuName[] = "type";
base::FEATURE_DISABLED_BY_DEFAULT}; const char kWebViewNativeContextMenuParameterSystem[] = "system";
const char kWebViewNativeContextMenuParameterWeb[] = "web";
bool UseWebClientDefaultUserAgent() { bool UseWebClientDefaultUserAgent() {
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
...@@ -59,9 +63,24 @@ bool UseWebClientDefaultUserAgent() { ...@@ -59,9 +63,24 @@ bool UseWebClientDefaultUserAgent() {
return false; return false;
} }
bool UseWebViewNativeContextMenu() { bool UseWebViewNativeContextMenuWeb() {
if (@available(iOS 13, *)) {
if (!base::FeatureList::IsEnabled(kWebViewNativeContextMenu))
return false;
std::string field_trial_param = base::GetFieldTrialParamValueByFeature(
kWebViewNativeContextMenu, kWebViewNativeContextMenuName);
return field_trial_param == kWebViewNativeContextMenuParameterWeb;
}
return false;
}
bool UseWebViewNativeContextMenuSystem() {
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
return base::FeatureList::IsEnabled(kWebViewNativeContextMenu); if (!base::FeatureList::IsEnabled(kWebViewNativeContextMenu))
return false;
std::string field_trial_param = base::GetFieldTrialParamValueByFeature(
kWebViewNativeContextMenu, kWebViewNativeContextMenuName);
return field_trial_param == kWebViewNativeContextMenuParameterSystem;
} }
return false; return false;
} }
......
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