tuarua / WebViewANE

WebView Adobe Air Native Extension for macOS 10.10+, Windows Desktop, iOS 9.0+ and Android 19+. This ANE provides access to a more modern webview from AIR.
Apache License 2.0
183 stars 53 forks source link

I cannot find any way to modify the accept-language headers #177

Closed jsrdzhk closed 6 years ago

jsrdzhk commented 6 years ago

Answer the below. DO NOT DELETE!!

Hello,I known ISSUE is only for bugs and I am sorry to disturb you.It seems that webviewane has no way to modify the accept-language.I tried my best to find this feature but failed.Please tell me the way to modify the accept-languages if it exists.Or please add this feature if you will.Thanks anyway!

tuarua commented 6 years ago

There is no current way to do that and it's not something I have a need for.

It would require custom coding. I would have to charge to add this. If you want to discuss that then please contact info@tuarua.co.uk for a quote.

jsrdzhk commented 6 years ago

@tuarua I'm sorry but I have to implement this feature by myself. UPDATE:I have written some code to add this feature but I have some troubles to package the webviewane.So I can't test what I modified. Here's what I did: 1.modify the CefView.cs and MainController.cs 2.add a string property acceptLanguage to Settings.as 3.build the WebViewANELib and get the WebViewANELib.dll 4.build the WebViewANE and get the WebViewANE.dll with some errors occurred,these errors are all about cannot find some files to copy. 5.I copied WebViewANELib.dll WebViewANE.dll extension.xml(extension descriptor file) and library.swf into the directory of adt.bat.Then I tried to package all of them with this command: adt -package -target ane WebViewANE.ane extension.xml -swc WebViewANE.swc -platform default -C platform/default library.swf.The returned result is 'Missing implementation for platform: Android-x86'.

Can you show me a tutorial about how to join this project and add new features to it?Thanks very much!

tuarua commented 6 years ago

Your adt command is wrong. Re-use what is already there.

  1. open build-windows.bat and modify the 2 paths at the top
  2. In VS Open Build > Batch Build
  3. Select All except 2 "Any CPU"

This builds the dlls, creates the ANE and copies dlls to AIR bin folder

Make sure you follow the instructions here to make the changes you need for the headers https://github.com/cefsharp/CefSharp/issues/534#issuecomment-60694502

jsrdzhk commented 6 years ago

Thanks for your response!I followed your instructions and modified the accept-language by these code:

CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser bsrowser, IFrame frame,
            IRequest request, IRequestCallback callback)
        {
            var headers = request.Headers;
            headers["Accept-Language"] = "zh-CN";
            request.Headers = headers;
            return CefReturnValue.Continue;
        }

That successfully changed the cef's request header and the website displayed language became Chinese.I tried to improve this method so that I can specify the accept-language from as code.Here's the change:

CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser bsrowser, IFrame frame,
            IRequest request, IRequestCallback callback)
        {
            var headers = request.Headers;
            headers["Accept-Language"] = _acceptLanguage;
            request.Headers = headers;
            return CefReturnValue.Continue;
        }

_acceptLanguage was fetched from as code by AcceptLanguage = settingFre.GetProp() and I changed the contructor of RequestHandler into

public RequestHandler(ArrayList whiteList, ArrayList blackList, string acceptLanguage) {
            _whiteList = whiteList;
            _blackList = blackList;
            _acceptLanguage = acceptLanguage;
        }

In the CefView.cs,I added the member variable public string AcceptLanguage { private get; set; } After these changes,I found no matter how I change the property acceptLanguage in as,the accept-language request header was always zh-CN.

UPDATE:I just modified AcceptLanguageList in CefSharp and it works.Thanks for your help!If you will,I can commit my little amount of modifications to your project.

tuarua commented 6 years ago

Thanks for investigating and providing details of the changes.

I didn't know about CefSettings.AcceptLanguageList

As it is a small change I have added it to the next version 1.9.0 which I will release 15/09/18

jsrdzhk commented 6 years ago

@tuarua I found the webview was always displayed on the top of the app and everything was covered by the webview instance.Is it possible to show some notifications by using as code?And I'm interested in the internal principle of this project.Should I start with your another project FreSharp?

tuarua commented 6 years ago

1 in the wiki

https://github.com/tuarua/WebViewANE/wiki/Troubleshooting---FAQs#can-i-overlay-flash-display-objects-over-the-webview

jsrdzhk commented 6 years ago

@tuarua Sorry for my stupid question.I'm a novice for GitHub and I only saw the HOME page of the wiki.I thought the Wiki had only one page before reding your answer......