Add testing/scripts/OWNERS
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / content_setting.js
blobc76b74ba074ae616a9b0c083661541bf92e257dd
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.
5 // Custom binding for the contentSettings API.
7 var sendRequest = require('sendRequest').sendRequest;
8 var validate = require('schemaUtils').validate;
10 function extendSchema(schema) {
11   var extendedSchema = $Array.slice(schema);
12   extendedSchema.unshift({'type': 'string'});
13   return extendedSchema;
16 function ContentSetting(contentType, settingSchema) {
17   this.get = function(details, callback) {
18     var getSchema = this.functionSchemas.get.definition.parameters;
19     validate([details, callback], getSchema);
20     return sendRequest('contentSettings.get',
21                        [contentType, details, callback],
22                        extendSchema(getSchema));
23   };
24   this.set = function(details, callback) {
25     var setSchema = $Array.slice(
26         this.functionSchemas.set.definition.parameters);
27     setSchema[0].properties.setting = settingSchema;
28     validate([details, callback], setSchema);
29     return sendRequest('contentSettings.set',
30                        [contentType, details, callback],
31                        extendSchema(setSchema));
32   };
33   this.clear = function(details, callback) {
34     var clearSchema = this.functionSchemas.clear.definition.parameters;
35     validate([details, callback], clearSchema);
36     return sendRequest('contentSettings.clear',
37                        [contentType, details, callback],
38                        extendSchema(clearSchema));
39   };
40   this.getResourceIdentifiers = function(callback) {
41     var schema =
42         this.functionSchemas.getResourceIdentifiers.definition.parameters;
43     validate([callback], schema);
44     return sendRequest(
45         'contentSettings.getResourceIdentifiers',
46         [contentType, callback],
47         extendSchema(schema));
48   };
51 exports.ContentSetting = ContentSetting;