diff --git a/mozilla/content/build/Makefile.in b/mozilla/content/build/Makefile.in index d38d245cf5d..9ce3344e3e1 100644 --- a/mozilla/content/build/Makefile.in +++ b/mozilla/content/build/Makefile.in @@ -39,13 +39,14 @@ CPPSRCS = \ nsContentDLF.cpp \ nsContentFactory.cpp \ nsContentModule.cpp \ + nsContentHTTPStartup.cpp \ $(NULL) ifndef MKSHLIB_FORCE_ALL CPPSRCS += dlldeps.cpp endif -EXPORTS = nsContentCID.h $(BUILD_DATE) +EXPORTS = nsContentCID.h SHARED_LIBRARY_LIBS = \ $(DIST)/lib/libgkconevents_s.$(LIB_SUFFIX) \ @@ -95,7 +96,7 @@ INCLUDES += -I$(srcdir)/../base/src \ GARBAGE+=$(BUILD_DATE) -$(BUILD_DATE): +$(BUILD_DATE): gbdate.pl $(RM) $@ $(PERL) $(srcdir)/gbdate.pl > $@ diff --git a/mozilla/content/build/gbdate.pl b/mozilla/content/build/gbdate.pl index abba8b57b0a..04832989f07 100755 --- a/mozilla/content/build/gbdate.pl +++ b/mozilla/content/build/gbdate.pl @@ -24,4 +24,4 @@ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; # localtime returns year minus 1900 $year = $year + 1900; -printf("#define PRODUCT_VERSION \"%04d%02d%02d\"\n", $year, 1+$mon, $mday); +printf("#define PRODUCT_VERSION NS_LITERAL_STRING(\"%04d%02d%02d\").get()\n", $year, 1+$mon, $mday); diff --git a/mozilla/content/build/makefile.win b/mozilla/content/build/makefile.win index 02711cc4dc1..cc884f95c99 100644 --- a/mozilla/content/build/makefile.win +++ b/mozilla/content/build/makefile.win @@ -27,13 +27,12 @@ DEFINES=-D_IMPL_NS_HTML MODULE=raptor IS_COMPONENT = 1 -CPPSRCS=dlldeps.cpp nsContentDLF.cpp nsContentFactory.cpp nsContentModule.cpp - CPP_OBJS= \ .\$(OBJDIR)\dlldeps.obj \ .\$(OBJDIR)\nsContentDLF.obj \ .\$(OBJDIR)\nsContentFactory.obj \ .\$(OBJDIR)\nsContentModule.obj \ + .\$(OBJDIR)\nsContentHTTPStartup.obj \ $(NULL) EXPORTS=nsContentCID.h @@ -93,14 +92,7 @@ clobber:: rm -f $(DIST)\lib\$(DLLNAME).lib rm -f gbdate.h -!if !EXIST ( gbdate.h ) - -gbdate.h:: +gbdate.h:: gbdate.pl $(PERL) gbdate.pl > gbdate.h -!else - -gbdate.h:: - -!endif diff --git a/mozilla/content/build/nsContentHTTPStartup.cpp b/mozilla/content/build/nsContentHTTPStartup.cpp new file mode 100644 index 00000000000..9a495f62e3c --- /dev/null +++ b/mozilla/content/build/nsContentHTTPStartup.cpp @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Alec Flett + */ + +#include "nsIServiceManager.h" +#include "nsICategoryManager.h" + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsXPIDLString.h" + +#include "nsContentHTTPStartup.h" +#include "nsIHTTPProtocolHandler.h" +#include "gbdate.h" + +#define PRODUCT_NAME NS_LITERAL_STRING("Gecko").get() + +NS_IMPL_ISUPPORTS1(nsContentHTTPStartup,nsIObserver) + +nsresult +nsContentHTTPStartup::Observe( nsISupports *aSubject, + const PRUnichar *aTopic, + const PRUnichar *aData) +{ + if (nsCRT::strcmp(aTopic, NS_HTTP_STARTUP_TOPIC) != 0) + return NS_OK; + + nsresult rv = nsnull; + + nsCOMPtr http(do_QueryInterface(aSubject)); + if (NS_FAILED(rv)) return rv; + + rv = http->SetProduct(PRODUCT_NAME); + if (NS_FAILED(rv)) return rv; + + rv = http->SetProductSub(PRODUCT_VERSION); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +nsresult +nsContentHTTPStartup::RegisterHTTPStartup() +{ + nsresult rv; + nsCOMPtr + catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); + + if (NS_FAILED(rv)) return rv; + + nsXPIDLCString previousEntry; + rv = catMan->AddCategoryEntry(NS_HTTP_STARTUP_CATEGORY, + "Content UserAgent Setter", + NS_CONTENTHTTPSTARTUP_CONTRACTID, + PR_TRUE, PR_TRUE, + getter_Copies(previousEntry)); + return rv; +} + +nsresult +nsContentHTTPStartup::UnregisterHTTPStartup() +{ + nsresult rv; + nsCOMPtr + catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); + + if (NS_FAILED(rv)) return rv; + + + return NS_OK; +} diff --git a/mozilla/content/build/nsContentHTTPStartup.h b/mozilla/content/build/nsContentHTTPStartup.h new file mode 100644 index 00000000000..e6890cf2460 --- /dev/null +++ b/mozilla/content/build/nsContentHTTPStartup.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Alec Flett + */ + +#include "nsIObserver.h" + +#define NS_CONTENTHTTPSTARTUP_CONTRACTID \ + "@mozilla.org/content/http-startup;1" + +/* c2f6ef7e-afd5-4be4-a1f5-c824efa4231b */ +#define NS_CONTENTHTTPSTARTUP_CID \ +{ 0xc2f6ef7e, 0xafd5, 0x4be4, \ + {0xa1, 0xf5, 0xc8, 0x24, 0xef, 0xa4, 0x23, 0x1b} } + +class nsContentHTTPStartup : public nsIObserver +{ +public: + nsContentHTTPStartup() { NS_INIT_ISUPPORTS(); } + virtual ~nsContentHTTPStartup() {} + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + +public: + static nsresult RegisterHTTPStartup(); + static nsresult UnregisterHTTPStartup(); + +private: + nsresult setUserAgent(); + +}; diff --git a/mozilla/content/build/nsContentModule.cpp b/mozilla/content/build/nsContentModule.cpp index d10cf4536fd..e37ca1bcd3c 100644 --- a/mozilla/content/build/nsContentModule.cpp +++ b/mozilla/content/build/nsContentModule.cpp @@ -56,8 +56,7 @@ #include "nsRange.h" #include "nsGenericElement.h" -#include "nsIHTTPProtocolHandler.h" -#include "gbdate.h" +#include "nsContentHTTPStartup.h" #include "nsContentPolicyUtils.h" #define PRODUCT_NAME "Gecko" @@ -66,7 +65,6 @@ #include "nsXULContentUtils.h" #endif -static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID); static nsContentModule *gModule = NULL; extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, @@ -216,8 +214,6 @@ nsContentModule::Initialize() } } - SetUserAgent(); - return rv; } @@ -377,6 +373,8 @@ static Components gComponents[] = { #endif { "Controller Command Manager", NS_CONTROLLERCOMMANDMANAGER_CID, "@mozilla.org/content/controller-command-manager;1", }, + { "Content HTTP Startup Listener", NS_CONTENTHTTPSTARTUP_CID, + NS_CONTENTHTTPSTARTUP_CONTRACTID, }, }; #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) @@ -407,8 +405,11 @@ nsContentModule::RegisterSelf(nsIComponentManager *aCompMgr, cp++; } - rv = RegisterDocumentFactories(aCompMgr, aPath); + // not fatal if these fail + nsContentHTTPStartup::RegisterHTTPStartup(); + rv = RegisterDocumentFactories(aCompMgr, aPath); + return rv; } @@ -433,6 +434,7 @@ nsContentModule::UnregisterSelf(nsIComponentManager* aCompMgr, cp++; } + nsContentHTTPStartup::UnregisterHTTPStartup(); UnregisterDocumentFactories(aCompMgr, aPath); return NS_OK; @@ -448,20 +450,3 @@ nsContentModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) return NS_ERROR_FAILURE; } -void -nsContentModule::SetUserAgent( void ) -{ - nsString productName; productName.AssignWithConversion(PRODUCT_NAME); - nsString productVersion; productVersion.AssignWithConversion(PRODUCT_VERSION); - nsresult rv = nsnull; - - nsCOMPtr theService(do_GetService(kHTTPHandlerCID, - &rv)); - - if( NS_SUCCEEDED(rv) && (nsnull != theService) ) - { - rv = theService->SetProduct(productName.GetUnicode()); - - rv = theService->SetProductSub(productVersion.GetUnicode()); - } -} diff --git a/mozilla/content/build/nsContentModule.h b/mozilla/content/build/nsContentModule.h index dc21df7c381..87a16d5f8d2 100644 --- a/mozilla/content/build/nsContentModule.h +++ b/mozilla/content/build/nsContentModule.h @@ -50,8 +50,6 @@ protected: void UnregisterDocumentFactories(nsIComponentManager* aCompMgr, nsIFile* aPath); - void SetUserAgent(); - PRBool mInitialized; // static nsIFactory* gFactory; static nsIScriptNameSetRegistry* gRegistry; diff --git a/mozilla/layout/build/gbdate.pl b/mozilla/layout/build/gbdate.pl index abba8b57b0a..04832989f07 100755 --- a/mozilla/layout/build/gbdate.pl +++ b/mozilla/layout/build/gbdate.pl @@ -24,4 +24,4 @@ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; # localtime returns year minus 1900 $year = $year + 1900; -printf("#define PRODUCT_VERSION \"%04d%02d%02d\"\n", $year, 1+$mon, $mday); +printf("#define PRODUCT_VERSION NS_LITERAL_STRING(\"%04d%02d%02d\").get()\n", $year, 1+$mon, $mday); diff --git a/mozilla/layout/build/nsContentHTTPStartup.cpp b/mozilla/layout/build/nsContentHTTPStartup.cpp new file mode 100644 index 00000000000..9a495f62e3c --- /dev/null +++ b/mozilla/layout/build/nsContentHTTPStartup.cpp @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Alec Flett + */ + +#include "nsIServiceManager.h" +#include "nsICategoryManager.h" + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsXPIDLString.h" + +#include "nsContentHTTPStartup.h" +#include "nsIHTTPProtocolHandler.h" +#include "gbdate.h" + +#define PRODUCT_NAME NS_LITERAL_STRING("Gecko").get() + +NS_IMPL_ISUPPORTS1(nsContentHTTPStartup,nsIObserver) + +nsresult +nsContentHTTPStartup::Observe( nsISupports *aSubject, + const PRUnichar *aTopic, + const PRUnichar *aData) +{ + if (nsCRT::strcmp(aTopic, NS_HTTP_STARTUP_TOPIC) != 0) + return NS_OK; + + nsresult rv = nsnull; + + nsCOMPtr http(do_QueryInterface(aSubject)); + if (NS_FAILED(rv)) return rv; + + rv = http->SetProduct(PRODUCT_NAME); + if (NS_FAILED(rv)) return rv; + + rv = http->SetProductSub(PRODUCT_VERSION); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +nsresult +nsContentHTTPStartup::RegisterHTTPStartup() +{ + nsresult rv; + nsCOMPtr + catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); + + if (NS_FAILED(rv)) return rv; + + nsXPIDLCString previousEntry; + rv = catMan->AddCategoryEntry(NS_HTTP_STARTUP_CATEGORY, + "Content UserAgent Setter", + NS_CONTENTHTTPSTARTUP_CONTRACTID, + PR_TRUE, PR_TRUE, + getter_Copies(previousEntry)); + return rv; +} + +nsresult +nsContentHTTPStartup::UnregisterHTTPStartup() +{ + nsresult rv; + nsCOMPtr + catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); + + if (NS_FAILED(rv)) return rv; + + + return NS_OK; +} diff --git a/mozilla/layout/build/nsContentHTTPStartup.h b/mozilla/layout/build/nsContentHTTPStartup.h new file mode 100644 index 00000000000..e6890cf2460 --- /dev/null +++ b/mozilla/layout/build/nsContentHTTPStartup.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Alec Flett + */ + +#include "nsIObserver.h" + +#define NS_CONTENTHTTPSTARTUP_CONTRACTID \ + "@mozilla.org/content/http-startup;1" + +/* c2f6ef7e-afd5-4be4-a1f5-c824efa4231b */ +#define NS_CONTENTHTTPSTARTUP_CID \ +{ 0xc2f6ef7e, 0xafd5, 0x4be4, \ + {0xa1, 0xf5, 0xc8, 0x24, 0xef, 0xa4, 0x23, 0x1b} } + +class nsContentHTTPStartup : public nsIObserver +{ +public: + nsContentHTTPStartup() { NS_INIT_ISUPPORTS(); } + virtual ~nsContentHTTPStartup() {} + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + +public: + static nsresult RegisterHTTPStartup(); + static nsresult UnregisterHTTPStartup(); + +private: + nsresult setUserAgent(); + +};