Firefox OS的system应用启动是通过加载一个内部资源页
chrome://b2g/content/shell.html- 1
来实现的,我们先看下这个文件的部分内容:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
id="shell"
windowtype="navigator:browser"
>
<head>
<link rel="stylesheet" href="shell.css" type="text/css">
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/settings.js"> </script>
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/shell.js"> </script>
<!-- this file is only loaded on Gonk to manage ADB state -->
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/devtools/adb.js"> </script>
<!-- manages DevTools server state -->
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/devtools/debugger.js"> </script>
</head>
<body id="container">
<!-- The html:iframe containing the UI is created here. -->
</body>
</html>- 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
该html加载时,主要加载以及运行两个js文件:
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/settings.js"> </script>
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/shell.js"> </script>- 1
- 2
- 3
- 4
shell.js中:
bootstrap: function() {
//...
this.start();
},
start: function shell_start() {
// ...
let homeURL = this.homeURL;
if (!homeURL) {
let msg = 'Fatal error during startup: No homescreen found: try setting B2G_HOMESCREEN';
alert(msg);
return;
}
let manifestURL = this.manifestURL;
// <html:iframe id="systemapp"
// mozbrowser="true" allowfullscreen="true"
// style="overflow: hidden; height: 100%; width: 100%; border: none;"
// src="data:text/html;charset=utf-8,%3C!DOCTYPE html>%3Cbody style='background:black;'>"/>
let systemAppFrame =
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:iframe');
systemAppFrame.setAttribute('id', 'systemapp');
systemAppFrame.setAttribute('mozbrowser', 'true');
systemAppFrame.setAttribute('mozapp', manifestURL);
systemAppFrame.setAttribute('allowfullscreen', 'true');
systemAppFrame.setAttribute('src', 'blank.html');
let container = document.getElementById('container');
#ifdef MOZ_WIDGET_COCOA
// See shell.html
let hotfix = document.getElementById('placeholder');
if (hotfix) {
container.removeChild(hotfix);
}
#endif
this.contentBrowser = container.appendChild(systemAppFrame);
systemAppFrame.contentWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.sessionHistory = Cc["@mozilla.org/browser/shistory;1"]
.createInstance(Ci.nsISHistory);
this.allowedAudioChannels = new Map();
let audioChannels = systemAppFrame.allowedAudioChannels;
audioChannels && audioChannels.forEach(function(audioChannel) {
this.allowedAudioChannels.set(audioChannel.name, audioChannel);
audioChannel.addEventListener('activestatechanged', this);
// Set all audio channels as unmuted by default
// because some audio in System app will be played
// before AudioChannelService[1] is Gaia is loaded.
// [1]: https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/audio_channel_service.js
audioChannel.setMuted(false);
}.bind(this));
// On firefox mulet, shell.html is loaded in a tab
// and we have to listen on the chrome event handler
// to catch key events
let chromeEventHandler = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler || window;
// Capture all key events so we can filter out hardware buttons
// And send them to Gaia via mozChromeEvents.
// Ideally, hardware buttons wouldn't generate key events at all, or
// if they did, they would use keycodes that conform to DOM 3 Events.
// See discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=762362
chromeEventHandler.addEventListener('keydown', this, true);
chromeEventHandler.addEventListener('keyup', this, true);
window.addEventListener('MozApplicationManifest', this);
window.addEventListener('MozAfterPaint', this);
window.addEventListener('sizemodechange', this);
window.addEventListener('unload', this);
this.contentBrowser.addEventListener('mozbrowserloadstart', this, true);
this.contentBrowser.addEventListener('mozbrowserselectionstatechanged', this, true);
this.contentBrowser.addEventListener('mozbrowserscrollviewchange', this, true);
this.contentBrowser.addEventListener('mozbrowsercaretstatechanged', this);
CustomEventManager.init();
WebappsHelper.init();
UserAgentOverrides.init();
CaptivePortalLoginHelper.init();
this.contentBrowser.src = homeURL;
},- 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
几个问题:
homeURL(b2g.system_startup_url):
app://system.gaiamobile.org/index.html "app:// for packaged app resources"- 1
- 2
- 3
manifestURL:
app://system.gaiamobile.org/manifest.webapp "app:// for packaged app resources"- 1
- 2
- 3
- system app实际上是一个iframe
let systemAppFrame =
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:iframe');- 1
- 2
该iframe是放在shell.html中id为”container”中:
let container = document.getElementById('container');
...
this.contentBrowser = container.appendChild(systemAppFrame);
...- 1
- 2
- 3
- 4
4.systemapp的iframe实际上有一系列属性:
systemAppFrame.setAttribute('id', 'systemapp');
systemAppFrame.setAttribute('mozbrowser', 'true');
systemAppFrame.setAttribute('mozapp', manifestURL);
systemAppFrame.setAttribute('allowfullscreen', 'true');
systemAppFrame.setAttribute('src', 'blank.html');- 1
- 2
- 3
- 4
- 5
system app的iframe里放的是 ‘blank.html’。其它属性:
mozbrowser:
An "iframe" is turned into a browser frame by setting the mozbrowser attribute
mozapp:
see [mozapp](https://wiki.mozilla.org/Security/Reviews/B2G/mozapp)- 1
- 2
- 3
- 4
- 5
system app刚开始加载的是
'blank.html',- 1
也就是没有界面的,之后开始加载
homeURL,即"app://system.gaiamobile.org/index.html"- 1
“system.gaiamobile.org”,实际上就是gaia里的system app。该app负责系统ui的显示以及home应用的加载等工作。
问题是:
b2g进程、system进程与Home进程的关系是什么样的? Home进程是如何创建出来的?- 1
我们下节再说。