Skip to content

Commit

Permalink
Merge branch 'changes/webrtc-permission-promts' into apicore/7.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gazben committed Apr 22, 2024
2 parents 05f8110 + 6c8a1f2 commit fa922b2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ - (void)pluginInitialize
}

CDVWebViewUIDelegate* uiDelegate = [[CDVWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
uiDelegate.mediaPermissionGrantType = [self parsePermissionGrantType:[settings cordovaSettingForKey:@"MediaPermissionGrantType"]];
uiDelegate.allowNewWindows = [settings cordovaBoolSettingForKey:@"AllowNewWindows" defaultValue:NO];
self.uiDelegate = uiDelegate;

Expand Down Expand Up @@ -488,6 +489,29 @@ - (UIView*)webView
return self.engineWebView;
}

- (CDVWebViewPermissionGrantType)parsePermissionGrantType:(NSString*)optionString
{
CDVWebViewPermissionGrantType result = CDVWebViewPermissionGrantType_Prompt;

if (optionString != nil){
if ([optionString isEqualToString:@"prompt"]) {
result = CDVWebViewPermissionGrantType_Prompt;
} else if ([optionString isEqualToString:@"deny"]) {
result = CDVWebViewPermissionGrantType_Deny;
} else if ([optionString isEqualToString:@"grant"]) {
result = CDVWebViewPermissionGrantType_Grant;
} else if ([optionString isEqualToString:@"grantIfSameHostElsePrompt"]) {
result = CDVWebViewPermissionGrantType_GrantIfSameHost_ElsePrompt;
} else if ([optionString isEqualToString:@"grantIfSameHostElseDeny"]) {
result = CDVWebViewPermissionGrantType_GrantIfSameHost_ElseDeny;
} else {
NSLog(@"Invalid \"MediaPermissionGrantType\" was detected. Fallback to default value of \"prompt\"");
}
}

return result;
}

#pragma mark WKScriptMessageHandler implementation

- (void)userContentController:(WKUserContentController*)userContentController didReceiveScriptMessage:(WKScriptMessage*)message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
NSMutableArray<UIViewController*>* windows;
}

typedef NS_ENUM(NSInteger, CDVWebViewPermissionGrantType) {
CDVWebViewPermissionGrantType_Prompt,
CDVWebViewPermissionGrantType_Deny,
CDVWebViewPermissionGrantType_Grant,
CDVWebViewPermissionGrantType_GrantIfSameHost_ElsePrompt,
CDVWebViewPermissionGrantType_GrantIfSameHost_ElseDeny
};

@property (nonatomic, copy) NSString* title;
@property (nonatomic, assign) BOOL allowNewWindows;
@property (nonatomic, assign) CDVWebViewPermissionGrantType mediaPermissionGrantType;

- (instancetype)initWithTitle:(NSString*)title;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,30 @@ - (void)webViewDidClose:(WKWebView*)webView
// We do not allow closing the primary WebView
}

- (void)webView:(WKWebView *)webView requestMediaCapturePermissionForOrigin:(nonnull WKSecurityOrigin *)origin initiatedByFrame:(nonnull WKFrameInfo *)frame type:(WKMediaCaptureType)type decisionHandler:(nonnull void (^)(WKPermissionDecision))decisionHandler
API_AVAILABLE(ios(15.0))
{
WKPermissionDecision decision;

if (_mediaPermissionGrantType == CDVWebViewPermissionGrantType_Prompt) {
decision = WKPermissionDecisionPrompt;
}
else if (_mediaPermissionGrantType == CDVWebViewPermissionGrantType_Deny) {
decision = WKPermissionDecisionDeny;
}
else if (_mediaPermissionGrantType == CDVWebViewPermissionGrantType_Grant) {
decision = WKPermissionDecisionGrant;
}
else {
if ([origin.host isEqualToString:webView.URL.host]) {
decision = WKPermissionDecisionGrant;
}
else {
decision =_mediaPermissionGrantType == CDVWebViewPermissionGrantType_GrantIfSameHost_ElsePrompt ? WKPermissionDecisionPrompt : WKPermissionDecisionDeny;
}
}

decisionHandler(decision);
}

@end
1 change: 1 addition & 0 deletions templates/cordova/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<preference name="AllowInlineMediaPlayback" value="false" />
<preference name="DisallowOverscroll" value="false" />
<preference name="EnableViewportScale" value="false" />
<preference name="MediaPermissionGrantType" value="prompt" />
<preference name="MediaTypesRequiringUserActionForPlayback" value="none" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="SuppressesLongPressGesture" value="false" />
Expand Down

0 comments on commit fa922b2

Please sign in to comment.