cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: Add a new type to the Native->JS bridge for binary strings.
Date Fri, 15 Mar 2013 20:47:58 GMT
Updated Branches:
  refs/heads/master d25b73f47 -> 7755a902d


Add a new type to the Native->JS bridge for binary strings.

It's needed since the bridge truncates strings that have null
characters in them :(.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/7755a902
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/7755a902
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/7755a902

Branch: refs/heads/master
Commit: 7755a902dd8ce8e352f1388e0e5626886407a3aa
Parents: d25b73f
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Mar 15 16:47:04 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Mar 15 16:47:04 2013 -0400

----------------------------------------------------------------------
 .../org/apache/cordova/NativeToJsMessageQueue.java |    9 ++++++++-
 .../src/org/apache/cordova/api/PluginResult.java   |   11 +++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7755a902/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
index 829f322..ea684a4 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -409,6 +409,9 @@ public class NativeToJsMessageQueue {
                 case PluginResult.MESSAGE_TYPE_STRING: // s
                     ret += 1 + pluginResult.getStrMessage().length();
                     break;
+                case PluginResult.MESSAGE_TYPE_BINARYSTRING:
+                    ret += 1 + pluginResult.getMessage().length();
+                    break;
                 case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
                     ret += 1 + pluginResult.getMessage().length();
                     break;
@@ -451,7 +454,11 @@ public class NativeToJsMessageQueue {
                     sb.append('s');
                     sb.append(pluginResult.getStrMessage());
                     break;
-                case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
+                case PluginResult.MESSAGE_TYPE_BINARYSTRING: // S
+                    sb.append('S');
+                    sb.append(pluginResult.getMessage());
+                    break;                    
+                case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: // A
                     sb.append('A');
                     sb.append(pluginResult.getMessage());
                     break;

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7755a902/framework/src/org/apache/cordova/api/PluginResult.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginResult.java b/framework/src/org/apache/cordova/api/PluginResult.java
index 4c1d833..a642200 100755
--- a/framework/src/org/apache/cordova/api/PluginResult.java
+++ b/framework/src/org/apache/cordova/api/PluginResult.java
@@ -71,11 +71,15 @@ public class PluginResult {
     }
 
     public PluginResult(Status status, byte[] data) {
+        this(status, data, false);
+    }
+
+    public PluginResult(Status status, byte[] data, boolean binaryString) {
         this.status = status.ordinal();
-        this.messageType = MESSAGE_TYPE_ARRAYBUFFER;
+        this.messageType = binaryString ? MESSAGE_TYPE_BINARYSTRING : MESSAGE_TYPE_ARRAYBUFFER;
         this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
     }
-
+    
     public void setKeepCallback(boolean b) {
         this.keepCallback = b;
     }
@@ -143,6 +147,9 @@ public class PluginResult {
     public static final int MESSAGE_TYPE_BOOLEAN = 4;
     public static final int MESSAGE_TYPE_NULL = 5;
     public static final int MESSAGE_TYPE_ARRAYBUFFER = 6;
+    // Use BINARYSTRING when your string may contain null characters.
+    // This is required to work around a bug in the platform :(.
+    public static final int MESSAGE_TYPE_BINARYSTRING = 7;
 
     public static String[] StatusMessages = new String[] {
         "No result",


Mime
View raw message