מניפסט לאזורי אחסון

בניגוד לאזורי האחסון local ו-sync, צריך להצהיר על המבנה של אזור האחסון managed כסכימת JSON ולבדוק אותו בקפידה על ידי Chrome. צריך לאחסן את הסכימה הזו בקובץ שצוין באמצעות המאפיין "managed_schema" של מפתח המניפסט "storage", ולציין את מדיניות הארגון שהאפליקציה תומכת בה.

כללי המדיניות דומים לאפשרויות, אבל הם מוגדרים על ידי האדמין במקום על ידי המשתמש, וכך האפליקציה יכולה להיות מוגדרת מראש לכל המשתמשים בארגון. לקבלת דוגמאות מ-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://policy אפשר לבדוק את כללי המדיניות ש-Chrome טען.

פורמט סכימה

לפורמט של סכימת JSON יש כמה דרישות נוספות מ-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" }
        }
      }
    }
  }
}