Expose device type in user agent. r=vlad

This commit is contained in:
Doug Turner 2009-10-24 23:09:46 -07:00
parent 1d81e23e8d
commit 195c21873d
5 changed files with 71 additions and 29 deletions

View File

@ -92,11 +92,7 @@
#endif
#ifdef MOZ_PLATFORM_HILDON
#include "nsCOMPtr.h"
#include "nsILocalFile.h"
#include "nsILineInputStream.h"
#include "nsNetUtil.h"
#include "nsIPropertyBag2.h"
PRInt32 gfxPlatformGtk::sMaemoClassic = -1;
#endif
@ -546,29 +542,22 @@ gfxPlatformGtk::InitDisplayCaps()
// Check the cached value
if (gfxPlatform::sDPI == -1) {
nsresult rv;
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(NS_LITERAL_STRING("/proc/component_version"),
PR_TRUE, getter_AddRefs(file));
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1", &rv);
if (NS_FAILED(rv)) {
NS_ASSERTION(infoService, "Could not find a system info service");
return;
}
nsCString deviceType;
rv = infoService->GetPropertyAsACString(NS_LITERAL_STRING("device"), deviceType);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIInputStream> fileStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file);
nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream);
// Extract the product code from the component_version file
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
if (lineStream && NS_SUCCEEDED(lineStream->ReadLine(buffer, &isMore))) {
if (StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-51"))) {
gfxPlatform::sDPI = 265; // It's an N900
gfxPlatformGtk::sMaemoClassic = 0;
}
else if (StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-44")) ||
StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-48")) ||
StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-34"))) {
gfxPlatform::sDPI = 225; // It's an N810/N800
gfxPlatformGtk::sMaemoClassic = 1;
}
}
if (deviceType.EqualsLiteral("Nokia N900")) {
gfxPlatform::sDPI = 265; // It's an N900
gfxPlatformGtk::sMaemoClassic = 0;
}
else if (deviceType.EqualsLiteral("Nokia N8xx")) {
gfxPlatform::sDPI = 225; // It's an N810/N800
gfxPlatformGtk::sMaemoClassic = 1;
}
}
}
#else

View File

@ -39,7 +39,7 @@
#include "nsIProxiedProtocolHandler.idl"
[scriptable, uuid(122c91c0-2485-40ba-89c9-b895934921bc)]
[scriptable, uuid(415D4087-79D3-40FE-B194-0ADA8471F895)]
interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
{
/**
@ -117,6 +117,15 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
* Get/Set the application comment misc portion.
*/
attribute ACString misc;
/**
* Get the current device type.
*
* @return The device type this application is running on. Maybe
* be null.
*/
readonly attribute ACString deviceType;
};
%{C++

View File

@ -246,6 +246,7 @@ nsHttpHandler::Init()
LOG(("> app-version = %s\n", mAppVersion.get()));
LOG(("> platform = %s\n", mPlatform.get()));
LOG(("> oscpu = %s\n", mOscpu.get()));
LOG(("> device = %s\n", mDeviceType.get()));
LOG(("> security = %s\n", mSecurity.get()));
LOG(("> language = %s\n", mLanguage.get()));
LOG(("> misc = %s\n", mMisc.get()));
@ -553,6 +554,7 @@ nsHttpHandler::BuildUserAgent()
mPlatform.Length() +
mSecurity.Length() +
mOscpu.Length() +
mDeviceType.Length() +
mLanguage.Length() +
mMisc.Length() +
mProduct.Length() +
@ -577,6 +579,10 @@ nsHttpHandler::BuildUserAgent()
mUserAgent += mSecurity;
mUserAgent.AppendLiteral("; ");
mUserAgent += mOscpu;
if (!mDeviceType.IsEmpty()) {
mUserAgent.AppendLiteral("; ");
mUserAgent += mDeviceType;
}
if (!mLanguage.IsEmpty()) {
mUserAgent.AppendLiteral("; ");
mUserAgent += mLanguage;
@ -721,6 +727,14 @@ nsHttpHandler::InitUserAgentComponents()
}
#endif
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
NS_ASSERTION(infoService, "Could not find a system info service");
nsCString deviceType;
nsresult rv = infoService->GetPropertyAsACString(NS_LITERAL_STRING("device"), deviceType);
if (NS_SUCCEEDED(rv))
mDeviceType = deviceType;
mUserAgentIsDirty = PR_TRUE;
}
@ -1637,6 +1651,13 @@ nsHttpHandler::GetOscpu(nsACString &value)
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetDeviceType(nsACString &value)
{
value = mDeviceType;
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::GetLanguage(nsACString &value)
{

View File

@ -285,6 +285,7 @@ private:
nsXPIDLCString mAppVersion;
nsCString mPlatform;
nsCString mOscpu;
nsCString mDeviceType;
nsXPIDLCString mSecurity;
nsCString mLanguage;
nsCString mMisc;

View File

@ -90,7 +90,29 @@ nsSystemInfo::Init()
NS_ENSURE_SUCCESS(rv, rv);
}
#endif
#ifdef MOZ_PLATFORM_HILDON
char * line = nsnull;
size_t len = 0;
ssize_t read;
FILE *fp = fopen ("/proc/component_version", "r");
if (fp) {
while ((read = getline(&line, &len, fp)) != -1) {
if (line) {
if (strstr(line, "RX-51")) {
SetPropertyAsACString(NS_ConvertASCIItoUTF16("device"), NS_LITERAL_CSTRING("Nokia N900"));
} else if (strstr(line, "RX-44") ||
strstr(line, "RX-48") ||
strstr(line, "RX-32") ) {
SetPropertyAsACString(NS_ConvertASCIItoUTF16("device"), NS_LITERAL_CSTRING("Nokia N8xx"));
}
}
}
if (line)
free(line);
}
#endif
return NS_OK;
}