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:
sgrebnov 2016-01-28 19:08:27 +03:00
parent 73ed40fe07
commit b024104a54

View File

@ -25,7 +25,6 @@
var cordova = require('cordova'),
channel = require('cordova/channel'),
urlutil = require('cordova/urlutil');
var browserWrap,
@ -35,11 +34,12 @@ var browserWrap,
backButton,
forwardButton,
closeButton,
bodyOverflowStyle;
bodyOverflowStyle,
navigationEventsCallback;
// x-ms-webview is available starting from Windows 8.1 (platformId is 'windows')
// 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) {
if (isWebViewAvailable) {
@ -48,17 +48,21 @@ function attachNavigationEvents(element, callback) {
});
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) {
// WebView found the content to be not HTML.
// 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) {
if (navigationButtonsDiv) {
if (navigationButtonsDiv && popup) {
if (popup.canGoBack) {
backButton.removeAttribute("disabled");
} else {
@ -92,8 +96,11 @@ function attachNavigationEvents(element, callback) {
var IAB = {
close: function (win, lose) {
setImmediate(function () {
if (browserWrap) {
if (win) win({ type: "exit" });
if (navigationEventsCallback) {
navigationEventsCallback({ type: "exit" });
}
browserWrap.parentNode.removeChild(browserWrap);
// Reset body overflow style to initial value
@ -101,18 +108,25 @@ var IAB = {
browserWrap = null;
popup = null;
}
});
},
show: function (win, lose) {
setImmediate(function () {
if (browserWrap) {
browserWrap.style.display = "block";
}
});
},
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],
target = args[1],
features = args[2],
url;
navigationEventsCallback = win;
if (target === "_system") {
url = new Windows.Foundation.Uri(strUrl);
Windows.System.Launcher.launchUriAsync(url);
@ -140,7 +154,7 @@ var IAB = {
browserWrap.onclick = function () {
setTimeout(function () {
IAB.close(win);
IAB.close(navigationEventsCallback);
}, 0);
};
@ -200,7 +214,7 @@ var IAB = {
closeButton.className = "app-bar-action action-close";
closeButton.addEventListener("click", function (e) {
setTimeout(function () {
IAB.close(win);
IAB.close(navigationEventsCallback);
}, 0);
});
@ -221,16 +235,18 @@ var IAB = {
}
// start listening for navigation events
attachNavigationEvents(popup, win);
attachNavigationEvents(popup, navigationEventsCallback);
if (isWebViewAvailable) {
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
}
popup.src = strUrl;
}
});
},
injectScriptCode: function (win, fail, args) {
setImmediate(function () {
var code = args[0],
hasCallback = args[1];
@ -244,9 +260,11 @@ var IAB = {
op.onerror = function () { };
op.start();
}
});
},
injectScriptFile: function (win, fail, args) {
setImmediate(function () {
var filePath = args[0],
hasCallback = args[1];
@ -268,18 +286,22 @@ var IAB = {
});
});
}
});
},
injectStyleCode: function (win, fail, args) {
setImmediate(function () {
var code = args[0],
hasCallback = args[1];
if (isWebViewAvailable && browserWrap && popup) {
injectCSS(popup, code, hasCallback && win);
}
});
},
injectStyleFile: function (win, fail, args) {
setImmediate(function () {
var filePath = args[0],
hasCallback = args[1];
@ -295,6 +317,7 @@ var IAB = {
// no-op, just catch an error
});
}
});
}
};