Skip to content

Commit

Permalink
Expose XRequestedWith api in glue code for AndroidX
Browse files Browse the repository at this point in the history
This commit does not expose the CONSTANT_WEBVIEW enum value, as it is
intended as a fallback for rollout testing, and is not at this point
intended for developer usage.

Bug: 1295213
Change-Id: Ia6af00ead6eb5f97e90e9eae61954002f6f4754a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3468347
Auto-Submit: Peter Pakkenberg <pbirk@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Commit-Queue: Peter Pakkenberg <pbirk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#972998}
  • Loading branch information
peterbn authored and Chromium LUCI CQ committed Feb 18, 2022
1 parent ef06c1e commit e25438c
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.chromium.support_lib_boundary;

import org.chromium.support_lib_boundary.WebSettingsBoundaryInterface.RequestedWithHeaderMode;

/**
* Boundary interface for ServiceWorkerWebSettings.
*/
Expand All @@ -23,4 +25,8 @@ public interface ServiceWorkerWebSettingsBoundaryInterface {
void setBlockNetworkLoads(boolean flag);

boolean getBlockNetworkLoads();

void setRequestedWithHeaderMode(@RequestedWithHeaderMode int mode);
@RequestedWithHeaderMode
int getRequestedWithHeaderMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ public interface WebSettingsBoundaryInterface {
void setWebAuthnSupport(@WebAuthnSupport int support);
@WebAuthnSupport
int getWebAuthnSupport();

@Retention(RetentionPolicy.SOURCE)
@interface RequestedWithHeaderMode {
int NO_HEADER = 0;
int APP_PACKAGE_NAME = 1;
}
void setRequestedWithHeaderMode(@RequestedWithHeaderMode int mode);
@RequestedWithHeaderMode
int getRequestedWithHeaderMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,10 @@ private Features() {}
// WebSettingsCompat.setWebAuthnSupport
// WebSettingsCompat.getWebAuthnSupport
public static final String WEB_AUTHENTICATION = "WEB_AUTHENTICATION";

// WebSettingsCompat.setRequestedWithHeaderMode
// WebSettingsCompat.getRequestedWithHeaderMode
// ServiceWorkerWebSettingsCompat.setRequestedWithHeaderMode
// ServiceWorkerWebSettingsCompat.getRequestedWithHeaderMode
public static final String REQUESTED_WITH_HEADER_CONTROL = "REQUESTED_WITH_HEADER_CONTROL";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import static org.chromium.support_lib_glue.SupportLibWebViewChromiumFactory.recordApiCall;

import org.chromium.android_webview.AwServiceWorkerSettings;
import org.chromium.android_webview.AwSettings;
import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
import org.chromium.support_lib_boundary.WebSettingsBoundaryInterface.RequestedWithHeaderMode;
import org.chromium.support_lib_glue.SupportLibWebViewChromiumFactory.ApiCall;

/**
Expand Down Expand Up @@ -71,4 +73,33 @@ public boolean getBlockNetworkLoads() {
recordApiCall(ApiCall.SERVICE_WORKER_SETTINGS_GET_BLOCK_NETWORK_LOADS);
return mAwServiceWorkerSettings.getBlockNetworkLoads();
}

@Override
public void setRequestedWithHeaderMode(int mode) {
recordApiCall(ApiCall.SERVICE_WORKER_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE);
switch (mode) {
case RequestedWithHeaderMode.NO_HEADER:
mAwServiceWorkerSettings.setRequestedWithHeaderMode(
AwSettings.REQUESTED_WITH_NO_HEADER);
break;
case RequestedWithHeaderMode.APP_PACKAGE_NAME:
mAwServiceWorkerSettings.setRequestedWithHeaderMode(
AwSettings.REQUESTED_WITH_APP_PACKAGE_NAME);
break;
}
}

@Override
public int getRequestedWithHeaderMode() {
recordApiCall(ApiCall.SERVICE_WORKER_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE);
// The AwSettings.REQUESTED_WITH_CONSTANT_WEBVIEW setting is intended to be internal
// and for testing only, so it will not be mapped in the public API.
switch (mAwServiceWorkerSettings.getRequestedWithHeaderMode()) {
case AwSettings.REQUESTED_WITH_NO_HEADER:
return RequestedWithHeaderMode.NO_HEADER;
case AwSettings.REQUESTED_WITH_APP_PACKAGE_NAME:
return RequestedWithHeaderMode.APP_PACKAGE_NAME;
}
return RequestedWithHeaderMode.APP_PACKAGE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,31 @@ public int getWebAuthnSupport() {
// Currently a no-op while this functionality is built out.
return WebAuthnSupport.NONE;
}

@Override
public void setRequestedWithHeaderMode(int mode) {
recordApiCall(ApiCall.WEB_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE);
switch (mode) {
case RequestedWithHeaderMode.NO_HEADER:
mAwSettings.setRequestedWithHeaderMode(AwSettings.REQUESTED_WITH_NO_HEADER);
break;
case RequestedWithHeaderMode.APP_PACKAGE_NAME:
mAwSettings.setRequestedWithHeaderMode(AwSettings.REQUESTED_WITH_APP_PACKAGE_NAME);
break;
}
}

@Override
public int getRequestedWithHeaderMode() {
recordApiCall(ApiCall.WEB_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE);
// The AwSettings.REQUESTED_WITH_CONSTANT_WEBVIEW setting is intended to be internal
// and for testing only, so it will not be mapped in the public API.
switch (mAwSettings.getRequestedWithHeaderMode()) {
case AwSettings.REQUESTED_WITH_NO_HEADER:
return RequestedWithHeaderMode.NO_HEADER;
case AwSettings.REQUESTED_WITH_APP_PACKAGE_NAME:
return RequestedWithHeaderMode.APP_PACKAGE_NAME;
}
return RequestedWithHeaderMode.APP_PACKAGE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary
Features.SET_SUPPORT_LIBRARY_VERSION + Features.DEV_SUFFIX,
Features.DOCUMENT_START_SCRIPT,
Features.PROXY_OVERRIDE_REVERSE_BYPASS,
Features.REQUESTED_WITH_HEADER_CONTROL + Features.DEV_SUFFIX
};

// These values are persisted to logs. Entries should not be renumbered and
Expand Down Expand Up @@ -143,7 +144,11 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary
ApiCall.ADD_DOCUMENT_START_SCRIPT,
ApiCall.REMOVE_DOCUMENT_START_SCRIPT,
ApiCall.SET_SAFE_BROWSING_ALLOWLIST,
ApiCall.SET_PROXY_OVERRIDE_REVERSE_BYPASS})
ApiCall.SET_PROXY_OVERRIDE_REVERSE_BYPASS,
ApiCall.WEB_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE,
ApiCall.WEB_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE,
ApiCall.SERVICE_WORKER_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE,
ApiCall.SERVICE_WORKER_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE})
public @interface ApiCall {
int ADD_WEB_MESSAGE_LISTENER = 0;
int CLEAR_PROXY_OVERRIDE = 1;
Expand Down Expand Up @@ -201,7 +206,12 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary
int REMOVE_DOCUMENT_START_SCRIPT = 53;
int SET_SAFE_BROWSING_ALLOWLIST = 54;
int SET_PROXY_OVERRIDE_REVERSE_BYPASS = 55;
int COUNT = 56;
int WEB_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE = 56;
int WEB_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE = 57;
int SERVICE_WORKER_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE = 58;
int SERVICE_WORKER_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE = 59;
// Remember to update AndroidXWebkitApiCall in enums.xml when adding new values here
int COUNT = 60;
}
// clang-format on

Expand Down
17 changes: 17 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2819,6 +2819,23 @@ Unknown properties are collapsed to zero. -->
<int value="54" label="SET_SAFE_BROWSING_ALLOWLIST">
WebViewCompat#setSafeBrowsingAllowlist(Set(String),ValueCallback(Boolean))
</int>
<int value="55" label="SET_PROXY_OVERRIDE_REVERSE_BYPASS">
ProxyController#setProxyOverride(String[][],String[],Runnable,Executor,boolean);
</int>
<int value="56" label="WEB_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE">
WebSettingsCompat#setRequestedWithHeaderMode(int)
</int>
<int value="57" label="WEB_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE">
WebViewCompat#WebSettingsCompat#getRequestedWithHeaderMode()
</int>
<int value="58"
label="SERVICE_WORKER_SETTINGS_SET_REQUESTED_WITH_HEADER_MODE">
ServiceWorkerWebSettingsCompat#setRequestedWithHeaderMode(int)
</int>
<int value="59"
label="SERVICE_WORKER_SETTINGS_GET_REQUESTED_WITH_HEADER_MODE">
ServiceWorkerWebSettingsCompat#getRequestedWithHeaderMode()
</int>
</enum>

<enum name="ANGLEProgramCacheResult">
Expand Down

0 comments on commit e25438c

Please sign in to comment.