cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Grieve <agri...@chromium.org>
Subject Re: Android: Deprecate WebView.sendJavascript()?
Date Tue, 03 Jun 2014 02:27:20 GMT
Filed: https://issues.apache.org/jira/browse/CB-6851


On Mon, May 26, 2014 at 9:42 PM, Andrew Grieve <agrieve@chromium.org> wrote:

> I believe this is the common case that the function is used for.
>
> The way to do it without eval is:
>
> 1. Have your app receive the intent. If the app is still starting up, then
> store it in a variable.
> 2. When cordova.js runs, have a plugin whose JS runs on start-up via a
> <runs/> tag. It would call exec() to retrieve the cached value.
> 3. Send the cached value with keepCallback=1, so that from now on, the
> plugin can push data to JS via that CallbackContext.
>
> This method is also nice, because you can have plugins delay the
> deviceready event until they've set up their CallbackContext channels (if
> desired).
>
>
>
>
> On Mon, May 26, 2014 at 3:17 PM, Axel Nennker <ignisvulpis@gmail.com>
> wrote:
>
>> We have plugins that register for a secure element element in Android.
>>
>> From the plugin.xml file:
>>
>>         <config-file target="AndroidManifest.xml"
>> parent="/manifest/application">
>>           <activity
>>
>> android:name="de.dtag.tlabs.wallet.handler.UiccTransactionEventHandlerActivity"
>>             android:finishOnTaskLaunch="true"
>>             android:launchMode="singleInstance"
>>             android:noHistory="true"
>>             android:theme="@android:style/Theme.NoTitleBar" >
>>             <intent-filter>
>>                 <action
>> android:name="android.nfc.action.TRANSACTION_DETECTED" />
>>                 <category android:name="android.intent.category.DEFAULT"
>> />
>>
>>                 <data
>>                     android:host="secure"
>>                     android:path="/a00000000102"
>>                     android:port="0"
>>                     android:scheme="nfc" />
>>            </intent-filter>
>>           </activity>
>>         </config-file>
>>
>> The activity then starts the main cordova application (with or without
>> newintent depending whether main is already running or not) and the plugin
>> fires a javascript event to the main application using sendJavascript.
>>
>>   static final String javaScriptEventTemplate = "var e =
>> document.createEvent(''Event'');\n"
>>       + "e.initEvent(''{0}'');\n" + "e.tag = {1};\n" +
>> "document.dispatchEvent(e);";
>>
>>   private void fireTagEvent(final String eventName, final String value) {
>>     final CordovaWebView webView = this.webView;
>>     cordova.getActivity().runOnUiThread(new Runnable() {
>>       @Override
>>       public void run() {
>>         String command = MessageFormat.format(javaScriptEventTemplate,
>> eventName, value);
>>         Log.v(TAG, "Executing java script command: ");
>>         Log.v(TAG, command);
>>         webView.sendJavascript(command);
>>       }
>>     });
>>   }
>>
>>
>>
>> I do not know how I would do this with PluginResult...
>>
>>
>> The main application has a addEventListener in it's javascript that
>> catches
>> the javascript event fired from the native plugin.
>> How would I do this without sendJavascript?
>>
>> -Axel
>>
>>
>>
>> 2014-05-26 20:58 GMT+02:00 Joe Bowser <bowserj@gmail.com>:
>>
>> > On Mon, May 26, 2014 at 11:53 AM, Jesse <purplecabbage@gmail.com>
>> wrote:
>> > > Is the webview method evaluateJavascript [1] still available, callable
>> > from
>> > > the context of a plugin? Or is this somehow hidden?
>> >
>> > It only exists on KitKat, earlier implementations require
>> > loadURL(javascript://).
>> >
>> > >
>> > > Personally I think is okay to remove the cordova implemented
>> > > sendJavascript() as long as there is still a way to accomplish the
>> rare
>> > but
>> > > sometimes required bare metal pass through.
>> > >
>> > > Do/will other pluggable webviews support a consistent interface for
>> > calling
>> > > javascript in their loaded pages? ie. Does crosswalk support
>> > > evaluateJavascript?
>> > >
>> > Very good question! I don't know.
>> >
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message