Skip to content

Commit 6c7dc8f

Browse files
graycreateclaude
andcommitted
fix: Address Copilot review comments for VshareWebActivity
- Fix navigation handling: Return false in shouldOverrideUrlLoading to let WebView handle standard navigation - Add security settings: Disable file/content access and enable Safe Browsing for API >= 26 - Fix theme switching: Compute URL in onCreate to handle live theme changes - Remove redundant progress bar logic: Consolidate visibility handling in WebChromeClient - Optimize cache handling: Use clearCache(false) to avoid purging shared cache - Fix layout theming: Use app-themed attribute (page_bg_color) instead of android:attr All issues identified by GitHub Copilot have been addressed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 174d615 commit 6c7dc8f

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

app/src/main/java/me/ghui/v2er/module/vshare/VshareWebActivity.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
*/
2929
public class VshareWebActivity extends AppCompatActivity {
3030

31-
private static final String KEY_URL = "url";
3231
private static final String VSHARE_BASE_URL = "https://v2er.app/vshare";
3332

3433
@BindView(R.id.webview)
@@ -39,14 +38,6 @@ public class VshareWebActivity extends AppCompatActivity {
3938

4039
public static void open(Context context) {
4140
Intent intent = new Intent(context, VshareWebActivity.class);
42-
// Append theme parameter based on current app theme
43-
String url = VSHARE_BASE_URL;
44-
if (DarkModelUtils.isDarkMode()) {
45-
url += "?theme=dark";
46-
} else {
47-
url += "?theme=light";
48-
}
49-
intent.putExtra(KEY_URL, url);
5041
context.startActivity(intent);
5142
}
5243

@@ -69,11 +60,14 @@ protected void onCreate(Bundle savedInstanceState) {
6960

7061
setupWebView();
7162

72-
// Load the URL
73-
String url = getIntent().getStringExtra(KEY_URL);
74-
if (url != null) {
75-
mWebView.loadUrl(url);
63+
// Compute URL with theme parameter based on current app theme
64+
String url = VSHARE_BASE_URL;
65+
if (DarkModelUtils.isDarkMode()) {
66+
url += "?theme=dark";
67+
} else {
68+
url += "?theme=light";
7669
}
70+
mWebView.loadUrl(url);
7771
}
7872

7973
@SuppressLint("SetJavaScriptEnabled")
@@ -86,6 +80,15 @@ private void setupWebView() {
8680
// Enable DOM storage
8781
settings.setDomStorageEnabled(true);
8882

83+
// Disable file and content access for security
84+
settings.setAllowFileAccess(false);
85+
settings.setAllowContentAccess(false);
86+
87+
// Enable Safe Browsing if API >= 26
88+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
89+
settings.setSafeBrowsingEnabled(true);
90+
}
91+
8992
// Enable responsive layout
9093
settings.setUseWideViewPort(true);
9194
settings.setLoadWithOverviewMode(true);
@@ -102,9 +105,8 @@ private void setupWebView() {
102105
mWebView.setWebViewClient(new WebViewClient() {
103106
@Override
104107
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
105-
// Keep navigation within the WebView
106-
view.loadUrl(request.getUrl().toString());
107-
return true;
108+
// Let the WebView handle the navigation
109+
return false;
108110
}
109111

110112
@Override
@@ -116,7 +118,6 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
116118
@Override
117119
public void onPageFinished(WebView view, String url) {
118120
super.onPageFinished(view, url);
119-
mProgressBar.setVisibility(View.GONE);
120121

121122
// Inject CSS to ensure proper theme is applied
122123
String theme = DarkModelUtils.isDarkMode() ? "dark" : "light";
@@ -153,7 +154,7 @@ public void onBackPressed() {
153154
protected void onDestroy() {
154155
if (mWebView != null) {
155156
mWebView.clearHistory();
156-
mWebView.clearCache(true);
157+
mWebView.clearCache(false);
157158
mWebView.loadUrl("about:blank");
158159
mWebView.pauseTimers();
159160
mWebView.destroy();

app/src/main/res/layout/activity_vshare_web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5-
android:background="?android:attr/windowBackground">
5+
android:background="?attr/page_bg_color">
66

77
<WebView
88
android:id="@+id/webview"

0 commit comments

Comments
 (0)