Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: blocking cookies from loading



>retrieved.  Cookies appear to be stored system wide, so I want my 
>so I want my application to be able to make the decision without 
>affecting any other programs that may be using the system at that 
>time. 

Yes, unfortunately Apple has not provided a way to use a private Cookie
storage. Though having a global cookie storage may be helpful in many 
cases, it is a really bad choice in some other cases. Maybe one day
Apple gives us the choice to officially use our own private cookie 
storage.

But there is a way to have your own private Cookie storage that works
well with WebView objects. I've done this in "iCab 4" which can use 
the global Cookie storage of Cocoa and a private storage as well. 

What you need to do is to subclass NSHTTPCookieStorage and then use the
"posing" feature of Objective C to make sure that your new storage class
is called whenever the original NSHTTPCookieStorage class would be called.
Which means you have to add the following into the main() function:

	[[MyPrivateCookieStorage class] poseAsClass:[NSHTTPCookieStorage class]];

Note: "posing" doesn't work in 64Bit apps.


Of course you also have to overwrite all messages of NSHTTPCookieStorage 
in your own subclass to store the cookies in your own arrays and you
have to do all the cookie processiong yourself. This can be tricky in 
some details. There are some rules you have to follow in order to get 
things right and to avoid "security" issues. So be careful.

Also note that the posing mechanism has same limitations. For example 
you can't add any member variables to your subclass which poses as 
its super class. So you have to store the data elsewhere (as static
variables or in another helper class etc.)

Also if you need  more control over Cookies, you may even need to
hook into the WebResourceLoadDelegates to collect all the cookies 
yourself when you receive HTTP responses and to set all cookies in 
URL Requests yourself (switching off "native" cookie support for URL
requests using [urlRequest setHTTPShouldHandleCookies:NO] and then
setting the Cookie header field in the request manually:
[urlRequest setValue: cookieHeader forHTTPHeaderField:@"Cookie"]
for example)

Like you can see in iCab 4 it is possible to use your private 
storage and the global in the same app, if this is required. In your
subclass of NSHTTPCookieStorage you can call the super class (which 
is NSHTTPCookieStorage) in you want to use the global storage or just
access your own storage arrays when you want to use the private 
storage.


-- 
Alexander Clauss

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webkitsdk-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webkitsdk-dev/email@hidden

This email sent to email@hidden

References: 
 >blocking cookies from loading (From: l keller <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.