AndroidX Webkit: small interstitials in the testapp
This adds an activity in the test app to demonstrate small (AKA "quiet")
Safe Browsing interstitials. This also modifies SafeBrowsingActivity to
call startSafeBrowsing(), since this will be a common dependency for
future Safe Browsing activities.
Bug: 124773936
Test: Manual
Change-Id: Id550ddfb55da4bbcd149c60211708fc76bc3631d
diff --git a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java
index 0f9a8fa..2d2385d 100644
--- a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java
+++ b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/SafeBrowsingActivity.java
@@ -17,10 +17,16 @@
package com.example.androidx.webkit;
import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
+import android.webkit.ValueCallback;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.webkit.WebViewCompat;
+import androidx.webkit.WebViewFeature;
/**
* An {@link Activity} to exercise Safe Browsing functionality.
@@ -31,9 +37,37 @@
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // TODO(ntfschr): actually do something eventually.
+ if (WebViewFeature.isFeatureSupported(WebViewFeature.START_SAFE_BROWSING)) {
+ WebViewCompat.startSafeBrowsing(this.getApplicationContext(),
+ new ValueCallback<Boolean>() {
+ @Override
+ public void onReceiveValue(@NonNull Boolean value) {
+ if (value) {
+ setupLayout();
+ } else {
+ WebkitHelpers.showMessageInActivity(SafeBrowsingActivity.this,
+ R.string.cannot_start_safe_browsing);
+ }
+ }
+ });
+ } else {
+ WebkitHelpers.showMessageInActivity(SafeBrowsingActivity.this,
+ R.string.webkit_api_not_available);
+ }
+ }
+
+ private void setupLayout() {
setContentView(R.layout.activity_safe_browsing);
setTitle(R.string.safebrowsing_activity_title);
WebkitHelpers.appendWebViewVersionToTitle(this);
+
+ final Context activityContext = this;
+ MenuListView listView = findViewById(R.id.safe_browsing_list);
+ MenuListView.MenuItem[] menuItems = new MenuListView.MenuItem[] {
+ new MenuListView.MenuItem(
+ getResources().getString(R.string.small_interstitial_activity_title),
+ new Intent(activityContext, SmallInterstitialActivity.class)),
+ };
+ listView.setItems(menuItems);
}
}