-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtjava.js
3954 lines (3510 loc) · 151 KB
/
dtjava.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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/**
The Java Deployment Toolkit is a utility to deploy Java content in
the browser as applets or applications using the right version of Java.
If needed it can initiate an upgrade of user's system to install required
components of Java platform.
<p>
Note that some of the Deployment Toolkit methods may not be fully operational if
used before web page body is loaded (because DT native plugins could not be instantiated).
If you intend to use it before web page DOM tree is ready then dtjava.js
needs to be loaded inside the body element of the page and before use of other DT APIs.
@module java/deployment_toolkit
*/
var dtjava = function() {
function notNull(o) {
return (o != undefined && o != null);
}
function isDef(fn) {
return (fn != null && typeof fn != "undefined");
}
//return true if any of patterns from query list is found in the given string
function containsAny(lst, str) {
for (var q = 0; q < lst.length; q++) {
if (str.indexOf(lst[q]) != -1) {
return true;
}
}
return false;
}
/* Location of static web content - images, javascript files. */
var jscodebase = (function () {
// <script> elements are added to the DOM and run synchronously,
// the currently running script will also be the last element in the array
var scripts = document.getElementsByTagName("script");
var src = scripts[scripts.length - 1].getAttribute("src");
return src ? src.substring(0, src.lastIndexOf('/') + 1) : "";
})();
//set to true to disable FX auto install (before release)
var noFXAutoInstall = false;
// page has no body yet, postpone plugin installation
postponeNativePluginInstallation = false;
// JRE version we start to have JRE and FX true co-bundle
var minJRECobundleVersion = "1.7.0_06";
//aliases
var d = document;
var w = window;
var cbDone = false; //done with onload callbacks
var domInternalCb = []; //list of internal callbacks
var domCb = []; //list of callbacks
var ua = null;
// Add internal function to be called on DOM ready event.
// These functions will be called before functions added by addOnDomReady().
// Used to do internal initialization (installing native plug-in) to avoid
// race condition with user requests.
function addOnDomReadyInternal(fn) {
if (cbDone) {
fn();
} else {
domInternalCb[domInternalCb.length] = fn;
}
}
// add function to be called on DOM ready event
function addOnDomReady(fn) {
if (cbDone) {
fn();
} else {
domCb[domCb.length] = fn;
}
}
//invoke pending onload callbacks
function invokeCallbacks() {
if (!cbDone) {
//swfoject.js tests whether DOM is actually ready first
// in order to not fire too early. Use same heuristic
try {
var t = d.getElementsByTagName("body")[0].appendChild(
d.createElement("div"));
t.parentNode.removeChild(t);
} catch (e) {
return;
}
cbDone = true;
for (var i = 0; i < domInternalCb.length; i++) {
domInternalCb[i]();
}
for (var i = 0; i < domCb.length; i++) {
domCb[i]();
}
}
}
//cross browser onload support.
//Derived from swfobject.js
function addOnload(fn) {
if (isDef(w.addEventListener)) {
w.addEventListener("load", fn, false);
} else if (isDef(d.addEventListener)) {
d.addEventListener("load", fn, false);
} else if (isDef(w.attachEvent)) {
w.attachEvent("onload", fn);
//TODO: swfobject also keeps references to the listeners to detach them on onload
// to avoid memory leaks ...
} else if (typeof w.onload == "function") {
var fnOld = w.onload;
w.onload = function() {
fnOld();
fn();
};
} else {
w.onload = fn;
}
}
function detectEnv() {
var dom = isDef(d.getElementById) && isDef(d.getElementsByTagName) && isDef(d.createElement);
var u = navigator.userAgent.toLowerCase(),
p = navigator.platform.toLowerCase();
//NB: may need to be refined as some user agent may contain strings related to other browsers
// (e.g. Chrome has both Safari and mozilla, Safari also has mozilla
var windows = p ? /win/.test(p) : /win/.test(u),
mac = p ? /mac/.test(p) : /mac/.test(u),
linux = p ? /linux/.test(p) : /linux/.test(u),
chrome = /chrome/.test(u),
// get webkit version or false if not webkit
webkit = !chrome && /webkit/.test(u) ?
parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false,
opera = /opera/.test(u),
cputype = null,
osVersion = null;
var ie = false;
try {
//Used to be using trick from
// http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
//ie = !+"\v1",
//but it does not work with IE9 in standards mode
//Reverting to alternative - use execScript
ie = isDef(window.execScript);
// IE 11 does not support execScript any more and no exception is thrown, so lets use more naive test.
// http://msdn.microsoft.com/en-us/library/ie/bg182625(v=vs.85).aspx
if (!ie) { // We do not want to overwrite if ie was detected above.
ie = (navigator.userAgent.match(/Trident/i) != null);
}
} catch (ee) {
//if javafx app is in the iframe and content of main window is coming from other domain
// then some browsers may restrict access to outer window properties,
// e.g. FF can throw exception for top.execScript (see RT-17885)
//We could revert to more naive test, e.g. test user agent for "MSIE " string
// but so far IE does not seem to throw exception => if we get here it is not IE anyways
ie = false;
}
var edge = false;
var noActiveX = false;
edge = (navigator.userAgent.match(/Edge/i) != null);
// If IE and Windows 8 or Windows 8.1 then check for Metro mode
if(ie && navigator.userAgent.match(/Windows NT 6\.[23]/i) != null) {
try {
// try to create a known ActiveX object
new ActiveXObject("htmlfile");
} catch(e) {
// ActiveX is disabled or not supported.
noActiveX = true;
}
}
if(edge || noActiveX) {
ie = false;
}
var noPluginWebBrowser = edge || chrome || noActiveX;
//we are not required to detect everything and can leave values null as
// long as we later treat them accordingly.
//We use "cputype" to detect if given hardware is supported,
// e.g. we do not support PPC or iPhone/iPad despite they are running Mac OS
//We use "osVersion" to detect if Java/JavaFX can be installed on this OS
// e.g. Oracle Java for Mac requires 10.7.3
if (mac) {
if ((p && /intel/.test(p)) || /intel/.test(u)) {
cputype = "intel";
}
//looking for things like 10_7, 10_6_8, 10.4 in the user agent
var t = u.match(/mac os x (10[0-9_\.]+)/);
//normalize to "." separators
osVersion = notNull(t) ? t[0].replace("mac os x ","").replace(/_/g, ".") : null;
}
// trim() is not supported by IE10 and before
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
// startsWith() is not supported by IE
if(typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function(searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
}
}
// Check mime types. Works with netscape family browsers and checks latest installed plugin only
var mm = navigator.mimeTypes;
var jre = null;
var deploy = null;
var fx = null;
var override = false;
if (typeof __dtjavaTestHook__ !== 'undefined' &&
__dtjavaTestHook__ != null &&
__dtjavaTestHook__.jre != null &&
__dtjavaTestHook__.jfx != null &&
__dtjavaTestHook__.deploy != null) {
jre = __dtjavaTestHook__.jre;
deploy = __dtjavaTestHook__.deploy;
fx = __dtjavaTestHook__.jfx;
override = true;
}
else {
//Cache configuration from plugin mimetypes
//It is only available for NPAPI browsers
for (var t = 0; t < mm.length; t++) {
// The jpi-version is the JRE version.
var m = navigator.mimeTypes[t].type;
if (m.indexOf("application/x-java-applet;version") != -1 && m.indexOf('=') != -1) {
var v = m.substring(m.indexOf('=') + 1);
// Use the existing version comparison mechanism to ensure that
// the latest JRE is selected ( "versionA"<="VersionB" equals to
// versionCheck("versionA+","versionB") returns "true")
if(jre == null || versionCheck(jre + "+", v)){
jre = v;
}
}
//Supported for 7u6 or later
if (m.indexOf("application/x-java-applet;deploy") != -1 && m.indexOf('=') != -1) {
deploy = m.substring(m.indexOf('=') + 1);
}
//javafx version for cobundled javafx (7u6+)
if (m.indexOf("application/x-java-applet;javafx") != -1 && m.indexOf('=') != -1) {
fx = m.substring(m.indexOf('=') + 1);
}
}
}
return {haveDom:dom, wk:webkit, ie:ie, win:windows,
linux:linux, mac:mac, op: opera, chrome:chrome, edge:edge,
jre:jre, deploy:deploy, fx:fx, noPluginWebBrowser:noPluginWebBrowser,
cputype: cputype, osVersion: osVersion, override: override};
}
function showMessageBox() {
var message = 'Java Plug-in is not supported by this browser. <a href="https://java.com/dt-redirect">More info</a>';
var mbStyle = 'background-color: #ffffce;text-align: left;border: solid 1px #f0c000; padding: 1.65em 1.65em .75em 0.5em; font-family: Helvetica, Arial, sans-serif; font-size: 75%; top:5;left:5;position:absolute; opacity:0.9; width:600px;';
var messageStyle = "border: .85px; margin:-2.2em 0 0.55em 2.5em;";
var messageBox = '<img src="https://java.com/js/alert_16.png"><div style="'+ messageStyle +'"><p>'+ message + '</p>';
var divTag = document.createElement("div");
divTag.id = "messagebox";
divTag.setAttribute('style', mbStyle);
divTag.innerHTML = messageBox;
document.body.appendChild(divTag);
}
//partially derived from swfobject.js
var initDone = false;
function init() {
if (typeof __dtjavaTestHook__ !== 'undefined') {
jre = null;
jfx = null;
deploy = null;
if ((__dtjavaTestHook__ != null) && (__dtjavaTestHook__.args != null)) {
jre = __dtjavaTestHook__.args.jre;
jfx = __dtjavaTestHook__.args.jfx;
deploy = __dtjavaTestHook__.args.deploy;
}
if ((window.location.href.indexOf('http://localhost') == 0) ||
(window.location.href.indexOf('file:///') == 0)) {
__dtjavaTestHook__ = {
detectEnv: detectEnv,
Version: Version,
checkFXSupport: checkFXSupport,
versionCheck: versionCheck,
versionCheckFX: versionCheckFX,
jre: jre,
jfx: jfx,
deploy: deploy
};
}
}
if (initDone) return;
ua = detectEnv();
if (!ua.haveDom) {
return;
}
//NB: dtjava.js can be added dynamically and init() can be called after
// document onload event is fired
if (( isDef(d.readyState) && d.readyState == "complete") ||
(!isDef(d.readyState) &&
(d.getElementsByTagName("body")[0] || d.body))) {
invokeCallbacks();
}
if (!cbDone) {
if (isDef(d.addEventListener)) {
d.addEventListener("DOMContentLoaded",
invokeCallbacks, false);
}
if (ua.ie && ua.win) {
// http://msdn.microsoft.com/en-us/library/ie/ms536343(v=vs.85).aspx
// attachEvent is not supported by IE 11.
if (isDef(d.addEventListener)) {
d.addEventListener("onreadystatechange", function() {
if (d.readyState == "complete") {
d.removeEventListener("onreadystatechange", arguments.callee, false);
invokeCallbacks();
}
}, false);
} else {
d.attachEvent("onreadystatechange", function() {
if (d.readyState == "complete") {
d.detachEvent("onreadystatechange", arguments.callee);
invokeCallbacks();
}
});
}
if (w == top) { // if not inside an iframe
(function() {
if (cbDone) {
return;
}
//AI: what for??
try {
d.documentElement.doScroll("left");
} catch(e) {
setTimeout(arguments.callee, 0);
return;
}
invokeCallbacks();
})();
}
}
if (ua.wk) {
(function() {
if (cbDone) {
return;
}
if (!/loaded|complete/.test(d.readyState)) {
setTimeout(arguments.callee, 0);
return;
}
invokeCallbacks();
})();
}
addOnload(invokeCallbacks);
}
//only try to install native plugin if we do not have DTLite
//Practically this means we are running NPAPI browser on Windows
//(Chrome or FF) and recent JRE (7u4+?)
if (!haveDTLite()) {
installNativePlugin();
}
}
function getAbsoluteUrl(jnlp){
var absoluteUrl;
if(isAbsoluteUrl(jnlp)) {
absoluteUrl = jnlp;
} else {
var location = window.location.href;
var pos = location.lastIndexOf('/');
var docbase = pos > -1 ? location.substring(0, pos + 1) : location + '/';
absoluteUrl = docbase + jnlp;
}
return absoluteUrl;
}
function launchWithJnlpProtocol(jnlp) {
document.location="jnlp:"+ getAbsoluteUrl(jnlp);
}
function isAbsoluteUrl(url){
var protocols = ["http://", "https://", "file://"];
for (var i=0; i < protocols.length; i++){
if(url.toLowerCase().startsWith(protocols[i])){
return true;;
}
}
return false;
}
/**
This class provides details on why current platform does not meet
application platform requirements. Note that severe problems are
reported immediately and therefore full check may be not performed and
some (unrelated to fatal problem)
methods may provide false positive answers.
<p>
If multiple components do not match then worst status is reported.
Application need to repeat checks on each individual component
if it want to find out all details.
@class PlatformMismatchEvent
@for dtjava
*/
function PlatformMismatchEvent(a) {
//expect to get all parameters needed
for (var p in a) {
this[p] = a[p];
}
/**
* @method toString
* @return {string}
* Returns string replesentation of event. Useful for debugging.
*/
this.toString = function() {
return "MISMATCH [os=" + this.os + ", browser=" + this.browser
+ ", jre=" + this.jre + ", fx=" + this.fx
+ ", relaunch=" + this.relaunch + ", platform="
+ this.platform + "]";
};
/**
@method isUnsupportedPlatform
@return {boolean}
Returns true if this platform (OS/hardware) is not supported in a way
to satisfy all platfrom requirements.
(E.g. page is viewed on iPhone or JavaFX 2.0 application on Solaris.)
<p>
Note that this does not include browser match data.
If platform is unsupported then application can not be
launched and user need to use another platform to view it.
*/
this.isUnsupportedPlatform = function() {
return this.os;
};
/**
@method isUnsupportedBrowser
@return {boolean}
Returns true if error is because current browser is not supported.
<p>
If true is returned and isRelaunchNeeded() returns true too then
there are known supported browsers browsers for this platform.
(but they are not necessary installed on end user system)
*/
this.isUnsupportedBrowser = function() {
return this.browser;
};
/**
@method jreStatus
@return {string}
Returns "ok" if error was not due to missing JRE.
Otherwise return error code characterizing the problem:
<ul>
<li> none - no JRE were detected on the system
<li> old - some version of JRE was detected but it does not match platform requirements
<li> oldplugin - matching JRE found but it is configured to use deprecated Java plugin that
does not support Java applets
<ul>
<p>
canAutoInstall() and isRelaunchNeeded() can be used to
get more details on how seamless user' install experience will be.
*/
this.jreStatus = function() {
return this.jre;
};
/**
* @method jreInstallerURL
* @param {string} locale (optional) Locale to be used for installation web page
* @return {string}
*
* Return URL of page to visit to install required version of Java.
* If matching java runtime is already installed or not officially supported
* then return value is null.
*/
this.jreInstallerURL = function(locale) {
if (!this.os && (this.jre == "old" || this.jre == "none")) {
return getJreUrl(locale);
}
return null;
};
/**
@method javafxStatus
@return {string}
Returns "ok" if error was not due to missing JavaFX.
Otherwise return error code characterizing the problem:
<ul>
<li> none - no JavaFX runtime is detected on the system
<li> old - some version of JavaFX runtime iss detected but it does not match platform requirements
<li> disabled - matching JavaFX is detected but it is disabled
<li> unsupported - JavaFX is not supported on this platform
<ul>
<p>
canAutoInstall() and isRelaunchNeeded() can be used to
get more details on how seamless user' install experience will be.
*/
this.javafxStatus = function() {
return this.fx;
};
/**
* @method javafxInstallerURL
* @param {string} locale (optional) Locale to be used for installation web page
* @return {string}
*
* Return URL of page to visit to install required version of JavaFX.
* If matching JavaFX runtime is already installed or not officially supported
* then return value is null.
*/
this.javafxInstallerURL = function(locale) {
if (!this.os && (this.fx == "old" || this.fx == "none")) {
return getFxUrl(locale);
}
return null;
};
/**
@method canAutoInstall
@return {boolean}
Returns true if installation of missing components can be
triggered automatically. In particular, ture is returned
if there are no missing components too.
<p>
If any of missing components need to be installed manually
(i.e. click through additional web pages) then false is returned.
*/
this.canAutoInstall = function() {
return isAutoInstallEnabled(this.platform, this.jre, this.fx);
};
/**
@method isRelaunchNeeded
@return {boolean}
Returns true if browser relaunch is needed before application can be loaded.
This often is true in conjuction with need to perform installation.
<p>
Other typical case - use of unsupported browser when
it is known that there are supported browser for this pltaform.
Then both isUnsupportedBrowser() and isRelaunchNeeded() return true.
*/
this.isRelaunchNeeded = function() {
return this.relaunch;
};
}
//returns version of instaled JavaFX runtime matching requested version
//or null otherwise
function getInstalledFXVersion(requestedVersion) {
//NPAPI browser and JRE with cobundle
if (ua.fx != null && versionCheckFX(requestedVersion, ua.fx)) {
return ua.fx;
}
//try to use DT
var p = getPlugin();
if (notNull(p)) {
try {
return p.getInstalledFXVersion(requestedVersion);
} catch(e) {}
}
return null;
}
//concatenate list with space as separator
function listToString(lst) {
if (lst != null) {
return lst.join(" ");
} else {
return null;
}
}
function addArgToList(lst, arg) {
if (notNull(lst)) {
lst.push(arg);
return lst;
} else {
var res = [arg];
return res;
}
}
function doLaunch(ld, platform, cb) {
var app = normalizeApp(ld, true);
if(ua.noPluginWebBrowser){
launchWithJnlpProtocol(app.url);
return;
}
//required argument is missing
if (!(notNull(app) && notNull(app.url))) {
throw "Required attribute missing! (application url need to be specified)";
}
//if we got array we need to copy over!
platform = new dtjava.Platform(platform);
//normalize handlers
cb = new dtjava.Callbacks(cb);
var launchFunc = function() {
//prepare jvm arguments
var jvmArgs = notNull(platform.jvmargs) ? platform.jvmargs : null;
if (notNull(platform.javafx)) {
//if FX is needed we know it is available or
// we will not get here
var v = getInstalledFXVersion(platform.javafx);
//add hint that we need FX toolkit to avoid relaunch
// if JNLP is not embedded
jvmArgs = addArgToList(jvmArgs, " -Djnlp.fx=" + v);
//for swing applications embedding FX we do not want this property as it will
// trigger FX toolkit and lead to app failure!
//But for JavaFX application it saves us relaunch as otherwise we wil launch with AWT toolkit ...
if (!notNull(ld.toolkit) || ld.toolkit == "fx") {
jvmArgs = addArgToList(jvmArgs, " -Djnlp.tk=jfx");
}
}
//if we on 7u6+ we can use DTLite plugin in the NPAPI browsers
//Caveat: as of 7u6 it does not work with Chrome on Linux because Chrome expects
// DTLite plugin to implement xembed (or claim to support xembed)
if (haveDTLite() && !(ua.linux && ua.chrome)) {
if (doLaunchUsingDTLite(app, jvmArgs, cb)) {
return;
}
}
//Did not launch yet? Try DT plugin (7u2+)
var p = getPlugin();
if (notNull(p)) {
try {
try {
//check if new DT APIs are available
if (versionCheck("10.6+", ua.deploy, false)) {
// obj.launchApp({"url" : "http://somewhere/my.jnlp",
// "jnlp_content" : "... BASE 64 ...",
// "vmargs" : [ "-ea -Djnlp.foo=bar"
// "appargs" : [ "first arg, second arg" ]
// "params" : {"p1" : "aaa", "p2" : "bbb"}});
var callArgs = {"url":app.url};
if (notNull(jvmArgs)) {
callArgs["vmargs"] = jvmArgs;
}
//Only use HTML parameters, they are supposed to overwrite values in the JNLP
//In the future we want to pass arguments too but this needs also be exposed for
// embedded deployment
if (notNull(app.params)) {
//copy over and ensure all values are strings
// (native code will ignore them otherwise)
var ptmp = {};
for (var k in app.params) {
ptmp[k] = String(app.params[k]);
}
callArgs["params"] = ptmp;
}
if (notNull(app.jnlp_content)) {
callArgs["jnlp_content"] = app.jnlp_content;
}
var err = p.launchApp(callArgs);
if (err == 0) { //0 - error
if (isDef(cb.onRuntimeError)) {
cb.onRuntimeError(app.id);
}
}
} else { //revert to old DT APIs
//older DT APIs expects vmargs as a single string
if (!p.launchApp(app.url, app.jnlp_content, listToString(jvmArgs))) {
if (isDef(cb.onRuntimeError)) {
cb.onRuntimeError(app.id);
}
}
}
return;
} catch (ee) { //temp support for older build of DT
if (!p.launchApp(app.url, app.jnlp_content)) {
if (isDef(cb.onRuntimeError)) {
cb.onRuntimeError(app.id);
}
}
return;
}
} catch (e) {
//old DT
}
} //old Java (pre DTLite)? not Windows? or old DT
//use old way to launch it using java plugin
var o = getWebstartObject(app.url);
if (notNull(d.body)) {
d.body.appendChild(o);
} else {
//should never happen
d.write(o.innerHTML);
}
}
var r = doValidateRelaxed(platform);
//can not launch, try to fix
if (r != null) {
resolveAndLaunch(app, platform, r, cb, launchFunc);
} else {
launchFunc();
}
}
//process unhandled platform error - convert to code and call callback
function reportPlatformError(app, r, cb) {
if (isDef(cb.onDeployError)) {
cb.onDeployError(app, r);
}
}
function isDTInitialized(p) {
//if plugin is blocked then p.version will be undefined
return p != null && isDef(p.version);
}
//Wait until DT plugin is initialized and then run the code
//Currently we only use it for embeded apps and Chrome on Windows
function runUsingDT(label, f) {
// Possible situations:
// a) plugin is live and we can simply run code
// - just run the code
// b) plugin is in the DOM tree but it is not initialized yet (e.g. Chrome blocking)
// and there is live timer (pendingCount > 0)
// - there could be another request. We will APPEND to it
// (this is different from dtlite as in this case we can not have multiple clicks)
// - renew timer life counter (do not want new timer)
// c) plugin is in the DOM tree and it is not fully initialized yet but timer is stopped
// - overwrite old request
// - restart timer
//
// Problem we are solving:
// when plugin is ready to serve request? How do we schedule call to happen when plugin is initialized?
// Caveat:
// Chrome can popup dialog asking user to grant permissions to load the plugin.
// There is no API to detect dialog is shown and when user grants or declines permissions
//
// Note:
// If we set property on plugin object before it is unblocked then they seem to be lost
// and are not propagated to the final object once it is instantiated.
//
// Workaround we use:
// Once plugin is added we will be checking if it is initialized and once we detect it we will execute code.
// We will stop checking after some time.
var p = getPlugin();
if (p == null) {
return; //NO DT
}
if (isDTInitialized(p)) {
f(p);
} else {
// see if we need new timer
var waitAndUse = null;
if (!isDef(dtjava.dtPendingCnt) || dtjava.dtPendingCnt == 0) {
waitAndUse = function () {
if (isDTInitialized(p)) {
if (notNull(dtjava.dtPending)) {
for (var i in dtjava.dtPending) {
dtjava.dtPending[i]();
}
}
return;
}
if (dtjava.dtPendingCnt > 0) {
dtjava.dtPendingCnt--;
setTimeout(waitAndUse, 500);
}
}
}
//add new task in queue
if (!notNull(dtjava.dtPending) || dtjava.dtPendingCnt == 0) {
dtjava.dtPending = {};
}
dtjava.dtPending[label] = f; //use map to ensure repitative actions are not queued (e.g. multiple click to launch webstart)
//reset the timer counter
dtjava.dtPendingCnt = 1000; //timer is gone after 500s
//start timer if needed
if (waitAndUse != null) waitAndUse();
}
}
//returns same mismatch event if not resolved, null if resolved
function resolveAndLaunch(app, platform, v, cb, launchFunction) {
var p = getPlugin();
if( p == null && ua.noPluginWebBrowser){
var readyStateCheck = setInterval(function() {
if(document.readyState == "complete"){
clearInterval(readyStateCheck);
showMessageBox();
}
}, 15);
return;
}
//Special case: Chrome/Windows
// (Note: IE may also block activeX control but then it will block attempts to use it too)
if (ua.chrome && ua.win && p != null && !isDTInitialized(p)) {
//this likely means DT plugin is blocked by Chrome
//tell user to grant permissions and retry
var actionLabel;
if (notNull(app.placeholder)) {
var onClickFunc = function() {w.open("https://www.java.com/en/download/faq/chrome.xml"); return false;};
var msg1 = "Please give Java permission to run on this browser web page.";
var msg2 = "Click for more information.";
var altText = "";
doShowMessageInTheArea(app, msg1, msg2, altText, "javafx-chrome.png", onClickFunc);
actionLabel = app.id + "-embed";
} else {
v.jre = "blocked";
reportPlatformError(app, v, cb);
actionLabel = "launch"; //we only queue ONE webstart launch.
//Do not want to try to queue different apps - bad UE
// (once user enable multiple things can spawn)
//Note: what if multiple webstart apps are set to launch on page load (suer do not need to click)?
// Guess do not worry for now
//Note: app.id may be null in case of webstart app.
}
//now we need to start waiter. Once DT is initialized we can proceeed
var retryFunc = function() {
var vnew = doValidateRelaxed(platform);
if (vnew == null) { //no problems with env
launchFunction();
} else {
resolveAndLaunch(app, platform, vnew, cb, launchFunction);
}
};
runUsingDT(actionLabel, retryFunc);
return;
}
if (!v.isUnsupportedPlatform() && !v.isUnsupportedBrowser()) { //otherwise fatal, at least until restart of browser
if (isMissingComponent(v) && isDef(cb.onInstallNeeded)) {
var resolveFunc= function() {
//once install is over we need to revalidate
var vnew = doValidateRelaxed(platform);
if (vnew == null) { //if no problems found - can launch
launchFunction();
} else { //TODO: what happens if we installed everything but relaunch is needed??
//We can not get here if component install was not offered for any or missing componens
//(if auto install was possible, see doInstall() implementation)
//Hence, it is safe to assume we failed to meet requirements
reportPlatformError(app, vnew, cb);
//TODO: may be should call itself again but
// then it easy can become infinite loop
//e.g. user installs but we fail to detect it because DT
// is not FX aware and retry, etc.
//TODO: think it through
}
};
cb.onInstallNeeded(app, platform, cb,
v.canAutoInstall(), v.isRelaunchNeeded(), resolveFunc);
return;
}
}
reportPlatformError(app, v, cb);
}
function haveDTLite() {
// IE does not support DTLite
if (ua.deploy != null && !ua.ie) {
return versionCheck("10.6+", ua.deploy, false);
}
return false;
}
function isDTLiteInitialized(p) {
//if plugin is blocked then p.version will be undefined
return p != null && isDef(p.version);
}
function getDTLitePlugin() {
return document.getElementById("dtlite");
}
function doInjectDTLite() {
//do not want more than one plugin
if (getDTLitePlugin() != null) return;
var p = document.createElement('embed');
p.width = '10px';
p.height = '10px';
p.id = "dtlite";
p.type = "application/x-java-applet"; //means we get latest
var div = document.createElement("div");
div.style.position = "relative";
div.style.left = "-10000px";
div.appendChild(p);
var e = document.getElementsByTagName("body");
e[0].appendChild(div);
}
function runUsingDTLite(f) {
// Possible situations:
// a) first request, plugin is not in the DOM tree yet
// - add plugin
// - setup wait mechanism and run f() once plugin is ready
// b) plugin is live and we can simply run code
// - just run the code
// c) plugin is in the DOM tree but it is not initialized yet (e.g. Chrome blocking)
// and there is live timer (pendingCount > 0)
// - there could be another request. We will override it (e.g. user clicked multiple times)
// - renew timer life counter (do not want new timer)
// d) plugin is in the DOM tree and it is not fully initialized yet but timer is stopped
// - overwrite old request
// - restart timer
//
// Problem:
// when plugin is ready to serve request? How do we schedule call to happen when plugin is initialized?
// Caveat:
// Chrome can popup dialog asking user to grant permissions to load the plugin.
// There is no API to detect dialog is shown and when user grants or declines permissions
//
// Note:
// If we set property on plugin object before it is unblocked then they seem to be lost
// and are not propagated to the final object once it is instantiated.
//
// Workaround we use:
// Once plugin is added we will be checking if it is initialized and once we detect it we will execute code.
// We will stop checking after some time.
var p = getDTLitePlugin();
if (p == null) {
doInjectDTLite();
p = getDTLitePlugin();
}
if (isDTLiteInitialized(p)) {
f(p);
} else {
// see if we need new timer
var waitAndUse = null;
if (!isDef(dtjava.dtlitePendingCnt) || dtjava.dtlitePendingCnt == 0) {
waitAndUse = function () {
if (isDef(p.version)) {
if (dtjava.pendingLaunch != null) {
dtjava.pendingLaunch(p);
}
dtjava.pendingLaunch = null;
return;
}
if (dtjava.dtlitePendingCnt > 0) {
dtjava.dtlitePendingCnt--;
setTimeout(waitAndUse, 500);
}
}
}
//add new task in queue
dtjava.pendingLaunch = f;
//reset the timer counter
dtjava.dtlitePendingCnt = 1000; //timer is gone after 500s
//start timer if needed