5

I'm Using Geckfx22.0 and xulrunner22.0. Since GeckoWebBrowser in .Net shares cookies with all other instances of GeckoWebBrowsers I would like for a GeckoWebBrowser to have it's own cookie container which doesn't share any cookies that was created previously in other GeckoWebBrowsers or other instances.

For example when I create a GeckoWebBrowser it shouldn't have any cookies. And when I run 2 instances of GeckoWebBrowser they have their own cookie container and don't share or conflict cookies with each other.

How is that possible?

I've tried various possible ways by creating different class and initiating geckofx but when running different browser at same time it sharing cookies among other browsers. If i remove cookies from one browser , the same happening for other browsers too. I have initiated the proxy and useragent at different times and its works but cant apply various useragents for multiple browsers at the same time.

 public void Initiate()
    {
        Gecko.Xpcom.Initialize(AppDomain.CurrentDomain.BaseDirectory + "/xulrunner");
        if (this.IsProxySet)
        {
            Gecko.GeckoPreferences.User["network.proxy.http"] = this.Host;
            Gecko.GeckoPreferences.User["network.proxy.http_port"] = this.Port;
            Gecko.GeckoPreferences.User["network.proxy.type"] = 1;
        }
        if (IsUseragentSet)
        {
            Gecko.GeckoPreferences.User["general.useragent.override"] = this.Useragent;
        }
    }

And to remove cookies i'm using following code :

nsICookieManager CookieMan;
            CookieMan = Xpcom.GetService<nsICookieManager>("@mozilla.org/cookiemanager;1");
            CookieMan = Xpcom.QueryInterface<nsICookieManager>(CookieMan);
            CookieMan.RemoveAll(); 

Help will be appreciated !!!

yasmuru
  • 1,178
  • 2
  • 20
  • 42

1 Answers1

1

You could possibly try implementing your own cookie manager that supports this:

see unittest Register_AfterDefaultFactoryHasBeenUnregistered_NewCookieServiceIsUsedInsteadOfDefaultOne for an example of how to do this.

This code is currently untested and may contain typeos

This code requires a geckofx version newer than v22.0-0.6

[Guid("c375fa80-150f-11d6-a618-0010a401eb10")]
    [ContractID(TestCookieServiceFactory.ContractID)]
    public class TestCookieServiceFactory
        : GenericOneClassNsFactory<TestCookieServiceFactory, TestCookieService>
    {
        public const string ContractID = "@mozilla.org/cookieService;1";
    }

 public class TestCookieService : nsICookieService
 {
   // Implement nsICookieService...       
 }

 public void Main()
 {
     Xpcom.Initialize("My Xulrunner/Fireofox location");
     var existingFactoryDetails = TestCookieServiceFactory.Unregister();
     TestCookieServiceFactory.Register();

     var browser = new GeckofxWebBrowser();
     // Add browser to form etc...
     browser.Navigate("http://SomeWebPageThatUsesCookies")

     // Cookie requests should now be sent to TestCookieService, process them as your want.
 }
Tom
  • 6,325
  • 4
  • 31
  • 55
  • can you just explain it ? – yasmuru Nov 27 '13 at 05:41
  • The unittest demos how to replace the Xpcom service "@mozilla.org/cookieService;1". (I suspect one could do the same for cookiemanager;1 or maybe cookiemanager works by using the cookieService). It works like this TestCookieServiceFactory creates a new implementation of "@mozilla.org/cookieService;1". (The actual work is delegated to a TestCookieService class that implements the nsICookieService interface.) Then as early as possible in program startup (ie after XpCom.Init) TestCookieServiceFactory.Unregister() is called to remove the default service, then call Register() to install new one. – Tom Nov 27 '13 at 06:01
  • i could not find the `TestCookieServiceFactory` ? if possible can you give any programming example ? – yasmuru Nov 27 '13 at 06:50
  • I have tried that , but its not working . Unable to call `Unregister`. And they sharing the same db file for every browser instance( if we using the browser instance in different project also) to store and fetch cookies and cache. so when we run the project first time it creates one folder in temp and using the same for every projects. only think we can do is , try to create different db for every browser instance. i dono whether that possible . if you get any idea let me know . i'm searching ..... – yasmuru Nov 28 '13 at 08:35
  • oops sorry. You need to use geckofx version newer than "v22.0-0.6" - I am currently using one built from source. So you could either build from source or wait for v22.0-0.7. – Tom Nov 28 '13 at 14:16