This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
homescreen_window.js
226 lines (199 loc) · 6.6 KB
/
homescreen_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
/* global BrowserConfigHelper, AppWindow */
'use strict';
(function(exports) {
/**
* HomescreenWindow creates a instance of homescreen by give manifestURL.
*
* ##### Flow chart
* ![Boot to Homescreen flow chart](http://i.imgur.com/vLA8YEN.png)
*
* @class HomescreenWindow
* @param {String} manifestURL The manifestURL of the homescreen app.
*/
var HomescreenWindow = function HomescreenWindow(manifestURL) {
this.instanceID = 'homescreen';
this.setBrowserConfig(manifestURL);
this.render();
this.publish('created');
return this;
};
/**
* Fired when the homescreen window is created.
* @event HomescreenWindow#homescreencreated
*/
/**
* Fired when the homescreen window is removed.
* @event HomescreenWindow#homescreenterminated
*/
/**
* Fired when the homescreen window is opening.
* @event HomescreenWindow#homescreenopening
*/
/**
* Fired when the homescreen window is opened.
* @event HomescreenWindow#homescreenopen
*/
/**
* Fired when the homescreen window is closed.
* @event HomescreenWindow#homescreenclosed
*/
/**
* Fired when the homescreen window is closing.
* @event HomescreenWindow#homescreenclosing
*/
/**
* Fired when the homescreen window is closed.
* @event HomescreenWindow#homescreenclose
*/
/**
* Fired before the homescreen window is rendered.
* @event HomescreenWindow#homescreenwillrender
*/
/**
* Fired when the homescreen window is rendered to the DOM tree.
* @event HomescreenWindow#homescreenrendered
*/
/**
* Fired when the page visibility of the homescreen window is
* changed to foreground.
* @event HomescreenWindow#homescreenforeground
*/
/**
* Fired when the page visibility of the homescreen window is
* changed to background.
* @event HomescreenWindow#homescreenbackground
*/
HomescreenWindow.prototype.__proto__ = AppWindow.prototype;
HomescreenWindow.prototype._DEBUG = false;
HomescreenWindow.prototype.CLASS_NAME = 'HomescreenWindow';
/**
* Construct browser config object by manifestURL.
* @param {String} manifestURL The manifestURL of homescreen.
*/
HomescreenWindow.prototype.setBrowserConfig =
function hw_setBrowserConfig(manifestURL) {
var app = window.applications.getByManifestURL(manifestURL);
this.origin = app.origin;
this.manifestURL = app.manifestURL;
this.url = app.origin + '/index.html#root';
this.browser_config =
new BrowserConfigHelper(this.origin, this.manifestURL);
// Necessary for b2gperf now.
this.name = this.browser_config.name;
this.manifest = this.browser_config.manifest;
// XXX: Remove this hardcode
this.browser_config.url = this.url;
this.browser_config.isHomescreen = true;
this.config = this.browser_config;
this.isHomescreen = true;
};
HomescreenWindow.REGISTERED_EVENTS =
['_opening', '_localized', 'mozbrowserclose', 'mozbrowsererror',
'mozbrowservisibilitychange', 'mozbrowserloadend', '_orientationchange',
'_focus'];
HomescreenWindow.SUB_COMPONENTS = {
'transitionController': window.AppTransitionController,
'modalDialog': window.AppModalDialog,
'authDialog': window.AppAuthenticationDialog,
'childWindowFactory': window.ChildWindowFactory
};
HomescreenWindow.prototype.openAnimation = 'zoom-out';
HomescreenWindow.prototype.closeAnimation = 'zoom-in';
HomescreenWindow.prototype._handle__opening = function hw__handle__opening() {
this.ensure();
};
HomescreenWindow.prototype._handle_mozbrowserclose =
function hw__handle_mozbrowserclose(evt) {
this.restart();
};
HomescreenWindow.prototype._handle_mozbrowsererror =
function hw__handle_mozbrowsererror(evt) {
if (evt.detail.type == 'fatal') {
this.publish('crashed');
this.restart();
}
};
HomescreenWindow.prototype.restart = function hw_restart() {
// If the crashing app is the home screen app and it is the displaying app
// we will need to relaunch it right away.
// Alternatively, if home screen is not the displaying app,
// we will not relaunch it until the foreground app is closed.
// (to be dealt in setDisplayedApp(), not here)
// If we're displayed, restart immediately.
if (this.isActive()) {
this.kill();
// XXX workaround bug 810431.
// we need this here and not in other situations
// as it is expected that homescreen frame is available.
setTimeout(function() {
if (this.element) {
return;
}
this.render();
this.open();
}.bind(this));
} else {
// Otherwise wait until next opening request.
this.kill();
}
};
HomescreenWindow.prototype.view = function hw_view() {
return '<div class="appWindow homescreen" id="homescreen">' +
'<div class="fade-overlay"></div>' +
'</div>';
};
HomescreenWindow.prototype.eventPrefix = 'homescreen';
HomescreenWindow.prototype.toggle = function hw_toggle(visible) {
this.ensure();
if (this.browser.element) {
this.setVisible(visible);
}
};
// Ensure the homescreen is loaded and return its frame. Restarts
// the homescreen app if it was killed in the background.
HomescreenWindow.prototype.ensure = function hw_ensure(reset) {
this.debug('ensuring homescreen...', this.frontWindow);
if (!this.element) {
this.render();
} else if (reset) {
if (this.frontWindow) {
// Just kill front window but not switch to the first page.
this.frontWindow.kill();
} else {
this.browser.element.src = this.browser_config.url + Date.now();
}
}
return this.element;
};
/**
*
* The homescreen instance always resizes if it's needed.
* (ie. the current layout is different from the current window dimensions)
* This helps with the back-to-homescreen transition.
*
*/
HomescreenWindow.prototype.resize = function aw_resize() {
this.debug('request RESIZE...');
this.debug(' will resize... ');
this._resize();
};
/**
* Hide the overlay element of this window.
*
* this {HomescreenWindow}
* memberof HomescreenWindow
*/
HomescreenWindow.prototype.hideFadeOverlay = function hw_hideFadeOverlay() {
this.fadeOverlay.classList.add('hidden');
};
/**
* Show the overlay element of this window.
*
* this {HomescreenWindow}
* memberof HomescreenWindow
*/
HomescreenWindow.prototype.showFadeOverlay = function hw_showFadeOverlay() {
this.fadeOverlay.classList.remove('hidden');
};
exports.HomescreenWindow = HomescreenWindow;
}(window));