Tidak seperti area penyimpanan local
dan sync
, area penyimpanan managed
mengharuskan strukturnya
dideklarasikan sebagai Skema JSON dan divalidasi secara ketat oleh Chrome. Skema ini harus disimpan dalam file yang ditunjukkan oleh properti "managed_schema"
dari kunci manifes "storage"
dan mendeklarasikan kebijakan perusahaan yang didukung oleh ekstensi.
Kebijakan serupa dengan opsi, tetapi dikonfigurasi oleh administrator sistem, bukan pengguna, sehingga ekstensi dapat dikonfigurasi sebelumnya untuk semua pengguna organisasi. Lihat cara Chrome menangani kebijakan untuk contoh dari Chrome itu sendiri.
Setelah mendeklarasikan kebijakan, kebijakan tersebut dapat dibaca dari API storage.managed. Ekstensilah yang akan menerapkan kebijakan yang dikonfigurasi oleh administrator.
Contoh manifest.json
Properti storage.managed_schema
menunjukkan file dalam ekstensi yang berisi skema kebijakan.
{
"name": "My enterprise extension",
"storage": {
"managed_schema": "schema.json"
},
...
}
Kemudian, Chrome akan memuat kebijakan tersebut dari sistem operasi dasar dan dari Google Apps untuk pengguna yang login. Peristiwa storage.onChanged diaktifkan setiap kali perubahan kebijakan terdeteksi, termasuk saat browser tidak berjalan jika ekstensi menggunakan halaman peristiwa. Anda dapat memverifikasi kebijakan yang dimuat Chrome di chrome://policy.
Format skema
Format Skema JSON memiliki beberapa persyaratan tambahan dari Chrome:
- Skema tingkat atas harus memiliki jenis
object
. object
tingkat teratas tidak boleh memilikiadditionalProperties
.properties
yang dideklarasikan adalah kebijakan untuk ekstensi ini.- Setiap skema harus memiliki nilai
$ref
atau tepat satutype
.
Jika skema tidak valid, Chrome tidak akan memuat ekstensi dan akan menunjukkan alasan skema tidak divalidasi. Jika nilai kebijakan tidak sesuai dengan skema, nilai kebijakan tidak akan dipublikasikan oleh storage.managed
API.
Skema contoh
{
"type": "object",
// "properties" maps an optional key of this object to its schema. At the
// top-level object, these keys are the policy names supported.
"properties": {
// The policy name "AutoSave" is mapped to its schema, which in this case
// declares it as a simple boolean value.
// "title" and "description" are optional and are used to show a
// user-friendly name and documentation to the administrator.
"AutoSave": {
"title": "Automatically save changes.",
"description": "If set to true then changes will be automatically saved.",
"type": "boolean"
},
// Other simple types supported include "integer", "string" and "number".
"PollRefreshRate": {
"type": "integer"
},
"DefaultServiceUrl": {
"type": "string"
},
// "array" is a list of items that conform to another schema, described
// in "items". An example to this schema is [ "one", "two" ].
"ServiceUrls": {
"type": "array",
"items": {
"type": "string"
}
},
// A more complex example that describes a list of bookmarks. Each bookmark
// has a "title", and can have a "url" or a list of "children" bookmarks.
// The "id" attribute is used to name a schema, and other schemas can reuse
// it using the "$ref" attribute.
"Bookmarks": {
"type": "array",
"id": "ListOfBookmarks",
"items": {
"type": "object",
"properties": {
"title": { "type": "string" },
"url": { "type": "string" },
"children": { "$ref": "ListOfBookmarks" }
}
}
},
// An "object" can have known properties listed as "properties", and can
// optionally have "additionalProperties" indicating a schema to apply to
// keys that aren't found in "properties".
// This example policy could map a URL to its settings. An example value:
// {
// "youtube.com": {
// "blocklisted": true
// },
// "google.com": {
// "bypass_proxy": true
// }
// }
"SettingsForUrls": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"blocklisted": { "type": "boolean" },
"bypass_proxy": { "type": "boolean" }
}
}
}
}
}