Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-inappbrowser

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-inappbrowser - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

77

ChromeTabsManagerActivity.js

@@ -21,16 +21,23 @@ var Intent = android.content.Intent;

};
let ChromeTabsManagerActivity = class ChromeTabsManagerActivity extends android.app.Activity {
constructor() {
super();
this.mOpened = false;
this.resultType = null;
this.isError = false;
return global.__native(this);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChromeTabsManagerActivity = void 0;
var ChromeTabsManagerActivity = /** @class */ (function (_super) {
__extends(ChromeTabsManagerActivity, _super);
function ChromeTabsManagerActivity() {
var _this = _super.call(this) || this;
_this.mOpened = false;
_this.resultType = null;
_this.isError = false;
return global.__native(_this);
}
onCreate(savedInstanceState) {
ChromeTabsManagerActivity.prototype.onCreate = function (savedInstanceState) {
try {
super.onCreate(savedInstanceState);
_super.prototype.onCreate.call(this, savedInstanceState);
// This activity gets opened in 2 different ways. If the extra KEY_BROWSER_INTENT is present we
// start that intent and if it is not it means this activity was started with FLAG_ACTIVITY_CLEAR_TOP
// in order to close the intent that was started previously so we just close this.
if (this.getIntent().hasExtra(KEY_BROWSER_INTENT)
&& (!savedInstanceState || !savedInstanceState.getString(BROWSER_RESULT_TYPE))) {
const browserIntent = this.getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
var browserIntent = this.getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

@@ -48,7 +55,10 @@ this.startActivity(browserIntent);

this.finish();
log(`InAppBrowser: ${error}`);
log("InAppBrowser: " + error);
}
}
onResume() {
super.onResume();
};
ChromeTabsManagerActivity.prototype.onResume = function () {
_super.prototype.onResume.call(this);
// onResume will get called twice, the first time when the activity is created and a second
// time if the user closes the chrome tabs activity. Knowing this we can detect if the user
// dismissed the activity and send an event accordingly.
if (!this.mOpened) {

@@ -61,4 +71,4 @@ this.mOpened = true;

}
}
onDestroy() {
};
ChromeTabsManagerActivity.prototype.onDestroy = function () {
if (this.resultType) {

@@ -75,23 +85,22 @@ switch (this.resultType) {

}
super.onDestroy();
}
onNewIntent(intent) {
super.onNewIntent(intent);
_super.prototype.onDestroy.call(this);
};
ChromeTabsManagerActivity.prototype.onNewIntent = function (intent) {
_super.prototype.onNewIntent.call(this, intent);
this.setIntent(intent);
}
onRestoreInstanceState(savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
};
ChromeTabsManagerActivity.prototype.onRestoreInstanceState = function (savedInstanceState) {
_super.prototype.onRestoreInstanceState.call(this, savedInstanceState);
this.resultType = savedInstanceState.getString(BROWSER_RESULT_TYPE);
}
onSaveInstanceState(savedInstanceState) {
};
ChromeTabsManagerActivity.prototype.onSaveInstanceState = function (savedInstanceState) {
savedInstanceState.putString(BROWSER_RESULT_TYPE, DEFAULT_RESULT_TYPE);
super.onSaveInstanceState(savedInstanceState);
}
};
ChromeTabsManagerActivity = __decorate([
NativeClass(),
JavaProxy('com.proyecto26.inappbrowser.ChromeTabsManagerActivity'),
__metadata("design:paramtypes", [])
], ChromeTabsManagerActivity);
export { ChromeTabsManagerActivity };
_super.prototype.onSaveInstanceState.call(this, savedInstanceState);
};
ChromeTabsManagerActivity = __decorate([
JavaProxy('com.proyecto26.inappbrowser.ChromeTabsManagerActivity')
], ChromeTabsManagerActivity);
return ChromeTabsManagerActivity;
}(android.app.Activity));
exports.ChromeTabsManagerActivity = ChromeTabsManagerActivity;
export const createStartIntent = (context, authIntent) => {

@@ -98,0 +107,0 @@ let intent = createBaseIntent(context);

@@ -15,209 +15,227 @@ var Uri = android.net.Uri;

function setup() {
var InAppBrowserModule_1;
let InAppBrowserModule = InAppBrowserModule_1 = class InAppBrowserModule extends java.lang.Object {
constructor() {
super();
this.animationIdentifierPattern = Pattern.compile('^.+:.+/');
return global.__native(this);
}
isAvailable() {
const context = Utils.android.getApplicationContext();
const resolveInfos = getPreferredPackages(context);
return Promise.resolve(!(resolveInfos === null || resolveInfos.isEmpty()));
}
async open(url, options) {
const mOpenBrowserPromise = InAppBrowserModule_1.redirectResolve;
if (mOpenBrowserPromise) {
this.flowDidFinish();
const result = {
type: BROWSER_TYPES.CANCEL
};
return Promise.resolve(result);
}
this.currentActivity = Application.android.foregroundActivity || Application.android.startActivity;
if (!this.currentActivity) {
return Promise.reject(new Error(InAppBrowserModule_1.ERROR_CODE));
}
const result = new Promise(function (resolve, reject) {
InAppBrowserModule_1.redirectResolve = resolve;
InAppBrowserModule_1.redirectReject = reject;
});
const inAppBrowserOptions = getDefaultOptions(url, options);
const builder = new CustomTabsIntent.Builder();
let colorString = inAppBrowserOptions[InAppBrowserModule_1.KEY_TOOLBAR_COLOR];
this.isLightTheme = false;
if (colorString) {
const color = tryParseColor(colorString, 'Invalid toolbar color');
if (color) {
builder.setToolbarColor(color.android);
this.isLightTheme = toolbarIsLight(color.android);
var InAppBrowserModule = /** @class */ (function (_super) {
__extends(InAppBrowserModule, _super);
function InAppBrowserModule() {
var _this = _super.call(this) || this;
_this.animationIdentifierPattern = Pattern.compile('^.+:.+/');
return global.__native(_this);
}
InAppBrowserModule.prototype.isAvailable = function () {
var context = Utils.android.getApplicationContext();
var resolveInfos = getPreferredPackages(context);
return Promise.resolve(!(resolveInfos === null || resolveInfos.isEmpty()));
};
InAppBrowserModule.prototype.open = function (url, options) {
return __awaiter(this, void 0, Promise, function () {
var mOpenBrowserPromise, result_1, result, inAppBrowserOptions, builder, colorString, color, color, color, color, context, animations, customTabsIntent, intent, keyHeaders, headers, key, packageName, packageName;
return __generator(this, function (_a) {
mOpenBrowserPromise = InAppBrowserModule.redirectResolve;
if (mOpenBrowserPromise) {
this.flowDidFinish();
result_1 = {
type: BROWSER_TYPES.CANCEL
};
return [2 /*return*/, Promise.resolve(result_1)];
}
}
colorString = inAppBrowserOptions[InAppBrowserModule_1.KEY_SECONDARY_TOOLBAR_COLOR];
if (colorString) {
const color = tryParseColor(colorString, 'Invalid secondary toolbar color');
if (color) {
builder.setSecondaryToolbarColor(color.android);
this.currentActivity = Application.android.foregroundActivity || Application.android.startActivity;
if (!this.currentActivity) {
return [2 /*return*/, Promise.reject(new Error(InAppBrowserModule.ERROR_CODE))];
}
}
colorString = inAppBrowserOptions[InAppBrowserModule_1.KEY_NAVIGATION_BAR_COLOR];
if (colorString) {
const color = tryParseColor(colorString, 'Invalid navigation bar color');
if (color) {
builder.setSecondaryToolbarColor(color.android);
result = new Promise(function (resolve, reject) {
InAppBrowserModule.redirectResolve = resolve;
InAppBrowserModule.redirectReject = reject;
});
inAppBrowserOptions = getDefaultOptions(url, options);
builder = new CustomTabsIntent.Builder();
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR];
this.isLightTheme = false;
if (colorString) {
color = tryParseColor(colorString, 'Invalid toolbar color');
if (color) {
builder.setToolbarColor(color.android);
this.isLightTheme = toolbarIsLight(color.android);
}
}
}
colorString = inAppBrowserOptions[InAppBrowserModule_1.KEY_NAVIGATION_BAR_DIVIDER_COLOR];
if (colorString) {
const color = tryParseColor(colorString, 'Invalid navigation bar divider color');
if (color) {
builder.setSecondaryToolbarColor(color.android);
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR];
if (colorString) {
color = tryParseColor(colorString, 'Invalid secondary toolbar color');
if (color) {
builder.setSecondaryToolbarColor(color.android);
}
}
}
if (inAppBrowserOptions[InAppBrowserModule_1.KEY_DEFAULT_SHARE_MENU_ITEM]) {
builder.addDefaultShareMenuItem();
}
const context = Utils.android.getApplicationContext();
if (inAppBrowserOptions[InAppBrowserModule_1.KEY_ANIMATIONS]) {
const animations = inAppBrowserOptions[InAppBrowserModule_1.KEY_ANIMATIONS];
this.applyAnimation(context, builder, animations);
}
if (inAppBrowserOptions[InAppBrowserModule_1.KEY_HAS_BACK_BUTTON]) {
builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.getResources(), this.isLightTheme
? getDrawableId(ARROW_BACK_BLACK)
: getDrawableId(ARROW_BACK_WHITE)));
}
const customTabsIntent = builder.build();
const intent = customTabsIntent.intent;
const keyHeaders = inAppBrowserOptions[InAppBrowserModule_1.KEY_HEADERS];
if (keyHeaders) {
const headers = new Bundle();
for (const key in keyHeaders) {
if (keyHeaders.hasOwnProperty(key)) {
headers.putString(key, keyHeaders[key]);
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_NAVIGATION_BAR_COLOR];
if (colorString) {
color = tryParseColor(colorString, 'Invalid navigation bar color');
if (color) {
builder.setNavigationBarColor(color.android);
}
}
intent.putExtra(Browser.EXTRA_HEADERS, headers);
}
if (inAppBrowserOptions[InAppBrowserModule_1.KEY_FORCE_CLOSE_ON_REDIRECTION]) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (!inAppBrowserOptions[InAppBrowserModule_1.KEY_SHOW_IN_RECENTS]) {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
}
intent.putExtra(CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, !!inAppBrowserOptions[InAppBrowserModule_1.KEY_ENABLE_URL_BAR_HIDING]);
try {
if (inAppBrowserOptions[InAppBrowserModule_1.KEY_BROWSER_PACKAGE] !== undefined) {
const packageName = inAppBrowserOptions[InAppBrowserModule_1.KEY_BROWSER_PACKAGE];
if (!TextUtils.isEmpty(packageName)) {
colorString = inAppBrowserOptions[InAppBrowserModule.KEY_NAVIGATION_BAR_DIVIDER_COLOR];
if (colorString) {
color = tryParseColor(colorString, 'Invalid navigation bar divider color');
if (color) {
builder.setNavigationBarDividerColor(color.android);
}
}
if (inAppBrowserOptions[InAppBrowserModule.KEY_DEFAULT_SHARE_MENU_ITEM]) {
builder.addDefaultShareMenuItem();
}
context = Utils.android.getApplicationContext();
if (inAppBrowserOptions[InAppBrowserModule.KEY_ANIMATIONS]) {
animations = inAppBrowserOptions[InAppBrowserModule.KEY_ANIMATIONS];
this.applyAnimation(context, builder, animations);
}
if (inAppBrowserOptions[InAppBrowserModule.KEY_HAS_BACK_BUTTON]) {
builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.getResources(), this.isLightTheme
? getDrawableId(ARROW_BACK_BLACK)
: getDrawableId(ARROW_BACK_WHITE)));
}
customTabsIntent = builder.build();
intent = customTabsIntent.intent;
keyHeaders = inAppBrowserOptions[InAppBrowserModule.KEY_HEADERS];
if (keyHeaders) {
headers = new Bundle();
for (key in keyHeaders) {
if (keyHeaders.hasOwnProperty(key)) {
headers.putString(key, keyHeaders[key]);
}
}
intent.putExtra(Browser.EXTRA_HEADERS, headers);
}
if (inAppBrowserOptions[InAppBrowserModule.KEY_FORCE_CLOSE_ON_REDIRECTION]) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (!inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_IN_RECENTS]) {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
}
intent.putExtra(CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, !!inAppBrowserOptions[InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING]);
try {
if (inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE] !== undefined) {
packageName = inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE];
if (!TextUtils.isEmpty(packageName)) {
intent.setPackage(packageName);
}
}
else {
packageName = inAppBrowserOptions[InAppBrowserModule.KEY_BROWSER_PACKAGE];
intent.setPackage(packageName);
}
}
catch (error) {
if (error.printStackTrace) {
error.printStackTrace();
}
}
this.registerEvent();
intent.setData(Uri.parse(url));
if (inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]) {
builder.setShowTitle(!!inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]);
}
else {
const packageName = inAppBrowserOptions[InAppBrowserModule_1.KEY_BROWSER_PACKAGE];
intent.setPackage(packageName);
intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
}
}
catch (error) {
if (error.printStackTrace) {
error.printStackTrace();
}
}
this.registerEvent();
intent.setData(Uri.parse(url));
if (inAppBrowserOptions[InAppBrowserModule_1.KEY_SHOW_PAGE_TITLE]) {
builder.setShowTitle(!!inAppBrowserOptions[InAppBrowserModule_1.KEY_SHOW_PAGE_TITLE]);
}
else {
intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
}
this.currentActivity.startActivity(createStartIntent(this.currentActivity, intent), customTabsIntent.startAnimationBundle);
return result;
this.currentActivity.startActivity(createStartIntent(this.currentActivity, intent), customTabsIntent.startAnimationBundle);
return [2 /*return*/, result];
});
});
};
InAppBrowserModule.prototype.close = function () {
if (!InAppBrowserModule.redirectResolve) {
return;
}
close() {
if (!InAppBrowserModule_1.redirectResolve) {
return;
}
if (!this.currentActivity) {
InAppBrowserModule_1.redirectReject(new Error(InAppBrowserModule_1.ERROR_CODE));
this.flowDidFinish();
return;
}
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
const result = {
type: 'dismiss'
};
InAppBrowserModule_1.redirectResolve(result);
if (!this.currentActivity) {
InAppBrowserModule.redirectReject(new Error(InAppBrowserModule.ERROR_CODE));
this.flowDidFinish();
this.currentActivity.startActivity(createDismissIntent(this.currentActivity));
return;
}
async openAuth(url, redirectUrl, options) {
let response = null;
try {
response = await openAuthSessionPolyfillAsync((startUrl, opt) => this.open(startUrl, opt), url, redirectUrl, options);
}
finally {
closeAuthSessionPolyfillAsync();
this.close();
}
return response;
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
var result = {
type: 'dismiss'
};
InAppBrowserModule.redirectResolve(result);
this.flowDidFinish();
this.currentActivity.startActivity(createDismissIntent(this.currentActivity));
};
InAppBrowserModule.prototype.openAuth = function (url, redirectUrl, options) {
return __awaiter(this, void 0, void 0, function () {
var response;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
response = null;
_a.label = 1;
case 1:
_a.trys.push([1, , 3, 4]);
return [4 /*yield*/, openAuthSessionPolyfillAsync(function (startUrl, opt) { return _this.open(startUrl, opt); }, url, redirectUrl, options)];
case 2:
response = _a.sent();
return [3 /*break*/, 4];
case 3:
closeAuthSessionPolyfillAsync();
this.close();
return [7 /*endfinally*/];
case 4: return [2 /*return*/, response];
}
});
});
};
InAppBrowserModule.prototype.closeAuth = function () {
closeAuthSessionPolyfillAsync();
this.close();
};
InAppBrowserModule.prototype.onEvent = function (event) {
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
if (!InAppBrowserModule.redirectResolve) {
return;
}
closeAuth() {
closeAuthSessionPolyfillAsync();
this.close();
var browserEvent = event.object;
if (browserEvent.isError) {
InAppBrowserModule.redirectReject(new Error(browserEvent.message));
}
onEvent(event) {
BROWSER_ACTIVITY_EVENTS.off(DISMISSED_EVENT);
if (!InAppBrowserModule_1.redirectResolve) {
return;
}
const browserEvent = event.object;
if (browserEvent.isError) {
InAppBrowserModule_1.redirectReject(new Error(browserEvent.message));
}
else {
InAppBrowserModule_1.redirectResolve({
type: browserEvent.resultType,
message: browserEvent.message
});
}
this.flowDidFinish();
else {
InAppBrowserModule.redirectResolve({
type: browserEvent.resultType,
message: browserEvent.message
});
}
registerEvent() {
BROWSER_ACTIVITY_EVENTS.once(DISMISSED_EVENT, (e) => this.onEvent(e));
this.flowDidFinish();
};
InAppBrowserModule.prototype.registerEvent = function () {
var _this = this;
BROWSER_ACTIVITY_EVENTS.once(DISMISSED_EVENT, function (e) { return _this.onEvent(e); });
};
InAppBrowserModule.prototype.resolveAnimationIdentifierIfNeeded = function (context, identifier) {
if (this.animationIdentifierPattern.matcher(identifier).find()) {
return context.getResources().getIdentifier(identifier, null, null);
}
resolveAnimationIdentifierIfNeeded(context, identifier) {
if (this.animationIdentifierPattern.matcher(identifier).find()) {
return context.getResources().getIdentifier(identifier, null, null);
}
else {
return context.getResources().getIdentifier(identifier, 'anim', context.getPackageName());
}
else {
return context.getResources().getIdentifier(identifier, 'anim', context.getPackageName());
}
applyAnimation(context, builder, animations) {
const startEnterAnimationId = animations[InAppBrowserModule_1.KEY_ANIMATION_START_ENTER]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule_1.KEY_ANIMATION_START_ENTER])
: -1;
const startExitAnimationId = animations[InAppBrowserModule_1.KEY_ANIMATION_START_EXIT]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule_1.KEY_ANIMATION_START_EXIT])
: -1;
const endEnterAnimationId = animations[InAppBrowserModule_1.KEY_ANIMATION_END_ENTER]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule_1.KEY_ANIMATION_END_ENTER])
: -1;
const endExitAnimationId = animations[InAppBrowserModule_1.KEY_ANIMATION_END_EXIT]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule_1.KEY_ANIMATION_END_EXIT])
: -1;
if (startEnterAnimationId !== -1 && startExitAnimationId !== -1) {
builder.setStartAnimations(context, startEnterAnimationId, startExitAnimationId);
}
if (endEnterAnimationId !== -1 && endExitAnimationId !== -1) {
builder.setExitAnimations(context, endEnterAnimationId, endExitAnimationId);
}
};
InAppBrowserModule.prototype.applyAnimation = function (context, builder, animations) {
var startEnterAnimationId = animations[InAppBrowserModule.KEY_ANIMATION_START_ENTER]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule.KEY_ANIMATION_START_ENTER])
: -1;
var startExitAnimationId = animations[InAppBrowserModule.KEY_ANIMATION_START_EXIT]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule.KEY_ANIMATION_START_EXIT])
: -1;
var endEnterAnimationId = animations[InAppBrowserModule.KEY_ANIMATION_END_ENTER]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule.KEY_ANIMATION_END_ENTER])
: -1;
var endExitAnimationId = animations[InAppBrowserModule.KEY_ANIMATION_END_EXIT]
? this.resolveAnimationIdentifierIfNeeded(context, animations[InAppBrowserModule.KEY_ANIMATION_END_EXIT])
: -1;
if (startEnterAnimationId !== -1 && startExitAnimationId !== -1) {
builder.setStartAnimations(context, startEnterAnimationId, startExitAnimationId);
}
flowDidFinish() {
InAppBrowserModule_1.redirectResolve = null;
InAppBrowserModule_1.redirectReject = null;
if (endEnterAnimationId !== -1 && endExitAnimationId !== -1) {
builder.setExitAnimations(context, endEnterAnimationId, endExitAnimationId);
}
};
InAppBrowserModule.prototype.flowDidFinish = function () {
InAppBrowserModule.redirectResolve = null;
InAppBrowserModule.redirectReject = null;
};
InAppBrowserModule.ERROR_CODE = 'InAppBrowser';

@@ -241,6 +259,4 @@ InAppBrowserModule.KEY_TOOLBAR_COLOR = 'toolbarColor';

InAppBrowserModule.KEY_SHOW_IN_RECENTS = 'showInRecents';
InAppBrowserModule = InAppBrowserModule_1 = __decorate([
NativeClass(),
__metadata("design:paramtypes", [])
], InAppBrowserModule);
return InAppBrowserModule;
}(java.lang.Object));
return new InAppBrowserModule();

@@ -247,0 +263,0 @@ }

@@ -15,186 +15,201 @@ import { Utils } from '@nativescript/core';

function setup() {
let InAppBrowserModule = class InAppBrowserModule extends NSObject {
constructor() {
super(...arguments);
this.safariVC = null;
this.redirectResolve = null;
this.redirectReject = null;
this.authSession = null;
this.animated = false;
var InAppBrowserModule = /** @class */ (function (_super) {
__extends(InAppBrowserModule, _super);
function InAppBrowserModule() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.safariVC = null;
_this.redirectResolve = null;
_this.redirectReject = null;
_this.authSession = null;
_this.animated = false;
return _this;
}
InAppBrowserModule.prototype.isAvailable = function () {
return Promise.resolve(Utils.ios.MajorVersion >= 9);
};
InAppBrowserModule.prototype.initializeWebBrowser = function (resolve, reject) {
if (this.redirectReject) {
this.redirectReject(new Error(InAppBrowserErrorMessage));
return false;
}
isAvailable() {
return Promise.resolve(Utils.ios.MajorVersion >= 9);
}
initializeWebBrowser(resolve, reject) {
if (this.redirectReject) {
this.redirectReject(new Error(InAppBrowserErrorMessage));
return false;
this.redirectResolve = resolve;
this.redirectReject = reject;
return true;
};
InAppBrowserModule.prototype.open = function (authURL, options) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.initializeWebBrowser(resolve, reject))
return;
var inAppBrowserOptions = getDefaultOptions(authURL, options);
_this.animated = inAppBrowserOptions.animated;
try {
// Safari View Controller to authorize request
var url = NSURL.URLWithString(inAppBrowserOptions.url);
if (Utils.ios.MajorVersion >= 11) {
var config = SFSafariViewControllerConfiguration.alloc().init();
config.barCollapsingEnabled = inAppBrowserOptions.enableBarCollapsing;
config.entersReaderIfAvailable = inAppBrowserOptions.readerMode;
_this.safariVC = SFSafariViewController.alloc().initWithURLConfiguration(url, config);
}
else {
_this.safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(url, inAppBrowserOptions.readerMode);
}
}
this.redirectResolve = resolve;
this.redirectReject = reject;
return true;
}
open(authURL, options) {
return new Promise((resolve, reject) => {
if (!this.initializeWebBrowser(resolve, reject))
return;
const inAppBrowserOptions = getDefaultOptions(authURL, options);
this.animated = inAppBrowserOptions.animated;
try {
const url = NSURL.URLWithString(inAppBrowserOptions.url);
if (Utils.ios.MajorVersion >= 11) {
const config = SFSafariViewControllerConfiguration.alloc().init();
config.barCollapsingEnabled = inAppBrowserOptions.enableBarCollapsing;
config.entersReaderIfAvailable = inAppBrowserOptions.readerMode;
this.safariVC = SFSafariViewController.alloc().initWithURLConfiguration(url, config);
}
else {
this.safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(url, inAppBrowserOptions.readerMode);
}
catch (error) {
reject(new Error("Unable to open url."));
_this.flowDidFinish();
log("InAppBrowser: " + error);
return;
}
_this.safariVC.delegate = _this;
if (Utils.ios.MajorVersion >= 11) {
if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.DONE) {
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Done;
}
catch (error) {
reject(new Error("Unable to open url."));
this.flowDidFinish();
log(`InAppBrowser: ${error}`);
return;
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CLOSE) {
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Close;
}
this.safariVC.delegate = this;
if (Utils.ios.MajorVersion >= 11) {
if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.DONE) {
this.safariVC.dismissButtonStyle = 0;
}
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CLOSE) {
this.safariVC.dismissButtonStyle = 1;
}
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CANCEL) {
this.safariVC.dismissButtonStyle = 2;
}
else if (inAppBrowserOptions.dismissButtonStyle === DISMISS_BUTTON_STYLES.CANCEL) {
_this.safariVC.dismissButtonStyle = SFSafariViewControllerDismissButtonStyle.Cancel;
}
if (Utils.ios.MajorVersion >= 10) {
if (inAppBrowserOptions.preferredBarTintColor) {
const color = parseColor(inAppBrowserOptions.preferredBarTintColor);
if (color) {
this.safariVC.preferredBarTintColor = color.ios;
}
}
if (Utils.ios.MajorVersion >= 10) {
if (inAppBrowserOptions.preferredBarTintColor) {
var color = parseColor(inAppBrowserOptions.preferredBarTintColor);
if (color) {
_this.safariVC.preferredBarTintColor = color.ios;
}
if (inAppBrowserOptions.preferredControlTintColor) {
const color = parseColor(inAppBrowserOptions.preferredControlTintColor);
if (color) {
this.safariVC.preferredControlTintColor = color.ios;
}
}
}
const ctrl = UIApplication.sharedApplication.keyWindow.rootViewController;
if (inAppBrowserOptions.modalEnabled) {
const safariHackVC = UINavigationController.alloc().initWithRootViewController(this.safariVC);
safariHackVC.setNavigationBarHiddenAnimated(true, false);
this.safariVC.modalPresentationStyle = 5;
safariHackVC.modalPresentationStyle = getPresentationStyle(inAppBrowserOptions.modalPresentationStyle);
if (this.animated) {
safariHackVC.modalTransitionStyle = getTransitionStyle(inAppBrowserOptions.modalTransitionStyle);
if (inAppBrowserOptions.preferredControlTintColor) {
var color = parseColor(inAppBrowserOptions.preferredControlTintColor);
if (color) {
_this.safariVC.preferredControlTintColor = color.ios;
}
if (Utils.ios.MajorVersion >= 13) {
safariHackVC.modalInPresentation = true;
if (safariHackVC[setModalInPresentation])
safariHackVC[setModalInPresentation](true);
}
safariHackVC.presentationController.delegate = this;
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, inAppBrowserOptions.animated, null);
}
else {
ctrl.presentViewControllerAnimatedCompletion(this.safariVC, inAppBrowserOptions.animated, null);
}
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController;
if (inAppBrowserOptions.modalEnabled) {
// This is a hack to present the SafariViewController modally
var safariHackVC = UINavigationController.alloc().initWithRootViewController(_this.safariVC);
safariHackVC.setNavigationBarHiddenAnimated(true, false);
// To disable "Swipe to dismiss" gesture which sometimes causes a bug where `safariViewControllerDidFinish`
// is not called.
_this.safariVC.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen;
safariHackVC.modalPresentationStyle = getPresentationStyle(inAppBrowserOptions.modalPresentationStyle);
if (_this.animated) {
safariHackVC.modalTransitionStyle = getTransitionStyle(inAppBrowserOptions.modalTransitionStyle);
}
});
}
close() {
const ctrl = UIApplication.sharedApplication.keyWindow.rootViewController;
ctrl.dismissViewControllerAnimatedCompletion(this.animated, () => {
if (this.redirectResolve) {
this.redirectResolve({
type: 'dismiss'
});
this.flowDidFinish();
if (Utils.ios.MajorVersion >= 13) {
safariHackVC.modalInPresentation = true;
if (safariHackVC[setModalInPresentation])
safariHackVC[setModalInPresentation](true);
}
});
}
async openAuth(authUrl, redirectUrl, options = {}) {
const inAppBrowserOptions = Object.assign(Object.assign({}, options), { ephemeralWebSession: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false });
if (Utils.ios.MajorVersion >= 11) {
return new Promise((resolve, reject) => {
if (!this.initializeWebBrowser(resolve, reject))
return;
const url = NSURL.URLWithString(authUrl);
const escapedRedirectURL = NSURL.URLWithString(redirectUrl).scheme;
this.authSession = (Utils.ios.MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession).alloc().initWithURLCallbackURLSchemeCompletionHandler(url, escapedRedirectURL, (callbackURL, error) => {
if (this.redirectResolve) {
if (!error) {
this.redirectResolve({
type: BROWSER_TYPES.SUCCESS,
url: callbackURL.absoluteString
});
}
else {
this.redirectResolve({
type: BROWSER_TYPES.CANCEL
});
}
this.flowDidFinish();
}
});
if (Utils.ios.MajorVersion >= 13) {
const webAuthSession = this.authSession;
webAuthSession.prefersEphemeralWebBrowserSession = inAppBrowserOptions.ephemeralWebSession;
webAuthSession.presentationContextProvider = this;
}
this.authSession.start();
});
safariHackVC.presentationController.delegate = _this;
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, inAppBrowserOptions.animated, null);
}
else {
this.flowDidFinish();
const response = {
type: BROWSER_TYPES.CANCEL,
message: InAppBrowserOpenAuthErrorMessage
};
return Promise.resolve(response);
ctrl.presentViewControllerAnimatedCompletion(_this.safariVC, inAppBrowserOptions.animated, null);
}
}
closeAuth() {
if (Utils.ios.MajorVersion >= 11) {
const authSession = this.authSession;
authSession.cancel();
if (this.redirectResolve) {
this.redirectResolve({
type: BROWSER_TYPES.DISMISS
});
});
};
InAppBrowserModule.prototype.close = function () {
var _this = this;
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController;
ctrl.dismissViewControllerAnimatedCompletion(this.animated, function () {
if (_this.redirectResolve) {
_this.redirectResolve({
type: 'dismiss'
});
_this.flowDidFinish();
}
});
};
InAppBrowserModule.prototype.openAuth = function (authUrl, redirectUrl, options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, Promise, function () {
var inAppBrowserOptions, response;
var _this = this;
return __generator(this, function (_a) {
inAppBrowserOptions = __assign(__assign({}, options), { ephemeralWebSession: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false });
if (Utils.ios.MajorVersion >= 11) {
return [2 /*return*/, new Promise(function (resolve, reject) {
if (!_this.initializeWebBrowser(resolve, reject))
return;
var url = NSURL.URLWithString(authUrl);
var escapedRedirectURL = NSURL.URLWithString(redirectUrl).scheme;
_this.authSession = (Utils.ios.MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession).alloc().initWithURLCallbackURLSchemeCompletionHandler(url, escapedRedirectURL, function (callbackURL, error) {
if (_this.redirectResolve) {
if (!error) {
_this.redirectResolve({
type: BROWSER_TYPES.SUCCESS,
url: callbackURL.absoluteString
});
}
else {
_this.redirectResolve({
type: BROWSER_TYPES.CANCEL
});
}
_this.flowDidFinish();
}
});
if (Utils.ios.MajorVersion >= 13) {
var webAuthSession = _this.authSession;
// Prevent re-use cookie from last auth session
webAuthSession.prefersEphemeralWebBrowserSession = inAppBrowserOptions.ephemeralWebSession;
webAuthSession.presentationContextProvider = _this;
}
_this.authSession.start();
})];
}
else {
this.flowDidFinish();
response = {
type: BROWSER_TYPES.CANCEL,
message: InAppBrowserOpenAuthErrorMessage
};
return [2 /*return*/, Promise.resolve(response)];
}
}
else {
this.close();
}
}
presentationAnchorForWebAuthenticationSession(_) {
return UIApplication.sharedApplication.keyWindow;
}
safariViewControllerDidFinish(controller) {
return [2 /*return*/];
});
});
};
InAppBrowserModule.prototype.closeAuth = function () {
if (Utils.ios.MajorVersion >= 11) {
var authSession = this.authSession;
authSession.cancel();
if (this.redirectResolve) {
this.redirectResolve({
type: BROWSER_TYPES.CANCEL
type: BROWSER_TYPES.DISMISS
});
this.flowDidFinish();
}
this.flowDidFinish();
if (!this.animated) {
dismissWithoutAnimation(controller);
}
}
flowDidFinish() {
this.safariVC = null;
this.redirectResolve = null;
this.redirectReject = null;
else {
this.close();
}
};
InAppBrowserModule.prototype.presentationAnchorForWebAuthenticationSession = function (_) {
return UIApplication.sharedApplication.keyWindow;
};
InAppBrowserModule.prototype.safariViewControllerDidFinish = function (controller) {
if (this.redirectResolve) {
this.redirectResolve({
type: BROWSER_TYPES.CANCEL
});
}
this.flowDidFinish();
if (!this.animated) {
dismissWithoutAnimation(controller);
}
};
InAppBrowserModule.prototype.flowDidFinish = function () {
this.safariVC = null;
this.redirectResolve = null;
this.redirectReject = null;
};
InAppBrowserModule.ObjCProtocols = protocols;
InAppBrowserModule = __decorate([
NativeClass()
], InAppBrowserModule);
return InAppBrowserModule;
}(NSObject));
return InAppBrowserModule.new();

@@ -201,0 +216,0 @@ }

{
"name": "nativescript-inappbrowser",
"version": "3.1.0",
"version": "3.1.1",
"description": "InAppBrowser for NativeScript",

@@ -18,2 +18,3 @@ "main": "InAppBrowser",

"scripts": {
"setup": "npm i && ts-patch install",
"tsc": "npm i && ts-patch install && tsc",

@@ -20,0 +21,0 @@ "build": "npm run tsc && npm run build.native",

@@ -22,2 +22,4 @@ declare namespace android {

setSecondaryToolbarColor(color: number): this;
setNavigationBarColor(color: number): this;
setNavigationBarDividerColor(color: number): this;
addDefaultShareMenuItem(): this;

@@ -55,2 +57,4 @@ enableUrlBarHiding(): this;

setSecondaryToolbarColor(color: number): this;
setNavigationBarColor(color: number): this;
setNavigationBarDividerColor(color: number): this;
addDefaultShareMenuItem(): this;

@@ -57,0 +61,0 @@ enableUrlBarHiding(): this;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc