В отличие от local и sync областей хранения, managed область хранения требует, чтобы ее структура была объявлена как схема JSON и строго проверяется Chrome. Эта схема должна храниться в файле, указанном свойством "managed_schema" ключа манифеста "storage" , и объявляет политики предприятия, поддерживаемые расширением.
Политики аналогичны параметрам, но настраиваются системным администратором для расширений, установленных политикой, что позволяет предварительно настроить расширение для всех пользователей организации. Посмотрите , как Chrome обрабатывает политики, на примерах самого Chrome.
После объявления политик их можно прочитать из API Storage.managed . Расширение должно обеспечивать соблюдение политик, настроенных администратором.
Пример манифеста.json
Свойство storage.managed_schema указывает файл внутри расширения, содержащий схему политики.
{ "name": "My enterprise extension", "storage": { "managed_schema": "schema.json" }, ... } Затем Chrome загрузит эти политики из базовой операционной системы и из Google Apps для вошедших в систему пользователей. Событие storage.onChanged вызывается при каждом обнаружении изменения политики. Вы можете проверить политики, загруженные Chrome, по адресу chrome://policy.
Формат схемы
К формату JSON Schema предъявляются некоторые дополнительные требования со стороны Chrome:
- Схема верхнего уровня должна иметь тип
object. -
objectверхнего уровня не может иметьadditionalProperties. Объявленныеpropertiesявляются политиками для этого расширения. - Каждая схема должна иметь либо значение
$ref, либо ровно одинtype.
Если схема недействительна, Chrome не загрузит расширение и укажет причину, по которой схема не была проверена. Если значение политики не соответствует схеме, оно не будет опубликовано API-интерфейсом storage.managed .
Пример схемы
{ "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" } } } } } }