Skip to content

Commit ad2cfe3

Browse files
authored
fixed the issue that cordova opens webview instead of system browser (#486)
1 parent 551c76c commit ad2cfe3

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

javascript/utils/util.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ firebaseui.auth.util.getScheme = function() {
5757
};
5858

5959

60+
/** @return {boolean} Whether Cordova InAppBrowser plugin is installed. */
61+
firebaseui.auth.util.isCordovaInAppBrowserInstalled = function() {
62+
return !!(window['cordova'] && window['cordova']['InAppBrowser']);
63+
};
64+
65+
6066
/** @return {boolean} Whether current scheme is HTTP or HTTPS. */
6167
firebaseui.auth.util.isHttpOrHttps = function() {
6268
return firebaseui.auth.util.getScheme() === 'http:' ||

javascript/widgets/config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ firebaseui.auth.widget.Config.prototype.getTosUrl = function() {
641641
return /** @type {function()} */ (tosUrl);
642642
} else if (goog.isString(tosUrl)) {
643643
return function() {
644-
firebaseui.auth.util.open(/** @type {string} */ (tosUrl), '_blank');
644+
firebaseui.auth.util.open(
645+
/** @type {string} */ (tosUrl),
646+
firebaseui.auth.util.isCordovaInAppBrowserInstalled() ?
647+
'_system' : '_blank');
645648
};
646649
}
647650
}
@@ -666,7 +669,9 @@ firebaseui.auth.widget.Config.prototype.getPrivacyPolicyUrl = function() {
666669
} else if (goog.isString(privacyPolicyUrl)) {
667670
return function() {
668671
firebaseui.auth.util.open(
669-
/** @type {string} */ (privacyPolicyUrl), '_blank');
672+
/** @type {string} */ (privacyPolicyUrl),
673+
firebaseui.auth.util.isCordovaInAppBrowserInstalled() ?
674+
'_system' : '_blank');
670675
};
671676
}
672677
}

javascript/widgets/config_test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,17 @@ function testGetTosUrl() {
10341034
[
10351035
'Privacy Policy URL is missing, the link will not be displayed.'
10361036
], warningLogMessages);
1037+
// Mock that Cordova InAppBrowser plugin is installed.
1038+
stub.replace(
1039+
firebaseui.auth.util,
1040+
'isCordovaInAppBrowserInstalled',
1041+
function() {
1042+
return true;
1043+
});
1044+
tosCallback = config.getTosUrl();
1045+
tosCallback();
1046+
// Target should be _system if Cordova InAppBrowser plugin is installed.
1047+
testUtil.assertOpen('http://localhost/tos', '_system');
10371048
// Tests if callback function is passed to tosUrl config.
10381049
tosCallback = function() {};
10391050
config.update('tosUrl', tosCallback);
@@ -1062,6 +1073,17 @@ function testGetPrivacyPolicyUrl() {
10621073
[
10631074
'Term of Service URL is missing, the link will not be displayed.'
10641075
], warningLogMessages);
1076+
// Mock that Cordova InAppBrowser plugin is installed.
1077+
stub.replace(
1078+
firebaseui.auth.util,
1079+
'isCordovaInAppBrowserInstalled',
1080+
function() {
1081+
return true;
1082+
});
1083+
privacyPolicyCallback = config.getPrivacyPolicyUrl();
1084+
privacyPolicyCallback();
1085+
// Target should be _system if Cordova InAppBrowser plugin is installed.
1086+
testUtil.assertOpen('http://localhost/privacy_policy', '_system');
10651087
// Tests if callback function is passed to privacyPolicyUrl config.
10661088
privacyPolicyCallback = function() {};
10671089
config.update('privacyPolicyUrl', privacyPolicyCallback);

0 commit comments

Comments
 (0)