2016-06-05 00:04:49 +03:00
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
using Bit.App.Repositories;
|
|
|
|
using Bit.App.Services;
|
|
|
|
using Bit.iOS.Core.Services;
|
|
|
|
using Foundation;
|
|
|
|
using UIKit;
|
|
|
|
using XLabs.Ioc;
|
|
|
|
using Bit.iOS.Core;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Bit.iOS.Extension.Models;
|
|
|
|
using MobileCoreServices;
|
2016-06-25 08:58:42 +03:00
|
|
|
using Plugin.Settings.Abstractions;
|
2016-07-03 06:53:45 +03:00
|
|
|
using Plugin.Connectivity;
|
2016-07-09 20:11:18 +03:00
|
|
|
using Plugin.Fingerprint;
|
2016-07-22 04:33:27 +03:00
|
|
|
using Bit.iOS.Core.Utilities;
|
|
|
|
using Bit.App.Resources;
|
2016-08-04 07:06:09 +03:00
|
|
|
using Bit.iOS.Core.Controllers;
|
2017-06-01 21:49:48 +03:00
|
|
|
using SimpleInjector;
|
|
|
|
using XLabs.Ioc.SimpleInjectorContainer;
|
2017-09-26 21:38:12 +03:00
|
|
|
using System.Collections.Generic;
|
2016-06-05 00:04:49 +03:00
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
2016-08-04 07:06:09 +03:00
|
|
|
public partial class LoadingViewController : ExtendedUIViewController
|
2016-06-05 00:04:49 +03:00
|
|
|
{
|
|
|
|
private Context _context = new Context();
|
2016-07-23 00:14:57 +03:00
|
|
|
private bool _setupHockeyApp = false;
|
2016-07-27 05:28:02 +03:00
|
|
|
private readonly JsonSerializerSettings _jsonSettings =
|
2016-07-26 04:32:15 +03:00
|
|
|
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
2016-08-04 07:25:10 +03:00
|
|
|
private IGoogleAnalyticsService _googleAnalyticsService;
|
2016-06-05 00:04:49 +03:00
|
|
|
|
|
|
|
public LoadingViewController(IntPtr handle) : base(handle)
|
2016-08-04 07:06:09 +03:00
|
|
|
{ }
|
2016-06-05 00:04:49 +03:00
|
|
|
|
|
|
|
public override void ViewDidLoad()
|
|
|
|
{
|
2016-08-10 03:00:55 +03:00
|
|
|
SetIoc();
|
2016-11-26 18:51:04 +03:00
|
|
|
SetCulture();
|
2016-07-23 00:55:11 +03:00
|
|
|
|
2016-08-04 15:31:42 +03:00
|
|
|
base.ViewDidLoad();
|
|
|
|
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
|
|
|
|
_context.ExtContext = ExtensionContext;
|
|
|
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
|
|
|
|
2016-07-23 00:14:57 +03:00
|
|
|
if(!_setupHockeyApp)
|
|
|
|
{
|
2016-07-28 01:46:55 +03:00
|
|
|
var appIdService = Resolver.Resolve<IAppIdService>();
|
2016-08-09 02:00:36 +03:00
|
|
|
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(appIdService, Resolver.Resolve<IAuthService>());
|
2016-07-23 00:14:57 +03:00
|
|
|
var manager = HockeyApp.iOS.BITHockeyManager.SharedHockeyManager;
|
2016-07-31 00:09:09 +03:00
|
|
|
manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate);
|
2016-07-23 05:56:45 +03:00
|
|
|
manager.CrashManager.CrashManagerStatus = HockeyApp.iOS.BITCrashManagerStatus.AutoSend;
|
2016-07-28 01:46:55 +03:00
|
|
|
manager.UserId = appIdService.AppId;
|
2016-07-23 00:14:57 +03:00
|
|
|
manager.StartManager();
|
|
|
|
manager.Authenticator.AuthenticateInstallation();
|
|
|
|
_setupHockeyApp = true;
|
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
foreach(var item in ExtensionContext.InputItems)
|
|
|
|
{
|
|
|
|
var processed = false;
|
|
|
|
foreach(var itemProvider in item.Attachments)
|
|
|
|
{
|
|
|
|
if(ProcessWebUrlProvider(itemProvider)
|
|
|
|
|| ProcessFindLoginProvider(itemProvider)
|
|
|
|
|| ProcessFindLoginBrowserProvider(itemProvider, Constants.UTTypeAppExtensionFillBrowserAction)
|
|
|
|
|| ProcessFindLoginBrowserProvider(itemProvider, Constants.UTTypeAppExtensionFillWebViewAction)
|
|
|
|
|| ProcessSaveLoginProvider(itemProvider)
|
2016-07-27 05:28:02 +03:00
|
|
|
|| ProcessChangePasswordProvider(itemProvider)
|
|
|
|
|| ProcessExtensionSetupProvider(itemProvider))
|
2016-06-05 00:04:49 +03:00
|
|
|
{
|
|
|
|
processed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(processed)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-06-25 02:24:00 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
|
2016-06-25 02:24:00 +03:00
|
|
|
public override void ViewDidAppear(bool animated)
|
|
|
|
{
|
|
|
|
base.ViewDidAppear(animated);
|
2016-07-22 02:02:04 +03:00
|
|
|
|
2016-07-22 04:33:27 +03:00
|
|
|
var authService = Resolver.Resolve<IAuthService>();
|
|
|
|
if(!authService.IsAuthenticated)
|
|
|
|
{
|
2016-11-26 01:05:14 +03:00
|
|
|
var alert = Dialogs.CreateAlert(null, AppResources.MustLogInMainApp, AppResources.Ok, (a) =>
|
2016-07-22 04:33:27 +03:00
|
|
|
{
|
2016-07-26 04:32:15 +03:00
|
|
|
CompleteRequest(null);
|
2016-07-22 04:33:27 +03:00
|
|
|
});
|
|
|
|
PresentViewController(alert, true, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-28 07:50:35 +03:00
|
|
|
if(_context.ProviderType == Constants.UTTypeAppExtensionSetup)
|
|
|
|
{
|
|
|
|
PerformSegue("setupSegue", this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-22 02:02:04 +03:00
|
|
|
var lockService = Resolver.Resolve<ILockService>();
|
2017-06-02 21:46:10 +03:00
|
|
|
var lockType = lockService.GetLockTypeAsync(false).GetAwaiter().GetResult();
|
2016-07-22 02:02:04 +03:00
|
|
|
switch(lockType)
|
|
|
|
{
|
|
|
|
case App.Enums.LockType.Fingerprint:
|
|
|
|
PerformSegue("lockFingerprintSegue", this);
|
|
|
|
break;
|
|
|
|
case App.Enums.LockType.PIN:
|
|
|
|
PerformSegue("lockPinSegue", this);
|
|
|
|
break;
|
|
|
|
case App.Enums.LockType.Password:
|
|
|
|
PerformSegue("lockPasswordSegue", this);
|
|
|
|
break;
|
|
|
|
default:
|
2016-08-05 07:23:48 +03:00
|
|
|
ContinueOn();
|
2016-07-22 02:02:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
|
|
|
|
{
|
|
|
|
var navController = segue.DestinationViewController as UINavigationController;
|
|
|
|
if(navController != null)
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
var listLoginController = navController.TopViewController as LoginListViewController;
|
|
|
|
var addLoginController = navController.TopViewController as LoginAddViewController;
|
2016-07-22 02:02:04 +03:00
|
|
|
var fingerprintViewController = navController.TopViewController as LockFingerprintViewController;
|
|
|
|
var pinViewController = navController.TopViewController as LockPinViewController;
|
|
|
|
var passwordViewController = navController.TopViewController as LockPasswordViewController;
|
2016-07-27 05:28:02 +03:00
|
|
|
var setupViewController = navController.TopViewController as SetupViewController;
|
2016-07-22 02:02:04 +03:00
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
if(listLoginController != null)
|
2016-07-22 02:02:04 +03:00
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
listLoginController.Context = _context;
|
|
|
|
listLoginController.LoadingController = this;
|
2016-07-22 02:02:04 +03:00
|
|
|
}
|
2017-01-03 08:17:15 +03:00
|
|
|
else if(addLoginController != null)
|
2016-06-05 00:04:49 +03:00
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
addLoginController.Context = _context;
|
|
|
|
addLoginController.LoadingController = this;
|
2016-07-22 02:02:04 +03:00
|
|
|
}
|
|
|
|
else if(fingerprintViewController != null)
|
|
|
|
{
|
|
|
|
fingerprintViewController.Context = _context;
|
2016-07-26 04:32:15 +03:00
|
|
|
fingerprintViewController.LoadingController = this;
|
2016-07-22 02:02:04 +03:00
|
|
|
}
|
|
|
|
else if(pinViewController != null)
|
|
|
|
{
|
|
|
|
pinViewController.Context = _context;
|
2016-07-26 04:32:15 +03:00
|
|
|
pinViewController.LoadingController = this;
|
2016-07-22 02:02:04 +03:00
|
|
|
}
|
|
|
|
else if(passwordViewController != null)
|
|
|
|
{
|
|
|
|
passwordViewController.Context = _context;
|
2016-07-26 04:32:15 +03:00
|
|
|
passwordViewController.LoadingController = this;
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
2016-07-27 05:28:02 +03:00
|
|
|
else if(setupViewController != null)
|
|
|
|
{
|
|
|
|
setupViewController.Context = _context;
|
|
|
|
setupViewController.LoadingController = this;
|
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-22 02:02:04 +03:00
|
|
|
public void DismissLockAndContinue()
|
|
|
|
{
|
2016-07-22 03:59:55 +03:00
|
|
|
Debug.WriteLine("BW Log, Dismissing lock controller.");
|
|
|
|
DismissViewController(false, () =>
|
2016-07-22 02:02:04 +03:00
|
|
|
{
|
2016-08-05 07:23:48 +03:00
|
|
|
ContinueOn();
|
2016-07-22 02:02:04 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-05 07:23:48 +03:00
|
|
|
private void ContinueOn()
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
Debug.WriteLine("BW Log, Segue to setup, login add or list.");
|
2016-08-05 07:23:48 +03:00
|
|
|
if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction)
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
PerformSegue("newLoginSegue", this);
|
2016-08-05 07:23:48 +03:00
|
|
|
}
|
|
|
|
else if(_context.ProviderType == Constants.UTTypeAppExtensionSetup)
|
|
|
|
{
|
|
|
|
PerformSegue("setupSegue", this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
PerformSegue("loginListSegue", this);
|
2016-08-05 07:23:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 21:38:12 +03:00
|
|
|
public void CompleteUsernamePasswordRequest(string username, string password,
|
|
|
|
List<Tuple<string, string>> fields, string totp)
|
2016-07-26 04:32:15 +03:00
|
|
|
{
|
|
|
|
NSDictionary itemData = null;
|
|
|
|
if(_context.ProviderType == UTType.PropertyList)
|
|
|
|
{
|
2017-09-26 21:38:12 +03:00
|
|
|
var fillScript = new FillScript(_context.Details, username, password, fields);
|
2016-07-26 04:32:15 +03:00
|
|
|
var scriptJson = JsonConvert.SerializeObject(fillScript, _jsonSettings);
|
|
|
|
var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
|
|
|
|
itemData = new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, scriptDict);
|
|
|
|
}
|
|
|
|
else if(_context.ProviderType == Constants.UTTypeAppExtensionFindLoginAction)
|
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
|
|
|
Constants.AppExtensionUsernameKey, username,
|
|
|
|
Constants.AppExtensionPasswordKey, password);
|
|
|
|
}
|
|
|
|
else if(_context.ProviderType == Constants.UTTypeAppExtensionFillBrowserAction
|
|
|
|
|| _context.ProviderType == Constants.UTTypeAppExtensionFillWebViewAction)
|
|
|
|
{
|
2017-09-26 21:38:12 +03:00
|
|
|
var fillScript = new FillScript(_context.Details, username, password, fields);
|
2016-07-26 04:32:15 +03:00
|
|
|
var scriptJson = JsonConvert.SerializeObject(fillScript, _jsonSettings);
|
|
|
|
itemData = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
|
|
|
|
}
|
|
|
|
else if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction)
|
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
|
|
|
Constants.AppExtensionUsernameKey, username,
|
|
|
|
Constants.AppExtensionPasswordKey, password);
|
|
|
|
}
|
|
|
|
else if(_context.ProviderType == Constants.UTTypeAppExtensionChangePasswordAction)
|
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
|
|
|
Constants.AppExtensionPasswordKey, string.Empty,
|
|
|
|
Constants.AppExtensionOldPasswordKey, password);
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:39:22 +03:00
|
|
|
if(!string.IsNullOrWhiteSpace(totp))
|
|
|
|
{
|
|
|
|
UIPasteboard.General.String = totp;
|
|
|
|
}
|
|
|
|
|
2016-07-26 04:32:15 +03:00
|
|
|
CompleteRequest(itemData);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CompleteRequest(NSDictionary itemData)
|
|
|
|
{
|
|
|
|
Debug.WriteLine("BW LOG, itemData: " + itemData);
|
|
|
|
|
|
|
|
var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
|
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
|
|
|
|
2016-08-05 02:35:56 +03:00
|
|
|
if(itemData != null)
|
|
|
|
{
|
|
|
|
_googleAnalyticsService.TrackExtensionEvent("AutoFilled", _context.ProviderType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_googleAnalyticsService.TrackExtensionEvent("Closed", _context.ProviderType);
|
|
|
|
}
|
|
|
|
|
|
|
|
_googleAnalyticsService.Dispatch(() =>
|
|
|
|
{
|
2016-08-09 02:00:36 +03:00
|
|
|
NSRunLoop.Main.BeginInvokeOnMainThread(() =>
|
|
|
|
{
|
2016-08-10 03:00:55 +03:00
|
|
|
Resolver.ResetResolver();
|
2017-09-29 05:56:36 +03:00
|
|
|
ExtensionContext?.CompleteRequest(returningItems, null);
|
2016-08-05 02:35:56 +03:00
|
|
|
});
|
|
|
|
});
|
2016-07-26 04:32:15 +03:00
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
private void SetIoc()
|
|
|
|
{
|
2017-06-01 21:49:48 +03:00
|
|
|
var container = new Container();
|
2016-06-05 00:04:49 +03:00
|
|
|
|
2017-06-01 21:49:48 +03:00
|
|
|
// Services
|
|
|
|
container.RegisterSingleton<IDatabaseService, DatabaseService>();
|
|
|
|
container.RegisterSingleton<ISqlService, SqlService>();
|
|
|
|
container.RegisterSingleton<ISecureStorageService, KeyChainStorageService>();
|
|
|
|
container.RegisterSingleton<ICryptoService, CryptoService>();
|
|
|
|
container.RegisterSingleton<IKeyDerivationService, CommonCryptoKeyDerivationService>();
|
|
|
|
container.RegisterSingleton<IAuthService, AuthService>();
|
|
|
|
container.RegisterSingleton<IFolderService, FolderService>();
|
2017-11-25 07:15:25 +03:00
|
|
|
container.RegisterSingleton<ICollectionService, CollectionService>();
|
2017-10-19 03:55:33 +03:00
|
|
|
container.RegisterSingleton<ICipherService, CipherService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<ISyncService, SyncService>();
|
2017-11-30 00:39:43 +03:00
|
|
|
container.RegisterSingleton<IDeviceActionService, NoopDeviceActionService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<IAppIdService, AppIdService>();
|
2017-11-30 00:39:43 +03:00
|
|
|
container.RegisterSingleton<IPasswordGenerationService, PasswordGenerationService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<ILockService, LockService>();
|
2017-11-30 00:39:43 +03:00
|
|
|
container.RegisterSingleton<IAppInfoService, AppInfoService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>();
|
2017-11-30 00:39:43 +03:00
|
|
|
container.RegisterSingleton<IDeviceInfoService, DeviceInfoService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<ILocalizeService, LocalizeService>();
|
|
|
|
container.RegisterSingleton<ILogService, LogService>();
|
|
|
|
container.RegisterSingleton<IHttpService, HttpService>();
|
|
|
|
container.RegisterSingleton<ITokenService, TokenService>();
|
|
|
|
container.RegisterSingleton<ISettingsService, SettingsService>();
|
|
|
|
container.RegisterSingleton<IAppSettingsService, AppSettingsService>();
|
2016-06-05 00:04:49 +03:00
|
|
|
|
2017-06-01 21:49:48 +03:00
|
|
|
// Repositories
|
|
|
|
container.RegisterSingleton<IFolderRepository, FolderRepository>();
|
|
|
|
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
|
2017-10-19 03:55:33 +03:00
|
|
|
container.RegisterSingleton<ICipherRepository, CipherRepository>();
|
2017-07-12 23:23:24 +03:00
|
|
|
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
|
2017-11-30 00:39:43 +03:00
|
|
|
container.RegisterSingleton<IDeviceApiRepository, DeviceApiRepository>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<IAccountsApiRepository, AccountsApiRepository>();
|
2017-07-25 16:52:07 +03:00
|
|
|
container.RegisterSingleton<ICipherApiRepository, CipherApiRepository>();
|
2017-11-30 00:39:43 +03:00
|
|
|
container.RegisterSingleton<ISettingsRepository, SettingsRepository>();
|
|
|
|
container.RegisterSingleton<ISettingsApiRepository, SettingsApiRepository>();
|
|
|
|
container.RegisterSingleton<ITwoFactorApiRepository, TwoFactorApiRepository>();
|
2017-09-20 20:17:05 +03:00
|
|
|
container.RegisterSingleton<ISyncApiRepository, SyncApiRepository>();
|
2017-11-25 00:11:40 +03:00
|
|
|
container.RegisterSingleton<ICollectionRepository, CollectionRepository>();
|
|
|
|
container.RegisterSingleton<ICipherCollectionRepository, CipherCollectionRepository>();
|
2016-06-25 08:58:42 +03:00
|
|
|
|
2017-06-01 21:49:48 +03:00
|
|
|
// Other
|
|
|
|
container.RegisterSingleton(CrossConnectivity.Current);
|
|
|
|
container.RegisterSingleton(CrossFingerprint.Current);
|
|
|
|
|
|
|
|
var settings = new Settings("group.com.8bit.bitwarden");
|
|
|
|
container.RegisterSingleton<ISettings>(settings);
|
|
|
|
|
|
|
|
Resolver.ResetResolver(new SimpleInjectorResolver(container));
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
|
2016-11-26 18:51:04 +03:00
|
|
|
private void SetCulture()
|
|
|
|
{
|
|
|
|
var localizeService = Resolver.Resolve<ILocalizeService>();
|
|
|
|
var ci = localizeService.GetCurrentCultureInfo();
|
|
|
|
AppResources.Culture = ci;
|
|
|
|
localizeService.SetLocale(ci);
|
|
|
|
}
|
|
|
|
|
2017-04-25 00:40:17 +03:00
|
|
|
private bool ProcessItemProvider(NSItemProvider itemProvider, string type, Action<NSDictionary> dictAction,
|
2017-04-25 01:05:23 +03:00
|
|
|
Action<NSUrl> urlAction = null)
|
2016-06-05 00:04:49 +03:00
|
|
|
{
|
|
|
|
if(!itemProvider.HasItemConformingTo(type))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemProvider.LoadItem(type, null, (NSObject list, NSError error) =>
|
|
|
|
{
|
|
|
|
if(list == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_context.ProviderType = type;
|
2017-04-25 00:40:17 +03:00
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
var dict = list as NSDictionary;
|
2017-04-25 00:40:17 +03:00
|
|
|
if(dict != null && dictAction != null)
|
|
|
|
{
|
|
|
|
dictAction(dict);
|
|
|
|
}
|
2017-04-25 05:22:12 +03:00
|
|
|
else if(list is NSUrl && urlAction != null)
|
2017-04-25 00:40:17 +03:00
|
|
|
{
|
2017-04-25 05:22:12 +03:00
|
|
|
var url = list as NSUrl;
|
2017-04-25 01:05:23 +03:00
|
|
|
urlAction(url);
|
2017-04-25 00:40:17 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-30 15:55:54 +03:00
|
|
|
throw new Exception("Cannot parse list for action. List is " +
|
|
|
|
(list?.GetType().ToString() ?? "null"));
|
2017-04-25 00:40:17 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
|
2016-08-05 02:35:56 +03:00
|
|
|
_googleAnalyticsService.TrackExtensionEvent("ProcessItemProvider", type);
|
2016-08-04 07:25:10 +03:00
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
Debug.WriteLine("BW LOG, ProviderType: " + _context.ProviderType);
|
2017-02-09 08:12:09 +03:00
|
|
|
Debug.WriteLine("BW LOG, Url: " + _context.UrlString);
|
2017-01-03 08:17:15 +03:00
|
|
|
Debug.WriteLine("BW LOG, Title: " + _context.LoginTitle);
|
2016-06-05 00:04:49 +03:00
|
|
|
Debug.WriteLine("BW LOG, Username: " + _context.Username);
|
|
|
|
Debug.WriteLine("BW LOG, Password: " + _context.Password);
|
|
|
|
Debug.WriteLine("BW LOG, Old Password: " + _context.OldPassword);
|
|
|
|
Debug.WriteLine("BW LOG, Notes: " + _context.Notes);
|
|
|
|
Debug.WriteLine("BW LOG, Details: " + _context.Details);
|
|
|
|
|
|
|
|
if(_context.PasswordOptions != null)
|
|
|
|
{
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Min Length: " + _context.PasswordOptions.MinLength);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Max Length: " + _context.PasswordOptions.MaxLength);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Require Digits: " + _context.PasswordOptions.RequireDigits);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Require Symbols: " + _context.PasswordOptions.RequireSymbols);
|
|
|
|
Debug.WriteLine("BW LOG, PasswordOptions Forbidden Chars: " + _context.PasswordOptions.ForbiddenCharacters);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessWebUrlProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, UTType.PropertyList, (dict) =>
|
|
|
|
{
|
|
|
|
var result = dict[NSJavaScriptExtension.PreprocessingResultsKey];
|
|
|
|
if(result == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-09 08:12:09 +03:00
|
|
|
_context.UrlString = result.ValueForKey(new NSString(Constants.AppExtensionUrlStringKey)) as NSString;
|
2016-06-05 00:04:49 +03:00
|
|
|
var jsonStr = result.ValueForKey(new NSString(Constants.AppExtensionWebViewPageDetails)) as NSString;
|
|
|
|
_context.Details = DeserializeString<PageDetails>(jsonStr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessFindLoginProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, Constants.UTTypeAppExtensionFindLoginAction, (dict) =>
|
|
|
|
{
|
|
|
|
var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[Constants.AppExtensionUrlStringKey] as NSString;
|
|
|
|
|
|
|
|
if(url != null)
|
|
|
|
{
|
2017-02-09 08:12:09 +03:00
|
|
|
_context.UrlString = url;
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessFindLoginBrowserProvider(NSItemProvider itemProvider, string action)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, action, (dict) =>
|
|
|
|
{
|
|
|
|
var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[Constants.AppExtensionUrlStringKey] as NSString;
|
|
|
|
if(url != null)
|
|
|
|
{
|
2017-02-09 08:12:09 +03:00
|
|
|
_context.UrlString = url;
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_context.Details = DeserializeDictionary<PageDetails>(dict[Constants.AppExtensionWebViewPageDetails] as NSDictionary);
|
2017-04-25 01:05:23 +03:00
|
|
|
}, (url) =>
|
2017-04-25 00:40:17 +03:00
|
|
|
{
|
2017-04-25 01:05:23 +03:00
|
|
|
if(url != null)
|
2017-04-25 00:40:17 +03:00
|
|
|
{
|
2017-04-25 01:05:23 +03:00
|
|
|
_context.UrlString = url.AbsoluteString;
|
2017-04-25 00:40:17 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessSaveLoginProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, Constants.UTTypeAppExtensionSaveLoginAction, (dict) =>
|
|
|
|
{
|
|
|
|
var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[Constants.AppExtensionUrlStringKey] as NSString;
|
|
|
|
var title = dict[Constants.AppExtensionTitleKey] as NSString;
|
|
|
|
var sectionTitle = dict[Constants.AppExtensionSectionTitleKey] as NSString;
|
|
|
|
var username = dict[Constants.AppExtensionUsernameKey] as NSString;
|
|
|
|
var password = dict[Constants.AppExtensionPasswordKey] as NSString;
|
|
|
|
var notes = dict[Constants.AppExtensionNotesKey] as NSString;
|
|
|
|
var fields = dict[Constants.AppExtensionFieldsKey] as NSDictionary;
|
|
|
|
|
|
|
|
if(url != null)
|
|
|
|
{
|
2017-02-09 08:12:09 +03:00
|
|
|
_context.UrlString = url;
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
_context.LoginTitle = title;
|
2016-06-05 00:04:49 +03:00
|
|
|
_context.Username = username;
|
|
|
|
_context.Password = password;
|
|
|
|
_context.Notes = notes;
|
|
|
|
_context.PasswordOptions = DeserializeDictionary<PasswordGenerationOptions>(dict[Constants.AppExtensionPasswordGeneratorOptionsKey] as NSDictionary);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessChangePasswordProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
return ProcessItemProvider(itemProvider, Constants.UTTypeAppExtensionChangePasswordAction, (dict) =>
|
|
|
|
{
|
|
|
|
var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[Constants.AppExtensionUrlStringKey] as NSString;
|
|
|
|
var title = dict[Constants.AppExtensionTitleKey] as NSString;
|
|
|
|
var sectionTitle = dict[Constants.AppExtensionSectionTitleKey] as NSString;
|
|
|
|
var username = dict[Constants.AppExtensionUsernameKey] as NSString;
|
|
|
|
var password = dict[Constants.AppExtensionPasswordKey] as NSString;
|
|
|
|
var oldPassword = dict[Constants.AppExtensionOldPasswordKey] as NSString;
|
|
|
|
var notes = dict[Constants.AppExtensionNotesKey] as NSString;
|
|
|
|
var fields = dict[Constants.AppExtensionFieldsKey] as NSDictionary;
|
|
|
|
|
|
|
|
if(url != null)
|
|
|
|
{
|
2017-02-09 08:12:09 +03:00
|
|
|
_context.UrlString = url;
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
_context.LoginTitle = title;
|
2016-06-05 00:04:49 +03:00
|
|
|
_context.Username = username;
|
|
|
|
_context.Password = password;
|
|
|
|
_context.OldPassword = oldPassword;
|
|
|
|
_context.Notes = notes;
|
|
|
|
_context.PasswordOptions = DeserializeDictionary<PasswordGenerationOptions>(dict[Constants.AppExtensionPasswordGeneratorOptionsKey] as NSDictionary);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-27 05:28:02 +03:00
|
|
|
private bool ProcessExtensionSetupProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
if(itemProvider.HasItemConformingTo(Constants.UTTypeAppExtensionSetup))
|
|
|
|
{
|
|
|
|
_context.ProviderType = Constants.UTTypeAppExtensionSetup;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
private T DeserializeDictionary<T>(NSDictionary dict)
|
|
|
|
{
|
|
|
|
if(dict != null)
|
|
|
|
{
|
|
|
|
NSError jsonError;
|
|
|
|
var jsonData = NSJsonSerialization.Serialize(dict, NSJsonWritingOptions.PrettyPrinted, out jsonError);
|
|
|
|
if(jsonData != null)
|
|
|
|
{
|
|
|
|
var jsonString = new NSString(jsonData, NSStringEncoding.UTF8);
|
|
|
|
return DeserializeString<T>(jsonString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
private T DeserializeString<T>(NSString jsonString)
|
|
|
|
{
|
|
|
|
if(jsonString != null)
|
|
|
|
{
|
|
|
|
var convertedObject = JsonConvert.DeserializeObject<T>(jsonString.ToString());
|
|
|
|
return convertedObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|