move some json dependencies out of extension project

This commit is contained in:
Kyle Spearrin 2019-07-02 14:03:59 -04:00
parent c2c73d5460
commit b308b4c54f
6 changed files with 38 additions and 21 deletions

View File

@ -1,4 +1,5 @@
using Bit.Core.Models.Domain; using Bit.Core.Models.Domain;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -179,5 +180,25 @@ namespace Bit.Core.Utilities
} }
return dict; return dict;
} }
public static string SerializeJson(object obj, bool ignoreNulls = false)
{
var jsonSerializationSettings = new JsonSerializerSettings();
if(ignoreNulls)
{
jsonSerializationSettings.NullValueHandling = NullValueHandling.Ignore;
}
return JsonConvert.SerializeObject(obj, jsonSerializationSettings);
}
public static T DeserializeJson<T>(string json, bool ignoreNulls = false)
{
var jsonSerializationSettings = new JsonSerializerSettings();
if(ignoreNulls)
{
jsonSerializationSettings.NullValueHandling = NullValueHandling.Ignore;
}
return JsonConvert.DeserializeObject<T>(json, jsonSerializationSettings);
}
} }
} }

View File

@ -4,7 +4,7 @@ using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Bit.iOS.Extension.Models namespace Bit.iOS.Core.Models
{ {
public class FillScript public class FillScript
{ {
@ -141,6 +141,17 @@ namespace Bit.iOS.Extension.Models
SetFillScriptForFocus(filledFields); SetFillScriptForFocus(filledFields);
} }
[JsonProperty(PropertyName = "script")]
public List<List<string>> Script { get; set; } = new List<List<string>>();
[JsonProperty(PropertyName = "documentUUID")]
public object DocumentUUID { get; set; }
[JsonProperty(PropertyName = "properties")]
public object Properties { get; set; } = new object();
[JsonProperty(PropertyName = "options")]
public object Options { get; set; } = new { animate = false };
[JsonProperty(PropertyName = "metadata")]
public object MetaData { get; set; } = new object();
private PageDetails.Field FindUsernameField(PageDetails pageDetails, PageDetails.Field passwordField, bool canBeHidden, private PageDetails.Field FindUsernameField(PageDetails pageDetails, PageDetails.Field passwordField, bool canBeHidden,
bool checkForm) bool checkForm)
{ {
@ -261,16 +272,5 @@ namespace Bit.iOS.Extension.Models
{ {
return Regex.Replace(label, @"(?:\r\n|\r|\n)", string.Empty).Trim().ToLower(); return Regex.Replace(label, @"(?:\r\n|\r|\n)", string.Empty).Trim().ToLower();
} }
[JsonProperty(PropertyName = "script")]
public List<List<string>> Script { get; set; } = new List<List<string>>();
[JsonProperty(PropertyName = "documentUUID")]
public object DocumentUUID { get; set; }
[JsonProperty(PropertyName = "properties")]
public object Properties { get; set; } = new object();
[JsonProperty(PropertyName = "options")]
public object Options { get; set; } = new { animate = false };
[JsonProperty(PropertyName = "metadata")]
public object MetaData { get; set; } = new object();
} }
} }

View File

@ -1,9 +1,8 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Bit.iOS.Extension.Models namespace Bit.iOS.Core.Models
{ {
public class PageDetails public class PageDetails
{ {
@ -48,5 +47,4 @@ namespace Bit.iOS.Extension.Models
public string Form { get; set; } public string Form { get; set; }
} }
} }
} }

View File

@ -63,6 +63,8 @@
<Compile Include="Controllers\PasswordGeneratorViewController.cs" /> <Compile Include="Controllers\PasswordGeneratorViewController.cs" />
<Compile Include="Models\AppExtensionContext.cs" /> <Compile Include="Models\AppExtensionContext.cs" />
<Compile Include="Models\CipherViewModel.cs" /> <Compile Include="Models\CipherViewModel.cs" />
<Compile Include="Models\FillScript.cs" />
<Compile Include="Models\PageDetails.cs" />
<Compile Include="Models\PasswordGenerationOptions.cs" /> <Compile Include="Models\PasswordGenerationOptions.cs" />
<Compile Include="Services\DeviceActionService.cs" /> <Compile Include="Services\DeviceActionService.cs" />
<Compile Include="Utilities\ASHelpers.cs" /> <Compile Include="Utilities\ASHelpers.cs" />

View File

@ -19,8 +19,6 @@ namespace Bit.iOS.Extension
public partial class LoadingViewController : ExtendedUIViewController public partial class LoadingViewController : ExtendedUIViewController
{ {
private Context _context = new Context(); private Context _context = new Context();
private readonly JsonSerializerSettings _jsonSettings =
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
public LoadingViewController(IntPtr handle) public LoadingViewController(IntPtr handle)
: base(handle) : base(handle)
@ -140,7 +138,7 @@ namespace Bit.iOS.Extension
if(_context.ProviderType == UTType.PropertyList) if(_context.ProviderType == UTType.PropertyList)
{ {
var fillScript = new FillScript(_context.Details, username, password, fields); var fillScript = new FillScript(_context.Details, username, password, fields);
var scriptJson = JsonConvert.SerializeObject(fillScript, _jsonSettings); var scriptJson = CoreHelpers.SerializeJson(fillScript, true);
var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson); var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
itemData = new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, scriptDict); itemData = new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, scriptDict);
} }
@ -154,7 +152,7 @@ namespace Bit.iOS.Extension
|| _context.ProviderType == Constants.UTTypeAppExtensionFillWebViewAction) || _context.ProviderType == Constants.UTTypeAppExtensionFillWebViewAction)
{ {
var fillScript = new FillScript(_context.Details, username, password, fields); var fillScript = new FillScript(_context.Details, username, password, fields);
var scriptJson = JsonConvert.SerializeObject(fillScript, _jsonSettings); var scriptJson = CoreHelpers.SerializeJson(fillScript, true);
itemData = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson); itemData = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
} }
else if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction) else if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction)

View File

@ -89,8 +89,6 @@
<None Include="Info.plist" /> <None Include="Info.plist" />
<None Include="Entitlements.plist" /> <None Include="Entitlements.plist" />
<Compile Include="Models\Context.cs" /> <Compile Include="Models\Context.cs" />
<Compile Include="Models\FillScript.cs" />
<Compile Include="Models\PageDetails.cs" />
<Compile Include="PasswordGeneratorViewController.cs" /> <Compile Include="PasswordGeneratorViewController.cs" />
<Compile Include="PasswordGeneratorViewController.designer.cs"> <Compile Include="PasswordGeneratorViewController.designer.cs">
<DependentUpon>PasswordGeneratorViewController.cs</DependentUpon> <DependentUpon>PasswordGeneratorViewController.cs</DependentUpon>