Recent

Author Topic: Minimum code for implementing WebView (deprecated) or WKWebView  (Read 22836 times)

ChrisR

  • Full Member
  • ***
  • Posts: 234
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #15 on: September 04, 2021, 07:22:32 pm »
Related to this, it looks like Ryan Joseph (aka genericptr) just ported MacOS 11 headers:

 https://github.com/genericptr/MacOS_11_0

Zoë

  • New Member
  • *
  • Posts: 20
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #16 on: November 10, 2021, 10:30:56 pm »
The attached file is a TWebBrowser-like control that uses WKWebView, including the delegate protocol, which we're using in Beyond Compare 4.  Any of you are welcome to use it however you want;  I updated the header to mention the LCL's modified LGPL in case it's used for a patch, but it can be whatever.

In case it's still relevant, I ran into two issues when originally writing, which are in Gitlab as #37441 and #35995

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #17 on: December 07, 2021, 01:36:07 am »
By the way everyone....

"Why is WK_API_ENABLED not on by default?"

Inspecting WebKit.pas > Sources.inc > WKNavigationDelegate.inc it depends on the define being set...

But why is it not set? I suppose I can set the define in some compiler option, but just seems very odd to me.

Am I doing it wrong? :)


MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #18 on: December 08, 2021, 02:03:31 am »
Example:


So first I had

Code: Pascal  [Select][+][-]
  1.   Tmsdv_cocoanative_WebBrowserCocoaWKWebViewDelegate_Navigation = objcclass(NSObject)
  2.   private
  3.     FBrowserCtrlRef: TmsdvWebBrowserCocoaWKWebView;
  4.   public
  5.     // need implement
  6.   end;
  7.  
  8.       FDelegate_Cocoa_Navigation := Tmsdv_cocoanative_WebBrowserCocoaWKWebViewDelegate_Navigation.alloc.init;
  9.       FDelegate_Cocoa_Navigation.FBrowserCtrlRef := Self;
  10.       FWebView_CocoaWKWebView.setNavigationDelegate(FDelegate_Cocoa_Navigation);
  11.  
  12.  

This gives error

Quote
Error: Incompatible type for arg no. 1: Got "Tmsdv_cocoanative_WebBrowserCocoaWKWebViewDelegate_Navigation", expected "WKNavigationDelegateProtocol"

Now this seems like a great error and easy fix

Code: Pascal  [Select][+][-]
  1.   Tmsdv_cocoanative_WebBrowserCocoaWKWebViewDelegate_Navigation = objcclass(NSObject, WKNavigationDelegateProtocol)
  2.   private
  3.     FBrowserCtrlRef: TmsdvWebBrowserCocoaWKWebView;
  4.   public
  5.     // need implement
  6.   end;
  7.  

But this will throw another error

Quote
Error: Identifier not found "WKNavigationDelegateProtocol"

.... Now I have added all units I could think of, but it won't help and the reason seems to be:

fpcsrc/packages/cocoaint/src/webkit/WebKit.pas
includes
fpcsrc/packages/cocoaint/src/webkit/src/Sources.inc
includes
fpcsrc/packages/cocoaint/src/webkit/src/webkit/WKNavigationDelegate.inc

But in this unit the WKNavigationDelegateProtocol does not get compiled in because these are not defined "WK_API_ENABLED, PROTOCOLS"


I am trying to understand how Lazarus one place can recognize the type, but then not recognize the type if I use it. Anyhow, I tried a "hack" defining the beforementioned defines them and then *including* the *WKNavigationDelegate.inc* file myself, but, well I did not get it working.


« Last Edit: December 08, 2021, 02:05:16 am by MISV »

Zoë

  • New Member
  • *
  • Posts: 20
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #19 on: December 08, 2021, 04:29:50 am »
See the patches in the bug reports I mentioned:

https://gitlab.com/freepascal.org/fpc/source/-/issues/37441

https://gitlab.com/freepascal.org/fpc/source/-/issues/35995

Still haven't heard why that hasn't been corrected, but the macOS 11 headers on GitHub are correct so if/when that gets merged it should be fixed.

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #20 on: December 08, 2021, 11:54:42 pm »
Thank you for explanation and links. I missed them reading the first round. Hmmm... Let us hope it gets merged in soon albeit I can see some time passed since you submitted patches so... Crossing fingers :)



trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1793
  • Former Delphi 1-7, 10.2 user
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #21 on: December 09, 2021, 12:36:31 am »
No need to wait; patch your copy of FPC and recompile it. Just make a note so that you can remember to redo it if you upgrade or change versions <voice of experience>.
Lazarus 2.3, FPC 3.3.1 macOS 12.1 x86_64 Xcode 13.2
Lazarus 2.3, FPC 3.3.1 macOS 12.1 aarch64 Xcode 13.2
Lazarus 2.3, FPC 3.2.2 FreeBSD 13.0 amd64 VM
Lazarus 2.3, FPC 3.2.2 FreeBSD 12.2 amd64 VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 VM
Lazarus 2.0.10 FPC 3.2.0 Win10 amd64 VM

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #22 on: December 13, 2021, 12:05:06 pm »
Okay, applying the patch no problem.

But wondering what the best way is to recompile fpc source that will not kill me.

1)
I tried "Clean all and build" but that did not work since it does not include FPC.

2)
In terminal I navigated to
/Users/%name%/%folder%/LazarusCocoa64/Lazarus
and then tried
./lazbuild --build-all --recursive "/Volumes/DiskW/%folder%/MyAppProjectOSX.lpi" (this project uses a ton of units directly or indirectly including WKWebView)

However it ends up
Error: (Lazarus) [TLazPackageGraph.CompileRequiredPackages] "Exit code 1"

...

What is the best way to force recompiliation of the fpcsrc units? :)






avra

  • Hero Member
  • *****
  • Posts: 2291
    • Additional info
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #23 on: December 13, 2021, 02:32:50 pm »
But wondering what the best way is to recompile fpc source that will not kill me.
Might not be the best but it works: https://wiki.freepascal.org/FPC_recompilation_automation
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #24 on: December 14, 2021, 12:21:21 am »
Thank you, I will check it out :)  (Albeit it states it is for Windows, but can probably use most of it)

Two more questions:
- Is there no way to trigger Lazarus to recompile a "system" FPCSrc unit in an easier manner? Like except the .pas file?
- Could I possibly copy fixed units into my project directory as an alternative?
« Last Edit: December 14, 2021, 12:33:18 am by MISV »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1793
  • Former Delphi 1-7, 10.2 user
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #25 on: December 14, 2021, 03:47:55 am »
What is the best way to force recompiliation of the fpcsrc units? :)

Code: Bash  [Select][+][-]
  1.  []$ cd <wherever you have the fpc src>
  2.  []$ make clean all FPC=/usr/local/lib/fpc/3.2.2/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
  3.  []$ sudo make install FPC=$PWD/compiler/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64
Lazarus 2.3, FPC 3.3.1 macOS 12.1 x86_64 Xcode 13.2
Lazarus 2.3, FPC 3.3.1 macOS 12.1 aarch64 Xcode 13.2
Lazarus 2.3, FPC 3.2.2 FreeBSD 13.0 amd64 VM
Lazarus 2.3, FPC 3.2.2 FreeBSD 12.2 amd64 VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 VM
Lazarus 2.0.10 FPC 3.2.0 Win10 amd64 VM

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #26 on: December 14, 2021, 10:10:30 am »
Thank you :)

I ended up using (since I used FPCDeluxe for installing)

1)
Navigated to
Code: Pascal  [Select][+][-]
  1. /Users/%name%/LazarusCocoa64/fpcsrc/
  2.  

2)
Code: Pascal  [Select][+][-]
  1. make clean all FPC=/Users/%name%/LazarusCocoa64/fpc/lib/fpc/3.3.1 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"

Got quite a few permission errors like
Quote
/Users/%name%/LazarusCocoa64/fpc/lib/fpc/3.3.1: Permission denied
(but process seemed to run OK for most part)

3)
Code: Pascal  [Select][+][-]
  1. sudo make install FPC=$PWD/compiler/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64

which resulted in error:
Quote
Makefile:135: *** Compiler /Users/%name%/LazarusCocoa64/fpcsrc/compiler/ppcx64 not found.  Stop.

I decided to instead try
Code: Pascal  [Select][+][-]
  1. sudo make install FPC=$PWD/../fpc/lib/fpc/3.3.1/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64

This appears to work...


Will report back later and update post if things worked out :)

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #27 on: December 14, 2021, 11:30:52 am »
It seemed to compile correctly but...

I guess not because I still get the error that it does not recognize WKNavigationDelegateProtocol etc.

I have tried to do a "Cleanup and build" just to make sure it is not inside LCL that had not updated somehow to the new fpcsrc compilation.

Oh well...

MISV

  • Hero Member
  • *****
  • Posts: 769
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #28 on: December 14, 2021, 11:12:14 pm »
In fpcsrc directory doing

ls -l

and all  files are either

-rw-r--r-- (seems to be all writeable files)
or
drwxr-xr-x (folders)

and I stand as user/owner %name% staff


I do not know...

I was starting to experiment with
sudo chmod -R ./ ...? (sorry did not get it working since day-to-day Windows user here)




I have also tried to introduce a bug into a compiletime bug into webkit ... and that did trigger error.
I have also tried to introduce a bug into a compiletime bug into wknavigationdelegate.inc  both to ensure protocol and wk_api_enabled defines are working... And yes, they are defined properly because inserting random text inside them triggered error



So what is next. Why the **** does it not work when compiling my code inside Lazarus?

Maybe related to permission errors? i.e. no new compiled files are actually generated? I will try research more... ... Open to ideas
« Last Edit: December 14, 2021, 11:40:04 pm by MISV »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1793
  • Former Delphi 1-7, 10.2 user
Re: Minimum code for implementing WebView (deprecated) or WKWebView
« Reply #29 on: December 15, 2021, 12:58:11 am »
I would guess that permission errors while recompiling are fatal. I have no idea why you would be getting permission errors if the source is in your home directory - maybe an FPCUpDeluxe issue.

In order of preference, you have a choice to make:

1) Find the files causing permission errors and correct the permissions and/or ownership with chmod and/or chown as necessary;
2) Run the compile command with sudo.
Lazarus 2.3, FPC 3.3.1 macOS 12.1 x86_64 Xcode 13.2
Lazarus 2.3, FPC 3.3.1 macOS 12.1 aarch64 Xcode 13.2
Lazarus 2.3, FPC 3.2.2 FreeBSD 13.0 amd64 VM
Lazarus 2.3, FPC 3.2.2 FreeBSD 12.2 amd64 VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 VM
Lazarus 2.0.10 FPC 3.2.0 Win10 amd64 VM

 

TinyPortal © 2005-2018