Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/renderer/resources/extensions/content_setting.js

Issue 1906593002: [Extensions] Finish freezing schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom binding for the contentSettings API. 5 // Custom binding for the contentSettings API.
6 6
7 var sendRequest = require('sendRequest').sendRequest; 7 var sendRequest = require('sendRequest').sendRequest;
8 var validate = require('schemaUtils').validate; 8 var validate = require('schemaUtils').validate;
9 9
10 function extendSchema(schema) { 10 function extendSchema(schema) {
11 /* var extendedSchema = [{'type': 'string'}];
12 $Array.forEach(schema, function(s) {
13 extendedSchema.push(s);
14 });*/
11 var extendedSchema = $Array.slice(schema); 15 var extendedSchema = $Array.slice(schema);
12 extendedSchema.unshift({'type': 'string'}); 16 extendedSchema.unshift({'type': 'string'});
13 return extendedSchema; 17 return extendedSchema;
14 } 18 }
15 19
16 function ContentSetting(contentType, settingSchema) { 20 function ContentSetting(contentType, settingSchema) {
17 this.get = function(details, callback) { 21 this.get = function(details, callback) {
18 var getSchema = this.functionSchemas.get.definition.parameters; 22 var getSchema = this.functionSchemas.get.definition.parameters;
19 validate([details, callback], getSchema); 23 validate([details, callback], getSchema);
20 return sendRequest('contentSettings.get', 24 return sendRequest('contentSettings.get',
21 [contentType, details, callback], 25 [contentType, details, callback],
22 extendSchema(getSchema)); 26 extendSchema(getSchema));
23 }; 27 };
24 this.set = function(details, callback) { 28 this.set = function(details, callback) {
25 var setSchema = $Array.slice( 29 // The set schema included in the Schema object is generic, since it varies
26 this.functionSchemas.set.definition.parameters); 30 // per-setting. However, this is only ever for a single setting, so we can
27 setSchema[0].properties.setting = settingSchema; 31 // enforce the types more thoroughly.
28 validate([details, callback], setSchema); 32 var rawSetSchema = this.functionSchemas.set.definition.parameters;
33 var rawSettingParam = rawSetSchema[0];
34 var props = $Object.assign({}, rawSettingParam.properties);
35 props.setting = settingSchema;
36 var modSettingParam = {
37 name: rawSettingParam.name,
38 type: rawSettingParam.type,
39 properties: props,
40 };
41 var modSetSchema = $Array.slice(rawSetSchema);
42 modSetSchema[0] = modSettingParam;
43 validate([details, callback], rawSetSchema);
29 return sendRequest('contentSettings.set', 44 return sendRequest('contentSettings.set',
30 [contentType, details, callback], 45 [contentType, details, callback],
31 extendSchema(setSchema)); 46 extendSchema(modSetSchema));
32 }; 47 };
33 this.clear = function(details, callback) { 48 this.clear = function(details, callback) {
34 var clearSchema = this.functionSchemas.clear.definition.parameters; 49 var clearSchema = this.functionSchemas.clear.definition.parameters;
35 validate([details, callback], clearSchema); 50 validate([details, callback], clearSchema);
36 return sendRequest('contentSettings.clear', 51 return sendRequest('contentSettings.clear',
37 [contentType, details, callback], 52 [contentType, details, callback],
38 extendSchema(clearSchema)); 53 extendSchema(clearSchema));
39 }; 54 };
40 this.getResourceIdentifiers = function(callback) { 55 this.getResourceIdentifiers = function(callback) {
41 var schema = 56 var schema =
42 this.functionSchemas.getResourceIdentifiers.definition.parameters; 57 this.functionSchemas.getResourceIdentifiers.definition.parameters;
43 validate([callback], schema); 58 validate([callback], schema);
44 return sendRequest( 59 return sendRequest(
45 'contentSettings.getResourceIdentifiers', 60 'contentSettings.getResourceIdentifiers',
46 [contentType, callback], 61 [contentType, callback],
47 extendSchema(schema)); 62 extendSchema(schema));
48 }; 63 };
49 } 64 }
50 65
51 exports.$set('ContentSetting', ContentSetting); 66 exports.$set('ContentSetting', ContentSetting);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698