webfontloader 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,143 @@
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
+ });
data/spec/deps.js CHANGED
@@ -14,7 +14,8 @@ goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunne
14
14
  goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.UserAgentParser","webfont.FontModuleLoader","webfont.WebFont"]);
15
15
  goog.addDependency("../../src/core/namespace.js", [], []);
16
16
  goog.addDependency("../../src/core/useragent.js", ["webfont.UserAgent"], []);
17
- goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent"]);
17
+ goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent","webfont.Version"]);
18
+ goog.addDependency("../../src/core/version.js", ["webfont.Version"], []);
18
19
  goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher"]);
19
20
  goog.addDependency("../../src/custom/customcss.js", ["webfont.CustomCss"], ["webfont.Font"]);
20
21
  goog.addDependency("../../src/fontdeck/fontdeck_script.js", ["webfont.FontdeckScript"], ["webfont.Font"]);
data/spec/index.html CHANGED
@@ -43,6 +43,7 @@
43
43
  <script src="../spec/core/fontwatchrunner_spec.js"></script>
44
44
  <script src="../spec/core/fontwatcher_spec.js"></script>
45
45
  <script src="../spec/core/webfont_spec.js"></script>
46
+ <script src="../spec/core/version_spec.js"></script>
46
47
  <script src="../spec/google/fontapiparser_spec.js"></script>
47
48
  <script src="../spec/google/fontapiurlbuilder_spec.js"></script>
48
49
  <script src="../spec/google/googlefontapi_spec.js"></script>
@@ -3,11 +3,11 @@ goog.provide('webfont.UserAgent');
3
3
  /**
4
4
  * @export
5
5
  * @param {string} name
6
- * @param {string} version
6
+ * @param {webfont.Version} version
7
7
  * @param {string} engine
8
- * @param {string} engineVersion
8
+ * @param {webfont.Version} engineVersion
9
9
  * @param {string} platform
10
- * @param {string} platformVersion
10
+ * @param {webfont.Version} platformVersion
11
11
  * @param {number|undefined} documentMode
12
12
  * @param {!webfont.BrowserInfo} browserInfo
13
13
  * @constructor
@@ -37,7 +37,7 @@ goog.scope(function () {
37
37
 
38
38
  /**
39
39
  * @export
40
- * @return {string}
40
+ * @return {webfont.Version}
41
41
  */
42
42
  UserAgent.prototype.getVersion = function() {
43
43
  return this.version_;
@@ -53,7 +53,7 @@ goog.scope(function () {
53
53
 
54
54
  /**
55
55
  * @export
56
- * @return {string}
56
+ * @return {webfont.Version}
57
57
  */
58
58
  UserAgent.prototype.getEngineVersion = function() {
59
59
  return this.engineVersion_;
@@ -69,7 +69,7 @@ goog.scope(function () {
69
69
 
70
70
  /**
71
71
  * @export
72
- * @return {string}
72
+ * @return {webfont.Version}
73
73
  */
74
74
  UserAgent.prototype.getPlatformVersion = function() {
75
75
  return this.platformVersion_;
@@ -2,6 +2,7 @@ goog.provide('webfont.UserAgentParser');
2
2
 
3
3
  goog.require('webfont.BrowserInfo');
4
4
  goog.require('webfont.UserAgent');
5
+ goog.require('webfont.Version');
5
6
 
6
7
  /**
7
8
  * @param {string} userAgent The browser userAgent string to parse.
@@ -34,11 +35,11 @@ webfont.UserAgentParser.BUILTIN_BROWSER = "BuiltinBrowser";
34
35
  */
35
36
  webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
36
37
  webfont.UserAgentParser.UNKNOWN,
38
+ new webfont.Version(),
37
39
  webfont.UserAgentParser.UNKNOWN,
40
+ new webfont.Version(),
38
41
  webfont.UserAgentParser.UNKNOWN,
39
- webfont.UserAgentParser.UNKNOWN,
40
- webfont.UserAgentParser.UNKNOWN,
41
- webfont.UserAgentParser.UNKNOWN,
42
+ new webfont.Version(),
42
43
  undefined,
43
44
  new webfont.BrowserInfo(false, false, false));
44
45
 
@@ -46,7 +47,8 @@ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
46
47
  goog.scope(function () {
47
48
  var UserAgentParser = webfont.UserAgentParser,
48
49
  BrowserInfo = webfont.BrowserInfo,
49
- UserAgent = webfont.UserAgent;
50
+ UserAgent = webfont.UserAgent,
51
+ Version = webfont.Version;
50
52
 
51
53
  /**
52
54
  * Parses the user agent string and returns an object.
@@ -93,10 +95,11 @@ goog.scope(function () {
93
95
 
94
96
  /**
95
97
  * @private
98
+ * @return {string}
96
99
  */
97
- UserAgentParser.prototype.getPlatformVersion_ = function() {
100
+ UserAgentParser.prototype.getPlatformVersionString_ = function() {
98
101
  var genericVersion = this.getMatchingGroup_(this.userAgent_,
99
- /(OS X|Windows NT|Android|CrOS) ([^;)]+)/, 2);
102
+ /(OS X|Windows NT|Android) ([^;)]+)/, 2);
100
103
  if (genericVersion) {
101
104
  return genericVersion;
102
105
  }
@@ -110,10 +113,15 @@ goog.scope(function () {
110
113
  if (iVersion) {
111
114
  return iVersion;
112
115
  }
113
- var linuxVersion = this.getMatchingGroup_(this.userAgent_,
114
- /Linux ([i\d]+)/, 1);
115
- if (linuxVersion) {
116
- return linuxVersion;
116
+ var linuxOrCrOsVersion = this.getMatchingGroup_(this.userAgent_,
117
+ /(?:Linux|CrOS) ([^;)]+)/, 1);
118
+ if (linuxOrCrOsVersion) {
119
+ var parts = linuxOrCrOsVersion.split(/\s/);
120
+ for (var i = 0; i < parts.length; i += 1) {
121
+ if (/^[\d\._]+$/.test(parts[i])) {
122
+ return parts[i];
123
+ }
124
+ }
117
125
  }
118
126
  var blackBerryVersion = this.getMatchingGroup_(this.userAgent_,
119
127
  /(BB\d{2}|BlackBerry).*?Version\/([^\s]*)/, 2);
@@ -135,31 +143,17 @@ goog.scope(function () {
135
143
  * @private
136
144
  */
137
145
  UserAgentParser.prototype.parseIeUserAgentString_ = function() {
146
+ var platform = this.getPlatform_(),
147
+ platformVersion = Version.parse(this.getPlatformVersionString_()),
148
+ browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /MSIE ([\d\w\.]+)/, 1)),
149
+ documentMode = this.getDocumentMode_(this.doc_),
150
+ supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
151
+ (platform == "Windows Phone" && platformVersion.major >= 8);
152
+
138
153
  // For IE we give MSIE as the engine name and the version of IE
139
154
  // instead of the specific Trident engine name and version
140
-
141
- var platform = this.getPlatform_();
142
- var platformVersionString = this.getPlatformVersion_();
143
-
144
- var browser = this.getMatchingGroup_(this.userAgent_, /(MSIE [\d\w\.]+)/, 1);
145
-
146
- if (browser != "") {
147
- var pair = browser.split(' ');
148
- var name = pair[0];
149
- var version = pair[1];
150
- var browserVersion = this.parseVersion_(version);
151
- var platformVersion = this.parseVersion_(platformVersionString);
152
- var supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
153
- (platform == "Windows Phone" && platformVersion.major >= 8);
154
-
155
- return new UserAgent(name, version, name, version,
156
- platform, platformVersionString, this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, false, false));
157
-
158
- }
159
-
160
- return new UserAgent("MSIE", webfont.UserAgentParser.UNKNOWN,
161
- "MSIE", webfont.UserAgentParser.UNKNOWN,
162
- platform, platformVersionString, this.getDocumentMode_(this.doc_), new BrowserInfo(false, false, false));
155
+ return new UserAgent("MSIE", browserVersion, "MSIE", browserVersion,
156
+ platform, platformVersion, documentMode, new BrowserInfo(supportWebFont, false, false));
163
157
  };
164
158
 
165
159
  /**
@@ -173,62 +167,46 @@ goog.scope(function () {
173
167
  * @private
174
168
  */
175
169
  UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
176
- var engineName = UserAgentParser.UNKNOWN;
177
- var engineVersion = UserAgentParser.UNKNOWN;
178
- var enginePair = this.getMatchingGroup_(this.userAgent_,
179
- /(Presto\/[\d\w\.]+)/, 1);
170
+ var engineName = UserAgentParser.UNKNOWN,
171
+ engineVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Presto\/([\d\w\.]+)/, 1)),
172
+ platformVersion = Version.parse(this.getPlatformVersionString_()),
173
+ documentMode = this.getDocumentMode_(this.doc_);
180
174
 
181
- if (enginePair != "") {
182
- var splittedEnginePair = enginePair.split('/');
183
-
184
- engineName = splittedEnginePair[0];
185
- engineVersion = splittedEnginePair[1];
175
+ if (engineVersion.isValid()) {
176
+ engineName = "Presto";
186
177
  } else {
187
178
  if (this.userAgent_.indexOf("Gecko") != -1) {
188
179
  engineName = "Gecko";
189
180
  }
190
- var geckoVersion = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
191
-
192
- if (geckoVersion != "") {
193
- engineVersion = geckoVersion;
194
- }
181
+ engineVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1));
195
182
  }
196
183
 
197
184
  // Check for Opera Mini first, since it looks like normal Opera
198
185
  if (this.userAgent_.indexOf("Opera Mini/") != -1) {
199
- var version = this.getMatchingGroup_(this.userAgent_, /Opera Mini\/([\d\.]+)/, 1);
200
-
201
- if (version == "") {
202
- version = UserAgentParser.UNKNOWN;
203
- }
186
+ var browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Opera Mini\/([\d\.]+)/, 1));
204
187
 
205
- return new UserAgent("OperaMini", version, engineName,
206
- engineVersion, this.getPlatform_(), this.getPlatformVersion_(),
207
- this.getDocumentMode_(this.doc_), new BrowserInfo(false, false, false));
188
+ return new UserAgent("OperaMini", browserVersion, engineName,
189
+ engineVersion, this.getPlatform_(), platformVersion,
190
+ documentMode, new BrowserInfo(false, false, false));
208
191
  }
209
192
 
210
193
  // Otherwise, find version information for normal Opera or Opera Mobile
211
194
  if (this.userAgent_.indexOf("Version/") != -1) {
212
- var versionString = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1);
195
+ var browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1));
213
196
 
214
- if (versionString != "") {
215
- var version = this.parseVersion_(versionString);
216
- return new UserAgent("Opera", versionString, engineName, engineVersion,
217
- this.getPlatform_(), this.getPlatformVersion_(),
218
- this.getDocumentMode_(this.doc_), new BrowserInfo(version.major >= 10, false, false));
197
+ if (browserVersion.isValid()) {
198
+ return new UserAgent("Opera", browserVersion, engineName, engineVersion, this.getPlatform_(),
199
+ platformVersion, documentMode, new BrowserInfo(browserVersion.major >= 10, false, false));
219
200
  }
220
201
  }
221
- var versionString = this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1);
202
+ var browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1));
222
203
 
223
- if (versionString != "") {
224
- var version = this.parseVersion_(versionString);
225
- return new UserAgent("Opera", versionString, engineName, engineVersion,
226
- this.getPlatform_(), this.getPlatformVersion_(),
227
- this.getDocumentMode_(this.doc_), new BrowserInfo(version.major >= 10, false, false));
204
+ if (browserVersion.isValid()) {
205
+ return new UserAgent("Opera", browserVersion, engineName, engineVersion, this.getPlatform_(),
206
+ platformVersion, documentMode, new BrowserInfo(browserVersion.major >= 10, false, false));
228
207
  }
229
- return new UserAgent("Opera", UserAgentParser.UNKNOWN,
230
- engineName, engineVersion, this.getPlatform_(),
231
- this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new BrowserInfo(false, false, false));
208
+ return new UserAgent("Opera", new Version(), engineName, engineVersion, this.getPlatform_(),
209
+ platformVersion, documentMode, new BrowserInfo(false, false, false));
232
210
  };
233
211
 
234
212
  /**
@@ -242,49 +220,40 @@ goog.scope(function () {
242
220
  * @private
243
221
  */
244
222
  UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
245
- var platform = this.getPlatform_();
246
- var platformVersionString = this.getPlatformVersion_();
247
- var webKitVersionString = this.getMatchingGroup_(this.userAgent_,
248
- /AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1);
249
- var supportWebFont = false;
250
-
251
- if (webKitVersionString == "") {
252
- webKitVersionString = UserAgentParser.UNKNOWN;
253
- }
254
- var webKitVersion = this.parseVersion_(webKitVersionString);
255
- var platformVersion = this.parseVersion_(platformVersionString);
256
- var name = UserAgentParser.UNKNOWN;
257
-
258
- if (this.userAgent_.indexOf("Chrome") != -1 || this.userAgent_.indexOf("CrMo") != -1 || this.userAgent_.indexOf("CriOS") != -1) {
259
- name = "Chrome";
223
+ var platform = this.getPlatform_(),
224
+ platformVersion = Version.parse(this.getPlatformVersionString_()),
225
+ webKitVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1)),
226
+ browserName = UserAgentParser.UNKNOWN,
227
+ browserVersion = new Version(),
228
+ supportWebFont = false;
229
+
230
+ if (this.userAgent_.indexOf("Chrome") != -1 ||
231
+ this.userAgent_.indexOf("CrMo") != -1 ||
232
+ this.userAgent_.indexOf("CriOS") != -1) {
233
+ browserName = "Chrome";
260
234
  } else if (/Silk\/\d/.test(this.userAgent_)) {
261
- name = "Silk";
235
+ browserName = "Silk";
262
236
  } else if (platform == "BlackBerry" || platform == "Android") {
263
- name = UserAgentParser.BUILTIN_BROWSER;
237
+ browserName = UserAgentParser.BUILTIN_BROWSER;
264
238
  } else if (this.userAgent_.indexOf("Safari") != -1) {
265
- name = "Safari";
239
+ browserName = "Safari";
266
240
  } else if (this.userAgent_.indexOf("AdobeAIR") != -1) {
267
- name = "AdobeAIR";
241
+ browserName = "AdobeAIR";
268
242
  }
269
- var version = UserAgentParser.UNKNOWN;
270
243
 
271
- if (name == UserAgentParser.BUILTIN_BROWSER) {
272
- version = UserAgentParser.UNKNOWN;
273
- } else if (/Silk\/\d/.test(this.userAgent_)) {
274
- version = this.getMatchingGroup_(this.userAgent_,
275
- /Silk\/([\d\._]+)/, 1);
244
+ if (browserName == UserAgentParser.BUILTIN_BROWSER) {
245
+ browserVersion = new Version();
246
+ } else if (browserName == "Silk") {
247
+ browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Silk\/([\d\._]+)/, 1));
276
248
  } else if (this.userAgent_.indexOf("Version/") != -1) {
277
- version = this.getMatchingGroup_(this.userAgent_,
278
- /Version\/([\d\.\w]+)/, 1);
279
- } else if (name == "Chrome") {
280
- version = this.getMatchingGroup_(this.userAgent_,
281
- /(Chrome|CrMo|CriOS)\/([\d\.]+)/, 2);
282
- } else if (name == "AdobeAIR") {
283
- version = this.getMatchingGroup_(this.userAgent_,
284
- /AdobeAIR\/([\d\.]+)/, 1);
249
+ browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.\w]+)/, 1));
250
+ } else if (browserName == "Chrome") {
251
+ browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /(Chrome|CrMo|CriOS)\/([\d\.]+)/, 2));
252
+ } else if (browserName == "AdobeAIR") {
253
+ browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /AdobeAIR\/([\d\.]+)/, 1));
285
254
  }
286
- if (name == "AdobeAIR") {
287
- var browserVersion = this.parseVersion_(version);
255
+
256
+ if (browserName == "AdobeAIR") {
288
257
  supportWebFont = browserVersion.major > 2 || browserVersion.major == 2 && browserVersion.minor >= 5;
289
258
  } else if (platform == "BlackBerry") {
290
259
  supportWebFont = platformVersion.major >= 10;
@@ -293,11 +262,12 @@ goog.scope(function () {
293
262
  } else {
294
263
  supportWebFont = webKitVersion.major >= 526 || webKitVersion.major >= 525 && webKitVersion.minor >= 13;
295
264
  }
265
+
296
266
  var hasWebKitFallbackBug = webKitVersion.major < 536 || (webKitVersion.major == 536 && webKitVersion.minor < 11),
297
267
  hasWebKitMetricsBug = platform == 'iPhone' || platform == 'iPad' || platform == 'iPod' || platform == 'Macintosh';
298
268
 
299
- return new UserAgent(name, version, "AppleWebKit", webKitVersionString,
300
- platform, platformVersionString, this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug));
269
+ return new UserAgent(browserName, browserVersion, "AppleWebKit", webKitVersion, platform, platformVersion,
270
+ this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug));
301
271
  };
302
272
 
303
273
  /**
@@ -311,57 +281,31 @@ goog.scope(function () {
311
281
  * @private
312
282
  */
313
283
  UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
314
- var name = UserAgentParser.UNKNOWN;
315
- var version = UserAgentParser.UNKNOWN;
316
- var supportWebFont = false;
284
+ var name = UserAgentParser.UNKNOWN,
285
+ version = new Version(),
286
+ platformVersion = Version.parse(this.getPlatformVersionString_()),
287
+ supportWebFont = false;
317
288
 
318
289
  if (this.userAgent_.indexOf("Firefox") != -1) {
319
290
  name = "Firefox";
320
- var versionNum = this.getMatchingGroup_(this.userAgent_,
321
- /Firefox\/([\d\w\.]+)/, 1);
322
-
323
- if (versionNum != "") {
324
- var firefoxVersion = this.parseVersion_(versionNum);
325
-
326
- version = versionNum;
327
- supportWebFont = firefoxVersion.major >= 3 &&
328
- firefoxVersion.minor >= 5;
329
- }
291
+ version = Version.parse(this.getMatchingGroup_(this.userAgent_, /Firefox\/([\d\w\.]+)/, 1));
292
+ supportWebFont = version.major >= 3 && version.minor >= 5;
330
293
  } else if (this.userAgent_.indexOf("Mozilla") != -1) {
331
294
  name = "Mozilla";
332
295
  }
333
- var geckoVersionString = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
334
296
 
335
- if (geckoVersionString == "") {
336
- geckoVersionString = UserAgentParser.UNKNOWN;
337
- } else {
338
- if (!supportWebFont) {
339
- var geckoVersion = this.parseVersion_(geckoVersionString);
340
-
341
- supportWebFont = geckoVersion.major > 1 ||
342
- geckoVersion.major == 1 && geckoVersion.minor > 9 ||
343
- geckoVersion.major == 1 && geckoVersion.minor == 9 && geckoVersion.patch >= 2 ||
344
- geckoVersionString.match(/1\.9\.1b[123]/) != null ||
345
- geckoVersionString.match(/1\.9\.1\.[\d\.]+/) != null;
346
- }
347
- }
348
- return new UserAgent(name, version, "Gecko", geckoVersionString,
349
- this.getPlatform_(), this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, false, false));
350
- };
297
+ var engineVersionString = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1),
298
+ engineVersion = Version.parse(engineVersionString);
351
299
 
352
- /**
353
- * @private
354
- */
355
- UserAgentParser.prototype.parseVersion_ = function(version) {
356
- var m = /([0-9]+)(?:\.([0-9]+)(?:\.([0-9]+)?)?)?/.exec(version),
357
- result = {};
358
-
359
- if (m) {
360
- result.major = parseInt(m[1] || -1, 10);
361
- result.minor = parseInt(m[2] || -1, 10);
362
- result.patch = parseInt(m[3] || -1, 10);
300
+ if (!supportWebFont) {
301
+ supportWebFont = engineVersion.major > 1 ||
302
+ engineVersion.major == 1 && engineVersion.minor > 9 ||
303
+ engineVersion.major == 1 && engineVersion.minor == 9 && engineVersion.patch >= 2 ||
304
+ engineVersionString.match(/1\.9\.1b[123]/) != null ||
305
+ engineVersionString.match(/1\.9\.1\.[\d\.]+/) != null;
363
306
  }
364
- return result;
307
+ return new UserAgent(name, version, "Gecko", engineVersion,
308
+ this.getPlatform_(), platformVersion, this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, false, false));
365
309
  };
366
310
 
367
311
  /**