This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
app_window.js
2363 lines (2088 loc) · 69.8 KB
/
app_window.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
/* global AppChrome */
/* global applications */
/* global BrowserFrame */
/* global layoutManager */
/* global ManifestHelper */
/* global OrientationManager */
/* global ScreenLayout */
/* global SettingsListener */
/* global StatusBar */
/* global Service */
/* global DUMP */
'use strict';
(function(exports) {
// Turn on this flag to debug all windows.
var DEBUG = false;
// Turn on this flag to print all trace in debugging function.
var TRACE = false;
var _id = 0;
/**
* AppWindow creates, contains, manages a
* [mozbrowser](https://developer.mozilla.org/en-US/docs/WebAPI/Browser)
* iframe. AppWindow is directly managed by AppWindowManager,
* by call resize(), open(), close() on AppWindow.
*
* Basically AppWindow would manipulate all mozbrowser events
* fired from the mozbrowser iframe by itself and show relevant UI.
*
* AppWindow is also the parent class of ActivityWindow and HomescreenWindow.
* Mostly they do the same thing but is different at some points
* like the way transitioning.
*
* About creating an AppWindow,
* you need to provide at least the web app/page URL.
* If you have also provided the manifest,
* then you would get an AppWindow object which is a web app.
* Otherwise you would get an AppWindow which is in 'Wrapper' type.
* The only one different thing between web app and web page is
* just the manifestURL.
*
* ##### Life cycle state machine of an appWindow instance
* ![appWindow Life cycle state machine](http://i.imgur.com/ELuEopw.png)
*
* @example
* var app = new AppWindow({
* url: 'http://uitest.gaiamobile.org:8080/index.html',
* manifestURL: 'http://uitest.gaiamobile.org:8080/manifest.webapp'
* });
* app.open();
*
* @class AppWindow
* @mixes BrowserMixin into AppWindow.prototype
*/
var AppWindow = function AppWindow(configuration) {
this.reConfig(configuration);
this.render();
/**
* This is fired when the app window is instantiated.
* @event AppWindow#appcreated
*/
this.publish('created');
if (DEBUG || this._DEBUG) {
this.constructor[this.instanceID] = this;
}
this.launchTime = Date.now();
return this;
};
/**
* When this option is set to true,
* an app would not be removed while it's crashed.
* And while it's opened next, we will re-render the mozbrowser iframe.
* @type {Boolean}
*/
AppWindow.SUSPENDING_ENABLED = false;
SettingsListener.observe('app-suspending.enabled', false, function(value) {
AppWindow.SUSPENDING_ENABLED = !!value;
});
/**
* Change this if new window has its own styles.
*
* @type string
* @memberof AppWindow
*/
AppWindow.prototype.CLASS_LIST = 'appWindow';
AppWindow.prototype._DEBUG = false;
/**
* This is telling us who is the hierarchy manager to manage this window.
* * HierarchyManager ->
* * AttentionWindowManager -> AttentionWindow, CallscreenWindow
* (-> its popup/activity)
* * SecureWindowManager -> SecureWindow (-> its popup/activity)
* * LockScreenWindowManager -> LockScreenWindow (-> its popup/activity)
* * GlobalOverlayWindowManager -> GlobalOverlayWindow
* (-> its popup/activity)
* * Rocketbar -> SearchWindow (-> its popup/activity)
* * AppWindowManager -> AppWindow, HomescreenWindow (-> its popup/activity)
* @type {String}
*/
AppWindow.prototype.HIERARCHY_MANAGER = 'AppWindowManager';
/**
* Generate instanceID of this instance.
*/
AppWindow.prototype.generateID = function() {
if (!this.instanceID) {
this.instanceID = this.CLASS_NAME + '_' + _id;
_id++;
}
};
/**
* Generate all configurations we need.
* @param {Object} configuration Initial configuration object
* Includes manifestURL, manifest, url, origin, name.
*/
AppWindow.prototype.reConfig = function aw_reConfig(configuration) {
// Some modules are querying appWindow.manifestURL or appWindow.origin
// so we inject all configurations into appWindow first.
for (var key in configuration) {
this[key] = configuration[key];
}
this.browser_config = configuration;
// Store initial configuration in this.config
this.config = configuration;
if (this.manifest) {
this.shortName = new ManifestHelper(this.manifest).short_name;
}
if (!this.manifest && this.config && this.config.title) {
this.updateName(this.config.title);
} else {
this.name = new ManifestHelper(this.manifest).name;
}
// Get icon splash
this.getIconForSplash();
this.generateID();
/**
* The instanceID of the root window of this window.
* @type {String}
*/
this.groupID = this.getRootWindow().instanceID;
if (this.previousWindow) {
this.previousWindow.setNextWindow(this);
} else if (this.rearWindow) {
this.rearWindow.setFrontWindow(this);
}
// W3C web app manifest "display" property takes precedence
if (this.manifest && this.manifest.display) {
switch(this.manifest.display) {
case 'fullscreen':
this._fullScreen = true;
this.config.chrome = {
scrollable: false,
maximized: false,
};
return; // Early return
case 'standalone':
this.config.chrome = {
scrollable: false,
maximized: false,
};
return;
case 'minimal-ui':
case 'browser':
this.config.chrome = {
navigation: true, //AppChrome checks for this
scrollable: true,
maximized: true
};
return;
default:
console.error('Invalid display property in web app manifest.');
}
}
// Fall back to mozApp manifest chrome and fullscreen properties
this.config.chrome = (this.manifest && this.manifest.chrome) ?
this.manifest.chrome :
this.config.chrome;
if (!this.config.chrome) {
this.config.chrome = {
scrollable: this.isBrowser(),
maximized: this.isBrowser()
};
} else if (this.config.chrome.navigation) {
this.config.chrome.scrollable = !this.isFullScreen();
// This is for backward compatibility with application that
// requests the |navigation| flag in their manifest.
this.config.chrome.maximized = true;
}
};
/**
* Update the name of this window.
* @param {String} name The new name.
*/
AppWindow.prototype.updateName = function aw_updateName(name) {
if (this.config && this.config.title) {
this.config.title = name;
}
this.name = name;
};
/**
* Represent the current pagee visibility state,
* i.e. what is currently visible. Possible value:
* 'foreground': setVisible(true)
* 'background': setVisible(false)
*
* Default value is foreground.
*/
AppWindow.prototype._visibilityState = 'foreground';
/**
* The rotating degree of current frame.
*/
AppWindow.prototype.rotatingDegree = 0;
AppWindow.prototype._dump = function aw__dump() {
console.log('======================');
try {
throw new Error('e');
} catch (e) {
this.debug(e.stack);
}
console.log('======================');
};
/**
* Set active should be only applied to top most window.
*/
AppWindow.prototype.setActive = function(enable) {
this.getTopMostWindow()._setActive(enable);
};
/**
* In order to prevent flashing of unpainted frame
* during switching from one to another,
* many event listener & callbacks are employed.
*
* When 'cardviewbeforeshow' is received, the screenshotOverlay is shown.
*
* When 'cardviewclosed' is received, the screenshotOverlay is hidden.
*
* When 'sheetdisplayed' is received, the screenshotOverlay is shown.
*
* When 'sheetsgestureend' is received the screenshotOverlay is hidden.
*
* However, setVisible *never* controls the visibility of the
* screenshotOverlay. The visibility of it is entirely event driven or can
* be triggered manually be calling _showScreenshotOverlay and
* _hideScreenshotOverlay.
*/
AppWindow.prototype.setVisible =
function aw_setVisible(visible) {
this.debug('set visibility -> ', visible);
this.setVisibleForScreenReader(visible);
this._setActive(visible);
if (visible) {
// If this window is not the lockscreen, and the screen is locked,
// we need to aria-hide the window.
this._showFrame();
} else {
this._hideFrame();
}
if (this.frontWindow) {
this.frontWindow.setVisible(visible);
}
};
/**
* Set screen reader visibility.
* @type {Boolean} A flag indicating if it should be visible to the screen
* reader.
*/
AppWindow.prototype.setVisibleForScreenReader =
function aw_setVisibleForScreenReader(visible) {
if (!this.element) {
return;
}
this.element.setAttribute('aria-hidden', !visible);
};
/**
* _showFrame turn on the frame visibility.
* So this shouldn't be invoked by others directly.
*/
AppWindow.prototype._showFrame = function aw__showFrame() {
this.debug('before showing frame');
this.reviveBrowser();
// If we're already showing, do nothing!
if (!this.browser.element.classList.contains('hidden')) {
return;
}
this.browser.element.classList.remove('hidden');
this._setVisible(true);
if (this.isHomescreen) {
return;
}
// Getting a new screenshot to force compositing before
// removing the screenshot overlay if it exists.
if (this.screenshotOverlay &&
this.screenshotOverlay.classList.contains('visible')) {
this.tryWaitForFullRepaint(this._hideScreenshotOverlay.bind(this));
}
};
/**
* _hideFrame will turn off the frame visibility.
* So this shouldn't be invoked by others directly.
*/
AppWindow.prototype._hideFrame = function aw__hideFrame() {
this.debug('before hiding frame');
// If we're already hidden, we have nothing to do!
if (!this.browser || this.browser.element.classList.contains('hidden')) {
return;
}
this._setVisible(false);
this.browser.element.classList.add('hidden');
};
/**
* An appWindow is active means:
* 1. Going to be opened.
* 2. Already opened.
* 3. Not going to be closed.
*
* Note: The element has active class unless it's at closed state.
* But a closing instance is not recognized as active.
*
* @return {Boolean} The instance is active or not.
*/
AppWindow.prototype.isActive = function aw_isActive() {
if (!this.element) {
return false;
}
if (this.element.classList.contains('will-become-active')) {
return true;
}
if (this.element.classList.contains('will-become-inactive')) {
return false;
}
if (this.transitionController) {
return (this.transitionController._transitionState == 'opened' ||
this.transitionController._transitionState == 'opening');
} else {
// Before the transition controller is inited
return false;
}
};
/**
* An appWindow should resize:
* 1. If it's active
* 2. If it was just queued for close.
*
* @return {Boolean} The instance should be resized.
*/
AppWindow.prototype.shouldResize = function aw_shouldResize() {
if (this.element.classList.contains('will-become-inactive')) {
return true;
}
return this.isActive();
};
AppWindow.prototype.isSheetTransitioning =
function aw_isSheetTransitioning() {
return this.element.classList.contains('inside-edges');
};
/**
* TODO: Integrate swipe transition.
*
* @return {Boolean} The instance is transitioning or not.
*/
AppWindow.prototype.isTransitioning = function aw_isTransitioning() {
if (this.transitionController) {
return (this.transitionController._transitionState == 'opening' ||
this.transitionController._transitionState == 'closing');
} else {
// Fallback
return (this.element.classList.contains('transition-opening') ||
this.element.classList.contains('transition-closing'));
}
};
/**
* If the instance is crashed but not resumed yet,
* it would be in suspended state.
*
* The state would be turned off once we render the browser again.
* @type {Boolean}
*/
AppWindow.prototype.suspended = false;
/**
* Re-render the browser element with the same config.
*/
AppWindow.prototype.reviveBrowser = function() {
if (this.browser) {
return;
}
this.isCrashed = false;
this.debug(' ...revived!');
this.browser = new BrowserFrame(this.browser_config);
this.browserContainer.appendChild(this.browser.element);
this.iframe = this.browser.element;
this.launchTime = Date.now();
this.suspended = false;
this.element.classList.remove('suspended');
// Launch as background by default.
this.browser.element.classList.add('hidden');
this._setVisible(false);
this.publish('resumed');
};
/**
* Remove the browser element and clear the states of the browser.
* @fires AppWindow#suspended
*/
AppWindow.prototype.destroyBrowser = function() {
if (!this.browser) {
return;
}
this.loading = false;
this.loaded = false;
this.suspended = true;
this.element.classList.add('suspended');
this.browserContainer.removeChild(this.browser.element);
this.browser = null;
this.iframe = null;
this._sslState = '';
this.publish('suspended');
};
/**
* Kill an instance.
*
* 1. If this instance has any living activity window as callee,
* all of the activity window callee would be killed.
* 2. If this instance is active, it would request to close.
*
* @fires AppWindow#appterminated
*/
AppWindow.prototype.kill = function aw_kill(evt) {
if (this._killed) {
return;
}
if (!this.isHomescreen) {
this._killed = true;
}
if (DEBUG || this._DEBUG) {
this.constructor[this.instanceID] = null;
}
// Remove callee <-> caller reference before we remove the window.
if (this.callerWindow) {
this.callerWindow.calleeWindow = null;
this.callerWindow = null;
}
if (this.calleeWindow) {
this.calleeWindow.callerWindow = null;
this.calleeWindow = null;
}
// Kill any front window.
if (this.frontWindow) {
this.frontWindow.kill();
this.frontWindow = null;
}
// Kill any next window.
if (this.nextWindow) {
this.nextWindow.kill();
this.nextWindow = null;
}
// Kill any attention window.
if (this.attentionWindow) {
this.attentionWindow.kill();
this.attentionWindow = null;
}
// If the app is the currently displayed app, switch to the homescreen
if (this.isActive() && this.getBottomMostWindow().isActive() &&
!this.isHomescreen) {
var onClosed = function() {
this.element.removeEventListener('_closed', onClosed);
this.destroy();
}.bind(this);
this.element.addEventListener('_closed', onClosed);
if (this.previousWindow) {
this.previousWindow.getBottomMostWindow().open('in-from-left');
this.close('out-to-right');
} else {
if (this.transitionController) {
// In normal case,
// the window manager will call this.close() to response
// the requestClose(), and when the timeout here is reached,
// it will not close again because transition controller
// is taking care of that.
setTimeout(this.close.bind(this, 'immediate'),
this.transitionController.CLOSING_TRANSITION_TIMEOUT);
}
this.requestClose();
}
} else {
this.destroy();
}
/**
* Fired when the instance is terminated.
* @event AppWindow#appterminated
*/
this.publish('terminated');
};
/**
* An appWindow is dead if somebody requested it to be killed.
*
* @return {Boolean} The instance is dead or not.
*/
AppWindow.prototype.isDead = function aw_isDead() {
return (this._killed || !this.element);
};
/**
* Destroy the instance.
* @fires AppWindow#appdestroyed
*/
AppWindow.prototype.destroy = function aw_destroy() {
/**
* Fired before the instance id destroyed.
* @event AppWindow#appwilldestroy
*/
// Remove previous -> next reference.
if (this.previousWindow) {
this.previousWindow.unsetNextWindow();
this.previousWindow = null;
}
// Remove rear -> front reference.
if (this.rearWindow) {
this.rearWindow.unsetFrontWindow();
this.rearWindow = null;
}
// Remove attention reference.
if (this.parentWindow) {
this.parentWindow.unsetAttentionWindow();
this.parentWindow = null;
}
this.publish('willdestroy');
this.uninstallSubComponents();
if (this.element) {
if (this.element.parentNode) {
this.element.parentNode.removeChild(this.element);
}
this.element = null;
}
/**
* Fired after the instance id destroyed.
* @event AppWindow#appdestroyed
*/
this.publish('destroyed');
};
AppWindow.prototype.containerElement = document.getElementById('windows');
AppWindow.prototype.view = function aw_view() {
return `<div class="${this.CLASS_LIST}" id="${this.instanceID}"
transition-state="closed">
<div class="identification-overlay">
<div>
<div class="icon"></div>
<span class="title"></span>
</div>
</div>
<div class="fade-overlay"></div>
<div class="touch-blocker"></div>
<div class="browser-container">
<div class="screenshot-overlay"></div>
</div>
</div>`;
};
/**
* Render the mozbrowser iframe and some overlays.
* @inner
*/
AppWindow.prototype._render = function aw__render() {
if (this.element) {
return;
}
/**
* Fired before this element is appended to the DOM tree.
* @event AppWindow#appwillrender
*/
this.publish('willrender');
var range = document.createRange();
var fragment = range.createContextualFragment(this.view());
// window.open would offer the iframe so we don't need to generate.
if (this.iframe) {
this.browser = {
element: this.iframe
};
} else {
this.browser = new BrowserFrame(this.browser_config);
}
this.element = fragment.getElementById(this.instanceID);
// For gaiauitest usage.
this.element.dataset.manifestName = this.manifest ? this.manifest.name : '';
// XXX: Remove following two lines once mozbrowser element is moved
// into appWindow.
this.frame = this.element;
this.iframe = this.browser.element;
this.iframe.dataset.frameType = 'window';
this.iframe.dataset.frameOrigin = this.origin;
this.iframe.dataset.url = this.config.url;
if (this.isFullScreen()) {
this.element.classList.add('fullscreen-app');
}
if (this.isBrowser()) {
this.element.classList.add('browser');
}
if (this.isPrivateBrowser()) {
this.element.classList.add('private');
}
this.browserContainer = this.element.querySelector('.browser-container');
this.browserContainer.appendChild(this.browser.element);
this.containerElement.appendChild(fragment);
this.screenshotOverlay = this.element.querySelector('.screenshot-overlay');
this.fadeOverlay = this.element.querySelector('.fade-overlay');
var overlay = '.identification-overlay';
this.identificationOverlay = this.element.querySelector(overlay);
var icon = '.identification-overlay .icon';
this.identificationIcon = this.element.querySelector(icon);
var title = '.identification-overlay .title';
this.identificationTitle = this.element.querySelector(title);
// Launched as background: set visibility and overlay screenshot.
// homescreen is launched at background under FTU/lockscreen too.
if (this.config.stayBackground || this.isHomescreen) {
this.setVisible(false);
}
/**
* Fired after the app window element is appended to the DOM tree.
* @event AppWindow#apprendered
*/
this.publish('rendered');
this._rendered = true;
setTimeout(this.setFrameBackground.bind(this));
};
AppWindow.prototype.render = function aw_render() {
this._render();
this._registerEvents();
this.installSubComponents();
// Pre determine the rotation degree.
this.determineRotationDegree();
};
/**
* Check an appWindow is a regular browsing window, not tied to a particular
* application.
*
* @return {Boolean} is the current instance a browsing window.
*/
AppWindow.prototype.isBrowser = function aw_isbrowser() {
return !this.manifestURL;
};
/**
* Checks if an appWindow is a private window.
*
* @return {Boolean} is the current instance a private window.
*/
AppWindow.prototype.isPrivateBrowser = function aw_isprivate() {
return !!this.browser_config.isPrivate;
};
/**
* Check an appWindow contains a certified application
*
* @return {Boolean} is the current instance a certified application.
*/
AppWindow.prototype.isCertified = function aw_iscertified() {
return this.config.manifest && 'certified' === this.config.manifest.type;
};
/**
* Try to navigate the current frame to a given url. If the current instance
* is not a browsing window, we reconfigure it to be a browser window, and
* give it a clean browser frame.
* @param {String} url The url to navigate to
*/
AppWindow.prototype.navigate = function aw_isbrowser(url) {
// Bug 1071882 - We currently only support navigating browser windows and
// apps with a role="search", which we use for the browser landing page.
var appIsSearch = this.manifest && this.manifest.role === 'search';
if (!this.isBrowser() && !appIsSearch) {
console.warn('Tried to navigate an illegal app window.');
return;
}
// Kill any front window.
if (this.frontWindow) {
this.frontWindow.kill();
this.frontWindow = null;
}
if (!this.isBrowser()) {
// Handle navigating from an app -> browser.
this.manifestURL = null;
this.manifest = null;
this.element.classList.add('browser');
// Reset the browser
this.reConfig({
url: url,
title: url,
oop: true
});
this.browserContainer.removeChild(this.browser.element);
this.browser = new BrowserFrame(this.browser_config);
this.browserContainer.appendChild(this.browser.element);
this.iframe = this.browser.element;
this.launchTime = Date.now();
this.appChrome && this.appChrome.reConfig();
}
this.browser.element.src = url;
};
/**
* The event is necessary for edge gesture swiper.
* It means the app window is swiped in.
*
* @access private
* @event AppWindow~_swipein
*/
/**
* The event is necessary for edge gesture swiper.
* It means the app window is swiped out.
*
* @access private
* @event AppWindow~_swipeout
*/
AppWindow.REGISTERED_EVENTS =
['mozbrowserclose', 'mozbrowsererror', 'mozbrowservisibilitychange',
'mozbrowserloadend', 'mozbrowseractivitydone', 'mozbrowserloadstart',
'mozbrowsertitlechange', 'mozbrowserlocationchange',
'mozbrowsermetachange', 'mozbrowsericonchange', 'mozbrowserasyncscroll',
'mozbrowsersecuritychange', 'mozbrowsermanifestchange',
'_localized', '_swipein', '_swipeout', '_kill_suspended',
'_orientationchange', '_focus', '_blur', '_hidewindow', '_sheetdisplayed',
'_sheetsgestureend', '_cardviewbeforeshow', '_cardviewclosed',
'_closed', '_shrinkingstart', '_shrinkingstop'];
AppWindow.SUB_COMPONENTS = {
'transitionController': window.AppTransitionController,
'modalDialog': window.AppModalDialog,
'valueSelector': window.ValueSelector,
'authDialog': window.AppAuthenticationDialog,
'contextmenu': window.BrowserContextMenu,
'childWindowFactory': window.ChildWindowFactory,
'statusbar': window.AppStatusbar
};
AppWindow.prototype.openAnimation = 'enlarge';
AppWindow.prototype.closeAnimation = 'reduce';
/**
* Install sub components belong to this window instance.
* The necessary components are based on AppWindow.SUB_COMPONENTS,
* now they are AppModalDialog/AppAuthenticationDialog.
*
* @example
* // Implement a new dialog
* var myDialog = function myDialog(app) {
* };
*
* var appWindow = new AppWindow();
* AppWindow.SUB_COMPONENTS.push(myDialog);
*
* app.installSubComponents();
*/
AppWindow.prototype.installSubComponents =
function aw_installSubComponents() {
this.debug('installing sub components...');
for (var componentName in this.constructor.SUB_COMPONENTS) {
if (this.constructor.SUB_COMPONENTS[componentName]) {
this[componentName] =
new this.constructor.SUB_COMPONENTS[componentName](this);
this[componentName].start && this[componentName].start();
}
}
if (this.isInputMethod) {
return;
}
if (this.manifest) {
var that = this;
that.element.addEventListener('_opened', function onOpened() {
that.element.removeEventListener('_opened', onOpened);
that.appChrome = new AppChrome(that);
// Some signals that chrome needs to respond to can occur before
// chrome has loaded - in those cases, manually call the handlers.
if (that.inError) {
that.appChrome.handleEvent({type: 'mozbrowsererror'});
}
if (that.loading) {
that.appChrome.handleEvent({type: 'mozbrowserloadstart'});
that.appChrome.handleEvent({type: '_loading'});
}
});
} else {
this.appChrome = new AppChrome(this);
}
};
AppWindow.prototype.uninstallSubComponents =
function aw_uninstallSubComponents() {
for (var componentName in this.constructor.SUB_COMPONENTS) {
if (this[componentName] && this[componentName].destroy) {
this[componentName].destroy();
}
this[componentName] = null;
}
if (this.appChrome) {
this.appChrome.destroy();
this.appChrome = null;
}
};
AppWindow.prototype._handle__localized = function aw__handle__localized() {
if (!this.manifest) {
return;
}
this.name = new ManifestHelper(this.manifest).name;
this.shortName = new ManifestHelper(this.manifest).short_name;
if (this.identificationTitle) {
this.identificationTitle.textContent = this.name;
}
// For uitest.
this.element.dataset.localizedName = this.name;
this.publish('namechanged');
};
AppWindow.prototype._handle__orientationchange = function(evt) {
if (this.isActive()) {
this.frontWindow && this.frontWindow.broadcast('orientationchange');
if (!this.isHomescreen) {
this._resize(evt.detail);
return;
// XXX: Preventing orientaiton of homescreen app is changed by background
// app. It's a workaround for bug 1089951.
// It should be remove once bug 1043102 is done.
} else if (Service.currentApp && Service.currentApp === this) {
this.lockOrientation();
}
}
var width = layoutManager.width;
var height = layoutManager.getHeightFor(this);
this.element.style.width = width + 'px';
this.element.style.height = height + 'px';
// The homescreen doesn't have an identification overlay
if (this.isHomescreen) {
return;
}
// If the screenshot doesn't match the new orientation hide it
if (this.width != width) {
this.screenshotOverlay.style.visibility = 'hidden';
} else {
this.screenshotOverlay.style.visibility = '';
}
};
AppWindow.prototype._handle_mozbrowservisibilitychange =
function aw__handle_mozbrowservisibilitychange(evt) {
var type = evt.detail.visible ? 'foreground' : 'background';
this.publish(type);
};
AppWindow.prototype._handle_mozbrowseractivitydone =
function aw__handle_mozbrowseractivitydone(evt) {
// In case we're not ActivityWindow but we're launched
// as window disposition activity.
if (this.isActive() && this.callerWindow) {
var caller = this.callerWindow;
var callerBottom = caller.getBottomMostWindow();
var calleeBottom = this.getBottomMostWindow();
caller.calleeWindow = null;
this.callerWindow = null;
// No transition when the callee is caller
if (callerBottom !== calleeBottom) {
callerBottom.open('in-from-left');
calleeBottom.close('out-to-right');
}
}
};
AppWindow.prototype._handle_mozbrowserclose =
function aw__handle_mozbrowserclose(evt) {
this.kill();
};
AppWindow.prototype._handle_mozbrowsererror =
function aw__handle_mozbrowsererror(evt) {
if (evt.detail.type !== 'fatal') {
this.inError = true;
return;
}
this.isCrashed = true;
// Send event instead of call crash reporter directly.
this.publish('crashed');
if (this.constructor.SUSPENDING_ENABLED && !this.isActive()) {
this.debug(' ..sleep! I will come back.');
this.destroyBrowser();
if (this.frontWindow) {
this.frontWindow.kill();
}
} else {
this.kill(evt);
}
};
AppWindow.prototype._handle_mozbrowserloadstart =
function aw__handle_mozbrowserloadstart(evt) {
this.loading = true;
this.inError = false;
this._changeState('loading', true);
this.publish('loading');
};
AppWindow.prototype._handle_mozbrowsertitlechange =
function aw__handle_handle_mozbrowsertitlechange(evt) {
this.title = evt.detail;
this.publish('titlechange');
if (this.identificationTitle && !this.manifest) {
this.identificationTitle.textContent = this.title;
}
};