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

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

Issue 1936673002: [Extensions] Finish freezing schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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 = $Array.slice(schema); 11 var extendedSchema = $Array.slice(schema);
12 extendedSchema.unshift({'type': 'string'}); 12 $Array.unshift(extendedSchema, {'type': 'string'});
13 return extendedSchema; 13 return extendedSchema;
14 } 14 }
15 15
16 function ContentSetting(contentType, settingSchema) { 16 function ContentSetting(contentType, settingSchema) {
17 this.get = function(details, callback) { 17 this.get = function(details, callback) {
18 var getSchema = this.functionSchemas.get.definition.parameters; 18 var getSchema = this.functionSchemas.get.definition.parameters;
19 validate([details, callback], getSchema); 19 validate([details, callback], getSchema);
20 return sendRequest('contentSettings.get', 20 return sendRequest('contentSettings.get',
21 [contentType, details, callback], 21 [contentType, details, callback],
22 extendSchema(getSchema)); 22 extendSchema(getSchema));
23 }; 23 };
24 this.set = function(details, callback) { 24 this.set = function(details, callback) {
25 var setSchema = $Array.slice( 25 // The set schema included in the Schema object is generic, since it varies
26 this.functionSchemas.set.definition.parameters); 26 // per-setting. However, this is only ever for a single setting, so we can
27 setSchema[0].properties.setting = settingSchema; 27 // enforce the types more thoroughly.
28 validate([details, callback], setSchema); 28 var rawSetSchema = this.functionSchemas.set.definition.parameters;
29 var rawSettingParam = rawSetSchema[0];
30 var props = $Object.assign({}, rawSettingParam.properties);
31 props.setting = settingSchema;
32 var modSettingParam = {
33 name: rawSettingParam.name,
34 type: rawSettingParam.type,
35 properties: props,
36 };
37 var modSetSchema = $Array.slice(rawSetSchema);
38 modSetSchema[0] = modSettingParam;
39 validate([details, callback], rawSetSchema);
29 return sendRequest('contentSettings.set', 40 return sendRequest('contentSettings.set',
30 [contentType, details, callback], 41 [contentType, details, callback],
31 extendSchema(setSchema)); 42 extendSchema(modSetSchema));
32 }; 43 };
33 this.clear = function(details, callback) { 44 this.clear = function(details, callback) {
34 var clearSchema = this.functionSchemas.clear.definition.parameters; 45 var clearSchema = this.functionSchemas.clear.definition.parameters;
35 validate([details, callback], clearSchema); 46 validate([details, callback], clearSchema);
36 return sendRequest('contentSettings.clear', 47 return sendRequest('contentSettings.clear',
37 [contentType, details, callback], 48 [contentType, details, callback],
38 extendSchema(clearSchema)); 49 extendSchema(clearSchema));
39 }; 50 };
40 this.getResourceIdentifiers = function(callback) { 51 this.getResourceIdentifiers = function(callback) {
41 var schema = 52 var schema =
42 this.functionSchemas.getResourceIdentifiers.definition.parameters; 53 this.functionSchemas.getResourceIdentifiers.definition.parameters;
43 validate([callback], schema); 54 validate([callback], schema);
44 return sendRequest( 55 return sendRequest(
45 'contentSettings.getResourceIdentifiers', 56 'contentSettings.getResourceIdentifiers',
46 [contentType, callback], 57 [contentType, callback],
47 extendSchema(schema)); 58 extendSchema(schema));
48 }; 59 };
49 } 60 }
50 61
51 exports.$set('ContentSetting', ContentSetting); 62 exports.$set('ContentSetting', ContentSetting);
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/chrome_setting.js ('k') | chrome/test/data/extensions/api_test/stubs_app/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698