OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Custom binding for the contentSettings API. | |
6 | |
7 var binding = require('binding').Binding.create('contentSettings'); | |
8 | |
9 var sendRequest = require('sendRequest').sendRequest; | |
10 var validate = require('schemaUtils').validate; | |
11 | |
12 binding.registerCustomType('contentSettings.ContentSetting', function() { | |
13 function extendSchema(schema) { | |
14 var extendedSchema = schema.slice(); | |
15 extendedSchema.unshift({'type': 'string'}); | |
16 return extendedSchema; | |
17 } | |
18 | |
19 function ContentSetting(contentType, settingSchema) { | |
20 this.get = function(details, callback) { | |
21 var getSchema = this.functionSchemas.get.definition.parameters; | |
22 validate([details, callback], getSchema); | |
23 return sendRequest('contentSettings.get', | |
24 [contentType, details, callback], | |
25 extendSchema(getSchema)); | |
26 }; | |
27 this.set = function(details, callback) { | |
28 var setSchema = this.functionSchemas.set.definition.parameters.slice(); | |
29 setSchema[0].properties.setting = settingSchema; | |
30 validate([details, callback], setSchema); | |
31 return sendRequest('contentSettings.set', | |
32 [contentType, details, callback], | |
33 extendSchema(setSchema)); | |
34 }; | |
35 this.clear = function(details, callback) { | |
36 var clearSchema = this.functionSchemas.clear.definition.parameters; | |
37 validate([details, callback], clearSchema); | |
38 return sendRequest('contentSettings.clear', | |
39 [contentType, details, callback], | |
40 extendSchema(clearSchema)); | |
41 }; | |
42 this.getResourceIdentifiers = function(callback) { | |
43 var schema = | |
44 this.functionSchemas.getResourceIdentifiers.definition.parameters; | |
45 validate([callback], schema); | |
46 return sendRequest( | |
47 'contentSettings.getResourceIdentifiers', | |
48 [contentType, callback], | |
49 extendSchema(schema)); | |
50 }; | |
51 } | |
52 | |
53 return ContentSetting; | |
54 }); | |
55 | |
56 exports.binding = binding.generate(); | |
OLD | NEW |