You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/02/07 02:42:03 UTC
cordova-firefoxos git commit: CB-8417 moved platform specific js into
platform
Repository: cordova-firefoxos
Updated Branches:
refs/heads/master 59472182f -> bacbd0910
CB-8417 moved platform specific js into platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/commit/bacbd091
Tree: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/tree/bacbd091
Diff: http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/diff/bacbd091
Branch: refs/heads/master
Commit: bacbd091067f8a670f6d57e4331961c89a955cbd
Parents: 5947218
Author: Steve Gill <st...@gmail.com>
Authored: Fri Feb 6 17:41:56 2015 -0800
Committer: Steve Gill <st...@gmail.com>
Committed: Fri Feb 6 17:41:56 2015 -0800
----------------------------------------------------------------------
cordova-js-src/exec.js | 44 +++++++++++++
cordova-js-src/init.js | 142 ++++++++++++++++++++++++++++++++++++++++
cordova-js-src/platform.js | 31 +++++++++
3 files changed, 217 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/bacbd091/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..60410ee
--- /dev/null
+++ b/cordova-js-src/exec.js
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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 firefoxos = require('cordova/platform');
+var cordova = require('cordova');
+var execProxy = require('cordova/exec/proxy');
+
+module.exports = function(success, fail, service, action, args) {
+ var proxy = execProxy.get(service,action);
+ if(proxy) {
+ var callbackId = service + cordova.callbackId++;
+ //console.log("EXEC:" + service + " : " + action);
+ if (typeof success == "function" || typeof fail == "function") {
+ cordova.callbacks[callbackId] = {success:success, fail:fail};
+ }
+ try {
+ proxy(success, fail, args);
+ }
+ catch(e) {
+ console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e);
+ }
+ }
+ else {
+ fail && fail("Missing Command Error");
+ }
+};
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/bacbd091/cordova-js-src/init.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/init.js b/cordova-js-src/init.js
new file mode 100644
index 0000000..b25d4af
--- /dev/null
+++ b/cordova-js-src/init.js
@@ -0,0 +1,142 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+/*
+ * This file has been copied into the firefoxos platform and patched
+ * to fix a problem with replacing the navigator object. We will have
+ * to keep this file up-to-date with the common init.js.
+ */
+
+var channel = require('cordova/channel');
+var cordova = require('cordova');
+var modulemapper = require('cordova/modulemapper');
+var platform = require('cordova/platform');
+var pluginloader = require('cordova/pluginloader');
+
+var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
+
+function logUnfiredChannels(arr) {
+ for (var i = 0; i < arr.length; ++i) {
+ if (arr[i].state != 2) {
+ console.log('Channel not fired: ' + arr[i].type);
+ }
+ }
+}
+
+window.setTimeout(function() {
+ if (channel.onDeviceReady.state != 2) {
+ console.log('deviceready has not fired after 5 seconds.');
+ logUnfiredChannels(platformInitChannelsArray);
+ logUnfiredChannels(channel.deviceReadyChannelsArray);
+ }
+}, 5000);
+
+// Replace navigator before any modules are required(), to ensure it happens as soon as possible.
+// We replace it so that properties that can't be clobbered can instead be overridden.
+function replaceNavigator(origNavigator) {
+ var CordovaNavigator = function() {};
+ CordovaNavigator.prototype = origNavigator;
+ var newNavigator = new CordovaNavigator();
+ // This work-around really only applies to new APIs that are newer than Function.bind.
+ // Without it, APIs such as getGamepads() break.
+ if (CordovaNavigator.bind) {
+ for (var key in origNavigator) {
+ try {
+ if (typeof origNavigator[key] == 'function') {
+ newNavigator[key] = origNavigator[key].bind(origNavigator);
+ }
+ } catch(e) {
+ // This try/catch was added for Firefox OS 1.0 and 1.1
+ // because it throws an security exception when trying
+ // to access a few properties of the navigator object.
+ // It has been fixed in 1.2.
+ }
+ }
+ }
+ return newNavigator;
+}
+if (window.navigator) {
+ window.navigator = replaceNavigator(window.navigator);
+}
+
+if (!window.console) {
+ window.console = {
+ log: function(){}
+ };
+}
+if (!window.console.warn) {
+ window.console.warn = function(msg) {
+ this.log("warn: " + msg);
+ };
+}
+
+// Register pause, resume and deviceready channels as events on document.
+channel.onPause = cordova.addDocumentEventHandler('pause');
+channel.onResume = cordova.addDocumentEventHandler('resume');
+channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
+
+// Listen for DOMContentLoaded and notify our channel subscribers.
+if (document.readyState == 'complete' || document.readyState == 'interactive') {
+ channel.onDOMContentLoaded.fire();
+} else {
+ document.addEventListener('DOMContentLoaded', function() {
+ channel.onDOMContentLoaded.fire();
+ }, false);
+}
+
+// _nativeReady is global variable that the native side can set
+// to signify that the native code is ready. It is a global since
+// it may be called before any cordova JS is ready.
+if (window._nativeReady) {
+ channel.onNativeReady.fire();
+}
+
+modulemapper.clobbers('cordova', 'cordova');
+modulemapper.clobbers('cordova/exec', 'cordova.exec');
+modulemapper.clobbers('cordova/exec', 'Cordova.exec');
+
+// Call the platform-specific initialization.
+platform.bootstrap && platform.bootstrap();
+
+pluginloader.load(function() {
+ channel.onPluginsReady.fire();
+});
+
+/**
+ * Create all cordova objects once native side is ready.
+ */
+channel.join(function() {
+ modulemapper.mapModules(window);
+
+ platform.initialize && platform.initialize();
+
+ // Fire event to notify that all objects are created
+ channel.onCordovaReady.fire();
+
+ // Fire onDeviceReady event once page has fully loaded, all
+ // constructors have run and cordova info has been received from native
+ // side.
+ channel.join(function() {
+ require('cordova').fireDocumentEvent('deviceready');
+ }, channel.deviceReadyChannelsArray);
+
+}, platformInitChannelsArray);
+
http://git-wip-us.apache.org/repos/asf/cordova-firefoxos/blob/bacbd091/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..b7d89b8
--- /dev/null
+++ b/cordova-js-src/platform.js
@@ -0,0 +1,31 @@
+/*
+ *
+ * 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: 'firefoxos',
+
+ bootstrap: function() {
+ var modulemapper = require('cordova/modulemapper');
+
+ modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
+ require('cordova/channel').onNativeReady.fire();
+ }
+};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org