1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
|
//------------------------------------------------------------------------------
// <copyright file="HttpBrowserCapabilities.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Built-in browser caps object
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web {
using System.Collections;
using System.Configuration;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Web.Configuration;
using System.Security.Permissions;
/// <devdoc>
/// <para> Enables the server to compile
/// information on the capabilities of the browser running on the client.</para>
/// </devdoc>
public class HttpBrowserCapabilities : HttpCapabilitiesBase {
// Lazy computation
// NOTE: The methods below are designed to work on multiple threads
// without a need for synchronization. Do NOT do something like replace
// all the _haveX booleans with bitfields or something similar, because
// the methods depend on the fact that "_haveX = true" is atomic.
/// <devdoc>
/// <para>Returns the .NET Common Language Runtime version running
/// on the client. If no CLR version is specified on the
/// User-Agent returns new Version(), which is 0,0.</para>
/// </devdoc>
/* public Version ClrVersion {
get {
ClrVersionEnsureInit();
return _clrVersion;
}
}
/// <devdoc>
/// <para>Returns all versions of the .NET CLR running on the
/// client. If no CLR version is specified on the User-Agent
/// returns an array containing a single empty Version object,
/// which is 0,0.</para>
/// </devdoc>
public Version [] GetClrVersions() {
ClrVersionEnsureInit();
return _clrVersions;
}
private void ClrVersionEnsureInit() {
if (!_haveClrVersion) {
Regex regex = new Regex("\\.NET CLR (?'clrVersion'[0-9\\.]*)");
MatchCollection matches = regex.Matches(this[String.Empty]);
if (matches.Count == 0) {
Version version = new Version();
Version [] clrVersions = new Version [1] {version};
_clrVersions = clrVersions;
_clrVersion = version;
}
else {
ArrayList versionList = new ArrayList();
foreach (Match match in matches) {
Version version = new Version(match.Groups["clrVersion"].Value);
versionList.Add(version);
}
versionList.Sort();
Version [] versions = (Version []) versionList.ToArray(typeof(Version));
_clrVersions = versions;
_clrVersion = versions[versions.Length - 1];
}
_haveClrVersion = true;
}
}
/// <devdoc>
/// <para>Returns the name of the client browser and its major version number. For example, "Microsoft Internet Explorer version
/// 5".</para>
/// </devdoc>
public string Type {
get {
if (!_havetype) {
_type = this["type"];
_havetype = true;
}
return _type;
}
}
/// <devdoc>
/// <para>Browser string in User Agent (for example: "IE").</para>
/// </devdoc>
public string Browser {
get {
if (!_havebrowser) {
_browser = this["browser"];
_havebrowser = true;
}
return _browser;
}
}
/// <devdoc>
/// <para>Returns the major version number + minor version number
/// of the client browser; for example: "5.5".</para>
/// </devdoc>
public string Version {
get {
if (!_haveversion) {
_version = this["version"];
_haveversion = true;
}
return _version;
}
}
/// <devdoc>
/// <para>Returns the major version number of the client browser; for example: 3.</para>
/// </devdoc>
public int MajorVersion {
get {
if (!_havemajorversion) {
try {
_majorversion = int.Parse(this["majorversion"], CultureInfo.InvariantCulture);
_havemajorversion = true;
}
catch (FormatException e) {
throw BuildParseError(e, "majorversion");
}
}
return _majorversion;
}
}
Exception BuildParseError(Exception e, string capsKey) {
string message = SR.GetString(SR.Invalid_string_from_browser_caps, e.Message, capsKey, this[capsKey]);
// to show ConfigurationException in stack trace
ConfigurationException configEx = new ConfigurationErrorsException(message, e);
// I want it to look like an unhandled exception
HttpUnhandledException httpUnhandledEx = new HttpUnhandledException(null, null);
// but show message from outer exception (it normally shows the inner-most)
httpUnhandledEx.SetFormatter(new UseLastUnhandledErrorFormatter(configEx));
return httpUnhandledEx;
}
bool CapsParseBool(string capsKey) {
try {
return bool.Parse(this[capsKey]);
}
catch (FormatException e) {
throw BuildParseError(e, capsKey);
}
}
/// <devdoc>
/// <para>Returns the minor version number of the client browser; for example: .01.</para>
/// </devdoc>
public double MinorVersion {
get {
if (!_haveminorversion) {
try {
// see ASURT 11176
_minorversion = double.Parse(
this["minorversion"],
NumberStyles.Float | NumberStyles.AllowDecimalPoint,
NumberFormatInfo.InvariantInfo);
_haveminorversion = true;
}
catch (FormatException e) {
throw BuildParseError(e, "majorversion");
}
}
return _minorversion;
}
}
/// <devdoc>
/// <para>Returns the platform's name; for example, "Win32".</para>
/// </devdoc>
public string Platform {
get {
if (!_haveplatform) {
_platform = this["platform"];
_haveplatform = true;
}
return _platform;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Type TagWriter {
get {
try {
if (!_havetagwriter) {
string tagWriter = this["tagwriter"];
if (String.IsNullOrEmpty(tagWriter)) {
_tagwriter = null;
}
else if (string.Compare(tagWriter, typeof(System.Web.UI.HtmlTextWriter).FullName, false, CultureInfo.InvariantCulture) == 0) {
_tagwriter= typeof(System.Web.UI.HtmlTextWriter);
}
else {
_tagwriter = System.Type.GetType(tagWriter, true /*throwOnError*///);
/* }
_havetagwriter = true;
}
}
catch (Exception e) {
throw BuildParseError(e, "tagwriter");
}
return _tagwriter;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Version EcmaScriptVersion {
get {
if (!_haveecmascriptversion) {
_ecmascriptversion = new Version(this["ecmascriptversion"]);
_haveecmascriptversion = true;
}
return _ecmascriptversion;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Version MSDomVersion {
get {
if (!_havemsdomversion) {
_msdomversion = new Version(this["msdomversion"]);
_havemsdomversion = true;
}
return _msdomversion;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Version W3CDomVersion {
get {
if (!_havew3cdomversion) {
_w3cdomversion = new Version(this["w3cdomversion"]);
_havew3cdomversion = true;
}
return _w3cdomversion;
}
}
/// <devdoc>
/// <para>Indicates whether the browser client is in beta.</para>
/// </devdoc>
public bool Beta {
get {
if (!_havebeta) {
_beta = CapsParseBool("beta");
_havebeta = true;
}
return _beta;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser is a Web-crawling search engine.</para>
/// </devdoc>
public bool Crawler {
get {
if (!_havecrawler) {
_crawler = CapsParseBool("crawler");
_havecrawler = true;
}
return _crawler;
}
}
/// <devdoc>
/// <para>Indicates whether the client is an AOL branded browser.</para>
/// </devdoc>
public bool AOL {
get {
if (!_haveaol) {
_aol = CapsParseBool("aol");
_haveaol = true;
}
return _aol;
}
}
/// <devdoc>
/// <para>Indicates whether the client is a Win16-based machine.</para>
/// </devdoc>
public bool Win16 {
get {
if (!_havewin16) {
_win16 = CapsParseBool("win16");
_havewin16 = true;
}
return _win16;
}
}
/// <devdoc>
/// <para>Indicates whether the client is a Win32-based machine.</para>
/// </devdoc>
public bool Win32 {
get {
if (!_havewin32) {
_win32 = CapsParseBool("win32");
_havewin32 = true;
}
return _win32;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports HTML frames.</para>
/// </devdoc>
public bool Frames {
get {
if (!_haveframes) {
_frames = CapsParseBool("frames");
_haveframes = true;
}
return _frames;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports the bold tag.</para>
/// </devdoc>
public bool SupportsBold {
get {
if (!_havesupportsbold) {
_supportsbold = CapsParseBool("supportsBold");
_havesupportsbold = true;
}
return _supportsbold;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports the italic tag.</para>
/// </devdoc>
public bool SupportsItalic {
get {
if (!_havesupportsitalic) {
_supportsitalic = CapsParseBool("supportsItalic");
_havesupportsitalic = true;
}
return _supportsitalic;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports tables.</para>
/// </devdoc>
public bool Tables {
get {
if (!_havetables) {
_tables = CapsParseBool("tables");
_havetables = true;
}
return _tables;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports cookies.</para>
/// </devdoc>
public bool Cookies {
get {
if (!_havecookies) {
_cookies = CapsParseBool("cookies");
_havecookies = true;
}
return _cookies;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports VBScript.</para>
/// </devdoc>
public bool VBScript {
get {
if (!_havevbscript) {
_vbscript = CapsParseBool("vbscript");
_havevbscript = true;
}
return _vbscript;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports JavaScript.</para>
/// </devdoc>
[Obsolete("Use EcmaScriptVersion instead of Javascript. Major versions greater than or equal to one imply javascript support.")]
public bool JavaScript {
get {
if (!_havejavascript) {
_javascript=CapsParseBool("javascript");
_havejavascript = true;
}
return _javascript;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports Java Applets.</para>
/// </devdoc>
public bool JavaApplets {
get {
if (!_havejavaapplets) {
_javaapplets=CapsParseBool("javaapplets");
_havejavaapplets = true;
}
return _javaapplets;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports ActiveX Controls.</para>
/// </devdoc>
public bool ActiveXControls {
get {
if (!_haveactivexcontrols) {
_activexcontrols=CapsParseBool("activexcontrols");
_haveactivexcontrols = true;
}
return _activexcontrols;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports background sounds.</para>
/// </devdoc>
public bool BackgroundSounds {
get {
if (!_havebackgroundsounds) {
_backgroundsounds=CapsParseBool("backgroundsounds");
_havebackgroundsounds = true;
}
return _backgroundsounds;
}
}
/// <devdoc>
/// <para>Indicates whether the client browser supports Channel Definition Format (CDF) for webcasting.</para>
/// </devdoc>
public bool CDF {
get {
if (!_havecdf) {
_cdf = CapsParseBool("cdf");
_havecdf = true;
}
return _cdf;
}
}
private string _type;
private string _browser;
private string _version;
private int _majorversion;
private double _minorversion;
private string _platform;
private Type _tagwriter;
private Version _ecmascriptversion;
private Version _msdomversion;
private Version _w3cdomversion;
private Version _clrVersion;
private Version [] _clrVersions;
private bool _beta;
private bool _crawler;
private bool _aol;
private bool _win16;
private bool _win32;
private bool _frames;
private bool _supportsbold;
private bool _supportsitalic;
private bool _tables;
private bool _cookies;
private bool _vbscript;
private bool _javascript;
private bool _javaapplets;
private bool _activexcontrols;
private bool _backgroundsounds;
private bool _cdf;
private bool _havetype;
private bool _havebrowser;
private bool _haveversion;
private bool _havemajorversion;
private bool _haveminorversion;
private bool _haveplatform;
private bool _havetagwriter;
private bool _haveecmascriptversion;
private bool _havemsdomversion;
private bool _havew3cdomversion;
private bool _haveClrVersion;
private bool _havebeta;
private bool _havecrawler;
private bool _haveaol;
private bool _havewin16;
private bool _havewin32;
private bool _haveframes;
private bool _havesupportsbold;
private bool _havesupportsitalic;
private bool _havetables;
private bool _havecookies;
private bool _havevbscript;
private bool _havejavascript;
private bool _havejavaapplets;
private bool _haveactivexcontrols;
private bool _havebackgroundsounds;
private bool _havecdf;
*/
}
}
|