1999-11-23 07:54:25 +00:00
|
|
|
/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1999-06-10 22:08:59 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* 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/
|
1999-06-10 22:08:59 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* 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.
|
1999-06-10 22:08:59 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-06-10 22:08:59 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-06-10 22:08:59 +00:00
|
|
|
*/
|
|
|
|
|
2000-08-03 07:00:14 +00:00
|
|
|
#ifdef DEBUG_dp
|
1999-06-10 22:08:59 +00:00
|
|
|
#include <stdio.h>
|
2000-08-03 07:00:14 +00:00
|
|
|
#endif
|
|
|
|
|
1999-06-10 22:08:59 +00:00
|
|
|
#include "nsCookieHTTPNotify.h"
|
1999-11-23 21:57:05 +00:00
|
|
|
#include "nsIGenericFactory.h"
|
1999-06-10 22:08:59 +00:00
|
|
|
#include "nsIHTTPChannel.h"
|
|
|
|
#include "nsCookie.h"
|
1999-06-12 00:01:52 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-10 22:08:59 +00:00
|
|
|
#include "nsCRT.h"
|
1999-08-27 10:16:52 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-11-29 22:02:20 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsINetModuleMgr.h"
|
1999-12-18 05:48:26 +00:00
|
|
|
#include "nsILoadGroup.h"
|
2000-01-22 22:46:13 +00:00
|
|
|
#include "nsICategoryManager.h"
|
2000-02-08 06:34:05 +00:00
|
|
|
#include "nsIHTTPProtocolHandler.h" // for NS_HTTP_STARTUP_CATEGORY
|
2000-06-30 01:23:16 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2000-06-16 14:56:47 +00:00
|
|
|
#include "nsIPrompt.h"
|
1999-11-29 22:02:20 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kINetModuleMgrCID, NS_NETMODULEMGR_CID);
|
1999-06-10 22:08:59 +00:00
|
|
|
|
|
|
|
///////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
1999-11-23 22:05:18 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsCookieHTTPNotify, nsIHTTPNotify, nsINetNotify);
|
1999-06-10 22:08:59 +00:00
|
|
|
|
|
|
|
///////////////////////////////////
|
|
|
|
// nsCookieHTTPNotify Implementation
|
|
|
|
|
1999-11-23 21:57:05 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
|
|
|
|
|
2000-01-22 22:46:13 +00:00
|
|
|
nsresult nsCookieHTTPNotify::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
1999-11-23 07:54:25 +00:00
|
|
|
{
|
2000-01-22 22:46:13 +00:00
|
|
|
return nsCookieHTTPNotifyConstructor(aOuter, aIID, aResult);
|
1999-06-10 22:08:59 +00:00
|
|
|
}
|
|
|
|
|
2000-01-31 22:57:28 +00:00
|
|
|
NS_METHOD nsCookieHTTPNotify::RegisterProc(nsIComponentManager *aCompMgr,
|
|
|
|
nsIFile *aPath,
|
|
|
|
const char *registryLocation,
|
2001-03-12 20:43:02 +00:00
|
|
|
const char *componentType,
|
|
|
|
const nsModuleComponentInfo *info)
|
1999-11-23 07:54:25 +00:00
|
|
|
{
|
2000-01-22 22:46:13 +00:00
|
|
|
// Register ourselves into the NS_CATEGORY_HTTP_STARTUP
|
|
|
|
nsresult rv;
|
2000-09-14 23:20:49 +00:00
|
|
|
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv);
|
2000-01-22 22:46:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString prevEntry;
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = catman->AddCategoryEntry(NS_HTTP_STARTUP_CATEGORY, "Http Cookie Notify", NS_COOKIEHTTPNOTIFY_CONTRACTID,
|
2000-01-22 22:46:13 +00:00
|
|
|
PR_TRUE, PR_TRUE, getter_Copies(prevEntry));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-01-31 22:57:28 +00:00
|
|
|
NS_METHOD nsCookieHTTPNotify::UnregisterProc(nsIComponentManager *aCompMgr,
|
|
|
|
nsIFile *aPath,
|
2001-03-12 20:43:02 +00:00
|
|
|
const char *registryLocation,
|
|
|
|
const nsModuleComponentInfo *info)
|
2000-01-22 22:46:13 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-09-14 23:20:49 +00:00
|
|
|
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv);
|
2000-01-22 22:46:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString prevEntry;
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = catman->DeleteCategoryEntry(NS_HTTP_STARTUP_CATEGORY, NS_COOKIEHTTPNOTIFY_CONTRACTID, PR_TRUE,
|
2000-01-22 22:46:13 +00:00
|
|
|
getter_Copies(prevEntry));
|
|
|
|
|
|
|
|
// Return value is not used from this function.
|
|
|
|
return NS_OK;
|
1999-06-10 22:08:59 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 21:57:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCookieHTTPNotify::Init()
|
1999-11-23 07:54:25 +00:00
|
|
|
{
|
2000-04-12 05:26:59 +00:00
|
|
|
mCookieHeader = getter_AddRefs(NS_NewAtom("Cookie"));
|
1999-11-23 21:57:05 +00:00
|
|
|
if (!mCookieHeader) return NS_ERROR_OUT_OF_MEMORY;
|
1999-12-06 23:28:26 +00:00
|
|
|
mSetCookieHeader = getter_AddRefs(NS_NewAtom("set-cookie"));
|
1999-11-23 21:57:05 +00:00
|
|
|
if (!mSetCookieHeader) return NS_ERROR_OUT_OF_MEMORY;
|
1999-12-06 23:28:26 +00:00
|
|
|
mExpiresHeader = getter_AddRefs(NS_NewAtom("date"));
|
1999-11-23 21:57:05 +00:00
|
|
|
if (!mExpiresHeader) return NS_ERROR_OUT_OF_MEMORY;
|
1999-11-29 22:02:20 +00:00
|
|
|
|
|
|
|
// Register to handing http requests and responses
|
2000-01-22 22:46:13 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-29 22:02:20 +00:00
|
|
|
nsCOMPtr<nsINetModuleMgr> pNetModuleMgr = do_GetService(kINetModuleMgrCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_CONTRACTID,
|
1999-11-29 22:02:20 +00:00
|
|
|
(nsIHTTPNotify *)this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_CONTRACTID,
|
1999-11-29 22:02:20 +00:00
|
|
|
(nsIHTTPNotify *)this);
|
2000-01-22 22:46:13 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-11-29 22:02:20 +00:00
|
|
|
|
2000-01-22 22:46:13 +00:00
|
|
|
nsCookieHTTPNotify::nsCookieHTTPNotify()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mCookieService = nsnull;
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG_dp
|
|
|
|
printf("CookieHTTPNotify Created.\n");
|
|
|
|
#endif /* DEBUG_dp */
|
1999-06-10 22:08:59 +00:00
|
|
|
}
|
|
|
|
|
1999-11-23 21:57:05 +00:00
|
|
|
nsCookieHTTPNotify::~nsCookieHTTPNotify()
|
1999-11-23 07:54:25 +00:00
|
|
|
{
|
1999-10-04 14:08:52 +00:00
|
|
|
}
|
|
|
|
|
1999-11-29 22:02:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCookieHTTPNotify::SetupCookieService()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mCookieService)
|
1999-12-17 00:42:33 +00:00
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
mCookieService = do_GetService(NS_COOKIESERVICE_CONTRACTID, &rv);
|
1999-12-17 00:42:33 +00:00
|
|
|
}
|
1999-11-29 22:02:20 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-10 22:08:59 +00:00
|
|
|
///////////////////////////////////
|
|
|
|
// nsIHTTPNotify
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-23 07:54:25 +00:00
|
|
|
nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-11-29 22:02:20 +00:00
|
|
|
// Preconditions
|
|
|
|
NS_ENSURE_ARG_POINTER(aContext);
|
1999-11-23 21:57:05 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHTTPChannel> pHTTPConnection = do_QueryInterface(aContext, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-12-18 05:48:26 +00:00
|
|
|
// Get the url
|
1999-11-23 21:57:05 +00:00
|
|
|
nsCOMPtr<nsIURI> pURL;
|
|
|
|
rv = pHTTPConnection->GetURI(getter_AddRefs(pURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-12-18 05:48:26 +00:00
|
|
|
// Get the original url that the user either typed in or clicked on
|
|
|
|
nsCOMPtr<nsILoadGroup> pLoadGroup;
|
|
|
|
rv = pHTTPConnection->GetLoadGroup(getter_AddRefs(pLoadGroup));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> pChannel;
|
1999-12-19 03:44:34 +00:00
|
|
|
if (pLoadGroup) {
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIRequest> pRequest;
|
|
|
|
rv = pLoadGroup->GetDefaultLoadRequest(getter_AddRefs(pRequest));
|
|
|
|
if (pRequest)
|
|
|
|
pChannel = do_QueryInterface(pRequest);
|
1999-12-19 03:44:34 +00:00
|
|
|
}
|
1999-12-18 05:48:26 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> pFirstURL;
|
|
|
|
if (pChannel) {
|
|
|
|
rv = pChannel->GetURI(getter_AddRefs(pFirstURL));
|
|
|
|
} else {
|
|
|
|
rv = pHTTPConnection->GetURI(getter_AddRefs(pFirstURL));
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-29 22:02:20 +00:00
|
|
|
// Ensure that the cookie service exists
|
|
|
|
rv = SetupCookieService();
|
1999-11-23 21:57:05 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
Landing changes Vidur made while the tree was closed for beta1 work, here's a list of the changes. r=me
[1] Cutting down the size of content. Made nsIJSScriptObject inherit from nsIScriptObjectOwner
[2] Cutting down the size of content. Made nsITextContent inherit from nsIContent.
[3] Cutting down the size of content. Moved implementation of nsIDOMReceiver to nsListenerManager. This is not true aggregation since it isn't transitive, but it's OK for now. It will be necessary for nsListenerManager to have a reference to its content in the future anyway, so the transitivity could be done.
dom/public/nsDOMPropEnums.h,v - bug 12559
dom/public/nsIJSScriptObject.h,v - [1]
dom/public/html/MANIFEST,v - bug 12559
dom/public/html/Makefile.in,v - bug 12559
dom/public/html/makefile.win,v - bug 12559
dom/public/html/nsIDOMHTMLInputElement.h,v - bug 17544
dom/public/idl/html/HTMLAnchorElement.idl,v - bug 12559
dom/public/idl/html/HTMLAreaElement.idl,v - bug 12559
dom/public/idl/html/HTMLInputElement.idl,v - bug 17544
dom/src/base/nsGlobalWindow.cpp,v - bug 30700
dom/src/base/nsGlobalWindow.h,v - [1]
dom/src/base/nsLocation.cpp,v - [1]
dom/src/html/nsJSHTMLAnchorElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLAreaElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLInputElement.cpp,v - bug 17544
layout/base/public/nsIDocument.h,v - bug 27953
layout/base/public/nsITextContent.h,v - [2]
layout/base/src/nsCommentNode.cpp,v - [2]
layout/base/src/nsDocument.cpp,v - bug 27953
layout/base/src/nsDocument.h,v - bug 27953
layout/base/src/nsDocumentViewer.cpp,v - bug 27953
layout/base/src/nsGenericDOMDataNode.cpp,v - [3]
layout/base/src/nsGenericDOMDataNode.h,v - [3]
layout/base/src/nsGenericElement.cpp,v - [3]
layout/base/src/nsGenericElement.h,v - [3]
layout/base/src/nsNameSpaceManager.cpp,v - bug 7834
layout/base/src/nsStyleContext.cpp,v - outline property shouldn't reflow
layout/base/src/nsTextNode.cpp,v - [2]
layout/events/src/nsEventListenerManager.cpp,v - [3]
layout/events/src/nsEventListenerManager.h,v - [3]
layout/html/base/src/nsGfxScrollFrame.cpp,v - nsString->nsAutoString
layout/html/content/src/nsAttributeContent.cpp,v - [2]
layout/html/content/src/nsHTMLAnchorElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAppletElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBodyElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLButtonElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDirectoryElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDivElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLEmbedElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFieldSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFormElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadingElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHtmlElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLImageElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInputElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInsElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIsIndexElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLIElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLabelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLayerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLegendElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLinkElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMapElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMenuElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMetaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLModElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLObjectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParagraphElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParamElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLPreElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLQuoteElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLScriptElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSelectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpacerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpanElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLStyleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCaptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCellElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableRowElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableSectionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTextAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTitleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLUListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLWBRElement.cpp,v - [1][3]
layout/html/document/src/nsHTMLDocument.cpp,v - bug 27953
layout/html/document/src/nsHTMLDocument.h,v - bug 27953
layout/xml/content/src/nsXMLCDATASection.cpp,v - [1][2]
layout/xml/content/src/nsXMLDocumentType.cpp,v - [1][2]
layout/xml/content/src/nsXMLElement.h,v - [1][2]
layout/xml/content/src/nsXMLEntity.cpp,v - [1][2]
layout/xml/content/src/nsXMLNotation.cpp,v - [1][2]
layout/xml/content/src/nsXMLProcessingInstruction.cpp,v - [1][2]
layout/xul/base/src/nsBoxFrame.cpp,v - nsString->nsAutoString
layout/xul/base/src/nsSliderFrame.cpp,v - nsString->nsAutoString
netwerk/protocol/http/src/nsHTTPRequest.cpp,v - nsString->nsAutoString
rdf/content/src/nsXULDocument.cpp,v - bug 27953
rdf/content/src/nsXULDocument.h,v - bug 27953
rdf/content/src/nsXULElement.h,v - [1]
xpcom/base/IIDS.h,v - bug 12559
2000-03-17 13:27:00 +00:00
|
|
|
nsAutoString cookie;
|
1999-12-18 05:48:26 +00:00
|
|
|
rv = mCookieService->GetCookieStringFromHTTP(pURL, pFirstURL, cookie);
|
1999-11-23 21:57:05 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-29 22:02:20 +00:00
|
|
|
// Set the cookie into the request headers
|
|
|
|
// XXX useless convertion from nsString to char * again
|
|
|
|
const char *cookieRaw = cookie.ToNewCString();
|
|
|
|
if (!cookieRaw) return NS_ERROR_OUT_OF_MEMORY;
|
1999-12-03 07:01:23 +00:00
|
|
|
|
|
|
|
// only set a cookie header if we have a value to send
|
|
|
|
if (*cookieRaw)
|
|
|
|
rv = pHTTPConnection->SetRequestHeader(mCookieHeader, cookieRaw);
|
2000-06-03 09:46:12 +00:00
|
|
|
nsMemory::Free((void *)cookieRaw);
|
1999-11-29 22:02:20 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-11-23 07:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-11-29 22:02:20 +00:00
|
|
|
// Preconditions
|
1999-11-23 21:57:05 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aContext);
|
|
|
|
|
1999-12-07 02:06:25 +00:00
|
|
|
nsCOMPtr<nsIHTTPChannel> pHTTPConnection = do_QueryInterface(aContext, &rv);
|
1999-11-23 21:57:05 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Get the Cookie header
|
1999-11-29 22:02:20 +00:00
|
|
|
nsXPIDLCString cookieHeader;
|
|
|
|
rv = pHTTPConnection->GetResponseHeader(mSetCookieHeader, getter_Copies(cookieHeader));
|
1999-11-23 21:57:05 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-08-03 07:00:14 +00:00
|
|
|
if (!cookieHeader) return NS_OK; // not an error, there's just no header.
|
1999-11-23 21:57:05 +00:00
|
|
|
|
1999-11-29 22:02:20 +00:00
|
|
|
// Get the url
|
1999-11-23 21:57:05 +00:00
|
|
|
nsCOMPtr<nsIURI> pURL;
|
|
|
|
rv = pHTTPConnection->GetURI(getter_AddRefs(pURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-29 22:02:20 +00:00
|
|
|
|
1999-12-18 05:48:26 +00:00
|
|
|
// Get the original url that the user either typed in or clicked on
|
|
|
|
nsCOMPtr<nsILoadGroup> pLoadGroup;
|
|
|
|
rv = pHTTPConnection->GetLoadGroup(getter_AddRefs(pLoadGroup));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsIChannel> pChannel;
|
1999-12-19 03:44:34 +00:00
|
|
|
if (pLoadGroup) {
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIRequest> pRequest;
|
|
|
|
rv = pLoadGroup->GetDefaultLoadRequest(getter_AddRefs(pRequest));
|
1999-12-19 03:44:34 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-02-21 20:38:08 +00:00
|
|
|
pChannel = do_QueryInterface(pRequest);
|
1999-12-19 03:44:34 +00:00
|
|
|
}
|
1999-12-18 05:48:26 +00:00
|
|
|
nsCOMPtr<nsIURI> pFirstURL;
|
|
|
|
if (pChannel) {
|
|
|
|
rv = pChannel->GetURI(getter_AddRefs(pFirstURL));
|
|
|
|
} else {
|
|
|
|
rv = pHTTPConnection->GetURI(getter_AddRefs(pFirstURL));
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-09-14 14:49:30 +00:00
|
|
|
// Get the prompter
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> pInterfaces;
|
|
|
|
nsCOMPtr<nsIPrompt> pPrompter;
|
|
|
|
if (pChannel) {
|
|
|
|
pChannel->GetNotificationCallbacks(getter_AddRefs(pInterfaces));
|
|
|
|
} else {
|
|
|
|
pHTTPConnection->GetNotificationCallbacks(getter_AddRefs(pInterfaces));
|
|
|
|
}
|
|
|
|
if (pInterfaces)
|
|
|
|
pInterfaces->GetInterface(NS_GET_IID(nsIPrompt), getter_AddRefs(pPrompter));
|
|
|
|
|
1999-11-23 21:57:05 +00:00
|
|
|
// Get the expires
|
1999-11-29 22:02:20 +00:00
|
|
|
nsXPIDLCString expiresHeader;
|
|
|
|
rv = pHTTPConnection->GetResponseHeader(mExpiresHeader, getter_Copies(expiresHeader));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Ensure that we have the cookie service
|
|
|
|
rv = SetupCookieService();
|
1999-11-23 21:57:05 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Save the cookie
|
2000-06-16 14:56:47 +00:00
|
|
|
rv = mCookieService->SetCookieStringFromHttp(pURL, pFirstURL, pPrompter, cookieHeader, expiresHeader);
|
1999-11-23 21:57:05 +00:00
|
|
|
|
1999-11-29 22:02:20 +00:00
|
|
|
return rv;
|
1999-06-10 22:08:59 +00:00
|
|
|
}
|
|
|
|
|