2 // System.Web.HttpBrowserCapabilities
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (c) 2003 Novell, Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Globalization;
34 using System.Web.Configuration;
36 using System.Security.Permissions;
39 namespace System.Web.Configuration {
40 public partial class HttpCapabilitiesBase
43 namespace System.Web {
44 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
45 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46 public class HttpBrowserCapabilities : HttpCapabilitiesBase
49 const int HaveActiveXControls = 1;
50 const int HaveAOL = 2;
51 const int HaveBackGroundSounds = 3;
52 const int HaveBeta = 4;
53 const int HaveBrowser = 5;
54 const int HaveCDF = 6;
55 //const int HaveClrVersion = 7;
56 const int HaveCookies = 8;
57 const int HaveCrawler = 9;
58 const int HaveEcmaScriptVersion = 10;
59 const int HaveFrames = 11;
60 const int HaveJavaApplets = 12;
61 const int HaveJavaScript = 13;
62 const int HaveMajorVersion = 14;
63 const int HaveMinorVersion = 15;
64 //const int HaveMSDomVersion = 16;
65 const int HavePlatform = 17;
66 const int HaveTables = 18;
67 //const int HaveTagWriter = 19;
68 const int HaveVBScript = 20;
69 const int HaveVersion = 21;
70 const int HaveW3CDomVersion = 22;
71 const int HaveWin16 = 23;
72 const int HaveWin32 = 24;
77 bool backgroundSounds;
84 Version ecmaScriptVersion;
90 //Version msDomVersion;
96 Version w3CDomVersion;
99 Version [] clrVersions;
100 internal string useragent;
103 public HttpBrowserCapabilities ()
108 public bool ActiveXControls {
110 if (!Get (HaveActiveXControls)) {
111 Set (HaveActiveXControls);
112 activeXControls = ReadBoolean ("activexcontrols", false);
115 return activeXControls;
121 if (!Get (HaveAOL)) {
123 aol = ReadBoolean ("aol", false);
130 public bool BackgroundSounds {
132 if (!Get (HaveBackGroundSounds)) {
133 Set (HaveBackGroundSounds);
134 backgroundSounds = ReadBoolean ("backgroundsounds", false);
137 return backgroundSounds;
143 if (!Get (HaveBeta)) {
145 beta = ReadBoolean ("beta", false);
152 public string Browser {
154 if (!Get (HaveBrowser)) {
156 browser = this ["browser"];
166 public ArrayList Browsers {
167 get { throw new NotImplementedException (); }
172 if (!Get (HaveCDF)) {
174 cdf = ReadBoolean ("cdf", false);
181 public Version ClrVersion {
183 if (clrVersion == null)
184 InternalGetClrVersions ();
190 public bool Cookies {
192 if (!Get (HaveCookies)) {
194 cookies = ReadBoolean ("cookies", false);
201 public bool Crawler {
203 if (!Get (HaveCrawler)) {
205 crawler = ReadBoolean ("crawler", false);
212 public Version EcmaScriptVersion {
214 if (!Get (HaveEcmaScriptVersion)) {
216 Set (HaveEcmaScriptVersion);
217 ver_str = this ["ecmascriptversion"];
219 ecmaScriptVersion = new Version (0, 0);
221 ecmaScriptVersion = new Version (ver_str);
224 return ecmaScriptVersion;
230 if (!Get (HaveFrames)) {
232 frames = ReadBoolean ("frames", false);
239 public bool JavaApplets {
241 if (!Get (HaveJavaApplets)) {
242 Set (HaveJavaApplets);
243 javaApplets = ReadBoolean ("javaapplets", false);
250 public bool JavaScript {
252 if (!Get (HaveJavaScript)) {
253 Set (HaveJavaScript);
254 javaScript = ReadBoolean ("javascript", false);
261 public int MajorVersion {
263 if (!Get (HaveMajorVersion)) {
264 Set (HaveMajorVersion);
265 majorVersion = ReadInt32 ("majorver", 0);
272 public double MinorVersion {
274 if (!Get (HaveMinorVersion)) {
275 Set (HaveMinorVersion);
276 minorVersion = ReadDouble ("minorver", 0);
283 public Version MSDomVersion {
285 return new Version (0, 0);
289 public string Platform {
291 if (!Get (HavePlatform)) {
293 platform = this ["platform"];
294 if (platform == null)
304 if (!Get (HaveTables)) {
306 tables = ReadBoolean ("tables", false);
313 public Type TagWriter {
315 return typeof (HtmlTextWriter);
321 return Browser + MajorVersion;
325 public bool VBScript {
327 if (!Get (HaveVBScript)) {
329 vbscript = ReadBoolean ("vbscript", false);
336 public string Version {
338 if (!Get (HaveVersion)) {
340 version = this ["version"];
349 public Version W3CDomVersion {
351 if (!Get (HaveW3CDomVersion)) {
353 Set (HaveW3CDomVersion);
354 ver_str = this ["w3cdomversion"];
356 w3CDomVersion = new Version (0, 0);
358 w3CDomVersion = new Version (ver_str);
361 return w3CDomVersion;
367 if (!Get (HaveWin16)) {
369 win16 = ReadBoolean ("win16", false);
378 // This is the list of different windows platforms that browscap.ini has.
379 // Win16 Win2000 Win2003 Win32 Win95 Win98 WinME WinNT WinVI WinXP
380 if (!Get (HaveWin32)) {
382 string platform = Platform;
383 win32 = (platform != "Win16" && platform.StartsWith ("Win"));
390 public Version [] GetClrVersions ()
392 if ((clrVersions == null) && (clrVersion == null))
393 InternalGetClrVersions ();
399 void InternalGetClrVersions ()
401 char [] anychars = new char [] { ';', ')' };
402 string s = useragent;
403 ArrayList list = null;
405 while ((s != null) && (idx = s.IndexOf (".NET CLR ")) != -1) {
406 int end = s.IndexOfAny (anychars, idx + 9);
410 string ver = s.Substring (idx + 9, end - idx - 9);
413 v = new Version (ver);
414 if (clrVersion == null || v > clrVersion)
418 list = new ArrayList (4);
422 s = s.Substring (idx + 9);
425 if (list == null || list.Count == 0) {
426 clrVersion = new Version ();
430 clrVersions = new Version [1] { clrVersion };
434 clrVersions = (Version []) list.ToArray (typeof (Version));
438 bool ReadBoolean (string key, bool dflt)
440 string v = this [key];
444 return (String.Compare (v, "True", true, CultureInfo.InvariantCulture) == 0);
447 int ReadInt32 (string key, int dflt)
449 string v = this [key];
454 return Int32.Parse (v);
460 double ReadDouble (string key, double dflt)
462 string v = this [key];
467 return Double.Parse (v);
475 return (flags & (1 << idx)) != 0;