@Test public void testJsonPopAndEncodeAsJs() { NativeToJsMessageQueue.BridgeMode bridge; bridge = new NativeToJsMessageQueue.NoOpBridgeMode(); queue.addBridgeMode(bridge); queue.setBridgeMode(0); JSONObject object = new JSONObject(); try { object.put("test", "value"); } catch (JSONException e) { e.printStackTrace(); } PluginResult result = new PluginResult(PluginResult.Status.OK, object); queue.addPluginResult(result, TEST_CALLBACK_ID); assertFalse(queue.isEmpty()); String resultString = queue.popAndEncodeAsJs(); assertTrue(resultString.startsWith("cordova.callbackFromNative")); }
@Override public void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, Whitelist whitelist, CordovaPreferences preferences) { if (this.cordova != null) { throw new IllegalStateException(); } this.cordova = cordova; this.whitelist = whitelist; this.preferences = preferences; pluginManager = new PluginManager(this, this.cordova, pluginEntries); resourceApi = new CordovaResourceApi(webview.getContext(), pluginManager); bridge = new CordovaBridge(pluginManager, new NativeToJsMessageQueue(this, cordova)); pluginManager.addService("App", "org.apache.cordova.CoreAndroid"); initWebViewSettings(); webview.init(this); exposeJsInterface(); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; chrome = new CordovaGeckoViewChrome(this, cordova); // We set the delegate on the Engine first. webView.setChromeDelegate(chrome); webView.loadConfiguration(); webView.init(this, cordova); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Test public void testEnabledBridge() { NativeToJsMessageQueue.BridgeMode bridge; bridge = new NativeToJsMessageQueue.NoOpBridgeMode(); queue.addBridgeMode(bridge); queue.setBridgeMode(0); assertTrue(queue.isBridgeEnabled()); }
@Test public void testPopAndEncode() { NativeToJsMessageQueue.BridgeMode bridge; bridge = new NativeToJsMessageQueue.NoOpBridgeMode(); queue.addBridgeMode(bridge); queue.setBridgeMode(0); PluginResult result = new PluginResult(PluginResult.Status.OK); queue.addPluginResult(result, TEST_CALLBACK_ID); assertFalse(queue.isEmpty()); String resultString = queue.popAndEncode(false); String [] results = resultString.split(" "); assertEquals(TEST_CALLBACK_ID, results[2]); }
@Test public void testBasicPopAndEncodeAsJs() { NativeToJsMessageQueue.BridgeMode bridge; bridge = new NativeToJsMessageQueue.NoOpBridgeMode(); queue.addBridgeMode(bridge); queue.setBridgeMode(0); PluginResult result = new PluginResult(PluginResult.Status.OK); queue.addPluginResult(result, TEST_CALLBACK_ID); assertFalse(queue.isEmpty()); String resultString = queue.popAndEncodeAsJs(); assertTrue(resultString.startsWith("cordova.callbackFromNative")); }
@Test public void testStringPopAndEncodeAsJs() { NativeToJsMessageQueue.BridgeMode bridge; bridge = new NativeToJsMessageQueue.NoOpBridgeMode(); queue.addBridgeMode(bridge); queue.setBridgeMode(0); PluginResult result = new PluginResult(PluginResult.Status.OK, "String Plugin Result"); queue.addPluginResult(result, TEST_CALLBACK_ID); assertFalse(queue.isEmpty()); String resultString = queue.popAndEncodeAsJs(); assertTrue(resultString.startsWith("cordova.callbackFromNative")); }
@Test public void testMultipartPopAndEncodeAsJs() { ArrayList<PluginResult> multiparts = new ArrayList<PluginResult>(); for (int i=0; i<5; i++) { multiparts.add(new PluginResult(PluginResult.Status.OK, i)); } PluginResult multipartresult = new PluginResult(PluginResult.Status.OK, multiparts); NativeToJsMessageQueue queue = new NativeToJsMessageQueue(); queue.addBridgeMode(new NativeToJsMessageQueue.NoOpBridgeMode()); queue.setBridgeMode(0); queue.addPluginResult(multipartresult, "37"); String result = queue.popAndEncodeAsJs(); assertEquals(result, "cordova.callbackFromNative('37',true,1,[0,1,2,3,4],false);"); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { //sometimes this can be called after calling webview.destroy() on destroy() //thus resulting in a NullPointerException if(webView!=null) { webView.setNetworkAvailable(value); } } @Override public void runOnUiThread(Runnable r) { SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova)); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } // Needed when prefs are not passed by the constructor if (preferences == null) { preferences = parentWebView.getPreferences(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this, cordova); initWebViewSettings(); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); exposeJsInterface(webView, bridge); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; CordovaPlugin activityDelegatePlugin = new CordovaPlugin() { @Override public void onResume(boolean multitasking) { activityDelegate.onResume(); } }; pluginManager.addService(new PluginEntry("XWalkActivityDelegate", activityDelegatePlugin)); webView.init(this); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode( new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { XWalkWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); }
@Override public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) { if (this.cordova != null) { throw new IllegalStateException(); } this.parentWebView = parentWebView; this.cordova = cordova; this.client = client; this.resourceApi = resourceApi; this.pluginManager = pluginManager; this.nativeToJsMessageQueue = nativeToJsMessageQueue; webView.init(this); nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode( new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() { @Override public void setNetworkAvailable(boolean value) { webView.setNetworkAvailable(value); } @Override public void runOnUiThread(Runnable r) { XWalkWebViewEngine.this.cordova.getActivity().runOnUiThread(r); } })); bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue); }