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;
37 namespace System.Web.Configuration {
38 public partial class HttpCapabilitiesBase
41 namespace System.Web {
42 public partial class HttpBrowserCapabilities : HttpCapabilitiesBase
45 const int HaveActiveXControls = 1;
46 const int HaveAOL = 2;
47 const int HaveBackGroundSounds = 3;
48 const int HaveBeta = 4;
49 const int HaveBrowser = 5;
50 const int HaveCDF = 6;
51 //const int HaveClrVersion = 7;
52 const int HaveCookies = 8;
53 const int HaveCrawler = 9;
54 const int HaveEcmaScriptVersion = 10;
55 const int HaveFrames = 11;
56 const int HaveJavaApplets = 12;
57 const int HaveJavaScript = 13;
58 const int HaveMajorVersion = 14;
59 const int HaveMinorVersion = 15;
60 //const int HaveMSDomVersion = 16;
61 const int HavePlatform = 17;
62 const int HaveTables = 18;
63 //const int HaveTagWriter = 19;
64 const int HaveVBScript = 20;
65 const int HaveVersion = 21;
66 const int HaveW3CDomVersion = 22;
67 const int HaveWin16 = 23;
68 const int HaveWin32 = 24;
73 bool backgroundSounds;
80 Version ecmaScriptVersion;
86 //Version msDomVersion;
92 Version w3CDomVersion;
95 Version [] clrVersions;
96 internal string useragent;
98 public bool ActiveXControls {
100 if (!Get (HaveActiveXControls)) {
101 Set (HaveActiveXControls);
102 activeXControls = ReadBoolean ("activexcontrols", false);
105 return activeXControls;
111 if (!Get (HaveAOL)) {
113 aol = ReadBoolean ("aol", false);
120 public bool BackgroundSounds {
122 if (!Get (HaveBackGroundSounds)) {
123 Set (HaveBackGroundSounds);
124 backgroundSounds = ReadBoolean ("backgroundsounds", false);
127 return backgroundSounds;
133 if (!Get (HaveBeta)) {
135 beta = ReadBoolean ("beta", false);
142 public string Browser {
144 if (!Get (HaveBrowser)) {
146 browser = this ["browser"];
157 if (!Get (HaveCDF)) {
159 cdf = ReadBoolean ("cdf", false);
166 public Version ClrVersion {
168 if (clrVersion == null)
169 InternalGetClrVersions ();
175 public bool Cookies {
177 if (!Get (HaveCookies)) {
179 cookies = ReadBoolean ("cookies", false);
186 public bool Crawler {
188 if (!Get (HaveCrawler)) {
190 crawler = ReadBoolean ("crawler", false);
197 public Version EcmaScriptVersion {
199 if (!Get (HaveEcmaScriptVersion)) {
201 Set (HaveEcmaScriptVersion);
202 ver_str = this ["ecmascriptversion"];
204 ecmaScriptVersion = new Version (0, 0);
206 ecmaScriptVersion = new Version (ver_str);
209 return ecmaScriptVersion;
215 if (!Get (HaveFrames)) {
217 frames = ReadBoolean ("frames", false);
224 public bool JavaApplets {
226 if (!Get (HaveJavaApplets)) {
227 Set (HaveJavaApplets);
228 javaApplets = ReadBoolean ("javaapplets", false);
235 public bool JavaScript {
237 if (!Get (HaveJavaScript)) {
238 Set (HaveJavaScript);
239 javaScript = ReadBoolean ("javascript", false);
246 public int MajorVersion {
248 if (!Get (HaveMajorVersion)) {
249 Set (HaveMajorVersion);
250 majorVersion = ReadInt32 ("majorver", 0);
257 public double MinorVersion {
259 if (!Get (HaveMinorVersion)) {
260 Set (HaveMinorVersion);
261 minorVersion = ReadDouble ("minorver", 0);
268 public Version MSDomVersion {
270 return new Version (0, 0);
274 public string Platform {
276 if (!Get (HavePlatform)) {
278 platform = this ["platform"];
279 if (platform == null)
289 if (!Get (HaveTables)) {
291 tables = ReadBoolean ("tables", false);
298 public Type TagWriter {
300 return typeof (HtmlTextWriter);
306 return Browser + MajorVersion;
310 public bool VBScript {
312 if (!Get (HaveVBScript)) {
314 vbscript = ReadBoolean ("vbscript", false);
321 public string Version {
323 if (!Get (HaveVersion)) {
325 version = this ["version"];
334 public Version W3CDomVersion {
336 if (!Get (HaveW3CDomVersion)) {
338 Set (HaveW3CDomVersion);
339 ver_str = this ["w3cdomversion"];
341 w3CDomVersion = new Version (0, 0);
343 w3CDomVersion = new Version (ver_str);
346 return w3CDomVersion;
352 if (!Get (HaveWin16)) {
354 win16 = ReadBoolean ("win16", false);
363 if (!Get (HaveWin32)) {
365 win32 = ReadBoolean ("win32", false);
373 public Version [] GetClrVersions ()
375 if (clrVersions == null)
376 InternalGetClrVersions ();
382 void InternalGetClrVersions ()
384 char [] anychars = new char [] { ';', ')' };
385 string s = useragent;
386 ArrayList list = null;
388 while ((idx = s.IndexOf (".NET CLR ")) != -1) {
389 int end = s.IndexOfAny (anychars, idx + 9);
393 string ver = s.Substring (idx + 9, end - idx - 9);
396 v = new Version (ver);
397 if (clrVersion == null || v > clrVersion)
401 list = new ArrayList (4);
405 s = s.Substring (idx + 9);
408 if (list == null || list.Count == 0) {
409 clrVersion = new Version ();
410 clrVersions = new Version [] { clrVersion };
413 clrVersions = (Version []) list.ToArray (typeof (Version));
417 bool ReadBoolean (string key, bool dflt)
419 string v = this [key];
423 return (v == "True");
426 int ReadInt32 (string key, int dflt)
428 string v = this [key];
433 return Int32.Parse (v);
439 double ReadDouble (string key, double dflt)
441 string v = this [key];
446 return Double.Parse (v);
454 return (flags & (1 << idx)) != 0;