-
Notifications
You must be signed in to change notification settings - Fork 3
/
perfidies.js
executable file
·803 lines (768 loc) · 33.8 KB
/
perfidies.js
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Plugin Check.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2___
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Austin King <[email protected]> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Plugin Finder Service Client Library.
* There are two layers to the mozilla.com/en-US/plugincheck/ page: The UI and the PFS2 API.
*
* This file is the lower level code that talks to PFS2.
*
* The main entry point into the PFS2 Client API is the findPluginInfos function.
* This funtion takes a NavigatorInfo, a list of PluginInfos, and a callback function.
*
* It will serially contact the PFS2 server for each plugin and analyze the results.
* It categorizes the plugins into disableNow, vulnerable, current, outdated, and unknown
* and the callback recieves a list of each of these types of plugins
*
* @author Austin King (ozten)
*/
if (window.Pfs === undefined) { window.Pfs = {}; }
Pfs = {
/**
* PFS2 accepts multiple mime-types per request. What is the maximum length
* of each mime-type field. If a plugin has too many mime-types then it
* will get chunked into several requests
*/
MAX_MIMES_LENGTH: 3000,
/**
* Timeout a PFS request after 3 seconds
*/
TIMEOUT: 3000,
/**
* Endpoint for the PFS2 API .
*/
endpoint: "error set me before using",
/**
* A list of well known plugin names that are *always* up to date.
* Bug#519234 - We skip RealPlayer G2 and use RealPlayer Version Plugin instead.
* @client
* @private
*/
skipPluginsNamed: ["Default Plugin", "Default Plug-in", "Mozilla Default Plug-in", "RealPlayer(tm) G2 LiveConnect-Enabled Plug-In (32-bit)"],
/**
* Status Code for incremental callback.
*
* The plugin is CURRENT, but their is also a known
* vulnerability, so it should be disbaled as soon
* as possible. No newer release is known to exist.
*/
DISABLE: "should_disable",
/**
* Status Code for incremental callback.
*
* This browser is vulnerable to exploit due to the
* currently installed plugin version. Upgrade the plugin
* to the latest version.
*
* Also can be used as a constant with PFS2Info status field
*/
VULNERABLE: "vulnerable",
/**
* Status Code for incremental callback.
*
* Version detection for this plugin is imprecise,
* and at least one plugin detected with this version
* has been reported as vulnerable. Manual inspection
* is suggested.
*
* Also can be used as a constant with PFS2Info status field
*/
MAYBE_VULNERABLE: "maybe_vulnerable",
/**
* Status Code for incremental callback
*
* This browser has an older version of the plugin installed.
* There are no known vulnerabilities. Upgrade the plugin
* to the latest version.
*
* Also can be used as a constant with PFS2Info status field
*/
OUTDATED: "outdated",
/**
* Status Code for incremental callback.
*
* Version detection for this plugin is imprecise,
* and at least one plugin detected with this version
* has been reported as outdated. Manual inspection
* is suggested.
*
* Also can be used as a constant with PFS2Info status field
*/
MAYBE_OUTDATED: "maybe_outdated",
/**
* Status Code for incremental callback
*
* The browser has a current versin of the plugin. Whee!
*
* Also can be used as a constant with PFS2Info status field
*/
CURRENT: "latest",
/**
* Status Code for incremental callback.
*
* The browser has a plugin that is not tracked by the PFS2 server.
*/
UNKNOWN: "unknown",
/**
* Status Code for incremental callback.
*
* Indicats that the browser's plugin is actually newer
* than any releases tracked by the PFS2 server.
*/
NEWER: "newer",
/**
* Given information about the browser and plugins installed
* the function contacts the PFS2 Service and analyzes each
* plugin. When completed it uses two callback functions to
* communicate progress and completion.
*
* The pluginInfos is a list of PluginInfo obejcts. The PluginInfo object
* has a mimes property. This is a space delimited list of all the mime-types the
* plugin accepts. You may want to include your own properties on each pluginInfo object for use
* during the incremental callback.
*
* @param {object} - navigatorInfo - A suitable navigatorInfo object is created via
* the function browserInfo in modern_browser.js, but you can create one directly... {
* clientOS: "Intel Mac OS X 10.5", chromeLocale: "en-US", appID: "...", appRelease: "3.5.3", appVersion: "20090824085414"
* }
* @param {object} - pluginInfos - A suitable pluginInfos array is created via
* the function browserPlugins in modern_browser.js, but you can create one directly... [{
* plugin: {}, mimes: ["mime1 mime2"], classified: false
* }]
*
* @param {function} - incrementalCallback - A function which takes one argument pfsResults. Called once
* each time a plugin is identified via the PFS2 service.
*
* @param {function} - finishedCallback - A function with no arguments which is called once finding plugins
* is completed. incremental Callback will not be called again, once this callback is invoked. It wil be invoked
* only once.
*/
findPluginInfos: function(navigatorInfo, pluginInfos, incrementalCallback, finishedCallback) {
var finderState = this.createFinder(navigatorInfo, incrementalCallback, finishedCallback);
// Walk through the plugins and get the metadata from PFS2
// PFS2 is JSONP and can't be called async using jQuery.ajax
// We'll create a queue and manage our requests
for(var i=0; i< pluginInfos.length; i++) {
if (Pfs.shouldSkipPluginNamed(pluginInfos[i].detected_version) !== true) {
finderState.findPluginQueue.push(pluginInfos[i]);
}
}
finderState.startFindingNextPlugin();
},
/**
* Creates an instance of the PluginFinder object, which tracks
* the state of calling the PFS2 server
* @private
* @returns {object}
*/
createFinder: function(navigatorInfo, incrementalCallback, finishedCallback) {
var finder = {
// A list of plugin2mimeTypes
findPluginQueue: [],
// A plugin2mimeTypes
currentPlugin: null,
currentMime: -1,
running: true,
/**
* The user supplied callback for when finding plugin information is complete
*/
finishedFn: finishedCallback,
incrementalCallbackFn: incrementalCallback,
startFindingNextPlugin: function() {
//Note unknown plugins before we start the next one
if (this.running && this.findPluginQueue.length > 0) {
this.currentPlugin = this.findPluginQueue.pop();
this.currentMime = 0;
this.findPluginInfo();
} else {
this.finishedFn();
}
},
findPluginInfo: function() {
var mime = this.currentPlugin.mimes[this.currentMime];
var that = this;
this.callPfs2(
{ detection: this.currentPlugin.detection_type, mimetype: mime },
function(){ that.pfs2Success.apply(that, arguments);},
function(){ that.pfs2Error.apply(that, arguments);}
);
},
/**
* Stops the finder from continuing to work it's way through plugins in the queue
*
* Added to support web badges, where we are only interested in making PFS2 calls
* until we hit our first "bad" plugin. Then we stop making calls.
*
* Once this method has been called, the callee will still receive a completed callback
* @public
* @void
*/
stopFindingPluginInfos: function() {
this.running = false;
},
/************* PFS2 below *************/
callPfs2: function(args_in, successFn, errorFn) {
if (Pfs.endpoint == "error set me before using") {
Pfs.e("You must configure Pfs.endpoint before using this library");
return false;
}
var args = Pfs.$.extend({}, navigatorInfo, args_in);
Pfs.$.jsonp({
cache: true,
callbackParameter: "callback",
data: args,
error: errorFn,
retry: 3,
success: successFn,
timeout: Pfs.TIMEOUT,
url: Pfs.endpoint
});
return true;
},
startFindingNextMimetypeOnCurrentPlugin: function() {
this.currentMime += 1;
if (this.currentMime < this.currentPlugin.mimes.length) {
this.findPluginInfo();
} else {
Pfs.w("Exhausted Mime-Types...");
if (this.currentPlugin !== null &&
! this.currentPlugin.classified) {
this.incrementalCallbackFn({
pluginInfo: this.currentPlugin,
pfsInfo: {},
status: Pfs.UNKNOWN,
url: ""
});
this.currentPlugin.classified = true;
}
this.startFindingNextPlugin();
}
},
/**
* pfs2Success JSON callback data has the following structure
* [
* {
* aliases: {
* literal: [String, String],
* regex: [String]
* },
* releases: {
* latest: {name: String, version: String, etc},
* others: [{name: String, version: String, etc}]
* }
* }
* ]
*/
pfs2Success: function(data, status){
var currentPluginName = this.currentPlugin.detected_version;
if (this.currentPlugin.raw && this.currentPlugin.raw.name) {
currentPluginName = this.currentPlugin.raw.name;
}
var searchingResults = true;
var pluginMatch = false;
var pluginInfo;
for (var i =0; i < data.length; i++) {
if (! searchingResults) { break; }
// Grab the current PFS info, and ensure it's well-formed and usable.
var pfsInfo = data[i];
if (! pfsInfo.aliases ||
(! pfsInfo.aliases.literal && ! pfsInfo.aliases.regex )) {
Pfs.e("Malformed PFS2 plugin info, no aliases");
break;
}
if (! pfsInfo.releases ||
! pfsInfo.releases.latest) {
Pfs.e("Malformed PFS2 plugin info, no latest release");
break;
}
// Is pfsInfo the plugin we seek?
var searchingPluginInfo = true;
if (pfsInfo.aliases.literal) {
for(var j=0; searchingPluginInfo && j < pfsInfo.aliases.literal.length; j++) {
var litName = pfsInfo.aliases.literal[j];
if (Pfs.$.trim(currentPluginName) == Pfs.$.trim(litName)) {
searchingResults = false;
searchingPluginInfo = false;
pluginMatch = true;
pluginInfo = pfsInfo;
}
}
}
if (pfsInfo.aliases.regex) {
for(var j=0; searchingPluginInfo && j < pfsInfo.aliases.regex.length; j++) {
var rxName = pfsInfo.aliases.regex[j];
if (new RegExp(rxName).test(currentPluginName)) {
searchingResults = false;
searchingPluginInfo = false;
pluginMatch = true;
pluginInfo = pfsInfo;
}
}
}
// This does not appear to be the plugin we're looking for,
// so continue.
if (!pluginMatch) { continue; }
var searchPluginRelease = true;
// Prepare a result to be reported to detection callback
var to_report = {
pluginInfo: this.currentPlugin,
pfsInfo: pfsInfo,
status: null,
url: pfsInfo.releases.latest ?
pfsInfo.releases.latest.url : ''
};
if (pfsInfo.releases.latest) {
to_report.url = pfsInfo.releases.latest.url;
to_report.release_info = pfsInfo.releases.latest;
// If a detected_version is available, use it.
// Otherwise, fall back to just plain version.
var pfs_version = (pfsInfo.releases.latest.detected_version) ?
pfsInfo.releases.latest.detected_version :
pfsInfo.releases.latest.version;
var pl_version = this.currentPlugin.detected_version;
switch(Pfs.compVersion(pl_version, pfs_version)) {
// Installed is newer than the latest in PFS
case 1:
/* No exact match records 'newer', but keeplooking */
if (Pfs.reportPluginFn) {
Pfs.reportPluginFn([pfsInfo], 'newer');
}
to_report.status = Pfs.NEWER;
this.currentPlugin.classified = true;
/* searchPluginRelease = false;
Bug#565252 keep searching even if we are newer than
the latest release, since this could be a data entry issue. */
break;
// Installed version matches latest in PFS
case 0:
// Now, let's see what the status of the latest is...
switch (pfsInfo.releases.latest.status) {
case Pfs.VULNERABLE:
case Pfs.DISABLE:
to_report.status = Pfs.DISABLE;
break;
case Pfs.MAYBE_VULNERABLE:
to_report.status = Pfs.MAYBE_VULNERABLE;
break;
case Pfs.MAYBE_OUTDATED:
to_report.status = Pfs.MAYBE_OUTDATED;
break;
default:
to_report.status = Pfs.CURRENT;
break;
}
this.currentPlugin.classified = true;
searchPluginRelease = false;
break;
// Installed may be older than latest, keep looking...
default:
break;
}
}
if (this.running && searchPluginRelease && pfsInfo.releases.others) {
var others = pfsInfo.releases.others;
for (var k=0; searchPluginRelease && k < others.length; k++) {
var c_version = (others[k].detected_version) ?
others[k].detected_version : others[k].version;
if (!c_version) {
continue;
}
to_report.release_info = others[k];
switch(Pfs.compVersion(this.currentPlugin.detected_version, c_version)) {
case 1:
//newer than ours, keep looking
break;
case 0:
if (others[k].status == Pfs.VULNERABLE) {
to_report.status = Pfs.VULNERABLE;
this.currentPlugin.classified = true;
} else {
to_report.status = Pfs.OUTDATED;
this.currentPlugin.classified = true;
}
searchPluginRelease = false;
break;
case -1:
//older than ours, keep looking
break;
default:
//keep looking
break;
}
}
if (this.currentPlugin.classified !== true) {
// Sparse matrix of version numbers...
// we know about 1.0.1 and 1.0.3 in db and this browser has 1.0.2, etc
to_report.status = Pfs.OUTDATED;
this.currentPlugin.classified = true;
}
}
if (this.currentPlugin.classified) {
this.incrementalCallbackFn(to_report);
}
}//for over the pfs2 JSON data
if (this.running === false || pluginMatch) {
searchingResults = false;
this.startFindingNextPlugin();
} else {
//none of the plugins for this mime-type were a match... try the next mime-type
this.startFindingNextMimetypeOnCurrentPlugin();
}
},
/**
* bad hostname, 500 server error, malformed JSON textStatus = 'error'
* server timeout textStatus= 'timeout'
*/
pfs2Error: function(xhr, textStatus, errorThrown){
xhr.retry = xhr.retry -1;
if (xhr.retry >= 0) {
Pfs.e("Error Type [", textStatus, "] retrying on mime/plugin ", xhr, textStatus, errorThrown, this.currentPlugin.mimes[this.currentMime], this.currentPlugin);
Pfs.$.jsonp(xhr);
} else {
Pfs.$('table.status').replaceWith(Pfs.$('#error-panel').show());
Pfs.e("Doh failed on mime/plugin ", xhr, textStatus, errorThrown, this.currentPlugin.mimes[this.currentMime], this.currentPlugin);
}
}
};
return finder;
},
/**
* Discover
*/
knownPluginsByMimeType: function(navigatorInfo, mimeType, incrementalCallback, finishedCallback) {
var pluginInfos = Pfs.simulatePlugins(mimeType);
Pfs.listPluginInfos(navigatorInfo, pluginInfos, incrementalCallback, finishedCallback);
},
/**
* @private
*/
simulatePlugins: function(mimeType) {
var simulatePlugin = { length: 1, "0": {
name: "", description: "", version: "0",
length: 1, "0": {type: mimeType}}};
return Pfs.UI.browserPlugins(simulatePlugin);
},
/**
* Given information about the browser and plugins mime-types required
* the function contacts the PFS2 Service and lists known
* plugins. When completed it uses two callback functions to
* communicate progress and completion.
*
* The pluginInfos is a list of PluginInfo obejcts. The PluginInfo object
* has a mimes property. This is a space delimited list of all the mime-types the
* plugin accepts. You may want to include your own properties on each pluginInfo object for use
* during the incremental callback.
*
* @param {object} - navigatorInfo - A suitable navigatorInfo object is created via
* the function browserInfo in modern_browser.js, but you can create one directly... {
* clientOS: "Intel Mac OS X 10.5", chromeLocale: "en-US", appID: "...", appRelease: "3.5.3", appVersion: "20090824085414"
* }
* @param {object} - pluginInfos - A suitable pluginInfos array is created via
* the function browserPlugins in modern_browser.js, but you can create one directly... [{
* plugin: {}, mimes: ["mime1 mime2"], classified: false
* }]
*
* @param {function} - incrementalCallback - A function which takes one argument pfsResults. Called once
* each time a plugin is listed via the PFS2 service.
*
* @param {function} - finishedCallback - A function with no arguments which is called once finding plugins
* is completed. incremental Callback will not be called again, once this callback is invoked. It wil be invoked
* only once.
*/
listPluginInfos: function(navigatorInfo, pluginInfos, incrementalCallback, finishedCallback) {
var listerState = this.createPluginLister(navigatorInfo, incrementalCallback, finishedCallback);
for(var i=0; i< pluginInfos.length; i++) {
listerState.findPluginQueue.push(pluginInfos[i]);
}
listerState.startFindingNextPlugin();
},
/**
* Creates an instance of the PluginLister object, which returns
* known plugins based on mime-types.
*
* @private
* @returns {object}
*/
createPluginLister: function(navigatorInfo, incrementalCallback, finishedCallback) {
var lister = this.createFinder(navigatorInfo, incrementalCallback, finishedCallback);
/**
* override createFinder's pfs2Success
*/
lister.pfs2Success = function(data, status){
for (var i =0; i < data.length; i++) {
// Grab the current PFS info, and ensure it's well-formed and usable.
var pfsInfo = data[i];
if (! pfsInfo.aliases ||
(! pfsInfo.aliases.literal && ! pfsInfo.aliases.regex )) {
Pfs.e("Malformed PFS2 plugin info, no aliases");
break;
}
if (! pfsInfo.releases ||
! pfsInfo.releases.latest) {
Pfs.e("Malformed PFS2 plugin info, no latest release");
break;
}
pfsInfo.releases.latest.name = pfsInfo.aliases.literal[0];
this.incrementalCallbackFn(pfsInfo.releases.latest);
}
this.startFindingNextPlugin();
};
return lister;
},
/**
* Compares the description of two plugin versions and returns
* either 1, 0, or -1 to indicate:
* newer = 1
* same = 0
* older = -1
* @private
* @client
* @param plugin1 {string} The first plugin description. Example: QuickTime Plug-in 7.6.2
* @param plugin2 {string} The second plugin description to compare against
* @returns {integer} The comparison results
*/
compVersion: function(v1, v2) {
if (v1 && v2) {
return this.compVersionChain( this.parseVersion(v1),
this.parseVersion(v2));
} else if (v1) {
Pfs.w("compVersion v1, v2, v2 is undefined v1=", v1, " v2=", v2);
return 1;
} else {
Pfs.w("compVersion v1, v2, either v1 or v2 or both is undefined v1=", v1, " v2=", v2);
return -1;
}
},
/**
* Ghetto BNF:
* A Version = description? version comment?
* version = versionPart | versionChain
* versionPart = digit | character
* versionChain = versionPart (seperator versionPart)+
* seperator = .
*
* v - string like "Quicktime 3.0.12"
* @private
* @client
* return a "VersionChain" which is an array of version parts example - [3, 0, 12]
*/
parseVersion: function(v) {
var tokens = v.split(' ');
var versionChain = [];
var inVersion = false;
var inNumericVersion = false;
var inCharVersion = false;
var currentVersionPart = "";
function isNumeric(c) { return ! isNaN(parseInt(c, 10)); }
function isChar(c) { return "abcdefghijklmnopqrstuvwxyz".indexOf(c.toLowerCase()) >= 0; }
function isSeperator(c) { return c === '.'; }
function startVersion(token, j) {
if (isNumeric(token.charAt(j))) {
inVersion = true;
inNumericVersion = true;
currentVersionPart += token.charAt(j);
} /* else {
skip we are in the description
}*/
}
function finishVersionPart() {
//cleanup this versionPart
if (inNumericVersion) {
versionChain.push(parseInt(currentVersionPart, 10));
inNumericVersion = false;
} else if (inCharVersion) {
versionChain.push(currentVersionPart);
inCharVersion = false;
} else {
Pfs.e("This should never happen", currentVersionPart, inNumericVersion, inCharVersion);
}
currentVersionPart = "";
}
for(var i=0; i < tokens.length; i++){
var token = Pfs.$.trim(tokens[i]);
if (token.length === 0) {
continue;
}
for(var j=0; j < token.length; j++) {
if (inVersion) {
if (isNumeric(token.charAt(j))) {
if (inCharVersion) {
finishVersionPart();
}
inNumericVersion = true;
currentVersionPart += token.charAt(j);
} else if(isSeperator(token.charAt(j))) {
finishVersionPart();
} else if(j != 0 && isChar(token.charAt(j))) {
// j != 0 - We are mid-token right? 3.0pre OK 3.0 Pre BAD
if (inNumericVersion) {
finishVersionPart();
}
inCharVersion = true;
currentVersionPart += token.charAt(j);
} else if(isSeperator(token.charAt(j))) {
finishVersionPart();
} else {
if (inNumericVersion) {
finishVersionPart();
}
return versionChain;
}
} else {
startVersion(token, j);
}
}
if (inVersion) {
//clean up previous token
finishVersionPart();
}
}
if (! inVersion) {
Pfs.w("Unable to parseVersion from " + v);
}
return versionChain;
},
/**
* Given two "version chains" it determines if the first is newer, the same, or older
* than the second argument. The results is either 1, 0, or -1
* newer = 1
* same = 0
* older = -1
* @private
* @param versionChain1 {array} A list of version components Example [5, 3, 'a']
* @param versionChain2 {array} The other version chain to compare against
* @returns integer
*/
compVersionChain: function(vc1, vc2) {
for(var i=0; i < vc1.length && i < vc2.length; i++) {
if (vc1[i] != vc2[i]) {
if (vc1[i] > vc2[i]) {
return 1;
} else {
return -1;
}
}
}
if (vc1.length != vc2.length) {
// Okay there is extra version info... is the difference significant?
if (vc1.length > vc2.length) {
for (var i = vc2.length; i < vc1.length; i++) {
var version = parseInt(vc1[i], 10);
if (isNaN(version) ||
version > 0) {
return 1;
}
}
return 0;
} else {
for (var i = vc1.length; i < vc2.length; i++) {
var version = parseInt(vc2[i], 10);
if (isNaN(version) ||
version > 0) {
return -1;
}
}
return 0;
}
}
return 0;
},
/**
* @private
*/
shouldSkipPluginNamed: function(name) {
// IEBug [].indexOf is undefined
if (this.skipPluginsNamed.indexOf) {
return this.skipPluginsNamed.indexOf(Pfs.$.trim(name)) >= 0;
} else {
return this.skipPluginsNamed.join(', ').indexOf(Pfs.$.trim(name)) >= 0;
}
},
/**
* Creates an object that can normailze and store mime types
*
* @returns {object} - the master mime instance
*/
createMasterMime: function() {
return {
seen: {},
/**
* normalizes a mime type. Example application/x-java-applet;version=1.3
* becomes application/x-java-applet
*/
normalize: function(mime) {
return mime.split(';')[0];
}
};
},
/**
* Log an error message if there is a console
* @variadic
* @param {object} or {string}
*/
e: function(msg) {if (window.console && console.error && console.error.apply) {console.error.apply(console, arguments);}},
/**
* Log a warning if there is a console
* @variadic
* @param {object} or {string}
*/
w: function(msg) {if (window.console && console.warn && console.warn.apply) {window.console.warn.apply(window.console, arguments);}},
/**
* Log a warning if there is a console
* @variadic
* @param {object} or {string}
*/
i: function(msg) {if (window.console && console.info && console.info.apply) {console.info.apply(console, arguments);}}
};
/*
if (window.opera) {
window.console = window.console || {};
console.info || (console.error = opera.postError)
console.info || (console.warn = opera.postError)
console.info || (console.info = opera.postError)
} else if (! window.console) {
var ul = Pfs.$('body').append('IE Console: <ul id="console"></ul>');
window.ielog = function(msg) {
ul.append('<li>' + msg + '</li>');
};
window.console = {};
console.error = window.ielog;
console.warn = window.ielog;
console.info = window.ielog;
}*/
//Bug#535030 - All PFS scripts will use Pfs.$ to access jQuery, so that additional inclusions of
// jQuery or a conflicting library won't break jQuery or it's plugins
Pfs.$ = jQuery.noConflict();