Permalink
Browse files

[CB-2621] Added OS X platform

  • Loading branch information...
1 parent d53601e commit 090ab8737ec27d33609b69d2b7d01fe4567c1511 @shazron shazron committed Mar 6, 2013
Showing with 163 additions and 0 deletions.
  1. +1 −0 Jakefile
  2. +1 −0 build/packager.js
  3. +124 −0 lib/osx/exec.js
  4. +33 −0 lib/osx/platform.js
  5. +4 −0 package.json
View
@@ -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();
View
@@ -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)))
View
@@ -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;
View
@@ -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);
+ }
+};
+
View
@@ -47,6 +47,10 @@
{
"name":"Dan Silivestru",
"email":"dansilivestru@apache.org"
+ },
+ {
+ "name":"Shazron Abdullah",
+ "email":"shazron@apache.org"
}
],
"dependencies": {

0 comments on commit 090ab87

Please sign in to comment.