initial patch for bug 210561 "eliminate nsCookieHTTPNotify; have HTTP talk directly to nsICookieService" patch=dwitte r=mvl sr=darin

This commit is contained in:
darin%meer.net 2003-08-05 01:44:27 +00:00
Родитель 9943df87b4
Коммит 0e1fa2dc76
10 изменённых файлов: 131 добавлений и 427 удалений

Просмотреть файл

@ -58,7 +58,6 @@ CPPSRCS = \
nsImgManager.cpp \
nsPermissionManager.cpp \
nsPopupWindowManager.cpp \
nsCookieHTTPNotify.cpp \
nsCookiePromptService.cpp \
nsCookiePermission.cpp \
$(NULL)

Просмотреть файл

@ -1,268 +1 @@
/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG_dp
#include <stdio.h>
#endif
#include "nsCookieService.h" /* don't remove -- needed for mac build */
#include "nsCookieHTTPNotify.h"
#include "nsIGenericFactory.h"
#include "nsIHttpChannel.h"
#include "nsCookie.h"
#include "nsIURL.h"
#include "nsCRT.h"
#include "nsLiteralString.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "nsINetModuleMgr.h"
#include "nsILoadGroup.h"
#include "nsICategoryManager.h"
#include "nsIHttpProtocolHandler.h" // for NS_HTTP_STARTUP_CATEGORY
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrompt.h"
// we want to explore making the document own the load group
// so we can associate the document URI with the load group.
// until this point, we have an evil hack:
#include "nsIHttpChannelInternal.h"
static NS_DEFINE_CID(kINetModuleMgrCID, NS_NETMODULEMGR_CID);
///////////////////////////////////
// nsISupports
NS_IMPL_ISUPPORTS2(nsCookieHTTPNotify, nsIHttpNotify, nsINetNotify);
///////////////////////////////////
// nsCookieHTTPNotify Implementation
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
nsresult nsCookieHTTPNotify::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
return nsCookieHTTPNotifyConstructor(aOuter, aIID, aResult);
}
NS_METHOD nsCookieHTTPNotify::RegisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
// Register ourselves into the NS_CATEGORY_HTTP_STARTUP
nsresult rv;
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString prevEntry;
rv = catman->AddCategoryEntry(NS_HTTP_STARTUP_CATEGORY, "Http Cookie Notify", NS_COOKIEHTTPNOTIFY_CONTRACTID,
PR_TRUE, PR_TRUE, getter_Copies(prevEntry));
return NS_OK;
}
NS_METHOD nsCookieHTTPNotify::UnregisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = catman->DeleteCategoryEntry(NS_HTTP_STARTUP_CATEGORY,
NS_COOKIEHTTPNOTIFY_CONTRACTID, PR_TRUE);
// Return value is not used from this function.
return NS_OK;
}
NS_IMETHODIMP
nsCookieHTTPNotify::Init()
{
// Register to handing http requests and responses
nsresult rv = NS_OK;
nsCOMPtr<nsINetModuleMgr> pNetModuleMgr = do_GetService(kINetModuleMgrCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_CONTRACTID,
(nsIHttpNotify *)this);
if (NS_FAILED(rv)) return rv;
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_CONTRACTID,
(nsIHttpNotify *)this);
return rv;
}
nsCookieHTTPNotify::nsCookieHTTPNotify()
{
mCookieService = nsnull;
#ifdef DEBUG_dp
printf("CookieHTTPNotify Created.\n");
#endif /* DEBUG_dp */
}
nsCookieHTTPNotify::~nsCookieHTTPNotify()
{
}
NS_IMETHODIMP
nsCookieHTTPNotify::SetupCookieService()
{
nsresult rv = NS_OK;
if (!mCookieService)
{
mCookieService = do_GetService(NS_COOKIESERVICE_CONTRACTID, &rv);
}
return rv;
}
///////////////////////////////////
// nsIHttpNotify
NS_IMETHODIMP
nsCookieHTTPNotify::OnModifyRequest(nsIHttpChannel *aHttpChannel)
{
nsresult rv;
// Preconditions
NS_ENSURE_ARG_POINTER(aHttpChannel);
// Get the url
nsCOMPtr<nsIURI> pURL;
rv = aHttpChannel->GetURI(getter_AddRefs(pURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(aHttpChannel);
NS_ENSURE_TRUE(httpInternal, NS_ERROR_UNEXPECTED);
// Get the original url that the user either typed in or clicked on
nsCOMPtr<nsIURI> pFirstURL;
rv = httpInternal->GetDocumentURI(getter_AddRefs(pFirstURL));
if (NS_FAILED(rv)) return rv;
if (!pFirstURL) {
rv = aHttpChannel->GetOriginalURI(getter_AddRefs(pFirstURL));
if (NS_FAILED(rv)) return rv;
}
// Ensure that the cookie service exists
rv = SetupCookieService();
if (NS_FAILED(rv)) return rv;
// Get the cookies
char * cookie;
rv = mCookieService->GetCookieStringFromHttp(pURL, pFirstURL, aHttpChannel, &cookie);
if (NS_FAILED(rv)) return rv;
const char *headerVal = "";
if (cookie && *cookie)
headerVal = cookie;
// Set the cookie into the request headers overwriting any existing header.
rv = aHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cookie"),
nsDependentCString(headerVal),
PR_FALSE);
nsMemory::Free((void *)cookie);
return rv;
}
NS_IMETHODIMP
nsCookieHTTPNotify::OnExamineResponse(nsIHttpChannel *aHttpChannel)
{
nsresult rv;
// Preconditions
NS_ENSURE_ARG_POINTER(aHttpChannel);
// Get the Cookie header
nsCAutoString cookieHeader;
rv = aHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Set-Cookie"), cookieHeader);
if (NS_FAILED(rv)) return rv;
if (cookieHeader.IsEmpty()) return NS_OK; // not an error, there's just no header.
// Get the url
nsCOMPtr<nsIURI> pURL;
rv = aHttpChannel->GetURI(getter_AddRefs(pURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(aHttpChannel);
NS_ENSURE_TRUE(httpInternal, NS_ERROR_UNEXPECTED);
// Get the original url that the user either typed in or clicked on
nsCOMPtr<nsIURI> pFirstURL;
rv = httpInternal->GetDocumentURI(getter_AddRefs(pFirstURL));
if (NS_FAILED(rv)) return rv;
// Get the prompter
nsCOMPtr<nsILoadGroup> pLoadGroup;
rv = aHttpChannel->GetLoadGroup(getter_AddRefs(pLoadGroup));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIChannel> pChannel;
if (pLoadGroup) {
nsCOMPtr<nsIRequest> pRequest;
rv = pLoadGroup->GetDefaultLoadRequest(getter_AddRefs(pRequest));
if (NS_FAILED(rv)) return rv;
pChannel = do_QueryInterface(pRequest);
}
nsCOMPtr<nsIInterfaceRequestor> pInterfaces;
nsCOMPtr<nsIPrompt> pPrompter;
if (pChannel) {
pChannel->GetNotificationCallbacks(getter_AddRefs(pInterfaces));
} else {
aHttpChannel->GetNotificationCallbacks(getter_AddRefs(pInterfaces));
}
if (pInterfaces)
pInterfaces->GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(pPrompter));
// Get the expires
nsCAutoString dateHeader;
rv = aHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Date"), dateHeader);
// NS_ERROR_NOT_AVAILABLE is not a fatal error, other errors are
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) return rv;
// Ensure that we have the cookie service
rv = SetupCookieService();
if (NS_FAILED(rv)) return rv;
// Save the cookie
rv = mCookieService->SetCookieStringFromHttp(pURL, pFirstURL, pPrompter, cookieHeader.get(), dateHeader.get(), aHttpChannel);
return rv;
}

Просмотреть файл

@ -1,87 +1 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsCookieHTTPNotify_h___
#define nsCookieHTTPNotify_h___
#include "nsIHttpNotify.h"
#include "nsICookieService.h"
#include "nsIComponentManager.h"
// {6BC1F522-1F45-11d3-8AD4-00105A1B8860}
#define NS_COOKIEHTTPNOTIFY_CID \
{ 0x6bc1f522, 0x1f45, 0x11d3, { 0x8a, 0xd4, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
#define NS_COOKIEHTTPNOTIFY_CONTRACTID "@mozilla.org/cookie-notifier;1"
#define NS_COOKIEHTTPNOTIFY_CLASSNAME "Cookie Notifier"
struct nsModuleComponentInfo; // forward declaration
class nsCookieHTTPNotify : public nsIHttpNotify {
public:
// nsISupports
NS_DECL_ISUPPORTS
// Init method
NS_IMETHOD Init();
// nsIHttpNotify methods:
NS_DECL_NSIHTTPNOTIFY
// nsCookieHTTPNotify methods:
nsCookieHTTPNotify();
virtual ~nsCookieHTTPNotify();
static nsresult Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info);
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info);
private:
nsCOMPtr<nsICookieService> mCookieService;
NS_IMETHOD SetupCookieService();
};
#endif /* nsCookieHTTPNotify_h___ */

Просмотреть файл

@ -45,7 +45,6 @@
#include "nsImgManager.h"
#include "nsPermissionManager.h"
#include "nsPopupWindowManager.h"
#include "nsCookieHTTPNotify.h"
#include "nsICategoryManager.h"
#include "nsCookiePromptService.h"
#include "nsCookiePermission.h"
@ -56,7 +55,6 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsCookieService, nsCookieService::GetSi
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsImgManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPermissionManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPopupWindowManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookiePermission)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookiePromptService)
@ -129,14 +127,7 @@ static const nsModuleComponentInfo components[] = {
NS_COOKIEPERMISSION_CID,
NS_COOKIEPERMISSION_CONTRACTID,
nsCookiePermissionConstructor
},
{ NS_COOKIEHTTPNOTIFY_CLASSNAME,
NS_COOKIEHTTPNOTIFY_CID,
NS_COOKIEHTTPNOTIFY_CONTRACTID,
nsCookieHTTPNotifyConstructor,
nsCookieHTTPNotify::RegisterProc,
nsCookieHTTPNotify::UnregisterProc
},
}
};
NS_IMPL_NSGETMODULE(nsCookieModule, components)

Просмотреть файл

@ -46,4 +46,14 @@ interface nsIHttpChannelInternal : nsISupports
* Get the major/minor version numbers for the response
*/
void getResponseVersion(out unsigned long major, out unsigned long minor);
/**
* Helper method to set a cookie with a consumer-provided
* cookie header, _but_ using the channel's other information
* (URI's, prompters, date headers etc).
*
* @param aCookieHeader
* The cookie header to be parsed.
*/
void setCookie(in string aCookieHeader);
};

Просмотреть файл

@ -49,6 +49,7 @@
#include "plstr.h"
#include "prprf.h"
#include "nsEscape.h"
#include "nsICookieService.h"
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
@ -545,6 +546,24 @@ nsHttpChannel::SetupTransaction()
return rv;
}
void
nsHttpChannel::AddCookiesToRequest()
{
nsXPIDLCString cookie;
nsICookieService *cs = gHttpHandler->GetCookieService();
if (cs)
cs->GetCookieStringFromHttp(mURI,
mDocumentURI ? mDocumentURI : mOriginalURI,
this,
getter_Copies(cookie));
// overwrite any existing cookie headers. be sure to clear any
// existing cookies if we have no cookies to set or if the cookie
// service is unavailable.
mRequestHead.SetHeader(nsHttp::Cookie, cookie, PR_FALSE);
}
void
nsHttpChannel::ApplyContentConversions()
{
@ -635,6 +654,9 @@ nsHttpChannel::ProcessResponse()
LOG(("nsHttpChannel::ProcessResponse [this=%x httpStatus=%u]\n",
this, httpStatus));
// set cookies, if any exist
SetCookie(mResponseHead->PeekHeader(nsHttp::Set_Cookie));
// notify nsIHttpNotify implementations
rv = gHttpHandler->OnExamineResponse(this);
NS_ASSERTION(NS_SUCCEEDED(rv), "OnExamineResponse failed");
@ -2682,6 +2704,9 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
if (NS_FAILED(rv))
return rv;
// fetch cookies, and add them to the request header
AddCookiesToRequest();
// Notify nsIHttpNotify implementations
rv = gHttpHandler->OnModifyRequest(this);
NS_ASSERTION(NS_SUCCEEDED(rv), "OnModifyRequest failed");
@ -2727,22 +2752,6 @@ nsHttpChannel::SetRequestMethod(const nsACString &method)
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetDocumentURI(nsIURI **aDocumentURI)
{
NS_ENSURE_ARG_POINTER(aDocumentURI);
*aDocumentURI = mDocumentURI;
NS_IF_ADDREF(*aDocumentURI);
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::SetDocumentURI(nsIURI *aDocumentURI)
{
mDocumentURI = aDocumentURI;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetReferrer(nsIURI **referrer)
{
@ -3037,14 +3046,9 @@ nsHttpChannel::SetResponseHeader(const nsACString &header,
atom == nsHttp::Transfer_Encoding)
return NS_ERROR_ILLEGAL_VALUE;
nsresult rv = mResponseHead->SetHeader(atom, value, merge);
// XXX temporary hack until http supports some form of a header change observer
if ((atom == nsHttp::Set_Cookie) && NS_SUCCEEDED(rv))
rv = gHttpHandler->OnExamineResponse(this);
mResponseHeadersModified = PR_TRUE;
return rv;
return mResponseHead->SetHeader(atom, value, merge);
}
NS_IMETHODIMP
@ -3139,6 +3143,75 @@ nsHttpChannel::GetContentEncodings(nsISimpleEnumerator** aEncodings)
return CallQueryInterface(enumerator, aEncodings);
}
//-----------------------------------------------------------------------------
// nsHttpChannel::nsIHttpChannelInternal
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsHttpChannel::GetDocumentURI(nsIURI **aDocumentURI)
{
NS_ENSURE_ARG_POINTER(aDocumentURI);
*aDocumentURI = mDocumentURI;
NS_IF_ADDREF(*aDocumentURI);
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::SetDocumentURI(nsIURI *aDocumentURI)
{
mDocumentURI = aDocumentURI;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetRequestVersion(PRUint32 *major, PRUint32 *minor)
{
int version = mRequestHead.Version();
if (major) { *major = version / 10; }
if (minor) { *minor = version % 10; }
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetResponseVersion(PRUint32 *major, PRUint32 *minor)
{
if (!mResponseHead)
{
*major = *minor = 0; // we should at least be kind about it
return NS_ERROR_NOT_AVAILABLE;
}
int version = mResponseHead->Version();
if (major) { *major = version / 10; }
if (minor) { *minor = version % 10; }
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::SetCookie(const char *aCookieHeader)
{
// empty header isn't an error
if (!(aCookieHeader && *aCookieHeader))
return NS_OK;
nsICookieService *cs = gHttpHandler->GetCookieService();
NS_ENSURE_TRUE(cs, NS_ERROR_FAILURE);
nsCOMPtr<nsIPrompt> prompt;
GetCallback(NS_GET_IID(nsIPrompt), getter_AddRefs(prompt));
return cs->SetCookieStringFromHttp(mURI,
mDocumentURI ? mDocumentURI : mOriginalURI,
prompt,
aCookieHeader,
mResponseHead->PeekHeader(nsHttp::Date),
this);
}
//-----------------------------------------------------------------------------
// nsHttpChannel::nsIRequestObserver
//-----------------------------------------------------------------------------
@ -3540,9 +3613,12 @@ nsHttpChannel::DoAuthRetry(nsAHttpConnection *conn)
// the request headers (bug 95044).
mIsPending = PR_FALSE;
// notify nsIHttpNotify implementations.. the server response could
// have included cookies that must be sent with this authentication
// attempt (bug 84794).
// fetch cookies, and add them to the request header.
// the server response could have included cookies that must be sent with
// this authentication attempt (bug 84794).
AddCookiesToRequest();
// notify nsIHttpNotify implementations
rv = gHttpHandler->OnModifyRequest(this);
NS_ASSERTION(NS_SUCCEEDED(rv), "OnModifyRequest failed");
@ -3716,32 +3792,3 @@ nsHttpChannel::nsContentEncodings::PrepareForNext(void)
mReady = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetRequestVersion(PRUint32 *major, PRUint32 *minor)
{
int version = mRequestHead.Version();
if (major) { *major = version / 10; }
if (minor) { *minor = version % 10; }
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetResponseVersion(PRUint32 *major, PRUint32 *minor)
{
if (!mResponseHead)
{
*major = *minor = 0; // we should at least be kind about it
return NS_ERROR_NOT_AVAILABLE;
}
int version = mResponseHead->Version();
if (major) { *major = version / 10; }
if (minor) { *minor = version % 10; }
return NS_OK;
}

Просмотреть файл

@ -110,6 +110,7 @@ private:
nsresult Connect(PRBool firstTime = PR_TRUE);
nsresult AsyncAbort(nsresult status);
nsresult SetupTransaction();
void AddCookiesToRequest();
void ApplyContentConversions();
nsresult CallOnStartRequest();
nsresult ProcessResponse();

Просмотреть файл

@ -77,6 +77,7 @@ extern PRThread *gSocketThread;
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kNetModuleMgrCID, NS_NETMODULEMGR_CID);
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID);
@ -453,6 +454,14 @@ nsHttpHandler::GetStreamConverterService(nsIStreamConverterService **result)
return NS_OK;
}
nsICookieService *
nsHttpHandler::GetCookieService()
{
if (!mCookieService)
mCookieService = do_GetService(kCookieServiceCID);
return mCookieService;
}
nsresult
nsHttpHandler::GetMimeService(nsIMIMEService **result)
{

Просмотреть файл

@ -45,6 +45,7 @@
#include "nsIStreamConverterService.h"
#include "nsICacheSession.h"
#include "nsIEventQueueService.h"
#include "nsICookieService.h"
#include "nsIMIMEService.h"
#include "nsIIDNService.h"
#include "nsITimer.h"
@ -146,7 +147,7 @@ public:
nsresult GetStreamConverterService(nsIStreamConverterService **);
nsresult GetMimeService(nsIMIMEService **);
nsresult GetIOService(nsIIOService** service);
nsICookieService * GetCookieService(); // not addrefed
// Called by the channel before writing a request
nsresult OnModifyRequest(nsIHttpChannel *);
@ -184,6 +185,7 @@ private:
nsCOMPtr<nsIEventQueueService> mEventQueueService;
nsCOMPtr<nsINetModuleMgr> mNetModuleMgr;
nsCOMPtr<nsIStreamConverterService> mStreamConvSvc;
nsCOMPtr<nsICookieService> mCookieService;
nsCOMPtr<nsIMIMEService> mMimeService;
nsCOMPtr<nsIIDNService> mIDNConverter;
nsCOMPtr<nsITimer> mTimer;

Просмотреть файл

@ -46,6 +46,7 @@
#include "nsReadableUtils.h"
#include "nsIMultiPartChannel.h"
#include "nsCRT.h"
#include "nsIHttpChannelInternal.h"
//
// Helper function for determining the length of data bytes up to
@ -924,13 +925,10 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
} else if (headerStr.EqualsIgnoreCase("content-disposition")) {
mContentDisposition = headerVal;
} else if (headerStr.EqualsIgnoreCase("set-cookie")) {
// setting headers on the HTTP channel
// causes HTTP to notify, again if necessary,
// it's header observers.
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
rv = httpChannel->SetResponseHeader(headerStr, headerVal, PR_TRUE);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIHttpChannelInternal> httpInternal =
do_QueryInterface(aChannel);
if (httpInternal) {
httpInternal->SetCookie(headerVal.get());
}
} else if (headerStr.EqualsIgnoreCase("content-range") ||
headerStr.EqualsIgnoreCase("range") ) {