CB-10451 InAppBrowser: loadstart event is not triggered on Windows
CB-10452 InAppBrowser: 'exit' event is not triggered on Windows CB-10454 InAppBrowser: 'loaderror' event does not have code and message on Windows CB-10450 InAppBrowser: Unable to get property 'canGoBack' of undefined on Windows github close #145
This commit is contained in:
parent
73ed40fe07
commit
b024104a54
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
|
|
||||||
var cordova = require('cordova'),
|
var cordova = require('cordova'),
|
||||||
channel = require('cordova/channel'),
|
|
||||||
urlutil = require('cordova/urlutil');
|
urlutil = require('cordova/urlutil');
|
||||||
|
|
||||||
var browserWrap,
|
var browserWrap,
|
||||||
@ -35,11 +34,12 @@ var browserWrap,
|
|||||||
backButton,
|
backButton,
|
||||||
forwardButton,
|
forwardButton,
|
||||||
closeButton,
|
closeButton,
|
||||||
bodyOverflowStyle;
|
bodyOverflowStyle,
|
||||||
|
navigationEventsCallback;
|
||||||
|
|
||||||
// x-ms-webview is available starting from Windows 8.1 (platformId is 'windows')
|
// x-ms-webview is available starting from Windows 8.1 (platformId is 'windows')
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx
|
||||||
var isWebViewAvailable = cordova.platformId == 'windows';
|
var isWebViewAvailable = cordova.platformId === 'windows';
|
||||||
|
|
||||||
function attachNavigationEvents(element, callback) {
|
function attachNavigationEvents(element, callback) {
|
||||||
if (isWebViewAvailable) {
|
if (isWebViewAvailable) {
|
||||||
@ -48,17 +48,21 @@ function attachNavigationEvents(element, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("MSWebViewNavigationCompleted", function (e) {
|
element.addEventListener("MSWebViewNavigationCompleted", function (e) {
|
||||||
callback({ type: e.isSuccess ? "loadstop" : "loaderror", url: e.uri}, {keepCallback: true});
|
if (e.isSuccess) {
|
||||||
|
callback({ type: "loadstop", url: e.uri }, { keepCallback: true });
|
||||||
|
} else {
|
||||||
|
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
|
element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
|
||||||
// WebView found the content to be not HTML.
|
// WebView found the content to be not HTML.
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
|
||||||
callback({ type: "loaderror", url: e.uri}, {keepCallback: true});
|
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener("MSWebViewContentLoading", function (e) {
|
element.addEventListener("MSWebViewContentLoading", function (e) {
|
||||||
if (navigationButtonsDiv) {
|
if (navigationButtonsDiv && popup) {
|
||||||
if (popup.canGoBack) {
|
if (popup.canGoBack) {
|
||||||
backButton.removeAttribute("disabled");
|
backButton.removeAttribute("disabled");
|
||||||
} else {
|
} else {
|
||||||
@ -92,8 +96,11 @@ function attachNavigationEvents(element, callback) {
|
|||||||
|
|
||||||
var IAB = {
|
var IAB = {
|
||||||
close: function (win, lose) {
|
close: function (win, lose) {
|
||||||
|
setImmediate(function () {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
if (win) win({ type: "exit" });
|
if (navigationEventsCallback) {
|
||||||
|
navigationEventsCallback({ type: "exit" });
|
||||||
|
}
|
||||||
|
|
||||||
browserWrap.parentNode.removeChild(browserWrap);
|
browserWrap.parentNode.removeChild(browserWrap);
|
||||||
// Reset body overflow style to initial value
|
// Reset body overflow style to initial value
|
||||||
@ -101,18 +108,25 @@ var IAB = {
|
|||||||
browserWrap = null;
|
browserWrap = null;
|
||||||
popup = null;
|
popup = null;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
show: function (win, lose) {
|
show: function (win, lose) {
|
||||||
|
setImmediate(function () {
|
||||||
if (browserWrap) {
|
if (browserWrap) {
|
||||||
browserWrap.style.display = "block";
|
browserWrap.style.display = "block";
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
open: function (win, lose, args) {
|
open: function (win, lose, args) {
|
||||||
|
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
|
||||||
|
setImmediate(function () {
|
||||||
var strUrl = args[0],
|
var strUrl = args[0],
|
||||||
target = args[1],
|
target = args[1],
|
||||||
features = args[2],
|
features = args[2],
|
||||||
url;
|
url;
|
||||||
|
|
||||||
|
navigationEventsCallback = win;
|
||||||
|
|
||||||
if (target === "_system") {
|
if (target === "_system") {
|
||||||
url = new Windows.Foundation.Uri(strUrl);
|
url = new Windows.Foundation.Uri(strUrl);
|
||||||
Windows.System.Launcher.launchUriAsync(url);
|
Windows.System.Launcher.launchUriAsync(url);
|
||||||
@ -140,7 +154,7 @@ var IAB = {
|
|||||||
|
|
||||||
browserWrap.onclick = function () {
|
browserWrap.onclick = function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
IAB.close(win);
|
IAB.close(navigationEventsCallback);
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -200,7 +214,7 @@ var IAB = {
|
|||||||
closeButton.className = "app-bar-action action-close";
|
closeButton.className = "app-bar-action action-close";
|
||||||
closeButton.addEventListener("click", function (e) {
|
closeButton.addEventListener("click", function (e) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
IAB.close(win);
|
IAB.close(navigationEventsCallback);
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -221,16 +235,18 @@ var IAB = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start listening for navigation events
|
// start listening for navigation events
|
||||||
attachNavigationEvents(popup, win);
|
attachNavigationEvents(popup, navigationEventsCallback);
|
||||||
|
|
||||||
if (isWebViewAvailable) {
|
if (isWebViewAvailable) {
|
||||||
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
|
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
|
||||||
}
|
}
|
||||||
popup.src = strUrl;
|
popup.src = strUrl;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
injectScriptCode: function (win, fail, args) {
|
injectScriptCode: function (win, fail, args) {
|
||||||
|
setImmediate(function () {
|
||||||
var code = args[0],
|
var code = args[0],
|
||||||
hasCallback = args[1];
|
hasCallback = args[1];
|
||||||
|
|
||||||
@ -244,9 +260,11 @@ var IAB = {
|
|||||||
op.onerror = function () { };
|
op.onerror = function () { };
|
||||||
op.start();
|
op.start();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
injectScriptFile: function (win, fail, args) {
|
injectScriptFile: function (win, fail, args) {
|
||||||
|
setImmediate(function () {
|
||||||
var filePath = args[0],
|
var filePath = args[0],
|
||||||
hasCallback = args[1];
|
hasCallback = args[1];
|
||||||
|
|
||||||
@ -268,18 +286,22 @@ var IAB = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
injectStyleCode: function (win, fail, args) {
|
injectStyleCode: function (win, fail, args) {
|
||||||
|
setImmediate(function () {
|
||||||
var code = args[0],
|
var code = args[0],
|
||||||
hasCallback = args[1];
|
hasCallback = args[1];
|
||||||
|
|
||||||
if (isWebViewAvailable && browserWrap && popup) {
|
if (isWebViewAvailable && browserWrap && popup) {
|
||||||
injectCSS(popup, code, hasCallback && win);
|
injectCSS(popup, code, hasCallback && win);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
injectStyleFile: function (win, fail, args) {
|
injectStyleFile: function (win, fail, args) {
|
||||||
|
setImmediate(function () {
|
||||||
var filePath = args[0],
|
var filePath = args[0],
|
||||||
hasCallback = args[1];
|
hasCallback = args[1];
|
||||||
|
|
||||||
@ -295,6 +317,7 @@ var IAB = {
|
|||||||
// no-op, just catch an error
|
// no-op, just catch an error
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user