3434 */
3535public class EasyBridgeWebView extends WebView {
3636
37+ public interface OnBridgeInjectedListener {
38+ /**
39+ * observe the bridge injected event of each page
40+ */
41+ void onInjected ();
42+ }
43+
3744 private static final String JAVA_SCRIPT_PROTOCOL = "javascript:" ;
3845 static final String MAPPING_JS_INTERFACE_NAME = "_easybridge" ;
3946 private static final String DEFAULT_BRIDGE_NAME = "easyBridge" ;
@@ -43,6 +50,7 @@ public class EasyBridgeWebView extends WebView {
4350 protected SecurityPolicyChecker policyChecker ;
4451 // whether the bridge had been injected to the currentPage
4552 private volatile boolean isInjected ;
53+ private OnBridgeInjectedListener listener ;
4654
4755 public EasyBridgeWebView (Context context , String bridgeName ) {
4856 this (context , (AttributeSet ) null );
@@ -77,6 +85,9 @@ private void initWebView() {
7785 @ Override
7886 public void onCall (String parameters , ResultCallBack callBack ) {
7987 Logger .debug ("inject bridge success in page:" + getUrl ());
88+ if (listener != null ) {
89+ listener .onInjected ();
90+ }
8091 setInjected (true );
8192 }
8293 });
@@ -97,6 +108,9 @@ public void unregisterHandler(String handlerName) {
97108 // use to execute JavaScript
98109 public void callHandler (String handlerName , String parameters , ResultCallBack resultCallBack ) {
99110 if (easyBridge != null ) {
111+ if (parameters == null ) {
112+ parameters = "" ;
113+ }
100114 easyBridge .callHandler (handlerName , parameters , resultCallBack );
101115 }
102116 }
@@ -140,6 +154,10 @@ public void setPolicyChecker(SecurityPolicyChecker policyChecker) {
140154 this .policyChecker = policyChecker ;
141155 }
142156
157+ public void setBridgeInjectedListener (OnBridgeInjectedListener listener ) {
158+ this .listener = listener ;
159+ }
160+
143161 public EasyBridgeWebView setDebuggable (boolean debuggable ) {
144162 Logger .setDebuggable (debuggable );
145163 return this ;
0 commit comments