You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by tr...@apache.org on 2017/09/27 05:20:34 UTC
mac commit: CB-13304: expose preference to control WebView navigation
Repository: cordova-osx
Updated Branches:
refs/heads/master 986621fde -> 5b8c0b577
CB-13304: expose preference to control WebView navigation
This closes #42
Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/5b8c0b57
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/5b8c0b57
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/5b8c0b57
Branch: refs/heads/master
Commit: 5b8c0b577956fcc8cc830a4f2eb7885e9be969da
Parents: 986621f
Author: alberto lalama <al...@users.noreply.github.com>
Authored: Thu Sep 21 15:24:40 2017 -0400
Committer: Tobias Bocanegra <tr...@adobe.com>
Committed: Wed Sep 27 11:28:14 2017 +1000
----------------------------------------------------------------------
CordovaLib/CordovaLib/Classes/CDVViewController.m | 9 +++++++++
CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h | 1 +
CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m | 10 ++++++++--
bin/templates/scripts/cordova/defaults.xml | 1 +
4 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5b8c0b57/CordovaLib/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.m b/CordovaLib/CordovaLib/Classes/CDVViewController.m
index 4631b9c..c310403 100644
--- a/CordovaLib/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/CordovaLib/Classes/CDVViewController.m
@@ -88,6 +88,7 @@
WebPreferences* prefs = [self.webView preferences];
[prefs setAutosaves:YES];
+ [self configureWebViewDelegate];
[self configureWebDefaults:prefs];
[self configureLocalStorage:prefs];
[self configureWindowSize];
@@ -165,6 +166,14 @@
self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:20];
}
+- (void)configureWebViewDelegate {
+ NSString *allowWebViewNavigation = [self.settings objectForKey:@"AllowWebViewNavigation"];
+ if (allowWebViewNavigation == nil) {
+ allowWebViewNavigation = @"true"; // Default to true for backwards compatibility.
+ }
+ self.webViewDelegate.allowWebViewNavigation = [allowWebViewNavigation boolValue];
+}
+
/**
* Configures the default web preferences
*/
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5b8c0b57/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h
index 41f7aeb..9e76690 100644
--- a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h
+++ b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h
@@ -30,6 +30,7 @@
@interface CDVWebViewDelegate : NSObject {
}
+@property (nonatomic) BOOL allowWebViewNavigation;
@property (nonatomic, strong) CDVConsole* console;
@property (nonatomic, strong) CDVBridge* bridge;
@property (nonatomic,
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5b8c0b57/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m
index a234e1c..ec99200 100644
--- a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m
+++ b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m
@@ -83,9 +83,15 @@
#pragma mark WebPolicyDelegate
- (void) webView:(WebView*) sender decidePolicyForNavigationAction:(NSDictionary*) actionInformation request:(NSURLRequest*) request frame:(WebFrame*) frame decisionListener:(id <WebPolicyDecisionListener>) listener {
- NSString* url = [[request URL] description];
- NSLog(@"navigating to %@", url);
+ NSURL *url = [request URL];
+ NSLog(@"navigating to %@", url.description);
+ if (self.allowWebViewNavigation || [@"file" isEqualToString:url.scheme]) {
+ // Open in-app if navigation is allowed in the WebView, or if this is a local file request.
[listener use];
+ } else {
+ // Forward external requests to the system otherwise.
+ [[NSWorkspace sharedWorkspace] openURL:url];
+ }
}
#pragma mark WebViewDelegate
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5b8c0b57/bin/templates/scripts/cordova/defaults.xml
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/defaults.xml b/bin/templates/scripts/cordova/defaults.xml
index e28a539..8439080 100644
--- a/bin/templates/scripts/cordova/defaults.xml
+++ b/bin/templates/scripts/cordova/defaults.xml
@@ -23,6 +23,7 @@
<!-- Preferences for OSX -->
<preference name="AllowInlineMediaPlayback" value="true" />
+ <preference name="AllowWebViewNavigation" value="true" />
<preference name="BackupWebStorage" value="cloud" />
<preference name="DisallowOverscroll" value="false" />
<preference name="EnableViewportScale" value="false" />
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org