儲存區域的資訊清單

localsync 儲存區域不同,managed 儲存區域的結構必須宣告為 JSON 結構定義,並且經過 Chrome 嚴格驗證。這個結構定義必須儲存在以 "storage" 資訊清單金鑰 "managed_schema" 屬性指定的檔案中,並宣告應用程式支援的企業政策。

政策與選項類似,但政策是由系統管理員 (而非使用者) 設定,可讓機構為機構的所有使用者預先設定應用程式。如需 Chrome 本身的範例,請參閱 Chrome 處理政策的方式

宣告政策之後,即可從 storage.managed API 讀取這些政策。應用程式可強制執行管理員所設定的政策。

manifest.json 範例

storage.managed_schema 屬性表示在應用程式內,包含政策結構定義的檔案。

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

Chrome 接著會從基礎作業系統和 Google Apps 載入這些政策,以供已登入使用者使用。每當偵測到政策變更,就會觸發 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" }
        }
      }
    }
  }
}