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;
38 namespace System.Web.Configuration {
39 public partial class HttpCapabilitiesBase
42 namespace System.Web {
43 public partial class HttpBrowserCapabilities : HttpCapabilitiesBase
46 const int HaveActiveXControls = 1;
47 const int HaveAOL = 2;
48 const int HaveBackGroundSounds = 3;
49 const int HaveBeta = 4;
50 const int HaveBrowser = 5;
51 const int HaveCDF = 6;
52 //const int HaveClrVersion = 7;
53 const int HaveCookies = 8;
54 const int HaveCrawler = 9;
55 const int HaveEcmaScriptVersion = 10;
56 const int HaveFrames = 11;
57 const int HaveJavaApplets = 12;
58 const int HaveJavaScript = 13;
59 const int HaveMajorVersion = 14;
60 const int HaveMinorVersion = 15;
61 //const int HaveMSDomVersion = 16;
62 const int HavePlatform = 17;
63 const int HaveTables = 18;
64 //const int HaveTagWriter = 19;
65 const int HaveVBScript = 20;
66 const int HaveVersion = 21;
67 const int HaveW3CDomVersion = 22;
68 const int HaveWin16 = 23;
69 const int HaveWin32 = 24;
74 bool backgroundSounds;
81 Version ecmaScriptVersion;
87 //Version msDomVersion;
93 Version w3CDomVersion;
96 Version [] clrVersions;
97 internal string useragent;
99 public bool ActiveXControls {
101 if (!Get (HaveActiveXControls)) {
102 Set (HaveActiveXControls);
103 activeXControls = ReadBoolean ("activexcontrols", false);
106 return activeXControls;
112 if (!Get (HaveAOL)) {
114 aol = ReadBoolean ("aol", false);
121 public bool BackgroundSounds {
123 if (!Get (HaveBackGroundSounds)) {
124 Set (HaveBackGroundSounds);
125 backgroundSounds = ReadBoolean ("backgroundsounds", false);
128 return backgroundSounds;
134 if (!Get (HaveBeta)) {
136 beta = ReadBoolean ("beta", false);
143 public string Browser {
145 if (!Get (HaveBrowser)) {
147 browser = this ["browser"];
157 public ArrayList Browsers {
158 get { throw new NotImplementedException (); }
163 if (!Get (HaveCDF)) {
165 cdf = ReadBoolean ("cdf", false);
172 public Version ClrVersion {
174 if (clrVersion == null)
175 InternalGetClrVersions ();
181 public bool Cookies {
183 if (!Get (HaveCookies)) {
185 cookies = ReadBoolean ("cookies", false);
192 public bool Crawler {
194 if (!Get (HaveCrawler)) {
196 crawler = ReadBoolean ("crawler", false);
203 public Version EcmaScriptVersion {
205 if (!Get (HaveEcmaScriptVersion)) {
207 Set (HaveEcmaScriptVersion);
208 ver_str = this ["ecmascriptversion"];
210 ecmaScriptVersion = new Version (0, 0);
212 ecmaScriptVersion = new Version (ver_str);
215 return ecmaScriptVersion;
221 if (!Get (HaveFrames)) {
223 frames = ReadBoolean ("frames", false);
230 public bool JavaApplets {
232 if (!Get (HaveJavaApplets)) {
233 Set (HaveJavaApplets);
234 javaApplets = ReadBoolean ("javaapplets", false);
241 public bool JavaScript {
243 if (!Get (HaveJavaScript)) {
244 Set (HaveJavaScript);
245 javaScript = ReadBoolean ("javascript", false);
252 public int MajorVersion {
254 if (!Get (HaveMajorVersion)) {
255 Set (HaveMajorVersion);
256 majorVersion = ReadInt32 ("majorver", 0);
263 public double MinorVersion {
265 if (!Get (HaveMinorVersion)) {
266 Set (HaveMinorVersion);
267 minorVersion = ReadDouble ("minorver", 0);
274 public Version MSDomVersion {
276 return new Version (0, 0);
280 public string Platform {
282 if (!Get (HavePlatform)) {
284 platform = this ["platform"];
285 if (platform == null)
295 if (!Get (HaveTables)) {
297 tables = ReadBoolean ("tables", false);
304 public Type TagWriter {
306 return typeof (HtmlTextWriter);
312 return Browser + MajorVersion;
316 public bool VBScript {
318 if (!Get (HaveVBScript)) {
320 vbscript = ReadBoolean ("vbscript", false);
327 public string Version {
329 if (!Get (HaveVersion)) {
331 version = this ["version"];
340 public Version W3CDomVersion {
342 if (!Get (HaveW3CDomVersion)) {
344 Set (HaveW3CDomVersion);
345 ver_str = this ["w3cdomversion"];
347 w3CDomVersion = new Version (0, 0);
349 w3CDomVersion = new Version (ver_str);
352 return w3CDomVersion;
358 if (!Get (HaveWin16)) {
360 win16 = ReadBoolean ("win16", false);
369 if (!Get (HaveWin32)) {
371 win32 = ReadBoolean ("win32", false);
379 public Version [] GetClrVersions ()
381 if ((clrVersions == null) && (clrVersion == null))
382 InternalGetClrVersions ();
388 void InternalGetClrVersions ()
390 char [] anychars = new char [] { ';', ')' };
391 string s = useragent;
392 ArrayList list = null;
394 while ((s != null) && (idx = s.IndexOf (".NET CLR ")) != -1) {
395 int end = s.IndexOfAny (anychars, idx + 9);
399 string ver = s.Substring (idx + 9, end - idx - 9);
402 v = new Version (ver);
403 if (clrVersion == null || v > clrVersion)
407 list = new ArrayList (4);
411 s = s.Substring (idx + 9);
414 if (list == null || list.Count == 0) {
415 clrVersion = new Version ();
419 clrVersions = new Version [1] { clrVersion };
423 clrVersions = (Version []) list.ToArray (typeof (Version));
427 bool ReadBoolean (string key, bool dflt)
429 string v = this [key];
433 return (String.Compare (v, "True", true, CultureInfo.InvariantCulture) == 0);
436 int ReadInt32 (string key, int dflt)
438 string v = this [key];
443 return Int32.Parse (v);
449 double ReadDouble (string key, double dflt)
451 string v = this [key];
456 return Double.Parse (v);
464 return (flags & (1 << idx)) != 0;