From 577de718b39a5e4319b5b490e0d6506030fe3117 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 30 Sep 2002 23:18:43 +0000 Subject: [PATCH] Move documentURI to a new interface. b=157133. r=rpotts@netscape.com, sr=darin@netscape.com --- docshell/base/nsDocShell.cpp | 14 +++++-- extensions/cookie/nsCookieHTTPNotify.cpp | 15 ++++++- extensions/cookie/nsCookies.cpp | 10 ++++- modules/libpr0n/src/imgLoader.cpp | 10 ++++- netwerk/macbuild/netwerkIDL.xml | 30 ++++++++++++++ netwerk/protocol/http/public/MANIFEST_IDL | 6 --- netwerk/protocol/http/public/Makefile.in | 1 + .../protocol/http/public/nsIHttpChannel.idl | 5 --- .../http/public/nsIHttpChannelInternal.idl | 40 +++++++++++++++++++ netwerk/protocol/http/src/nsHttpChannel.cpp | 37 ++++++++++------- netwerk/protocol/http/src/nsHttpChannel.h | 4 ++ 11 files changed, 140 insertions(+), 32 deletions(-) create mode 100644 netwerk/protocol/http/public/nsIHttpChannelInternal.idl diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 45143b2f4ac..12a77c54e5e 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -58,6 +58,12 @@ #include "nsIPluginViewer.h" #include "nsContentPolicyUtils.h" // NS_CheckContentLoadPolicy(...) +// 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" + + // Local Includes #include "nsDocShell.h" #include "nsDocShellLoadInfo.h" @@ -5099,12 +5105,14 @@ nsDocShell::DoURILoad(nsIURI * aURI, channel->SetOriginalURI(aURI); + //hack nsCOMPtr httpChannel(do_QueryInterface(channel)); - if (httpChannel) { + nsCOMPtr httpChannelInternal(do_QueryInterface(channel)); + if (httpChannelInternal) { if (firstParty) { - httpChannel->SetDocumentURI(aURI); + httpChannelInternal->SetDocumentURI(aURI); } else { - httpChannel->SetDocumentURI(aReferrerURI); + httpChannelInternal->SetDocumentURI(aReferrerURI); } } diff --git a/extensions/cookie/nsCookieHTTPNotify.cpp b/extensions/cookie/nsCookieHTTPNotify.cpp index 8c6338f4b47..7e1651ce07e 100644 --- a/extensions/cookie/nsCookieHTTPNotify.cpp +++ b/extensions/cookie/nsCookieHTTPNotify.cpp @@ -58,6 +58,11 @@ #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); /////////////////////////////////// @@ -165,9 +170,12 @@ nsCookieHTTPNotify::OnModifyRequest(nsIHttpChannel *aHttpChannel) rv = aHttpChannel->GetURI(getter_AddRefs(pURL)); if (NS_FAILED(rv)) return rv; + nsCOMPtr 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 pFirstURL; - rv = aHttpChannel->GetDocumentURI(getter_AddRefs(pFirstURL)); + rv = httpInternal->GetDocumentURI(getter_AddRefs(pFirstURL)); if (NS_FAILED(rv)) return rv; if (!pFirstURL) { rv = aHttpChannel->GetOriginalURI(getter_AddRefs(pFirstURL)); @@ -213,9 +221,12 @@ nsCookieHTTPNotify::OnExamineResponse(nsIHttpChannel *aHttpChannel) rv = aHttpChannel->GetURI(getter_AddRefs(pURL)); if (NS_FAILED(rv)) return rv; + nsCOMPtr 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 pFirstURL; - rv = aHttpChannel->GetDocumentURI(getter_AddRefs(pFirstURL)); + rv = httpInternal->GetDocumentURI(getter_AddRefs(pFirstURL)); if (NS_FAILED(rv)) return rv; // Get the prompter diff --git a/extensions/cookie/nsCookies.cpp b/extensions/cookie/nsCookies.cpp index 3b648adfd97..f3d4c847845 100644 --- a/extensions/cookie/nsCookies.cpp +++ b/extensions/cookie/nsCookies.cpp @@ -56,6 +56,11 @@ #include "nsComObsolete.h" #include +// 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" + #define MAX_NUMBER_OF_COOKIES 300 #define MAX_COOKIES_PER_SERVER 20 #define MAX_BYTES_PER_COOKIE 4096 /* must be at least 1 */ @@ -1459,7 +1464,10 @@ COOKIE_SetCookieString(nsIURI * aURL, nsIPrompt *aPrompter, const char * setCook nsresult rv; if (aHttpChannel) { - rv = aHttpChannel->GetDocumentURI(getter_AddRefs(pFirstURL)); + nsCOMPtr httpInternal = do_QueryInterface(aHttpChannel); + if (!httpInternal) return; + + rv = httpInternal->GetDocumentURI(getter_AddRefs(pFirstURL)); if (NS_FAILED(rv)) return; } COOKIE_SetCookieStringFromHttp(aURL, pFirstURL, aPrompter, setCookieHeader, 0, aHttpChannel); diff --git a/modules/libpr0n/src/imgLoader.cpp b/modules/libpr0n/src/imgLoader.cpp index 596c1c64345..89f5f53fb67 100644 --- a/modules/libpr0n/src/imgLoader.cpp +++ b/modules/libpr0n/src/imgLoader.cpp @@ -43,6 +43,11 @@ #include "nsIComponentRegistrar.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" + #ifdef DEBUG_pavlov #include "nsIEnumerator.h" #include "nsXPCOM.h" @@ -194,7 +199,10 @@ static nsresult NewImageChannel(nsIChannel **aResult, NS_LITERAL_CSTRING("")); newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), NS_LITERAL_CSTRING("video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1")); - newHttpChannel->SetDocumentURI(aInitialDocumentURI); + + nsCOMPtr httpChannelInternal = do_QueryInterface(newHttpChannel); + NS_ENSURE_TRUE(httpChannelInternal, NS_ERROR_UNEXPECTED); + httpChannelInternal->SetDocumentURI(aInitialDocumentURI); newHttpChannel->SetReferrer(aReferringURI); } diff --git a/netwerk/macbuild/netwerkIDL.xml b/netwerk/macbuild/netwerkIDL.xml index f46c7035a66..73852844bf0 100644 --- a/netwerk/macbuild/netwerkIDL.xml +++ b/netwerk/macbuild/netwerkIDL.xml @@ -1085,6 +1085,13 @@ Text + + Name + nsIHTTPChannelInternal.idl + MacOS + Text + + Name nsIHttpHeaderVisitor.idl @@ -1689,6 +1696,11 @@ nsIHTTPChannel.idl MacOS + + Name + nsIHTTPChannelInternal.idl + MacOS + Name nsIHttpHeaderVisitor.idl @@ -3035,6 +3047,13 @@ Text + + Name + nsIHTTPChannelInternal.idl + MacOS + Text + + Name nsIHttpHeaderVisitor.idl @@ -3630,6 +3649,11 @@ nsIHTTPChannel.idl MacOS + + Name + nsIHTTPChannelInternal.idl + MacOS + Name nsIHttpHeaderVisitor.idl @@ -4469,6 +4493,12 @@ nsIHTTPChannel.idl MacOS + + headers + Name + nsIHTTPChannelInternal.idl + MacOS + headers Name diff --git a/netwerk/protocol/http/public/MANIFEST_IDL b/netwerk/protocol/http/public/MANIFEST_IDL index 389722cfbc5..e69de29bb2d 100644 --- a/netwerk/protocol/http/public/MANIFEST_IDL +++ b/netwerk/protocol/http/public/MANIFEST_IDL @@ -1,6 +0,0 @@ -nsIHttpChannel.idl -nsIHttpHeaderVisitor.idl -nsIHttpProtocolHandler.idl -nsIHttpAuthenticator.idl -nsIHttpNotify.idl -nsIHttpEventSink.idl diff --git a/netwerk/protocol/http/public/Makefile.in b/netwerk/protocol/http/public/Makefile.in index a88cd9413dd..c8e5a9429ad 100644 --- a/netwerk/protocol/http/public/Makefile.in +++ b/netwerk/protocol/http/public/Makefile.in @@ -31,6 +31,7 @@ XPIDL_MODULE = necko_http XPIDLSRCS = \ nsIHttpChannel.idl \ + nsIHttpChannelInternal.idl \ nsIHttpHeaderVisitor.idl \ nsIHttpNotify.idl \ nsIHttpProtocolHandler.idl \ diff --git a/netwerk/protocol/http/public/nsIHttpChannel.idl b/netwerk/protocol/http/public/nsIHttpChannel.idl index 4dfd42c322a..205b588cc59 100644 --- a/netwerk/protocol/http/public/nsIHttpChannel.idl +++ b/netwerk/protocol/http/public/nsIHttpChannel.idl @@ -46,11 +46,6 @@ interface nsIHttpChannel : nsIChannel */ attribute nsIURI referrer; - /** - * An http channel can own a reference to the document URI - */ - attribute nsIURI documentURI; - /** * Header strings are case insensitive. Setting a header is additive; to * clear a header, assign an empty string. diff --git a/netwerk/protocol/http/public/nsIHttpChannelInternal.idl b/netwerk/protocol/http/public/nsIHttpChannelInternal.idl new file mode 100644 index 00000000000..14c626acc05 --- /dev/null +++ b/netwerk/protocol/http/public/nsIHttpChannelInternal.idl @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface nsIURI; +/** + * Dumping ground for http. This interface will never be frozen. If you are + * using any feature exposed by this interface, be aware that this interface + * will change and you will be broken. You have been warned. + */ + +[scriptable, uuid(7552588e-d018-48a2-b67c-432414d0b64c)] +interface nsIHttpChannelInternal : nsISupports +{ + /** + * An http channel can own a reference to the document URI + */ + attribute nsIURI documentURI; + +}; diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index 9c120e32b43..986a085cc66 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -1536,14 +1536,17 @@ nsHttpChannel::ProcessRedirection(PRUint32 redirectType) nsCOMPtr httpChannel = do_QueryInterface(newChannel); if (httpChannel) { + nsCOMPtr httpInternal = do_QueryInterface(newChannel); + NS_ENSURE_TRUE(httpInternal, NS_ERROR_UNEXPECTED); + // update the DocumentURI indicator since we are being redirected. // if this was a top-level document channel, then the new channel // should have its mDocumentURI point to newURI; otherwise, we // just need to pass along our mDocumentURI to the new channel. if (newURI && (mURI == mDocumentURI)) - httpChannel->SetDocumentURI(newURI); + httpInternal->SetDocumentURI(newURI); else - httpChannel->SetDocumentURI(mDocumentURI); + httpInternal->SetDocumentURI(mDocumentURI); // convey the referrer if one was used for this channel to the next one if (mReferrer) httpChannel->SetReferrer(mReferrer); @@ -2075,18 +2078,24 @@ nsHttpChannel::GetCurrentPath(nsACString &path) // nsHttpChannel::nsISupports //----------------------------------------------------------------------------- -NS_IMPL_THREADSAFE_ISUPPORTS11(nsHttpChannel, - nsIRequest, - nsIChannel, - nsIRequestObserver, - nsIStreamListener, - nsIHttpChannel, - nsIInterfaceRequestor, - nsIProgressEventSink, - nsICachingChannel, - nsIUploadChannel, - nsICacheListener, - nsIEncodedChannel) +NS_IMPL_THREADSAFE_ADDREF(nsHttpChannel) +NS_IMPL_THREADSAFE_RELEASE(nsHttpChannel) + +NS_INTERFACE_MAP_BEGIN(nsHttpChannel) + NS_INTERFACE_MAP_ENTRY(nsIRequest) + NS_INTERFACE_MAP_ENTRY(nsIChannel) + NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) + NS_INTERFACE_MAP_ENTRY(nsIStreamListener) + NS_INTERFACE_MAP_ENTRY(nsIHttpChannel) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink) + NS_INTERFACE_MAP_ENTRY(nsICachingChannel) + NS_INTERFACE_MAP_ENTRY(nsIUploadChannel) + NS_INTERFACE_MAP_ENTRY(nsICacheListener) + NS_INTERFACE_MAP_ENTRY(nsIEncodedChannel) + NS_INTERFACE_MAP_ENTRY(nsIHttpChannelInternal) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel) +NS_INTERFACE_MAP_END //----------------------------------------------------------------------------- // nsHttpChannel::nsIRequest diff --git a/netwerk/protocol/http/src/nsHttpChannel.h b/netwerk/protocol/http/src/nsHttpChannel.h index 660e91a3247..8af2feb7655 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.h +++ b/netwerk/protocol/http/src/nsHttpChannel.h @@ -49,6 +49,8 @@ #include "nsXPIDLString.h" #include "nsHttpConnection.h" +#include "nsIHttpChannelInternal.h" + class nsHttpTransaction; class nsHttpResponseHead; class nsHttpAuthCache; @@ -67,6 +69,7 @@ class nsHttpChannel : public nsIHttpChannel , public nsIUploadChannel , public nsICacheListener , public nsIEncodedChannel + , public nsIHttpChannelInternal { public: NS_DECL_ISUPPORTS @@ -81,6 +84,7 @@ public: NS_DECL_NSIUPLOADCHANNEL NS_DECL_NSICACHELISTENER NS_DECL_NSIENCODEDCHANNEL + NS_DECL_NSIHTTPCHANNELINTERNAL nsHttpChannel(); virtual ~nsHttpChannel();