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;
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"];
165 [MonoTODO ("Not implemented")]
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 if (!Get (HaveMSDomVersion)) {
287 Set (HaveMSDomVersion);
288 ver_str = this ["msdomversion"];
290 msDomVersion = new Version (0, 0);
292 msDomVersion = new Version (ver_str);
299 public string Platform {
301 if (!Get (HavePlatform)) {
303 platform = this ["platform"];
304 if (platform == null)
314 if (!Get (HaveTables)) {
316 tables = ReadBoolean ("tables", false);
323 public Type TagWriter {
325 return typeof (HtmlTextWriter);
331 return Browser + MajorVersion;
335 public bool VBScript {
337 if (!Get (HaveVBScript)) {
339 vbscript = ReadBoolean ("vbscript", false);
346 public string Version {
348 if (!Get (HaveVersion)) {
350 version = this ["version"];
359 public Version W3CDomVersion {
361 if (!Get (HaveW3CDomVersion)) {
363 Set (HaveW3CDomVersion);
364 ver_str = this ["w3cdomversion"];
366 w3CDomVersion = new Version (0, 0);
368 w3CDomVersion = new Version (ver_str);
371 return w3CDomVersion;
377 if (!Get (HaveWin16)) {
379 win16 = ReadBoolean ("win16", false);
388 // This is the list of different windows platforms that browscap.ini has.
389 // Win16 Win2000 Win2003 Win32 Win95 Win98 WinME WinNT WinVI WinXP
390 if (!Get (HaveWin32)) {
392 string platform = Platform;
393 win32 = (platform != "Win16" && platform.StartsWith ("Win"));
400 public Version [] GetClrVersions ()
402 if ((clrVersions == null) && (clrVersion == null))
403 InternalGetClrVersions ();
409 void InternalGetClrVersions ()
411 char [] anychars = new char [] { ';', ')' };
412 string s = useragent;
413 ArrayList list = null;
415 while ((s != null) && (idx = s.IndexOf (".NET CLR ")) != -1) {
416 int end = s.IndexOfAny (anychars, idx + 9);
420 string ver = s.Substring (idx + 9, end - idx - 9);
423 v = new Version (ver);
424 if (clrVersion == null || v > clrVersion)
428 list = new ArrayList (4);
432 s = s.Substring (idx + 9);
435 if (list == null || list.Count == 0) {
436 clrVersion = new Version ();
440 clrVersions = new Version [1] { clrVersion };
444 clrVersions = (Version []) list.ToArray (typeof (Version));
448 bool ReadBoolean (string key, bool dflt)
450 string v = this [key];
454 return (String.Compare (v, "True", true, CultureInfo.InvariantCulture) == 0);
457 int ReadInt32 (string key, int dflt)
459 string v = this [key];
464 return Int32.Parse (v);
470 double ReadDouble (string key, double dflt)
472 string v = this [key];
477 return Double.Parse (v);
485 return (flags & (1 << idx)) != 0;