Debian Codegraph @

closure-library/closure/goog/useragent/flash.js

raw
1 // Copyright 2006 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Flash detection.
17 * @see ../demos/useragent.html
18 */
19
20 goog.provide('goog.userAgent.flash');
21
22 goog.require('goog.string');
23
24
25 /**
26 * @define {boolean} Whether we know at compile-time that the browser doesn't
27 * have flash.
28 */
29 goog.define('goog.userAgent.flash.ASSUME_NO_FLASH', false);
30
31
32 /**
33 * Whether we can detect that the browser has flash
34 * @type {boolean}
35 * @private
36 */
37 goog.userAgent.flash.detectedFlash_ = false;
38
39
40 /**
41 * Full version information of flash installed, in form 7.0.61
42 * @type {string}
43 * @private
44 */
45 goog.userAgent.flash.detectedFlashVersion_ = '';
46
47
48 /**
49 * Initializer for goog.userAgent.flash
50 *
51 * This is a named function so that it can be stripped via the jscompiler if
52 * goog.userAgent.flash.ASSUME_NO_FLASH is true.
53 * @private
54 */
55 goog.userAgent.flash.init_ = function() {
56 if (navigator.plugins && navigator.plugins.length) {
57 var plugin = navigator.plugins['Shockwave Flash'];
58 if (plugin) {
59 goog.userAgent.flash.detectedFlash_ = true;
60 if (plugin.description) {
61 goog.userAgent.flash.detectedFlashVersion_ =
62 goog.userAgent.flash.getVersion_(plugin.description);
63 return;
64 }
65 }
66
67 if (navigator.plugins['Shockwave Flash 2.0']) {
68 goog.userAgent.flash.detectedFlash_ = true;
69 goog.userAgent.flash.detectedFlashVersion_ = '2.0.0.11';
70 return;
71 }
72 }
73
74 if (navigator.mimeTypes && navigator.mimeTypes.length) {
75 var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];
76 goog.userAgent.flash.detectedFlash_ =
77 !!(mimeType && mimeType.enabledPlugin);
78 if (goog.userAgent.flash.detectedFlash_) {
79 goog.userAgent.flash.detectedFlashVersion_ =
80 goog.userAgent.flash.getVersion_(mimeType.enabledPlugin.description);
81 return;
82 }
83 }
84
85
86 try {
87 // Try 7 first, since we know we can use GetVariable with it
88 var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
89 goog.userAgent.flash.detectedFlash_ = true;
90 goog.userAgent.flash.detectedFlashVersion_ =
91 goog.userAgent.flash.getVersion_(ax.GetVariable('$version'));
92 return;
93 } catch (e) {
94 /* Fall through */
95 }
96
97 // Try 6 next, some versions are known to crash with GetVariable calls
98
99 try {
100 var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
101 goog.userAgent.flash.detectedFlash_ = true;
102 // First public version of Flash 6
103 goog.userAgent.flash.detectedFlashVersion_ = '6.0.21';
104 return;
105 } catch (e) {
106 /* Fall through */
107 }
108
109
110 try {
111 // Try the default activeX
112 var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
113 goog.userAgent.flash.detectedFlash_ = true;
114 goog.userAgent.flash.detectedFlashVersion_ =
115 goog.userAgent.flash.getVersion_(ax.GetVariable('$version'));
116 return;
117 } catch (e) {
118 // No flash
119 }
120 };
121
122
123 /**
124 * Derived from Apple's suggested sniffer.
125 * @param {string} desc e.g. Shockwave Flash 7.0 r61.
126 * @return {string} 7.0.61.
127 * @private
128 */
129 goog.userAgent.flash.getVersion_ = function(desc) {
130 var matches = desc.match(/[\d]+/g);
131 if (!matches) {
132 return '';
133 }
134 matches.length = 3; // To standardize IE vs FF
135 return matches.join('.');
136 };
137
138
139 if (!goog.userAgent.flash.ASSUME_NO_FLASH) {
140 goog.userAgent.flash.init_();
141 }
142
143
144 /**
145 * Whether we can detect that the browser has flash
146 * @type {boolean}
147 */
148 goog.userAgent.flash.HAS_FLASH = goog.userAgent.flash.detectedFlash_;
149
150
151 /**
152 * Full version information of flash installed, in form 7.0.61
153 * @type {string}
154 */
155 goog.userAgent.flash.VERSION = goog.userAgent.flash.detectedFlashVersion_;
156
157
158 /**
159 * Whether the installed flash version is as new or newer than a given version.
160 * @param {string} version The version to check.
161 * @return {boolean} Whether the installed flash version is as new or newer
162 * than a given version.
163 */
164 goog.userAgent.flash.isVersion = function(version) {
165 return goog.string.compareVersions(goog.userAgent.flash.VERSION, version) >=
166 0;
167 };