diff options
| author | Kumar Priyansh <[email protected]> | 2020-01-03 18:34:23 +0530 |
|---|---|---|
| committer | Kumar Priyansh <[email protected]> | 2020-01-03 18:34:23 +0530 |
| commit | c3373becc9a1393b2e03c8cd6c154601481a60dd (patch) | |
| tree | a8a31f613aef864d8d481ed57dc2c97490dfd328 /CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m | |
| parent | 2917c8eda330a126b530dd83573670cbc98a4206 (diff) | |
| download | WeatherApp-c3373becc9a1393b2e03c8cd6c154601481a60dd.tar.xz WeatherApp-c3373becc9a1393b2e03c8cd6c154601481a60dd.zip | |
Rewriting the app from scratch with Swift 5
Diffstat (limited to 'CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m')
| -rw-r--r-- | CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m deleted file mode 100644 index bc56fdd..0000000 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m +++ /dev/null @@ -1,153 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVUIWebViewNavigationDelegate.h" -#import <Cordova/CDVViewController.h> -#import <Cordova/CDVCommandDelegateImpl.h> -#import <Cordova/CDVUserAgentUtil.h> -#import <objc/message.h> - -@implementation CDVUIWebViewNavigationDelegate - -- (instancetype)initWithEnginePlugin:(CDVPlugin*)theEnginePlugin -{ - self = [super init]; - if (self) { - self.enginePlugin = theEnginePlugin; - } - - return self; -} - -/** - When web application loads Add stuff to the DOM, mainly the user-defined settings from the Settings.plist file, and - the device's data such as device ID, platform version, etc. - */ -- (void)webViewDidStartLoad:(UIWebView*)theWebView -{ - NSLog(@"Resetting plugins due to page load."); - CDVViewController* vc = (CDVViewController*)self.enginePlugin.viewController; - - [vc.commandQueue resetRequestId]; - [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginResetNotification object:self.enginePlugin.webView]]; -} - -/** - Called when the webview finishes loading. This stops the activity view. - */ -- (void)webViewDidFinishLoad:(UIWebView*)theWebView -{ - NSLog(@"Finished load of: %@", theWebView.request.URL); - CDVViewController* vc = (CDVViewController*)self.enginePlugin.viewController; - - // It's safe to release the lock even if this is just a sub-frame that's finished loading. - [CDVUserAgentUtil releaseLock:vc.userAgentLockToken]; - - /* - * Hide the Top Activity THROBBER in the Battery Bar - */ - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; - - [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPageDidLoadNotification object:self.enginePlugin.webView]]; -} - -- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error -{ - CDVViewController* vc = (CDVViewController*)self.enginePlugin.viewController; - - [CDVUserAgentUtil releaseLock:vc.userAgentLockToken]; - - NSString* message = [NSString stringWithFormat:@"Failed to load webpage with error: %@", [error localizedDescription]]; - NSLog(@"%@", message); - - NSURL* errorUrl = vc.errorURL; - if (errorUrl) { - errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [message stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathAllowedCharacterSet]] relativeToURL:errorUrl]; - NSLog(@"%@", [errorUrl absoluteString]); - if(error.code != NSURLErrorCancelled) { - [theWebView loadRequest:[NSURLRequest requestWithURL:errorUrl]]; - } - } -} - -- (BOOL)defaultResourcePolicyForURL:(NSURL*)url -{ - /* - * If a URL is being loaded that's a file url, just load it internally - */ - if ([url isFileURL]) { - return YES; - } - - return NO; -} - -- (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType -{ - NSURL* url = [request URL]; - CDVViewController* vc = (CDVViewController*)self.enginePlugin.viewController; - - /* - * Execute any commands queued with cordova.exec() on the JS side. - * The part of the URL after gap:// is irrelevant. - */ - if ([[url scheme] isEqualToString:@"gap"]) { - [vc.commandQueue fetchCommandsFromJs]; - // The delegate is called asynchronously in this case, so we don't have to use - // flushCommandQueueWithDelayedJs (setTimeout(0)) as we do with hash changes. - [vc.commandQueue executePending]; - return NO; - } - - /* - * Give plugins the chance to handle the url - */ - BOOL anyPluginsResponded = NO; - BOOL shouldAllowRequest = NO; - - for (NSString* pluginName in vc.pluginObjects) { - CDVPlugin* plugin = [vc.pluginObjects objectForKey:pluginName]; - SEL selector = NSSelectorFromString(@"shouldOverrideLoadWithRequest:navigationType:"); - if ([plugin respondsToSelector:selector]) { - anyPluginsResponded = YES; - shouldAllowRequest = (((BOOL (*)(id, SEL, id, int))objc_msgSend)(plugin, selector, request, navigationType)); - if (!shouldAllowRequest) { - break; - } - } - } - - if (anyPluginsResponded) { - return shouldAllowRequest; - } - - /* - * Handle all other types of urls (tel:, sms:), and requests to load a url in the main webview. - */ - BOOL shouldAllowNavigation = [self defaultResourcePolicyForURL:url]; - if (shouldAllowNavigation) { - return YES; - } else { - [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; - } - - return NO; -} - -@end |
