You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/11/01 00:43:31 UTC
[11/50] ios commit: CB-7735 Update cordova.js snapshot with the
bridge fix
CB-7735 Update cordova.js snapshot with the bridge fix
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/24e3ba6c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/24e3ba6c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/24e3ba6c
Branch: refs/heads/wkwebview
Commit: 24e3ba6c0f56a9c68033b034534eeaa9141b0e29
Parents: c4ece0e
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Oct 14 16:43:30 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Oct 14 16:43:30 2014 -0400
----------------------------------------------------------------------
CordovaLib/cordova.js | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/24e3ba6c/CordovaLib/cordova.js
----------------------------------------------------------------------
diff --git a/CordovaLib/cordova.js b/CordovaLib/cordova.js
index 963dfe6..7889955 100644
--- a/CordovaLib/cordova.js
+++ b/CordovaLib/cordova.js
@@ -1,5 +1,5 @@
// Platform: ios
-// d9e2a1c2401b986b5af09ecd6b4be60df2cbf131
+// 94291706945c42fd47fa632ed30f5eb811080e95
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -840,15 +840,20 @@ var cordova = require('cordova'),
commandQueue = [], // Contains pending JS->Native messages.
isInContextOfEvalJs = 0;
-function createExecIframe() {
+function createExecIframe(src, unloadListener) {
var iframe = document.createElement("iframe");
iframe.style.display = 'none';
+ // Both the unload listener and the src must be set before adding the iframe
+ // to the document in order to avoid race conditions. Callbacks from native
+ // can happen within the appendChild() call!
+ iframe.onunload = unloadListener;
+ iframe.src = src;
document.body.appendChild(iframe);
return iframe;
}
function createHashIframe() {
- var ret = createExecIframe();
+ var ret = createExecIframe('about:blank');
// Hash changes don't work on about:blank, so switch it to file:///.
ret.contentWindow.history.replaceState(null, null, 'file:///#');
return ret;
@@ -1021,6 +1026,11 @@ function pokeNativeViaXhr() {
execXhr.send(null);
}
+function onIframeUnload() {
+ execIframe = null;
+ setTimeout(pokeNativeViaIframe, 0);
+}
+
function pokeNativeViaIframe() {
// CB-5488 - Don't attempt to create iframe before document.body is available.
if (!document.body) {
@@ -1028,6 +1038,7 @@ function 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)
execHashIframe = execHashIframe || createHashIframe();
// Check if they've removed it from the DOM, and put it back if so.
if (!execHashIframe.contentWindow) {
@@ -1041,12 +1052,15 @@ function pokeNativeViaIframe() {
}
execHashIframe.contentWindow.location.hash = hashValue;
} else {
- execIframe = execIframe || createExecIframe();
// Check if they've removed it from the DOM, and put it back if so.
- if (!execIframe.contentWindow) {
- execIframe = createExecIframe();
+ if (execIframe && execIframe.contentWindow) {
+ // Listen for unload, since it can happen (CB-7735) that the iframe gets
+ // removed from the DOM before it gets a chance to poke the native side.
+ execIframe.contentWindow.onunload = onIframeUnload;
+ execIframe.src = 'gap://ready';
+ } else {
+ execIframe = createExecIframe('gap://ready', onIframeUnload);
}
- execIframe.src = "gap://ready";
}
}
@@ -1064,6 +1078,10 @@ iOSExec.setJsToNativeBridgeMode = function(mode) {
};
iOSExec.nativeFetchMessages = function() {
+ // Stop listing for window detatch once native side confirms poke.
+ if (execIframe && execIframe.contentWindow) {
+ execIframe.contentWindow.onunload = null;
+ }
// Each entry in commandQueue is a JSON string already.
if (!commandQueue.length) {
return '';
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org