2017-04-05 20:56:22 +00:00
|
|
|
//==============================================================================
|
|
|
|
// This file is part of Master Password.
|
|
|
|
// Copyright (c) 2011-2017, Maarten Billemont.
|
2014-05-10 13:18:46 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// Master Password is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2014-05-10 13:18:46 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// Master Password is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2014-05-10 13:18:46 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// You can find a copy of the GNU General Public License in the
|
|
|
|
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
|
|
|
|
//==============================================================================
|
2014-05-10 13:18:46 +00:00
|
|
|
|
|
|
|
#import "MPWebViewController.h"
|
|
|
|
|
|
|
|
@implementation MPWebViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
if (!self.initialURL)
|
2018-06-03 20:26:08 +00:00
|
|
|
self.initialURL = [NSURL URLWithString:@"https://masterpassword.app"];
|
2014-06-04 01:04:22 +00:00
|
|
|
self.webNavigationItem.title = self.initialURL.host;
|
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
// WKWebView can't be on the storyboard for iOS pre 11 due to an NSCoding bug.
|
|
|
|
[self.view insertSubview:self.webView = [WKWebView new] atIndex:0];
|
|
|
|
[self.webView setNavigationDelegate:self];
|
|
|
|
[self.webView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
|
|
|
[self.webView.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES;
|
|
|
|
[self.webView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
|
|
|
|
[self.webView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
|
|
|
|
[self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
|
|
|
|
|
2014-05-10 13:18:46 +00:00
|
|
|
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:self.initialURL]];
|
|
|
|
}
|
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
[super viewWillAppear:animated];
|
2014-05-10 13:18:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
- (void)viewDidLayoutSubviews {
|
|
|
|
[self.webView.scrollView insetOcclusion];
|
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
}
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle {
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
return UIStatusBarStyleLightContent;
|
|
|
|
}
|
2014-09-29 02:25:48 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
#pragma mark - WKNavigationDelegate
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
self.webNavigationItem.title = webView.URL.host;
|
|
|
|
self.webNavigationItem.prompt = strl( @"Loading" );
|
2014-05-10 13:18:46 +00:00
|
|
|
|
|
|
|
UIActivityIndicatorView *activityView =
|
|
|
|
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
|
|
|
|
[self.webNavigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:activityView]];
|
|
|
|
[activityView startAnimating];
|
|
|
|
}
|
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 14:44:59 +00:00
|
|
|
if ([[webView.URL absoluteString] rangeOfString:@"thanks.lhunath.com"].location != NSNotFound) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"tipped.thanks"];
|
|
|
|
if (![[NSUserDefaults standardUserDefaults] synchronize])
|
|
|
|
wrn( @"Couldn't synchronize thanks tip." );
|
|
|
|
}
|
2014-05-10 13:18:46 +00:00
|
|
|
|
2020-04-25 15:44:27 +00:00
|
|
|
[self.webNavigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc]
|
|
|
|
initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(openURL:)]];
|
2020-04-25 14:44:59 +00:00
|
|
|
[webView evaluateJavaScript:@"document.title" completionHandler:^(id o, NSError *error) {
|
|
|
|
self.webNavigationItem.prompt = [o description];
|
|
|
|
}];
|
2014-05-10 13:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
2020-04-25 15:44:27 +00:00
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
|
2014-05-10 13:18:46 +00:00
|
|
|
- (IBAction)done:(id)sender {
|
|
|
|
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|