From 10b205c541291aa2a90486019e0d627ee6afdcfa Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 25 Apr 2020 11:44:27 -0400 Subject: [PATCH] Open URLs in external browser. --- .../Source/iOS/MPWebViewController.m | 37 ++++++++++++++++++- .../Source/iOS/MasterPassword-Info.plist | 6 +++ .../Source/iOS/Storyboard.storyboard | 5 ++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/platform-darwin/Source/iOS/MPWebViewController.m b/platform-darwin/Source/iOS/MPWebViewController.m index 7d0a41a4..0e92d8a7 100644 --- a/platform-darwin/Source/iOS/MPWebViewController.m +++ b/platform-darwin/Source/iOS/MPWebViewController.m @@ -76,8 +76,8 @@ wrn( @"Couldn't synchronize thanks tip." ); } - [self.webNavigationItem setLeftBarButtonItem:[webView canGoBack]? [[UIBarButtonItem alloc] - initWithTitle:@"⬅︎" style:UIBarButtonItemStylePlain target:webView action:@selector( goBack )]: nil]; + [self.webNavigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] + initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(openURL:)]]; [webView evaluateJavaScript:@"document.title" completionHandler:^(id o, NSError *error) { self.webNavigationItem.prompt = [o description]; }]; @@ -85,6 +85,39 @@ #pragma mark - Actions +- (IBAction)openURL:(id)sender { + + UIAlertController *controller = [UIAlertController new]; + controller.title = self.webView.URL.host; + controller.message = self.webView.URL.absoluteString; + [controller addAction:[UIAlertAction actionWithTitle:@"Safari" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [UIApp openURL:self.webView.URL]; + }]]; + if ([UIApp canOpenURL:[NSURL URLWithString:@"firefox:"]]) { + [controller addAction:[UIAlertAction actionWithTitle:@"Firefox" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [UIApp openURL:[NSURL URLWithString:strf( @"firefox://open-url?url=%@", + [self.webView.URL.absoluteString stringByAddingPercentEncodingWithAllowedCharacters: + [NSCharacterSet URLQueryAllowedCharacterSet]] )]]; + }]]; + } + if ([UIApp canOpenURL:[NSURL URLWithString:@"googlechrome:"]]) { + NSURL *url = [[NSURL alloc] initWithScheme:[self.webView.URL.scheme isEqualToString:@"http"]? @"googlechrome": @"googlechromes" + host:self.webView.URL.host path:self.webView.URL.path]; + [controller addAction:[UIAlertAction actionWithTitle:@"Chrome" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [UIApp openURL:url]; + }]]; + } + if ([UIApp canOpenURL:[NSURL URLWithString:@"opera-http:"]]) { + NSURL *url = [[NSURL alloc] initWithScheme:[self.webView.URL.scheme isEqualToString:@"http"]? @"opera-http": @"opera-https" + host:self.webView.URL.host path:self.webView.URL.path]; + [controller addAction:[UIAlertAction actionWithTitle:@"Opera" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [UIApp openURL:url]; + }]]; + } + [controller addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; + [self presentViewController:controller animated:YES completion:nil]; +} + - (IBAction)done:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; diff --git a/platform-darwin/Source/iOS/MasterPassword-Info.plist b/platform-darwin/Source/iOS/MasterPassword-Info.plist index 3db0771f..e63bf3c4 100644 --- a/platform-darwin/Source/iOS/MasterPassword-Info.plist +++ b/platform-darwin/Source/iOS/MasterPassword-Info.plist @@ -39,6 +39,12 @@ [auto] CFBundleVersion [auto] + LSApplicationQueriesSchemes + + firefox + googlechrome + opera-http + LSRequiresIPhoneOS LSSupportsOpeningDocumentsInPlace diff --git a/platform-darwin/Source/iOS/Storyboard.storyboard b/platform-darwin/Source/iOS/Storyboard.storyboard index a01415bb..3ec8ed4c 100644 --- a/platform-darwin/Source/iOS/Storyboard.storyboard +++ b/platform-darwin/Source/iOS/Storyboard.storyboard @@ -69,7 +69,7 @@ - + @@ -476,6 +476,7 @@ + @@ -3257,7 +3258,7 @@ Ut in geometria, prima si dederis, danda sunt omnia. Nonne igitur tibi videntur, - +