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.Web.Configuration;
38 public class HttpBrowserCapabilities : HttpCapabilitiesBase
40 const int HaveActiveXControls = 1;
41 const int HaveAOL = 2;
42 const int HaveBackGroundSounds = 3;
43 const int HaveBeta = 4;
44 const int HaveBrowser = 5;
45 const int HaveCDF = 6;
46 const int HaveClrVersion = 7;
47 const int HaveCookies = 8;
48 const int HaveCrawler = 9;
49 const int HaveEcmaScriptVersion = 10;
50 const int HaveFrames = 11;
51 const int HaveJavaApplets = 12;
52 const int HaveJavaScript = 13;
53 const int HaveMajorVersion = 14;
54 const int HaveMinorVersion = 15;
55 const int HaveMSDomVersion = 16;
56 const int HavePlatform = 17;
57 const int HaveTables = 18;
58 const int HaveTagWriter = 19;
59 const int HaveVBScript = 20;
60 const int HaveVersion = 21;
61 const int HaveW3CDomVersion = 22;
62 const int HaveWin16 = 23;
63 const int HaveWin32 = 24;
68 bool backgroundSounds;
75 Version ecmaScriptVersion;
87 Version w3CDomVersion;
89 Version [] clrVersions;
90 internal string useragent;
92 public HttpBrowserCapabilities () { }
94 public bool ActiveXControls {
96 if (!Get (HaveActiveXControls)) {
97 Set (HaveActiveXControls);
98 activeXControls = ReadBoolean ("activexcontrols", false);
101 return activeXControls;
107 if (!Get (HaveAOL)) {
109 aol = ReadBoolean ("aol", false);
116 public bool BackgroundSounds {
118 if (!Get (HaveBackGroundSounds)) {
119 Set (HaveBackGroundSounds);
120 backgroundSounds = ReadBoolean ("backgroundsounds", false);
123 return backgroundSounds;
129 if (!Get (HaveBeta)) {
131 beta = ReadBoolean ("beta", false);
138 public string Browser {
140 if (!Get (HaveBrowser)) {
142 browser = this ["browser"];
153 if (!Get (HaveCDF)) {
155 cdf = ReadBoolean ("cdf", false);
162 public Version ClrVersion {
164 if (clrVersion == null)
165 InternalGetClrVersions ();
171 public bool Cookies {
173 if (!Get (HaveCookies)) {
175 cookies = ReadBoolean ("cookies", false);
182 public bool Crawler {
184 if (!Get (HaveCrawler)) {
186 crawler = ReadBoolean ("crawler", false);
194 public Version EcmaScriptVersion {
196 return new Version (0, 0);
202 if (!Get (HaveFrames)) {
204 frames = ReadBoolean ("frames", false);
211 public bool JavaApplets {
213 if (!Get (HaveJavaApplets)) {
214 Set (HaveJavaApplets);
215 javaApplets = ReadBoolean ("javaapplets", false);
222 public bool JavaScript {
224 if (!Get (HaveJavaScript)) {
225 Set (HaveJavaScript);
226 javaScript = ReadBoolean ("javascript", false);
233 public int MajorVersion {
235 if (!Get (HaveMajorVersion)) {
236 Set (HaveMajorVersion);
237 majorVersion = ReadInt32 ("majorver", 0);
244 public double MinorVersion {
246 if (!Get (HaveMinorVersion)) {
247 Set (HaveMinorVersion);
248 minorVersion = ReadDouble ("minorver", 0);
256 public Version MSDomVersion {
258 return new Version (0, 0);
262 public string Platform {
264 if (!Get (HavePlatform)) {
266 platform = this ["platform"];
267 if (platform == null)
277 if (!Get (HaveTables)) {
279 tables = ReadBoolean ("tables", false);
287 public Type TagWriter {
289 return typeof (HtmlTextWriter);
295 return Browser + MajorVersion;
299 public bool VBScript {
301 if (!Get (HaveVBScript)) {
303 vbscript = ReadBoolean ("vbscript", false);
310 public string Version {
312 if (!Get (HaveVersion)) {
314 version = this ["version"];
324 public Version W3CDomVersion {
326 return new Version (0, 0);
332 if (!Get (HaveWin16)) {
334 win16 = ReadBoolean ("win16", false);
348 public Version [] GetClrVersions ()
350 if (clrVersions == null)
351 InternalGetClrVersions ();
357 void InternalGetClrVersions ()
359 char [] anychars = new char [] { ';', ')' };
360 string s = useragent;
361 ArrayList list = null;
363 while ((idx = s.IndexOf (".NET CLR ")) != -1) {
364 int end = s.IndexOfAny (anychars, idx + 9);
368 string ver = s.Substring (idx + 9, end - idx - 9);
371 v = new Version (ver);
372 if (clrVersion == null || v > clrVersion)
376 list = new ArrayList (4);
380 s = s.Substring (idx + 9);
383 if (list == null || list.Count == 0) {
384 clrVersion = new Version ();
385 clrVersions = new Version [] { clrVersion };
388 clrVersions = (Version []) list.ToArray (typeof (Version));
392 bool ReadBoolean (string key, bool dflt)
394 string v = this [key];
398 return (v == "True");
401 int ReadInt32 (string key, int dflt)
403 string v = this [key];
408 return Int32.Parse (v);
414 double ReadDouble (string key, double dflt)
416 string v = this [key];
421 return Double.Parse (v);
429 return (flags & (1 << idx)) != 0;