You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/03/20 16:49:03 UTC
[19/40] js commit: [CB-2621] Added OS X platform
[CB-2621] Added OS X platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/090ab873
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/090ab873
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/090ab873
Branch: refs/heads/cb2227
Commit: 090ab8737ec27d33609b69d2b7d01fe4567c1511
Parents: d53601e
Author: Shazron Abdullah <sh...@apache.org>
Authored: Tue Mar 5 17:40:08 2013 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue Mar 5 17:40:08 2013 -0800
----------------------------------------------------------------------
Jakefile | 1 +
build/packager.js | 1 +
lib/osx/exec.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++
lib/osx/platform.js | 33 ++++++++++++
package.json | 4 ++
5 files changed, 163 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/090ab873/Jakefile
----------------------------------------------------------------------
diff --git a/Jakefile b/Jakefile
index aec4b69..5acee33 100644
--- a/Jakefile
+++ b/Jakefile
@@ -96,6 +96,7 @@ task('build', ['clean', 'hint', 'update-version'], function () {
packager.generate("bada",commitId);
packager.generate("tizen",commitId);
packager.generate("webos", commitId);
+ packager.generate("osx", commitId);
packager.generate("errgen",commitId);
packager.generate("test",commitId);
complete();
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/090ab873/build/packager.js
----------------------------------------------------------------------
diff --git a/build/packager.js b/build/packager.js
index b630f5b..c5f1636 100644
--- a/build/packager.js
+++ b/build/packager.js
@@ -64,6 +64,7 @@ packager.bundle = function(platform, debug, commitId ) {
copyProps(modules, collectFiles(path.join('lib', 'ios', 'plugin', 'ios'), 'plugin/ios/'));
copyProps(modules, collectFiles(path.join('lib', 'bada', 'plugin', 'bada'), 'plugin/bada/'));
copyProps(modules, collectFiles(path.join('lib', 'android', 'plugin', 'android'), 'plugin/android/'));
+ copyProps(modules, collectFiles(path.join('lib', 'osx', 'plugin', 'osx'), 'plugin/osx/'));
}
else {
copyProps(modules, collectFiles(path.join('lib', platform)))
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/090ab873/lib/osx/exec.js
----------------------------------------------------------------------
diff --git a/lib/osx/exec.js b/lib/osx/exec.js
new file mode 100644
index 0000000..facb1c4
--- /dev/null
+++ b/lib/osx/exec.js
@@ -0,0 +1,124 @@
+/*
+ *
+ * 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');
+
+
+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 = [];
+ var encodeArrayBufferAs8bitString = function(ab) {
+ return String.fromCharCode.apply(null, new Uint8Array(ab));
+ };
+ var encodeArrayBufferAsBase64 = function(ab) {
+ return window.btoa(encodeArrayBufferAs8bitString(ab));
+ };
+ args.forEach(function(arg, i) {
+ if (utils.typeName(arg) == 'ArrayBuffer') {
+ ret.push({
+ 'CDVType': 'ArrayBuffer',
+ 'data': encodeArrayBufferAsBase64(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) {
+ return (function() {
+ 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-js/blob/090ab873/lib/osx/platform.js
----------------------------------------------------------------------
diff --git a/lib/osx/platform.js b/lib/osx/platform.js
new file mode 100644
index 0000000..be40bf5
--- /dev/null
+++ b/lib/osx/platform.js
@@ -0,0 +1,33 @@
+/*
+ *
+ * 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() {
+ var modulemapper = require('cordova/modulemapper');
+
+ modulemapper.loadMatchingModules(/cordova.*\/plugininit$/);
+
+ modulemapper.loadMatchingModules(/cordova.*\/symbols$/);
+ modulemapper.mapModules(window);
+ }
+};
+
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/090ab873/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 938412d..2565cf9 100644
--- a/package.json
+++ b/package.json
@@ -47,6 +47,10 @@
{
"name":"Dan Silivestru",
"email":"dansilivestru@apache.org"
+ },
+ {
+ "name":"Shazron Abdullah",
+ "email":"shazron@apache.org"
}
],
"dependencies": {