Skip to content

Commit

Permalink
fix(core): ShadowWebView init时应避免调用子类setWebViewClient实现
Browse files Browse the repository at this point in the history
note:init时调用setWebViewClient是为了应对业务代码从来没有调用setWebViewClient的场景。

fix Tencent#1175
  • Loading branch information
shifujun committed Apr 18, 2023
1 parent a30a15c commit 4b3f23d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.tencent.shadow.sample.plugin.app.lib.usecases.webview;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tencent.shadow.sample.plugin.app.lib.gallery.cases.entity.UseCase;

Expand All @@ -29,10 +32,31 @@ public Class getPageClass() {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

WebView webView = new WebView(this);
WebView webView = new FooWebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/web/test.html?t=" + Math.random());

setContentView(webView);
}
}

/**
* 复现
* https://github.com/Tencent/Shadow/issues/1175
*/
class FooWebView extends WebView {

public FooWebView(@NonNull Context context) {
super(context);
}

@Override
public void setWebViewClient(@NonNull WebViewClient client) {
FooWebViewClient fooWebViewClient = (FooWebViewClient) client;
super.setWebViewClient(fooWebViewClient);
}
}

class FooWebViewClient extends WebViewClient {

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ShadowWebView(Context context, AttributeSet attrs, int defStyleAttr, bool

private void init(Context context) {
mContext = context;
setWebViewClient(new WebViewClient());
super.setWebViewClient(new WarpWebViewClient(new WebViewClient(), mContext));
}

@Override
Expand Down

0 comments on commit 4b3f23d

Please sign in to comment.