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 2014/07/14 16:24:03 UTC

js commit: CB-6714 Base webOS 3.x Cordova implementation

Repository: cordova-js
Updated Branches:
  refs/heads/master 938a674be -> 3f3eb72ae


CB-6714 Base webOS 3.x Cordova implementation

close #68


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/3f3eb72a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/3f3eb72a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/3f3eb72a

Branch: refs/heads/master
Commit: 3f3eb72ae004d331d2b0ee0ade1a08b1c368b00f
Parents: 938a674
Author: Jason Robitaille <ro...@gmail.com>
Authored: Sun Apr 20 02:49:10 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Jul 14 10:23:00 2014 -0400

----------------------------------------------------------------------
 Gruntfile.js               |   1 +
 src/webos/exec.js          |  35 ++++++++++++
 src/webos/platform.js      |  86 +++++++++++++++++++++++++++++
 src/webos/webos/service.js | 118 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 240 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/3f3eb72a/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
index 5182572..bba8be1 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -30,6 +30,7 @@ module.exports = function(grunt) {
             "windows8": { useWindowsLineEndings: true },
             "windowsphone": { useWindowsLineEndings: true },
             "firefoxos": {},
+            "webos": {},
             "ubuntu": {},
             "browser": {}
         },

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/3f3eb72a/src/webos/exec.js
----------------------------------------------------------------------
diff --git a/src/webos/exec.js b/src/webos/exec.js
new file mode 100644
index 0000000..2a0e0d8
--- /dev/null
+++ b/src/webos/exec.js
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var execProxy = require('cordova/exec/proxy');
+
+module.exports = function(success, fail, service, action, args) {
+    var proxy = execProxy.get(service,action);
+    if(proxy) {
+        try {
+            proxy(success, fail, args);
+        } catch(e) {
+            console.log("Exception calling exec with command :: " + service + " :: " + action  + " ::exception=" + e);
+        }
+    } else {
+        fail && fail("Missing Command Error");
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/3f3eb72a/src/webos/platform.js
----------------------------------------------------------------------
diff --git a/src/webos/platform.js b/src/webos/platform.js
new file mode 100644
index 0000000..965a6ad
--- /dev/null
+++ b/src/webos/platform.js
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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: 'webos',
+    bootstrap: function() {
+        var channel = require('cordova/channel');
+        var isLegacy = ((navigator.userAgent.indexOf("webOS")>-1) || (navigator.userAgent.indexOf("hpwOS")>-1));
+        var webOSjsLib = (window.webOS!==undefined);
+        if(!webOSjsLib && window.PalmSystem && window.PalmSystem.stageReady && isLegacy) {
+            window.PalmSystem.stageReady();
+        }
+        
+        // create global legacy Mojo object if it does not exist
+        window.Mojo = window.Mojo || {};
+
+        // Check for support for page visibility api
+        if(typeof document.webkitHidden !== "undefined") {
+            document.addEventListener("webkitvisibilitychange", function(e) {
+                if(document.webkitHidden) {
+                    channel.onPause.fire();
+                } else {
+                    channel.onResume.fire();
+                }
+            });
+        } else { //backward compatability with webOS devices that don't support Page Visibility API
+            // LunaSysMgr calls this when the windows is maximized or opened.
+            window.Mojo.stageActivated = function() {
+                channel.onResume.fire();
+            };
+            // LunaSysMgr calls this when the windows is minimized or closed.
+            window.Mojo.stageDeactivated = function() {
+                channel.onPause.fire();
+            };
+        }
+
+        if(isLegacy && !webOSjsLib) {
+            var lp = JSON.parse(PalmSystem.launchParams || "{}") || {};
+            window.cordova.fireDocumentEvent("webOSLaunch", {type:"webOSLaunch", detail:lp});
+            // LunaSysMgr calls this whenever an app is "launched;"
+            window.Mojo.relaunch = function(e) {
+                var lp = JSON.parse(PalmSystem.launchParams || "{}") || {};
+                if(lp['palm-command'] && lp['palm-command'] == 'open-app-menu') {
+                    window.cordova.fireDocumentEvent("menubutton");
+                    return true;
+                } else {
+                    window.cordova.fireDocumentEvent("webOSRelaunch", {type:"webOSRelaunch", detail:lp});
+                }
+            };
+        }
+        document.addEventListener("keydown", function(e) {
+            // back gesture/button varies by version and build
+            if(e.keyCode == 27 || e.keyIdentifier == "U+1200001" ||
+                    e.keyIdentifier == "U+001B" || e.keyIdentifier == "Back") {
+                window.cordova.fireDocumentEvent("backbutton", e);
+            }
+        });
+        // SmartTV webOS uses HTML5 History API, so bind to that
+        // Leave freedom upto developers to enforce History states as they please
+        // rather than enforcing particular states
+        window.addEventListener("popstate", function(e) {
+            window.cordova.fireDocumentEvent("backbutton", e);
+        });
+
+        require('cordova/modulemapper').clobbers('cordova/webos/service', 'navigator.service');
+        channel.onNativeReady.fire();
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/3f3eb72a/src/webos/webos/service.js
----------------------------------------------------------------------
diff --git a/src/webos/webos/service.js b/src/webos/webos/service.js
new file mode 100644
index 0000000..0e4b111
--- /dev/null
+++ b/src/webos/webos/service.js
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var isLegacy = ((navigator.userAgent.indexOf("webOS")>-1) || (navigator.userAgent.indexOf("hpwOS")>-1));
+
+function LS2Request(uri, params) {
+    this.uri = uri;
+    params = params || {};
+    if(params.method) {
+        if(this.uri.charAt(this.uri.length-1) != "/") {
+            this.uri += "/";
+        }
+        this.uri += params.method;
+    }
+    if(typeof params.onSuccess === 'function') {
+        this.onSuccess = params.onSuccess;
+    }
+    if(typeof params.onFailure === 'function') {
+        this.onFailure = params.onFailure;
+    }
+    if(typeof params.onComplete === 'function') {
+        this.onComplete = params.onComplete;
+    }
+    this.params = (typeof params.parameters === 'object') ? params.parameters : {};
+    this.subscribe = params.subscribe || false;
+    if(this.subscribe) {
+        this.params.subscribe = params.subscribe;
+    }
+    if(this.params.subscribe) {
+        this.subscribe = this.params.subscribe;
+    }
+    this.resubscribe = params.resubscribe || false;
+    this.send();
+}
+
+LS2Request.prototype.send = function() {
+    if(!window.PalmServiceBridge) {
+        console.error("PalmServiceBridge not found.");
+        return;
+    }
+    this.bridge = new PalmServiceBridge();
+    var self = this;
+    this.bridge.onservicecallback = this.callback = function(msg) {
+        var parsedMsg;
+        if(self.cancelled) {
+            return;
+        }
+        try {
+            parsedMsg = JSON.parse(msg);
+        } catch(e) {
+            parsedMsg = {
+                errorCode: -1,
+                errorText: msg
+            };
+        }
+        if((parsedMsg.errorCode || parsedMsg.returnValue===false) && self.onFailure) {
+            self.onFailure(parsedMsg);
+            if(self.resubscribe && self.subscribe) {
+                self.delayID = setTimeout(function() {
+                    self.send();
+                }, LS2Request.resubscribeDelay);
+            }
+        } else if(self.onSuccess) {
+            self.onSuccess(parsedMsg);
+        }
+        if(self.onComplete) {
+            self.onComplete(parsedMsg);
+        }
+        if(!self.subscribe) {
+            self.cancel();
+        }
+    };
+    this.bridge.call(this.uri, JSON.stringify(this.params));
+};
+
+LS2Request.prototype.cancel = function() {
+    this.cancelled = true;
+    if(this.resubscribeJob) {
+        clearTimeout(this.delayID);
+    }
+    if(this.bridge) {
+        this.bridge.cancel();
+        this.bridge = undefined;
+    }
+};
+
+LS2Request.prototype.toString = function() {
+    return "[LS2Request]";
+};
+
+LS2Request.resubscribeDelay = 10000;
+
+module.exports = {
+    request: function (uri, params) {
+        var req = new LS2Request(uri, params);
+        return req;
+    },
+    systemPrefix: ((isLegacy) ? "com.palm." : "com.webos."),
+    protocol: "luna://"
+};