Im Gegensatz zu den Speicherbereichen local
und sync
muss der managed
-Speicherbereich so aufgebaut sein, dass
als JSON-Schema deklariert und von Chrome streng geprüft. Dieses Schema muss in einem
Datei, die durch das Attribut "managed_schema"
des Manifestschlüssels "storage"
angegeben wird, und deklariert die
von der App unterstützten Unternehmensrichtlinien.
Richtlinien sind analog zu Optionen, werden jedoch von einem Systemadministrator und nicht vom Nutzer konfiguriert. Dadurch kann die App für alle Nutzer einer Organisation vorkonfiguriert werden. So verarbeitet Chrome Richtlinien für Beispiele aus Chrome.
Nachdem die Richtlinien deklariert wurden, können sie aus der storage.managed API gelesen werden. Es liegt an der App um die vom Administrator konfigurierten Richtlinien zu erzwingen.
Beispielmanifest.json
Das Attribut storage.managed_schema
gibt eine Datei in der App an, die die Richtlinie enthält.
Schema.
{
"name": "My enterprise app",
"storage": {
"managed_schema": "schema.json"
},
...
}
Chrome lädt diese Richtlinien dann aus dem zugrunde liegenden Betriebssystem und aus Google Apps für angemeldeten Nutzer. Das Ereignis storage.onChanged wird ausgelöst, wenn eine Richtlinienänderung erkannt wird. auch wenn der Browser nicht ausgeführt wurde, wenn die App Ereignisseiten verwendet. Sie können die Richtlinien, die Chrome unter chrome://policy geladen hat.
Schema format
Für das JSON-Schemaformat gelten einige zusätzliche Anforderungen von Chrome:
- Das Schema der obersten Ebene muss den Typ
object
haben. - Das
object
auf oberster Ebene darfadditionalProperties
nicht enthalten. Die deklariertenproperties
sind die für diese App. - Jedes Schema muss entweder einen
$ref
-Wert oder genau einetype
haben.
Wenn das Schema ungültig ist, lädt Chrome die Erweiterung nicht und gibt den Grund für die
Schema nicht validiert wurde. Wenn ein Richtlinienwert nicht dem Schema entspricht, ist er nicht
von der storage.managed
API veröffentlicht.
Beispielschema
{
"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" }
}
}
}
}
}