2016-05-27 05:22:38 +03:00
|
|
|
using System;
|
2016-05-28 23:06:53 +03:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
using Bit.App.Repositories;
|
|
|
|
using Bit.App.Services;
|
|
|
|
using Bit.iOS.Core.Services;
|
2016-05-27 05:22:38 +03:00
|
|
|
using CoreGraphics;
|
2016-05-07 08:54:44 +03:00
|
|
|
using Foundation;
|
2016-05-28 23:06:53 +03:00
|
|
|
using Microsoft.Practices.Unity;
|
2016-05-27 05:22:38 +03:00
|
|
|
using MobileCoreServices;
|
2016-05-07 08:54:44 +03:00
|
|
|
using UIKit;
|
2016-05-28 23:06:53 +03:00
|
|
|
using XLabs.Ioc;
|
|
|
|
using XLabs.Ioc.Unity;
|
2016-05-07 08:54:44 +03:00
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
|
|
|
public partial class ActionViewController : UIViewController
|
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
private const string AppExtensionVersionNumberKey = "version_number";
|
|
|
|
private const string AppExtensionUrlStringKey = "url_string";
|
|
|
|
private const string UTTypeAppExtensionFindLoginAction = "org.appextension.find-login-action";
|
|
|
|
private const string UTTypeAppExtensionSaveLoginAction = "org.appextension.save-login-action";
|
|
|
|
private const string UTTypeAppExtensionChangePasswordAction = "org.appextension.change-password-action";
|
|
|
|
private const string UTTypeAppExtensionFillWebViewAction = "org.appextension.fill-webview-action";
|
|
|
|
private const string UTTypeAppExtensionFillBrowserAction = "org.appextension.fill-browser-action";
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
public ActionViewController() : base("ActionViewController", null)
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
2016-05-28 23:06:53 +03:00
|
|
|
if(!Resolver.IsSet)
|
|
|
|
{
|
|
|
|
SetIoc();
|
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
public string HtmlContent { get; set; }
|
|
|
|
public Uri BaseUri { get; set; }
|
|
|
|
public Uri Url { get; set; }
|
2016-05-07 08:54:44 +03:00
|
|
|
|
2016-05-28 23:06:53 +03:00
|
|
|
private void SetIoc()
|
|
|
|
{
|
|
|
|
var container = new UnityContainer();
|
|
|
|
|
|
|
|
container
|
|
|
|
// Services
|
|
|
|
.RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterType<ISecureStorageService, KeyChainStorageService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
|
|
|
|
// Repositories
|
|
|
|
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISiteRepository, SiteRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<ISiteApiRepository, SiteApiRepository>(new ContainerControlledLifetimeManager())
|
|
|
|
.RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager());
|
2016-05-30 10:08:12 +03:00
|
|
|
// Other
|
|
|
|
//.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
|
|
|
|
//.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
|
2016-05-28 23:06:53 +03:00
|
|
|
|
|
|
|
Resolver.SetResolver(new UnityResolver(container));
|
|
|
|
}
|
|
|
|
|
2016-05-07 08:54:44 +03:00
|
|
|
public override void DidReceiveMemoryWarning()
|
|
|
|
{
|
|
|
|
base.DidReceiveMemoryWarning();
|
|
|
|
}
|
|
|
|
|
2016-05-28 23:06:53 +03:00
|
|
|
public async override void LoadView()
|
2016-05-27 05:22:38 +03:00
|
|
|
{
|
|
|
|
View = new UIView(new CGRect(x: 0.0, y: 0, width: 320.0, height: 200.0));
|
|
|
|
var button = new UIButton(new CGRect(x: 10.0, y: 50.0, width: 200.0, height: 30.0));
|
|
|
|
button.SetTitle("Done", UIControlState.Normal);
|
|
|
|
button.TouchUpInside += Button_TouchUpInside;
|
|
|
|
View.AddSubview(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Button_TouchUpInside(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var itemData = new NSDictionary(
|
2016-05-28 07:59:36 +03:00
|
|
|
"username", "me@example.com",
|
|
|
|
"password", "mypassword",
|
|
|
|
"autoSubmit", true);
|
2016-05-27 05:22:38 +03:00
|
|
|
|
|
|
|
var resultsProvider = new NSItemProvider(
|
2016-05-28 07:59:36 +03:00
|
|
|
new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, itemData), UTType.PropertyList);
|
2016-05-27 05:22:38 +03:00
|
|
|
|
2016-05-28 07:59:36 +03:00
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
2016-05-27 05:22:38 +03:00
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
2016-05-28 07:59:36 +03:00
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
ExtensionContext.CompleteRequest(returningItems, null);
|
|
|
|
}
|
|
|
|
|
2016-05-07 08:54:44 +03:00
|
|
|
public override void ViewDidLoad()
|
|
|
|
{
|
|
|
|
base.ViewDidLoad();
|
|
|
|
|
|
|
|
foreach(var item in ExtensionContext.InputItems)
|
|
|
|
{
|
|
|
|
foreach(var itemProvider in item.Attachments)
|
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
if(ProcessWebUrlProvider(itemProvider))
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
break;
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
2016-05-30 10:08:12 +03:00
|
|
|
else if(ProcessFindLoginProvider(itemProvider))
|
2016-05-25 07:09:11 +03:00
|
|
|
{
|
2016-05-30 10:08:12 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 10:08:12 +03:00
|
|
|
private bool ProcessWebUrlProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
if(!itemProvider.HasItemConformingTo(UTType.PropertyList))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemProvider.LoadItem(UTType.PropertyList, null, (NSObject list, NSError error) =>
|
|
|
|
{
|
|
|
|
if(list == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dict = list as NSDictionary;
|
|
|
|
var result = dict[NSJavaScriptExtension.PreprocessingResultsKey];
|
|
|
|
if(result == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HtmlContent = result.ValueForKey(new NSString("htmlContent")) as NSString;
|
|
|
|
BaseUri = new Uri(result.ValueForKey(new NSString("baseUri")) as NSString);
|
|
|
|
Url = new Uri(result.ValueForKey(new NSString("url")) as NSString);
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool ProcessFindLoginProvider(NSItemProvider itemProvider)
|
|
|
|
{
|
|
|
|
if(!itemProvider.HasItemConformingTo(UTTypeAppExtensionFindLoginAction))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemProvider.LoadItem(UTTypeAppExtensionFindLoginAction, null, (NSObject list, NSError error) =>
|
|
|
|
{
|
|
|
|
if(list == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dict = list as NSDictionary;
|
|
|
|
var version = dict[AppExtensionVersionNumberKey] as NSNumber;
|
|
|
|
var url = dict[AppExtensionUrlStringKey] as NSString;
|
|
|
|
if(url == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Url = new Uri(url);
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
2016-05-27 05:22:38 +03:00
|
|
|
}
|