Skip to content

Commit

Permalink
chore: applied feedback suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed May 27, 2020
1 parent c682728 commit 653cbf9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ - (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName names

- (void)parserDidStartDocument:(NSXMLParser*)parser
{
NSString* scheme = [NSString stringWithFormat:@"%@://",((CDVViewController*)self.viewController).appScheme];
// file: url <allow-navigations> are added by default
// navigation to the scheme used by the app is also allowed
self.allowNavigations = [[NSMutableArray alloc] initWithArray:@[ @"file://", scheme ]];
self.allowNavigations = [[NSMutableArray alloc] initWithArray:@[ @"file://"]];

// If the custom app scheme is defined, append it to the allow navigation as default
NSString* scheme = ((CDVViewController*)self.viewController).appScheme;
if (scheme) {
[self.allowNavigations addObject: [NSString stringWithFormat:@"%@://", scheme]];
}

// no intents are added by default
self.allowIntents = [[NSMutableArray alloc] init];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,24 @@ - (void)pluginInitialize
if(hostname == nil){
hostname = @"localhost";
}
}

self.CDV_ASSETS_URL = [NSString stringWithFormat:@"%@://%@", scheme, hostname];
self.CDV_ASSETS_URL = [NSString stringWithFormat:@"%@://%@", scheme, hostname];
}

self.uiDelegate = [[CDVWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];

CDVWebViewWeakScriptMessageHandler *weakScriptMessageHandler = [[CDVWebViewWeakScriptMessageHandler alloc] initWithScriptMessageHandler:self];

WKUserContentController* userContentController = [[WKUserContentController alloc] init];
[userContentController addScriptMessageHandler:weakScriptMessageHandler name:CDV_BRIDGE_NAME];
NSString * scriptCode = [NSString stringWithFormat:@"window.CDV_ASSETS_URL = '%@';", self.CDV_ASSETS_URL];
WKUserScript *wkScript =
[[WKUserScript alloc] initWithSource:scriptCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
if (wkScript) {
[userContentController addUserScript:wkScript];

if(self.CDV_ASSETS_URL) {
NSString *scriptCode = [NSString stringWithFormat:@"window.CDV_ASSETS_URL = '%@';", self.CDV_ASSETS_URL];
WKUserScript *wkScript = [[WKUserScript alloc] initWithSource:scriptCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];

if (wkScript) {
[userContentController addUserScript:wkScript];
}
}

WKWebViewConfiguration* configuration = [self createConfigurationFromSettings:settings];
Expand Down
2 changes: 1 addition & 1 deletion CordovaLib/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ var WkWebKit = {
exec(null, null, 'CDVWebViewEngine', 'allowsBackForwardNavigationGestures', [allow]);
},
convertFilePath: function (path) {
if (!path) {
if (!path || !window.CDV_ASSETS_URL) {
return path;
}
if (path.startsWith('/')) {
Expand Down
2 changes: 1 addition & 1 deletion cordova-js-src/plugin/ios/wkwebkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var WkWebKit = {
exec(null, null, 'CDVWebViewEngine', 'allowsBackForwardNavigationGestures', [allow]);
},
convertFilePath: function (path) {
if (!path) {
if (!path || !window.CDV_ASSETS_URL) {
return path;
}
if (path.startsWith('/')) {
Expand Down

0 comments on commit 653cbf9

Please sign in to comment.