存储区域的清单

localsync 存储区域不同,managed 存储区域的结构必须为 声明为 JSON 架构,并经过 Chrome 的严格验证。此架构必须存储在 (由 "storage" 清单键的 "managed_schema" 属性指示)文件,并声明 应用支持的企业政策。

政策类似于选项,但是由系统管理员(而不是用户)配置的 从而为组织的所有用户预先配置应用。了解Chrome 如何处理 政策

声明政策后,您可以通过 storage.managed API 读取政策。一切由应用决定 以强制执行管理员配置的政策。

manifest.json 示例

storage.managed_schema 属性表示应用内包含政策的文件 架构。

{
  "name": "My enterprise app",
  "storage": {
    "managed_schema": "schema.json"
  },
  ...
}

然后,Chrome 会从基础操作系统和 Google Apps for Business 加载这些政策。 已登录的用户只要检测到政策更改,就会触发 storage.onChanged 事件, 包括浏览器未运行时(如果应用使用事件页面)。您可以验证 Chrome 在 chrome://policy 中加载的政策。

架构格式

对于 JSON 架构格式,Chrome 还需遵循一些额外要求:

  • 顶级架构的类型必须为 object
  • 顶级 object 不能包含 additionalProperties。声明的 properties 是 政策
  • 每个架构必须有一个 $ref 值或只有一个 type

如果架构无效,则 Chrome 不会加载该扩展程序,并会说明 架构未经过验证。如果政策值不符合架构,则不会 由 storage.managed API 发布。

示例架构

{
  "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" }
        }
      }
    }
  }
}