forked from mirrors/gecko-dev
		
	Make it possible for apps, extensions, and vendors to all add tokens to the User-Agent string (using default preferences) without overwriting each other. b=274928 r+sr=darin a=mkaply
This commit is contained in:
		
							parent
							
								
									06ee318b44
								
							
						
					
					
						commit
						5d312ec4b3
					
				
					 14 changed files with 64 additions and 22 deletions
				
			
		|  | @ -168,7 +168,7 @@ include $(topsrcdir)/config/static-rules.mk | |||
| endif | ||||
| 
 | ||||
| APP_VERSION = $(shell cat $(srcdir)/../config/version.txt) | ||||
| DEFINES += -DAPP_VERSION=\"$(APP_VERSION)\" | ||||
| DEFINES += -DAPP_VERSION="$(APP_VERSION)" | ||||
| 
 | ||||
| ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) | ||||
| ifdef BUILD_STATIC_LIBS | ||||
|  |  | |||
|  | @ -46,7 +46,7 @@ | |||
| static const nsXREAppData kAppData = { | ||||
|   "Mozilla", | ||||
|   "Firefox", | ||||
|   APP_VERSION, | ||||
|   NS_STRINGIFY(APP_VERSION), | ||||
|   NS_STRINGIFY(BUILD_ID), | ||||
|   // ec8030f7-c20a-464f-9b0e-13a3a9e97384
 | ||||
|   { 0xec8030f7, 0xc20a, 0x464f, { 0x9b, 0x0e, 0x13, 0xa3, 0xa9, 0xe9, 0x73, 0x84 } }, | ||||
|  |  | |||
|  | @ -129,8 +129,7 @@ pref("keyword.URL", "http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UT | |||
| 
 | ||||
| pref("general.useragent.locale", "@AB_CD@"); | ||||
| pref("general.skins.selectedSkin", "classic/1.0"); | ||||
| pref("general.useragent.vendor", "Firefox"); | ||||
| pref("general.useragent.vendorSub", @APP_VERSION@); | ||||
| pref("general.useragent.extra.firefox", "Firefox/@APP_VERSION@"); | ||||
| 
 | ||||
| pref("general.smoothScroll", false); | ||||
| #ifdef XP_UNIX | ||||
|  |  | |||
|  | @ -168,7 +168,7 @@ include $(topsrcdir)/config/static-rules.mk | |||
| endif | ||||
| 
 | ||||
| APP_VERSION = $(shell cat $(srcdir)/../config/version.txt) | ||||
| DEFINES += -DAPP_VERSION=\"$(APP_VERSION)\" | ||||
| DEFINES += -DAPP_VERSION="$(APP_VERSION)" | ||||
| 
 | ||||
| ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) | ||||
| ifdef BUILD_STATIC_LIBS | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ | |||
| static const nsXREAppData kAppData = { | ||||
|   "Mozilla", | ||||
|   "Sunbird", | ||||
|   APP_VERSION, | ||||
|   NS_STRINGIFY(APP_VERSION), | ||||
|   NS_STRINGIFY(BUILD_ID), | ||||
|   // {718e30fb-e89b-41dd-9da7-e25a45638b28}
 | ||||
|   { 0x718e30fb, 0xe89b, 0x41dd, { 0x9d, 0xa7, 0xe2, 0x5a, 0x45, 0x63, 0x8b, 0x28 } }, | ||||
|  |  | |||
|  | @ -81,10 +81,7 @@ pref("update.extensions.count", 0); | |||
| 
 | ||||
| pref("general.useragent.locale", "chrome://global/locale/intl.properties"); | ||||
| pref("general.useragent.contentlocale", "chrome://browser-region/locale/region.properties"); | ||||
| pref("general.useragent.vendor", "Mozilla Sunbird"); | ||||
| pref("general.useragent.vendorSub", | ||||
| #expand __APP_VERSION__ | ||||
| ); | ||||
| #expand pref("general.useragent.extra.sunbird", "Mozilla Sunbird/__APP_VERSION__"); | ||||
| 
 | ||||
| // Scripts & Windows prefs
 | ||||
| pref("dom.disable_open_during_load",        true); | ||||
|  |  | |||
|  | @ -36,8 +36,7 @@ | |||
|  * ***** END LICENSE BLOCK ***** */ | ||||
| 
 | ||||
| pref("general.skins.selectedSkin", "modern/1.0");  | ||||
| pref("general.useragent.vendor", "Mozilla (standalone) Composer"); | ||||
| pref("general.useragent.vendorSub", "0.0.1"); | ||||
| pref("general.useragent.extra.composer", "Mozilla (standalone) Composer/0.0.1"); | ||||
| 
 | ||||
| pref("general.startup.browser",             false); | ||||
| pref("general.startup.editor",              true); | ||||
|  |  | |||
|  | @ -91,6 +91,10 @@ ifneq (,$(filter gtk gtk2 xlib,$(MOZ_WIDGET_TOOLKIT))) | |||
| LIBS += $(XLDFLAGS) $(XLIBS) | ||||
| endif | ||||
| 
 | ||||
| ifdef MOZ_JPROF | ||||
| LIBS += -ljprof | ||||
| endif | ||||
| 
 | ||||
| ifndef MOZ_WINCONSOLE | ||||
| ifdef MOZ_DEBUG | ||||
| MOZ_WINCONSOLE = 1 | ||||
|  | @ -146,7 +150,7 @@ include $(topsrcdir)/config/static-rules.mk | |||
| endif | ||||
| 
 | ||||
| APP_VERSION = $(shell cat $(srcdir)/../config/version.txt) | ||||
| DEFINES += -DAPP_VERSION=\"$(APP_VERSION)\" | ||||
| DEFINES += -DAPP_VERSION="$(APP_VERSION)" | ||||
| 
 | ||||
| ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) | ||||
| ifdef BUILD_STATIC_LIBS | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ | |||
| static const nsXREAppData kAppData = { | ||||
|   0, | ||||
|   "Thunderbird", | ||||
|   APP_VERSION, | ||||
|   NS_STRINGIFY(APP_VERSION), | ||||
|   NS_STRINGIFY(BUILD_ID), | ||||
|   // {3550f703-e582-4d05-9a08-453d09bdfdc6}
 | ||||
|   { 0x3550f703, 0xe582, 0x4d05, { 0x9a, 0x08, 0x45, 0x3d, 0x09, 0xbd, 0xfd, 0xc6 } }, | ||||
|  |  | |||
|  | @ -35,10 +35,7 @@ | |||
|  * | ||||
|  * ***** END LICENSE BLOCK ***** */ | ||||
| 
 | ||||
| pref("general.useragent.vendor", "Thunderbird"); | ||||
| pref("general.useragent.vendorSub", | ||||
| #expand __APP_VERSION__ | ||||
| ); | ||||
| #expand pref("general.useragent.extra.thunderbird", "Thunderbird/__APP_VERSION__"); | ||||
| 
 | ||||
| #expand pref("general.useragent.locale", "__AB_CD__"); | ||||
| pref("general.skins.selectedSkin", "classic/1.0"); | ||||
|  |  | |||
|  | @ -70,6 +70,7 @@ | |||
| #include "nsAutoLock.h" | ||||
| #include "prprf.h" | ||||
| #include "nsReadableUtils.h" | ||||
| #include "nsQuickSort.h" | ||||
| 
 | ||||
| #if defined(XP_UNIX) || defined(XP_BEOS) | ||||
| #include <sys/utsname.h> | ||||
|  | @ -239,6 +240,7 @@ nsHttpHandler::Init() | |||
|     LOG(("> vendor = %s\n", mVendor.get())); | ||||
|     LOG(("> vendor-sub = %s\n", mVendorSub.get())); | ||||
|     LOG(("> vendor-comment = %s\n", mVendorComment.get())); | ||||
|     LOG(("> extra = %s\n", mExtraUA.get())); | ||||
|     LOG(("> product = %s\n", mProduct.get())); | ||||
|     LOG(("> product-sub = %s\n", mProductSub.get())); | ||||
|     LOG(("> product-comment = %s\n", mProductComment.get())); | ||||
|  | @ -530,6 +532,7 @@ nsHttpHandler::BuildUserAgent() | |||
|                            mVendor.Length() + | ||||
|                            mVendorSub.Length() + | ||||
|                            mVendorComment.Length() + | ||||
|                            mExtraUA.Length() + | ||||
|                            22); | ||||
| 
 | ||||
|     // Application portion
 | ||||
|  | @ -584,6 +587,9 @@ nsHttpHandler::BuildUserAgent() | |||
|             mUserAgent += ')'; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if (!mExtraUA.IsEmpty()) | ||||
|         mUserAgent += mExtraUA; | ||||
| } | ||||
| 
 | ||||
| void | ||||
|  | @ -696,6 +702,12 @@ nsHttpHandler::InitUserAgentComponents() | |||
|     mUserAgentIsDirty = PR_TRUE; | ||||
| } | ||||
| 
 | ||||
| static int StringCompare(const void* s1, const void* s2, void*) | ||||
| { | ||||
|     return nsCRT::strcmp(*NS_STATIC_CAST(const char *const *, s1), | ||||
|                          *NS_STATIC_CAST(const char *const *, s2)); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) | ||||
| { | ||||
|  | @ -705,6 +717,8 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) | |||
|     LOG(("nsHttpHandler::PrefsChanged [pref=%s]\n", pref)); | ||||
| 
 | ||||
| #define PREF_CHANGED(p) ((pref == nsnull) || !PL_strcmp(pref, p)) | ||||
| #define MULTI_PREF_CHANGED(p) \ | ||||
|   ((pref == nsnull) || !PL_strncmp(pref, p, sizeof(p) - 1)) | ||||
| 
 | ||||
|     //
 | ||||
|     // UA components
 | ||||
|  | @ -743,6 +757,36 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) | |||
|         mUserAgentIsDirty = PR_TRUE; | ||||
|     } | ||||
| 
 | ||||
|     if (MULTI_PREF_CHANGED(UA_PREF("extra."))) { | ||||
|         mExtraUA.Truncate(); | ||||
| 
 | ||||
|         // Unfortunately, we can't do this using the pref branch.
 | ||||
|         nsCOMPtr<nsIPrefService> service = | ||||
|             do_GetService(NS_PREFSERVICE_CONTRACTID); | ||||
|         nsCOMPtr<nsIPrefBranch> branch; | ||||
|         service->GetBranch(UA_PREF("extra."), getter_AddRefs(branch)); | ||||
|         if (branch) { | ||||
|             PRUint32 extraCount; | ||||
|             char **extraItems; | ||||
|             rv = branch->GetChildList("", &extraCount, &extraItems); | ||||
|             if (NS_SUCCEEDED(rv) && extraItems) { | ||||
|                 NS_QuickSort(extraItems, extraCount, sizeof(extraItems[0]), | ||||
|                              StringCompare, nsnull); | ||||
|                 for (char **item = extraItems, | ||||
|                       **item_end = extraItems + extraCount; | ||||
|                      item < item_end; ++item) { | ||||
|                     nsXPIDLCString valStr; | ||||
|                     branch->GetCharPref(*item, getter_Copies(valStr)); | ||||
|                     if (!valStr.IsEmpty()) | ||||
|                         mExtraUA += NS_LITERAL_CSTRING(" ") + valStr; | ||||
|                 } | ||||
|                 NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(extraCount, extraItems); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         mUserAgentIsDirty = PR_TRUE; | ||||
|     } | ||||
| 
 | ||||
|     // Gather product values.
 | ||||
|     if (PREF_CHANGED(UA_PREF("product"))) { | ||||
|         prefs->GetCharPref(UA_PREF_PREFIX "product", | ||||
|  | @ -1075,6 +1119,7 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) | |||
|     } | ||||
| 
 | ||||
| #undef PREF_CHANGED | ||||
| #undef MULTI_PREF_CHANGED | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  |  | |||
|  | @ -285,6 +285,7 @@ private: | |||
|     nsXPIDLCString mProduct; | ||||
|     nsXPIDLCString mProductSub; | ||||
|     nsXPIDLCString mProductComment; | ||||
|     nsCString      mExtraUA; | ||||
| 
 | ||||
|     nsCString      mUserAgent; | ||||
|     nsXPIDLCString mUserAgentOverride; | ||||
|  |  | |||
|  | @ -427,9 +427,10 @@ typedef PRUint32 nsresult; | |||
| #define NS_INT32_TO_PTR(x) ((void *)((char *)0 + (x))) | ||||
| 
 | ||||
| /*
 | ||||
|  * Use this macro to form a string literal from an identifier. | ||||
|  * Use NS_STRINGIFY to form a string literal from the value of a macro. | ||||
|  */ | ||||
| #define NS_STRINGIFY(x) #x | ||||
| #define NS_STRINGIFY_HELPER(x_) #x_ | ||||
| #define NS_STRINGIFY(x_) NS_STRINGIFY_HELPER(x_) | ||||
| 
 | ||||
| /*
 | ||||
|  * These macros allow you to give a hint to the compiler about branch | ||||
|  |  | |||
|  | @ -1,3 +1,2 @@ | |||
| pref("toolkit.defaultChromeURI", "chrome://simple/content/simple.xul"); | ||||
| pref("general.useragent.vendor", "SimpleApp"); | ||||
| pref("general.useragent.vendorSub", "0.1"); | ||||
| pref("general.useragent.extra.simple", "SimpleApp/0.1"); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 dbaron%dbaron.org
						dbaron%dbaron.org