ไฟล์ Manifest สำหรับพื้นที่เก็บข้อมูล

พื้นที่เก็บข้อมูล managed กำหนดให้ต้องประกาศโครงสร้างเป็นสคีมา JSON และ Chrome จะตรวจสอบอย่างเข้มงวด ซึ่งแตกต่างจากพื้นที่เก็บข้อมูล local และ sync สคีมานี้ต้องจัดเก็บไว้ในไฟล์ที่ระบุโดยพร็อพเพอร์ตี้ "managed_schema" ของคีย์ไฟล์ Manifest "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 โหลดได้ที่ chrome://policy

รูปแบบสคีมา

รูปแบบสคีมา JSON มีข้อกำหนดเพิ่มเติมบางอย่างจาก Chrome ดังนี้

  • สคีมาระดับบนสุดต้องมีประเภท object
  • object ระดับบนสุดต้องไม่มี additionalProperties properties ที่ประกาศคือนโยบายสำหรับแอปนี้
  • แต่ละสคีมาต้องมีค่า $ref หรือ type เพียง 1 รายการเท่านั้น

หากสคีมาไม่ถูกต้อง 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" }
       
}
     
}
   
}
 
}
}