Manifest per le aree di stoccaggio

A differenza delle aree di archiviazione local e sync, l'area di archiviazione managed richiede che la sua struttura sia dichiarata come schema JSON ed è rigorosamente convalidata da Chrome. Questo schema deve essere archiviato in un file indicato dalla proprietà "managed_schema" della chiave manifest "storage" e dichiarare i criteri aziendali supportati dall'app.

I criteri sono analoghi alle opzioni, ma sono configurati da un amministratore di sistema anziché dall'utente, consentendo la preconfigurazione dell'app per tutti gli utenti di un'organizzazione. Per vedere alcuni esempi tratti da Chrome, leggi in che modo Chrome gestisce i criteri.

Dopo aver dichiarato i criteri, possono essere letti dall'API storage.managed. Spetta all'app applicare i criteri configurati dall'amministratore.

File manifest.json di esempio

La proprietà storage.managed_schema indica un file all'interno dell'app che contiene lo schema dei criteri.

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

Chrome caricherà quindi questi criteri dal sistema operativo sottostante e da Google Apps per gli utenti che hanno eseguito l'accesso. L'evento storage.onChanged viene attivato ogni volta che viene rilevata una modifica dei criteri, anche quando il browser non era in esecuzione se l'app utilizza pagine di eventi. Puoi verificare i criteri caricati da Chrome all'indirizzo chrome://policy.

Formato schema

Il formato dello schema JSON prevede alcuni requisiti aggiuntivi di Chrome:

  • Lo schema di primo livello deve essere di tipo object.
  • L'elemento object di primo livello non può avere additionalProperties. I properties dichiarati sono i criteri per questa app.
  • Ogni schema deve avere un valore $ref o un solo valore type.

Se lo schema non è valido, Chrome non caricherà l'estensione e indicherà il motivo per cui lo schema non è stato convalidato. Se un valore del criterio non è conforme allo schema, non verrà pubblicato dall'API storage.managed.

Schema di esempio

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