在Firefox OS 學習——Gaia 編譯分析 這篇文章多次提到manifest.webapp文件,對於做過android app 開發的人來說,都很熟悉Android.mk 和Manifest.xml文件。在Firefox OS中,manifest.webapp的作用是綜合了android 中的Android.mk 和Manifest.xml的作用。下面就具體說說manifest.webapp的結構及其內容。
manifest.webapp採用的是json的數據格式(鍵值對的形式),它描述了app 的name,icon,loacl,premissions等相關的信息。先看一個相對完整的manifest.webapp的格式及其內容:
{
"name": "MozillaBall",
"description": "Exciting Open Web development action!",
"launch_path": "/",
"version": "1.0",
"type": "privileged",
"icons": {
"16": "/img/icon_16.png",
"48": "/img/icon_48.png",
"128": "/img/icon_128.png"
},
"developer": {
"name": "Mozilla",
"url": "https://mozilla.org/en-US"
},
"installs_allowed_from": [
"https://marketplace.mozilla.org"
"https://marketplace.example.org"
],
"appcache_path": "/cache.manifest",
"locales": [
"es": {
"description": "¡Acción abierta emocionante del desarrollo del Web!",
"developer": {
"url": "https://mozilla.org/es-ES"
}
}
"it": {
"description": "Azione aperta emozionante di sviluppo di fotoricettore!",
"developer": {
"url": "http://it.mozillalabs.com/"
}
}
],
"default_locale": "en",
"screen_size": {
"min_width": "600",
"min_height": "300"
},
"required_features": [
"touch", "geolocation", "webgl"
],
"orientation": "landscape",
"permissions": {
"contacts": {
"description": "Required for autocompletion in the share screen",
"access": "read"
}
},
"fullscreen": "true",
"activities": {
"share": {
"filters": {
"type": ["image/png", "image/gif"]
}
"href": "/share.html",
"disposition": "window"
}
}
}
屬性
上述code清單中的各種屬性,用法,含義,下面做詳細介紹。這些屬性必須包含String,其實它的屬性大致可以分爲兩類:強制屬性,可選屬性。
1.強制屬性
name:默認locale下,web app的名稱,顯示在設備中app的名稱,最大支持128字符
description:默認locale下,web app的簡短描述(查詢了一些資料,沒發現它的功能)最大支持1024字符
default_locale:設置默認的locale,確定name,description的語言環境。
2.可選屬性
launch_path:指定web app被打開時,首先加載的東西,一般都是"/index.html".如果值缺省了(即"/"),將加載域名的東西。
version:web app的版本號,
type:確定這個app 和manifest如何被runtime解析,還有所使用的安全機制。它的值只能是下面三個中一個:
* web:正常的web app可以單獨存在,在應用商店可以下載安裝,並且會列舉有限的權限。type 不指定時,默認是web。
* privileged:就像android Ios 一樣單獨存在的app,會在本地安裝一個文件包。它需要通過應用商店的審覈。
* certified:不用於第三發app中,屬於系統級別的東西,例如系統設置,撥號器,電源管理等。類似android:sharedUserId 作用把。
icons:app icon,支持 16 x 16, 32 x 32, 48 x 48, 64 x 64, 128 x 128 and 256 x 256
developer:開發者相關的信息,包括開發者名稱,及其URL。
installs_allowed_from:指定app可以從那些應用商店安裝,"*"可以從任何地方安裝," "無法從任何網站商店安裝。
appcache_path:存放app cache manifest的絕對路徑,當打開安裝的web app時,cache.manifest會被解析。靜態的一些資源會被存放到緩存中。
locales:重寫一些locales特定的值,適應不同的語言。locales, installs_allowed_from, default_locale是不能被重寫的。如果locales被設置了,default_locale也必須被設置。
screen_size:包含兩個屬性min_width,min_height,分別設置app適應的最小寬度和高度(以像素爲單位)。
required_features:包含app 能正確運行需要的一些強制屬性。具體的值尚無定論。這個在app中可能用的很少。
orientation:鎖定app的屏幕方向,和android orientation的功能一樣。它的值必須是下面四個中的一個或多個:
* portrait-primary:鎖定單一portrait顯示。如果設備有明顯的portrait,就是顯示成portrait。如果設備從landscape順時針旋轉90度,app也顯示portrait。
* landscape-primary:鎖定單一landscape顯示。如果設備有明顯的landscape,就是顯示成landscape。如果設備從portrait順時針旋轉90度,app也顯示landscape。
* portrait-secondary:鎖定單一portrait顯示。如果設備有明顯的portrait,就是顯示成portrait。如果設備從landscape逆時針旋轉90度,app也顯示portrait。
* landscape-secondary:鎖定單一landscape顯示。如果設備有明顯的landscape,就是顯示成landscape。如果設備從portrait逆時針旋轉90度,app也顯示landscape。
* portrait:相當於["portrait-primary", "portrait-secondary"]這種組合模式。
* landscape:相當於["landscape-primary", "landscape-secondary"]組合模式
permissions:描述app 所需要的權限,android開發者對着部分就很熟悉了。只是的它格式和寫法不同。下面給了example:
"permissions": {
"contacts": {
"description": "Required for autocompletion in the share screen",
"access": "readcreate"
},
"alarms": {
"description": "Required to schedule notifications"
}
}
permissions詳細的請參照App_permissions。
fullscreen:設置app是否全屏,只能true 或者false。默認應該是false吧(有待驗證)。
activities:指定這個app可以支持的web activities。activities命名沒有什麼講究。下面給出個例子:
"activities": {
"share": {
"filters": {
"type": ["image/png", "image/gif"]
}
"href": "/share.html",
"disposition": "window"
}
}
關於activities中的三個屬性filters
, href
,disposition
andreturnValue
請參考 Activity
handler description。
redirects:針對 privileged 或 certified類型 app做第三方認證。從第三方認證後需要重定向當前app URL。但是privileged 或 certified類型 app是沒有可以使用的web URL,所以它只能重定向到app 內部的URL。下面給個exanple:
"redirects": [
{"from": "http://mydomain.com/oauth2/flow.html",
"to": "/redirects/redirect.html"},
{"from": "http://mydomain.com/oauth2/dialogs_end.html",
"to": "/redirects/dialogs_end.html"}
]
origin:針對 privileged 或 certified類型 app的屬性,功能之一就是很容易通過類似的OAuth , Persona等認證。格式是app://<UUID>.example:
"origin": "app://my-app.com"
messages:捕獲系統消息作出的反映,example:
"messages": [
{ "telephony-new-call": "/dialer/index.html#keyboard-view" },
{ "bluetooth-dialer-command": "/dialer/index.html#keyboard-view" },
{ "headset-button": "/dialer/index.html#keyboard-view" },
{ "notification": "/dialer/index.html#keyboard-view" },
{ "alarm": "/facebook/fb_sync.html" }
]
上面的例子中,當接受的電話打進請求消息時,會彈出keyboard-view,以便用會作出接聽,掛斷的操作。
chrome:
在屏幕底部添加一個導航欄,對於沒有返回按鈕的app,可以快速增加一個導航欄。
左邊的圖是導航欄隱藏的時候的圖,右邊是顯示時候的圖。
到此,manifest.webapp結構的內容基本上都涉及到了。都只是粗略的弄懂概念而已,具體的細節還要在應用中去具體甄別。
參考文章:App manifest