integrating ios extension with onepassword-app-extension

This commit is contained in:
Kyle Spearrin 2016-05-30 03:08:12 -04:00
parent 48db0e8d13
commit 72c1a987c9
4 changed files with 109 additions and 43 deletions

View file

@ -17,6 +17,14 @@ namespace Bit.iOS.Extension
{
public partial class ActionViewController : UIViewController
{
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";
public ActionViewController() : base("ActionViewController", null)
{
if(!Resolver.IsSet)
@ -50,11 +58,11 @@ namespace Bit.iOS.Extension
.RegisterType<ISiteRepository, SiteRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ISiteApiRepository, SiteApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager());
// Other
//.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
//.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
//.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
//.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
// Other
//.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
//.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
//.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
//.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
Resolver.SetResolver(new UnityResolver(container));
}
@ -97,34 +105,73 @@ namespace Bit.iOS.Extension
{
foreach(var itemProvider in item.Attachments)
{
if(!itemProvider.HasItemConformingTo(UTType.PropertyList))
if(ProcessWebUrlProvider(itemProvider))
{
continue;
break;
}
itemProvider.LoadItem(UTType.PropertyList, null, (NSObject list, NSError error) =>
else if(ProcessFindLoginProvider(itemProvider))
{
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);
});
break;
break;
}
}
}
}
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;
}
}
}

View file

@ -29,18 +29,20 @@
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>extension</string>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsText</key>
<false/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<string>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.find-login-action"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.save-login-action"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.change-password-action"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.fill-webview-action"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.fill-browser-action"
).@count == $extensionItem.attachments.@count
).@count == 1</string>
<key>NSExtensionPointName</key>
<string>com.apple.ui-services</string>
<key>NSExtensionPointVersion</key>

View file

@ -107,6 +107,11 @@ namespace Bit.iOS
Debug.WriteLine("WillEnterForeground");
}
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
return true;
}
private void SendLockMessage()
{
MessagingCenter.Send(Xamarin.Forms.Application.Current, "Lock", false);

View file

@ -22,7 +22,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>9.3</string>
<string>9.0</string>
<key>CFBundleDisplayName</key>
<string>bitwarden</string>
<key>CFBundleIdentifier</key>
@ -57,8 +57,20 @@
<key>UIMainStoryboardFile~ipad</key>
<string>LaunchScreen</string>
<key>UIStatusBarStyle</key>
+ <string>UIStatusBarStyleLightContent</string>
+ <key>UIViewControllerBasedStatusBarAppearance</key>
+ <false/>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>bitwarden</string>
<string>org-appextension-feature-password-management</string>
</array>
<key>CFBundleURLName</key>
<string>com.bitwarden.vault.url</string>
</dict>
</array>
</dict>
</plist>