clobba / open-webkit-sharp

Automatically exported from code.google.com/p/open-webkit-sharp
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Custom Url protocol #99

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

How can i implement custom URL protocol diffrent "http" like 
"cust_protocol://something/path ..." ? 

WebView.policyDelegate ?

Thanks for help

Original issue reported on code.google.com by prubo...@gmail.com on 26 Apr 2012 at 7:13

GoogleCodeExporter commented 8 years ago
whats wrong?
===============

    public partial class MyWebKit : Form, Ihpb_AskControl, IWebPolicyDelegate
    {
         public MyWebKit ()
         {
            WebView wv = (WebView)browser.GetWebViewAsObject();
            wv.setPolicyDelegate(this);

//            ((WebViewClass)browser.WebView).setPolicyDelegate(this);
         }

// ............

        public void decidePolicyForMIMEType(WebView WebView, string type, IWebURLRequest request, webFrame frame, IWebPolicyDecisionListener listener)
        {
            throw new NotImplementedException();
        }

        public void decidePolicyForNavigationAction(WebView WebView, CFDictionaryPropertyBag actionInformation, IWebURLRequest request, webFrame frame, IWebPolicyDecisionListener listener)
        {
            throw new NotImplementedException();
        }

        public void decidePolicyForNewWindowAction(WebView WebView, CFDictionaryPropertyBag actionInformation, IWebURLRequest request, string frameName, IWebPolicyDecisionListener listener)
        {
            throw new NotImplementedException();
        }

        public void unableToImplementPolicyWithError(WebView WebView, WebError error, webFrame frame)
        {
            throw new NotImplementedException();
        }

    }

Original comment by prubo...@gmail.com on 26 Apr 2012 at 9:31

GoogleCodeExporter commented 8 years ago
You must edit the source of OpenWebKitSharp and not override IWebPolicyDelegate 
because this way many other features such as the downloader and new windows 
will not work. Inside WebPolicyDelegate.cs at decidePolicyForNavigationAction 
you must see if request.url().StartsWith("myprotocol") and if it does you can 
do whatever you want, either navigate to that (listener.use() or 
listener.allow()) or fire a custom event which will send the url back and then 
interfere with it in the way you want.

Original comment by tsumalis96@gmail.com on 26 Apr 2012 at 4:52

GoogleCodeExporter commented 8 years ago
Great thanks!

But anyway, I realized the overriding interface methods in your code ;) As a 
basis, I took the code from the file "WebPolicyDelegate.cs".  As a bonus, I 
found a place that happens to popular people COM exception:
+-------------------------------------------------------------------------------
An exception of type 'System.AccessViolationException' occurred in test.exe but 
was not handled in user code

Additional information: Attempted to read or write protected memory. This is 
often an indication that other memory is corrupt.
+-------------------------------------------------------------------------------

He has consistently played in the procedure "decidePolicyForNewWindowAction" on 
the line of code "listener.use ();"

public void decidePolicyForNewWindowAction(WebView WebView, 
CFDictionaryPropertyBag actionInformation, IWebURLRequest request, string 
frameName, IWebPolicyDecisionListener listener)
{
  if (listener != null)
      listener.use();

   string url = request.url();
  // NewWindowRequestUrlAvailable(url);
  // throw new NotImplementedException();
}

The site for the demonstration of this: "http://ria.ru/riatv/#loop"

Security updates for MFC and ATL for VC2008 redist, which would you recommend 
to install, have installed. The problem, as you know, that keep this method 
without implementation is impossible, because there site does not open. Maybe 
you have an idea how to overcome it?

Original comment by prubo...@gmail.com on 27 Apr 2012 at 11:31

GoogleCodeExporter commented 8 years ago
You were right, that's not good to override an interface in my code. No 
exception occurs if the option AllowDownloads = true. And therefore will need 
to duplicate downloader code ...

I'll do as you advised. Thank you.

I think the issue is closed.

Original comment by prubo...@gmail.com on 27 Apr 2012 at 12:28

GoogleCodeExporter commented 8 years ago
Sorry, exception found into decidePolicyForNewWindowAction if AllowDownloads = 
false

Original comment by prubo...@gmail.com on 27 Apr 2012 at 6:16

GoogleCodeExporter commented 8 years ago
That's very weird. That method has nothing to do with downloads. What is the 
exception details?

Original comment by tsumalis96@gmail.com on 29 Apr 2012 at 9:43