Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BrowserCapabilities.cs « System.Web « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1e219c54be9e35b2d13337ccb17be91a78a0ba4d (plain)
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
// 
// System.Web.HttpBrowserCapabilities
//
// Authors:
//   Patrik Torstensson (Patrik.Torstensson@labs2.com)
//   Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (c) 2003 Novell, Inc. (http://www.novell.com)
//

//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System.Collections;
using System.Globalization;
using System.Web.Configuration;
using System.Web.UI;

#if NET_2_0
namespace System.Web.Configuration {
	public partial class HttpCapabilitiesBase
#else

namespace System.Web {
	public partial class HttpBrowserCapabilities : HttpCapabilitiesBase
#endif
	{
		const int HaveActiveXControls = 1;
		const int HaveAOL = 2;
		const int HaveBackGroundSounds = 3;
		const int HaveBeta = 4;
		const int HaveBrowser = 5;
		const int HaveCDF = 6;
		//const int HaveClrVersion = 7;
		const int HaveCookies = 8;
		const int HaveCrawler = 9;
		const int HaveEcmaScriptVersion = 10;
		const int HaveFrames = 11;
		const int HaveJavaApplets = 12;
		const int HaveJavaScript = 13;
		const int HaveMajorVersion = 14;
		const int HaveMinorVersion = 15;
		//const int HaveMSDomVersion = 16;
		const int HavePlatform = 17;
		const int HaveTables = 18;
		//const int HaveTagWriter = 19;
		const int HaveVBScript = 20;
		const int HaveVersion = 21;
		const int HaveW3CDomVersion = 22;
		const int HaveWin16 = 23;
		const int HaveWin32 = 24;

		int flags;
		bool activeXControls;
		bool aol;
		bool backgroundSounds;
		bool beta;
		string browser;
		bool cdf;
		Version clrVersion;
		bool cookies;
		bool crawler;
		Version ecmaScriptVersion;
		bool frames;
		bool javaApplets;
		bool javaScript;
		int majorVersion;
		double minorVersion;
		//Version msDomVersion;
		string platform;
		bool tables;
		//Type tagWriter;
		bool vbscript;
		string version;
		Version w3CDomVersion;
		bool win16;
		bool win32;
		Version [] clrVersions;
		internal string useragent;

		public bool ActiveXControls {
			get {
				if (!Get (HaveActiveXControls)) {
					Set (HaveActiveXControls);
					activeXControls = ReadBoolean ("activexcontrols", false);
				}

				return activeXControls;
			}
		}

		public bool AOL {
			get {
				if (!Get (HaveAOL)) {
					Set (HaveAOL);
					aol = ReadBoolean ("aol", false);
				}

				return aol;
			}
		}

		public bool BackgroundSounds {
			get {
				if (!Get (HaveBackGroundSounds)) {
					Set (HaveBackGroundSounds);
					backgroundSounds = ReadBoolean ("backgroundsounds", false);
				}

				return backgroundSounds;
			}
		}

		public bool Beta {
			get {
				if (!Get (HaveBeta)) {
					Set (HaveBeta);
					beta = ReadBoolean ("beta", false);
				}

				return beta;
			}
		}

		public string Browser {
			get {
				if (!Get (HaveBrowser)) {
					Set (HaveBrowser);
					browser = this ["browser"];
					if (browser == null)
						browser = "Unknown";
				}

				return browser;
			}
		}
#if NET_2_0
		[MonoTODO]
		public ArrayList Browsers {
			get { throw new NotImplementedException (); }
		}
#endif
		public bool CDF {
			get {
				if (!Get (HaveCDF)) {
					Set (HaveCDF);
					cdf = ReadBoolean ("cdf", false);
				}

				return cdf;
			}
		}

		public Version ClrVersion {
			get {
				if (clrVersion == null)
					InternalGetClrVersions ();

				return clrVersion;
			}
		}

		public bool Cookies {
			get {
				if (!Get (HaveCookies)) {
					Set (HaveCookies);
					cookies = ReadBoolean ("cookies", false);
				}

				return cookies;
			}
		}

		public bool Crawler {
			get {
				if (!Get (HaveCrawler)) {
					Set (HaveCrawler);
					crawler = ReadBoolean ("crawler", false);
				}

				return crawler;
			}
		}

		public Version EcmaScriptVersion {
			get {
				if (!Get (HaveEcmaScriptVersion)) {
					string ver_str;
					Set (HaveEcmaScriptVersion);
					ver_str = this ["ecmascriptversion"];
					if (ver_str == null)
						ecmaScriptVersion = new Version (0, 0);
					else
						ecmaScriptVersion = new Version (ver_str);
				}

				return ecmaScriptVersion;
			}
		}

		public bool Frames {
			get {
				if (!Get (HaveFrames)) {
					Set (HaveFrames);
					frames = ReadBoolean ("frames", false);
				}

				return frames;
			}
		}

		public bool JavaApplets {
			get {
				if (!Get (HaveJavaApplets)) {
					Set (HaveJavaApplets);
					javaApplets = ReadBoolean ("javaapplets", false);
				}

				return javaApplets;
			}
		}

		public bool JavaScript {
			get {
				if (!Get (HaveJavaScript)) {
					Set (HaveJavaScript);
					javaScript = ReadBoolean ("javascript", false);
				}

				return javaScript;
			}
		}

		public int MajorVersion {
			get {
				if (!Get (HaveMajorVersion)) {
					Set (HaveMajorVersion);
					majorVersion = ReadInt32 ("majorver", 0);
				}

				return majorVersion;
			}
		}

		public double MinorVersion {
			get {
				if (!Get (HaveMinorVersion)) {
					Set (HaveMinorVersion);
					minorVersion = ReadDouble ("minorver", 0);
				}

				return minorVersion;
			}
		}

		public Version MSDomVersion {
			get {
				return new Version (0, 0);
			}
		}

		public string Platform {
			get {
				if (!Get (HavePlatform)) {
					Set (HavePlatform);
					platform = this ["platform"];
					if (platform == null)
						platform = "";
				}

				return platform;
			}
		}

		public bool Tables {
			get {
				if (!Get (HaveTables)) {
					Set (HaveTables);
					tables = ReadBoolean ("tables", false);
				}

				return tables;
			}
		}

		public Type TagWriter {
			get {
				return typeof (HtmlTextWriter);
			}
		}

		public string Type {
			get {
				return Browser + MajorVersion;
			}
		}

		public bool VBScript {
			get {
				if (!Get (HaveVBScript)) {
					Set (HaveVBScript);
					vbscript = ReadBoolean ("vbscript", false);
				}

				return vbscript;
			}
		}

		public string Version {
			get {
				if (!Get (HaveVersion)) {
					Set (HaveVersion);
					version = this ["version"];
					if (version == null)
						version = "";
				}

				return version;
			}
		}

		public Version W3CDomVersion {
			get {
				if (!Get (HaveW3CDomVersion)) {
					string ver_str;
					Set (HaveW3CDomVersion);
					ver_str = this ["w3cdomversion"];
					if (ver_str == null)
						w3CDomVersion = new Version (0, 0);
					else
						w3CDomVersion = new Version (ver_str);
				}

				return w3CDomVersion;
			}
		}

		public bool Win16 {
			get {
				if (!Get (HaveWin16)) {
					Set (HaveWin16);
					win16 = ReadBoolean ("win16", false);
				}

				return win16;
			}
		}

		public bool Win32 {
			get {
				// This is the list of different windows platforms that browscap.ini has.
				// Win16 Win2000 Win2003 Win32 Win95 Win98 WinME WinNT WinVI WinXP
				if (!Get (HaveWin32)) {
					Set (HaveWin32);
					string platform = Platform;
					win32 = (platform != "Win16" && platform.StartsWith ("Win"));
				}
				return win32;
			}
		}

#if NET_1_1
		public Version [] GetClrVersions ()
		{
			if ((clrVersions == null) && (clrVersion == null))
				InternalGetClrVersions ();

			return clrVersions;
		}
#endif

		void InternalGetClrVersions ()
		{
			char [] anychars = new char [] { ';', ')' };
			string s = useragent;
			ArrayList list = null;
			int idx;
			while ((s != null) && (idx = s.IndexOf (".NET CLR ")) != -1) {
				int end = s.IndexOfAny (anychars, idx + 9);
				if (end == -1)
					break;

				string ver = s.Substring (idx + 9, end - idx - 9);
				Version v = null;
				try {
					v = new Version (ver);
					if (clrVersion == null || v > clrVersion)
						clrVersion = v;

					if (list == null)
						list = new ArrayList (4);

					list.Add (v);
				} catch { }
				s = s.Substring (idx + 9);
			}
			
			if (list == null || list.Count == 0) {
				clrVersion = new Version ();
#if NET_2_0
				clrVersions = null;
#else
				clrVersions = new Version [1] { clrVersion };
#endif
			} else {
				list.Sort ();
				clrVersions = (Version []) list.ToArray (typeof (Version));
			}
		}

		bool ReadBoolean (string key, bool dflt)
		{
			string v = this [key];
			if (v == null)
				return dflt;

			return (String.Compare (v, "True", true, CultureInfo.InvariantCulture) == 0);
		}

		int ReadInt32 (string key, int dflt)
		{
			string v = this [key];
			if (v == null)
				return dflt;

			try {
				return Int32.Parse (v);
			} catch {
				return dflt;
			}
		}

		double ReadDouble (string key, double dflt)
		{
			string v = this [key];
			if (v == null)
				return dflt;

			try {
				return Double.Parse (v);
			} catch {
				return dflt;
			}
		}

		bool Get (int idx)
		{
			return (flags & (1 << idx)) != 0;
		}

		void Set (int idx)
		{
			flags |= (1 << idx);
		}
	}
}