2016-05-27 05:22:38 +03:00
|
|
|
using System;
|
2016-06-05 00:04:49 +03:00
|
|
|
using Bit.iOS.Core;
|
|
|
|
using Bit.iOS.Extension.Models;
|
2016-05-07 08:54:44 +03:00
|
|
|
using Foundation;
|
2016-05-27 05:22:38 +03:00
|
|
|
using MobileCoreServices;
|
2016-06-02 07:18:47 +03:00
|
|
|
using Newtonsoft.Json;
|
2016-05-07 08:54:44 +03:00
|
|
|
using UIKit;
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
|
|
|
public partial class ActionViewController : UIViewController
|
|
|
|
{
|
2016-06-03 06:28:17 +03:00
|
|
|
public ActionViewController(IntPtr handle) : base(handle)
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
public Context Context { get; set; }
|
2016-05-07 08:54:44 +03:00
|
|
|
|
2016-06-03 06:28:17 +03:00
|
|
|
public override void ViewDidLoad()
|
2016-06-03 03:35:54 +03:00
|
|
|
{
|
2016-06-03 06:28:17 +03:00
|
|
|
base.ViewDidLoad();
|
2016-06-04 19:10:03 +03:00
|
|
|
View.BackgroundColor = UIColor.FromPatternImage(new UIImage("boxed-bg.png"));
|
2016-05-27 05:22:38 +03:00
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
partial void CancelClicked(UIBarButtonItem sender)
|
|
|
|
{
|
|
|
|
CompleteRequest(null);
|
|
|
|
}
|
2016-06-04 22:27:50 +03:00
|
|
|
|
2016-06-04 19:10:03 +03:00
|
|
|
partial void DoneClicked(NSObject sender)
|
|
|
|
{
|
2016-05-31 05:51:53 +03:00
|
|
|
NSDictionary itemData = null;
|
2016-06-05 00:04:49 +03:00
|
|
|
if(Context.ProviderType == UTType.PropertyList)
|
2016-06-03 01:09:25 +03:00
|
|
|
{
|
2016-06-05 00:04:49 +03:00
|
|
|
var fillScript = new FillScript(Context.Details);
|
2016-06-03 01:09:25 +03:00
|
|
|
var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
2016-06-05 00:04:49 +03:00
|
|
|
var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
|
2016-06-03 01:09:25 +03:00
|
|
|
itemData = new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, scriptDict);
|
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
if(Context.ProviderType == Constants.UTTypeAppExtensionFindLoginAction)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
2016-06-05 00:04:49 +03:00
|
|
|
Constants.AppExtensionUsernameKey, "me@example.com",
|
|
|
|
Constants.AppExtensionPasswordKey, "mypassword");
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
else if(Context.ProviderType == Constants.UTTypeAppExtensionFillBrowserAction
|
|
|
|
|| Context.ProviderType == Constants.UTTypeAppExtensionFillWebViewAction)
|
2016-06-02 07:18:47 +03:00
|
|
|
{
|
2016-06-05 00:04:49 +03:00
|
|
|
var fillScript = new FillScript(Context.Details);
|
2016-06-02 07:28:41 +03:00
|
|
|
var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
2016-06-05 00:04:49 +03:00
|
|
|
itemData = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
|
2016-06-02 07:18:47 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
else if(Context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
2016-06-05 00:04:49 +03:00
|
|
|
Constants.AppExtensionUsernameKey, "me@example.com",
|
|
|
|
Constants.AppExtensionPasswordKey, "mypassword");
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
else if(Context.ProviderType == Constants.UTTypeAppExtensionChangePasswordAction)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
|
|
|
itemData = new NSDictionary(
|
2016-06-05 00:04:49 +03:00
|
|
|
Constants.AppExtensionPasswordKey, "mynewpassword",
|
|
|
|
Constants.AppExtensionOldPasswordKey, "myoldpassword");
|
2016-05-30 10:08:12 +03:00
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
CompleteRequest(itemData);
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
2016-05-30 10:08:12 +03:00
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
private void CompleteRequest(NSDictionary itemData)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-05 00:04:49 +03:00
|
|
|
var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
|
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
2016-06-02 07:18:47 +03:00
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
Context.ExtContext.CompleteRequest(returningItems, null);
|
2016-06-02 07:18:47 +03:00
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|