Add firefox as supported browser to open links.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2018-09-14 11:27:55 +02:00
Родитель c57981217c
Коммит 30ce3e8e7b
13 изменённых файлов: 223 добавлений и 1 удалений

20
ThirdParty/Firefox/OpenInFirefoxControllerObjC.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#import <Foundation/Foundation.h>
// This class is used to check if Firefox is installed in the system and
// to open a URL in Firefox either with or without a callback URL.
@interface OpenInFirefoxControllerObjC : NSObject
// Returns a shared instance of the OpenInFirefoxControllerObjC.
+ (OpenInFirefoxControllerObjC *)sharedInstance;
// Returns YES if Firefox is installed in the user's system.
- (BOOL)isFirefoxInstalled;
// Opens a URL in Firefox.
- (BOOL)openInFirefox:(NSURL *)url;
@end

59
ThirdParty/Firefox/OpenInFirefoxControllerObjC.m поставляемый Normal file
Просмотреть файл

@ -0,0 +1,59 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#import <UIKit/UIKit.h>
#import "OpenInFirefoxControllerObjC.h"
static NSString *const firefoxScheme = @"firefox:";
@implementation OpenInFirefoxControllerObjC
// Creates a shared instance of the controller.
+ (OpenInFirefoxControllerObjC *)sharedInstance {
static OpenInFirefoxControllerObjC *sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
// Custom function that does complete percent escape for constructing the URL.
static NSString *encodeByAddingPercentEscapes(NSString *string) {
NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(CFStringRef)string,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedString;
}
// Checks if Firefox is installed.
- (BOOL)isFirefoxInstalled {
NSURL *url = [NSURL URLWithString:firefoxScheme];
return [[UIApplication sharedApplication] canOpenURL:url];
}
// Opens the URL in Firefox.
- (BOOL)openInFirefox:(NSURL *)url {
if (![self isFirefoxInstalled]) {
return NO;
}
NSString *scheme = [url.scheme lowercaseString];
if (![scheme isEqualToString:@"http"] && ![scheme isEqualToString:@"https"]) {
return NO;
}
NSString *urlString = [url absoluteString];
NSMutableString *firefoxURLString = [NSMutableString string];
[firefoxURLString appendFormat:@"%@//open-url?url=%@", firefoxScheme, encodeByAddingPercentEscapes(urlString)];
NSURL *firefoxURL = [NSURL URLWithString: firefoxURLString];
// Open the URL with Firefox.
return [[UIApplication sharedApplication] openURL:firefoxURL];
}
@end

Просмотреть файл

@ -47,6 +47,7 @@
2C4D7D721F309DA500FF4A0D /* RTCIceCandidate+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D6E1F309DA500FF4A0D /* RTCIceCandidate+JSON.m */; };
2C4D7D731F309DA500FF4A0D /* RTCSessionDescription+JSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D701F309DA500FF4A0D /* RTCSessionDescription+JSON.m */; };
2C4D7D761F30F7B600FF4A0D /* ARDUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D751F30F7B600FF4A0D /* ARDUtilities.m */; };
2C4E758F214B942D003910D5 /* OpenInFirefoxControllerObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4E758E214B942D003910D5 /* OpenInFirefoxControllerObjC.m */; };
2C5435ED1FB1E5E8003D4222 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2C5435EC1FB1E5E8003D4222 /* GoogleService-Info.plist */; };
2C604BD9211988A700D34DCD /* SystemMessageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */; };
2C7381562106136000CDB8DB /* NCChatTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C7381552106136000CDB8DB /* NCChatTitleView.m */; };
@ -207,6 +208,8 @@
2C4D7D701F309DA500FF4A0D /* RTCSessionDescription+JSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RTCSessionDescription+JSON.m"; sourceTree = "<group>"; };
2C4D7D741F30F7B600FF4A0D /* ARDUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARDUtilities.h; sourceTree = "<group>"; };
2C4D7D751F30F7B600FF4A0D /* ARDUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARDUtilities.m; sourceTree = "<group>"; };
2C4E758D214B942D003910D5 /* OpenInFirefoxControllerObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenInFirefoxControllerObjC.h; sourceTree = "<group>"; };
2C4E758E214B942D003910D5 /* OpenInFirefoxControllerObjC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenInFirefoxControllerObjC.m; sourceTree = "<group>"; };
2C5435EC1FB1E5E8003D4222 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
2C604BD7211988A700D34DCD /* SystemMessageTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemMessageTableViewCell.h; sourceTree = "<group>"; };
2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SystemMessageTableViewCell.m; sourceTree = "<group>"; };
@ -493,6 +496,7 @@
2C05749C1EDDA01700D9E7F2 /* ThirdParty */ = {
isa = PBXGroup;
children = (
2C4E758C214B942D003910D5 /* Firefox */,
2C8B5FF01FB4A9DA006E87EF /* openssl */,
2C9219591F58530B008AC1A3 /* UIImageView+Letters */,
2C4D7D601F2F7C2C00FF4A0D /* AppRTC */,
@ -550,6 +554,16 @@
path = ThirdParty/AppRTC;
sourceTree = "<group>";
};
2C4E758C214B942D003910D5 /* Firefox */ = {
isa = PBXGroup;
children = (
2C4E758D214B942D003910D5 /* OpenInFirefoxControllerObjC.h */,
2C4E758E214B942D003910D5 /* OpenInFirefoxControllerObjC.m */,
);
name = Firefox;
path = ThirdParty/Firefox;
sourceTree = "<group>";
};
2C5521661F7D47A50077E587 /* Rooms */ = {
isa = PBXGroup;
children = (
@ -1141,6 +1155,7 @@
2C06330F2046CC8B0043481A /* NCUserInterfaceController.m in Sources */,
2C0574821EDD9E8E00D9E7F2 /* main.m in Sources */,
2CC007B820D8139D0096D91F /* RoomCreationTableViewController.m in Sources */,
2C4E758F214B942D003910D5 /* OpenInFirefoxControllerObjC.m in Sources */,
2CA1CCA41F025F64002FE6A2 /* RoomsTableViewController.m in Sources */,
2C90E5D31EE80C870093D85A /* AuthenticationViewController.m in Sources */,
2C604BD9211988A700D34DCD /* SystemMessageTableViewCell.m in Sources */,

Просмотреть файл

@ -16,6 +16,7 @@
#import <WebRTC/RTCAudioSession.h>
#import <WebRTC/RTCAudioSessionConfiguration.h>
#import "OpenInFirefoxControllerObjC.h"
#import "NCConnectionController.h"
#import "NCPushNotification.h"
#import "NCRoomsManager.h"
@ -67,6 +68,16 @@
configuration.mode = AVAudioSessionModeVideoChat;
[RTCAudioSessionConfiguration setWebRTCConfiguration:configuration];
// Check supported browsers
NSMutableArray *supportedBrowsers = [[NSMutableArray alloc] initWithObjects:@"Safari", nil];
if ([[OpenInFirefoxControllerObjC sharedInstance] isFirefoxInstalled]) {
[supportedBrowsers addObject:@"Firefox"];
}
[NCSettingsController sharedInstance].supportedBrowsers = supportedBrowsers;
if (![supportedBrowsers containsObject:[NCSettingsController sharedInstance].defaultBrowser]) {
[NCSettingsController sharedInstance].defaultBrowser = @"Safari";
}
[NCUserInterfaceController sharedInstance].mainTabBarController = (UITabBarController *) self.window.rootViewController;
//Init rooms manager to start receiving NSNotificationCenter notifications

Просмотреть файл

@ -7,9 +7,14 @@
//
#import "ChatMessageTableViewCell.h"
#import "OpenInFirefoxControllerObjC.h"
#import "SLKUIConstants.h"
#import "UIImageView+AFNetworking.h"
#import "UIImageView+Letters.h"
#import "NCSettingsController.h"
@interface ChatMessageTableViewCell () <UITextViewDelegate>
@end
@implementation ChatMessageTableViewCell
@ -119,6 +124,7 @@
{
if (!_bodyTextView) {
_bodyTextView = [MessageBodyTextView new];
_bodyTextView.delegate = self;
_bodyTextView.font = [UIFont systemFontOfSize:[ChatMessageTableViewCell defaultFontSize]];
}
return _bodyTextView;
@ -141,4 +147,15 @@
return pointSize;
}
#pragma mark - UITextView delegate
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(nonnull NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction
{
if ([[NCSettingsController sharedInstance].defaultBrowser isEqualToString:@"Firefox"] && [[OpenInFirefoxControllerObjC sharedInstance] isFirefoxInstalled]) {
[[OpenInFirefoxControllerObjC sharedInstance] openInFirefox:URL];
return NO;
}
return YES;
}
@end

Просмотреть файл

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "browser-settings.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "browser-settings@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "browser-settings@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Двоичные данные
VideoCalls/Images.xcassets/browser-settings.imageset/browser-settings.png поставляемый Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 848 B

Двоичные данные
VideoCalls/Images.xcassets/browser-settings.imageset/browser-settings@2x.png поставляемый Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.8 KiB

Двоичные данные
VideoCalls/Images.xcassets/browser-settings.imageset/browser-settings@3x.png поставляемый Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.8 KiB

Просмотреть файл

@ -67,5 +67,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>firefox</string>
</array>
</dict>
</plist>

Просмотреть файл

@ -24,6 +24,7 @@ extern NSString * const kNCPNPrivateKey;
extern NSString * const kNCDeviceIdentifier;
extern NSString * const kNCDeviceSignature;
extern NSString * const kNCUserPublicKey;
extern NSString * const kNCUserDefaultBrowser;
extern NSString * const kCapabilityChatV2;
extern NSString * const kCapabilityFavorites;
@ -53,6 +54,8 @@ extern NSString * const NCServerCapabilitiesReceivedNotification;
@property (nonatomic, copy) NSString *ncDeviceSignature;
@property (nonatomic, copy) NSString *ncUserPublicKey;
@property (nonatomic, copy) NSDictionary *ncTalkCapabilities;
@property (nonatomic, copy) NSString *defaultBrowser;
@property (nonatomic, copy) NSMutableArray *supportedBrowsers;
@property (nonatomic, copy) ARDSettingsModel *videoSettingsModel;
+ (instancetype)sharedInstance;

Просмотреть файл

@ -38,6 +38,7 @@ NSString * const kNCPNPrivateKey = @"ncPNPrivateKey";
NSString * const kNCDeviceIdentifier = @"ncDeviceIdentifier";
NSString * const kNCDeviceSignature = @"ncDeviceSignature";
NSString * const kNCUserPublicKey = @"ncUserPublicKey";
NSString * const kNCUserDefaultBrowser = @"ncUserDefaultBrowser";
NSString * const kCapabilityChatV2 = @"chat-v2";
NSString * const kCapabilityFavorites = @"favorites";
@ -85,6 +86,7 @@ NSString * const NCServerCapabilitiesReceivedNotification = @"NCServerCapabiliti
_ncDeviceIdentifier = [_keychain stringForKey:kNCDeviceIdentifier];
_ncDeviceSignature = [_keychain stringForKey:kNCDeviceSignature];
_ncUserPublicKey = [_keychain stringForKey:kNCUserPublicKey];
_defaultBrowser = [_keychain stringForKey:kNCUserDefaultBrowser];
}
- (void)cleanUserAndServerStoredValues
@ -98,6 +100,7 @@ NSString * const NCServerCapabilitiesReceivedNotification = @"NCServerCapabiliti
_ncUserPublicKey = nil;
_ncDeviceIdentifier = nil;
_ncDeviceSignature = nil;
_defaultBrowser = nil;
[_keychain removeItemForKey:kNCServerKey];
[_keychain removeItemForKey:kNCUserKey];
@ -108,6 +111,7 @@ NSString * const NCServerCapabilitiesReceivedNotification = @"NCServerCapabiliti
[_keychain removeItemForKey:kNCDeviceIdentifier];
[_keychain removeItemForKey:kNCDeviceSignature];
[_keychain removeItemForKey:kNCUserPublicKey];
[_keychain removeItemForKey:kNCUserDefaultBrowser];
#warning TODO - Restore NCAPIController in a diferent way
[[NCAPIController sharedInstance] setAuthHeaderWithUser:NULL andToken:NULL];
@ -156,6 +160,12 @@ NSString * const NCServerCapabilitiesReceivedNotification = @"NCServerCapabiliti
if (block) block(nil);
}
- (void)setDefaultBrowser:(NSString *)defaultBrowser
{
_defaultBrowser = defaultBrowser;
[_keychain setString:defaultBrowser forKey:kNCUserDefaultBrowser];
}
#pragma mark - Server Capabilities
- (void)getCapabilitiesWithCompletionBlock:(GetCapabilitiesCompletionBlock)block;

Просмотреть файл

@ -14,6 +14,7 @@
#import "NCAPIController.h"
#import "NCUserInterfaceController.h"
#import "NCConnectionController.h"
#import "OpenInFirefoxControllerObjC.h"
#import "UIImageView+AFNetworking.h"
#import "UIImageView+Letters.h"
#import <SafariServices/SafariServices.h>
@ -27,6 +28,7 @@ typedef enum SettingsSection {
typedef enum ConfigurationSection {
kConfigurationSectionVideo = 0,
kConfigurationSectionBrowser,// Keep it always as last option
kConfigurationSectionNumber
} ConfigurationSection;
@ -232,6 +234,42 @@ typedef enum AboutSection {
[self presentViewController:optionsActionSheet animated:YES completion:nil];
}
- (void)presentBrowserSelector
{
NSIndexPath *browserConfIndexPath = [NSIndexPath indexPathForRow:kConfigurationSectionBrowser inSection:kSettingsSectionConfiguration];
NSArray *supportedBrowsers = [[NCSettingsController sharedInstance] supportedBrowsers];
NSString *defaultBrowser = [[NCSettingsController sharedInstance] defaultBrowser];
UIAlertController *optionsActionSheet =
[UIAlertController alertControllerWithTitle:@"Open links in"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
for (NSString *browser in supportedBrowsers) {
BOOL isDefaultBrowser = [browser isEqualToString:defaultBrowser];
UIAlertAction *action = [UIAlertAction actionWithTitle:browser
style:UIAlertActionStyleDefault
handler:^void (UIAlertAction *action) {
[NCSettingsController sharedInstance].defaultBrowser = browser;
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[browserConfIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}];
if (isDefaultBrowser) {
[action setValue:[[UIImage imageNamed:@"checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
}
[optionsActionSheet addAction:action];
}
[optionsActionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
// Presentation on iPads
optionsActionSheet.popoverPresentationController.sourceView = self.tableView;
optionsActionSheet.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:browserConfIndexPath];
[self presentViewController:optionsActionSheet animated:YES completion:nil];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@ -243,7 +281,10 @@ typedef enum AboutSection {
{
switch (section) {
case kSettingsSectionConfiguration:
return kConfigurationSectionNumber;
{
NSUInteger numberOfSupportedBrowsers = [NCSettingsController sharedInstance].supportedBrowsers.count;
return (numberOfSupportedBrowsers > 1) ? kConfigurationSectionNumber : kConfigurationSectionNumber - 1;
}
break;
case kSettingsSectionAbout:
@ -293,6 +334,7 @@ typedef enum AboutSection {
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
static NSString *videoConfigurationCellIdentifier = @"VideoConfigurationCellIdentifier";
static NSString *browserConfigurationCellIdentifier = @"BrowserConfigurationCellIdentifier";
static NSString *privacyCellIdentifier = @"PrivacyCellIdentifier";
static NSString *sourceCodeCellIdentifier = @"SourceCodeCellIdentifier";
@ -334,6 +376,18 @@ typedef enum AboutSection {
cell.detailTextLabel.text = [[[NCSettingsController sharedInstance] videoSettingsModel] readableResolution:resolution];
}
break;
case kConfigurationSectionBrowser:
{
cell = [tableView dequeueReusableCellWithIdentifier:browserConfigurationCellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:browserConfigurationCellIdentifier];
cell.textLabel.text = @"Open links in";
cell.imageView.contentMode = UIViewContentModeCenter;
[cell.imageView setImage:[UIImage imageNamed:@"browser-settings"]];
}
cell.detailTextLabel.text = [[NCSettingsController sharedInstance] defaultBrowser];
}
break;
}
}
break;
@ -384,6 +438,12 @@ typedef enum AboutSection {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
break;
case kConfigurationSectionBrowser:
{
[self presentBrowserSelector];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
break;
}
}
break;