Updated Branches: refs/heads/master 7df5b6940 -> da71266af
[ios] Add a method for dispatching plugin results and poll for exec() calls at the same time. Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/99fed6dc Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/99fed6dc Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/99fed6dc Branch: refs/heads/master Commit: 99fed6dce70a6c6c6a666a72e6a812e595855f18 Parents: 7df5b69 Author: Andrew Grieve <agri...@chromium.org> Authored: Thu Oct 4 11:19:51 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Thu Oct 4 15:57:14 2012 -0400 ---------------------------------------------------------------------- lib/ios/exec.js | 30 ++++++++++++++++++++++++++---- lib/ios/plugin/ios/nativecomm.js | 32 -------------------------------- 2 files changed, 26 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/99fed6dc/lib/ios/exec.js ---------------------------------------------------------------------- diff --git a/lib/ios/exec.js b/lib/ios/exec.js index 45cf2d6..18b616d 100644 --- a/lib/ios/exec.js +++ b/lib/ios/exec.js @@ -27,7 +27,6 @@ */ var cordova = require('cordova'), channel = require('cordova/channel'), - nativecomm = require('cordova/plugin/ios/nativecomm'), utils = require('cordova/utils'), jsToNativeModes = { IFRAME_NAV: 0, @@ -41,7 +40,8 @@ var cordova = require('cordova'), bridgeMode = navigator.userAgent.indexOf(' 4_') == -1 ? jsToNativeModes.XHR_NO_PAYLOAD : jsToNativeModes.IFRAME_NAV, execIframe, execXhr, - requestCount = 0; + requestCount = 0, + isInContextOfEvalJs = 0; function createExecIframe() { var iframe = document.createElement("iframe"); @@ -110,7 +110,7 @@ function iOSExec() { // the command is executed. cordova.commandQueue.push(JSON.stringify(command)); - if (!cordova.commandQueueFlushing) { + if (!cordova.commandQueueFlushing && !isInContextOfEvalJs) { if (bridgeMode != jsToNativeModes.IFRAME_NAV) { // Re-using the XHR improves exec() performance by about 10%. // It is possible for a native stringByEvaluatingJavascriptFromString call @@ -127,7 +127,7 @@ function iOSExec() { execXhr.setRequestHeader('vc', cordova.iOSVCAddr); execXhr.setRequestHeader('rc', ++requestCount); if (shouldBundleCommandJson()) { - execXhr.setRequestHeader('cmds', nativecomm()); + execXhr.setRequestHeader('cmds', iOSExec.nativeFetchMessages()); } execXhr.send(null); } else { @@ -150,4 +150,26 @@ iOSExec.setJsToNativeBridgeMode = function(mode) { bridgeMode = mode; }; +iOSExec.nativeFetchMessages = function() { + // Each entry in commandQueue is a JSON string already. + if (!cordova.commandQueue.length) { + return ''; + } + var json = '[' + cordova.commandQueue.join(',') + ']'; + cordova.commandQueue.length = 0; + return json; +}; + +iOSExec.nativeCallback = function(callbackId, status, payload, keepCallback) { + // This shouldn't be nested, but better to be safe. + isInContextOfEvalJs++; + try { + var success = status == 0 || status == 1; + cordova.callbackFromNative(callbackId, success, status, payload, keepCallback); + return iOSExec.nativeFetchMessages(); + } finally { + isInContextOfEvalJs--; + } +}; + module.exports = iOSExec; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/99fed6dc/lib/ios/plugin/ios/nativecomm.js ---------------------------------------------------------------------- diff --git a/lib/ios/plugin/ios/nativecomm.js b/lib/ios/plugin/ios/nativecomm.js deleted file mode 100644 index 197ebb1..0000000 --- a/lib/ios/plugin/ios/nativecomm.js +++ /dev/null @@ -1,32 +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'); - -/** - * Called by native code to retrieve all queued commands and clear the queue. - */ -module.exports = function() { - // Each entry in commandQueue is a JSON string already. - var json = '[' + cordova.commandQueue.join(',') + ']'; - cordova.commandQueue.length = 0; - return json; -};