diff options
Diffstat (limited to 'files/zh-cn/archive/b2g_os/platform')
17 files changed, 0 insertions, 3782 deletions
diff --git a/files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html b/files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html deleted file mode 100644 index 0960f1d970..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Firefox OS apps 架构 -slug: Archive/B2G_OS/Platform/Apps_architecture -translation_of: Archive/B2G_OS/Platform/Apps_architecture ---- -<div class="summary"> - <p>本文讲述了Firefox OS 应用启动和管理的内部原理。对 Firefox OS 平台开发者和将操作系统移植到硬件的团队是有用的。如果您仅仅是一个应用开发者,则不用了解这些细节,但又何妨一读,因为它是十分有趣的过程。</p> -</div> -<h2 id="app启动过程">app启动过程</h2> -<p>当用户选择他们想要启动或需要启动的应用时, home screen app会通过<a href="/zh-CN/docs/Web/API/App" title="此页面仍未被本地化, 期待您的翻译!"><code>App</code></a> API,获取到一个app的引用,之后会调用 <a href="/zh-CN/docs/Web/API/App/launch" title="此页面仍未被本地化, 期待您的翻译!"><code>App.launch()</code></a> 方法启动这个应用。 </p> -<p>Gecko 接收到请求后会向携带着 app 详情 向System app发送 <a href="/zh-CN/docs/Web/API/MozChromeEvent" title="此页面仍未被本地化, 期待您的翻译!"><code>mozChromeEvent</code></a> 事件。 System app 对事件进行处理:向 DOM tree中插入一个新的 <a href="/zh-CN/docs/Web/HTML/Element/iframe" title="HTML内联框架元素 <iframe> 表示嵌套的浏览上下文,有效地将另一个HTML页面嵌入到当前页面中。在HTML 4.01中,文档可能包含头部和正文,或头部和框架集,但不能包含正文和框架集。但是,<iframe>可以在正常的文档主体中使用。每个浏览上下文都有自己的会话历史记录和活动文档。包含嵌入内容的浏览上下文称为父浏览上下文。顶级浏览上下文(没有父级)通常是浏览器窗口。"><code><iframe></code></a> ,并且在这个新的 <a href="/zh-CN/docs/Web/HTML/Element/iframe" title="HTML内联框架元素 <iframe> 表示嵌套的浏览上下文,有效地将另一个HTML页面嵌入到当前页面中。在HTML 4.01中,文档可能包含头部和正文,或头部和框架集,但不能包含正文和框架集。但是,<iframe>可以在正常的文档主体中使用。每个浏览上下文都有自己的会话历史记录和活动文档。包含嵌入内容的浏览上下文称为父浏览上下文。顶级浏览上下文(没有父级)通常是浏览器窗口。"><code><iframe></code></a> 中装载 app。 此后 frame 就会是 app 的 home 了,直到 app终止。</p> -<p>每个 app都需要一个 manifest文件来对 app进行描述,并且在它的包中有一个特定的文件结构。要了解更多详情,请参阅文章 <a href="/en-US/docs/Web/Apps/App_Manifest">App manifest</a>。</p> -<h2 id="与_Gecko_通信">与 Gecko 通信</h2> -<p>Gecko 和 Gaia 系统应用之间的通信是通过 <a href="/zh-CN/docs/Web/API/MozChromeEvent" title="此页面仍未被本地化, 期待您的翻译!"><code>mozChromeEvent</code></a> 和<a href="/zh-CN/docs/Web/API/MozContentEvent" title="此页面仍未被本地化, 期待您的翻译!"><code>mozContentEvent</code></a> 完成的。<code>mozChromeEvent </code>是从 chrome 到 content 的广播;<code>而 </code> <code>mozContentEvent</code>s 是从 content 到 chrome 的广播。 这种通信过程用来控制可信任UI 的创建和关闭,以及为通知和其他工作注入需要的功能,如告诉System app 启动一个 app 。</p> -<div class="note"> - <p><strong>注意:</strong> 通过阅读 <a href="/en-US/Firefox_OS/Platform/Gaia/Gaia_apps/System">System app documentation</a> 您可以获取到关于这些事件工作的更多的内容。 通过阅读 <code><a href="https://dxr.mozilla.org/mozilla-central/source/b2g/chrome/content/shell.js" rel="custom">b2g/chrome/content/shell.js</a></code> 您也可已获取到更多使用的细节。 </p> -</div> -<h2 id="参见">参见</h2> -<ul> - <li><a href="/en-US/docs/Web/Apps">Apps</a></li> - <li><a href="/zh-CN/docs/Web/API/App" title="此页面仍未被本地化, 期待您的翻译!"><code>App</code></a></li> - <li><a href="/en-US/Firefox_OS/Platform/Gaia/Gaia_apps/System">System app</a></li> - <li><a href="/en-US/Firefox_OS/Platform/Architecture">Firefox OS architecture</a></li> -</ul> diff --git a/files/zh-cn/archive/b2g_os/platform/architecture/index.html b/files/zh-cn/archive/b2g_os/platform/architecture/index.html deleted file mode 100644 index 4b57f44ada..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/architecture/index.html +++ /dev/null @@ -1,1024 +0,0 @@ ---- -title: Firefox OS架构 -slug: Archive/B2G_OS/Platform/Architecture -tags: - - Architecture - - B2G - - Firefox OS - - Guide - - IPC - - IPDL -translation_of: Archive/B2G_OS/Architecture ---- -<p> </p> - -<div class="overheadIndicator draft"> -<p><strong>草案</strong><br> - 本页尚未完工.</p> -</div> - -<p> </p> - -<p>这篇文章是对Firefox OS平台的高度概览,介绍了一些关键的概念以及组件如何交互的过程。</p> - -<div class="note"> -<p><strong>Note:</strong> Firefox OS 仍然是未发布的产品,这里描述的架构并不是最终版本。</p> -</div> - -<h2 id="Firefox_OS_术语">Firefox OS 术语</h2> - -<p>在进一步学习 Firefox OS 文档前,请先了解下面的术语。</p> - -<h2 id="架构框图" style="margin-bottom: 20px; line-height: 30px;">架构框图</h2> - -<dl> - <dt>B2G</dt> - <dd>Boot to Gecko 的简称。</dd> - <dt>Boot to Gecko</dt> - <dd>Firefox OS 操作系统的工程代号。 因为在该项目拥有官方名称之前B2G已经使用了很久的原因,它经常用于指代 Firefox OS。</dd> - <dt>Firefox OS</dt> - <dd>FIrefox OS 基本上是指 Mozilla及合作伙伴应用在 B2G上的品牌和服务支持, 最终将创建一个发布的产品。</dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Gaia" title="/en-US/docs/Mozilla/Firefox_OS/Gaia">Gaia</a></dt> - <dd>Firefox OS 平台的用户接口层。屏幕启动时渲染到屏幕上的一切都是Gaia层的产物。Gaia 实现了 lock screen, home screen, 和所有你所期待在智能手机上看到的标准应用。Gaia 完全使用 HTML, CSS, 和 JavaScript实现。Web APIs 是Gaia层到底层系统的唯一入口,Web APIs 是由Gecko 层实现的。第三方应用可以安装在Gaia层。</dd> - <dt><a href="/en-US/docs/Gecko" title="/en-US/docs/Accessibility/AT-APIs/Gecko">Gecko</a></dt> - <dd>Firefox OS 应用的运行环境;该层提供了对: HTML, CSS, and JavaScript三个标准的支持,它能确保APIs能够在gecko支持的系统上良好工作。也就是说,它包括了网络栈,图形栈,布局引擎,js虚拟机和端口层。</dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Gonk" title="/en-US/docs/Mozilla/Firefox_OS/Gonk">Gonk</a></dt> - <dd>Gonk 是Firefox OS平台更低层的系统,包括了 Linux kernel (基于 AOSP)和用户空间硬件抽象层 (HAL)。内核和一些用户空间库都是公共的开源项目:linux, libusb, bluez等。其他的一些硬件抽象层部分是与android项目共享的:GPS, camera等。你可以认为 Gonk 是一个非常简单的 Linux 版本。Gonk 是 Gecko 层的端口目标;也就是说 Gecko 层有到 Gonk 的端口,就像Gecko 到 Mac OS X, Windows, 和 Android 一样。因为Firefox OS 对 Gonk 拥有完全的控制权,相比其他操作系统,我们可以释放更多的接口到 Gecko。例如,Gecko 拥有到 Gonk 电话栈和帧缓冲区的直接入口,但在其他操作系统却没有。</dd> - <dt>Jank</dt> - <dd>这个术语经常用在移动app空间的讨论中,主要是指在app中缓慢/低效的代码操作会导致 block UI的更新甚至出现无响应状态。我们的gaia工程师会不惜一切代价使用各种优化技术来避免这一问题。</dd> - <dt> </dt> - <dt> </dt> - <dt><img alt="Firefox OS Architecture" src="/files/4605/FirefoxOS.png" style="height: 915px; width: 754px;"></dt> -</dl> - -<p> </p> - -<h2 id="Firefox_OS_启动步骤" style="margin-bottom: 20px; line-height: 30px;">Firefox OS 启动步骤</h2> - -<p>本节主要描述了FIrefox OS 设备启动以及各模块交互的过程。简而言之,整个系统的启动流程是从内核空间的bootloaders开始,继而对native code初始化,到B2G至用户空间的Gecko,最后会到 Gaia 层 system app,window manager,homescreen app。而其他应用都是在它们上面执行的。</p> - -<p><img alt="Firefox os bootup " src="/files/7491/bootup.png"></p> - -<h2 id="自启动过程">自启动过程</h2> - -<p>当Firefox OS 设备启动时,执行过程从主要的引导装载程序(primary bootloader)开始。此时,会以常用的方式装载主操作系统。在这个链条中,一级级的装载会触发更高层次的迭代。这个过程最终是交由 Linux 内核处理。</p> - -<p>关于启动过程,这里有几点需要注意的地方:</p> - -<ul> - <li>在设备启动时,装载程序会显示第一个 splash 界面给用户。界面通常是一个厂商的logo。</li> - <li>装载程序会为设备实现一个图片的动画。不同的设备使用的协议是有差别的,绝大多数手机会使用 <a href="http://android-dls.com/wiki/index.php?title=Fastboot" title="http://android-dls.com/wiki/index.php?title=Fastboot">fastboot protocol</a>, 但是Samsung Galaxy S II 使用的是 odin 协议。</li> - <li>在启动过程结束时, modem image 通常会被装载并运行在 modem 处理器上。然而这些过程都是由设备不同而区分的,有的甚至是独有的。</li> -</ul> - -<h2 id="Linux_内核">Linux 内核</h2> - -<p>Gonk使用的 Linux内核与原生Linux派生出的AOSP是非常相似的。与AOSP (<a href="http://source.android.com/" style="text-decoration: underline;" title="http://source.android.com/">Android Open Source Project</a> )相比,它还有一些小的变化。另外,厂商还可能会对内核进行修改,并将这些变化按照自身的要求来设定。 一般而言, Linux内核是非常相近的。</p> - -<p>网络上对 <a href="http://en.wikipedia.org/wiki/Linux_startup_process" title="http://en.wikipedia.org/wiki/Linux_startup_process">startup process for Linux</a> 有许多详细的介绍,此处不会再赘述。</p> - -<p>Linux内核会带动设备的启动并且运行基本的过程。它会先执行 <code>init.rc </code> 中的步骤,继而运行 <code>init.b2g.rc</code> 来启动必须的步骤, 如包含的Gecko内的Firefox OS 基本过程以及 rild (电话相关由不同芯片组相关的进程)— 下面会有更详细的说明。 在过程结束时,正如绝大多数 UNIX-like 操作系统一样, 用户空间 <code style="font-style: normal;">init 进程会被启动。</code></p> - -<p>当 <code>init</code> 进程启动完成时,Linux内核会处理来自用户空间的系统请求,来自硬件的中断等。许多硬件特性会通过 <code><a href="http://en.wikipedia.org/wiki/Sysfs" title="http://en.wikipedia.org/wiki/Sysfs">sysfs</a> 暴露给用户空间</code>。例如这里的 <a href="https://github.com/cgjones/mozilla-central/blob/master/hal/gonk/GonkHal.cpp#L277">代码片段</a> 就在Gecko中读取电池的状态。</p> - -<pre class="brush:cpp;">FILE *capacityFile = fopen("/sys/class/power_supply/battery/capacity", "r"); -double capacity = dom::battery::kDefaultLevel * 100; -if (capacityFile) { - fscanf(capacityFile, "%lf", &capacity); - fclose(capacityFile); -}</pre> - -<h2 id="init_进程">init 进程</h2> - -<p>在Gonk中的 <code>init</code> 进程会处理文件系统的加载请求以及派生的系统服务。在此之后,它会作为进程的管理器而存在。这与其他的 UNIX-like操作系统是非常类似的。它会 将<span style="font-family: 'Courier New','Andale Mono',monospace;">init*.rc </span>脚本文件解释成包含启动各种服务的命令的集合。Firefox OS <code>init.b2g.rc</code> 其实就是在 Android <code>init.rc</code> 文件的基础上添加一些关于启动Firefox OS的命令的文件。</p> - -<p><code>init</code> 进程启动过程中一个关键任务就是启动 <code>b2g</code> 进程,它是 Firefox OS 操作系统的核心所在。</p> - -<p><code>init.b2g.rc</code> 文件中启动b2g进程的命令如下所示:</p> - -<pre>service b2g /system/bin/b2g.sh - class main - onrestart restart media</pre> - -<p>您也可以查看下 <code><a href="https://github.com/mozilla-b2g/gonk-misc/blob/master/init.b2g.rc" title="https://github.com/mozilla-b2g/gonk-misc/blob/master/init.b2g.rc">init.b2g.rc</a> </code>文件内容,它是添加在 Android init.rc 文件后用来启动b2g进程的。<font face="'Courier New', 'Andale Mono', monospace"> </font></p> - -<div class="note"> -<p><strong>注意: </strong>对\不同的设备而言<strong>,</strong><code>init.rc</code> 与 Android 的 对应文件间的差别也是不同的。,<code>init.b2g.rc</code> 只是简单的附加在文件后面的,有时候 patch 文件显得会更重要些。</p> -</div> - -<h2 id="userspace_进程架构">userspace 进程架构</h2> - -<p>现在如果概览一下Firefox OS的不同组件是如何组合在一起并与其他组件交互的过程是非常有用的。下图则包含了 Firefox OS 主要的 usersapce 进程。</p> - -<p><a href="/files/3849/B2G userspace architecture.svg"><img alt="Userspace diagram" src="/files/3849/B2G%20userspace%20architecture.svg" style="float: right; height: 491px; position: relative; width: 520px;"></a></p> - -<div class="note"> -<p><strong>注意: 我们应当知道,由于 FIrefox OS 正处在活跃开发阶段,这个框图可能会发生变化,不会那么准确。</strong></p> -</div> - -<p><code>b2g</code> 进程是主要的系统进程。它会以非常高的优先级运行,并且会访问绝大多数的硬件设备。<span style="font-family: 'Courier New','Andale Mono',monospace;">b2g</span> 会和 modem 进行通信, 会在 display framerbuffer上绘图, 与 GPS, Camera 以及其他硬件交互。 <code style="font-style: normal;">b2g </code>内部运行在Gecko层(由 <code style="font-style: normal;">libxul.so</code> 实现)。查看 <a href="#Gecko">Gecko</a> 可以获得 Gecko层如何工作, <code style="font-style: normal;">b2g</code> 与Gecko如何通信的细节。</p> - -<h3 id="b2g">b2g</h3> - -<p><code>b2g</code> 进程可能会反过来孵化一些低优先级的 <strong>content processes。 </strong>这些进程都是关于 web 应用或其他的 web 内容装载的过程。这些进程会和Gecko server主进程通过 <a href="/en-US/docs/IPDL" style="text-decoration: underline;" title="/en-US/docs/IPDL">IPDL</a> 消息传送系统进行通信。</p> - -<h3 id="rild">rild</h3> - -<p><code>rild</code> 进程是 modem 处理器的接口。 <code>rild</code> 是实现 <strong>Radio Interface Layer</strong> (RIL) 的守护进程。 它是一个专有的代码,由硬件供应商与自己的modem 硬件实现。<code>rild</code> 使客户端代码连接它所绑定的 UNIX域的 socket成为可能。它会由 <code>init</code> 脚本中的如下代码启动:</p> - -<pre>service ril-daemon /system/bin/rild - socket rild stream 660 root radio</pre> - -<h3 id="rilproxy">rilproxy</h3> - -<p>在Firefox OS 中, <code>rild</code> 客户端就是 <code>rilproxy</code> 进程。它在 <code style="font-style: normal;">rild</code> 和 <span style="font-family: 'Courier New','Andale Mono',monospace;">b2g </span>扮演着简单的转发代理服务器的角色。这个代理需要的是实现的细节,可以说,这确实是非常必要的。<a href="https://github.com/mozilla-b2g/rilproxy"><code>riproxy</code> 代码</a>可以在Github上找到。</p> - -<h3 id="mediaserver">mediaserver</h3> - -<p><a href="https://github.com/android/platform_frameworks_base/tree/ics-mr0-release/media/libmediaplayerservice"><code>mediaserver</code> 进程</a>控制着音频和视频的播放。Gecko会通过 Android远程过程调用机制(RPC)与 其通信。Gecko可以播放的多媒体(OGG Vorbis 音频, OGG Theora 视频,以及 <a href="http://www.webmproject.org/about/" title="http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CDUQFjAA&url=http%3A%2F%2Fwww.webmproject.org%2F&ei=8Q84UOnoMoHH6wHZ44DwBA&usg=AFQjCNHK9j6wyhUful5RmKCpU6b8GDfpYQ&sig2=tCl8VxL3mCvrH86EyOwO_A">WebM</a> 视频)都是由 Gecko解码并直接发送给 <code>mediaserver</code> 进程。其他的多媒体文件是由 <code>libstagefright 解码的,它能够访问专用编码器和硬件编码器。</code></p> - -<div class="note"> -<p><strong>注意:</strong> <code>mediaserver</code> 进程时一个临时的Firefox OS组件, 对我们初始的开发会有帮助,但最终会离开。然而在 Firefox OS 2.0 之前,可能不会发生。</p> -</div> - -<h3 id="netd">netd</h3> - -<p><code>netd</code> 进程用来对网络接口进行配置。</p> - -<h3 id="wpa_supplicant">wpa_supplicant</h3> - -<p><code>wpa_supplicant</code> 进程是标准的 UNIX样式的守护进程,会处理 WIFI 的连接。</p> - -<h3 id="dbus-daemon">dbus-daemon</h3> - -<p>dbus-daemon 实现了 <a href="http://www.freedesktop.org/wiki/Software/dbus" title="http://www.freedesktop.org/wiki/Software/dbus">D-Bus</a>( DBus 是指Firefox OS 用于蓝牙通信的一种消息总线系统)。</p> - -<p> </p> - -<h2 id="Gecko" style="margin-bottom: 20px; line-height: 30px;">Gecko</h2> - -<p><a href="https://developer.mozilla.org/en-US/docs/Gecko" title="/en-US/docs/Gecko">Gecko</a>,正如之前提到的,是对 web标准( <a href="https://developer.mozilla.org/en-US/docs/HTML" style="text-decoration: underline;" title="/en-US/docs/HTML">HTML</a>, <a href="https://developer.mozilla.org/en-US/docs/CSS" title="/en-US/docs/CSS">CSS</a>, and<a href="https://developer.mozilla.org/en-US/docs/JavaScript" title="/en-US/docs/JavaScript">JavaScript</a>)的实现,用于实现用户在Firefox OS 上看到的一切界面。</p> - -<div class="note"> -<p><strong>注意:</strong> 您可以使用 <a href="http://dxr.mozilla.org/" style="text-decoration: underline;">http://dxr.mozilla.org</a> 来查找Gecko代码库。这个网站非常有趣,并且提供了较好的参照特性,但是代码库的数量有限。或者您可以尝试下传统的 <a href="http://mxr.mozilla.org/">http://mxr.mozilla.org</a> ,其中会包括更多的Mozilla 项目。</p> -</div> - -<h3 id="与Firefox_OS_相关的_Gecko_文件" style="line-height: 24px; letter-spacing: normal;">与Firefox OS 相关的 Gecko 文件</h3> - -<h4 id="b2g_2" style="line-height: 18px; letter-spacing: normal;">b2g/</h4> - -<p>b2g 文件夹会包含了一些主要的Firefox OS 相关的功能。.</p> - -<h5 id="b2gchromecontent">b2g/chrome/content</h5> - -<p>包含了在system app 之上运行的 Javascript 文件。</p> - -<h5 id="b2gchromecontentshell.html">b2g/chrome/content/shell.html</h5> - -<p>Gaia的入口 — system app的html。 <code>shell.html</code> 会加载 <code>settings.js 和</code> <code>shell.js</code>:</p> - -<pre class="brush: html language-html" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="script token"><span class="tag token" style="color: #990055;"><span class="tag token"><span class="punctuation token" style="color: #999999;"><</span>script</span> <span class="attr-name token" style="color: #669900;">type</span><span class="attr-value token" style="color: #0077aa;"><span class="punctuation token" style="color: #999999;">=</span><span class="punctuation token" style="color: #999999;">"</span>application/javascript;version<span class="punctuation token" style="color: #999999;">=</span>1.8<span class="punctuation token" style="color: #999999;">"</span></span> <span class="attr-name token" style="color: #669900;">src</span><span class="attr-value token" style="color: #0077aa;"><span class="punctuation token" style="color: #999999;">=</span><span class="punctuation token" style="color: #999999;">"</span>chrome://browser/content/settings.js<span class="punctuation token" style="color: #999999;">"</span></span><span class="punctuation token" style="color: #999999;">></span></span> <span class="tag token" style="color: #990055;"><span class="tag token"><span class="punctuation token" style="color: #999999;"></</span>script</span><span class="punctuation token" style="color: #999999;">></span></span></span> -<span class="script token"><span class="tag token" style="color: #990055;"><span class="tag token"><span class="punctuation token" style="color: #999999;"><</span>script</span> <span class="attr-name token" style="color: #669900;">type</span><span class="attr-value token" style="color: #0077aa;"><span class="punctuation token" style="color: #999999;">=</span><span class="punctuation token" style="color: #999999;">"</span>application/javascript;version<span class="punctuation token" style="color: #999999;">=</span>1.8<span class="punctuation token" style="color: #999999;">"</span></span> <span class="attr-name token" style="color: #669900;">src</span><span class="attr-value token" style="color: #0077aa;"><span class="punctuation token" style="color: #999999;">=</span><span class="punctuation token" style="color: #999999;">"</span>chrome://browser/content/shell.js<span class="punctuation token" style="color: #999999;">"</span></span><span class="punctuation token" style="color: #999999;">></span></span> <span class="tag token" style="color: #990055;"><span class="tag token"><span class="punctuation token" style="color: #999999;"></</span>script</span><span class="punctuation token" style="color: #999999;">></span></span></span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<p><code>settings.js</code> 包含了系统设置的默认参数。</p> - -<h5 id="b2gchromecontentshell.js">b2g/chrome/content/shell.js</h5> - -<p><code>shell.js</code> 是在 Gaia <code>system</code> app中装载的第一个脚本文件。.</p> - -<p><code>shell.js</code> 导入了所有需要的模块,注册键值监听,定义了 <code style="font-style: normal;">sendCustomEvent </code>和<code style="font-style: normal;">sendChromeEvent</code> 与Gaia 通信,并且提供了 webapp 的安装助手: indexedDB quota, RemoteDebugger, keyboard helper, 和screenshot 工具。</p> - -<p>但是<code>shell.js</code> 最重要的功能就是启动了 Gaia <code>system</code> app, 之后又将整个系统相关的管理工作移交给了 Gaia <code>system</code> app。</p> - -<pre class="brush: js language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">let</span> systemAppFrame <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> - document<span class="punctuation token" style="color: #999999;">.</span><span class="function token">createElementNS<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">'http://www.w3.org/1999/xhtml'</span><span class="punctuation token" style="color: #999999;">,</span> <span class="string token" style="color: #669900;">'html:iframe'</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">.</span> - container<span class="punctuation token" style="color: #999999;">.</span><span class="function token">appendChild<span class="punctuation token" style="color: #999999;">(</span></span>systemAppFrame<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<h5 id="b2gappb2g.js">b2g/app/b2g.js</h5> - -<p>这个脚本中包含了预定义的配置信息,如浏览器中的 about:config, 文件与 Gaia 中的 pref.js 类似。这些配置可以在 Settings app中更改,可以使用Gaia 构建脚本文件 Gaia user.js文件覆写。</p> - -<h4 id="domAPI" style="line-height: 18px; letter-spacing: normal;">dom/{API}</h4> - -<p>新的 API 实现(post-b2g)放置在 <code>dom/ 文件夹中;而旧的API 的 dom/base 文件夹中,如 </code> <code>navigator.cpp。</code></p> - -<h5 id="domapps">dom/apps</h5> - -<p><code>.jsm</code> 文件会被加载,是对<code>.js</code> API 的实现,如 <code>webapp.js</code> <font face="'Courier New', 'Andale Mono', monospace">等。</font></p> - -<h5 id="domappssrc">dom/apps/src/</h5> - -<p>所有的权限信息都在 <a href="http://mxr.mozilla.org/mozilla-central/source/dom/apps/src/PermissionsTable.jsm">PermissionsTable.jsm</a> 文件中定义。</p> - -<h4 id="domwebidl" style="line-height: 18px; letter-spacing: normal;">dom/webidl</h4> - -<p>WebIDL 是一种用来定义 web APIs 的语言。可查看 <a href="https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings" style="text-decoration: underline;">WebIDL_bindings</a> 文件来获取它所支持的特性。</p> - -<h4 id="halgonk" style="line-height: 18px; letter-spacing: normal;">hal/gonk</h4> - -<p>这个文件夹包含了 gonk 接口层的相关文件。</p> - -<h4 id="Generated_files" style="line-height: 18px; letter-spacing: normal;">Generated files</h4> - -<h5 id="modulelibprefsrcinitall.js">module/libpref/src/init/all.js</h5> - -<p>包含所有的配置文件。</p> - -<h5 id="systemb2g_omni.ja_and_omni.js">/system/b2g/ omni.ja and omni.js</h5> - -<p>包含了设备中的资源样式包。</p> - -<h3 id="输入事件处理" style="line-height: 24px; letter-spacing: normal;">输入事件处理</h3> - -<p>在Gekco层绝大多数动作都是由用户行为触发的。这些动作是由输入事件所表示的(如按钮点击,触屏设备的触控,等等)。这些事件是通过 <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIAppShell" title="">nsIAppShell</a></code> 的 <a href="https://dxr.mozilla.org/mozilla-central/source/widget/gonk/nsAppShell.cpp" rel="custom">Gonk implementation</a> 传入的,这个接口用来表示Gecko 应用的最初入口点。也就是说, 输入设备会调用 nspAppShell对象的方法,来表示 Gecko子系统想要发送事件到用户界面。</p> - -<p>例如:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">void GeckoInputDispatcher<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">notifyKey<span class="punctuation token" style="color: #999999;">(</span></span>nsecs_t eventTime<span class="punctuation token" style="color: #999999;">,</span> - int32_t deviceId<span class="punctuation token" style="color: #999999;">,</span> - int32_t source<span class="punctuation token" style="color: #999999;">,</span> - uint32_t policyFlags<span class="punctuation token" style="color: #999999;">,</span> - int32_t action<span class="punctuation token" style="color: #999999;">,</span> - int32_t flags<span class="punctuation token" style="color: #999999;">,</span> - int32_t keyCode<span class="punctuation token" style="color: #999999;">,</span> - int32_t scanCode<span class="punctuation token" style="color: #999999;">,</span> - int32_t metaState<span class="punctuation token" style="color: #999999;">,</span> - nsecs_t downTime<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - UserInputData data<span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>timeMs <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> <span class="function token">nanosecsToMillisecs<span class="punctuation token" style="color: #999999;">(</span></span>eventTime<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>type <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> UserInputData<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span>KEY_DATA<span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>action <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> action<span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>flags <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> flags<span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>metaState <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> metaState<span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>key<span class="punctuation token" style="color: #999999;">.</span>keyCode <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> keyCode<span class="punctuation token" style="color: #999999;">;</span> - data<span class="punctuation token" style="color: #999999;">.</span>key<span class="punctuation token" style="color: #999999;">.</span>scanCode <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> scanCode<span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">{</span> - MutexAutoLock <span class="function token">lock<span class="punctuation token" style="color: #999999;">(</span></span>mQueueLock<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - mEventQueue<span class="punctuation token" style="color: #999999;">.</span><span class="function token">push<span class="punctuation token" style="color: #999999;">(</span></span>data<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> - gAppShell<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">NotifyNativeEvent<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 171px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 190px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 209px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 228px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 247px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 266px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 285px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 304px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 323px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 342px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 361px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 380px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 399px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 418px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 437px;"> </div> - -<p>这些事件都来自于标准的Linux <span style="font-family: 'Courier New','Andale Mono',monospace;">input_event </span>系统。Firefox OS 使用了 <a href="https://dxr.mozilla.org/mozilla-central/source/widget/gonk/libui/InputReader.cpp" rel="custom">light abstraction layer</a> 来覆写它;它也提供了较好的特性如事件过滤机制。 您可以在 <a href="https://dxr.mozilla.org/mozilla-central/source/widget/gonk/libui/EventHub.cpp" rel="custom">widget/gonk/libui/EventHub.cpp</a> 文件的 <code style="font-style: normal;">EventHub::getEvents()</code> 的方法中找到创建输入事件的代码。</p> - -<p>当Gecko层接收到事件时,就会通过<code style="font-style: normal;"><a href="https://dxr.mozilla.org/mozilla-central/source/widget/gonk/nsAppShell.cpp" rel="custom">nsAppShell</a> </code>分发到DOM中。</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">static nsEventStatus <span class="function token">sendKeyEventWithMsg<span class="punctuation token" style="color: #999999;">(</span></span>uint32_t keyCode<span class="punctuation token" style="color: #999999;">,</span> - uint32_t msg<span class="punctuation token" style="color: #999999;">,</span> - uint64_t timeMs<span class="punctuation token" style="color: #999999;">,</span> - uint32_t flags<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - nsKeyEvent <span class="function token">event<span class="punctuation token" style="color: #999999;">(</span></span><span class="boolean token" style="color: #990055;">true</span><span class="punctuation token" style="color: #999999;">,</span> msg<span class="punctuation token" style="color: #999999;">,</span> NULL<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - event<span class="punctuation token" style="color: #999999;">.</span>keyCode <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> keyCode<span class="punctuation token" style="color: #999999;">;</span> - event<span class="punctuation token" style="color: #999999;">.</span>location <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> nsIDOMKeyEvent<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span>DOM_KEY_LOCATION_MOBILE<span class="punctuation token" style="color: #999999;">;</span> - event<span class="punctuation token" style="color: #999999;">.</span>time <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> timeMs<span class="punctuation token" style="color: #999999;">;</span> - event<span class="punctuation token" style="color: #999999;">.</span>flags <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">|</span><span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> flags<span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">return</span> nsWindow<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">DispatchInputEvent<span class="punctuation token" style="color: #999999;">(</span></span>event<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 171px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 190px;"> </div> - -<p>此后,事件就会由Gecko本身处理或作为 <a href="https://developer.mozilla.org/en-US/docs/DOM_Client_Object_Cross-Reference/DOM_Events" style="text-decoration: underline;" title="/en-US/docs/DOM_Client_Object_Cross-Reference/DOM_Events">DOM events</a> 分发到web 应用中进一步处理</p> - -<h3 id="图像" style="line-height: 24px; letter-spacing: normal;">图像</h3> - -<p>在底层, Gecko 会使用 <a href="http://www.khronos.org/opengles/2_X/" title="http://www.khronos.org/opengles/2_X/">OpenGL ES 2.0</a> to draw to a GL context that wraps the hardware frame buffers. 这是由 Gonk 层<span style="font-family: 'Courier New','Andale Mono',monospace;"><a href="https://dxr.mozilla.org/mozilla-central/source/widget/gonk/nsWindow.cpp" rel="custom">nsWindow</a> 实现的,代码如下:</span></p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">gNativeWindow <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">android</span><span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">FramebufferNativeWindow<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -sGLContext <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> GLContextProvider<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">CreateForWindow<span class="punctuation token" style="color: #999999;">(</span></span>this<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<p><code>FramebufferNativeWindow</code> 类是直接 从Android拿过来的,可参考 <a href="https://github.com/android/platform_frameworks_base/blob/ics-mr1-release/libs/ui/FramebufferNativeWindow.cpp" title="https://github.com/android/platform_frameworks_base/blob/ics-mr1-release/libs/ui/FramebufferNativeWindow.cpp"><code>FramebufferNativeWindow.cpp</code></a>。为了能够将缓存从帧缓存设备映射到内存中,它使用了 <strong>gralloc</strong> API 来访问图像驱动。</p> - -<p>Gecko 使用了 <a href="https://developer.mozilla.org/en-US/docs/Gecko/Layers" title="/en-US/docs/Gecko/Layers">Layers</a> 系统来将复合后的内容画在屏幕上。总结一些,基本步骤是:</p> - -<ol> - <li>Gecko draws separate regions of pages into memory buffers. Sometimes these buffers are in system memory; other times, they're textures mapped into Gecko's address space, which means that Gecko is drawing directly into video memory. This is typically done in the method <a href="http://mxr.mozilla.org/mozilla-central/source/gfx/layers/basic/BasicThebesLayer.cpp#83" title="http://mxr.mozilla.org/mozilla-central/source/gfx/layers/basic/BasicThebesLayer.cpp#201"><code>BasicThebesLayer::PaintThebes()</code></a>.</li> - <li>Gecko then composites all of these textures to the screen using OpenGL commands. This composition occurs in <a href="http://mxr.mozilla.org/mozilla-central/source/gfx/layers/opengl/ThebesLayerOGL.cpp#124" title="http://mxr.mozilla.org/mozilla-central/source/gfx/layers/basic/BasicThebesLayer.cpp#201"><code>ThebesLayerOGL::RenderTo()</code></a>.</li> -</ol> - -<p>The details of how Gecko handles the rendering of web content is outside the scope of this document.</p> - -<h3 id="硬件抽象层_(HAL)" style="line-height: 24px; letter-spacing: normal;">硬件抽象层 (HAL)</h3> - -<p>The Gecko hardware abstraction layer is one of the porting layers of Gecko. It handles low-level access to system interfaces across multiple platforms using a C++ API that's accessible to the higher levels of Gecko. These APIs are implemented on a per-platform basis inside the Gecko HAL itself. This hardware abstraction layer is not exposed directly to JavaScript code in Gecko.</p> - -<h4 id="How_the_HAL_works" style="line-height: 18px; letter-spacing: normal;">How the HAL works</h4> - -<p>Let's consider the <a href="/zh-CN/docs/Web/API/Window/navigator/vibrate" title="此页面仍未被本地化, 期待您的翻译!"><code>Vibration</code></a> API as an example. The Gecko HAL for this API is defined in <a href="https://dxr.mozilla.org/mozilla-central/source/hal/Hal.h" rel="custom">hal/Hal.h</a>. In essence (simplifying the method signature for clarity's sake), you have this function:</p> - -<pre class="language-html" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;">void Vibrate(const nsTArray<uint32> &pattern);</pre> - -<p>This is the function called by Gecko code to turn on vibration of the device according to the specified pattern; a corresponding function exists to cancel any ongoing vibration. The Gonk implementation of this method is in <a href="https://dxr.mozilla.org/mozilla-central/source/hal/gonk/GonkHal.cpp" rel="custom">hal/gonk/GonkHal.cpp</a>:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">void <span class="function token">Vibrate<span class="punctuation token" style="color: #999999;">(</span></span>const nsTArray<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>uint32_t> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span>pattern<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="function token">EnsureVibratorThreadInitialized<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - sVibratorRunnable<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">Vibrate<span class="punctuation token" style="color: #999999;">(</span></span>pattern<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<p>This code sends the request to start vibrating the device to another thread, which is implemented in <code>VibratorRunnable::Run()</code>. This thread's main loop looks like this:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">while</span> <span class="punctuation token" style="color: #999999;">(</span><span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">!</span>mShuttingDown<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">if</span> <span class="punctuation token" style="color: #999999;">(</span>mIndex <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span> mPattern<span class="punctuation token" style="color: #999999;">.</span><span class="function token">Length<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - uint32_t duration <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> mPattern<span class="punctuation token" style="color: #999999;">[</span>mIndex<span class="punctuation token" style="color: #999999;">]</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">if</span> <span class="punctuation token" style="color: #999999;">(</span>mIndex <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">%</span> <span class="number token" style="color: #990055;">2</span> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">==</span> <span class="number token" style="color: #990055;">0</span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="function token">vibrator_on<span class="punctuation token" style="color: #999999;">(</span></span>duration<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> - mIndex<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">++</span><span class="punctuation token" style="color: #999999;">;</span> - mMonitor<span class="punctuation token" style="color: #999999;">.</span><span class="function token">Wait<span class="punctuation token" style="color: #999999;">(</span></span><span class="function token">PR_MillisecondsToInterval<span class="punctuation token" style="color: #999999;">(</span></span>duration<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> - <span class="keyword token" style="color: #0077aa;">else</span> <span class="punctuation token" style="color: #999999;">{</span> - mMonitor<span class="punctuation token" style="color: #999999;">.</span><span class="function token">Wait<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 171px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 190px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 209px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 228px;"> </div> - -<p><code>vibrator_on()</code> is the Gonk HAL API that turns on the vibrator motor. Internally, this method sends a message to the kernel driver by writing a value to a kernel object using<code>sysfs</code>.</p> - -<h4 id="Fallback_HAL_API_implementations" style="line-height: 18px; letter-spacing: normal;">Fallback HAL API implementations</h4> - -<p>The Gecko HAL APIs are supported across all platforms. When Gecko is built for a platform that doesn't expose an interface to vibration motors (such as a desktop computer), then a fallback implementation of the HAL API is used. For vibration, this is implemented in <a href="https://dxr.mozilla.org/mozilla-central/source/hal/fallback/FallbackVibration.cpp" rel="custom">hal/fallback/FallbackVibration.cpp</a>.</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">void <span class="function token">Vibrate<span class="punctuation token" style="color: #999999;">(</span></span>const nsTArray<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>uint32_t> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span>pattern<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<h4 id="Sandbox_implementations" style="line-height: 18px; letter-spacing: normal;">Sandbox implementations</h4> - -<p>Because most web content runs in content processes with low privileges, we can't assume those processes have the privileges needed to be able to (for example), turn on and off the vibration motor. In addition, we want to have a central location for handling potential race conditions. In the Gecko HAL, this is done through a "sandbox" implementation of the HAL. This sandbox implementation simply proxies requests made by content processes and forwards them to the "Gecko server" process. The proxy requests are sent using IPDL.</p> - -<p>For vibration, this is handled by the <code>Vibrate()</code> function implemented in <a href="https://dxr.mozilla.org/mozilla-central/source/hal/sandbox/SandboxHal.cpp" rel="custom">hal/sandbox/SandboxHal.cpp</a>:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">void <span class="function token">Vibrate<span class="punctuation token" style="color: #999999;">(</span></span>const nsTArray<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>uint32_t><span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span> pattern<span class="punctuation token" style="color: #999999;">,</span> const WindowIdentifier <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span>id<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - AutoInfallibleTArray<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>uint32_t<span class="punctuation token" style="color: #999999;">,</span> <span class="number token" style="color: #990055;">8</span>> <span class="function token">p<span class="punctuation token" style="color: #999999;">(</span></span>pattern<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - - WindowIdentifier <span class="function token">newID<span class="punctuation token" style="color: #999999;">(</span></span>id<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - newID<span class="punctuation token" style="color: #999999;">.</span><span class="function token">AppendProcessID<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="function token">Hal<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">SendVibrate<span class="punctuation token" style="color: #999999;">(</span></span>p<span class="punctuation token" style="color: #999999;">,</span> newID<span class="punctuation token" style="color: #999999;">.</span><span class="function token">AsArray<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">,</span> <span class="function token">GetTabChildFrom<span class="punctuation token" style="color: #999999;">(</span></span>newID<span class="punctuation token" style="color: #999999;">.</span><span class="function token">GetWindow<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<p>This sends a message defined by the <code>PHal</code> interface, described by IPDL in <a href="https://dxr.mozilla.org/mozilla-central/source/hal/sandbox/PHal.ipdl" rel="custom">hal/sandbox/PHal.ipdl</a>. This method is described more or less as follows:</p> - -<pre class="language-html" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;">Vibrate(uint32_t[] pattern);</pre> - -<p>The receiver of this message is the <code>HalParent::RecvVibrate()</code> method in <a href="https://dxr.mozilla.org/mozilla-central/source/hal/sandbox/SandboxHal.cpp" rel="custom">hal/sandbox/SandboxHal.cpp</a>, which looks like this:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">virtual bool <span class="function token">RecvVibrate<span class="punctuation token" style="color: #999999;">(</span></span>const InfallibleTArray<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>unsigned int><span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span> pattern<span class="punctuation token" style="color: #999999;">,</span> - const InfallibleTArray<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>uint64_t> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span>id<span class="punctuation token" style="color: #999999;">,</span> - PBrowserParent <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">*</span>browserParent<span class="punctuation token" style="color: #999999;">)</span> MOZ_OVERRIDE <span class="punctuation token" style="color: #999999;">{</span> - - hal<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">Vibrate<span class="punctuation token" style="color: #999999;">(</span></span>pattern<span class="punctuation token" style="color: #999999;">,</span> newID<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">return</span> <span class="boolean token" style="color: #990055;">true</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<p>This omits some details that aren't relevant to this discussion; however, it shows how the message progresses from a content process through Gecko to Gonk, then to the Gonk HAL implementation of <code>Vibrate()</code>, and eventually to the Vibration driver.</p> - -<h3 id="DOM_APIs" style="line-height: 24px; letter-spacing: normal;">DOM APIs</h3> - -<p><strong>DOM interfaces</strong> 从本质上说,是指web内容与Gecko的如何通信的。当然此处会涉及到更多的内容,如果您对更多的细节感兴趣,可以参考 <a href="https://developer.mozilla.org/en-US/docs/DOM/About_the_Document_Object_Model" title="/en-US/docs/DOM/About_the_Document_Object_Model">about the DOM</a> 。. DOM 接口是使用 <a href="https://developer.mozilla.org/en-US/docs/XPIDL" style="text-decoration: underline;" title="/en-US/docs/XPIDL">IDL</a> 定义的,包括外部功能接口(FFI) 和使用JavaScript 和 C++ 的对象模型(OM)。</p> - -<p>震动API是通过IDL接口暴露给web内容的,IDL接口定义在<code><a href="https://dxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMNavigator.idl" rel="custom">nsIDOMNavigator.idl</a>:</code></p> - -<pre class="language-html" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;">[implicit_jscontext] void mozVibrate(in jsval aPattern);</pre> - -<p><a href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/Jsval" title="/en-US/docs/SpiderMonkey/JSAPI_Reference/JSVAL_IS_OBJECT"><code>jsval</code></a> 参数表示 <code>mozVibrate()</code> (这个未定版的震动规范是以我们的厂商作为前缀实现的)会接受任何输入的JavaScript值。 IDL编译器 <code><a href="https://developer.mozilla.org/en-US/docs/XPIDL/xpidl" title="/en-US/docs/XPIDL/xpidl">xpidl</a> </code>会产生一个C++接口,这个接口由 定义在 <span style="font-family: 'Courier New','Andale Mono',monospace;"><a href="https://dxr.mozilla.org/mozilla-central/source/dom/base/Navigator.cpp" rel="custom">Navigator.cpp</a> 文件中的</span> <code>Navigator</code> 类 <code>实现。</code></p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">NS_IMETHODIMP Navigator<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">MozVibrate<span class="punctuation token" style="color: #999999;">(</span></span>const jsval<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span> aPattern<span class="punctuation token" style="color: #999999;">,</span> JSContext<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">*</span> cx<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="comment token" style="color: #708090; display: inherit;"> // ... -</span> hal<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">Vibrate<span class="punctuation token" style="color: #999999;">(</span></span>pattern<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">return</span> NS_OK<span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<p>您在这个方法中看到的源码要比这里要多,但这并非我们此次讨论的目的。关键点在于此处会调用 <code>hal::Vibrate()</code> 将控制行为从DOM层传送到GECKO HAL层。 在那里,我们会进入 在之前一节HAL 实现的讨论,并会一直走到图形驱动层。最重要的是,DOM的实现并不会关心它运行在那个平台 (Gonk, Windows, Mac OS X, 或者其他)。、它也不会关心这些代码时运行在 content 进程或者是 Gecko 服务器进程。这些细节都会由系统底层处理。</p> - -<p>震动 API 非常简单, 可以作为一个好的例子来讲解。 <a href="https://developer.mozilla.org/en-US/docs/API/WebSMS" title="/en-US/docs/API/WebSMS">SMS API</a> 则比较复杂会使用到自身的“远程”层级连接content 进程到服务器。</p> - -<h2 id="Radio_Interface_Layer_(RIL)" style="margin-bottom: 20px; line-height: 30px;">Radio Interface Layer (RIL)</h2> - -<p>The RIL was mentioned in the section <a href="#The_userspace_process_architecture">The userspace process architecture</a>. This section will examine how the various pieces of this layer interact in a bit more detail.</p> - -<p>The main components involved in the RIL are:</p> - -<dl> - <dt><code>rild</code></dt> - <dd>The daemon that talks to the proprietary modem firmware.</dd> - <dt><code>rilproxy</code></dt> - <dd>The daemon that proxies messages between <code>rild</code> and Gecko (which is implemented in the <code>b2g</code> process). This overcomes the permission problem that arises when trying to talk to <code>rild</code> directly, since <code>rild</code> can only be communicated with from within the <code>radio</code>group.</dd> - <dt><code>b2g</code></dt> - <dd>This process, also known as the <strong>chrome process</strong>, implements Gecko. The portions of it that relate to the Radio Interface Layer are <a href="https://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js" rel="custom">dom/system/gonk/ril_worker.js</a> (which implements a worker thread that talks to <code>rild</code> through <code>rilproxy</code> and implements the radio state machine; and the <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIRadioInterfaceLayer" title="">nsIRadioInterfaceLayer</a></code> interface, which is the main thread's <a href="https://developer.mozilla.org/en-US/docs/XPCOM" title="/en-US/docs/XPCOM">XPCOM</a>service that acts primarily as a message exchange between the <code>ril_worker.js</code> thread and various other Gecko components, including the Gecko content process.</dd> - <dt>Gecko's content process</dt> - <dd>Within Gecko's content process, the <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIRILContentHelper" title="">nsIRILContentHelper</a></code> interface provides an XPCOM service that lets code implementing parts of the DOM, such as the<a href="https://developer.mozilla.org/en-US/docs/API/WebTelephony" title="/en-US/docs/API/WebTelephony">Telephony</a> and <a href="https://developer.mozilla.org/en-US/docs/API/WebSMS" title="/en-US/docs/API/WebSMS">SMS</a> APIs talk to the radio interface, which is in the chrome process.</dd> -</dl> - -<h3 id="Example_Communicating_from_rild_to_the_DOM" style="line-height: 24px; letter-spacing: normal;">Example: Communicating from rild to the DOM</h3> - -<p>Let's take a look at an example of how the lower level parts of the system communicate with DOM code. When the modem receives an incoming call, it notifies <code>rild</code> using a proprietary mechanism. <code>rild</code> then prepares a message for its client according to the "open" protocol, which is described in <a href="https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h" title="https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h"><code>ril.h</code></a>. In the case of an incoming call, a<code>RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED</code> message is generated and sent by <code>rild</code> to<code>rilproxy</code>.</p> - -<p><code>rilproxy</code>, implemented in <a href="https://github.com/mozilla-b2g/rilproxy/blob/master/src/rilproxy.c" title="https://github.com/mozilla-b2g/rilproxy/blob/master/src/rilproxy.c"><code>rilproxy.c</code></a>, receives this message in its main loop, which polls its connection to <code>rild</code> using code like this:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">ret <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> <span class="function token">read<span class="punctuation token" style="color: #999999;">(</span></span>rilproxy_rw<span class="punctuation token" style="color: #999999;">,</span> data<span class="punctuation token" style="color: #999999;">,</span> <span class="number token" style="color: #990055;">1024</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - -<span class="keyword token" style="color: #0077aa;">if</span><span class="punctuation token" style="color: #999999;">(</span>ret > <span class="number token" style="color: #990055;">0</span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="function token">writeToSocket<span class="punctuation token" style="color: #999999;">(</span></span>rild_rw<span class="punctuation token" style="color: #999999;">,</span> data<span class="punctuation token" style="color: #999999;">,</span> ret<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<p>Once the message is received from <code>rild</code>, it's then forwarded along to Gecko on the socket that connects <code>rilproxy</code> to Gecko. Gecko receives the forwarded message on its <a href="https://dxr.mozilla.org/mozilla-central/source/ipc/ril/Ril.cpp" rel="custom">IPC thread</a>:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">int ret <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> <span class="function token">read<span class="punctuation token" style="color: #999999;">(</span></span>fd<span class="punctuation token" style="color: #999999;">,</span> mIncoming<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>>Data<span class="punctuation token" style="color: #999999;">,</span> <span class="number token" style="color: #990055;">1024</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span><span class="comment token" style="color: #708090; display: inherit;"> -// ... handle errors ... -</span>mIncoming<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>>mSize <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> ret<span class="punctuation token" style="color: #999999;">;</span> -sConsumer<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">MessageReceived<span class="punctuation token" style="color: #999999;">(</span></span>mIncoming<span class="punctuation token" style="color: #999999;">.</span><span class="function token">forget<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<p>The consumer of these messages is <a href="https://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/SystemWorkerManager.cpp" rel="custom">SystemWorkerManager</a>, which repackages the messages and dispatches them to the<code><a href="https://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js" rel="custom">ril_worker.js</a></code> thread that implements the RIL state machine; this is done in the<code>RILReceiver::MessageReceived()</code> method:</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">virtual void <span class="function token">MessageReceived<span class="punctuation token" style="color: #999999;">(</span></span>RilRawData <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">*</span>aMessage<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - nsRefPtr<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>DispatchRILEvent> <span class="function token">dre<span class="punctuation token" style="color: #999999;">(</span></span><span class="keyword token" style="color: #0077aa;">new</span> <span class="class-name token">DispatchRILEvent</span><span class="punctuation token" style="color: #999999;">(</span>aMessage<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - mDispatcher<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">PostTask<span class="punctuation token" style="color: #999999;">(</span></span>dre<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<p>The task posted to that thread in turn calls the <code>onRILMessage()</code> function, which is implemented in JavaScript. This is done using the JavaScript API function<code><a href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_CallFunctionName" title="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_CallFunctionName">JS_CallFunctionName</a>()</code>:</p> - -<pre class="language-html" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;">return JS_CallFunctionName(aCx, obj, "onRILMessage", NS_ARRAY_LENGTH(argv), argv, argv);</pre> - -<p><code>onRILMessage()</code> is implemented in <a href="https://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js" rel="custom">dom/system/gonk/ril_worker.js</a>, which processes the message bytes and chops them into parcels. Each complete parcel is then dispatched to individual handler methods as appropriate:</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">handleParcel<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">handleParcel<span class="punctuation token" style="color: #999999;">(</span></span>request_type<span class="punctuation token" style="color: #999999;">,</span> length<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">let</span> method <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> this<span class="punctuation token" style="color: #999999;">[</span>request_type<span class="punctuation token" style="color: #999999;">]</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">if</span> <span class="punctuation token" style="color: #999999;">(</span><span class="keyword token" style="color: #0077aa;">typeof</span> method <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">==</span> <span class="string token" style="color: #669900;">"function"</span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">if</span> <span class="punctuation token" style="color: #999999;">(</span>DEBUG<span class="punctuation token" style="color: #999999;">)</span> <span class="function token">debug<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"Handling parcel as "</span> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">+</span> method<span class="punctuation token" style="color: #999999;">.</span>name<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - method<span class="punctuation token" style="color: #999999;">.</span><span class="function token">call<span class="punctuation token" style="color: #999999;">(</span></span>this<span class="punctuation token" style="color: #999999;">,</span> length<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<p>This code works by getting the request type from the object, making sure it's defined as a function in the JavaScript code, then calling the method. Since ril_worker.js implements each request type in a method given the same name as the request type, this is very simple.</p> - -<p>In our example, <code>RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED</code>, the following handler is called:</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">RIL<span class="punctuation token" style="color: #999999;">[</span>UNSOLICITED_RESPONSE_CALL_STATE_CHANGED<span class="punctuation token" style="color: #999999;">]</span> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">UNSOLICITED_RESPONSE_CALL_STATE_CHANGED<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - this<span class="punctuation token" style="color: #999999;">.</span><span class="function token">getCurrentCalls<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<p>As you see in the code above, when notification is received that the call state has changed, the state machine simply fetches the current call state by calling the<code>getCurrentCall()</code> method:</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">getCurrentCalls<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">getCurrentCalls<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - Buf<span class="punctuation token" style="color: #999999;">.</span><span class="function token">simpleRequest<span class="punctuation token" style="color: #999999;">(</span></span>REQUEST_GET_CURRENT_CALLS<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<p>This sends a request back to <code>rild</code> to request the state of all currently active calls. The request flows back along a similar path the <code>RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED</code>message followed, but in the opposite direction (that is, from <code>ril_worker.js</code> to<code>SystemWorkerManager</code> to <code>Ril.cpp</code>, then <code>rilproxy</code> and finally to the <code>rild</code> socket). <code>rild</code>then responds in kind, back along the same path, eventually arriving in <code>ril_worker.js</code>'s handler for the <code>REQUEST_GET_CURRENT_CALLS</code> message. And thus bidirectional communication occurs.</p> - -<p>The call state is then processed and compared to the previous state; if there's a change of state, ril_worker.js notifies the <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIRadioInterfaceLayer" title="">nsIRadioInterfaceLayer</a></code> service on the main thread:</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">_handleChangedCallState<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">_handleChangedCallState<span class="punctuation token" style="color: #999999;">(</span></span>changedCall<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">let</span> message <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> <span class="punctuation token" style="color: #999999;">{</span>type<span class="punctuation token" style="color: #999999;">:</span> <span class="string token" style="color: #669900;">"callStateChange"</span><span class="punctuation token" style="color: #999999;">,</span> - call<span class="punctuation token" style="color: #999999;">:</span> changedCall<span class="punctuation token" style="color: #999999;">}</span><span class="punctuation token" style="color: #999999;">;</span> - this<span class="punctuation token" style="color: #999999;">.</span><span class="function token">sendDOMMessage<span class="punctuation token" style="color: #999999;">(</span></span>message<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<p><code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIRadioInterfaceLayer" title="">nsIRadioInterfaceLayer</a></code> is implemented in <a href="https://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/RadioInterfaceLayer.js" rel="custom">dom/system/gonk/RadioInterfaceLayer.js</a>; the message is received by its<code>onmessage()</code> method:</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;"> onmessage<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">onmessage<span class="punctuation token" style="color: #999999;">(</span></span>event<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">let</span> message <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> event<span class="punctuation token" style="color: #999999;">.</span>data<span class="punctuation token" style="color: #999999;">;</span> - <span class="function token">debug<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"Received message from worker: "</span> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">+</span> JSON<span class="punctuation token" style="color: #999999;">.</span><span class="function token">stringify<span class="punctuation token" style="color: #999999;">(</span></span>message<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - switch <span class="punctuation token" style="color: #999999;">(</span>message<span class="punctuation token" style="color: #999999;">.</span>type<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - case <span class="string token" style="color: #669900;">"callStateChange"</span><span class="punctuation token" style="color: #999999;">:</span> - <span class="comment token" style="color: #708090; display: inherit;"> // This one will handle its own notifications. -</span> this<span class="punctuation token" style="color: #999999;">.</span><span class="function token">handleCallStateChange<span class="punctuation token" style="color: #999999;">(</span></span>message<span class="punctuation token" style="color: #999999;">.</span>call<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">break</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">.</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<p>All this really does is dispatch the message to the content process using the Parent Process Message Manager (PPMM):</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">handleCallStateChange<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">handleCallStateChange<span class="punctuation token" style="color: #999999;">(</span></span>call<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="punctuation token" style="color: #999999;">[</span>some internal state updating<span class="punctuation token" style="color: #999999;">]</span> - ppmm<span class="punctuation token" style="color: #999999;">.</span><span class="function token">sendAsyncMessage<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"RIL:CallStateChanged"</span><span class="punctuation token" style="color: #999999;">,</span> call<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<p>In the content process, the message is received by <code>receiveMessage()</code> method in the <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIRILContentHelper" title="">nsIRILContentHelper</a></code> service, from the Child Process Message Manager (CPMM):</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">receiveMessage<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">receiveMessage<span class="punctuation token" style="color: #999999;">(</span></span>msg<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">let</span> request<span class="punctuation token" style="color: #999999;">;</span> - <span class="function token">debug<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"Received message '"</span> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">+</span> msg<span class="punctuation token" style="color: #999999;">.</span>name <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">+</span> <span class="string token" style="color: #669900;">"': "</span> <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">+</span> JSON<span class="punctuation token" style="color: #999999;">.</span><span class="function token">stringify<span class="punctuation token" style="color: #999999;">(</span></span>msg<span class="punctuation token" style="color: #999999;">.</span>json<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - switch <span class="punctuation token" style="color: #999999;">(</span>msg<span class="punctuation token" style="color: #999999;">.</span>name<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - case <span class="string token" style="color: #669900;">"RIL:CallStateChanged"</span><span class="punctuation token" style="color: #999999;">:</span> - this<span class="punctuation token" style="color: #999999;">.</span><span class="function token">_deliverTelephonyCallback<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"callStateChanged"</span><span class="punctuation token" style="color: #999999;">,</span> - <span class="punctuation token" style="color: #999999;">[</span>msg<span class="punctuation token" style="color: #999999;">.</span>json<span class="punctuation token" style="color: #999999;">.</span>callIndex<span class="punctuation token" style="color: #999999;">,</span> msg<span class="punctuation token" style="color: #999999;">.</span>json<span class="punctuation token" style="color: #999999;">.</span>state<span class="punctuation token" style="color: #999999;">,</span> - msg<span class="punctuation token" style="color: #999999;">.</span>json<span class="punctuation token" style="color: #999999;">.</span>number<span class="punctuation token" style="color: #999999;">,</span> msg<span class="punctuation token" style="color: #999999;">.</span>json<span class="punctuation token" style="color: #999999;">.</span>isActive<span class="punctuation token" style="color: #999999;">]</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">break</span><span class="punctuation token" style="color: #999999;">;</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<p>This, in turn, calls the <code><a href="https://developer.mozilla.org/zh-CN/docs/XPCOM_Interface_Reference/nsIRILTelephonyCallback#callStateChanged()">nsIRILTelephonyCallback.callStateChanged()</a></code> methods on every registered telephony callback object. Every web application that accesses the <a href="/zh-CN/docs/Web/API/Window/navigator/mozTelephony" title="此页面仍未被本地化, 期待您的翻译!"><code>window.navigator.mozTelephony</code></a> API has registered one such callback object that dispatches events to the JavaScript code in the web application, either as a state change of an existing call object or a new <code>incoming</code> call event.</p> - -<pre class="brush:cpp; language-cpp" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-cpp" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">NS_IMETHODIMP Telephony<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">CallStateChanged<span class="punctuation token" style="color: #999999;">(</span></span>PRUint32 aCallIndex<span class="punctuation token" style="color: #999999;">,</span> PRUint16 aCallState<span class="punctuation token" style="color: #999999;">,</span> - const nsAString<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">&</span> aNumber<span class="punctuation token" style="color: #999999;">,</span> bool aIsActive<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="punctuation token" style="color: #999999;">[</span><span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">.</span><span class="punctuation token" style="color: #999999;">]</span> - - <span class="keyword token" style="color: #0077aa;">if</span> <span class="punctuation token" style="color: #999999;">(</span>modifiedCall<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="comment token" style="color: #708090; display: inherit;"> // Change state. -</span> modifiedCall<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">ChangeState<span class="punctuation token" style="color: #999999;">(</span></span>aCallState<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - - <span class="comment token" style="color: #708090; display: inherit;"> // See if this should replace our current active call. -</span> <span class="keyword token" style="color: #0077aa;">if</span> <span class="punctuation token" style="color: #999999;">(</span>aIsActive<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - mActiveCall <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> modifiedCall<span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> - - <span class="keyword token" style="color: #0077aa;">return</span> NS_OK<span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> - - nsRefPtr<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>TelephonyCall> call <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> - TelephonyCall<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">Create<span class="punctuation token" style="color: #999999;">(</span></span>this<span class="punctuation token" style="color: #999999;">,</span> aNumber<span class="punctuation token" style="color: #999999;">,</span> aCallState<span class="punctuation token" style="color: #999999;">,</span> aCallIndex<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - nsRefPtr<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;"><</span>CallEvent> event <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> CallEvent<span class="punctuation token" style="color: #999999;">:</span><span class="punctuation token" style="color: #999999;">:</span><span class="function token">Create<span class="punctuation token" style="color: #999999;">(</span></span>call<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - nsresult rv <span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">=</span> event<span class="operator token" style="background-clip: initial; background-color: rgba(255, 255, 255, 0.496094); color: #a67f59;">-</span>><span class="function token">Dispatch<span class="punctuation token" style="color: #999999;">(</span></span><span class="function token">ToIDOMEventTarget<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">,</span> <span class="function token">NS_LITERAL_STRING<span class="punctuation token" style="color: #999999;">(</span></span><span class="string token" style="color: #669900;">"incoming"</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="function token">NS_ENSURE_SUCCESS<span class="punctuation token" style="color: #999999;">(</span></span>rv<span class="punctuation token" style="color: #999999;">,</span> rv<span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">return</span> NS_OK<span class="punctuation token" style="color: #999999;">;</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 171px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 190px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 209px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 228px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 247px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 266px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 285px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 304px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 323px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 342px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 361px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 380px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 399px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 418px;"> </div> - -<p>Applications can receive these events and update their user interface and so forth:</p> - -<pre class="brush:js; language-js" style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;"><code class="language-js" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;">handleEvent<span class="punctuation token" style="color: #999999;">:</span> <span class="keyword token" style="color: #0077aa;">function</span> <span class="function token">fm_handleEvent<span class="punctuation token" style="color: #999999;">(</span></span>evt<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - switch <span class="punctuation token" style="color: #999999;">(</span>evt<span class="punctuation token" style="color: #999999;">.</span>call<span class="punctuation token" style="color: #999999;">.</span>state<span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - case <span class="string token" style="color: #669900;">'connected'</span><span class="punctuation token" style="color: #999999;">:</span> - this<span class="punctuation token" style="color: #999999;">.</span><span class="function token">connected<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">break</span><span class="punctuation token" style="color: #999999;">;</span> - case <span class="string token" style="color: #669900;">'disconnected'</span><span class="punctuation token" style="color: #999999;">:</span> - this<span class="punctuation token" style="color: #999999;">.</span><span class="function token">disconnected<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="keyword token" style="color: #0077aa;">break</span><span class="punctuation token" style="color: #999999;">;</span> - default<span class="punctuation token" style="color: #999999;">:</span> - <span class="keyword token" style="color: #0077aa;">break</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="punctuation token" style="color: #999999;">}</span> -<span class="punctuation token" style="color: #999999;">}</span></code></pre> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 38px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 57px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 76px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 95px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 114px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 133px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 152px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 171px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 190px;"> </div> - -<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 209px;"> </div> - -<p>Take a look at the implementation of <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/dialer/js/dialer.js" title="https://github.com/mozilla-b2g/gaia/blob/master/apps/communications/dialer/js/dialer.js"><code>handleEvent()</code> in the Dialer application</a> as an extended example.</p> - -<h3 id="3G_data" style="line-height: 24px; letter-spacing: normal;">3G data</h3> - -<p>There is a RIL message that initiates a "data call" to the cellular service; this enables data transfer mode in the modem. This data call ends up creating and activating a <a href="https://zh.wikipedia.org/wiki/Point-to-Point Protocol" title="Point-to-Point Protocol">Point-to-Point Protocol</a> (PPP) interface device in the Linux kernel that can be configured using the usual interfaces.</p> - -<div class="note"> -<p><strong>Note:</strong> This section needs to be written.</p> -</div> - -<h3 id="Related_DOM_APIs" style="line-height: 24px; letter-spacing: normal;">Related DOM APIs</h3> - -<p>This section lists DOM APIs that are related to RIL communications:</p> - -<ul> - <li><a href="https://developer.mozilla.org/en-US/docs/API/WebTelephony/Introduction_to_WebTelephony" title="/en-US/docs/API/WebTelephony/Introduction_to_WebTelephony">Telephony API</a></li> - <li><a href="https://developer.mozilla.org/en-US/docs/API/WebSMS/Introduction_to_WebSMS" title="/en-US/docs/API/WebSMS/Introduction_to_WebSMS">SMS API</a></li> - <li>Mobile Connection API</li> -</ul> - -<h2 id="WiFi" style="margin-bottom: 20px; line-height: 30px;">WiFi</h2> - -<p>Firefox OS 的WIFI后台只是简单的借助 <code>wpa_supplicant</code> 来完成绝大部分工作。也就是说,后台的主要工作就是对 supplicant 的简单管理以及一些初始化的工作,如装载WiFi 驱动和使能或禁止网络接口。后台本质上只是一个跟随supplicant 状态而变化的状态机。</p> - -<div class="note"> -<p><strong>注意:</strong> 在WIFI中发生的绝大部分事情会取决于 <code>wpa_supplicant</code> 进程状态的变化。</p> -</div> - -<p>WIFI组件的实现可以分成两个文件:</p> - -<dl> - <dt><a href="https://dxr.mozilla.org/mozilla-central/source/dom/wifi/DOMWifiManager.js" rel="custom">dom/wifi/DOMWifiManager.js</a></dt> - <dd>实现了暴露给web 内容的API,这些API是定义在 <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWifi.idl" title="">nsIWifi.idl</a></code>中的。</dd> - <dt><a href="https://dxr.mozilla.org/mozilla-central/source/dom/wifi/WifiWorker.js" rel="custom">dom/wifi/WifiWorker.js</a></dt> - <dd>实现了关于 supplicant 的状态机和驱动代码。</dd> -</dl> - -<p>这两个文件之间使用 <a href="https://developer.mozilla.org/en-US/docs/The_message_manager" title="/en-US/docs/The_message_manager">message manager</a> 通信。消息的后台监听需要特定的动作触发,如 "associate", 当动作执行完成时也会返回一个消息。</p> - -<p>对响应方法的DOM侧监听与一些事件消息一样,都表示状态的变化和信息的更新。</p> - -<div class="note"> -<p><strong>Note:</strong> 任何同步的 DOM APIs 都是通过管道一侧的缓存数据实现的。如果可能的话,要尽量避免使用同步消息。</p> -</div> - -<h3 id="WifiWorker.js" style="line-height: 24px; letter-spacing: normal;">WifiWorker.js</h3> - -<p>This file implements the main logic behind the WiFi interface. It runs in the chrome process (in multi-process builds) and is instantiated by the SystemWorkerManager. The file is generally broken into two sections: a giant anonymous function and <code>WifiWorker</code>(and its prototype). The anonymous function ends up being the <code>WifiManager</code> by providing a local API, including notifications for events such as connection to the supplicant and scan results being available. In general, it contains little logic and lets its sole consumer control its actions while it simply responds with the requested information and controls the details of the connection with the supplicant.</p> - -<p>The <code>WifiWorker</code> object sits between the <code>WifiManager</code> and the DOM. It reacts to events and forwards them to the DOM; in turn, it receives requests from the DOM and performs the appropriate actions on the supplicant. It also maintains state information about the supplicant and what it needs to do next.</p> - -<h3 id="DOMWifiManager.js" style="line-height: 24px; letter-spacing: normal;">DOMWifiManager.js</h3> - -<p>This implements the DOM API, transmitting messages back and forth between callers and the actual WiFi worker. There's very little logic involved.</p> - -<div class="note"> -<p><strong>Note:</strong> In order to avoid synchronous messages to the chrome process, the WiFi Manager does need to cache the state based on the received event.</p> -</div> - -<p>There's a single synchronous message, which is sent at the time the DOM API is instantiated, in order to get the current state of the supplicant.</p> - -<h3 id="DHCP" style="line-height: 24px; letter-spacing: normal;">DHCP</h3> - -<p>DHCP and DNS are handled by <code>dhcpcd</code>, the standard Linux DHCP client. However, it's not able to react when the network connection is lost. Because of this, Firefox OS kills and restarts <code>dhcpcd</code> each time it connects to a given wireless network.</p> - -<p><code>dhcpcd</code> is also responsible for setting the default route; we call into the network manager to tell the kernel about DNS servers.</p> - -<h2 id="网络管理器" style="margin-bottom: 20px; line-height: 30px;">网络管理器</h2> - -<p>网络管理器会对由3G数据和WIFI组件打开的网络接口进行配置。</p> - -<div class="note"> -<p><strong>注意:</strong> 这部分内容需要完善。</p> -</div> - -<h2 id="进程和线程" style="margin-bottom: 20px; line-height: 30px;">进程和线程</h2> - -<p>Firefox OS 操作系统使用 POSIX 线程机制实现所有的应用线程,包括每个应用的主线程,Web workers和辅助线程。优先值是由标准的Linux内核调度程序决定用来表示进程和线程执行时的优先级。根据进程的状态不同,我们设定了不同的优先值。当前共有7个等级:</p> - -<p>进程优先级等级</p> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Priority</th> - <th scope="col">Nice</th> - <th scope="col">Used for</th> - </tr> - </thead> - <tbody> - <tr> - <td><code>MASTER</code></td> - <td>0</td> - <td>b2g 主进程</td> - </tr> - <tr> - <td><code>FOREGROUND_HIGH</code></td> - <td>0</td> - <td>持有 CPU wakelock 的应用</td> - </tr> - <tr> - </tr> - <tr> - <td><code>FOREGROUND</code></td> - <td>1</td> - <td>前台应用</td> - </tr> - <tr> - <td><code>FOREGROUND_KEYBOARD</code></td> - <td>1</td> - <td>键盘应用</td> - </tr> - <tr> - <td><code>BACKGROUND_PERCEIVABLE</code></td> - <td>7</td> - <td>播放音乐的后台应用</td> - </tr> - <tr> - <td><code>BACKGROUND_HOMESCREEN</code></td> - <td>18</td> - <td>homescreen 应用</td> - </tr> - <tr> - <td><code>BACKGROUND</code></td> - <td>18</td> - <td>运行在后台的所有其他应用</td> - </tr> - </tbody> -</table> - -<p>有些等级优先值是相同的,这是因为这些等级是低内存查杀机制处理的方式是不同的。所有的优先级都可以在构建时通过参数配置进行调整。您可以在 <code><a href="http://hg.mozilla.org/mozilla-central/file/54e8c6492dc4/b2g/app/b2g.js#l610">b2g/app/b2g.js</a>文件中找到相关实体。</code></p> - -<div class="note"> -<p><strong>注意</strong>: 要获取更多关于内存溢出(out-of-memory killer)以及 Firefoex OS 是如何管理低内存状态的内容,可以参阅 <a href="https://developer.mozilla.org/en-US/Firefox_OS/Platform/Out_of_memory_management_on_Firefox_OS">Out of memory management on Firefox OS</a>.</p> -</div> - -<p>在一个进程内部,主线程继承了进程的优先值,同时则给定了web worker线程比主线程高一个值的优先值。因此web worker 线程优先级与主线程相比要低一些。之所以这么做是为了避免 CPU密集性的工作降低主线程的处理速度。当比较重要的事件(如一个应用转到前台或后台,启动一个新的应用或一个已存在的应用获得 CPU wakelock)发生时,进程优先级就会发生变化。当一个进程优先级发生变化时,其中所有的线程优先级就会对应的作出调整。</p> - -<div class="note"> -<p><strong>注意:</strong> cgroups 当前并没有用于资源的管理,它们在特定的设备及内核中显得并不可靠。</p> -</div> - -<p> </p> diff --git a/files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html b/files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html deleted file mode 100644 index 591d5e7bb6..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html +++ /dev/null @@ -1,158 +0,0 @@ ---- -title: 功能支持图表 -slug: Archive/B2G_OS/Platform/Feature_support_chart -tags: - - B2G - - QA - - Testing -translation_of: Archive/B2G_OS/Platform/Feature_support_chart ---- -<p></p> -<div class="summary"> - <p><span class="seoSummary">这里有许多不同的 Firefox OS 编译版本,您可以选择下载或者由自己编译,在每个设备上所支持的功能都会有所区别。下面的图表则可以帮助我们理解在不同设备上所支持或不支持的功能。</span></p> -</div> -<table class="standard-table"> - <thead> - <tr> - <th scope="row">功能</th> - <th scope="col">设备</th> - <th scope="col">模拟器</th> - <th scope="col">桌面版本</th> - </tr> - </thead> - <tbody> - <tr> - <th scope="row">Dialer</th> - <td>All</td> - <td>UI only, no network</td> - <td>UI only, no network</td> - </tr> - <tr> - <th scope="row">Contacts</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">SMS</th> - <td>All</td> - <td>UI only, no network</td> - <td>UI only, no network</td> - </tr> - <tr> - <th scope="row">Camera</th> - <td>All</td> - <td>UI only, no camera support</td> - <td>UI only, unsure about desktop camera support at this time</td> - </tr> - <tr> - <th scope="row">Gallery</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Video</th> - <td>All</td> - <td>UI only</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Music</th> - <td>All</td> - <td> </td> - <td>All</td> - </tr> - <tr> - <th scope="row">FM Radio</th> - <td>All</td> - <td>All</td> - <td>UI only</td> - </tr> - <tr> - <th scope="row">Email</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Calculator</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Browser</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Marketplace</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Clock</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Calendar</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Home Screen</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Lock Screen</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Keyboard</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Task Manager</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">First-Run</th> - <td>All</td> - <td>?</td> - <td>?</td> - </tr> - <tr> - <th scope="row">Notification</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - <tr> - <th scope="row">Status Bar</th> - <td>All</td> - <td>一些网络状态不能被测试</td> - <td>一些网络状态不能被测试</td> - </tr> - <tr> - <th scope="row">Settings</th> - <td>All</td> - <td>All</td> - <td>All</td> - </tr> - </tbody> -</table> -<p> </p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html deleted file mode 100644 index 85d101cf3a..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: 构建系统入门 -slug: Archive/B2G_OS/Platform/Gaia/Build_System_Primer -translation_of: Archive/B2G_OS/Developing_Gaia/Build_System_Primer ---- -<p><span style="font-weight: bold; background-color: rgb(244, 247, 248);">本文介绍了Gaia构建系统是如何工作的,包括</span><span style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; font-weight: bold; background-color: rgb(244, 247, 248);" class="seoSummary"> makefile, 构建过程,环境变量及潜在定制。 </span></p> -<p>在构建步骤中绝大多数有意义的工作都是由存放在Gaia子文件夹 <code>build/</code> 下的脚本执行的,它们主要是使用make, node.js , <a href="https://developer.mozilla.org/en-US/docs/XPConnect/xpcshell" title="https://developer.mozilla.org/en-US/docs/XPConnect/xpcshell">XPCShell</a> (也称作JS Shell)以及 <a href="/zh-CN/docs/XULRunner">XULRunner [zh-CN]</a>执行的。Gaia构建系统中包含许多帮助工具,可以将webapp安装,测试,定位和打包到实际设备上。它同样允许开发者通过诸如更改默认壁纸,铃声,应用和设置的方式来对Gaia自定义。</p> -<h2 id="Makefile文件">Makefile文件</h2> -<p> Makefile文件中包含许多有用的命令,本节会对最有用的一些命令进行解释: </p> -<h4 id="install-gaia">install-gaia</h4> -<p>该命令会将Gaia层所有的应用推送到设备端。如果想要推送特定的应用,可以使用APP 标志位:</p> -<pre class="brush: bash">APP=calendar make install-gaia</pre> -<p>运行上面命令时所在的位置必须是Gaia apps 下的文件夹(例如 <code>apps</code>).</p> -<h4 id="reset-gaia">reset-gaia</h4> -<p>该命令会对设备中的应用进行清理并且在安装完成应用后会设置权限的默认值,除此之外与 <code>install-gaia 命令作用是相同的</code>. 在构建工程时,应用会存放在 <code>/data/local类似的目录</code>. 它同样也会将测试和调试的应用推送到手机中。</p> -<div class="warning"> - <p>注意: 如果在使用 <code>reset-gaia</code> 时加入 <code>APP</code> 环境变量,会使您的手机不可用(此时可以通过再次执行不带 <code>APP</code> 变量的命令恢复). 因此请不要这样做.</p> -</div> -<h4 id="production">production</h4> -<p>该命令会将web应用安装在<span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;">/system/b2g 下,而不是</span><span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;">/data/local,除此之外与</span> <code>reset-gaia </code>作用是相同的。这个命令能够使您对user版本进行仿真,这个命令同样会将一系列的应用安装在user版本上<code>。</code></p> -<h4 id="sect1"> </h4> -<h3 style="line-height: 24px; letter-spacing: normal;" id="参考工作负载">参考工作负载</h3> -<p>These goals push variously sized workloads to the device, helping us with debugging and fixing the performance and scalability issues we might have. These goals accept the APP environment variable, or an APPS environment variable that should contain the app names separated by a space, e.g.,</p> -<pre style="padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 30px; border-left-width: 6px; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; background-color: rgba(234, 239, 242, 0.246094); text-shadow: none; direction: ltr; text-align: left; white-space: normal;" class="brush: bash language-html"><code style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr; white-space: pre;" class="language-html">APP=sms make reference-workload-light -APPS="sms communications/contacts" make reference-workload-heavy</code></pre> -<div style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 0px;" class="line-number"> - </div> -<div style="margin-top: 1em; position: absolute; left: 0px; right: 0px; background-clip: initial; background-color: transparent; line-height: inherit; top: 19px;" class="line-number"> - </div> -<div class="note"> - <p><strong>注意:</strong> For more information, read <a href="https://developer.mozilla.org/en-US/Firefox_OS/Platform/Gaia/Hacking#Reference_Workloads">Hacking Gaia: Reference workloads</a>.</p> -</div> -<h3 id="环境变量">环境变量</h3> -<p>一些环境变量能够让你控制在设备上的构建与安装的一些方面:</p> -<h4 id="B2G_SYSTEM_APPS1">B2G_SYSTEM_APPS=1</h4> -<p>这个环境变量能够让你把应用推送到 <code>/system/b2g 而不是 /data/local</code>。 You should use that when you work with a user build. This variable is automatically set when running <code>make production</code>. This can be used for <code>install-gaia</code> or <code>reset-gaia</code> too.</p> -<h4 id="GAIA_OPTIMIZE1">GAIA_OPTIMIZE=1</h4> -<p>This triggers an optimization pass on the JavaScript files. This is automatically set when running <code>make production</code>. This can be used for <code>install-gaia</code> or <code>reset-gaia</code> too.</p> -<h4 id="PRODUCTION1">PRODUCTION=1</h4> -<p>This is basically an alias for <code>make production</code> (or is it the other way around ?).</p> -<h4 id="DEBUG1">DEBUG=1</h4> -<p>This lets you generate a debug profile to use with the <a href="/en-US/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_unit_tests" title="/en-US/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_unit_tests">unit tests</a> or to develop your Firefox OS app in Firefox. You must delete the existing profile directory before trying to generate a new one.</p> -<h4 id="GAIA_DEV_PIXELS_PER_PX1.5">GAIA_DEV_PIXELS_PER_PX=1.5</h4> -<p>This generates a profile suitable for running on WVGA devices.</p> -<h2 id="Customizing_the_preferences">Customizing the preferences</h2> -<p>If you find that you have a set of custom preferences you need to set each time you flash your device, create a file called <code>custom-prefs.js</code> inside the <code>build</code> directory and store them in there. This keeps them from being overwritten and out of source control.</p> -<p>Here are some useful preferences:</p> -<pre class="brush: js">// this enables marionette which lets you run performance tests -// see https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_performance_tests -user_pref("marionette.defaultPrefs.enabled", true); - -// this sets the port for remote debugging your application on the device -user_pref("devtools.debugger.remote-port", 60000); - -// this enables the remote debugger -user_pref("devtools.debugger.remote-enabled", true); - -// this outputs debug information about the Radio Interface Layer in logcat -user_pref("ril.debugging.enabled", true); -</pre> -<p>This file is read each time you generate a profile. The safest way to be sure that everything is generated is to delete your profile first:</p> -<pre class="brush: bash">rm -rf profile && make profile</pre> -<p>Then you can safely use the <code>install-gaia</code> goal.</p> -<h2 id="FAQ">FAQ</h2> -<h3 id="1)_The_device_remains_black_after_a_flash">1) The device remains black after a flash</h3> -<p>This can sometimes happen if you flash the device while it is idle. To remedy this just restart B2G by issuing the following command from the command line:</p> -<p>adb shell stop b2g && adb shell start b2g</p> -<p> </p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html deleted file mode 100644 index 856090aaca..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html +++ /dev/null @@ -1,107 +0,0 @@ ---- -title: Browser -slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Browser -tags: - - Apps - - B2G - - Firefox OS - - Gaia - - 指南 - - 浏览器 -translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Browser ---- -<div class="summary"> - <p><span class="seoSummary"><a href="https://github.com/mozilla-b2g/gaia/tree/master/apps/browser">Browser app</a> (当前是 System 的一部分) 提供了浏览器相关的功能 — 包括页面导航,搜索和书签。本文介绍了 Browser app 的基本工作以及它是如何融合进更大的 System中的。</span></p> -</div> -<p>由于 Gaia 运行 Gecko 的上层, 在基于 Gekco 实例之上,启动一个 Browser app/ System 浏览器进行常规的页面是非常容易做到的。它是由 <a href="https://developer.mozilla.org/en-US/docs/DOM/Using_the_Browser_API">mozBrowser API</a> 实现的。</p> -<div class="note"> - <p><b>注意</b>: Firefox OS 2.1 之后, Browser app 就是 System app 的一部分了。这意味着可以同时通过点击浏览器图标启动 Browser app 或通过全局搜索以及导航的能力来进行 web 浏览。 app 和 浏览器 tab 页此后会有共同的公共体验, 它们会作为 <a href="https://wiki.mozilla.org/FirefoxOS/Haida" style="text-decoration: underline;">Haida 用户体验</a> 的一部分,存在于任务管理器和表视图中(用于边缘手势)。</p> -</div> -<h2 id="System_浏览器_(浏览器框架)">System 浏览器 (浏览器框架)</h2> -<p>当 Firefox OS 用户将一个 web 页面添加为标签时, 它就会显示在 homescreen 上, 这个 web 页面后续就会打开 System 浏览器而不是 Browser app。在页面底部会有一个工具栏, 包括 向前/向后/刷新的功能。在 Gaia 中,它被称之为浏览器框架或包装器( wrapper)。您可以在下面图片的右手侧看到。</p> -<p><img alt="A diagram showing that when a web page is opened in the system browser, it is given a toolbar." src="https://mdn.mozillademos.org/files/7869/browser-app.png" style="width: 738px; height: 500px; display: block; margin: 0px auto;"></p> -<p>如果想要使您的 web 页面仍具有 后退/前进/刷新 的功能, 您可以在 app 表单文件中包含下面声明来使能浏览器框架。</p> -<pre class="brush: json">declare { chrome: { navigation: true } }</pre> -<div class="note"> - <p><b>注意</b>: 浏览器框架工具栏会影响到内容的高度,因此当在设计 web 页面布局时将其考虑进去。</p> -</div> -<h3 id="代码流程">代码流程</h3> -<p>当在 Firefox OS 中打开一个新的 web 页面时,调用流程如下</p> -<pre>Gecko > WrapperFactory > Window Manager > AppWindow > BrowserFrame</pre> -<p>Wrappers inheriting from <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/wrapper_factory.js">system/js/wrapper_factory</a> will receive the <code>mozbrowseropenwindow</code> event for a bookmarked web page.</p> -<p>In the <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/wrapper_factory.js#L15">handleEvent</a> section, the handler will check the event to decide whether the web page should be opened as an app or in browser chrome.</p> -<p>Finally, <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/wrapper_factory.js#L115">launchWrapper</a> is called to launch the corresponding window.</p> -<h2 id="全局搜索_导航">全局搜索 & 导航</h2> -<p>With the new search and navigation bar, users can get to their favorites, type in a URL, or discover a new app, from anywhere in Firefox OS. The search bar lives at the top of the screen, and users can just tap or swipe to open it.</p> -<p>Think of it as a combination of the <a href="https://support.mozilla.org/en-US/kb/awesome-bar-find-your-bookmarks-history-and-tabs">Awesome Bar</a> from the browser and the <a href="https://support.mozilla.org/en-US/kb/use-adaptive-search-discover-personalized-apps">adaptive app search</a> from the homescreen. Because Firefox OS uses web apps, when you find what you want, even if it’s a new app, it opens right away. You don’t need to install anything, because everything is instant and web—like.</p> -<h2 id="Browser_App">Browser App</h2> -<p>The Browser app is a certified webapp that provides a general web browser experience. The main function is located in <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/browser/js/browser.js">apps/browser/js/browser.js</a>:</p> -<pre class="brush: js">var Browser = { - init: function browser_init() { - this.getAllElements(); - ... - BrowserDB.init((function() { - ... - } - } -}; - -window.addEventListener('load', function browserOnLoad(evt) { - window.removeEventListener('load', browserOnLoad); - Browser.init(); -});</pre> -<p>The Browser will call its <code>init()</code> function while the DOM is loaded.</p> -<pre class="brush: js">getAllElements: function browser_getAllElements() { - var elementIDs = [ - 'toolbar—start', ... 'danger—dialog']; - - // Loop and add element with camel style name to Modal Dialog attribute. - elementIDs.forEach(function createElementRef(name) { - this[this.toCamelCase(name)] = document.getElementById(name); - }, this); -},</pre> -<p>The <code>getAllElements</code> function is used to get all camelCase element handlers, after which the <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/browser/js/browser_db.js">apps/browser/js/browser_db.js</a> is called, to prepare for adding the default search engine and bookmarks.</p> -<h2 id="书签">书签</h2> -<p>From Firefox OS 2.0 <a href="https://github.com/mozilla-b2g/gaia/tree/master/apps/bookmark">apps/bookmark</a> is used to handle bookmark save/remove activities.</p> -<p>The most interesting parts <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/bookmark/manifest.webapp">apps/bookmark/webapp.manifest</a> looks like so:</p> -<pre class="brush: json">"activities": { - "save—bookmark": { - "filters": { - "type": "url", - "url": { "required":true, "pattern":"https?:.{1,16384}" } - }, - "disposition": "inline", - "href": "/save.html", - "returnValue": true - }, - "remove—bookmark": { - "filters": { - "type": "url", - "url": { "required":true, "pattern":"https?:.{1,16384}" } - }, - "disposition": "inline", - "href": "/remove.html", - "returnValue": true - } -},</pre> -<p>As seen above, the activity is handled by save.html and remove.html. Both operations are delegated to <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/bookmark/js/activity_handler.js">apps/bookmark/js/activity_handler.js</a>:</p> -<pre class="brush: js">var ActivityHandler = { - 'save—bookmark': function ah_save(activity) { - }, - - 'remove—bookmark': function ah_remove(activity) { - } -}; - -navigator.mozSetMessageHandler('activity', function onActivity(activity) { - var name = activity.source.name; - switch (name) { - case 'save—bookmark': - case 'remove—bookmark': - if (activity.source.data.type === 'url') { - ActivityHandler[name](activity); - } - ... - } -}</pre> -<p>When the message handler listener <code>navigator.mozSetMessageHandler('activity')</code> receives the save-bookmark or remove-bookmark activities, the <code>ActivityHandler</code> function is triggered to handle correspondent operations.</p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html deleted file mode 100644 index c8a36a6477..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: Gaia应用 -slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps -tags: - - Apps - - B2G - - Firefox OS - - Gaia - - 架构 -translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps ---- -<div class="summary"> - <p><span class="seoSummary">Gaia是Firefox OS 的前端, 它包括系统管理的功能以及附带在Firefox OS上的一些内置应用。所有的Gaia源代码(包括system和键盘IMEs)都完全由HTML5 ( HTML + CSS + JavaScript ) & 开放Web API实现的。 本文介绍了在Gaia家族工作的每一个可获得的应用的信息。</span></p> -</div> -<h2 id="Gaia_功能性分类">Gaia 功能性分类</h2> -<p>Gaia中的应用大致可分成下面几类。</p> -<div class="note"> - <p><b>注意:</b> 许多关于解释单个应用如何工作的页面都是链接自 <a href="https://github.com/mozilla-b2g/gaia/">Gaia Github repo</a> 中的README文件。这是因为许多app都处在快速开发周期内,会迅速的变化(通常是每天),因此如果使MDN页面根据这些变化快速的更新是没有什么意义的。工程师维护的README页面则是当前信息最准确的来源。</p> -</div> -<h3 id="平台">平台</h3> -<p>包括系统(System),设置(Settings),锁屏(Lockscreen),编译脚本(build scripts) 以及蓝牙(Bluetooth) 应用。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7503/platform_team.png" style="width: 355px; height: 269px; margin: 0px auto; display: block;"></p> -<h4 id="平台应用:进一步讲解">平台应用:进一步讲解</h4> -<dl> - <dt> - <a href="/zh-CN/Firefox_OS/Platform/Gaia/Gaia_apps/System">System</a></dt> - <dd> - System app是在<a href="/en-US/Firefox_OS/Platform/Architecture#Firefox_OS_bootup_procedure">Firefox OS启动过程</a>中由Gecko装载的第一个web应用。它会担负许多责任,一般都是系统运行所需要的,因此不会局限于对某一个web应用。</dd> - <dt> - <a href="/zh-CN/Firefox_OS/Platform/Gaia/Gaia_apps/Browser">Browser</a></dt> - <dd> - Browser app(当前是System 的一部分)会提供一些浏览器类似的功能—包括页面导航,搜索和书签等。</dd> - <dt> - <a href="/zh-CN/Firefox_OS/Platform/Gaia/Gaia_apps/Window_Management">Window Management</a></dt> - <dd> - Firefox OS的窗口管理功能 — 包括应用的生命周期和交互、通知、动画以及其他 — 是由System app的特定部分所处理的。本文会着眼于Firefox OS 窗口管理的细节问题。</dd> - <dt> - <a href="/zh-CN/Firefox_OS/Platform/Gaia/Gaia_apps/Settings">Settings</a></dt> - <dd> - Firefox OS 用户可以通过 Settings 应用来配置设备的设置信息,响应传入的活动(带有config名称的<a href="/en-US/docs/WebAPI/Web_Activities">Web activities</a>),这种传入的活动可以使其他应用跳转到Settings应用的不同的界面来处理需要的配置(例如,当没有数据链接时,会显示wifi设置界面)。</dd> -</dl> -<dl> - <dt> - </dt> -</dl> -<h3 id="通信">通信</h3> -<p>包括 Dialer, Contact, SMS 以及 FTU应用.</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7499/comms_team.png" style="width: 317px; height: 246px; margin: 0px auto; display: block;"></p> -<h4 id="通信应用:进一步讲解">通信应用:进一步讲解</h4> -<p>TBD(有待讨论)</p> -<h3 id="生产力应用">生产力应用</h3> -<p>包括 Email, Calendar, 以及 Clock 应用。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7505/productivity_team.png" style="width: 303px; height: 178px; margin: 0px auto; display: block;"></p> -<h4 id="生产力应用:进一步讲解">生产力应用:进一步讲解</h4> -<dl> - <dt> - <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/calendar/README.md">Calendar</a></dt> - <dd> - Firefox OS内置的日历应用。</dd> - <dt> - <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/clock/README.md">Clock</a></dt> - <dd> - Firefox OS原生的始终应用,包括闹钟,定时器,跑表功能。</dd> - <dt> - <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/email/README.md">Email</a></dt> - <dd> - Gaia e-mail 应用。</dd> -</dl> -<h3 id="多媒体">多媒体</h3> -<p>包括相机(Camera), 图库(Gallery), 音乐播放器(Music), 视频播放器(Video)应用以及一些多媒体相关的功能比如DRM和壁纸(wallpapers)。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7501/media_team.png" style="width: 386px; height: 250px; margin: 0px auto; display: block;"></p> -<h4 id="多媒体:进一步讲解">多媒体:进一步讲解</h4> -<dl> - <dt> - <a href="/en-US/docs/Mozilla/Firefox_OS/Platform/Gaia/Gaia_apps/Video">Video</a></dt> - <dd> - Video 是视频播放应用,它能够播放在您Firefox OS 设备中存储的多媒体</dd> - <dt> - <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/camera/README.md">Camera</a></dt> - <dd> - 用户可以使用Camera来从设备摄像头中捕捉和管理视频和图片,而且还能够响应其他应用想要使用摄像头功能来获取多媒体时发出的<code>pick</code>类型的 <a href="/en-US/docs/WebAPI/Web_Activities">Web activitie</a>。</dd> -</dl> -<h3 id="其他的Gaia_功能">其他的Gaia 功能</h3> -<p>除了这些功能,还有其他一些主要的功能例如 browser, homescreen, marketplace, test framework, PDF viewer,以及 app manager,这些都是和Gaia一起紧密开发的。</p> -<dl> - <dt> - <a href="https://github.com/mozilla/pdf.js/blob/master/README.md">pdf.js</a></dt> - <dd> - pdf.js 是基于HTML5的PDF阅读器,用于在Gaia内阅读PDF文件。注意 pdf.js是在Gaia外一个独立的仓库维护的。</dd> -</dl> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html deleted file mode 100644 index 2d14f5798f..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: 系统设置 (Settings) -slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Settings -translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Settings ---- -<div class="summary"> - <p><span class="seoSummary">Settings app 允许用户来配置设备的系统设置信息,同时会对传入的 activities作出响应,即允许app开发者在app中显示特定的settings 视图(例如, 如果没有有效的数据链接,显示 wifi设置面板)。本文主要讲述了它是如何工作的。</span></p> -</div> -<h2 id="mozSettings_API_和_Data_绑定">mozSettings API 和 Data 绑定</h2> -<p>从技术上讲, Settings app 是一个向用户提供对认证<a href="/en-US/docs/Web/API/Navigator.mozSettings"> window.navigator.mozSettings API</a> 访问的UI界面。</p> -<p> Settings app 会自动的处理基本的系统设置操作,如绑定数据字段和 mozSettings 值 — 所有基本操作,如勾选一项设置或改变输入值将会使相关的 mozSettings 值也会改变。</p> -<p><code>window.navigator.mozSettings</code> API 会从Gecko 中获取系统设置的数据。 使用方式如下所示:</p> -<pre class="brush: js">navigator.mozSettings.createLock().set(values);</pre> -<p>上面是设置数据信息。</p> -<div class="note"> - <p><strong>注意</strong>: 在读或写任何 <code>mozSettings</code>, 我们需要使用 <code>createLock()</code> 方法来锁定settings。</p> -</div> -<p>要检索数据,我们可以使用获取或设置一个回调函数的方式启动对数据的操作:</p> -<pre class="brush: js">var reqTimerGoBack = -window.navigator.mozSettings.createLock().get('icc.goBackTimeout'); -reqTimerGoBack.onsuccess = function icc_getTimerGoBackSuccess() { - goBackTimer.timeout = reqTimerGoBack.result['icc.goBackTimeout']; - ... -};</pre> -<p>数据会存储在一个名为 <code>instance.result</code> 词典下。</p> -<p>Firefox OS 2.0 开始, <code>mozSettings</code> 实例可以通过 <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/modules/settings_cache.js">js/modules/settings_cache.js</a> 实例被重复使用:</p> -<pre class="brush: js">var SettingsCache = require('modules/settings_cache'); - -SettingsCache.getSettings(function(result){ - var onlineSupportTitle = result['support.onlinesupport.title']; - ... -});</pre> -<h2 id="导航">导航</h2> -<p>当用户打开 Settings app, 在概览页面会显示多个面板,这个页面则是一个功能性的独立页面。<code>SettingsService.navigate</code> (<a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/modules/settings_service.js">js/module/settings_service.js</a>) 则会控制这些页面间的导航。</p> -<div class="note"> - <p><strong>注意</strong>: For legacy panels (which are not yet ported to the new structure), settings.currentPanel is used instead of SettingsService.navigate to navigate<br> - between panels.</p> -</div> -<p>Since Firefox OS will support tablet devices as well as mobiles, the Settings app has two different types of navigation model implemented:</p> -<ul> - <li>一列(手机端)</li> - <li>两列 (平板端)</li> -</ul> -<p>While called, <code>SettingsService.navigate</code> determines what navigation model to use via the following code:</p> -<pre class="brush: js">if (_isTabletAndLandscape()) { - PageTransitions.twoColumn(oldPanel, newPanel, callback); -} else { - PageTransitions.oneColumn(oldPanel, newPanel, callback); -}</pre> -<h2 id="面板">面板</h2> -<p>From Firefox OS 2.0 onwards, the basic panel structure is defined in <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/modules/panel.js">js/modules/panel.js</a>. It defines six lifecycle stats:</p> -<ul> - <li><code>init</code></li> - <li><code>beforeShow</code></li> - <li><code>show</code></li> - <li><code>hide</code></li> - <li><code>beforeHide</code></li> - <li><code>uninit</code></li> -</ul> -<p>All new settings panels are inherited from <code>SettingsPanel</code>, which extends <code>Panel</code>’s functionalities. The code is contained in <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/modules/settings_panel.js">js/modules/settings_panel.js</a>:</p> -<pre class="brush: js">onInit: function(panel, initOptions) { - ... - - PanelUtils.activate(panel); -}, - -onBeforeShow: function(panel, beforeShowOptions) { - // Preset the panel every time when it is presented. - PanelUtils.preset(panel); - _addListeners(panel); - ... -},</pre> -<p><code>PanelUtils.activate</code> — defined in <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/modules/panel_utils.js">js/modules/panel_utils.js</a> — is used to parse all links in the panel and adds corresponding handlers in <code>onInit</code> stat, and <code>PanelUtils.preset</code> is used to preset elements with the settings values in the <code>onBeforeShow</code> stat.</p> -<p>All new settings panels are defined in the <a href="https://github.com/mozilla-b2g/gaia/tree/master/apps/settings/js/panels">js/panels</a> folder.</p> -<h2 id="AMD_模块和编译时间优化">AMD 模块和编译时间优化</h2> -<p>From Firefox OS 2.0 onwards, the Settings app uses the <a href="http://en.wikipedia.org/wiki/Asynchronous_module_definition">AMD modules pattern</a> to implement each panel. The AMD modules are loaded via <a href="https://github.com/requirejs/alameda">Alemeda</a> (a lighter version of <a href="http://requirejs.org/">RequireJS</a>) and built/optimized using <code>r.js</code> (the RequireJS optimizer). The Settings app still had dependencies on files (<a href="https://github.com/mozilla-b2g/gaia/tree/master/shared/js">shared/js</a>) which aren’t AMD modules. For those it uses the <code>shim</code> options defined in <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/config/require.js">settings/js/config/require.js</a>.</p> -<h2 id="参考">参考</h2> -<p> <a href="https://github.com/mozilla-b2g/gaia/tree/master/apps/settings">Settings app has a build-in README</a> ,这个文件可以用来获取 Settings (大部分内容是由 Arthur Chen and Fred Lin 完成的)。</p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html deleted file mode 100644 index 853dd41fbb..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html +++ /dev/null @@ -1,226 +0,0 @@ ---- -title: System -slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/System -translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/System ---- -<div class="summary"> - <p><span class="seoSummary">System app 是在 <a href="https://developer.mozilla.org/en-US/Firefox_OS/Platform/Architecture#Firefox_OS_bootup_procedure">Firefox OS 启动过程</a> 中由Gecko装载的第一个 web 应用, 它会处理许多运行系统所需要的任务,因此不会局限于某一个单独的 web 应用。 这篇文档主要是讲解 Sytem如何工作。</span></p> -</div> -<blockquote> - <p>任何一个可以用 JavaScript 编写的应用, 会最终使用 JavaScript 构建的。 -- Atwood's Law</p> -</blockquote> -<div class="note"> - <p><b>注意</b>: 您可以在 Gaia Github 仓库中获取到 <a href="https://github.com/mozilla-b2g/gaia/tree/master/apps/system">source code for the System app</a></p> -</div> -<h2 id="system_app_是如何启动的">system app 是如何启动的</h2> -<p>当 Gecko 试图启动System应用时, 它会解析System's manifest.webapp 文件,并根据 <code style="font-style: normal;">launch_path </code>参数(该参数在Gaia应用中一般是 /index.html) 装载 index.html 文件。 要管理整个的移动系统,Sytem app需要装载很多资源文件。 </p> -<p>整个启动过程是从 <code>bootstrap.js </code>中的下面代码开始的: </p> -<pre class="brush: js">window.addEventListener('load', function startup() { -// define safelyLaunchFTU -function safelyLaunchFTU() { - ... -} - -if (Applications.ready) { - safelyLaunchFTU(); -} else { - ... -} - -window.addEventListener('ftudone', function doneWithFTU() { - window.removeEventListener('ftudone', doneWithFTU); - - var lock = window.navigator.mozSettings.createLock(); - lock.set({ - 'gaia.system.checkForUpdates': true - }); -} - - ... - -// With all important event handlers in place, we can now notify -// Gecko that we're ready for certain system services to send us -// messages (e.g. the radio). -var evt = new CustomEvent('mozContentEvent', -{ bubbles: true, cancelable: false, - detail: { type: 'system-message-listener-ready' } }); - window.dispatchEvent(evt); -}</pre> -<p>这段代码是这样工作的:</p> -<ol> - <li>System 是运行在浏览器引擎中真正的web应用, 并需要所有它依赖的资源都装载进去 — 包括 图片(images)和样式(styles)。 因此一旦 <a href="/zh-CN/docs/Web/API/Window/onload" title="此页面仍未被本地化, 期待您的翻译!"><code>window.onload</code></a> 事件触发, 我们就要开始这些工作。</li> - <li>首先,我们要使用 <span style="font-family: 'Courier New', 'Andale Mono', monospace;">safelyLaunchFTU() 函数</span>准备启动首次启动体验(FTU) 。顾名思义, 只有当用户首次启动 Firefox OS 时, FTU才会出现。</li> - <li>当用户在 FTU中点击 “完成” 时, 会启动 <span style="font-family: 'Courier New', 'Andale Mono', monospace;">ftudone </span>自定义事件, <code>bootstrap.js</code> 会监听和处理这个事件。</li> - <li>下一步, 我们会使用 <a href="/zh-CN/docs/Web/API/Settings" title="此页面仍未被本地化, 期待您的翻译!"><code>Settings</code></a> API (<code>navigator.mozSettings</code>) 将 <code>gaia.system.checkForUpdates</code> 设置成 <code>true</code>, 表示系统会检查更新。</li> - <li>最后,我们会通过 <span style="font-family: 'Courier New', 'Andale Mono', monospace;">CustomEvent </span>运行自定义的 <code>window.dispatchEvent</code>。这是Gaia 使用的一个非常重要的设计模式, 用于系统消息的处理以及与Gecko层的通信。上面方法是指 Gaia System app 通知 Gecko层, 它已经准备好监听和处理事件了。 </li> -</ol> -<h2 id="实现模块化">实现模块化</h2> -<p>为了实现更好的模块化和灵活性,system 应用本身也在不断的改进。 从1.4 版本开始, 专门发起了一个关于 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=912952">refactor the system module as instantiable object</a> 的倡议来讨论该问题。</p> -<p>在所有上述代码运行后,每个对 <code style="font-style: normal;">bootstrap.js</code> 中的系统组件的引用都是是如下的形式:</p> -<pre class="brush: js">window.telephonySettings = new TelephonySettings(); -window.telephonySettings.start();</pre> -<p> <code>TelephonySettings()</code> 的源代码框架如下:</p> -<pre class="brush: js">(function(exports) { - 'use strict'; - function TelephonySettings() { - this.init_param = false; - } - - TelephonySettings.prototype = { - // Initialzes all settings. - start: function() { - ... - }, - - // Clean all settings. - stop: function() { - ... - }, - - 1st_method: function ts_1st_method() { - ... - }, - - 2nd_method: function ts_2nd_method() { - ... - } - }; - - exports.TelephonySettings = TelephonySettings; - -}(window));</pre> -<p>这种模式可以帮助每个系统组件实现模块化,并使它们的可测性更强。</p> -<h2 id="开机和关机动画">开机和关机动画</h2> -<p>本部分会讲解 System app是如何控制开机动画和关机动画的。 <code>init_logo_handler.js</code> 和 <code>sleep_menu.js</code> 文件会对 system 开机动画和关机动画进行处理。</p> -<h3 id="开机动画">开机动画</h3> -<p>开机动画当前并没有包含在主引导程序中,而是要借助于检查 <code style="font-style: normal;">EventListeners。</code></p> -<p>在 <code>init_logo_handler.js</code> 文件中的开机启动代码如下所示:</p> -<p>一旦Gecko准备将一些东西画在屏幕上时, 会选择 logo或者是动画。当DOM装载完成时, 我们会运行合适的系统处理程序来完成log或动画。当 <span style="font-family: 'Courier New', 'Andale Mono', monospace;">ftudone 或者 </span><span style="font-family: 'Courier New', 'Andale Mono', monospace;">ftuskip </span>运行时会将logo隐藏。 包含在 <code>init_logo_handler.js 中的</code> <code style="font-style: normal;">_appendCarrierPowerOn</code> 方法表示了如何通过监听<span style="font-family: 'Courier New', 'Andale Mono', monospace;">DOMContentLoaded</span>事件来启动动画或启动logo。<code>logoLoader</code> 方法则在 <code>logo_loader.js 中定义。</code></p> -<pre class="brush: js">var self = this; -document.addEventListener('DOMContentLoaded', function() { - self.carrierLogo.appendChild(self.logoLoader.element); - self._setReady(); -});</pre> -<p>一旦准备好 logo, 系统会调用 <code>_setReady()</code> 方法, 在方法中会建立一个监听器来监听特殊的 <code>mozChromeEvent事件,这个事件会带有</code> <code>system-first-paint</code> 类型,表示系统系统已经准备好向屏幕绘图。</p> -<pre class="brush: js">var elem = this.logoLoader.element; - ... -window.addEventListener('mozChromeEvent', function startVideo(e) { - if (e.detail.type == 'system-first-paint') { - window.removeEventListener('mozChromeEvent', startVideo); - if (elem &amp;&amp; elem.ended === false) { - elem.play(); - } - } -});</pre> -<p>此时图形元素开始运行。一旦启动 <code>ftuopen</code> 或 <code>ftuskip</code> 事件, <code>init_logo_handler.js</code> 会调用默认的 <code>handleEvent()</code> 方法反过来触发 <code>animate()</code> 方法来以淡出的效果隐藏动画。</p> -<pre class="brush: js">init: function ilh_init(logoLoader) { - window.addEventListener('ftuopen', this); - window.addEventListener('ftuskip', this); - ... -}, - -handleEvent: function ilh_handleEvent() { - this.animate(); -},</pre> -<h3 id="关机动画">关机动画</h3> -<p>当系统准备就绪时,长按电源(power)按键,会触发定义在 <code style="font-style: normal;">hardware_button.js 文件中的 </code><code>holdsleep</code> 事件。 <code style="font-style: normal;">hardware_button.js 文件会处理所有“物理按键点击“的事件,包括电源(休眠)键,home键,音量增/减键等。</code></p> -<pre class="brush: js">HardwareButtonsSleepState.prototype.enter = function() { - this.timer = setTimeout(function() { - / * When the user holds Sleep button more than HOLD_INTERVAL. */ - this.hardwareButtons.publish('holdsleep'); - this.hardwareButtons.setState('base'); - }.bind(this), this.hardwareButtons.HOLD_INTERVAL); -};</pre> -<p>关机动画是由 <code>sleep_menu.js 处理的</code>;这个脚本文件会监听 <code>holdsleep</code> 事件,并且当它触发时会显示菜单对话框。</p> -<pre class="brush: js">init: function sm_init() { - ... - window.addEventListener('holdsleep', this.show.bind(this)); - ... -}</pre> -<p>如果用户通过重启和关机菜单选项选择关机,会触发 <code>startPowerOff()</code> 方法, 它反过来会触发 <code>LogoLoader()</code> 函数来对关机动画进行处理。</p> -<pre class="brush: js">handleEvent: function sm_handleEvent(evt) { - switch (evt.type) { - case 'click': - ... - this.handler(action); - break; - ... - } -} - -handler: function sm_handler(action) { - switch (action) { - ... - case 'restart': - this.startPowerOff(true); - break; - - case 'power': - this.startPowerOff(false); - break; - ... - } -}</pre> -<h2 id="System_的功能">System 的功能</h2> -<p> System app 会负责许多功能和任务, 你可能还会对能在其职权范围内找到而惊讶。系统应用负责的范围包括:状态栏( statusbar)和 实用工具盘管理(utility tray management), SIM卡锁(SIM lock), 更新管理(update manager), 主屏幕启动(homescreen launcher),webapp 窗口管理(webapp window) 等。 本节会对System 提供的一些最重要的功能进行探究。</p> -<h3 id="状态栏(Statusbar)和实用工具盘(utility_tray)">状态栏(Statusbar)和实用工具盘(utility tray)</h3> -<p>系统状态栏和下拉菜单 (Gaia 通常称之为 <em>utility tray</em>; Android 称之为<em> notification bar</em>) 是由 <code>statusbar.js</code> 和 <code>utility_tray.js </code>来处理的。 在应用的 <code>index.html 中,状态栏条目是在</code> <code><div id="statusbar" data-z-index-level="statusbar"></code> 中定义的,而实用工具盘条目在下面的结构中定义:</p> -<pre class="brush: html"><div id="utility-tray" data-z-index-level="utility-tray"> - <div id="notifications-container"> - ... - </div> -</div></pre> -<p>实用工具盘(utility tray)中会有一些特殊的面板,如更新管理器,紧急回调管理器,存储监视通知,媒体播放通知和控制,蓝牙传输状态,按键输入法(IME)切换。与之相关联的处理程序和样式放置在 <code>js</code>/ 和<code>style/</code> 文件夹中。</p> -<h3 id="特殊的应用launcher">特殊的应用launcher</h3> -<p>System app 有三个特殊的launchers, 在需要时会调用单独的web应用程序。</p> -<ul> - <li>主屏幕启动器 : Homescreen 应用在运行时,当用户按下 Home 按钮,webapp 崩溃或者使用其他方式退出webapp时,都会显示主屏幕。</li> - <li>锁屏启动器: 运行 lockscreen 应用时, 每次当用户打开屏幕时都会显示锁屏界面。</li> - <li> FTU 启动器: 运行FTU 体验应用。这个应用只会在用户使用一个全新的 FirefoxOS设备(或者将设备恢复到出厂模式)时运行一次。而且 FTU webapp不会允许用户点击Home按键退出这个应用。</li> -</ul> -<h3 id="锁屏">锁屏</h3> -<p>Lockscreen app 的主要入口文件是 <code>system/js/lockscreen.js</code>。用户可以在这个界面解锁,启动相机以及音乐播放器。</p> -<h3 id="紧急拨号器">紧急拨号器</h3> -<p>紧急拨号器的代码是在 <code>gaia/apps/system/emergency-call/</code> 文件夹下的。 它是拨号应用的简化版本,允许用户可以访问 <a href="#SIM_PIN_unlock_dialog">SIM PIN unlock dialog</a> 实现紧急拨号服务。</p> -<h2 id="全系统(System-wide)UI">全系统(System-wide)UI</h2> -<p>System应用会处理绝大多数的全系统(system-wide) UI, 其中大部分包括的是一些对话框,如音量警告对话框,SIM PIN解锁对话框,小区广播(cell broadcast)对话框,还包括一些影响窗口行为的UI元素,如 software home按键。</p> -<h3 id="z-index_level">z-index level</h3> -<p>在System 应用的 <code>index.html</code> 文件中,许多组件都带有 <code>data-z-index-level</code> 属性,例如</p> -<pre class="brush: html"><div id="sleep-menu" data-z-index-level="sleep-menu"> - ... -</div></pre> -<p>对应 z-index-levels 定义在 <code>system/style/zindex.css 文件中,如</code></p> -<pre class="brush: css">#screen > [data-z-index-level="sleep-menu"] { - z-index: 65536; -} - -... - -#screen > [data-z-index-level="app"] > .appWindow { - z-index: 3; -}</pre> -<p>z-index 设置是根据元素在屏幕上显示的顺序进行排列的 — 如果元素需要在视觉层次中比较高的元素数值也会较高。这就是System app在基本水平上窗口管理的方式。 </p> -<h3 id="software_home_按键">software home 按键</h3> -<p> software home 按键是 home按键的一种替代,会在缺少物理 home按键的情况下自动启动。例如在 Nexus 4 中。 要控制它的外观,Gecko提供了一个专有的媒体功能称为 <code>-moz-physical-home-button,</code> 它能够在媒体查询时使用基于硬件Home按键的外观。 如果需要,窗口管理会为 <code>software home</code>按键分配一些屏幕的空间。</p> -<p>在 <code>system/style/window.css</code> (以及许多其他的系统样式文件中), 可以看到</p> -<pre class="brush: css">@media not all and (-moz-physical-home-button) { - #screen:not(.software-button-disabled) > #windows > .appWindow { - bottom: 5rem; - } - }</pre> -<h3 id="Home_手势_(从屏幕底部向上滑动)">Home 手势 (从屏幕底部向上滑动)</h3> -<p>home 手势是另外一个硬件home按键的替代;它可以在 <a href="/en-US/Firefox_OS/Debugging/Developer_settings">开发者设置</a> 中使能,而控制代码在 <code>system/js/home_gesture.js 文件中。例如,这个手势涉及到从屏幕底部清扫,可以用来关闭应用。</code></p> -<p>这个手势能够在 Firefox OS 平板设备中自动使能。 而 <code>gaia/shared/js/screen_layout.js</code> 是专门用于检测设备是否是平板的。</p> -<h3 id="音量警告对话框">音量警告对话框</h3> -<p>在 <code>system/js/sound_manager.js</code>. 中包含控制音量警告对话框的代码。如果下面所有条件都满足,则会弹出音量警告对话框:</p> -<ul> - <li>耳机已插入设备</li> - <li>已超过最大音量限值 85dB </li> - <li>声道音频中有内容播放</li> -</ul> -<h3 id="SIM_PIN_解锁对话框">SIM PIN 解锁对话框</h3> -<p>控制SIM PIN 解锁对话框的代码在 <code>system/js/simcard_dialog.js 中</code> — 当Passcode lock选项使能时,对话框会在锁屏界面显示。开放的应用必须要在 <code style="font-style: normal;">manifest.webapp</code> 中包含 telephony 权限中(System app中含有该权限)。</p> -<div class="note"> - <p><b>注意</b>: 当手机在飞行模式时,不会显示SIM PIN 解锁对话框</p> -</div> -<p> </p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html deleted file mode 100644 index c0871e3130..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html +++ /dev/null @@ -1,279 +0,0 @@ ---- -title: 窗口管理(Window Management) -slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Window_Management -translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Window_Management ---- -<div class="summary"> - <p><span class="seoSummary">一般来说,window manager 是应用的一部分,会在图形用户界面中控制窗口的放置和外观。本文会对Firefox OS是如何进行窗口管理的内容进行探究。</span></p> -</div> -<p>Firefox OS中, Window Management是System app的一部分,主要负责:</p> -<ul> - <li>App的生命周期以及app之间的交互。 </li> - <li>UI 元素的布局,调整,显示及动画/切换</li> - <li>全系统的UI逻辑,包括 web activities, app 消息, 以及任务管理(task manager)</li> - <li>App-指定的UI特性如弹出框,情景菜单和错误页面。 </li> -</ul> -<p>在深入理解上述条目的细节前,让我们来看下应用是如何在Gaia内部启动的。 </p> -<h2 id="App在Gaia中的启动">App在Gaia中的启动</h2> -<p>app在 Firefox OS 中的启动有几种方式,例如,通过其他app的系统消息,或者在HomeScreen中点击app图标等。 </p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7709/app-launch-flow.png" style="width: 728px; height: 414px; display: block; margin: 0px auto;"></p> -<p>控制app开启的事件是由 Gecko引擎和 System App 处理的,下面会有详细阐述。</p> -<h3 id="App_结构">App 结构</h3> -<p>所有的 Gaia webapps 都是 <a href="/en-US/Marketplace/Publishing/Packaged_apps">packaged apps</a>,它们都是基本的zip文件,其中会包含所有的应用程序文件: HTML, CSS, JavaScript, images, manifest, 等等。每个在 Gaia 中的 web 应用都会以下面 的基本结构进行组织: </p> -<div class="code-block"> - <div class="highlight"> - <pre><code class="brush: bash">apps</code><code class="o">/</code><code class="p">[</code><code class="n">app</code> <code class="n">name</code><code class="p">]</code><code class="o">/</code> - <code class="o">-</code> <code class="n">js</code> - <code class="o">-</code> <code class="n">styles</code> - <code class="o">-</code> <code class="n">locales</code> - <code class="o">-</code> <code class="n">test</code> - <code class="o">-</code> <code class="n">index</code><code class="p">.</code><code class="n">html</code> - <code class="o">-</code> <code class="n">manifest</code><code class="p">.</code><code class="n">webapp</code> -</pre> - </div> -</div> -<p><img alt="" src="https://mdn.mozillademos.org/files/7497/app_load_process.png" style="width: 2262px; height: 1979px; margin: 0px auto; display: block;"></p> -<p>当一个内嵌的Gaia app 从 homescreen 启动时,Gecko 会试图打开 URL 地址 <code>manifest://[app name].gaiamobile.org:8080, 解析对应的</code> <code>manifest.webapp</code> 文件,之后运行文件中 <code>launch_path </code>指定的文件 — 在所有内嵌 webapp中都是 <code>index.html</code> 。<code>index.html</code> 文件会加载所有需要的样式和 JavaScript。</p> -<div class="note"> - <p><b>注意 </b>: 此处有一个非正式的约定,Gaia app的主要 js 入口点一般是 <code>[app name].js</code> 或 <code>main.js</code>.</p> -</div> -<h3 id="App启动次序">App启动次序</h3> -<p>启动事件会发给Gecko。一旦 Gecko 准备就绪, <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/app_window_factory.js">system/js/app_window_factory.js</a> 文件中的 <code>AppwindowFactory</code> 就会收到一个 app的 <code>webapps-launch</code> 事件或一个用于处理挂起消息的 <code>open-app </code>事件。</p> -<pre class="brush: js">window.addEventListener('applicationready', function appReady(e) { - window.removeEventListener('applicationready', appReady); - window.addEventListener('webapps-launch', self); - window.addEventListener('webapps-close', self); - window.addEventListener('open-app', self); -});</pre> -<p><span style="background-color: #ffff00;">关于 handleEvent 动作的细节, </span><code><span style="background-color: #ffff00;">this.launch(config)</span></code><span style="background-color: #ffff00;"> 会启动一个 app window 或 activity。一旦app关闭, </span><code><span style="background-color: #ffff00;">Appwindow</span></code><span style="background-color: #ffff00;"> 会收到 </span><code><span style="background-color: #ffff00;">webapps-close</span></code><span style="background-color: #ffff00;"> 事件。</span></p> -<p>主进程中的 <code>launch()</code> 方法如下:</p> -<pre class="brush: js">var app = AppWindowManager.getApp(config.origin); -if (app) { - app.reviveBrowser(); -} else if (config.origin !== homescreenLauncher.origin) { - new AppWindow(config); -} else if (config.origin == homescreenLauncher.origin) { - homescreenLauncher.getHomescreen().ensure(); -}</pre> -<p>首先,会检查 app 变量是否存在并试图到Gecko 中恢复app的运行。否则,如果是常规的app,我们会创建一个关于 app 的 <code>AppWindow</code> 实例。另一个特殊的情况是 <code>homescreenLauncher</code> — 此时我们会执行一些必要的操作。</p> -<h3 id="AppWindow">AppWindow</h3> -<p>Firefox OS 会使用专门的 <a href="https://developer.mozilla.org/en-US/docs/WebAPI/Browser">mozBrowser API</a> 使 web 页面看起来像一个 app。 窗口管理的核心只是使用 <code>mozBrowser</code> API 封装来处理 内部的 iFrames (窗口)。之所以创建这个特殊的 <code>moz-browser</code> 类型,主要是为了使iFrame 看起来更像一个真实的浏览器窗口。</p> -<p><code>AppWindow</code> 可以创建,容纳以及管理 <code>mozBrowser</code> iFrame。<code>AppWindow</code> 可以操控所有由 <code>mozBrowser</code> iFrame 本身触发的 <code>mozBrowser</code> 事件并且还可以显示相关的UI特性。</p> -<h2 id="App_生命周期管理">App 生命周期管理</h2> -<p>app整个的生命周期如下:</p> -<ul> - <li>App launch</li> - <li>将 iframe 添加到 System DOM tree中</li> - <li>Start App 开启动画</li> - <li>App opened</li> - <li>App close 动画</li> - <li>App closed</li> - <li>从 DOM tree 中移除 iframe</li> - <li>App terminated</li> -</ul> -<h3 id="启动_app">启动 app</h3> -<p>当用户点击 homescreen 上的应用图标时,homescreen 会使用 <a href="/en-US/docs/Web/API/Navigator.mozApps">mozApps API</a> 来通知 Gecko 引擎打开对应的app。当Gecko 准备就绪时,它会发送一个适当的事件给 system app。</p> -<h3 id="Killing_apps">Killing apps</h3> -<p>在下面情况下,App 将会被 kill 掉:</p> -<ul> - <li>app crashes</li> - <li><a href="https://developer.mozilla.org/en-US/Firefox_OS/Debugging/Debugging_OOMs#Process_priorities">OOM killer</a> kills it</li> - <li>app 由任务管理器关闭</li> - <li><code>window.close()</code> 被调用</li> -</ul> -<p>对于活动的应用程序而言,在关闭动画后,被 kill app 的 iFrame 就会从 DOM tree中移除。 对于不活动的应用程序,在它们被kill 后, 对应的 iframe 就会立刻移除。</p> -<p>在下面情况下,Apps 会被中断:</p> -<ul> - <li>对于web activities来说: 当activity 调用者被打开时</li> - <li>弹出框 (Popups): 当 window.open 调用者被打开时</li> - <li>App: 不做任何事情时</li> -</ul> -<h3 id="重启_app">重启 app</h3> -<p>在下面情况下, Apps 会被重启:</p> -<ul> - <li>homescreen app: 当按下 home 键时</li> - <li>如果是从任务管理器打开或通过边缘手势滑动(正在实验中的功能),Zombie apps 会通过同样的URL复活,</li> -</ul> -<h2 id="app是如何被渲染的">app是如何被渲染的</h2> -<p>在启动一个app时,屏幕会分为下面几部分:</p> -<ul> - <li>System header</li> - <li>App iframe</li> - <li>底部包装栏 (如果在浏览器框架模式下)</li> -</ul> -<p><img alt="" src="https://mdn.mozillademos.org/files/7711/app-window-layout.png" style="width: 393px; height: 348px; display: block; margin: 0px auto;"></p> -<h3 id="App_布局">App 布局</h3> -<p>应用 iframe 的主要容器如下:</p> -<pre class="brush: html"><iframe id="browser2" mozallowfullscreen="true" mozbrowser="true" remote="true"... -... src="", data-url="" data-frame-type="window" data-frame-origin="..."> -</iframe></pre> -<p>iframe 中包括:</p> -<ul> - <li>启动路径(<code>data-url</code>, <code>data-frame-origin</code>)</li> - <li>mozbrowser iframe 属性 (<code>mozallowfullscreen="true"</code>, <code>mozbrowser="true"</code>)</li> - <li>容器,覆盖视窗,app指定UI</li> -</ul> -<h3 id="调整_AppWindow大小">调整 AppWindow大小</h3> -<p>AppWindow 会在下面几种情况下被调整:</p> -<ul> - <li> system app 只有在转屏时才会调整大小。</li> - <li>对于一般的 app, 在下列情况下会调整大小: - <ul> - <li>system app 调整大小</li> - <li>keyboard 开启/关闭 动画结束时</li> - <li>状态栏变化时</li> - <li><code>window.resizedBy()</code> 或 <code>window.resizeTo()</code> 被调用时</li> - <li>software home 按钮被选中时</li> - </ul> - </li> -</ul> -<p><img alt="" src="https://mdn.mozillademos.org/files/7713/app-area.png" style="width: 715px; height: 305px; margin: 0px auto; display: block;"></p> -<p>总之,屏幕的大小会受到下面要素的影响:</p> -<ul> - <li>Orientation 状态</li> - <li>Keyboard 状态</li> - <li>AttentionScreen 状态 (被呼叫,有短信等)</li> - <li>Chrome 导航状态</li> - <li>全屏状态 <code>manifest.fullscreen</code> / <code>parentWindow</code></li> - <li>Software homebutton 状态</li> -</ul> -<p><img alt="" src="https://mdn.mozillademos.org/files/7715/app-area2.png" style="width: 687px; height: 330px; margin: 0px auto; display: block;"></p> -<h3 id="AppWindow_方向">AppWindow 方向</h3> -<p>app 的方向可以由每个单独的app或由系统全局控制。您可以在 <code>manifest.webapp</code> 中使用 <code>orientation</code> 属性来设置方向。例如</p> -<pre class="brush: json">"orientation": "default",</pre> -<p>您也可以使用orientation API 来锁定和解锁方向:</p> -<pre class="brush: js">screen.mozLockOrientation([‘portrait-primary’]); - -screen.mozUnlockOrientation();</pre> -<p>可以用下面的属性值来强制对方向进行设定:</p> -<ul> - <li><code>default</code>: 系统默认方向</li> - <li><code>portrait</code>: 强制屏幕竖直方向显示</li> - <li><code>landscape</code>: 强制屏幕横向显示</li> -</ul> -<p>要获取更多的细节,请参考 <a href="/en-US/docs/Web/API/Screen.lockOrientation">Screen.lockOrientation</a> , 您也可以在 <a href="https://github.com/mozilla-b2g/gaia/blob/master/test_apps/uitest/js/API/orientation.js">gaia/test_apps/uitest/js/API/orientation.js</a>. 查看设定的实例。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7717/app-orientation.png" style="width: 745px; height: 530px; margin: 0px auto; display: block;"></p> -<h3 id="App_可见性">App 可见性</h3> -<p>只有当关掉屏幕时, System app 才会到后台;而正常的 app 到后台要依赖下面几个因素:</p> -<ul> - <li>Audio competing</li> - <li>Process policy</li> - <li>Rendering</li> -</ul> -<div class="note"> - <p><strong>注意</strong>: 当父 iframe 页面非活动时,页面可见性会被继承。</p> -</div> -<p>在下面情况下,APP通常会在前台运行:</p> -<ul> - <li>启动动画开始时</li> - <li>滑动(Swipe-in)动画结束时</li> - <li>锁屏界面被解锁时</li> -</ul> -<p>下面情况下,App 通常会在后台运行:</p> -<ul> - <li>关闭动画结束时</li> - <li>呼叫屏幕(callscreen)显示3秒之后</li> - <li>屏幕关闭时</li> -</ul> -<p>对上面的规则而言,有一些意外的情况:</p> -<ul> - <li>在正常渠道下,伴有音频播放的Active app</li> - <li>Apps 调用内嵌的 web activities</li> - <li>Apps 打开 <code>window.open('', '', 'dialog')</code></li> -</ul> -<div class="note"> - <p><strong>注意</strong>: 此处的 Active app 是指当前正在前台运行的应用;而 inactive app是指挡在后台运行的应用(界面不可见)。</p> -</div> -<h3 id="AppWindow_动画和过渡">AppWindow 动画和过渡</h3> -<p>为了让用户获得更顺畅的使用体验,Gaia 的窗口管理器(Window Manager)也会提供 app window 动画和过渡效果。</p> -<p> AppWindow 动画和过渡效果是由下面的状态来管理的:</p> -<ul> - <li><code>displayedApp</code> — 当前的 App</li> - <li><code>runningApps</code> / <code>numRunningApps</code> — 运行的app集合</li> - <li><code>openFrame</code> / <code>closeFrame</code> — 打开/关闭动画的过渡框架</li> -</ul> -<p>在调用 <code>setDisplayedApp()</code> 方法时, app 会通过下图中列出的状态来启动。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7719/app-animations-state-manchine.png" style="width: 704px; height: 358px; display: block; margin: 0px auto;"></p> -<p>在控制 Firefox OS app动画流程时,有下面几个技巧:</p> -<ul> - <li>在 app opened 之前,我们要确认它已经从后台状态中恢复。 我们通常会取一个 1 x 1 截屏来进行重绘。</li> - <li>在 app 准备好 opened 时, 我们会同时执行当前 app 关闭的动画和下一个 app 启动的动画。</li> - <li>在 app opening 和 closing 期间,我们会运行代码对转屏进行锁定和解锁。</li> - <li>仅仅当 app resized 一次之后, 在 opening 时,我们才会运行代码执行 app resize 操作;否则,我们会忽略 resizing 步骤。</li> - <li>我们在改变页面的可见性时,会再次使用 1 x 1 截屏(请看上面)。</li> -</ul> -<p><img alt="" src="https://mdn.mozillademos.org/files/7721/app-switching-flow.png" style="width: 530px; height: 258px; display: block; margin: 0px auto;"></p> -<h2 id="AppWindow_特定UI">AppWindow 特定UI</h2> -<p>有一些特定的 UI 元素只和特定的 app 相关,如 Browser chrome, modal dialogs, context menus, popups, 以及 error pages.</p> -<p>下面让我们来讨论下。</p> -<h3 id="弹出框(Modal_dialogs)">弹出框(Modal dialogs)</h3> -<p>在 desktop Firefox 中,,如果您启动了浏览器开发面板, 在其中输入如 <code>alert()</code>, <code>confirm()或</code> <code>prompt()</code> 等命令,就会在屏幕中心弹出一个对话框,并遮盖了下面的内容。Firefox OS 中的 modle dialogs 和这个效果是相同的。<br> - <br> - <img alt="" src="https://mdn.mozillademos.org/files/7723/modal-dialogs.png" style="width: 715px; height: 357px; margin: 0px auto; display: block;"></p> -<h3 id="快捷菜单(Context_menu)对话框">快捷菜单(Context menu)对话框</h3> -<p>移动开发者都会非常熟悉 快捷菜单(或长按菜单)。一般在设计app时,为了使用户能够更简便的使用 app,最常用的用户动作应该是对用户可见的。我们可以将一些无法直接放置在UI上,但又经常使用的动作放在快捷菜单中。<br> - <br> - <img alt="" src="https://mdn.mozillademos.org/files/7725/context-menu-dialogs.png" style="width: 722px; height: 360px; display: block; margin: 0px auto;"></p> -<h3 id="授权(Authentication)_(https)_对话框">授权(Authentication) (https) 对话框</h3> -<p>定义在 <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/app_authentication_dialog.js">system/js/app_authentication_dialog.js</a> 文件中。</p> -<h3 id="值选择,时间,日期对话框">值选择,时间,日期对话框</h3> -<p>定义在 <a href="https://github.com/mozilla-b2g/gaia/tree/master/apps/system/js/value_selector">system/js/value_selector/</a>.</p> -<h3 id="权限对话框">权限对话框</h3> -<p>定义在 <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/permission_manager.js">system/js/permission_manager.js</a> 和 <a href="https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/media_recording.js">system/js/media_recording.js</a> 文件。</p> -<h2 id="特定应用">特定应用</h2> -<p>有些应用需要一个特殊的 <code>appWindow</code> 对象来处理它们包含的特定功能。其中包括:</p> -<ul> - <li>Homescreen</li> - <li>FTU</li> - <li>Keyboard</li> - <li>Cost control</li> - <li>Secure camera</li> - <li>Lockscreen</li> -</ul> -<h2 id="子窗口管理">子窗口管理</h2> -<p>子窗口是由 其他 app/pages 直接或间接打开的。如:</p> -<ul> - <li>Attention window</li> - <li>Popup window</li> - <li>Activity window</li> - <li>Trusted UI / Trusted window</li> -</ul> -<p>当子窗口被正常终止时,它的父窗口应该被重新打开。有些自窗口可会也会包含其他的子窗口。父窗口与子窗口间进程优先级的管理也是一个问题。</p> -<h2 id="视窗(Attention_Window)">视窗(Attention Window)</h2> -<p>Attention Windows 用来获取用户的注意力:</p> -<ul> - <li>拨号界面 — dialer</li> - <li>时钟界面 — clock</li> - <li>权限确认界面</li> -</ul> -<p>当前这些 attention window 都是被强制使用的默认方向(竖向优先)。</p> -<h2 id="委托(Trusted)_UI">委托(Trusted) UI</h2> -<p>Persona 和 mozPay API 使用的时委托 UI。它们使用特定的尺寸sizing: 80% 显示。在 trusted UI 运行时Homescreen是部分显示的。<br> - <br> - <img alt="" src="https://mdn.mozillademos.org/files/7727/trusted-ui.png" style="width: 737px; height: 516px; display: block; margin: 0px auto;"></p> -<h2 id="历史记录管理_(History_Management)">历史记录管理 (History Management)</h2> -<p>本节我们会讲解一些可以在 Firefox 中管理历史记录的组件。</p> -<h3 id="任务管理器">任务管理器</h3> -<p>任务管理器 Task manager (card 视图) 可通过长按 home 按钮触发。它会显示设备上的app历史,此时可以动态的kill一个app。</p> -<h3 id="Web_activity_处理">Web activity 处理</h3> -<p>内嵌 Activities 会创建一个新的引用页面为 activity 提供数据。<br> - <br> - Window Activities 会重复使用已存在的app window 来反映 acitivity 数据。</p> -<h3 id="边缘手势_(测试中)">边缘手势 (测试中)</h3> -<p>这个测试的边缘手势动能在 Firefox 2.0+ 开发模式版本才存在,它会允许您使用手动滑动 设备的 右/左边缘来在app和web页面之间切换。</p> -<h4 id="How_is_the_next_app_to_display_chosen">How is the next app to display chosen?</h4> -<ul> - <li>Child window of the active app</li> - <li>Launch time is newer</li> - <li>Find the head window of the next app stack</li> -</ul> -<h4 id="How_is_the_previous_app_chosen">How is the previous app chosen?</h4> -<ul> - <li>Parent window of the active app</li> - <li>Launch time is older</li> - <li>Find the rear window of the previous app stack</li> -</ul> -<h3 id="截屏管理">截屏管理</h3> -<p>截屏工具会被 任务管理器(卡片视图)所使用,来显示历史记录中的app。当app 关闭动画结束时, 就会获取到一个app的屏幕截图。</p> -<h2 id="参考">参考</h2> -<p><a href="http://alivedise.github.io/blog/2013/02/23/from-browser-to-browser/">From Browser to Browser</a></p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html deleted file mode 100644 index 6c3633a7a5..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html +++ /dev/null @@ -1,542 +0,0 @@ ---- -title: Hacking Gaia -slug: Archive/B2G_OS/Platform/Gaia/Hacking -translation_of: Firefox_OS/Developing_Gaia ---- -<div class="warning"> -<p>该页面是为Gaia开发者写的。如果您在寻找关于如何编译和运行Firefox OS 的信息,可以参考 <a href="/zh-CN/docs/Mozilla/Firefox_OS/Building_and_installing_Firefox_OS" title="/zh-CN/docs/Mozilla/Firefox_OS/Building_and_installing_Firefox_OS">Building and installing Firefox OS page</a> .</p> -</div> - -<div class="summary"> -<p><span class="seoSummary">Gaia 是<a href="https://developer.mozilla.org/apps" rel="nofollow">web apps</a> 的集合,并且由它组合成 <a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Firefox_OS">Firefox OS</a>的前端. 在Firefox OS 屏幕上看到的都是由Web技术构建的。其中包括主屏幕和所有的原生app。本文则提供了修改Gaia代码的详细说明。</span></p> -</div> - -<h2 id="获取源码">获取源码</h2> - -<p>要获取Gaia的源码, <a href="https://github.com/mozilla-b2g/gaia" title="https://github.com/mozilla-b2g/gaia">fork us on GitHub</a> 并且使用 <a href="http://git-scm.com/" title="http://git-scm.com/">git</a> 将您fork的代码clone到本地。</p> - -<pre>$ git clone https://github.com/mozilla-b2g/gaia.git</pre> - -<h2 id="运行Gaia">运行Gaia</h2> - -<p>有三种方式可以运行Gaia,分别是在桌面,火狐浏览器或者兼容的移动设备。</p> - -<h3 id="B2G_桌面">B2G 桌面</h3> - -<p>B2G 桌面是在Firefox OS设备上运行应用程序的桌面版本,您可以使用它在电脑桌面上运行Gaia。</p> - -<p>您可以从<a href="http://nightly.mozilla.org/">Firefox Nightly站点</a>上下载<a href="http://nightly.mozilla.org/#Desktop%20Boot2Gecko">B2G桌面的nightly版本</a>。其中有关于Linux (32位 and 64 位), Mac OS X 以及 Windows的版本.</p> - -<p>Nightly 版本都会对近期的gaia版本打包。一旦您下载完成压缩包,只需要解压到文件夹中,并从解压到的文件夹中运行b2g二进制文件就可以了。 </p> - -<pre>$ cd b2g -$ ./b2g</pre> - -<p>如果您出于开发的目的来运行带有指定版本Gaia的B2G, 则需要从您clone的代码位置构建一个配置文件:</p> - -<pre>$ cd /path/to/gaia -$ DEBUG=1 DESKTOP=0 make</pre> - -<p>上面的命令会在<code>gaia</code> 生成一个名称为<code>profile</code>的文件夹。 <code>DEBUG选项会将</code> Gaia 作为托管的应用在内置的Web服务器上运行,而不是在每次更改后都需要重新打包的原生应用。在运行上面的命令后,您可以在最后的输出行中找到配置文件夹的路径,大体是 </p> - -<pre>Profile Ready: please run [b2g|firefox] -profile /path/to/gaia/profile</pre> - -<p>之后则可以指定配置文件来运行B2G。</p> - -<pre>$ ./b2g /path/to/gaia/profile</pre> - -<p>您用可以从源码中编译出自身的B2G桌面。</p> - -<div class="note"> -<p><strong>注意 :</strong> 在 Mac OS X, <code>b2g</code> 二进制文件会存在于 B2G.app.您需要运行下面命令:</p> - -<p><code>./B2G.app/Contents/MacOS/b2g /path/to/gaia/profile</code></p> -</div> - -<h3 id="在Firefox中运行Gaia">在Firefox中运行Gaia</h3> - -<p>也可以在Firefox内部运行Gaia。这种方式会让您的开发周期大大缩短,同时也可以使用标准的web开发工具和调试器。 可以参考<a href="/zh-CN/docs/Mozilla/Firefox_OS/Developing_Firefox_OS/Quickstart_guide_to_Gaia_development">Gaia开发快速指南</a> 获取更多的信息.</p> - -<h3 id="在设备上运行Gaia">在设备上运行Gaia</h3> - -<p>如果您有一个兼容的移动设备,也可以使用Firefox OS 烧机来运行Gaia。您可以参考<a href="/zh-CN/docs/Mozilla/Firefox_OS/Building_and_installing_Firefox_OS">编译和安装Firefox OS </a>获取更多信息. 我们也有关于<a href="/zh-CN/docs/Mozilla/Firefox_OS/Platform/Testing">如何测试Firefox OS</a>的文章。</p> - -<h2 id="单元测试">单元测试</h2> - -<p>参考<a href="/zh-CN/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_unit_tests">Gaia单元测试</a> 来获取如何创建和在Gaia层运行单元测试的文章。</p> - -<h2 id="提交bug">提交bug</h2> - -<p>在Bugzilla的 <a href="https://bugzilla.mozilla.org/buglist.cgi?product=Firefox OS&component=Gaia&resolution=---" rel="nofollow">Firefox OS > Gaia</a> 中提交bug。在<a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Firefox_OS">Gaia组件</a> (或者是子组件)中提交bug.</p> - -<h2 id="为_Gaia做贡献">为 Gaia做贡献</h2> - -<p>Mozilla依赖开源社区的贡献,以帮助开发Gaia应用,我们也希望您能参与进来。</p> - -<p>我们可以从一些非常好的网址来发现一些bug:</p> - -<ul> - <li><a href="https://bugzilla.mozilla.org/buglist.cgi?quicksearch=component:gaia%20sw:polish%20@nobody;list_id=4566236" rel="nofollow">Unowned Gaia polish bugs on Bugzilla</a></li> - <li><a href="http://www.joshmatthews.net/bugsahoy/?b2g=1" rel="nofollow">Mentored bugs</a></li> -</ul> - -<h3 id="编码风格基本知识">编码风格基本知识</h3> - -<ul> - <li>背景: - <ul> - <li><a href="/zh-CN/docs/Developer_Guide/Coding_Style#General_practices" title="Developer_Guide/Coding_Style#General_practices">Coding Style: General practices</a></li> - <li><a href="/zh-CN/docs/Developer_Guide/Coding_Style#JavaScript_practices" title="Developer_Guide/Coding_Style#JavaScript_practices">Coding Style: JavaScript practices</a></li> - <li><a href="/zh-CN/docs/Developer_Guide/Coding_Style#Naming_and_formatting_guide" title="Developer_Guide/Coding_Style#Naming_and_formatting_guide">Coding Style: Naming and formatting guide</a></li> - </ul> - </li> - <li>Make sure HTML files are declared <code><!DOCTYPE html></code> (that is, as HTML5 documents). If you don't, Internet Explorer 9 and later will load them in compatibility mode.</li> - <li>Include the <code>"use strict";</code> statement (just like that, including the quotes) to the top of your JavaScript files to put them into strict mode.</li> - <li>Always use two spaces for indentation, rather than tabs.</li> - <li>Please use line breaks to separate logical bits of code!</li> - <li>Multi-word file names should use the "underscore" character to separate words, <code>like_this.js</code>.</li> - <li>Use single quotes instead of double quotes for strings.</li> -</ul> - -<h4 id="Additional_rules">Additional rules</h4> - -<p>Bad:</p> - -<pre>if (expression) doSomething(); -</pre> - -<p>Correct:</p> - -<pre>if (expression) { - doSomething(); -} -</pre> - -<p>If you're working on the system app, check out the guidance listed <a href="https://groups.google.com/d/msg/mozilla.dev.gaia/rEhSrw6XmT4/UNvE7qW9pgYJ" title="See_here_for_some_rules._https://groups.google.com/d/msg/mozilla.dev.gaia/rEhSrw6XmT4/UNvE7qW9pgYJ">here</a>.</p> - -<p>Before submitting a patch we recommend you run <a href="https://developers.google.com/closure/utilities/docs/linter_howto" title="http://closure-linter.googlecode.com/svn/trunk/closure_linter/gjslint.py">gjslint</a> on it to check for any style errors:</p> - -<pre>gjslint --nojsdoc my_file.js</pre> - -<h3 id="提交一个_patch">提交一个 patch</h3> - -<p>First file or assign a bug to yourself on <a href="https://bugzilla.mozilla.org/buglist.cgi?product=Firefox OS&component=Gaia&resolution=---" title="https://bugzilla.mozilla.org/buglist.cgi?product=Firefox OS&component=Gaia&resolution=---">Bugzilla</a>, you'll need a Bugzilla account.</p> - -<p>Then create a branch on your fork of Gaia:</p> - -<pre>$ git branch branchname -$ git checkout branchname</pre> - -<p>Commit your changes:</p> - -<pre>$ git add /file/to/add -$ git commit -m "Bug XXXXX - Fix the broken Gaia and save the world"</pre> - -<p>Push your branch:</p> - -<pre>$ git push origin branchname</pre> - -<p>Send a pull request by navigating to the branch in your fork on GitHub and finding the pull request button.</p> - -<div class="note"> -<p><strong>Note</strong>: Except under unusual circumstances, patches should be landing first on the master branch, not a release branch like v1-train, v1.3, etc. If they need to land on a release branch, they must go through the usual approval process as outlined on the <a href="https://wiki.mozilla.org/Release_Management/B2G_Landing">B2G Landing wiki page</a>.</p> -</div> - -<p>To request a review of your patch, <a href="http://globau.wordpress.com/2013/10/21/github-pull-requests-and-bugzilla/">attach the pull request</a> to the bug in Bugzilla by referencing the URL of the pull request, and set the review ("r") flag to "?" and enter the bugzilla ID of one of the <a href="https://wiki.mozilla.org/Modules/FirefoxOS" title="https://wiki.mozilla.org/Modules/FirefoxOS">module owners and peers</a> (very important - otherwise your bug will not likely be seen by anyone). The <a href="https://addons.mozilla.org/zh-CN/firefox/addon/github-tweaks-for-bugzilla/" title="https://addons.mozilla.org/zh-CN/firefox/addon/github-tweaks-for-bugzilla/">Github tweaks for bugzilla extension on AMO</a> can help automate this process by automatically creating the attachment and adding it to the bug; you will still need to set the review flag on Bugzilla.</p> - -<p>The reviewer may ask you to make some changes; you may need to amend the original commit and force push it to the original branch/pull request. Once they're happy with your patch, they will merge it into the master branch for you. Before they do this they would prefer it if you could squash all your changes into a single commit, so your contribution can be tracked easily.</p> - -<p>The person who merges the commit (usually the reviewer) would add a <code>r=</code> flag in the comment of the merge commit.</p> - -<h2 id="Make_选项">Make 选项</h2> - -<p>you use the <code>make</code> command inside the Gaia repo to create a Gaia profile that can be loaded onto your device or run in a <a href="/zh-CN/Firefox_OS/Using_the_B2G_desktop_client">B2G Desktop</a> build. This section looks in detail at the different make options available.</p> - -<p>There are many environment variables present in the Makefile. Do not depend on them as they may be removed in the future.</p> - -<p>Created profiles are stored in <code>/gaia/profile</code>, and contain the following items:</p> - -<ul> - <li>defaults: Directory containing default settings to be reloaded after you reset the phone.</li> - <li>extensions: Directory containing extensions.</li> - <li>settings.json: Settings file.</li> - <li>user.js: Another file containing more settings/preferences.</li> - <li>webapps: Directory containing all the web apps that are to be installed on the phone.</li> -</ul> - -<div class="note"> -<p><strong>Note</strong>: When you've already made a profile and you want to build a new one, you must delete the existing profile directory before trying to generate a new one.</p> -</div> - -<h3 id="Default">Default</h3> - -<pre class="brush: bash">make</pre> - -<p>This simply gives you an unbranded, non-debug build. For a branded build build you need to use <a href="#Official_Mozilla_branding_make">Official Mozilla branding make</a>; for a debug build you need <a href="#Debug_make">Debug make</a>.</p> - -<h3 id="推送到设备端">推送到设备端</h3> - -<pre class="brush: bash">make install-gaia - -make reset-gaia -</pre> - -<p>With <a href="/zh-CN/Firefox_OS/Debugging/Installing_ADB">ADB</a> (Android Debug Bridge) setup, these make targets will push Gaia to the device. <code>install-gaia</code> will just push updates of Gaia from your working directory to your device. <code>reset-gaia</code> will purge all existing configuration, profiles, web apps and database entries (a new settings database will be initialized) before pushing Gaia.</p> - -<h3 id="编译特定的应用">编译特定的应用</h3> - -<pre class="brush: bash">APP=system make - -APP=system make install-gaia</pre> - -<p>When a profile already exists, <code>APP</code> allows you to specify which app to re-package, instead of re-packing and re-pushing all the Gaia apps.</p> - -<h3 id="指定自定义的配置文件夹">指定自定义的配置文件夹</h3> - -<p>You can specify a custom directory to build your profile in, using <code>PROFILE_FOLDER</code>, for example:</p> - -<pre class="brush: bash">PROFILE_FOLDER=profile-b2g-desktop make</pre> - -<h3 id="不同设备的编译">不同设备的编译</h3> - -<p>There are a few make options that create builds for different devices, with different purposes.</p> - -<h4 id="Create_a_phone_build_of_Gaia">Create a phone build of Gaia</h4> - -<pre class="brush: bash">GAIA_DEVICE_TYPE=phone make</pre> - -<p>This build gets apps from <code>/gaia/build/config/phone/apps-engineering.list</code>.</p> - -<h4 id="Create_a_tablet_build_of_Gaia">Create a tablet build of Gaia</h4> - -<pre class="brush: bash">GAIA_DEVICE_TYPE=tablet make</pre> - -<p>This build gets apps from <code>/gaia/build/config/phone/apps-engineering.list</code>.</p> - -<h3 id="不同类型的编译">不同类型的编译</h3> - -<p>There are a few make options that create different types of build, with different purposes.</p> - -<h4 id="Production_make">Production make</h4> - -<pre class="brush: bash">PRODUCTION=1 make</pre> - -<p>This creates a production build of Gaia:</p> - -<ul> - <li>Gaia is run as packaged apps, which are harder to debug, but are the best available state for apps in terms of available API permissions, etc.</li> - <li>Test apps are not included in the build</li> - <li>Remote debugging is turned off by default</li> - <li>Lock screen is turned on (which in turn will cut USB connections)</li> - <li>Marionette is turned off</li> - <li>First time user experience is turned on</li> - <li>Offline cache is used.</li> -</ul> - -<div class="note"> -<p><strong>Note</strong>: You can also use the alias <code>make production</code>.</p> -</div> - -<h4 id="Debug_make">Debug make</h4> - -<pre class="brush: bash">DEBUG=1 make</pre> - -<p>The <code>DEBUG</code> variable runs Gaia as hosted apps on a built-in web server on a specific <code>GAIA_PORT</code>, rather than the default of packaged apps which have to be re-packaged after every change; this makes things easier to test. Launching the profile with the latest Firefox Nightly will also give you nice B2G specific panels on the Firefox Developer Tools.</p> - -<p>In addition:</p> - -<ul> - <li>Test apps are included in the build.</li> - <li>Remote debugging is turned on by default.</li> - <li>Lock screen is turned off (USB connections won't be interrupted.)</li> - <li><a href="/zh-CN/docs/Mozilla/QA/Marionette">Marionette</a> is turned on, which is needed when running Gaia <a href="/zh-CN/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_unit_tests" title="/zh-CN/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_unit_tests">unit tests</a>.</li> - <li>First time user experience is turned off.</li> - <li>Offline cache is not used, even if it is generated.</li> -</ul> - -<h4 id="Device_debug_make">Device debug make</h4> - -<pre class="brush: bash">DEVICE_DEBUG=1 make</pre> - -<p>This disables screen lock on the device, and enables debugging with the ADB tool, so is useful for device debugging.</p> - -<p>In Firefox OS version > 1.2, specify this param when you want to debug Firefox OS webapps with the <a href="/zh-CN/Firefox_OS/Using_the_App_Manager">App Manager</a>.</p> - -<h4 id="Debug_desktop_make">Debug desktop make</h4> - -<pre class="brush: bash">DEBUG=1 DESKTOP=0 make</pre> - -<p>This option creates a desktop debug version, for running inside <a href="/zh-CN/Firefox_OS/Using_the_B2G_desktop_client">B2G desktop</a>.</p> - -<h4 id="Official_Mozilla_branding_make">Official Mozilla branding make</h4> - -<pre class="brush: bash">MOZILLA_OFFICIAL=1 make</pre> - -<p>Use this to make an official Mozilla-branded build.</p> - -<h4 id="Dogfood_make">Dogfood make</h4> - -<pre class="brush: bash">DOGFOOD=1 make</pre> - -<p>Dogfooding options and utilities are turned on, for example the Feedback app, which allows doog fooders to easily submit feedback on the OS.</p> - -<h4 id="System_apps_make">System apps make</h4> - -<pre class="brush: bash">B2G_SYSTEM_APPS=1 make</pre> - -<p>This environment variable lets you push an app to <code>/system/b2g</code> instead of <code>/data/local</code>. You should use this when you work with a user build. This variable is automatically set when running <code>make production</code>. This can be used for <code>install-gaia</code> or <code>reset-gaia</code> too.</p> - -<h4 id="Distribution_and_market_customization_build">Distribution and market customization build</h4> - -<pre class="brush: bash">GAIA_DISTRIBUTION_DIR=./dir</pre> - -<div class="note"> -<p><strong>Note</strong>: Read <a href="/zh-CN/Firefox_OS/Hacking_Firefox_OS/Market_customizations_guide">Market Customizations</a> for more details.</p> -</div> - -<h3 id="开发调试选项">开发/调试选项</h3> - -<p>There are also make options for adding/removing features or changing settings, for debugging purposes.</p> - -<h4 id="Enable_remote_debugging">Enable remote debugging</h4> - -<pre class="brush: bash">REMOTE_DEBUGGER=1</pre> - -<p>This enables remote debugging on the device, the same as using the option in the <a href="/zh-CN/Firefox_OS/Debugging/Developer_settings#Remote_debugging">developer settings</a>.</p> - -<h4 id="JavaScript_optimization_make">JavaScript optimization make</h4> - -<pre class="brush: bash">GAIA_OPTIMIZE=1 make</pre> - -<p>This triggers an optimization pass on Gaia's JavaScript, concatenating/compressing the files. This is automatically set when running <code>make production</code>. This can be used for <code>install-gaia</code> or <code>reset-gaia</code> too.</p> - -<h4 id="High_resolution_image_assets">High resolution image assets</h4> - -<pre class="brush: bash">GAIA_DEV_PIXELS_PER_PX=1.5 make</pre> - -<p>When packaging the app, this option replaces images with their <code>*@1.5x.(gif|jpg|png)</code> equivalents if such images exist. You need to use the above option as part of a standard <code>make</code> command, for example:</p> - -<pre class="brush: bash">GAIA_DEV_PIXELS_PER_PX=1.5 make reset-gaia - -GAIA_DEV_PIXELS_PER_PX=1.5 make install-gaia</pre> - -<p>Gaia is currently targetting the following screen resolutions:</p> - -<ul> - <li>qHD: ~540×960; device pixel ratio = 1.6875</li> - <li>WVGA: ~480×800; device pixel ratio = 1.5</li> - <li>HBGA (320x240); device pixel ratio = 1</li> -</ul> - -<p>use <code>GAIA_DEV_PIXELS_PER_PX</code> to make sure the images looks sharp on qHD and WVGA devices. see <a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Mobile/Viewport_meta_tag#A_pixel_is_not_a_pixel" title="https://developer.mozilla.org/zh-CN/docs/Mozilla/Mobile/Viewport_meta_tag#A_pixel_is_not_a_pixel">A pixel is not a pixel</a> for more information about device pixels per css pixels.</p> - -<h4 id="Haida_features">Haida features</h4> - -<pre class="brush: bash">HAIDA=1 make reset-gaia</pre> - -<p>This build enables the Haida feature set, which is currently limited to <a href="https://wiki.mozilla.org/FirefoxOS/systemsfe/epm#Rocketbar_Results">rocketbar</a> and <a href="https://wiki.mozilla.org/FirefoxOS/Haida#Edge_Gestures_Between_Open_Content">edge</a> gestures, but will likely include other features in the near future.</p> - -<h4 id="Disable_first_time_use_experience_(FTU)">Disable first time use experience (FTU)</h4> - -<pre class="brush: bash">NOFTU=1 -</pre> - -<p>Disable the FTU with this environment variable.</p> - -<h4 id="Disable_lockscreen">Disable lockscreen</h4> - -<p>You can disable the Firefox OS lockscreen using the NO_LOCK_SCREEN option, for example:</p> - -<pre class="brush: bash">NO_LOCK_SCREEN=1 make</pre> - -<h4 id="Reference_Workloads">Reference Workloads</h4> - -<p>Reference workloads allow developers/testers to quickly install a large amount of data in several applications, typically on a newly-flashed phone.</p> - -<p>The commands are (from the gaia directory):</p> - -<pre class="brush: bash">make reference-workload-light</pre> - -<ul> - <li>200 contacts</li> - <li>200 sms messages</li> - <li>50 dialer history entries</li> - <li>20 gallery images</li> - <li>20 songs</li> - <li>5 videos</li> -</ul> - -<pre class="brush: bash">make reference-workload-medium</pre> - -<ul> - <li>500 contacts</li> - <li>500 sms messages</li> - <li>100 dialer history entries</li> - <li>50 gallery images</li> - <li>50 songs</li> - <li>10 videos</li> -</ul> - -<pre class="brush: bash">make reference-workload-heavy</pre> - -<ul> - <li>1000 contacts</li> - <li>1000 sms messages</li> - <li>200 dialer history entries</li> - <li>100 gallery images</li> - <li>100 songs</li> - <li>20 videos</li> -</ul> - -<pre class="brush: bash">make reference-workload-x-heavy</pre> - -<ul> - <li>2000 contacts</li> - <li>2000 sms messages</li> - <li>500 dialer history entries</li> - <li>250 gallery images</li> - <li>250 songs</li> - <li>50 videos</li> -</ul> - -<p>These targets accept the <code>APP</code> environment variable, or an <code>APPS</code> environment variable that should contain the app names separated by a space, e.g.:</p> - -<pre class="brush: bash">APP=sms make reference-workload-light -APPS="sms communications/contacts" make reference-workload-heavy -</pre> - -<p>The apps available are:</p> - -<pre class="brush: bash">APPS="gallery music video communications/contacts sms communications/dialer"</pre> - -<p>In order to install music (songs) with reference workloads, the utility mid3v2 must be installed. This utility can be installed with:</p> - -<pre class="brush: bash">sudo apt-get install python-mutagen</pre> - -<p>If you run Fedora or RHEL instead, use:</p> - -<pre class="brush: bash">sudo yum install python-mutagen</pre> - -<h4 id="Documentation_make">Documentation make</h4> - -<p>Gaia docs can be built, via jsdoc3. To generate these, you can use the following command:</p> - -<pre class="brush: bash">make docs</pre> - -<h4 id="Enabling_IME_layout_and_dictionaries">Enabling IME layout and dictionaries</h4> - -<p>To enable keyboard IME layout and dictionaries enabled, use following command structure:</p> - -<pre class="brush: bash">GAIA_KEYBOARD_LAYOUTS=en,zh-Hant-Zhuyin,el,de,fr,zh-Hans-Pinyin make</pre> - -<h2 id="自定义_build-time_应用">自定义 build-time 应用</h2> - -<p>The apps that run on Firefox OS are all contained within the Gaia source tree, in one of two locations:</p> - -<ul> - <li><code>gaia/apps</code>: This is where the system default apps are found, such as <code>calendar</code>, <code>email</code>, <code>settings</code>, etc.</li> - <li><code>gaia/external-apps</code>: This is where the Firefox Marketplace app is found (<code>marketplace.firefox.com</code>), and where apps subsequently installed by the user are stored.</li> - <li><code>gaia/showcase-apps</code>: This is a container for multiple showcase apps, for example a 3D Crystal Skull to show off WebGL performance on the device.</li> - <li><code>gaia/test-apps</code>: This directory is a repository for simple tests, designed to test simple B2G features.</li> - <li><code>gaia/external-apps</code>: This directory contains more tests.</li> - <li>There may be oters too, depending on the version of Gaia you have cloned.</li> -</ul> - -<div class="note"> -<p><strong>Note</strong>: If you are building B2G rather than Gaia, the paths will of course have <code>B2G/</code> on the front, e.g. <code>B2G/gaia/apps</code> and <code>B2G/gaia/external-apps</code>.</p> -</div> - -<p>If you want to omit some of these apps from your build of Gaia/B2G, you can do this in a few different ways:</p> - -<ol> - <li> - <p>The "brute force" method is to simply delete the apps you don't want to be present at build time, before building.</p> - </li> - <li> - <p>The more refined method is to edit the <code>gaia/build/config/apps-*.list</code> files to include the paths to the apps you want to include at build time. For example, <code>gaia/build/config/apps-production.list </code>looks something like this:</p> - - <pre class="brush: bash">apps/* -external-apps/* -outoftree_apps/*</pre> - - <p>But you could also include specific apps rather than just picking them all, for example:</p> - - <pre class="brush: bash">apps/clock</pre> - - <p>The mechanism for choosing which <code>apps-*.list</code> file is used during the build to determine the available apps is contained inside <code>gaia/Makefile</code>:</p> - - <pre class="brush: cpp">GAIA_APP_TARGET?=engineering -... -ifeq ($(MAKECMDGOALS), demo) -GAIA_DOMAIN=thisdomaindoesnotexist.org -GAIA_APP_TARGET=demo -else ifeq ($(MAKECMDGOALS), dogfood) -DOGFOOD=1 -else ifeq ($(MAKECMDGOALS), production) -PRODUCTION=1 -endif -... -ifeq ($(PRODUCTION), 1) -GAIA_OPTIMIZE=1 -GAIA_APP_TARGET=production -endif - -ifeq ($(DOGFOOD), 1) -GAIA_APP_TARGET=dogfood -endif -... -ifndef GAIA_APP_CONFIG -GAIA_APP_CONFIG=build$(SEP)config$(SEP)apps-$(GAIA_APP_TARGET).list -endif</pre> - - <p>Initially, the <code>GAIA_APP_TARGET</code> variable is set to <code>engineering</code>, so by default building gaia from source will use <code>app-engineering.list</code> (which includes all the tests, demos, etc.):</p> - - <pre class="brush: bash">make -</pre> - - <p>To specify usage of a different apps list you specify different options when running the make command. To build with <code>apps-production.list</code>, for example, you'd use</p> - - <pre class="brush: bash">PRODUCTION=1 make</pre> - - <ul> - <li>If you specifically build with <code>DEMO=1</code> specified, then it will use <code>apps-demo.list</code>.</li> - <li>If you specifically build with <code>DOGFOOD=1</code> specified, then it will use <code>apps-dogfood.list</code>.</li> - <li>You can completely override the decision by using <code>GAIA_APP_CONFIG</code> and providing your own <code>apps-*.list</code> file.</li> - </ul> - - <p><code>gaia/Android.mk</code> contains these lines:</p> - - <pre class="brush: cpp">ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),) -GAIA_MAKE_FLAGS += PRODUCTION=1 -B2G_SYSTEM_APPS := 1 -endif</pre> - - <p>When you build, if <code>VARIANT=user</code> or <code>VARIANT=userdebug</code> are set (these wind up getting reflected in the <code>TARGET_BUILD_VARIANT</code> variable), <code>PRODUCTION=1</code> is automatically set when building gaia.</p> - </li> - <li> - <p>The third, and most refined (but most complex) method is to use customizations. These allow you to specify build-time customization instructions in separate difrectories, without modifying the core Gaia repo. You can include your own customizations in distinct directories, or use the preexisting directories that come with the source.</p> - - <p>For example, the basic Firefox tablet customized app list is defined in <code>apps.list</code> under the <a href="https://github.com/mozilla-b2g/gaia/tree/master/distribution_tablet"><code>distribution_tablet</code></a> folder (<code>gaia/distribution_tablet</code>). These customizations can be applied at build time using options like this:</p> - - <pre class="brush: bash">GAIA_DISTRIBUTION_DIR=distribution_tablet make</pre> - - <div class="note"> - <p><strong>Note</strong>: Customizations is its own separate topic entirely. To learn more about it, read <a href="/zh-CN/Firefox_OS/Hacking_Firefox_OS/Market_customizations_guide">Market Customizations</a>.</p> - </div> - - <div class="note"> - <p><strong>Note</strong>: If you want to include custom external apps as part of your Gaia build, you need to build them in a specific way, and then place them into the <code>gaia/external-apps/</code> folder. Read <a href="/zh-CN/Firefox_OS/Hacking_Firefox_OS/Market_customizations_guide#Building_Prebundled_web_apps">Building Prebundled web apps</a> to find out how.</p> - </div> - </li> -</ol> - -<div class="warning"> -<p><strong>Important</strong>: If you are a device vendor creating a custom B2G/Gaia build for distribution, you need to satisfy certain criteria before you are allowed to include the Firefox Marketplace app on your phones/tablets/etc. Contact Mozilla for more details.</p> -</div> - -<h2 id="联系小组">联系小组</h2> - -<ul> - <li><a href="https://lists.mozilla.org/listinfo/dev-gaia" rel="nofollow">Gaia Mailing List</a></li> - <li>#gaia IRC channel on irc.mozilla.org</li> -</ul> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/index.html deleted file mode 100644 index 698c63da42..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/index.html +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: Gaia -slug: Archive/B2G_OS/Platform/Gaia -translation_of: Archive/B2G_OS/Platform/Gaia ---- -<p>Gaia是<a href="/zh-CN/docs/Mozilla/Firefox_OS" title="Mozilla/Firefox_OS">Firefox OS</a>的用户界面层.在Firefox OS启动之后,显示在屏幕上的一切东西都是由Gaia绘制出来的,包括锁屏,主屏幕,拨号界面,以及其他的应用程序.Gaia完全是由<a href="/zh-CN/docs/zh-CN/HTML" title="HTML">HTML</a>,<a href="/zh-CN/docs/CSS" title="CSS">CSS</a>,和<a href="/zh-CN/docs/JavaScript" title="JavaScript">JavaScript</a>编写的.它和底层的操作系统以及硬件进行交互是通过标准的Web API来完成的,这些API是由<a href="/zh-CN/docs/Gecko" title="Gecko">Gecko</a>实现的.</p> -<p>正因为这样的设计,Gaia不仅能直接运行在Firefox OS设备上,还能运行在其他的操作系统以及其他的web浏览器中.</p> -<p>和Gaia一起安装在设备上的第三方应用程序也可以由Gaia来启动.</p> -<table class="topicpage-table"> - <tbody> - <tr> - <td> - <h2 class="Documentation" id="Documentation" name="Documentation">Gaia的相关文档</h2> - <dl> - <dt> - <a href="/zh-CN/docs/Mozilla/Firefox_OS/Platform/Gaia/Introduction_to_Gaia" title="Mozilla/Boot_to_Gecko/Introduction to Gaia">介绍Gaia</a></dt> - <dd> - Gaia是Firefox OS设备上使用的用户界面应用程序,它仅仅是一个运行在Firefox OS软件栈上的Web应用程序.本指南会详细的介绍Gaia.</dd> - </dl> - <dl> - <dt> - <a href="/en-US/docs/Mozilla/Firefox_OS/Platform/Gaia/Gaia_apps">Gaia应用</a></dt> - <dd> - 对Gaia中可获得的默认应用进行介绍,包括如何使用和修改它们。</dd> - <dt> - <a href="/zh-CN/docs/Mozilla/Firefox_OS/Platform/Gaia/Hacking">Gaia hacking 指南</a></dt> - <dd> - 关于hacking和修改Gaia接口的指南。</dd> - <dt> - <a href="/en-US/docs/Mozilla/Firefox_OS/Platform/Gaia/Build_System_Primer">Gaia系统构建入门</a></dt> - <dd> - 在Gaia build子文件夹下由脚本执行的绝大多数有意以的构建步骤。</dd> - <dt> - <a href="/en-US/docs/Mozilla/Firefox_OS/Platform/Gaia/Hacking_Tips_And_FAQ">Gaia Hacking提示和常见问题 </a></dt> - <dd> - 关于hacking Gaia的一些有用的提示以及常见问题。</dd> - </dl> - <p><span class="alllinks"><a href="/zh-CN/docs/tag/Gaia" title="tag/B2G">查看更多...</a></span></p> - </td> - <td> - <h2 class="Community" id="Community" name="Community">到社区寻求帮助</h2> - <p>如果你的工作需要和Gaia打交道,或者正在开发一个Gaia应用程序,有相关的社区资源可以帮助你!</p> - <ul> - <li>咨询Boot to Gecko项目论坛: <ul> - <li><a href="https://lists.mozilla.org/listinfo/dev-gaia"> 邮件列表</a></li> - - - <li><a href="http://groups.google.com/group/mozilla.dev.gaia"> 新闻组</a></li> - <li><a href="http://groups.google.com/group/mozilla.dev.gaia/feeds"> Web feed</a></li> -</ul></li> - </ul> - <ul> - <li>在Mozilla的Gaia IRC频道上提出你的问题: <a href="irc://irc.mozilla.org/gaia" title="irc://irc.mozilla.org/gaia">#gaia</a></li> - </ul> - <p><span class="alllinks"><a class="external" href="http://www.catb.org/~esr/faqs/smart-questions.html" title="http://www.catb.org/~esr/faqs/smart-questions.html">不要忘记"提问的艺术"...</a></span></p> - <br> - <h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">相关话题</h2> - <ul> - <li><a href="/zh-CN/docs/Mobile" title="Mobile">Mobile</a></li> - <li><a href="/zh-CN/docs/HTML" title="HTML">HTML</a></li> - <li><a href="/zh-CN/docs/CSS" title="CSS">CSS</a></li> - <li><a href="/zh-CN/docs/JavaScript" title="JavaScript">JavaScript</a></li> - </ul> - <h2 class="Tools" id="Resources" name="Resources">资源</h2> - <ul> - <li><a href="/zh-CN/docs/Mozilla/Firefox_OS/Architecture" title="Mozilla/Firefox_OS/Architecture">Firefox OS体系结构概述</a></li> - </ul> - </td> - </tr> - </tbody> -</table> -<p> </p> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html deleted file mode 100644 index 562cb61765..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: Gaia简介 -slug: Archive/B2G_OS/Platform/Gaia/Introduction_to_Gaia -tags: - - Apps - - B2G - - Gaia - - Settings -translation_of: Archive/B2G_OS/Platform/Gaia/Introduction_to_Gaia ---- -<div class="summary"> - <br> - Gaia 是Boot to Gecko (B2G) 的用户界面; 它是一个web应用的集合,可以本地运行在B2G设备,仿真器,桌面版本或firefox版本上。添加app或规Gaia更改时使用的web技术都是 <a href="https://developer.mozilla.org/en/JavaScript" title="en/JavaScript">JavaScript</a>, <a href="https://developer.mozilla.org/en/HTML" title="en/HTML">HTML</a>,和 <a href="https://developer.mozilla.org/en/CSS" title="en/CSS">CSS</a>.</div> -<h2 id="Gaia_锁屏界面" style="margin-bottom: 20px; line-height: 30px;"> Gaia 锁屏界面</h2> -<p>锁屏界面会显示网络运营商,当前时间和日期,和一个滑动条可用来解锁手机或直接进入相机拍照。 如果用户有密码锁定设置,锁屏界面会显示一个密码输入窗口。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7611/gaia-lockscreen.png" style="margin-right: auto; margin-left: auto; height: 480px; width: 320px; display: block;"></p> -<p>注意一些设备默认是使能密码锁定的;这种情况下,默认的解锁PIN码是 "0000"。该功能后续可能会有所改变。</p> -<h2 id="默认的Gaia接口" style="margin-bottom: 20px; line-height: 30px;">默认的Gaia接口</h2> -<p>Gaia的默认界面,如下图所示,与您在绝大多数智能手机上看到界面是非常相似的。</p> -<p><img alt="" src="https://mdn.mozillademos.org/files/7613/device-2013-01-24-163623.png" style="margin-right: auto; margin-left: auto; height: 480px; width: 320px; display: block;"></p> -<p>这张图片显然是一个预发布版本的操作系统,其中还带有占位符图标和一些测试应用。界面顶端的状态栏放置了一些状态标识,包括当前手机选择的网络运营商(或者没有SIM卡),SIM卡信号强度,WIFI信号强度,电池点亮以及当前时间。</p> -<p>界面中间区域显示了应用的图标,滑动屏幕可查看各界面的图标。您可以在<a href="https://developer.mozilla.org/en-US/Firefox_OS/Platform/Gaia/Gaia_apps" style="text-decoration: underline;">Gaia apps</a> 一文中获取更多关于 Gaia 默认 app集合的信息。 </p> -<p>屏幕的最下方是是一个快速启动栏,一般会放置一些您最常用到的应用。您也可已从快速启动栏拖动一个app图标到中间的区域。</p> -<h2 id="参考" style="margin-bottom: 20px; line-height: 30px;">参考</h2> -<ul> - <li><a href="https://developer.mozilla.org/en-US/Firefox_OS/Platform/Gaia/Gaia_apps">Gaia apps</a>: 该页面会对每个app进行介绍,包括如何使用和修改它们。</li> - <li><a href="https://developer.mozilla.org/en-US/Firefox_OS/Debugging/Developer_settings">Developer settings</a>: 对不同的开发者设置进行介绍,而且可以通过Gaia Settings 应用来配置它们。</li> -</ul> diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/weinre远程调试工具/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/weinre远程调试工具/index.html deleted file mode 100644 index 213a8defb1..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gaia/weinre远程调试工具/index.html +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: Weinre 远程调试工具 -slug: Archive/B2G_OS/Platform/Gaia/Weinre远程调试工具 -tags: - - weinre -translation_of: Tools/Remote_Debugging ---- -<p>Weinre 是Apache基础工程之一,是 WEb INspector REmote 的缩写。正如其名,它是和 Firebug 或浏览器调试工具类似,但是能够在远程运行调试web页面。所以如果你使用过火狐开发者工具或Chrome的调试工具,那么上手Weinre就会非常容易,非常自然。</p> - -<h2 id="安装_Weinre">安装 Weinre</h2> - -<p>因为 Weinre 运行在 Node.js 的基础上, your first port of call would be to <a href="http://nodejs.org/">安装 Node.js</a>. Node.js comes with NPM (Node Package Manager) bundled nowadays and this is what we are going to use to install Weinre. From a terminal run the following:</p> - -<pre style="font-family: monospace;" class="bash">npm <span style="color: #660033;">-g</span> <strong style="color: #c20cb9; font-weight: bold;">install</strong> weinre</pre> - -<blockquote> -<p>NOTE: The <code>-g</code> flag is used to install Weinre as a <a href="https://npmjs.org/doc/global.html">global Node.js module</a> for command line goodness but, on Linux and Mac, this means you most likely are going to need to run the above by prepending <code>sudo</code> to the above command.</p> -</blockquote> - -<p>Once the installation process is complete, we are ready to use Weinre to debug.</p> - -<h2 id="启动_Weinre_服务">启动 Weinre 服务</h2> - -<p>On the terminal enter the following line to start up the Weinre server:</p> - -<pre style="font-family: monospace;" class="bash">$ weinre <span style="color: #660033;">--boundHost</span> 127.0.0.1 <span style="color: #660033;">--httpPort</span> <span style="color: #000000;">9090</span></pre> - -<p><span style="color: #000000;">The two parameters passed here are the host to bind to and the port the server should listen on. Once the server has started the terminal should display a line similar to the following:</span></p> - -<pre style="font-family: monospace;" class="bash"><span style="color: #000000;">2013</span>-01-28T10:<span style="color: #000000;">42</span>:40.498Z weinre: starting server at http:<strong style="color: #000000; font-weight: bold;">//</strong>127.0.0.1:<span style="color: #000000;">9090</span></pre> - -<p>With that, fire up a browser (<em>NOTE: The UI for Weinre is built specifically for Webkit based browsers so, while it might work to some degree in other browsers, I would suggest you use Chrome</em>) and point it to <a href="http://127.0.0.1:9090">http://127.0.0.1:9090</a>. Once the landing page loads, click on the link to the debug client user interface. From this portion of the UI you can see connected clients, initially one which is the current instance of the web inspector, some general properties of our server, and your targets.</p> - -<h2 id="设置_Weinre_目标页面">设置 Weinre 目标页面</h2> - -<p>In Weinre targets are the web pages or apps that you want to debug, and in order for the target to be able to connect, you need to add a one liner to the relevant file of your app. For example, if you wanted to use Weinre to debug the Calendar app in Gaia you would open gaia -> apps -> calendar -> index.html and right before the clong body tag, add the following:</p> - -<pre style="font-family: monospace;" class="xml"><span style="color: #009900;"><strong style="color: #000000; font-weight: bold;"><script</strong> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"http://127.0.0.1:9090/target/target-script-min.js#anonymous"</span><strong style="color: #000000; font-weight: bold;">></strong><strong style="color: #000000; font-weight: bold;"></script<strong style="color: #000000; font-weight: bold;">></strong></strong></span></pre> - -<p>Normally that would be all you need to do to set up your target, but for FirefoxOS there is one more step. Gaia uses a <a href="http://www.w3.org/TR/CSP/#introduction">Content Security Policy</a> and as part of that, scripts are said to only be allowed to load if from the same origin as the application. So, if we were to try and load the Calendar now, the script from above would be blocked as it is not being loaded from the specified origin.</p> - -<p>To overcome this, we need to temporarily disable CSP. To do this, open up gaia -> build -> preferences.js and add the following line, around line 24:</p> - -<pre style="font-family: monospace;" class="javascript">prefs.<span style="color: #660066;">push</span><span style="color: #009900;">(</span><span style="color: #009900;">[</span><span style="color: #3366CC;">"security.csp.enable"</span><span style="color: #339933;">,</span> <strong style="color: #003366; font-weight: bold;">false</strong><span style="color: #009900;">]</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre> - -<h2 id="使用_Weinre_和_B2G_Desktop_进行调试">使用 Weinre 和 B2G Desktop 进行调试</h2> - -<p>The first step we need before launching the desktop is to build our Gaia profile:</p> - -<pre style="font-family: monospace;" class="bash"><span style="color: #007800;">DEBUG</span>=<span style="color: #000000;">1</span> <strong style="color: #c20cb9; font-weight: bold;">make</strong></pre> - -<p>Once the profile is built, launch B2G desktop:</p> - -<div class="wp_syntax"> -<pre style="font-family: monospace;" class="bash"><strong style="color: #000000; font-weight: bold;">/</strong>Applications<strong style="color: #000000; font-weight: bold;">/</strong>B2G.app<strong style="color: #000000; font-weight: bold;">/</strong>Contents<strong style="color: #000000; font-weight: bold;">/</strong>MacOS<strong style="color: #000000; font-weight: bold;">/</strong>b2g-bin <span style="color: #660033;">-profile</span> <strong style="color: #000000; font-weight: bold;">/</strong>Users<strong style="color: #000000; font-weight: bold;">/</strong>username<strong style="color: #000000; font-weight: bold;">/</strong>mozilla<strong style="color: #000000; font-weight: bold;">/</strong>projects<strong style="color: #000000; font-weight: bold;">/</strong>gaia<strong style="color: #000000; font-weight: bold;">/</strong>profile</pre> -</div> - -<p>Once B2G launches, unlock the screen and navigate to the Calendar app. Tap the app icon and keep an eye on the Weinre debug client UI. Once the app has launched you should see a target being added. Next we want to start inspecting our code, so click on the 'Elements' tab to open up the HTML and CSS inspector. You can go right ahead and edit either the HTML or the CSS as you normally would and see the changes reflected live. Note that even though the CSS looks grayed out and disabled, it is fully editable. You can also add completely new styles to the current element using the empty element.style block or amending existing rules. You will also notice you have access to the computed styles as well as metrics of the current element.</p> - -<h2 id="使用控制台工作">使用控制台工作</h2> - -<p>The next tab of interest to us is the Console tab. Here you can code away and run any JavaScript you want directly against the current app or execute code exposed by the app. In order to demonstrate the console, we will target the Call Log portion of the dialer and interact with the records stored there. First step then is to move your script src to the Dialer which is located at gaia -> apps – > communication -> dialer -> index.html.</p> - -<p>After it is added, build your profile, launch B2G, and then launch the Dialer. With the Dialer open, click on the call log icon, bottom left. Currently the call log is already populated with some dummy data, but let’s create our own. Click over to the Console tab in Weinre, type the following, and press enter.</p> - -<pre style="font-family: monospace;" class="javascript">RecentsDBManager.<span style="color: #660066;">deleteAll</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre> - -<p>To see that our code was executed and worked, we need to refresh the call log:</p> - -<pre style="font-family: monospace;" class="javascript">Recents.<span style="color: #660066;">refresh</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre> - -<p>As you can see, our call log is empty. Next step then is to add an entry back. To do this, we will create a dummy call entry Object and then pass this to the add function of the RecentsDBManager to store it:</p> - -<pre style="font-family: monospace;" class="javascript"><em>// Dummy entry</em> -<strong style="color: #000066; font-weight: bold;">var</strong> recentCall <span style="color: #339933;">=</span> <span style="color: #009900;">{</span> - type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'incoming-refused'</span><span style="color: #339933;">,</span> - number<span style="color: #339933;">:</span> <span style="color: #3366CC;">'555-6677'</span><span style="color: #339933;">,</span> - date<span style="color: #339933;">:</span> <strong style="color: #000066; font-weight: bold;">new</strong> <span>Date</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span> -<span style="color: #009900;">}</span><span style="color: #339933;">;</span> -RecentsDBManager.<span style="color: #660066;">add</span><span style="color: #009900;">(</span>recentCall<span style="color: #009900;">)</span><span style="color: #339933;">;</span> -Recents.<span style="color: #660066;">refresh</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre> - -<p>And as you can see now, the entry we just created has been added to storage, <a href="https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB">IndexedDB</a> to be exact, and is visible in the call log view. As you might very well have noticed, another of the great features that comes with the console is auto-complete which will further speed up development.</p> - -<h2 id="在移动设备上调试">在移动设备上调试</h2> - -<p>The above has focused on using Weinre and B2G desktop, but the process to use Weinre to inspect and debug your code running on a device is exactly the same except for the IP address you will be using. When you want to debug on the device you first need to know the IP address of your host computer. Then you need to start up Weinre using this IP as the boundHost and also as the IP when including the script into your target documents.</p> - -<blockquote> -<p>On Mac and Linux you can get this address using <code>ifconfig</code> and on Windows it is <code>ipconfig</code>.</p> -</blockquote> - -<p>Once you have the new IP, just stop the current instance of Weinre and then do the following:</p> - -<pre style="font-family: monospace;" class="bash">weinre <span style="color: #660033;">--boundHost</span> 192.168.1.1 <span style="color: #660033;">--httpPort</span> <span style="color: #000000;">9090</span></pre> - -<p>Then inside your target document add:</p> - -<pre style="font-family: monospace;" class="bash"><strong style="color: #000000; font-weight: bold;"><</strong>script <span style="color: #007800;">src</span>=<span style="color: #ff0000;">"http://192.168.1.1:9090/target/target-script-min.js#anonymous"</span><strong style="color: #000000; font-weight: bold;">></</strong>script<strong style="color: #000000; font-weight: bold;">></strong></pre> - -<p>Make and push your Gaia profile to the device using:</p> - -<pre style="font-family: monospace;" class="bash"><strong style="color: #c20cb9; font-weight: bold;">make</strong> install-gaia</pre> - -<p>Launch your target app and you are in business!</p> diff --git a/files/zh-cn/archive/b2g_os/platform/gonk/index.html b/files/zh-cn/archive/b2g_os/platform/gonk/index.html deleted file mode 100644 index 63d02ef70a..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/gonk/index.html +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: Gonk -slug: Archive/B2G_OS/Platform/Gonk -translation_of: Archive/B2G_OS/Platform/Gonk ---- -<div class="summary"> -<p>Gonk 是 <a href="../../../../en-US/docs/Mozilla/Firefox_OS" title="/en-US/docs/Mozilla/Firefox_OS">Firefox OS</a> 平台底层的操作系统, 包括基于 <a class="external external-icon" href="http://source.android.com/">Android Open Source Project</a> (AOSP) 的 Linux Kernel 和用户空间硬件抽象层 (HAL) 。本文旨在介绍Gonk的组成;要获取更多有关 Firefox OS 架构和 Gonk 如何在其中适配的知识,请参考 <a href="../../../../en-US/Firefox_OS/Platform/Architecture">Firefox OS architecture</a> 指南。</p> -</div> - -<h2 id="Gonk_overview">Gonk overview</h2> - -<p>Gonk 在 Firefox OS stack 中可看作是 kernel 层级的组件,在 Gecko 和 底层硬件中间充当接口的作用。Gonk 对底层的硬件进行控制,并且将硬件信息及操控接口暴露给 Gecko中的 Web APIs。Gonk 可以看作是一个 黑盒, 在屏幕后面做了所有复杂细节的工作用于在硬件层级上对 mobile device 进行控制。</p> - -<p>Gonk 只是一个简单的 Linux 发行版本,其中包括了 Android 的一些组件(如 GPS 和 Camera)以及由 Mozilla 扩展的常用的开源工程,如 libusb, bluez, 进而将所有的层级集成到 Firefox OS 架构中。这种设计方式对 OEM 将软件组件从其他 Android 实现上移植过来是非常方便的。</p> - -<p>Gonk 是一个设备接口层,可看作是 硬件和 Gecko 之间的适配器。 Gonk is a relatively simple Linux distribution that can be treated as a Gecko Port paired with Gecko porting layers — so Gonk is a <strong>porting target</strong> of <a href="https://developer.mozilla.org/en-US/docs/Gecko">Gecko</a>, just like there's a port of Gecko to OS X, Windows, and Android.</p> - -<div class="note"> -<p><strong>Note</strong>: Since different mobile devices may have different chipsets and other hardware specs, devices may contain different Gonk distributions.</p> -</div> - -<p>由于 Firefox OS 工程对 Gonk 的完整控制,我们可以向 Gecko 中暴露一些在其他操作系统中无法实现的接口。例如, Gecko 已经可以直接对 full telephone stack 直接进行发给男问,并在 Gonk 中显示出 frame buffer。</p> - -<h2 id="Gonk_架构">Gonk 架构</h2> - -<p>Each mobile phone model has a specialized combination of Gonk components based on the system libraries, device drivers, and firmware required to operate the device. These components are determined by the OEM in collaboration with chipset manufacturers and ODMs. The following figure shows an example Gonk implementation:</p> - -<p><img alt="" src="https://mdn.mozillademos.org/files/9489/gonk-architecture.png" style="width: 987px; height: 329px; margin: 0px auto; display: block;"></p> - -<p>This example shows the following main components (which represent only a subset of the possible components in any given Gonk implementation):</p> - -<ul> - <li><strong>Linux Kernel</strong>: Uses libraries from Android (GPS, camera, etc.) and other open source projects (Linux, libusb, bluez, and so on).</li> - <li><strong>Radio Interface Layer (RIL)</strong>: Interacts with the modem hardware (telephony) in the phone. Consists of two components: - <ul> - <li><strong>rild daemon</strong>: Talks to the modem firmware.</li> - <li><strong>rilProxy</strong>: Proxies messages between rild and the b2g process</li> - </ul> - </li> - <li><strong>mediaserver process</strong>: 控制 audio 和 video 的播放。Gecko 与 media server 通过 Android RPC 机制进行通信。</li> - <li><strong>netd process</strong>: 与 network 接口 (Wifi) 硬件直接交互的 Network dameon</li> - <li><strong>Bluetooth, etc.</strong>: Bluetooth and other service-level daemons provide access to hardware capabilities.</li> -</ul> - -<p>Gonk 也会启动,管理以及关闭 b2g process, b2g process 属于 Firefox OS 的 Gecko 层。The b2g process acts as a client to service-level daemons in Gonk that interact directly with the hardware and expose to Gecko the underlying hardware functionality of the phone. Gecko talks with these daemons via inter-process communication (IPC). These components collaboratively exchange commands and protocols to request and provide services.</p> - -<div class="note"> -<p><strong>Note</strong>: For more information on Gonk architecture, see the <a href="https://developer.mozilla.org/en-US/Firefox_OS/Platform/Architecture">Firefox OS architecture guide</a>.</p> -</div> - -<h2 id="Porting_Gonk">Porting Gonk</h2> - -<p>Because Firefox OS is based on the Android kernel, existing device drivers, firmware, service daemons, and other components can be ported to work with Firefox OS, usually with minimal effort. If a custom component (for example, a custom RIL or new daemon) is needed, or if a modification must be made to an ODM’s reference design, then additional integration and testing effort might be required.</p> - -<p>In b2g, clients communicate with service-level daemons via inter-process communication (IPC). The client initiates a socket connection to the service-level daemon, submits the request (using the server’s request protocol) over that connection, receives the response, and closes the connection. OEMs are responsible for designing and implementing this inter-process communication between clients and servers.</p> - -<div class="note"> -<p><strong>Note</strong>: For more information about how the porting process works, see <a href="https://developer.mozilla.org/en-US/Firefox_OS/Developing_Firefox_OS/Porting">Porting Firefox OS</a>.</p> -</div> - -<h3 id="How_Mozilla_works_on_Gonk_ports_with_OEMs_and_phone_manufacturers">How Mozilla works on Gonk ports with OEMs and phone manufacturers</h3> - -<p>Every Gonk implementation is the result of collaboration among Mozilla, OEMs, and associated manufacturers (ODMs, chipset manufacturers).</p> - -<p>Mozilla provides source repositories and support files for Gonk in its Firefox OS distributions. The source repositories include the base Linux kernel (with only slight changes) and hooks into Gecko.</p> - -<p>OEMs are responsible for building, compiling, testing, certifying, and distributing the Firefox OS system image for a given device model. For the Gonk portion of the system image, OEMs are responsible for the bulk of the effort in order to ensure the seamless integration between Web API calls and phone hardware functionality. The type and scope of effort required is highly dependent on the specific chipsets and other hardware components used on the phone.</p> - -<h3 id="Device_components">Device components</h3> - -<p>OEMs collaborate with chipset manufacturers and ODMs to provide all of the device-specific components that are needed to run the mobile device. For example, a manufacturer of the Wi-Fi components would provide the chipset and affiliated software. Components might include:</p> - -<ul> - <li>Drivers — For supported phone functionality, such as modem (data and voice), Wi-fi, Bluetooth, display, camera, audio, and so on.</li> - <li>Firmware — Some hardware (the network interface card, for example) might load firmware off the flash drive.</li> - <li>Service-level daemons — For invoking and managing the operation of various hardware components. This can include support libraries and startup scripts.</li> -</ul> - -<h3 id="Integration_between_Gonk_and_Gecko">Integration between Gonk and Gecko</h3> - -<p>OEMs must ensure that hardware capabilities in the mobile device are correctly and completely exposed to the Web APIs implemented in Gecko. This involves:</p> - -<ul> - <li>building or adapting (in Gonk) service-level daemons, along with any associated drivers or firmware, to manage the hardware functionality</li> - <li>setting up (in b2g) all the methods needed to communicate with the service-level daemons</li> -</ul> - -<h2 id="Gonk_源代码">Gonk 源代码</h2> - -<p>The main <a href="https://github.com/mozilla-b2g/B2G">B2G repo on Github</a> contains officially supported Gonk ports for a variety of devices, so you can treat it as Gonk’s repository. The list of supported devices is available in <code>B2G/config.sh</code>.</p> - -<p>The b2g process (along with other things), defined in Gonk, can be found at <a href="https://github.com/mozilla-b2g/gonk-misc">mozilla-b2g/gonk-misc</a>. Modifications to b2g source code are made here.</p> - -<div class="note"> -<p><strong>Note</strong>: In the <a href="https://github.com/mozilla/gecko-dev">Gecko source</a> there’s a <code>b2g/</code> folder that contains the Gonk Port of Gecko: this consists of a Linux kernel, HAL, and other OEM-specific libraries.</p> -</div> - -<p>Gonk 层每天的工作主要集中在 porting system 到不同的板子上,并且确保 Gecko 在不同的设备上能够正常工作。</p> diff --git a/files/zh-cn/archive/b2g_os/platform/index.html b/files/zh-cn/archive/b2g_os/platform/index.html deleted file mode 100644 index 3f256549c6..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/index.html +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: Firefox OS 平台 -slug: Archive/B2G_OS/Platform -tags: - - B2G - - Firefox OS - - NeedsTranslation - - TopicStub -translation_of: Archive/B2G_OS/Platform ---- -<p>FireFox OS 平台包括很多组件。为了构建能够在FF OS中运行的应用,你不需要理解系统内部架构,如果你将要在该平台构建应用程序或者只是简单的好奇,你可能对以下文档感兴趣。</p> - -<table class="topicpage-table"> - <tbody> - <tr> - <td> - <h2 class="Documentation" id="Documentation" name="Documentation">关于Firefox OS 平台的文件</h2> - - <dl> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Introduction" title="en-US/docs/Mozilla/Firefox_OS/Introduction">介绍 Firefox OS</a></dt> - <dd>关于 OS 如何运作</dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Building_and_installing_Firefox_OS" title="en-US/docs/Mozilla/Firefox_OS/Building and installing Boot to Gecko">搭建安装 Firefox OS</a></dt> - <dd>Firefox OS 安装指南。也是在Pc搭建Firefox OS虚拟机指南</dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Gaia" title="/en-US/docs/Mozilla/Gaia">Gaia</a></dt> - <dd>FireFox OS 顶层文档</dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Gonk" title="/en-US/docs/Mozilla/Firefox_OS/Gonk">Gonk</a></dt> - <dd>关于Gonk的文档, Gonk比Gaia在操作系统中更加底层, 由Linux内核和Gecko调用的硬件抽象层组成. </dd> - <dt><a href="/en-US/docs/Gecko" title="/en-US/docs/Gecko">Gecko</a></dt> - <dd>Gecko在Firefox OS为提供标准的开放web标准实现, 像被Firefox和Thunderbird等等许多其他的应用运用着. </dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Platform/Feature_support_chart">图表支持特性</a> </dt> - <dd>用一张图表就可以把所有Firefox OS编译的类型哪些可用的展现出来. </dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Architecture">Firefox OS 架构概述</a></dt> - <dd>对Firefox OS 架构的概述. </dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Testing_Firefox_OS">Firefox OS 测试</a></dt> - <dd>一个Firefox OS的测试指南, 包含如何创建自动化测试. </dd> - <dt><a href="/en-US/docs/Mozilla/Firefox_OS/Porting">Firefox OS 端口设置</a></dt> - <dd>关于Firefox OS在新设备中的端口设置. </dd> - <dt><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Customization_with_the_.userconfig_file">.userconfig 文件的配置</a></dt> - <dd>如何配置Firefox OS的编译和执行通过修改.userconfig文件. </dd> - </dl> - - <p><span class="alllinks"><a href="/en-US/docs/tag/B2G" title="/en-US/docs/tag/B2G">View All...</a></span></p> - </td> - <td> - <h2 class="Community" id="Community" name="Community">从社区获得帮助</h2> - - <p>以下资源助你开发火狐应用</p> - - <ul> - <li>Consult the Boot to Gecko project forum: <ul> - <li><a href="https://lists.mozilla.org/listinfo/dev-b2g"> 邮件列表</a></li> - - - <li><a href="http://groups.google.com/group/mozilla.dev.b2g"> 新闻组</a></li> - <li><a href="http://groups.google.com/group/mozilla.dev.b2g/feeds"> Web feed</a></li> -</ul></li> - </ul> - - <ul> - <li>Ask your question on Mozilla's Boot to Gecko IRC channel: <a class="link-irc" href="irc://irc.mozilla.org/b2g" title="irc://irc.mozilla.org/b2g">#b2g</a></li> - </ul> - - <p><span class="alllinks"><a class="external" href="http://www.catb.org/~esr/faqs/smart-questions.html" title="http://www.catb.org/~esr/faqs/smart-questions.html">Don't forget about the <em>netiquette</em>...</a></span></p> - - - <h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">相关要点</h2> - - <ul> - <li><a href="/en-US/docs/Mobile" title="en-US/docs/Mobile">Mobile</a> </li> - <li><a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a></li> - <li><a href="/en-US/docs/CSS" title="en-US/docs/CSS">CSS</a></li> - <li><a href="/en-US/docs/JavaScript" title="en-US/docs/JavaScript">JavaScript</a></li> - </ul> - - <h2 class="Tools" id="Resources">Resources</h2> - - <ul> - <li><a class="link-https" href="https://wiki.mozilla.org/B2G/FAQ" title="B2G/FAQ">Mozilla wiki FAQ</a></li> - <li><a class="link-https" href="https://wiki.mozilla.org/B2G/Schedule_Roadmap" title="https://wiki.mozilla.org/B2G/Schedule_Roadmap">Roadmap</a></li> - <li><a href="/en-US/docs/Mozilla/Firefox_OS/Feature_support_chart" title="/en-US/docs/Mozilla/Firefox_OS/Feature_support_chart">Feature support chart</a></li> - </ul> - </td> - </tr> - </tbody> -</table> - -<p> </p> diff --git a/files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html b/files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html deleted file mode 100644 index eda111fbc8..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: Firefox OS 中的内存溢出管理 -slug: Archive/B2G_OS/Platform/Out_of_memory_management_on_Firefox_OS -tags: - - B2G - - Firefox OS - - Gaia - - LMK - - OOM - - Out of memory - - oom_adj - - 低内存管理器 - - 低内存通知器 -translation_of: Archive/B2G_OS/Platform/Out_of_memory_management_on_Firefox_OS ---- -<div class="summary"> -<p><span class="seoSummary">Firefox OS 运行在一些严重内存受限的设备上时,</span>就会很容易出现app在运行时将内存耗尽的情况。当一个进程将系统上可用的内存耗尽时, 为了能够释放内存,kernel 层必须要 kill 掉其他的进程。本文则描述了低内存 killer和 低内存通知器是如何工作的 。</p> -</div> - -<p>FxOS 的操作会涉及到多进程问题—一个“主进程”运行基本的系统服务和潜在众多的“子进程”。FxOS 环境下应用很少会由用户主动关闭,因此当新的 app需要空间或已存在的 app需要额外的内存时, system会自动对应用程序的生命周期进行管理。</p> - -<p>有两个子系统负责这方面的管理: 低内存管理器 <strong>Low memory killer (LMK)</strong> 和低内存通知器<strong>Low memory notifications</strong>.</p> - -<h2 id="低内存管理器_Low_memory_killer">低内存管理器 Low memory killer</h2> - -<p><a href="https://android.googlesource.com/kernel/common.git/+/edd540ea92954f896bfb7ee0ebf5dfdde6e6cb41/drivers/staging/android/lowmemorykiller.txt"> LMK</a> 是 Android 内核的子系统,当有获取内存空间的需求时,能够自动的对进程进行查杀。为了能够选择出哪一个进程需要第一个查杀,每个进程都要通过 <a href="https://www.kernel.org/doc/Documentation/filesystems/proc.txt">/proc/<pid>/oom_adj or /proc/<pid>/oom_score_adj files</a> 来设定一个优先级。 每个进程的优先级也可称为调整分数或 <code>oom_adj</code>. <code>oom_adj</code> ,值越小则表示器进程优先级越高。</p> - -<p>一般来说,进程的调整得分越高,越可能被查杀。 LMK 提供了多个等级,每一个都与一定程度的闲置内存和最小调整分数对应。当闲置内存的数量低于某个特定等级时,所有高于该等级指定的最小调整分数的进程都具有被查杀的可能。LMK会开始查杀这些进程,分数高的会被先杀掉,直到闲置内存再次高于临界值为止。</p> - -<p><strong>Note</strong>: When a background app is killed by the LMK, it is made available in the task manager/through edge swipes as a "zombie app": next time you browse to that app, it will be revived. The maximum number of apps that can be kept in this state is currently 10.</p> - -<div class="note"> -<p><b>注意</b>: 当设备存储器不足(oom) 时杀掉的进程并不一定是导致存储器不足(oom)的原因。</p> -</div> - -<h3 id="进程优先级">进程优先级</h3> - -<p>Firefox OS 中的 app 是以下面的优先级次序策略来管理的,这种策略是根据每个应用的优先级等级和这些等级相关的 OOM 调整分数 (<a style="text-decoration: underline;" href="http://hg.mozilla.org/mozilla-central/file/545c35907eff/b2g/app/b2g.js#l661">the current values are set in prefs</a>)而制定的: </p> - -<ol> - <li>后台应用会首先被干掉,先从使用最少的应用开始</li> - <li>之后会干掉 homescreen 应用程序</li> - <li>可由用户感知的后台应用会被干掉 (例如, 在后台播放音频的音乐播放器或者持有 <code>high-priority</code> 或 <code>cpu</code> wakelock,并且注册系统消息的处理程序)</li> - <li>如果 keyboard 应用正在运行,会被干掉</li> - <li>前台应用被干掉</li> - <li>最后,已请求 <code>high-priority</code> 或 <code>cpu</code> wakelocks 的前台应用会最后被干掉</li> -</ol> - -<div class="note"> -<p><b>注意</b>: 当子进程在前台时,会以 <span style="font-family: 'Courier New', 'Andale Mono', monospace;">oom_adj 2 </span>运行。后台的子进程运行时,其 <code>oom_adj</code> 会在 <code>3</code> 和 <code>6</code> (包括6) 之间。后台运行的子进程 <code>oom_adj</code> 数值要取决于许多因素,如是否播放音乐,是否是homescreen 等。</p> -</div> - -<p>也有两个例外的情况:</p> - -<ul> - <li>主进程是不会被 LMK 干掉的,否则就会干掉所有的子进程并且重启操作系统。主进程运行时 <code>oom_adj 0</code>.</li> - <li>我们会保持一个名为 <strong>preallocated process 的进程</strong>以加速新应用的启动<strong>。</strong>这个进程通常需要一直存在,因为它消耗很有限的内存,而且能够明显提高应用程序的启动速度。它只在一种情况下被干掉,就是主线程需要内存保持运行,杀掉其他进程后, 内存空间还不够时。</li> -</ul> - -<h2 id="低内存通知器_Low_memory_notifications">低内存通知器 Low memory notifications</h2> - -<p>释放内存的第二种机制就是低内存通知器。 LMK 提供一个<a href="https://www.codeaurora.org/cgit/quic/la//kernel/msm/commit/?id=b3f986cba580b14438b77b42070ebbc77b69d4c4">特定的门限值</a>,当超出该值时,会通知用户当前系统已运行在低内存状态。system 应用和常规的用户应用都会持续的等待这个条件,并通过 observer service 发送一个 <code style="font-style: normal;">memory-pressure</code> 方法来响应它。 这个事件只对 C++ 和 chrome JS 代码可见,并非由应用直接发送。通过Gecko 代码库,我们使用该事件可以释放尽可能多的内存— 一般会通过清除内部缓存(图片,DNS,数据库等),丢弃可重新创建的资源(例如, WebGL contexts)以及运行垃圾回收器,生命周期回收器等方式实现。</p> - -<p>当低内存情况发生时, 触发的第一个 <code>memory-pressure</code> 事件会有一个<code> low-memory </code>负载。 如果在预订时间(5s) 后, 还处在低内存状态, 会触发另一个 <code>memory-pressure</code> 事件,但此次负载值变为 <code>low-memory-onging</code> 。当一直处在低内存条件下,并且要清除缓存以及做其他简单的内存削减时,该负载会被使用,但应当知道一些繁重的工作,如 GC , 是不能成功的。(此段翻译可能不是太贴切,要深入理解,还请参考英文原文)</p> - -<h2 id="LMK_和低内存通知器是如何配合工作的"> LMK 和低内存通知器是如何配合工作的</h2> - -<p>当前<a href="http://hg.mozilla.org/mozilla-central/file/545c35907eff/b2g/app/b2g.js#l722">低内存限值设定在后台进程 LMK 等级和 homescreen 之间。</a> 因此当设备在低内存状态下运行时, LMK 和 低内存通知器联合作出的反应如下:</p> - -<ol> - <li>以最不经常使用的次序 kill 掉 后台 app</li> - <li>如果我们没有释放足够的内存, 向所有现存的应用发送 <code>memory-pressure</code> 事件</li> - <li>如果低内存情况还在,每个 5 秒重发一次 <code>memory-pressure</code> 事件,但将它们标记为 ongoing , 使 GC/CC 不会对它们动作。</li> - <li>Kill 掉 homescreen.</li> - <li>Kill 掉可感知的或高优先级的后台应用</li> - <li>如果 keyboard app 正在运行,Kill 掉</li> - <li>Kill 掉前台应用</li> - <li>Kill 掉高优先级的前台应用</li> - <li>Kill 掉 preallocated process</li> -</ol> diff --git a/files/zh-cn/archive/b2g_os/platform/settings_list/index.html b/files/zh-cn/archive/b2g_os/platform/settings_list/index.html deleted file mode 100644 index fc834dc10f..0000000000 --- a/files/zh-cn/archive/b2g_os/platform/settings_list/index.html +++ /dev/null @@ -1,716 +0,0 @@ ---- -title: Firefox OS 设置选项列表 -slug: Archive/B2G_OS/Platform/Settings_list -tags: - - API - - B2G - - Firefox OS - - Settings - - WebAPI - - 参考 -translation_of: Archive/B2G_OS/Platform/Settings_list ---- -<div class="summary"> - <p><span class="seoSummary">Firefox OS 提供了许多设置项,用于配置设备以及内嵌的功能。这些设置项可以由 </span>certified apps 通过使用 <a style="text-decoration: underline;" href="/en-US/docs/WebAPI/Settings" title="/en-US/docs/WebAPI/Settings">Settings API</a> 来访问。</p> -</div> -<div class="note"> - <p><strong>注意:</strong> 由于不同的 Firefox OS 发行版本及设备提供的功能会有所不同,这个列表可能并不会精确的对每个设备进行匹配。</p> -</div> -<table class="standard-table"> - <thead> - <tr> - <th scope="col">设置项名称</th> - <th scope="col">类型</th> - <th scope="col">默认值</th> - </tr> - </thead> - <tbody> - <tr> - <td><code>accessibility.invert</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>accessibility.screenreader</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>alarm.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>app.reportCrashes</code></td> - <td>String</td> - <td><code>ask</code></td> - </tr> - <tr> - <td><code>app.update.interval</code></td> - <td>Number</td> - <td>86400</td> - </tr> - <tr> - <td><code>audio.volume.alarm</code></td> - <td>Number</td> - <td>15</td> - </tr> - <tr> - <td><code>audio.volume.bt_sco</code></td> - <td>Number</td> - <td>15</td> - </tr> - <tr> - <td><code>audio.volume.dtmf</code></td> - <td>Number</td> - <td>15</td> - </tr> - <tr> - <td><code>audio.volume.content</code></td> - <td>Number</td> - <td>15</td> - </tr> - <tr> - <td><code>audio.volume.notification</code></td> - <td>Number</td> - <td>15</td> - </tr> - <tr> - <td><code>audio.volume.tts</code></td> - <td>Number</td> - <td>15</td> - </tr> - <tr> - <td><code>audio.volume.telephony</code></td> - <td>Number</td> - <td>5</td> - </tr> - <tr> - <td><code>bluetooth.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>bluetooth.debugging.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>camera.shutter.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>clear.remote-windows.data</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.grid.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.oop.disabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.fps.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.ttl.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.log-animations.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.paint-flashing.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>debug.peformancedata.shared</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>deviceinfo.firmware_revision</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>deviceinfo.hardware</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>deviceinfo.os</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>deviceinfo.platform_build_id</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>deviceinfo.platform_version</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>deviceinfo.software</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>deviceinfo.update_channel</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>gaia.system.checkForUpdates</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>general.useragent.updates.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>geolocation.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.english</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.dvorak</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.otherlatins</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.cyrillic</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.arabic</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.hebrew</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.zhuyin</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.pinyin</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.greek</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.japanese</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.polish</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.portuguese</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.layouts.spanish</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.vibration</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.clicksound</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>keyboard.autocorrect</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>keyboard.wordsuggestion</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>keyboard.current</code></td> - <td>String</td> - <td><code>en</code></td> - </tr> - <tr> - <td><code>language.current</code></td> - <td>String</td> - <td><code>en-US</code></td> - </tr> - <tr> - <td><code>lockscreen.passcode-lock.code</code></td> - <td>String</td> - <td><code>0000</code></td> - </tr> - <tr> - <td><code>lockscreen.passcode-lock.timeout</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>lockscreen.passcode-lock.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>lockscreen.notifications-preview.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>lockscreen.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>lockscreen.locked</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>lockscreen.unlock-sound.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>mail.sent-sound.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>message.sent-sound.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>operatorvariant.mcc</code></td> - <td>String</td> - <td><code>0</code></td> - </tr> - <tr> - <td><code>operatorvariant.mnc</code></td> - <td>String</td> - <td><code>0</code></td> - </tr> - <tr> - <td><code>ril.iccInfo.mbdn</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.sms.strict7BitEncoding.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.cellbroadcast.searchlist</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>debug.console.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>phone.ring.keypad</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>powersave.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>powersave.threshold</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>privacy.donottrackheader.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.callwaiting.enabled</code></td> - <td> </td> - <td> </td> - </tr> - <tr> - <td><code>ril.cf.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.data.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.data.apn</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.data.carrier</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.data.defaultServiceId</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>ril.data.passwd</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.data.httpProxyHost</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.data.httpProxyPort</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>ril.data.mmsc</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.data.mmsproxy</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.data.mmsport</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>ril.data.roaming_enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.data.user</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.apn</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.carrier</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.httpProxyHost</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.httpProxyPort</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.mmsc</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.mmsport</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.mmsproxy</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.passwd</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.mms.user</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.radio.preferredNetworkType</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.radio.disabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.supl.apn</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.supl.carrier</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.supl.httpProxyHost</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.supl.httpProxyPort</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.supl.passwd</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.supl.user</code></td> - <td>String</td> - <td> </td> - </tr> - <tr> - <td><code>ril.sms.strict7BitEncoding.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ril.sms.</code>defaultServiceId</td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>ril.telephony.</code>defaultServiceId</td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>ring.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>screen.automatic-brightness</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>screen.brightness</code></td> - <td>Number</td> - <td>1</td> - </tr> - <tr> - <td><code>screen.timeout</code></td> - <td>Number</td> - <td>60</td> - </tr> - <tr> - <td><code>tethering.usb.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>tethering.usb.ip</code></td> - <td>String</td> - <td><code>192.168.0.1</code></td> - </tr> - <tr> - <td><code>tethering.usb.prefix</code></td> - <td>String</td> - <td><code>24</code></td> - </tr> - <tr> - <td><code>tethering.usb.dhcpserver.startip</code></td> - <td>String</td> - <td><code>192.168.0.10</code></td> - </tr> - <tr> - <td><code>tethering.usb.dhcpserver.endip</code></td> - <td>String</td> - <td><code>192.168.0.30</code></td> - </tr> - <tr> - <td><code>tethering.wifi.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>tethering.wifi.ip</code></td> - <td>String</td> - <td><code>192.168.1.1</code></td> - </tr> - <tr> - <td><code>tethering.wifi.prefix</code></td> - <td>String</td> - <td><code>24</code></td> - </tr> - <tr> - <td><code>tethering.wifi.dhcpserver.startip</code></td> - <td>String</td> - <td><code>192.168.1.10</code></td> - </tr> - <tr> - <td><code>tethering.wifi.dhcpserver.endip</code></td> - <td>String</td> - <td><code>192.168.1.30</code></td> - </tr> - <tr> - <td><code>tethering.wifi.ssid</code></td> - <td>String</td> - <td><code>FirefoxHotspot</code></td> - </tr> - <tr> - <td><code>tethering.wifi.security.type</code></td> - <td>String</td> - <td><code>open</code></td> - </tr> - <tr> - <td><code>tethering.wifi.security.password</code></td> - <td>String</td> - <td><code>1234567890</code></td> - </tr> - <tr> - <td><code>tethering.wifi.connectedClients</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>tethering.usb.connectedClients</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>time.nitz.automatic-update.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>time.timezone</code></td> - <td> </td> - <td> </td> - </tr> - <tr> - <td><code>ums.enabled</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>ums.mode</code></td> - <td>Number</td> - <td>0</td> - </tr> - <tr> - <td><code>vibration.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>wifi.enabled</code></td> - <td>Boolean</td> - <td><code>true</code></td> - </tr> - <tr> - <td><code>wifi.screen_off_timeout</code></td> - <td>Number</td> - <td>600000</td> - </tr> - <tr> - <td><code>wifi.disabled_by_wakelock</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>wifi.notification</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>wifi.connect_via_settings</code></td> - <td>Boolean</td> - <td><code>false</code></td> - </tr> - <tr> - <td><code>icc.displayTextTimeout</code></td> - <td>Number</td> - <td>40000</td> - </tr> - <tr> - <td><code>icc.inputTextTimeout</code></td> - <td>Number</td> - <td>40000</td> - </tr> - </tbody> -</table> -<h2 id="参考">参考</h2> -<ul> - <li><a href="/en-US/docs/WebAPI/Settings" title="/en-US/docs/WebAPI/Settings">Settings API</a></li> - <li><a href="/zh-CN/docs/Web/API/SettingsManager" title="此页面仍未被本地化, 期待您的翻译!"><code>SettingsManager</code></a></li> - <li><a href="/zh-CN/docs/Web/API/Window/navigator/mozSettings" title="此页面仍未被本地化, 期待您的翻译!"><code>navigator.mozSettings</code></a></li> - <li><a href="https://github.com/mozilla-b2g/gaia/tree/master/build/config">gaia 仓库中的配置文件</a></li> -</ul> |
