webfontloader 1.5.21 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,143 +0,0 @@
1
- describe('Version', function () {
2
- var Version = webfont.Version;
3
-
4
- describe('parse', function () {
5
- it('should ignore non versions', function () {
6
- expect(Version.parse('abcedf')).toEqual(new Version());
7
- expect(Version.parse('...')).toEqual(new Version());
8
- expect(Version.parse('Unknown')).toEqual(new Version());
9
- });
10
-
11
- it('should parse single digit versions', function () {
12
- expect(Version.parse('0')).toEqual(new Version(0));
13
- expect(Version.parse('1')).toEqual(new Version(1));
14
- });
15
-
16
- it('should parse two digit versions', function () {
17
- expect(Version.parse('1.0')).toEqual(new Version(1, 0));
18
- expect(Version.parse('12.9')).toEqual(new Version(12, 9));
19
- });
20
-
21
- it('should parse three digit versions', function () {
22
- expect(Version.parse('1.2.5')).toEqual(new Version(1, 2, 5));
23
- expect(Version.parse('10.0.2')).toEqual(new Version(10, 0, 2));
24
- });
25
-
26
- it('should accept alternate separators', function () {
27
- expect(Version.parse('10_8_2')).toEqual(new Version(10, 8, 2));
28
- expect(Version.parse('5-46-2')).toEqual(new Version(5, 46, 2));
29
- });
30
-
31
- it('should accept build strings', function () {
32
- expect(Version.parse('1.3.5+alpha')).toEqual(new Version(1, 3, 5, 'alpha'));
33
- expect(Version.parse('1.3.5-askdsj')).toEqual(new Version(1, 3, 5, 'askdsj'));
34
- });
35
-
36
- it('should parse real version strings', function () {
37
- expect(Version.parse('5.0')).toEqual(new Version(5, 0));
38
- expect(Version.parse('531.9')).toEqual(new Version(531, 9));
39
- expect(Version.parse('1.9.2.3')).toEqual(new Version(1, 9, 2, 3));
40
- expect(Version.parse('3.6.3')).toEqual(new Version(3, 6, 3));
41
- expect(Version.parse('1.9.2a1pre')).toEqual(new Version(1, 9, 2, 'a1pre'));
42
- expect(Version.parse('3.6a1pre')).toEqual(new Version(3, 6, null, 'a1pre'));
43
- expect(Version.parse('2.0b1')).toEqual(new Version(2, 0, null, 'b1'));
44
- expect(Version.parse('5.0.342.9')).toEqual(new Version(5, 0, 342, 9));
45
- expect(Version.parse('10_5_8')).toEqual(new Version(10, 5, 8));
46
- expect(Version.parse('18.0.1025.46')).toEqual(new Version(18, 0, 1025, 46));
47
- expect(Version.parse('4.0dp1')).toEqual(new Version(4, 0, null, 'dp1'));
48
- expect(Version.parse('528.4+')).toEqual(new Version(528, 4));
49
- expect(Version.parse('2.1-update1')).toEqual(new Version(2, 1, null, 'update1'));
50
- expect(Version.parse('10.0.22.79_1003310')).toEqual(new Version(10, 0, 22, '79_1003310'));
51
- expect(Version.parse('1.b')).toEqual(new Version(1, null, null, 'b'));
52
- expect(Version.parse('0.10.1')).toEqual(new Version(0, 10, 1));
53
- });
54
- });
55
-
56
- describe('#compare', function () {
57
- it('should return zero when two versions are equal', function () {
58
- expect(new Version(1, 2, 3).compare(new Version(1, 2, 3))).toEqual(0);
59
- });
60
-
61
- it('should return one when one version is greater', function () {
62
- expect(new Version(1, 2, 3).compare(new Version(0, 1, 3))).toEqual(1);
63
- expect(new Version(1, 2, 3).compare(new Version(1, 2, 2))).toEqual(1);
64
- expect(new Version(1, 2, 3).compare(new Version(1, 1, 3))).toEqual(1);
65
- });
66
-
67
- it('should return minus one when one version is smaller', function () {
68
- expect(new Version(1, 2, 3).compare(new Version(1, 2, 4))).toEqual(-1);
69
- expect(new Version(1, 2, 3).compare(new Version(1, 3, 3))).toEqual(-1);
70
- expect(new Version(1, 2, 3).compare(new Version(2, 2, 3))).toEqual(-1);
71
- });
72
- });
73
-
74
- describe('#eq', function () {
75
- it('should return true when two versions are equal', function () {
76
- expect(new Version(1, 2, 3).eq(new Version(1, 2, 3))).toBe(true);
77
- });
78
-
79
- it('should return false when two versions are unequal', function () {
80
- expect(new Version(3, 2, 1).eq(new Version(1, 2, 3))).toBe(false);
81
- });
82
- });
83
-
84
- describe('#gt', function () {
85
- it('should return true when one version is greater than another', function () {
86
- expect(new Version(3, 2, 1).gt(new Version(1, 2, 3))).toBe(true);
87
- });
88
-
89
- it('should return false when one version is not greater than another', function () {
90
- expect(new Version(1, 2, 3).gt(new Version(3, 2, 1))).toBe(false)
91
- });
92
- });
93
-
94
- describe('#ge', function () {
95
- it('should return true when one version is greater than another', function () {
96
- expect(new Version(3, 2, 1).ge(new Version(1, 2, 3))).toBe(true);
97
- });
98
-
99
- it('should return false when one version is not greater than another', function () {
100
- expect(new Version(1, 2, 3).ge(new Version(3, 2, 1))).toBe(false)
101
- });
102
-
103
- it('should return true when one version is equal to another', function () {
104
- expect(new Version(1, 2, 3).ge(new Version(1, 2, 3))).toBe(true);
105
- });
106
- });
107
-
108
- describe('#lt', function () {
109
- it('should return true when one version is less than another', function () {
110
- expect(new Version(1, 2, 3).lt(new Version(3, 2, 1))).toBe(true);
111
- });
112
-
113
- it('should return false when one version is not less than another', function () {
114
- expect(new Version(3, 2, 1).lt(new Version(1, 2, 3))).toBe(false)
115
- });
116
- });
117
-
118
- describe('#le', function () {
119
- it('should return true when one version is less than another', function () {
120
- expect(new Version(1, 2, 3).le(new Version(3, 2, 1))).toBe(true);
121
- });
122
-
123
- it('should return false when one version is not less than another', function () {
124
- expect(new Version(3, 2, 1).le(new Version(1, 2, 3))).toBe(false)
125
- });
126
-
127
- it('should return true when one version is equal to another', function () {
128
- expect(new Version(1, 2, 3).le(new Version(1, 2, 3))).toBe(true);
129
- });
130
- });
131
-
132
- describe('#isValid', function () {
133
- it('should return true when the version is valid', function () {
134
- expect(new Version(1).isValid()).toBe(true);
135
- expect(new Version(1, 2).isValid()).toBe(true);
136
- });
137
-
138
- it('should return false when the version is not valid', function () {
139
- expect(new Version().isValid()).toBe(false);
140
- expect(new Version(null, 1).isValid()).toBe(false);
141
- });
142
- });
143
- });
@@ -1,76 +0,0 @@
1
- goog.provide('webfont.BrowserInfo');
2
-
3
- /**
4
- * @constructor
5
- * @param {boolean} webfontSupport
6
- * @param {boolean} webKitFallbackBug
7
- * @param {boolean} webKitMetricsBug
8
- */
9
- webfont.BrowserInfo = function (webfontSupport, webKitFallbackBug, webKitMetricsBug, hasNativeFontLoading) {
10
- this.webfontSupport_ = webfontSupport;
11
- this.webKitFallbackBug_ = webKitFallbackBug;
12
- this.webKitMetricsBug_ = webKitMetricsBug;
13
- this.hasNativeFontLoading_ = hasNativeFontLoading;
14
- };
15
-
16
- goog.scope(function () {
17
- var BrowserInfo = webfont.BrowserInfo;
18
-
19
- /**
20
- * Returns true if the browser supports web fonts.
21
- *
22
- * @return {boolean}
23
- */
24
- BrowserInfo.prototype.hasWebFontSupport = function () {
25
- return this.webfontSupport_;
26
- };
27
-
28
- /**
29
- * Returns true if the browser has the WebKit fallback bug.
30
- *
31
- * The bug causes the normal CSS font stack to be ignored while
32
- * loading web fonts. Instead it picks the generic font family
33
- * (or the default generic font family) of the first instance
34
- * the web font is mentioned in CSS. It switches to this font
35
- * immediately while loading web font, causing two changes in
36
- * font to occur (compared to other browsers which only change
37
- * font once the web font has loaded.)
38
- *
39
- * The bug has been fixed and is only happens in WebKit versions
40
- * below 536.11. Even though it is fixed we still have a large
41
- * percentage of users on older WebKit versions, mostly on mobile
42
- * platforms.
43
- *
44
- * Also see: https://bugs.webkit.org/show_bug.cgi?id=76684
45
- *
46
- * @return {boolean}
47
- */
48
- BrowserInfo.prototype.hasWebKitFallbackBug = function () {
49
- return this.webKitFallbackBug_;
50
- };
51
-
52
- /**
53
- * Returns true if the browser has the WebKit metrics bug
54
- *
55
- * The metrics bug causes WebKit to change the height of a font
56
- * while loading a web font. Other browsers do not modify
57
- * the width or height of the fallback font while a web font is
58
- * loading. This caused our width and height check to be incorrect,
59
- * triggering a false positive.
60
- *
61
- * Also see: https://bugs.webkit.org/show_bug.cgi?id=110977
62
- *
63
- * @return {boolean}
64
- */
65
- BrowserInfo.prototype.hasWebKitMetricsBug = function () {
66
- return this.webKitMetricsBug_;
67
- };
68
-
69
- /**
70
- * Returns true if this browser has native font loading as
71
- * specified in: http://dev.w3.org/csswg/css-font-loading/
72
- */
73
- BrowserInfo.prototype.hasNativeFontLoading = function () {
74
- return this.hasNativeFontLoading_;
75
- };
76
- });
@@ -1,93 +0,0 @@
1
- goog.provide('webfont.UserAgent');
2
-
3
- /**
4
- * A user agent string representation.
5
- *
6
- * @param {string} name
7
- * @param {webfont.Version} version
8
- * @param {string} engine
9
- * @param {webfont.Version} engineVersion
10
- * @param {string} platform
11
- * @param {webfont.Version} platformVersion
12
- * @param {number|undefined} documentMode
13
- * @param {!webfont.BrowserInfo} browserInfo
14
- * @constructor
15
- */
16
- webfont.UserAgent = function(
17
- name,
18
- version,
19
- engine,
20
- engineVersion,
21
- platform,
22
- platformVersion,
23
- documentMode,
24
- browserInfo) {
25
- this.name_ = name;
26
- this.version_ = version;
27
- this.engine_ = engine;
28
- this.engineVersion_ = engineVersion;
29
- this.platform_ = platform;
30
- this.platformVersion_ = platformVersion;
31
- this.documentMode_ = documentMode;
32
- this.browserInfo_ = browserInfo;
33
- };
34
-
35
- goog.scope(function () {
36
- var UserAgent = webfont.UserAgent;
37
-
38
- /**
39
- * @return {string}
40
- */
41
- UserAgent.prototype.getName = function() {
42
- return this.name_;
43
- };
44
-
45
- /**
46
- * @return {webfont.Version}
47
- */
48
- UserAgent.prototype.getVersion = function() {
49
- return this.version_;
50
- };
51
-
52
- /**
53
- * @return {string}
54
- */
55
- UserAgent.prototype.getEngine = function() {
56
- return this.engine_;
57
- };
58
-
59
- /**
60
- * @return {webfont.Version}
61
- */
62
- UserAgent.prototype.getEngineVersion = function() {
63
- return this.engineVersion_;
64
- };
65
-
66
- /**
67
- * @return {string}
68
- */
69
- UserAgent.prototype.getPlatform = function() {
70
- return this.platform_;
71
- };
72
-
73
- /**
74
- * @return {webfont.Version}
75
- */
76
- UserAgent.prototype.getPlatformVersion = function() {
77
- return this.platformVersion_;
78
- };
79
-
80
- /**
81
- * @return {number|undefined}
82
- */
83
- UserAgent.prototype.getDocumentMode = function() {
84
- return this.documentMode_;
85
- };
86
-
87
- /**
88
- * @return {webfont.BrowserInfo}
89
- */
90
- UserAgent.prototype.getBrowserInfo = function() {
91
- return this.browserInfo_;
92
- };
93
- });
@@ -1,422 +0,0 @@
1
- goog.provide('webfont.UserAgentParser');
2
-
3
- goog.require('webfont.BrowserInfo');
4
- goog.require('webfont.UserAgent');
5
- goog.require('webfont.Version');
6
-
7
- /**
8
- * @param {string} userAgent The browser userAgent string to parse.
9
- * @constructor
10
- */
11
- webfont.UserAgentParser = function(userAgent, doc) {
12
- this.userAgent_ = userAgent;
13
- this.doc_ = doc;
14
- };
15
-
16
- /**
17
- * @const
18
- * @type {string}
19
- */
20
- webfont.UserAgentParser.UNKNOWN = "Unknown";
21
-
22
- /**
23
- * A constant for identifying a generic browser on a mobile platform that
24
- * doesn't really have a name, but just came with the platform. Usually these
25
- * are WebKit based, and examples are the default browser app on Android and
26
- * the default browser app on BlackBerry 10.
27
- * @const
28
- * @type {string}
29
- */
30
- webfont.UserAgentParser.BUILTIN_BROWSER = "BuiltinBrowser";
31
-
32
- /**
33
- * @const
34
- * @type {webfont.UserAgent}
35
- */
36
- webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
37
- webfont.UserAgentParser.UNKNOWN,
38
- new webfont.Version(),
39
- webfont.UserAgentParser.UNKNOWN,
40
- new webfont.Version(),
41
- webfont.UserAgentParser.UNKNOWN,
42
- new webfont.Version(),
43
- undefined,
44
- new webfont.BrowserInfo(false, false, false, false));
45
-
46
-
47
- goog.scope(function () {
48
- var UserAgentParser = webfont.UserAgentParser,
49
- BrowserInfo = webfont.BrowserInfo,
50
- UserAgent = webfont.UserAgent,
51
- Version = webfont.Version;
52
-
53
- /**
54
- * Parses the user agent string and returns an object.
55
- * @return {webfont.UserAgent}
56
- */
57
- UserAgentParser.prototype.parse = function() {
58
- if (this.isIe_()) {
59
- return this.parseIeUserAgentString_();
60
- } else if (this.isOldOpera_()) {
61
- return this.parseOldOperaUserAgentString_();
62
- } else if (this.isOpera_()) {
63
- return this.parseWebKitUserAgentString_();
64
- } else if (this.isWebKit_()) {
65
- return this.parseWebKitUserAgentString_();
66
- } else if (this.isGecko_()) {
67
- return this.parseGeckoUserAgentString_();
68
- } else {
69
- return webfont.UserAgentParser.UNKNOWN_USER_AGENT;
70
- }
71
- };
72
-
73
- /**
74
- * @private
75
- */
76
- UserAgentParser.prototype.getPlatform_ = function() {
77
- var mobileOs = this.getMatchingGroup_(this.userAgent_,
78
- /(iPod|iPad|iPhone|Android|Windows Phone|BB\d{2}|BlackBerry)/, 1);
79
-
80
- if (mobileOs != "") {
81
- if (/BB\d{2}/.test(mobileOs)) {
82
- mobileOs = "BlackBerry";
83
- }
84
- return mobileOs;
85
- }
86
- var os = this.getMatchingGroup_(this.userAgent_,
87
- /(Linux|Mac_PowerPC|Macintosh|Windows|CrOS|PlayStation|CrKey)/, 1);
88
-
89
- if (os != "") {
90
- if (os == "Mac_PowerPC") {
91
- os = "Macintosh";
92
- } else if (os == "PlayStation") {
93
- os = "Linux";
94
- }
95
- return os;
96
- }
97
- return webfont.UserAgentParser.UNKNOWN;
98
- };
99
-
100
- /**
101
- * @private
102
- * @return {string}
103
- */
104
- UserAgentParser.prototype.getPlatformVersionString_ = function() {
105
- var genericVersion = this.getMatchingGroup_(this.userAgent_,
106
- /(OS X|Windows NT|Android) ([^;)]+)/, 2);
107
- if (genericVersion) {
108
- return genericVersion;
109
- }
110
- var winPhoneVersion = this.getMatchingGroup_(this.userAgent_,
111
- /Windows Phone( OS)? ([^;)]+)/, 2);
112
- if (winPhoneVersion) {
113
- return winPhoneVersion;
114
- }
115
- var iVersion = this.getMatchingGroup_(this.userAgent_,
116
- /(iPhone )?OS ([\d_]+)/, 2);
117
- if (iVersion) {
118
- return iVersion;
119
- }
120
- var linuxOrCrOsVersion = this.getMatchingGroup_(this.userAgent_,
121
- /(?:Linux|CrOS|CrKey) ([^;)]+)/, 1);
122
- if (linuxOrCrOsVersion) {
123
- var parts = linuxOrCrOsVersion.split(/\s/);
124
- for (var i = 0; i < parts.length; i += 1) {
125
- if (/^[\d\._]+$/.test(parts[i])) {
126
- return parts[i];
127
- }
128
- }
129
- }
130
- var blackBerryVersion = this.getMatchingGroup_(this.userAgent_,
131
- /(BB\d{2}|BlackBerry).*?Version\/([^\s]*)/, 2);
132
- if (blackBerryVersion) {
133
- return blackBerryVersion;
134
- }
135
-
136
- return UserAgentParser.UNKNOWN;
137
- };
138
-
139
- /**
140
- * @private
141
- */
142
- UserAgentParser.prototype.isIe_ = function() {
143
- return this.userAgent_.indexOf("MSIE") != -1 || this.userAgent_.indexOf("Trident/") != -1;
144
- };
145
-
146
- /**
147
- * @private
148
- */
149
- UserAgentParser.prototype.parseIeUserAgentString_ = function() {
150
- var platform = this.getPlatform_(),
151
- platformVersion = Version.parse(this.getPlatformVersionString_()),
152
- browserVersion = null,
153
- engine = null,
154
- engineVersion = null,
155
- engineVersionString = this.getMatchingGroup_(this.userAgent_, /Trident\/([\d\w\.]+)/, 1),
156
- documentMode = this.getDocumentMode_(this.doc_);
157
-
158
- if (this.userAgent_.indexOf("MSIE") != -1) {
159
- browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /MSIE ([\d\w\.]+)/, 1));
160
- } else {
161
- browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /rv:([\d\w\.]+)/, 1));
162
- }
163
-
164
- if (engineVersionString != '') {
165
- engine = 'Trident';
166
- engineVersion = Version.parse(engineVersionString);
167
- } else {
168
- engine = UserAgentParser.UNKNOWN;
169
- engineVersion = new Version();
170
- }
171
-
172
- var supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
173
- (platform == "Windows Phone" && platformVersion.major >= 8);
174
-
175
- return new UserAgent(
176
- "MSIE",
177
- browserVersion,
178
- engine,
179
- engineVersion,
180
- platform,
181
- platformVersion,
182
- documentMode,
183
- new BrowserInfo(supportWebFont, false, false, !!this.doc_['fonts'])
184
- );
185
- };
186
-
187
- /**
188
- * @private
189
- */
190
- UserAgentParser.prototype.isOldOpera_ = function() {
191
- return this.userAgent_.indexOf("Opera") != -1;
192
- };
193
-
194
- /**
195
- * @private
196
- */
197
- UserAgentParser.prototype.isOpera_ = function () {
198
- return /OPR\/[\d.]+/.test(this.userAgent_);
199
- };
200
-
201
- /**
202
- * @private
203
- */
204
- UserAgentParser.prototype.parseOldOperaUserAgentString_ = function() {
205
- var engineName = UserAgentParser.UNKNOWN,
206
- engineVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Presto\/([\d\w\.]+)/, 1)),
207
- platformVersion = Version.parse(this.getPlatformVersionString_()),
208
- documentMode = this.getDocumentMode_(this.doc_);
209
-
210
- if (engineVersion.isValid()) {
211
- engineName = "Presto";
212
- } else {
213
- if (this.userAgent_.indexOf("Gecko") != -1) {
214
- engineName = "Gecko";
215
- }
216
- engineVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1));
217
- }
218
-
219
- // Check for Opera Mini first, since it looks like normal Opera
220
- if (this.userAgent_.indexOf("Opera Mini/") != -1) {
221
- var browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Opera Mini\/([\d\.]+)/, 1));
222
-
223
- return new UserAgent(
224
- "OperaMini",
225
- browserVersion,
226
- engineName,
227
- engineVersion,
228
- this.getPlatform_(),
229
- platformVersion,
230
- documentMode,
231
- new BrowserInfo(false, false, false, !!this.doc_['fonts'])
232
- );
233
- }
234
-
235
- // Otherwise, find version information for normal Opera or Opera Mobile
236
- if (this.userAgent_.indexOf("Version/") != -1) {
237
- var browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1));
238
-
239
- if (browserVersion.isValid()) {
240
- return new UserAgent(
241
- "Opera",
242
- browserVersion,
243
- engineName,
244
- engineVersion,
245
- this.getPlatform_(),
246
- platformVersion,
247
- documentMode,
248
- new BrowserInfo(browserVersion.major >= 10, false, false, !!this.doc_['fonts'])
249
- );
250
- }
251
- }
252
- var browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1));
253
-
254
- if (browserVersion.isValid()) {
255
- return new UserAgent(
256
- "Opera",
257
- browserVersion,
258
- engineName,
259
- engineVersion,
260
- this.getPlatform_(),
261
- platformVersion,
262
- documentMode,
263
- new BrowserInfo(browserVersion.major >= 10, false, false, !!this.doc_['fonts'])
264
- );
265
- }
266
- return new UserAgent(
267
- "Opera",
268
- new Version(),
269
- engineName,
270
- engineVersion,
271
- this.getPlatform_(),
272
- platformVersion,
273
- documentMode,
274
- new BrowserInfo(false, false, false, !!this.doc_['fonts'])
275
- );
276
- };
277
-
278
- /**
279
- * @private
280
- */
281
- UserAgentParser.prototype.isWebKit_ = function() {
282
- return /AppleWeb(K|k)it/.test(this.userAgent_);
283
- };
284
-
285
- /**
286
- * @private
287
- */
288
- UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
289
- var platform = this.getPlatform_(),
290
- platformVersion = Version.parse(this.getPlatformVersionString_()),
291
- webKitVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1)),
292
- browserName = UserAgentParser.UNKNOWN,
293
- browserVersion = new Version(),
294
- browserVersionString = UserAgentParser.UNKNOWN,
295
- supportWebFont = false;
296
-
297
- if (/OPR\/[\d.]+/.test(this.userAgent_)) {
298
- browserName = "Opera";
299
- } else if (this.userAgent_.indexOf("Chrome") != -1 ||
300
- this.userAgent_.indexOf("CrMo") != -1 ||
301
- this.userAgent_.indexOf("CriOS") != -1) {
302
- browserName = "Chrome";
303
- } else if (/Silk\/\d/.test(this.userAgent_)) {
304
- browserName = "Silk";
305
- } else if (platform == "BlackBerry" || platform == "Android") {
306
- browserName = UserAgentParser.BUILTIN_BROWSER;
307
- } else if (this.userAgent_.indexOf("PhantomJS") != -1) {
308
- browserName = "PhantomJS";
309
- } else if (this.userAgent_.indexOf("Safari") != -1) {
310
- browserName = "Safari";
311
- } else if (this.userAgent_.indexOf("AdobeAIR") != -1) {
312
- browserName = "AdobeAIR";
313
- } else if (this.userAgent_.indexOf("PlayStation") != -1) {
314
- browserName = "BuiltinBrowser";
315
- }
316
-
317
- if (browserName == UserAgentParser.BUILTIN_BROWSER) {
318
- browserVersionString = UserAgentParser.UNKNOWN;
319
- } else if (browserName == "Silk") {
320
- browserVersionString = this.getMatchingGroup_(this.userAgent_, /Silk\/([\d\._]+)/, 1);
321
- } else if (browserName == "Chrome") {
322
- browserVersionString = this.getMatchingGroup_(this.userAgent_, /(Chrome|CrMo|CriOS)\/([\d\.]+)/, 2);
323
- } else if (this.userAgent_.indexOf("Version/") != -1) {
324
- browserVersionString = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.\w]+)/, 1);
325
- } else if (browserName == "AdobeAIR") {
326
- browserVersionString = this.getMatchingGroup_(this.userAgent_, /AdobeAIR\/([\d\.]+)/, 1);
327
- } else if (browserName == "Opera") {
328
- browserVersionString = this.getMatchingGroup_(this.userAgent_, /OPR\/([\d.]+)/, 1);
329
- } else if (browserName == "PhantomJS") {
330
- browserVersionString = this.getMatchingGroup_(this.userAgent_, /PhantomJS\/([\d.]+)/, 1);
331
- }
332
- browserVersion = Version.parse(browserVersionString);
333
-
334
- if (browserName == "AdobeAIR") {
335
- supportWebFont = browserVersion.major > 2 || browserVersion.major == 2 && browserVersion.minor >= 5;
336
- } else if (platform == "BlackBerry") {
337
- supportWebFont = platformVersion.major >= 10;
338
- } else if (platform == "Android") {
339
- supportWebFont = platformVersion.major > 2 || (platformVersion.major == 2 && platformVersion.minor > 1);
340
- } else {
341
- supportWebFont = webKitVersion.major >= 526 || webKitVersion.major >= 525 && webKitVersion.minor >= 13;
342
- }
343
-
344
- var hasWebKitFallbackBug = webKitVersion.major < 536 || (webKitVersion.major == 536 && webKitVersion.minor < 11),
345
- hasWebKitMetricsBug = platform == 'iPhone' || platform == 'iPad' || platform == 'iPod' || platform == 'Macintosh';
346
-
347
- return new UserAgent(
348
- browserName,
349
- browserVersion,
350
- "AppleWebKit",
351
- webKitVersion,
352
- platform,
353
- platformVersion,
354
- this.getDocumentMode_(this.doc_),
355
- new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug, !!this.doc_['fonts'])
356
- );
357
- };
358
-
359
- /**
360
- * @private
361
- */
362
- UserAgentParser.prototype.isGecko_ = function() {
363
- return this.userAgent_.indexOf("Gecko") != -1;
364
- };
365
-
366
- /**
367
- * @private
368
- */
369
- UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
370
- var name = UserAgentParser.UNKNOWN,
371
- version = new Version(),
372
- platformVersion = Version.parse(this.getPlatformVersionString_()),
373
- supportWebFont = false;
374
-
375
- if (this.userAgent_.indexOf("Firefox") != -1) {
376
- name = "Firefox";
377
- version = Version.parse(this.getMatchingGroup_(this.userAgent_, /Firefox\/([\d\w\.]+)/, 1));
378
- supportWebFont = version.major >= 3 && version.minor >= 5;
379
- } else if (this.userAgent_.indexOf("Mozilla") != -1) {
380
- name = "Mozilla";
381
- }
382
-
383
- var engineVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1));
384
-
385
- if (!supportWebFont) {
386
- supportWebFont = engineVersion.major > 1 ||
387
- engineVersion.major == 1 && engineVersion.minor > 9 ||
388
- engineVersion.major == 1 && engineVersion.minor == 9 && engineVersion.patch >= 2;
389
- }
390
- return new UserAgent(
391
- name,
392
- version,
393
- "Gecko",
394
- engineVersion,
395
- this.getPlatform_(),
396
- platformVersion,
397
- this.getDocumentMode_(this.doc_),
398
- new BrowserInfo(supportWebFont, false, false, !!this.doc_['fonts'])
399
- );
400
- };
401
-
402
- /**
403
- * @private
404
- */
405
- UserAgentParser.prototype.getMatchingGroup_ = function(str,
406
- regexp, index) {
407
- var groups = str.match(regexp);
408
-
409
- if (groups && groups[index]) {
410
- return groups[index];
411
- }
412
- return "";
413
- };
414
-
415
- /**
416
- * @private
417
- */
418
- UserAgentParser.prototype.getDocumentMode_ = function(doc) {
419
- if (doc.documentMode) return doc.documentMode;
420
- return undefined;
421
- };
422
- });