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/05/19 01:21:04 UTC
[6/8] js commit: CB-8441 grunt compile now uses platform dependencies
cordova-js-src for platform specific exec files
CB-8441 grunt compile now uses platform dependencies cordova-js-src for platform specific exec files
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/994d6bba
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/994d6bba
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/994d6bba
Branch: refs/heads/master
Commit: 994d6bba75771f2df54f50e7459102d34c8d55b3
Parents: fcef6f2
Author: Steve Gill <st...@gmail.com>
Authored: Mon May 11 18:23:08 2015 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Mon May 18 02:05:21 2015 -0700
----------------------------------------------------------------------
src/amazon-fireos/android/nativeapiprovider.js | 36 ---
.../android/promptbasednativeapi.js | 35 --
src/amazon-fireos/exec.js | 290 -----------------
src/amazon-fireos/platform.js | 65 ----
src/amazon-fireos/plugin/android/app.js | 107 ------
src/android/android/nativeapiprovider.js | 36 ---
src/android/android/promptbasednativeapi.js | 35 --
src/android/exec.js | 283 ----------------
src/android/platform.js | 91 ------
src/android/plugin/android/app.js | 108 -------
src/blackberry10/exec.js | 150 ---------
src/blackberry10/platform.js | 57 ----
src/browser/confighelper.js | 95 ------
src/browser/exec.js | 48 ---
src/browser/platform.js | 48 ---
src/firefoxos/exec.js | 44 ---
src/firefoxos/init.js | 142 --------
src/firefoxos/platform.js | 31 --
src/ios/exec.js | 323 -------------------
src/ios/platform.js | 28 --
.../amazon-fireos/android/nativeapiprovider.js | 36 +++
.../android/promptbasednativeapi.js | 35 ++
src/legacy-exec/amazon-fireos/exec.js | 290 +++++++++++++++++
src/legacy-exec/amazon-fireos/platform.js | 65 ++++
.../amazon-fireos/plugin/android/app.js | 107 ++++++
.../android/android/nativeapiprovider.js | 36 +++
.../android/android/promptbasednativeapi.js | 35 ++
src/legacy-exec/android/exec.js | 283 ++++++++++++++++
src/legacy-exec/android/platform.js | 91 ++++++
src/legacy-exec/android/plugin/android/app.js | 108 +++++++
src/legacy-exec/blackberry10/exec.js | 150 +++++++++
src/legacy-exec/blackberry10/platform.js | 57 ++++
src/legacy-exec/browser/confighelper.js | 95 ++++++
src/legacy-exec/browser/exec.js | 48 +++
src/legacy-exec/browser/platform.js | 48 +++
src/legacy-exec/firefoxos/exec.js | 44 +++
src/legacy-exec/firefoxos/init.js | 142 ++++++++
src/legacy-exec/firefoxos/platform.js | 31 ++
src/legacy-exec/ios/exec.js | 323 +++++++++++++++++++
src/legacy-exec/ios/platform.js | 28 ++
src/legacy-exec/osx/exec.js | 117 +++++++
src/legacy-exec/osx/platform.js | 27 ++
src/legacy-exec/osx/plugin/osx/.gitignore | 0
src/legacy-exec/ubuntu/exec.js | 85 +++++
src/legacy-exec/ubuntu/platform.js | 33 ++
src/legacy-exec/webos/exec.js | 35 ++
src/legacy-exec/webos/platform.js | 86 +++++
src/legacy-exec/webos/webos/service.js | 118 +++++++
src/legacy-exec/windows/exec.js | 111 +++++++
src/legacy-exec/windows/platform.js | 73 +++++
src/legacy-exec/wp8/exec.js | 76 +++++
src/legacy-exec/wp8/platform.js | 34 ++
src/osx/exec.js | 117 -------
src/osx/platform.js | 27 --
src/osx/plugin/osx/.gitignore | 0
src/ubuntu/exec.js | 85 -----
src/ubuntu/platform.js | 33 --
src/webos/exec.js | 35 --
src/webos/platform.js | 86 -----
src/webos/webos/service.js | 118 -------
src/windows/exec.js | 111 -------
src/windows/platform.js | 73 -----
src/wp8/exec.js | 76 -----
src/wp8/platform.js | 34 --
tasks/lib/bundle.js | 24 +-
65 files changed, 2867 insertions(+), 2851 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/amazon-fireos/android/nativeapiprovider.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/android/nativeapiprovider.js b/src/amazon-fireos/android/nativeapiprovider.js
deleted file mode 100644
index 2e9aa67..0000000
--- a/src/amazon-fireos/android/nativeapiprovider.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.
-*/
-
-/**
- * Exports the ExposedJsApi.java object if available, otherwise exports the PromptBasedNativeApi.
- */
-
-var nativeApi = this._cordovaNative || require('cordova/android/promptbasednativeapi');
-var currentApi = nativeApi;
-
-module.exports = {
- get: function() { return currentApi; },
- setPreferPrompt: function(value) {
- currentApi = value ? require('cordova/android/promptbasednativeapi') : nativeApi;
- },
- // Used only by tests.
- set: function(value) {
- currentApi = value;
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/amazon-fireos/android/promptbasednativeapi.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/android/promptbasednativeapi.js b/src/amazon-fireos/android/promptbasednativeapi.js
deleted file mode 100644
index f7fb6bc..0000000
--- a/src/amazon-fireos/android/promptbasednativeapi.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
-*/
-
-/**
- * Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
- * This is used pre-JellyBean, where addJavascriptInterface() is disabled.
- */
-
-module.exports = {
- exec: function(bridgeSecret, service, action, callbackId, argsJson) {
- return prompt(argsJson, 'gap:'+JSON.stringify([bridgeSecret, service, action, callbackId]));
- },
- setNativeToJsBridgeMode: function(bridgeSecret, value) {
- prompt(value, 'gap_bridge_mode:' + bridgeSecret);
- },
- retrieveJsMessages: function(bridgeSecret, fromOnlineEvent) {
- return prompt(+fromOnlineEvent, 'gap_poll:' + bridgeSecret);
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/amazon-fireos/exec.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/exec.js b/src/amazon-fireos/exec.js
deleted file mode 100644
index 87cd52c..0000000
--- a/src/amazon-fireos/exec.js
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/**
- * Execute a cordova command. It is up to the native side whether this action
- * is synchronous or asynchronous. The native side can return:
- * Synchronous: PluginResult object as a JSON string
- * Asynchronous: Empty string ""
- * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
- * depending upon the result of the action.
- *
- * @param {Function} success The success callback
- * @param {Function} fail The fail callback
- * @param {String} service The name of the service to use
- * @param {String} action Action to be run in cordova
- * @param {String[]} [args] Zero or more arguments to pass to the method
- */
-var cordova = require('cordova'),
- nativeApiProvider = require('cordova/android/nativeapiprovider'),
- utils = require('cordova/utils'),
- base64 = require('cordova/base64'),
- channel = require('cordova/channel'),
- jsToNativeModes = {
- PROMPT: 0,
- JS_OBJECT: 1
- },
- nativeToJsModes = {
- // Polls for messages using the JS->Native bridge.
- POLLING: 0,
- // For LOAD_URL to be viable, it would need to have a work-around for
- // the bug where the soft-keyboard gets dismissed when a message is sent.
- LOAD_URL: 1,
- // For the ONLINE_EVENT to be viable, it would need to intercept all event
- // listeners (both through addEventListener and window.ononline) as well
- // as set the navigator property itself.
- ONLINE_EVENT: 2,
- // Uses reflection to access private APIs of the WebView that can send JS
- // to be executed.
- // Requires Android 3.2.4 or above.
- PRIVATE_API: 3
- },
- jsToNativeBridgeMode, // Set lazily.
- nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
- pollEnabled = false,
- messagesFromNative = [],
- bridgeSecret = -1;
-
-function androidExec(success, fail, service, action, args) {
- if (bridgeSecret < 0) {
- // If we ever catch this firing, we'll need to queue up exec()s
- // and fire them once we get a secret. For now, I don't think
- // it's possible for exec() to be called since plugins are parsed but
- // not run until until after onNativeReady.
- throw new Error('exec() called without bridgeSecret');
- }
- // Set default bridge modes if they have not already been set.
- // By default, we use the failsafe, since addJavascriptInterface breaks too often
- if (jsToNativeBridgeMode === undefined) {
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
- }
-
- // Process any ArrayBuffers in the args into a string.
- for (var i = 0; i < args.length; i++) {
- if (utils.typeName(args[i]) == 'ArrayBuffer') {
- args[i] = base64.fromArrayBuffer(args[i]);
- }
- }
-
- var callbackId = service + cordova.callbackId++,
- argsJson = JSON.stringify(args);
-
- if (success || fail) {
- cordova.callbacks[callbackId] = {success:success, fail:fail};
- }
-
- var messages = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
- // If argsJson was received by Java as null, try again with the PROMPT bridge mode.
- // This happens in rare circumstances, such as when certain Unicode characters are passed over the bridge on a Galaxy S2. See CB-2666.
- if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && messages === "@Null arguments.") {
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
- androidExec(success, fail, service, action, args);
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
- return;
- } else {
- androidExec.processMessages(messages, true);
- }
-}
-
-androidExec.init = function() {
- bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode);
- channel.onNativeReady.fire();
-};
-
-function pollOnceFromOnlineEvent() {
- pollOnce(true);
-}
-
-function pollOnce(opt_fromOnlineEvent) {
- if (bridgeSecret < 0) {
- // This can happen when the NativeToJsMessageQueue resets the online state on page transitions.
- // We know there's nothing to retrieve, so no need to poll.
- return;
- }
- var msg = nativeApiProvider.get().retrieveJsMessages(bridgeSecret, !!opt_fromOnlineEvent);
- androidExec.processMessages(msg);
-}
-
-function pollingTimerFunc() {
- if (pollEnabled) {
- pollOnce();
- setTimeout(pollingTimerFunc, 50);
- }
-}
-
-function hookOnlineApis() {
- function proxyEvent(e) {
- cordova.fireWindowEvent(e.type);
- }
- // The network module takes care of firing online and offline events.
- // It currently fires them only on document though, so we bridge them
- // to window here (while first listening for exec()-releated online/offline
- // events).
- window.addEventListener('online', pollOnceFromOnlineEvent, false);
- window.addEventListener('offline', pollOnceFromOnlineEvent, false);
- cordova.addWindowEventHandler('online');
- cordova.addWindowEventHandler('offline');
- document.addEventListener('online', proxyEvent, false);
- document.addEventListener('offline', proxyEvent, false);
-}
-
-hookOnlineApis();
-
-androidExec.jsToNativeModes = jsToNativeModes;
-androidExec.nativeToJsModes = nativeToJsModes;
-
-androidExec.setJsToNativeBridgeMode = function(mode) {
- if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
- mode = jsToNativeModes.PROMPT;
- }
- nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
- jsToNativeBridgeMode = mode;
-};
-
-androidExec.setNativeToJsBridgeMode = function(mode) {
- if (mode == nativeToJsBridgeMode) {
- return;
- }
- if (nativeToJsBridgeMode == nativeToJsModes.POLLING) {
- pollEnabled = false;
- }
-
- nativeToJsBridgeMode = mode;
- // Tell the native side to switch modes.
- // Otherwise, it will be set by androidExec.init()
- if (bridgeSecret >= 0) {
- nativeApiProvider.get().setNativeToJsBridgeMode(bridgeSecret, mode);
- }
-
- if (mode == nativeToJsModes.POLLING) {
- pollEnabled = true;
- setTimeout(pollingTimerFunc, 1);
- }
-};
-
-function buildPayload(payload, message) {
- var payloadKind = message.charAt(0);
- if (payloadKind == 's') {
- payload.push(message.slice(1));
- } else if (payloadKind == 't') {
- payload.push(true);
- } else if (payloadKind == 'f') {
- payload.push(false);
- } else if (payloadKind == 'N') {
- payload.push(null);
- } else if (payloadKind == 'n') {
- payload.push(+message.slice(1));
- } else if (payloadKind == 'A') {
- var data = message.slice(1);
- payload.push(base64.toArrayBuffer(data));
- } else if (payloadKind == 'S') {
- payload.push(window.atob(message.slice(1)));
- } else if (payloadKind == 'M') {
- var multipartMessages = message.slice(1);
- while (multipartMessages !== "") {
- var spaceIdx = multipartMessages.indexOf(' ');
- var msgLen = +multipartMessages.slice(0, spaceIdx);
- var multipartMessage = multipartMessages.substr(spaceIdx + 1, msgLen);
- multipartMessages = multipartMessages.slice(spaceIdx + msgLen + 1);
- buildPayload(payload, multipartMessage);
- }
- } else {
- payload.push(JSON.parse(message));
- }
-}
-
-// Processes a single message, as encoded by NativeToJsMessageQueue.java.
-function processMessage(message) {
- try {
- var firstChar = message.charAt(0);
- if (firstChar == 'J') {
- eval(message.slice(1));
- } else if (firstChar == 'S' || firstChar == 'F') {
- var success = firstChar == 'S';
- var keepCallback = message.charAt(1) == '1';
- var spaceIdx = message.indexOf(' ', 2);
- var status = +message.slice(2, spaceIdx);
- var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
- var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
- var payloadMessage = message.slice(nextSpaceIdx + 1);
- var payload = [];
- buildPayload(payload, payloadMessage);
- cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
- } else {
- console.log("processMessage failed: invalid message: " + JSON.stringify(message));
- }
- } catch (e) {
- console.log("processMessage failed: Error: " + e);
- console.log("processMessage failed: Stack: " + e.stack);
- console.log("processMessage failed: Message: " + message);
- }
-}
-
-var isProcessing = false;
-
-// This is called from the NativeToJsMessageQueue.java.
-androidExec.processMessages = function(messages, opt_useTimeout) {
- if (messages) {
- messagesFromNative.push(messages);
- }
- // Check for the reentrant case.
- if (isProcessing) {
- return;
- }
- if (opt_useTimeout) {
- window.setTimeout(androidExec.processMessages, 0);
- return;
- }
- isProcessing = true;
- try {
- // TODO: add setImmediate polyfill and process only one message at a time.
- while (messagesFromNative.length) {
- var msg = popMessageFromQueue();
- // The Java side can send a * message to indicate that it
- // still has messages waiting to be retrieved.
- if (msg == '*' && messagesFromNative.length === 0) {
- setTimeout(pollOnce, 0);
- return;
- }
- processMessage(msg);
- }
- } finally {
- isProcessing = false;
- }
-};
-
-function popMessageFromQueue() {
- var messageBatch = messagesFromNative.shift();
- if (messageBatch == '*') {
- return '*';
- }
-
- var spaceIdx = messageBatch.indexOf(' ');
- var msgLen = +messageBatch.slice(0, spaceIdx);
- var message = messageBatch.substr(spaceIdx + 1, msgLen);
- messageBatch = messageBatch.slice(spaceIdx + msgLen + 1);
- if (messageBatch) {
- messagesFromNative.unshift(messageBatch);
- }
- return message;
-}
-
-module.exports = androidExec;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/amazon-fireos/platform.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/platform.js b/src/amazon-fireos/platform.js
deleted file mode 100644
index e380c2e..0000000
--- a/src/amazon-fireos/platform.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *
- * 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: 'amazon-fireos',
- bootstrap: function() {
- var channel = require('cordova/channel'),
- cordova = require('cordova'),
- exec = require('cordova/exec'),
- modulemapper = require('cordova/modulemapper');
-
- // Get the shared secret needed to use the bridge.
- exec.init();
-
- // TODO: Extract this as a proper plugin.
- modulemapper.clobbers('cordova/plugin/android/app', 'navigator.app');
-
- // Inject a listener for the backbutton on the document.
- var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
- backButtonChannel.onHasSubscribersChange = function() {
- // If we just attached the first handler or detached the last handler,
- // let native know we need to override the back button.
- exec(null, null, "App", "overrideBackbutton", [this.numHandlers == 1]);
- };
-
- // Add hardware MENU and SEARCH button handlers
- cordova.addDocumentEventHandler('menubutton');
- cordova.addDocumentEventHandler('searchbutton');
-
- function bindButtonChannel(buttonName) {
- // generic button bind used for volumeup/volumedown buttons
- var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
- volumeButtonChannel.onHasSubscribersChange = function() {
- exec(null, null, "App", "overrideButton", [buttonName, this.numHandlers == 1]);
- };
- }
- // Inject a listener for the volume buttons on the document.
- bindButtonChannel('volumeup');
- bindButtonChannel('volumedown');
-
- // Let native code know we are all done on the JS side.
- // Native code will then un-hide the WebView.
- channel.onCordovaReady.subscribe(function() {
- exec(null, null, "App", "show", []);
- });
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/amazon-fireos/plugin/android/app.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/plugin/android/app.js b/src/amazon-fireos/plugin/android/app.js
deleted file mode 100644
index 7fccc40..0000000
--- a/src/amazon-fireos/plugin/android/app.js
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- *
- * 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 exec = require('cordova/exec');
-
-module.exports = {
- /**
- * Clear the resource cache.
- */
- clearCache:function() {
- exec(null, null, "App", "clearCache", []);
- },
-
- /**
- * Load the url into the webview or into new browser instance.
- *
- * @param url The URL to load
- * @param props Properties that can be passed in to the activity:
- * wait: int => wait msec before loading URL
- * loadingDialog: "Title,Message" => display a native loading dialog
- * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error
- * clearHistory: boolean => clear webview history (default=false)
- * openExternal: boolean => open in a new browser (default=false)
- *
- * Example:
- * navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
- */
- loadUrl:function(url, props) {
- exec(null, null, "App", "loadUrl", [url, props]);
- },
-
- /**
- * Cancel loadUrl that is waiting to be loaded.
- */
- cancelLoadUrl:function() {
- exec(null, null, "App", "cancelLoadUrl", []);
- },
-
- /**
- * Clear web history in this web view.
- * Instead of BACK button loading the previous web page, it will exit the app.
- */
- clearHistory:function() {
- exec(null, null, "App", "clearHistory", []);
- },
-
- /**
- * Go to previous page displayed.
- * This is the same as pressing the backbutton on Android device.
- */
- backHistory:function() {
- exec(null, null, "App", "backHistory", []);
- },
-
- /**
- * Override the default behavior of the Android back button.
- * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
- *
- * Note: The user should not have to call this method. Instead, when the user
- * registers for the "backbutton" event, this is automatically done.
- *
- * @param override T=override, F=cancel override
- */
- overrideBackbutton:function(override) {
- exec(null, null, "App", "overrideBackbutton", [override]);
- },
-
- /**
- * Override the default behavior of the Android volume button.
- * If overridden, when the volume button is pressed, the "volume[up|down]button"
- * JavaScript event will be fired.
- *
- * Note: The user should not have to call this method. Instead, when the user
- * registers for the "volume[up|down]button" event, this is automatically done.
- *
- * @param button volumeup, volumedown
- * @param override T=override, F=cancel override
- */
- overrideButton:function(button, override) {
- exec(null, null, "App", "overrideButton", [button, override]);
- },
-
- /**
- * Exit and terminate the application.
- */
- exitApp:function() {
- return exec(null, null, "App", "exitApp", []);
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/android/android/nativeapiprovider.js
----------------------------------------------------------------------
diff --git a/src/android/android/nativeapiprovider.js b/src/android/android/nativeapiprovider.js
deleted file mode 100644
index 2e9aa67..0000000
--- a/src/android/android/nativeapiprovider.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.
-*/
-
-/**
- * Exports the ExposedJsApi.java object if available, otherwise exports the PromptBasedNativeApi.
- */
-
-var nativeApi = this._cordovaNative || require('cordova/android/promptbasednativeapi');
-var currentApi = nativeApi;
-
-module.exports = {
- get: function() { return currentApi; },
- setPreferPrompt: function(value) {
- currentApi = value ? require('cordova/android/promptbasednativeapi') : nativeApi;
- },
- // Used only by tests.
- set: function(value) {
- currentApi = value;
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/android/android/promptbasednativeapi.js
----------------------------------------------------------------------
diff --git a/src/android/android/promptbasednativeapi.js b/src/android/android/promptbasednativeapi.js
deleted file mode 100644
index f7fb6bc..0000000
--- a/src/android/android/promptbasednativeapi.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
-*/
-
-/**
- * Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
- * This is used pre-JellyBean, where addJavascriptInterface() is disabled.
- */
-
-module.exports = {
- exec: function(bridgeSecret, service, action, callbackId, argsJson) {
- return prompt(argsJson, 'gap:'+JSON.stringify([bridgeSecret, service, action, callbackId]));
- },
- setNativeToJsBridgeMode: function(bridgeSecret, value) {
- prompt(value, 'gap_bridge_mode:' + bridgeSecret);
- },
- retrieveJsMessages: function(bridgeSecret, fromOnlineEvent) {
- return prompt(+fromOnlineEvent, 'gap_poll:' + bridgeSecret);
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/android/exec.js
----------------------------------------------------------------------
diff --git a/src/android/exec.js b/src/android/exec.js
deleted file mode 100644
index fa8b41b..0000000
--- a/src/android/exec.js
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/**
- * Execute a cordova command. It is up to the native side whether this action
- * is synchronous or asynchronous. The native side can return:
- * Synchronous: PluginResult object as a JSON string
- * Asynchronous: Empty string ""
- * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
- * depending upon the result of the action.
- *
- * @param {Function} success The success callback
- * @param {Function} fail The fail callback
- * @param {String} service The name of the service to use
- * @param {String} action Action to be run in cordova
- * @param {String[]} [args] Zero or more arguments to pass to the method
- */
-var cordova = require('cordova'),
- nativeApiProvider = require('cordova/android/nativeapiprovider'),
- utils = require('cordova/utils'),
- base64 = require('cordova/base64'),
- channel = require('cordova/channel'),
- jsToNativeModes = {
- PROMPT: 0,
- JS_OBJECT: 1
- },
- nativeToJsModes = {
- // Polls for messages using the JS->Native bridge.
- POLLING: 0,
- // For LOAD_URL to be viable, it would need to have a work-around for
- // the bug where the soft-keyboard gets dismissed when a message is sent.
- LOAD_URL: 1,
- // For the ONLINE_EVENT to be viable, it would need to intercept all event
- // listeners (both through addEventListener and window.ononline) as well
- // as set the navigator property itself.
- ONLINE_EVENT: 2
- },
- jsToNativeBridgeMode, // Set lazily.
- nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
- pollEnabled = false,
- bridgeSecret = -1;
-
-var messagesFromNative = [];
-var isProcessing = false;
-var resolvedPromise = typeof Promise == 'undefined' ? null : Promise.resolve();
-var nextTick = resolvedPromise ? function(fn) { resolvedPromise.then(fn); } : function(fn) { setTimeout(fn); };
-
-function androidExec(success, fail, service, action, args) {
- if (bridgeSecret < 0) {
- // If we ever catch this firing, we'll need to queue up exec()s
- // and fire them once we get a secret. For now, I don't think
- // it's possible for exec() to be called since plugins are parsed but
- // not run until until after onNativeReady.
- throw new Error('exec() called without bridgeSecret');
- }
- // Set default bridge modes if they have not already been set.
- // By default, we use the failsafe, since addJavascriptInterface breaks too often
- if (jsToNativeBridgeMode === undefined) {
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
- }
-
- // Process any ArrayBuffers in the args into a string.
- for (var i = 0; i < args.length; i++) {
- if (utils.typeName(args[i]) == 'ArrayBuffer') {
- args[i] = base64.fromArrayBuffer(args[i]);
- }
- }
-
- var callbackId = service + cordova.callbackId++,
- argsJson = JSON.stringify(args);
-
- if (success || fail) {
- cordova.callbacks[callbackId] = {success:success, fail:fail};
- }
-
- var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
- // If argsJson was received by Java as null, try again with the PROMPT bridge mode.
- // This happens in rare circumstances, such as when certain Unicode characters are passed over the bridge on a Galaxy S2. See CB-2666.
- if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && msgs === "@Null arguments.") {
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
- androidExec(success, fail, service, action, args);
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
- } else if (msgs) {
- messagesFromNative.push(msgs);
- // Always process async to avoid exceptions messing up stack.
- nextTick(processMessages);
- }
-}
-
-androidExec.init = function() {
- bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode);
- channel.onNativeReady.fire();
-};
-
-function pollOnceFromOnlineEvent() {
- pollOnce(true);
-}
-
-function pollOnce(opt_fromOnlineEvent) {
- if (bridgeSecret < 0) {
- // This can happen when the NativeToJsMessageQueue resets the online state on page transitions.
- // We know there's nothing to retrieve, so no need to poll.
- return;
- }
- var msgs = nativeApiProvider.get().retrieveJsMessages(bridgeSecret, !!opt_fromOnlineEvent);
- if (msgs) {
- messagesFromNative.push(msgs);
- // Process sync since we know we're already top-of-stack.
- processMessages();
- }
-}
-
-function pollingTimerFunc() {
- if (pollEnabled) {
- pollOnce();
- setTimeout(pollingTimerFunc, 50);
- }
-}
-
-function hookOnlineApis() {
- function proxyEvent(e) {
- cordova.fireWindowEvent(e.type);
- }
- // The network module takes care of firing online and offline events.
- // It currently fires them only on document though, so we bridge them
- // to window here (while first listening for exec()-releated online/offline
- // events).
- window.addEventListener('online', pollOnceFromOnlineEvent, false);
- window.addEventListener('offline', pollOnceFromOnlineEvent, false);
- cordova.addWindowEventHandler('online');
- cordova.addWindowEventHandler('offline');
- document.addEventListener('online', proxyEvent, false);
- document.addEventListener('offline', proxyEvent, false);
-}
-
-hookOnlineApis();
-
-androidExec.jsToNativeModes = jsToNativeModes;
-androidExec.nativeToJsModes = nativeToJsModes;
-
-androidExec.setJsToNativeBridgeMode = function(mode) {
- if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
- mode = jsToNativeModes.PROMPT;
- }
- nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
- jsToNativeBridgeMode = mode;
-};
-
-androidExec.setNativeToJsBridgeMode = function(mode) {
- if (mode == nativeToJsBridgeMode) {
- return;
- }
- if (nativeToJsBridgeMode == nativeToJsModes.POLLING) {
- pollEnabled = false;
- }
-
- nativeToJsBridgeMode = mode;
- // Tell the native side to switch modes.
- // Otherwise, it will be set by androidExec.init()
- if (bridgeSecret >= 0) {
- nativeApiProvider.get().setNativeToJsBridgeMode(bridgeSecret, mode);
- }
-
- if (mode == nativeToJsModes.POLLING) {
- pollEnabled = true;
- setTimeout(pollingTimerFunc, 1);
- }
-};
-
-function buildPayload(payload, message) {
- var payloadKind = message.charAt(0);
- if (payloadKind == 's') {
- payload.push(message.slice(1));
- } else if (payloadKind == 't') {
- payload.push(true);
- } else if (payloadKind == 'f') {
- payload.push(false);
- } else if (payloadKind == 'N') {
- payload.push(null);
- } else if (payloadKind == 'n') {
- payload.push(+message.slice(1));
- } else if (payloadKind == 'A') {
- var data = message.slice(1);
- payload.push(base64.toArrayBuffer(data));
- } else if (payloadKind == 'S') {
- payload.push(window.atob(message.slice(1)));
- } else if (payloadKind == 'M') {
- var multipartMessages = message.slice(1);
- while (multipartMessages !== "") {
- var spaceIdx = multipartMessages.indexOf(' ');
- var msgLen = +multipartMessages.slice(0, spaceIdx);
- var multipartMessage = multipartMessages.substr(spaceIdx + 1, msgLen);
- multipartMessages = multipartMessages.slice(spaceIdx + msgLen + 1);
- buildPayload(payload, multipartMessage);
- }
- } else {
- payload.push(JSON.parse(message));
- }
-}
-
-// Processes a single message, as encoded by NativeToJsMessageQueue.java.
-function processMessage(message) {
- var firstChar = message.charAt(0);
- if (firstChar == 'J') {
- // This is deprecated on the .java side. It doesn't work with CSP enabled.
- eval(message.slice(1));
- } else if (firstChar == 'S' || firstChar == 'F') {
- var success = firstChar == 'S';
- var keepCallback = message.charAt(1) == '1';
- var spaceIdx = message.indexOf(' ', 2);
- var status = +message.slice(2, spaceIdx);
- var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
- var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
- var payloadMessage = message.slice(nextSpaceIdx + 1);
- var payload = [];
- buildPayload(payload, payloadMessage);
- cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
- } else {
- console.log("processMessage failed: invalid message: " + JSON.stringify(message));
- }
-}
-
-function processMessages() {
- // Check for the reentrant case.
- if (isProcessing) {
- return;
- }
- if (messagesFromNative.length === 0) {
- return;
- }
- isProcessing = true;
- try {
- var msg = popMessageFromQueue();
- // The Java side can send a * message to indicate that it
- // still has messages waiting to be retrieved.
- if (msg == '*' && messagesFromNative.length === 0) {
- nextTick(pollOnce);
- return;
- }
- processMessage(msg);
- } finally {
- isProcessing = false;
- if (messagesFromNative.length > 0) {
- nextTick(processMessages);
- }
- }
-}
-
-function popMessageFromQueue() {
- var messageBatch = messagesFromNative.shift();
- if (messageBatch == '*') {
- return '*';
- }
-
- var spaceIdx = messageBatch.indexOf(' ');
- var msgLen = +messageBatch.slice(0, spaceIdx);
- var message = messageBatch.substr(spaceIdx + 1, msgLen);
- messageBatch = messageBatch.slice(spaceIdx + msgLen + 1);
- if (messageBatch) {
- messagesFromNative.unshift(messageBatch);
- }
- return message;
-}
-
-module.exports = androidExec;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/android/platform.js
----------------------------------------------------------------------
diff --git a/src/android/platform.js b/src/android/platform.js
deleted file mode 100644
index bffc675..0000000
--- a/src/android/platform.js
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- *
- * 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: 'android',
- bootstrap: function() {
- var channel = require('cordova/channel'),
- cordova = require('cordova'),
- exec = require('cordova/exec'),
- modulemapper = require('cordova/modulemapper');
-
- // Get the shared secret needed to use the bridge.
- exec.init();
-
- // TODO: Extract this as a proper plugin.
- modulemapper.clobbers('cordova/plugin/android/app', 'navigator.app');
-
- var APP_PLUGIN_NAME = Number(cordova.platformVersion.split('.')[0]) >= 4 ? 'CoreAndroid' : 'App';
-
- // Inject a listener for the backbutton on the document.
- var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
- backButtonChannel.onHasSubscribersChange = function() {
- // If we just attached the first handler or detached the last handler,
- // let native know we need to override the back button.
- exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [this.numHandlers == 1]);
- };
-
- // Add hardware MENU and SEARCH button handlers
- cordova.addDocumentEventHandler('menubutton');
- cordova.addDocumentEventHandler('searchbutton');
-
- function bindButtonChannel(buttonName) {
- // generic button bind used for volumeup/volumedown buttons
- var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
- volumeButtonChannel.onHasSubscribersChange = function() {
- exec(null, null, APP_PLUGIN_NAME, "overrideButton", [buttonName, this.numHandlers == 1]);
- };
- }
- // Inject a listener for the volume buttons on the document.
- bindButtonChannel('volumeup');
- bindButtonChannel('volumedown');
-
- // Let native code know we are all done on the JS side.
- // Native code will then un-hide the WebView.
- channel.onCordovaReady.subscribe(function() {
- exec(onMessageFromNative, null, APP_PLUGIN_NAME, 'messageChannel', []);
- exec(null, null, APP_PLUGIN_NAME, "show", []);
- });
- }
-};
-
-function onMessageFromNative(msg) {
- var cordova = require('cordova');
- var action = msg.action;
-
- switch (action)
- {
- // Button events
- case 'backbutton':
- case 'menubutton':
- case 'searchbutton':
- // App life cycle events
- case 'pause':
- case 'resume':
- // Volume events
- case 'volumedownbutton':
- case 'volumeupbutton':
- cordova.fireDocumentEvent(action);
- break;
- default:
- throw new Error('Unknown event action ' + action);
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/android/plugin/android/app.js
----------------------------------------------------------------------
diff --git a/src/android/plugin/android/app.js b/src/android/plugin/android/app.js
deleted file mode 100644
index 22cf96e..0000000
--- a/src/android/plugin/android/app.js
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- *
- * 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 exec = require('cordova/exec');
-var APP_PLUGIN_NAME = Number(require('cordova').platformVersion.split('.')[0]) >= 4 ? 'CoreAndroid' : 'App';
-
-module.exports = {
- /**
- * Clear the resource cache.
- */
- clearCache:function() {
- exec(null, null, APP_PLUGIN_NAME, "clearCache", []);
- },
-
- /**
- * Load the url into the webview or into new browser instance.
- *
- * @param url The URL to load
- * @param props Properties that can be passed in to the activity:
- * wait: int => wait msec before loading URL
- * loadingDialog: "Title,Message" => display a native loading dialog
- * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error
- * clearHistory: boolean => clear webview history (default=false)
- * openExternal: boolean => open in a new browser (default=false)
- *
- * Example:
- * navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
- */
- loadUrl:function(url, props) {
- exec(null, null, APP_PLUGIN_NAME, "loadUrl", [url, props]);
- },
-
- /**
- * Cancel loadUrl that is waiting to be loaded.
- */
- cancelLoadUrl:function() {
- exec(null, null, APP_PLUGIN_NAME, "cancelLoadUrl", []);
- },
-
- /**
- * Clear web history in this web view.
- * Instead of BACK button loading the previous web page, it will exit the app.
- */
- clearHistory:function() {
- exec(null, null, APP_PLUGIN_NAME, "clearHistory", []);
- },
-
- /**
- * Go to previous page displayed.
- * This is the same as pressing the backbutton on Android device.
- */
- backHistory:function() {
- exec(null, null, APP_PLUGIN_NAME, "backHistory", []);
- },
-
- /**
- * Override the default behavior of the Android back button.
- * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
- *
- * Note: The user should not have to call this method. Instead, when the user
- * registers for the "backbutton" event, this is automatically done.
- *
- * @param override T=override, F=cancel override
- */
- overrideBackbutton:function(override) {
- exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [override]);
- },
-
- /**
- * Override the default behavior of the Android volume button.
- * If overridden, when the volume button is pressed, the "volume[up|down]button"
- * JavaScript event will be fired.
- *
- * Note: The user should not have to call this method. Instead, when the user
- * registers for the "volume[up|down]button" event, this is automatically done.
- *
- * @param button volumeup, volumedown
- * @param override T=override, F=cancel override
- */
- overrideButton:function(button, override) {
- exec(null, null, APP_PLUGIN_NAME, "overrideButton", [button, override]);
- },
-
- /**
- * Exit and terminate the application.
- */
- exitApp:function() {
- return exec(null, null, APP_PLUGIN_NAME, "exitApp", []);
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/blackberry10/exec.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/exec.js b/src/blackberry10/exec.js
deleted file mode 100644
index 1bfd564..0000000
--- a/src/blackberry10/exec.js
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- *
- * 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 cordova = require('cordova'),
- execProxy = require('cordova/exec/proxy');
-
-function RemoteFunctionCall(functionUri) {
- var params = {};
-
- function composeUri() {
- return "http://localhost:8472/" + functionUri;
- }
-
- function createXhrRequest(uri, isAsync) {
- var request = new XMLHttpRequest();
- request.open("POST", uri, isAsync);
- request.setRequestHeader("Content-Type", "application/json");
- return request;
- }
-
- this.addParam = function (name, value) {
- params[name] = encodeURIComponent(JSON.stringify(value));
- };
-
- this.makeAsyncCall = function () {
- var requestUri = composeUri(),
- request = new XMLHttpRequest(),
- didSucceed,
- response,
- fail = function () {
- var callbackId = JSON.parse(decodeURIComponent(params.callbackId));
- response = JSON.parse(decodeURIComponent(request.responseText) || "null");
- cordova.callbacks[callbackId].fail && cordova.callbacks[callbackId].fail(response.msg, response);
- delete cordova.callbacks[callbackId];
- };
-
- request.open("POST", requestUri, true /* async */);
- request.setRequestHeader("Content-Type", "application/json");
- request.timeout = 1000; // Timeout in 1000ms
- request.ontimeout = fail;
- request.onerror = fail;
-
- request.onload = function () {
- response = JSON.parse(decodeURIComponent(request.responseText) || "null");
- if (request.status === 200) {
- didSucceed = response.code === cordova.callbackStatus.OK || response.code === cordova.callbackStatus.NO_RESULT;
- cordova.callbackFromNative(
- JSON.parse(decodeURIComponent(params.callbackId)),
- didSucceed,
- response.code,
- [ didSucceed ? response.data : response.msg ],
- !!response.keepCallback
- );
- } else {
- fail();
- }
- };
-
- request.send(JSON.stringify(params));
- };
-
- this.makeSyncCall = function () {
- var requestUri = composeUri(),
- request = createXhrRequest(requestUri, false),
- response;
- try {
- request.send(JSON.stringify(params));
- response = JSON.parse(decodeURIComponent(request.responseText) || "null");
- } catch (e) {
- console.error('makeSyncCall failed', e);
- response = { code: 500, msg: 'exec bridge failure' };
- }
- return response;
- };
-
-}
-
-module.exports = function (success, fail, service, action, args, sync) {
- var uri = service + "/" + action,
- request = new RemoteFunctionCall(uri),
- callbackId = service + cordova.callbackId++,
- proxy,
- response,
- name,
- didSucceed;
-
- cordova.callbacks[callbackId] = {
- success: success,
- fail: fail
- };
-
- proxy = execProxy.get(service, action);
-
- if (proxy) {
- proxy(success, fail, args);
- }
-
- else {
-
- request.addParam("callbackId", callbackId);
-
- for (name in args) {
- if (Object.hasOwnProperty.call(args, name)) {
- request.addParam(name, args[name]);
- }
- }
-
- if (sync !== undefined && !sync) {
- request.makeAsyncCall();
- return;
- }
-
- response = request.makeSyncCall();
-
- if (response.code < 0) {
- if (fail) {
- fail(response.msg, response);
- }
- delete cordova.callbacks[callbackId];
- } else {
- didSucceed = response.code === cordova.callbackStatus.OK || response.code === cordova.callbackStatus.NO_RESULT;
- cordova.callbackFromNative(
- callbackId,
- didSucceed,
- response.code,
- [ didSucceed ? response.data : response.msg ],
- !!response.keepCallback
- );
- }
- }
-
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/blackberry10/platform.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/platform.js b/src/blackberry10/platform.js
deleted file mode 100644
index 9fcbda0..0000000
--- a/src/blackberry10/platform.js
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *
- * 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: "blackberry10",
-
- bootstrap: function() {
-
- var channel = require('cordova/channel'),
- addEventListener = document.addEventListener;
-
- //ready as soon as the plugins are
- channel.onPluginsReady.subscribe(function () {
- channel.onNativeReady.fire();
- });
-
- //pass document online/offline event listeners to window
- document.addEventListener = function (type) {
- if (type === "online" || type === "offline") {
- window.addEventListener.apply(window, arguments);
- } else {
- addEventListener.apply(document, arguments);
- }
- };
-
- //map blackberry.event to document
- if (!window.blackberry) {
- window.blackberry = {};
- }
- window.blackberry.event =
- {
- addEventListener: document.addEventListener,
- removeEventListener: document.removeEventListener
- };
-
- }
-
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/browser/confighelper.js
----------------------------------------------------------------------
diff --git a/src/browser/confighelper.js b/src/browser/confighelper.js
deleted file mode 100644
index de19c8d..0000000
--- a/src/browser/confighelper.js
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *
- * 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 config;
-
-function Config(xhr) {
- function loadPreferences(xhr) {
- var parser = new DOMParser();
- var doc = parser.parseFromString(xhr.responseText, "application/xml");
-
- var preferences = doc.getElementsByTagName("preference");
- return Array.prototype.slice.call(preferences);
- }
-
- this.xhr = xhr;
- this.preferences = loadPreferences(this.xhr);
-}
-
-function readConfig(success, error) {
- var xhr;
-
- if(typeof config != 'undefined') {
- success(config);
- }
-
- function fail(msg) {
- console.error(msg);
-
- if(error) {
- error(msg);
- }
- }
-
- var xhrStatusChangeHandler = function() {
- if (xhr.readyState == 4) {
- if (xhr.status == 200 || xhr.status == 304 || xhr.status === 0 /* file:// */) {
- config = new Config(xhr);
- success(config);
- }
- else {
- fail('[Browser][cordova.js][xhrStatusChangeHandler] Could not XHR config.xml: ' + xhr.statusText);
- }
- }
- };
-
- if ("ActiveXObject" in window) {
- // Needed for XHR-ing via file:// protocol in IE
- xhr = new window.ActiveXObject("MSXML2.XMLHTTP");
- xhr.onreadystatechange = xhrStatusChangeHandler;
- } else {
- xhr = new XMLHttpRequest();
- xhr.addEventListener("load", xhrStatusChangeHandler);
- }
-
- try {
- xhr.open("get", "config.xml", true);
- xhr.send();
- } catch(e) {
- fail('[Browser][cordova.js][readConfig] Could not XHR config.xml: ' + JSON.stringify(e));
- }
-}
-
-/**
- * Reads a preference value from config.xml.
- * Returns preference value or undefined if it does not exist.
- * @param {String} preferenceName Preference name to read */
-Config.prototype.getPreferenceValue = function getPreferenceValue(preferenceName) {
- var preferenceItem = this.preferences && this.preferences.filter(function(item) {
- return item.attributes.name && item.attributes.name.value === preferenceName;
- });
-
- if(preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) {
- return preferenceItem[0].attributes.value.value;
- }
-};
-
-exports.readConfig = readConfig;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/browser/exec.js
----------------------------------------------------------------------
diff --git a/src/browser/exec.js b/src/browser/exec.js
deleted file mode 100644
index 744282e..0000000
--- a/src/browser/exec.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *
- * 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 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++;
-
- if (typeof success == "function" || typeof fail == "function") {
- cordova.callbacks[callbackId] = {success:success, fail:fail};
- }
-
- try {
- proxy(success, fail, args);
- }
- catch(e) {
- // TODO throw maybe?
- var msg = "Exception calling :: " + service + " :: " + action + " ::exception=" + e;
- console.log(msg);
- }
- }
- else {
- fail && fail("Missing Command Error");
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/browser/platform.js
----------------------------------------------------------------------
diff --git a/src/browser/platform.js b/src/browser/platform.js
deleted file mode 100644
index 0514059..0000000
--- a/src/browser/platform.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *
- * 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: 'browser',
- cordovaVersion: '3.4.0',
-
- bootstrap: function() {
-
- var modulemapper = require('cordova/modulemapper');
- var channel = require('cordova/channel');
-
- modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
-
- channel.onNativeReady.fire();
-
- // FIXME is this the right place to clobber pause/resume? I am guessing not
- // FIXME pause/resume should be deprecated IN CORDOVA for pagevisiblity api
- document.addEventListener('webkitvisibilitychange', function() {
- if (document.webkitHidden) {
- channel.onPause.fire();
- }
- else {
- channel.onResume.fire();
- }
- }, false);
-
- // End of bootstrap
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/firefoxos/exec.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/exec.js b/src/firefoxos/exec.js
deleted file mode 100644
index 60410ee..0000000
--- a/src/firefoxos/exec.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * 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-js/blob/994d6bba/src/firefoxos/init.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/init.js b/src/firefoxos/init.js
deleted file mode 100644
index b25d4af..0000000
--- a/src/firefoxos/init.js
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- *
- * 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-js/blob/994d6bba/src/firefoxos/platform.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/platform.js b/src/firefoxos/platform.js
deleted file mode 100644
index b7d89b8..0000000
--- a/src/firefoxos/platform.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *
- * 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();
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/ios/exec.js
----------------------------------------------------------------------
diff --git a/src/ios/exec.js b/src/ios/exec.js
deleted file mode 100644
index 856b9b1..0000000
--- a/src/ios/exec.js
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- *
- * 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 iframe used to notify the native code about queued
- * commands.
- */
-var cordova = require('cordova'),
- channel = require('cordova/channel'),
- utils = require('cordova/utils'),
- base64 = require('cordova/base64'),
- // XHR mode does not work on iOS 4.2.
- // XHR mode's main advantage is working around a bug in -webkit-scroll, which
- // doesn't exist only on iOS 5.x devices.
- // IFRAME_NAV is the fastest.
- // IFRAME_HASH could be made to enable synchronous bridge calls if we wanted this feature.
- jsToNativeModes = {
- IFRAME_NAV: 0, // Default. Uses a new iframe for each poke.
- // XHR bridge appears to be flaky sometimes: CB-3900, CB-3359, CB-5457, CB-4970, CB-4998, CB-5134
- XHR_NO_PAYLOAD: 1, // About the same speed as IFRAME_NAV. Performance not about the same as IFRAME_NAV, but more variable.
- XHR_WITH_PAYLOAD: 2, // Flakey, and not as performant
- XHR_OPTIONAL_PAYLOAD: 3, // Flakey, and not as performant
- IFRAME_HASH_NO_PAYLOAD: 4, // Not fully baked. A bit faster than IFRAME_NAV, but risks jank since poke happens synchronously.
- IFRAME_HASH_WITH_PAYLOAD: 5, // Slower than no payload. Maybe since it has to be URI encoded / decoded.
- WK_WEBVIEW_BINDING: 6 // Only way that works for WKWebView :)
- },
- bridgeMode,
- execIframe,
- execHashIframe,
- hashToggle = 1,
- execXhr,
- requestCount = 0,
- vcHeaderValue = null,
- commandQueue = [], // Contains pending JS->Native messages.
- isInContextOfEvalJs = 0,
- failSafeTimerId = 0;
-
-function shouldBundleCommandJson() {
- if (bridgeMode === jsToNativeModes.XHR_WITH_PAYLOAD) {
- return true;
- }
- if (bridgeMode === jsToNativeModes.XHR_OPTIONAL_PAYLOAD) {
- var payloadLength = 0;
- for (var i = 0; i < commandQueue.length; ++i) {
- payloadLength += commandQueue[i].length;
- }
- // The value here was determined using the benchmark within CordovaLibApp on an iPad 3.
- return payloadLength < 4500;
- }
- return false;
-}
-
-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 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 iOSExec() {
- if (bridgeMode === undefined) {
- bridgeMode = jsToNativeModes.IFRAME_NAV;
- }
-
- if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.cordova && window.webkit.messageHandlers.cordova.postMessage) {
- bridgeMode = jsToNativeModes.WK_WEBVIEW_BINDING;
- }
-
- var successCallback, failCallback, service, action, actionArgs, splitCommand;
- var callbackId = null;
- if (typeof arguments[0] !== "string") {
- // FORMAT ONE
- successCallback = arguments[0];
- failCallback = arguments[1];
- service = arguments[2];
- action = arguments[3];
- actionArgs = arguments[4];
-
- // Since we need to maintain backwards compatibility, we have to pass
- // an invalid callbackId even if no callback was provided since plugins
- // will be expecting it. The Cordova.exec() implementation allocates
- // an invalid callbackId and passes it even if no callbacks were given.
- callbackId = 'INVALID';
- } else {
- // FORMAT TWO, REMOVED
- try {
- splitCommand = arguments[0].split(".");
- action = splitCommand.pop();
- service = splitCommand.join(".");
- actionArgs = Array.prototype.splice.call(arguments, 1);
-
- console.log('The old format of this exec call has been removed (deprecated since 2.1). Change to: ' +
- "cordova.exec(null, null, \"" + service + "\", \"" + action + "\"," + JSON.stringify(actionArgs) + ");"
- );
- return;
- } catch (e) {}
- }
-
- // If actionArgs is not provided, default to an empty array
- actionArgs = actionArgs || [];
-
- // 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);
-
- var command = [callbackId, service, action, actionArgs];
-
- if (bridgeMode === jsToNativeModes.WK_WEBVIEW_BINDING) {
- window.webkit.messageHandlers.cordova.postMessage(command);
- } else {
- // Stringify and queue the command. We stringify to command now to
- // effectively clone the command arguments in case they are mutated before
- // the command is executed.
- commandQueue.push(JSON.stringify(command));
-
- // If we're in the context of a stringByEvaluatingJavaScriptFromString call,
- // then the queue will be flushed when it returns; no need for a poke.
- // Also, if there is already a command in the queue, then we've already
- // poked the native side, so there is no reason to do so again.
- if (!isInContextOfEvalJs && commandQueue.length == 1) {
- pokeNative();
- }
- }
-}
-
-function pokeNative() {
- switch (bridgeMode) {
- case jsToNativeModes.XHR_NO_PAYLOAD:
- case jsToNativeModes.XHR_WITH_PAYLOAD:
- case jsToNativeModes.XHR_OPTIONAL_PAYLOAD:
- pokeNativeViaXhr();
- break;
- default: // iframe-based.
- pokeNativeViaIframe();
- }
-}
-
-function pokeNativeViaXhr() {
- // This prevents sending an XHR when there is already one being sent.
- // This should happen only in rare circumstances (refer to unit tests).
- if (execXhr && execXhr.readyState != 4) {
- execXhr = null;
- }
- // Re-using the XHR improves exec() performance by about 10%.
- execXhr = execXhr || new XMLHttpRequest();
- // Changing this to a GET will make the XHR reach the URIProtocol on 4.2.
- // For some reason it still doesn't work though...
- // Add a timestamp to the query param to prevent caching.
- execXhr.open('HEAD', "/!gap_exec?" + (+new Date()), true);
- if (!vcHeaderValue) {
- vcHeaderValue = /.*\((.*)\)$/.exec(navigator.userAgent)[1];
- }
- execXhr.setRequestHeader('vc', vcHeaderValue);
- execXhr.setRequestHeader('rc', ++requestCount);
- if (shouldBundleCommandJson()) {
- execXhr.setRequestHeader('cmds', iOSExec.nativeFetchMessages());
- }
- execXhr.send(null);
-}
-
-function pokeNativeViaIframe() {
- // CB-5488 - Don't attempt to create iframe before document.body is available.
- if (!document.body) {
- setTimeout(pokeNativeViaIframe);
- return;
- }
- if (bridgeMode === jsToNativeModes.IFRAME_HASH_NO_PAYLOAD || bridgeMode === jsToNativeModes.IFRAME_HASH_WITH_PAYLOAD) {
- // TODO: This bridge mode doesn't properly support being removed from the DOM (CB-7735)
- if (!execHashIframe) {
- execHashIframe = document.createElement('iframe');
- execHashIframe.style.display = 'none';
- document.body.appendChild(execHashIframe);
- // Hash changes don't work on about:blank, so switch it to file:///.
- execHashIframe.contentWindow.history.replaceState(null, null, 'file:///#');
- }
- // The delegate method is called only when the hash changes, so toggle it back and forth.
- hashToggle = hashToggle ^ 3;
- var hashValue = '%0' + hashToggle;
- if (bridgeMode === jsToNativeModes.IFRAME_HASH_WITH_PAYLOAD) {
- hashValue += iOSExec.nativeFetchMessages();
- }
- execHashIframe.contentWindow.location.hash = hashValue;
- } else {
- // Check if they've removed it from the DOM, and put it back if so.
- if (execIframe && execIframe.contentWindow) {
- execIframe.contentWindow.location = 'gap://ready';
- } else {
- execIframe = document.createElement('iframe');
- execIframe.style.display = 'none';
- execIframe.src = 'gap://ready';
- document.body.appendChild(execIframe);
- }
- // Use a timer to protect against iframe being unloaded during the poke (CB-7735).
- // This makes the bridge ~ 7% slower, but works around the poke getting lost
- // when the iframe is removed from the DOM.
- // An onunload listener could be used in the case where the iframe has just been
- // created, but since unload events fire only once, it doesn't work in the normal
- // case of iframe reuse (where unload will have already fired due to the attempted
- // navigation of the page).
- failSafeTimerId = setTimeout(function() {
- if (commandQueue.length) {
- pokeNative();
- }
- }, 50); // Making this > 0 improves performance (marginally) in the normal case (where it doesn't fire).
- }
-}
-
-iOSExec.jsToNativeModes = jsToNativeModes;
-
-iOSExec.setJsToNativeBridgeMode = function(mode) {
- // Remove the iFrame since it may be no longer required, and its existence
- // can trigger browser bugs.
- // https://issues.apache.org/jira/browse/CB-593
- if (execIframe) {
- if (execIframe.parentNode) {
- execIframe.parentNode.removeChild(execIframe);
- }
- execIframe = null;
- }
- bridgeMode = mode;
-};
-
-iOSExec.nativeFetchMessages = function() {
- // Stop listing for window detatch once native side confirms poke.
- if (failSafeTimerId) {
- clearTimeout(failSafeTimerId);
- failSafeTimerId = 0;
- }
- // Each entry in commandQueue is a JSON string already.
- if (!commandQueue.length) {
- return '';
- }
- var json = '[' + commandQueue.join(',') + ']';
- commandQueue.length = 0;
- return json;
-};
-
-iOSExec.nativeCallback = function(callbackId, status, message, keepCallback) {
- return iOSExec.nativeEvalAndFetch(function() {
- var success = status === 0 || status === 1;
- var args = convertMessageToArgsNativeToJs(message);
- cordova.callbackFromNative(callbackId, success, status, args, keepCallback);
- });
-};
-
-iOSExec.nativeEvalAndFetch = function(func) {
- // This shouldn't be nested, but better to be safe.
- isInContextOfEvalJs++;
- try {
- func();
- return iOSExec.nativeFetchMessages();
- } finally {
- isInContextOfEvalJs--;
- }
-};
-
-module.exports = iOSExec;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/994d6bba/src/ios/platform.js
----------------------------------------------------------------------
diff --git a/src/ios/platform.js b/src/ios/platform.js
deleted file mode 100644
index 36529ba..0000000
--- a/src/ios/platform.js
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *
- * 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: 'ios',
- bootstrap: function() {
- require('cordova/channel').onNativeReady.fire();
- }
-};
-
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org