Recent

Author Topic: WebView and https  (Read 2558 times)

y.ivanov

  • Sr. Member
  • ****
  • Posts: 283
WebView and https
« on: August 25, 2021, 06:53:49 pm »
Does anybody knows how to handle SSL Certificate errors in jWebView?

It opens http locations, but when it reaches the https URL with untrusted certificate it does just nothing. Perhaps it misses a handler for the SSL errors:
Code: Java  [Select][+][-]
  1. @Override
  2. public void onReceivedSslError(WebView view,...)

Thanks in advance!

Mongkey

  • Full Member
  • ***
  • Posts: 178
Re: WebView and https
« Reply #1 on: August 27, 2021, 09:47:53 am »
Try look at manifest, set clear traffic, may be it helps

y.ivanov

  • Sr. Member
  • ****
  • Posts: 283
Re: WebView and https
« Reply #2 on: August 27, 2021, 04:50:44 pm »
Try look at manifest, set clear traffic, may be it helps
For the manifest: I didn't realize yet how to include permissions other than those listed into Project Options/LAMW Configuration. For example, I need to use the microphone. The manifest gets overwritten every time, I just can't simply put it there.

Same with the jWebView.java - it comes fresh on every build from LAMW directories.

I've modified it there, added the onReceivedSslError() in jWebViewClient, and it works now for the untrusted certificate. But my next trouble is with the permissions. I'm opening a video chat site into the jWebView and it can't get the mic, because of no permissions.

Looking at large, these android bridges aren't bridging most of the methods, and maybe, the only way is to modify the LAMW itself.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1943
Re: WebView and https
« Reply #3 on: August 27, 2021, 06:02:49 pm »
Quote
I need to use the microphone. The manifest gets overwritten every time, I just can't simply put it there.

Please, put here what permission you need ...

Quote
I've modified it there, added the onReceivedSslError() in jWebViewClient,

Please, put code here ...

I will try updated jWebViewClient!


Thank you!


Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

y.ivanov

  • Sr. Member
  • ****
  • Posts: 283
Re: WebView and https
« Reply #4 on: August 27, 2021, 07:06:22 pm »
Quote
I've modified it there, added the onReceivedSslError() in jWebViewClient,

Please, put code here ...

I will try updated jWebViewClient!

The code I've tried was:
Code: Java  [Select][+][-]
  1. @Override
  2. public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
  3.     handler.proceed(); // Ignore SSL certificate errors
  4. }
I took it from: https://stackoverflow.com/questions/7416096/android-webview-not-loading-an-https-url

But it was just a workaround to see if it was the real issue. I suggest the real method should call/bridge to an event handler in Lazarus code to allow user choice whether to proceed or not. And that is a little bit complicated for me, I'm not a true Java developer. That's why I'm using laz4android.

Since the workaround worked, then I hit the problem with the permissions. And as long the camera permission can be given, the mic is not included into the LAMW table.

Quote
I need to use the microphone. The manifest gets overwritten every time, I just can't simply put it there.

Please, put here what permission you need ...

I believe they're:
Code: [Select]
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.RECORD_AUDIO
Again, considering: https://stackoverflow.com/questions/62037838/android-webview-not-getting-camera-and-mic-enabled-for-conference

But I can't be really sure until trying.  Furthermore, in the above thread, it was noted that:
Quote
After getting those permissions, you need to override onPermissionRequest in WebChromeClient like this:
Code: Java  [Select][+][-]
  1. webView.setWebChromeClient(new WebChromeClient() {
  2.   @Override
  3.    public void onPermissionRequest(final PermissionRequest request) {
  4.        request.grant(request.getResources());
  5. }
  6. });
And that is just another modification in the jWebView.java. ;)

Thank you for your reply and all your efforts regarding LAMW!

Mongkey

  • Full Member
  • ***
  • Posts: 178
Re: WebView and https
« Reply #5 on: August 27, 2021, 09:26:03 pm »
Oh, Sorry
Sometimes website has invalid ssl/bad ssl, let say you want visit that site over jWebView?

Example site with bad ssl
https://expired.badssl.com/

I think this thread also lead overriding permission on jWebview.java  :D
« Last Edit: August 27, 2021, 09:49:45 pm by Mongkey »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1943
Re: WebView and https
« Reply #6 on: August 28, 2021, 08:50:48 am »

Done!

Improved jWebView component!

New property:
   DomStorage

New event:
  OnReceivedSslError

New demo: "AppWebViewDemo1"     // <--- "how to" handle permissions!
 
New methods:

SetDomStorage
SetLoadWithOverviewMode
SetUseWideViewPort
SetAllowContentAccess
SetAllowFileAccess
SetAppCacheEnabled
SetDisplayZoomControls
SetGeolocationEnabled
SetJavaScriptCanOpenWindowsAutomatically
SetLoadsImagesAutomatically
SetSupportMultipleWindows
SetAllowUniversalAccessFromFileURLs
SetMediaPlaybackRequiresUserGesture
SetSafeBrowsingEnabled
SetSupportZoom
SetUserAgent


Thanks to All!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

y.ivanov

  • Sr. Member
  • ****
  • Posts: 283
Re: WebView and https
« Reply #7 on: August 28, 2021, 02:40:45 pm »
It is quite strange, when I try to reach LAMW/Path Settings, laz4android gives me:
Quote
[Window Title]
Lazarus IDE v2.0.0 - project1

[Content]
Unable to open file "D:\devel\android\android-ndk-r10e\REALEASE.TXT".

Press OK to ignore and risk data corruption.
Press Abort to kill the program.

[OK] [Abort]
laz4android: Lazarus 2.0.0 rUnknown FPC 3.0.4 i386-win32-win32/win64

The file is actually there  %)

Edit: That happened after I cloned fresh LAMW from github and rebuilt laz4android
« Last Edit: August 28, 2021, 02:57:19 pm by y.ivanov »

dseligo

  • Sr. Member
  • ****
  • Posts: 360
Re: WebView and https
« Reply #8 on: August 28, 2021, 03:06:13 pm »
It is quite strange, when I try to reach LAMW/Path Settings, laz4android gives me:
Quote
[Window Title]
Lazarus IDE v2.0.0 - project1

[Content]
Unable to open file "D:\devel\android\android-ndk-r10e\REALEASE.TXT".

Press OK to ignore and risk data corruption.
Press Abort to kill the program.

[OK] [Abort]
laz4android: Lazarus 2.0.0 rUnknown FPC 3.0.4 i386-win32-win32/win64

The file is actually there  %)

Edit: That happened after I cloned fresh LAMW from github and rebuilt laz4android

I just copied RELEASE.TXT and renamed it to REALEASE.TXT. It's spelling error somewhere.

y.ivanov

  • Sr. Member
  • ****
  • Posts: 283
Re: WebView and https
« Reply #9 on: August 28, 2021, 03:25:55 pm »
*snip*
I just copied RELEASE.TXT and renamed it to REALEASE.TXT. It's spelling error somewhere.
REALEASE.TXT (?!) I should go for my glasses replacement. Thanks!

jmpessoa

  • Hero Member
  • *****
  • Posts: 1943
Re: WebView and https
« Reply #10 on: August 28, 2021, 07:16:40 pm »
Quote
I just copied RELEASE.TXT and renamed it to REALEASE.TXT. It's spelling error somewhere.

 It's spelling error .... LAMW??

I will try fix some fix....
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

dseligo

  • Sr. Member
  • ****
  • Posts: 360
Re: WebView and https
« Reply #11 on: August 28, 2021, 07:25:34 pm »
Quote
I just copied RELEASE.TXT and renamed it to REALEASE.TXT. It's spelling error somewhere.

 It's spelling error .... LAMW??

I will try fix some fix....

Yes, it's in following files:
Code: Text  [Select][+][-]
  1. \ccr\lamw\android_wizard\uformworkspace.pas
  2. \ccr\lamw\android_wizard\smartdesigner.pas
  3. \ccr\lamw\ide_tools\uformsettingspaths.pas
  4.  

jmpessoa

  • Hero Member
  • *****
  • Posts: 1943
Re: WebView and https
« Reply #12 on: August 28, 2021, 07:46:06 pm »

Fixed!!!

Thanks!

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018