client-side.js revision 444985316bc63f83512ed2251cd427e3aa0262e5
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/*
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen *
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen *
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * The contents of this file are subject to the terms
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * of the Common Development and Distribution License
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * (the License). You may not use this file except in
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen * compliance with the License.
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen *
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * You can obtain a copy of the License at
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * https://opensso.dev.java.net/public/CDDLv1.0.html or
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * opensso/legal/CDDLv1.0.txt
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen * See the License for the specific language governing
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen * permission and limitations under the License.
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen *
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen * When distributing Covered Code, include this CDDL
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen * Header Notice in each file and include the License file
75a32ef74f52fd17728cf25ccc6309d35ae65dc2Timo Sirainen * at opensso/legal/CDDLv1.0.txt.
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen * If applicable, add the following below the CDDL Header,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * with the fields enclosed by brackets [] replaced by
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen * your own identifying information:
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * "Portions Copyrighted [year] [name of copyright owner]"
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen *
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen */
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen/*
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * Portions Copyrighted 2013 Syntegrity.
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen * Portions Copyrighted 2013-2014 ForgeRock AS.
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen */
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainenvar collectScreenInfo = function () {
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen var screenInfo = {};
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen if (screen) {
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen if (screen.width) {
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen screenInfo.screenWidth = screen.width;
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen }
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen if (screen.height) {
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen screenInfo.screenHeight = screen.height;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen }
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen if (screen.pixelDepth) {
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen screenInfo.screenColourDepth = screen.pixelDepth;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen }
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen } else {
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen console.warn("Cannot collect screen information. screen is not defined.");
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen }
return screenInfo;
},
collectTimezoneInfo = function () {
var timezoneInfo = {}, offset = new Date().getTimezoneOffset();
if (offset) {
timezoneInfo.timezone = offset;
} else {
console.warn("Cannot collect timezone information. timezone is not defined.");
}
return timezoneInfo;
},
collectBrowserPluginsInfo = function () {
if (navigator && navigator.plugins) {
var pluginsInfo = {}, i, plugins = navigator.plugins;
pluginsInfo.installedPlugins = "";
for (i = 0; i < plugins.length; i++) {
pluginsInfo.installedPlugins = pluginsInfo.installedPlugins + plugins[i].filename + ";";
}
return pluginsInfo;
} else {
console.warn("Cannot collect browser plugin information. navigator.plugins is not defined.");
return {};
}
},
// Getting geolocation takes some time and is done asynchronously, hence need a callback which is called once geolocation is retrieved.
collectGeolocationInfo = function (callback) {
var geolocationInfo = {};
if (navigator && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
geolocationInfo.longitude = position.coords.longitude;
geolocationInfo.latitude = position.coords.latitude;
callback(geolocationInfo);
});
} else {
console.warn("Cannot collect geolocation information. navigator.geolocation is not defined.");
callback(geolocationInfo);
}
},
collectBrowserFontsInfo = function () {
var fontsInfo = {}, i, fontsList = ["cursive","monospace","serif","sans-serif","fantasy","default","Arial","Arial Black",
"Arial Narrow","Arial Rounded MT Bold","Bookman Old Style","Bradley Hand ITC","Century","Century Gothic",
"Comic Sans MS","Courier","Courier New","Georgia","Gentium","Impact","King","Lucida Console","Lalit",
"Modena","Monotype Corsiva","Papyrus","Tahoma","TeX","Times","Times New Roman","Trebuchet MS","Verdana",
"Verona"];
fontsInfo.installedFonts = "";
for (i = 0; i < fontsList.length; i++) {
if (fontDetector.detect(fontsList[i])) {
fontsInfo.installedFonts = fontsInfo.installedFonts + fontsList[i] + ";";
}
}
return fontsInfo;
},
devicePrint = {};
devicePrint.screen = collectScreenInfo();
devicePrint.timezone = collectTimezoneInfo();
devicePrint.plugins = collectBrowserPluginsInfo();
devicePrint.fonts = collectBrowserFontsInfo();
if (navigator.userAgent) {
devicePrint.userAgent = navigator.userAgent;
}
if (navigator.appName) {
devicePrint.appName = navigator.appName;
}
if (navigator.appCodeName) {
devicePrint.appCodeName = navigator.appCodeName;
}
if (navigator.appVersion) {
devicePrint.appVersion = navigator.appVersion;
}
if (navigator.appMinorVersion) {
devicePrint.appMinorVersion = navigator.appMinorVersion;
}
if (navigator.buildID) {
devicePrint.buildID = navigator.buildID;
}
if (navigator.platform) {
devicePrint.platform = navigator.platform;
}
if (navigator.cpuClass) {
devicePrint.cpuClass = navigator.cpuClass;
}
if (navigator.oscpu) {
devicePrint.oscpu = navigator.oscpu;
}
if (navigator.product) {
devicePrint.product = navigator.product;
}
if (navigator.productSub) {
devicePrint.productSub = navigator.productSub;
}
if (navigator.vendor) {
devicePrint.vendor = navigator.vendor;
}
if (navigator.vendorSub) {
devicePrint.vendorSub = navigator.vendorSub;
}
if (navigator.language) {
devicePrint.language = navigator.language;
}
if (navigator.userLanguage) {
devicePrint.userLanguage = navigator.userLanguage;
}
if (navigator.browserLanguage) {
devicePrint.browserLanguage = navigator.browserLanguage;
}
if (navigator.systemLanguage) {
devicePrint.systemLanguage = navigator.systemLanguage;
}
// This will cause the script to wait until the user's location has been found.
// To avoid the wait move the output.value assignment outside of the function callback
collectGeolocationInfo(function(geolocationInfo) {
devicePrint.geolocation = geolocationInfo;
});
output.value = JSON.stringify(devicePrint);