cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject mac commit: CB-8417 moved platform specific js into platform
Date Sat, 07 Feb 2015 01:42:47 GMT
Repository: cordova-osx
Updated Branches:
  refs/heads/master 1c612a2a3 -> 67e69f6c5


CB-8417 moved platform specific js into platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/67e69f6c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/67e69f6c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/67e69f6c

Branch: refs/heads/master
Commit: 67e69f6c52a56a2f7254da50b60045108cead66d
Parents: 1c612a2
Author: Steve Gill <stevengill97@gmail.com>
Authored: Fri Feb 6 17:42:42 2015 -0800
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Fri Feb 6 17:42:42 2015 -0800

----------------------------------------------------------------------
 cordova-js-src/exec.js               | 117 ++++++++++++++++++++++++++++++
 cordova-js-src/platform.js           |  27 +++++++
 cordova-js-src/plugin/osx/.gitignore |   0
 3 files changed, 144 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/67e69f6c/cordova-js-src/exec.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js
new file mode 100644
index 0000000..ff52009
--- /dev/null
+++ b/cordova-js-src/exec.js
@@ -0,0 +1,117 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/**
+ * Creates a gap bridge used to notify the native code about commands.
+
+ * @private
+ */
+var cordova = require('cordova'),
+    channel = require('cordova/channel'),
+    utils = require('cordova/utils'),
+    base64 = require('cordova/base64');
+
+
+function massageMessageNativeToJs(message) {
+    if (message.CDVType == 'ArrayBuffer') {
+        var stringToArrayBuffer = function(str) {
+            var ret = new Uint8Array(str.length);
+            for (var i = 0; i < str.length; i++) {
+                ret[i] = str.charCodeAt(i);
+            }
+            return ret.buffer;
+        };
+        var base64ToArrayBuffer = function(b64) {
+            return stringToArrayBuffer(atob(b64));
+        };
+        message = base64ToArrayBuffer(message.data);
+    }
+    return message;
+}
+
+function convertMessageToArgsNativeToJs(message) {
+    var args = [];
+    if (!message || !message.hasOwnProperty('CDVType')) {
+        args.push(message);
+    } else if (message.CDVType == 'MultiPart') {
+        message.messages.forEach(function(e) {
+            args.push(massageMessageNativeToJs(e));
+        });
+    } else {
+        args.push(massageMessageNativeToJs(message));
+    }
+    return args;
+}
+
+function massageArgsJsToNative(args) {
+    if (!args || utils.typeName(args) != 'Array') {
+        return args;
+    }
+    var ret = [];
+    args.forEach(function(arg, i) {
+        if (utils.typeName(arg) == 'ArrayBuffer') {
+            ret.push({
+                'CDVType': 'ArrayBuffer',
+                'data': base64.fromArrayBuffer(arg)
+            });
+        } else {
+            ret.push(arg);
+        }
+    });
+    return ret;
+}
+
+function OSXExec() {
+
+    var successCallback, failCallback, service, action, actionArgs, splitCommand;
+    var callbackId = 'INVALID';
+
+    successCallback = arguments[0];
+    failCallback = arguments[1];
+    service = arguments[2];
+    action = arguments[3];
+    actionArgs = arguments[4];
+
+    // Register the callbacks and add the callbackId to the positional
+    // arguments if given.
+    if (successCallback || failCallback) {
+        callbackId = service + cordova.callbackId++;
+        cordova.callbacks[callbackId] =
+            {success:successCallback, fail:failCallback};
+    }
+
+    actionArgs = massageArgsJsToNative(actionArgs);
+
+    if (window.cordovabridge && window.cordovabridge.exec) {
+        window.cordovabridge.exec(callbackId, service, action, actionArgs);
+    } else {
+        alert('window.cordovabridge binding is missing.');
+    }
+}
+
+
+OSXExec.nativeCallback = function(callbackId, status, message, keepCallback) {
+    var success = status === 0 || status === 1;
+    var args = convertMessageToArgsNativeToJs(message);
+    cordova.callbackFromNative(callbackId, success, status, args, keepCallback);
+};
+
+module.exports = OSXExec;

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/67e69f6c/cordova-js-src/platform.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js
new file mode 100644
index 0000000..c74c2be
--- /dev/null
+++ b/cordova-js-src/platform.js
@@ -0,0 +1,27 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+    id: "osx",
+    initialize:function() {
+    }
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/67e69f6c/cordova-js-src/plugin/osx/.gitignore
----------------------------------------------------------------------
diff --git a/cordova-js-src/plugin/osx/.gitignore b/cordova-js-src/plugin/osx/.gitignore
new file mode 100644
index 0000000..e69de29


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message