bool CookieServiceParent::RecvSetCookieString(const URIParams& aHost, const bool& aIsForeign, const nsCString& aCookieString, const nsCString& aServerTime, const bool& aFromHttp, const IPC::SerializedLoadContext& aLoadContext) { if (!mCookieService) return true; // Deserialize URI. Having a host URI is mandatory and should always be // provided by the child; thus we consider failure fatal. nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost); if (!hostURI) return false; uint32_t appId; bool isInBrowserElement, isPrivate; bool valid = GetAppInfoFromParams(aLoadContext, appId, isInBrowserElement, isPrivate); if (!valid) { return false; } nsDependentCString cookieString(aCookieString, 0); //TODO: bug 812475, pass a real channel object mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString, aServerTime, aFromHttp, appId, isInBrowserElement, isPrivate, nullptr); return true; }
nsresult CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI, nsIChannel *aChannel, const char *aCookieString, const char *aServerTime, bool aFromHttp) { NS_ENSURE_ARG(aHostURI); NS_ENSURE_ARG_POINTER(aCookieString); // Determine whether the request is foreign. Failure is acceptable. bool isForeign = true; if (RequireThirdPartyCheck()) mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign); nsDependentCString cookieString(aCookieString); nsDependentCString serverTime; if (aServerTime) serverTime.Rebind(aServerTime); // Synchronously call the parent. SendSetCookieString(IPC::URI(aHostURI), !!isForeign, cookieString, serverTime, aFromHttp); return NS_OK; }
String cookies(const KURL& url) { DeprecatedString str = url.url(); char domainBuffer[SIZE_OF_LATIN1_BUFFERS]; char pathBuffer[SIZE_OF_LATIN1_BUFFERS]; int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH; int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1; int tl_pathLocationInUrlEnds = str.findRev("/"); strncpy(domainBuffer, str.ascii() + tl_domainLocationInUrlBegins, tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1); domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0'; strncpy(pathBuffer, str.ascii() + tl_domainLocationInUrlEnds + 1, tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds); pathBuffer[tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds] = '\0'; char* cookStr = WebKitApollo::g_HostFunctions->getJavaScriptCookies(domainBuffer,pathBuffer); if(!cookStr) { return String(); } String cookieString(cookStr); ::free(cookStr); return cookieString; }
bool CookieServiceParent::RecvSetCookieString(const URIParams& aHost, const bool& aIsForeign, const nsCString& aCookieString, const nsCString& aServerTime, const bool& aFromHttp, const IPC::SerializedLoadContext& aLoadContext) { if (!mCookieService) return true; // Deserialize URI. Having a host URI is mandatory and should always be // provided by the child; thus we consider failure fatal. nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost); if (!hostURI) return false; uint32_t appId; bool isInBrowserElement, isPrivate; bool valid = GetAppInfoFromParams(aLoadContext, appId, isInBrowserElement, isPrivate); if (!valid) { return false; } // This is a gross hack. We've already computed everything we need to know // for whether to set this cookie or not, but we need to communicate all of // this information through to nsICookiePermission, which indirectly // computes the information from the channel. We only care about the // aIsPrivate argument as nsCookieService::SetCookieStringInternal deals // with aIsForeign before we have to worry about nsCookiePermission trying // to use the channel to inspect it. nsCOMPtr<nsIChannel> dummyChannel; CreateDummyChannel(hostURI, appId, isInBrowserElement, isPrivate, getter_AddRefs(dummyChannel)); // NB: dummyChannel could be null if something failed in CreateDummyChannel. nsDependentCString cookieString(aCookieString, 0); mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString, aServerTime, aFromHttp, appId, isInBrowserElement, isPrivate, dummyChannel); return true; }
void CookieTest::MaxSizeTest() { BNetworkCookieJar jar; status_t result; BUrl url("http://testsuites.opera.com/cookies/006.php"); BString cookieString("006="); for (int i = 0; i < 128; i++) { cookieString << "00xxxxxxxxxxxxxx16xxxxxxxxxxxxxx"; } result = jar.AddCookie(cookieString, url); CPPUNIT_ASSERT(result == B_OK); url.SetUrlString("http://testsuites.opera.com/cookies/006-1.php"); const BNetworkCookie* cookie = _GetCookie(jar, url, "006"); CPPUNIT_ASSERT(cookie != NULL); CPPUNIT_ASSERT(cookie->Value().Length() == 4096); }