summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/resources/extensions/content_settings_custom_bindings.js
blob: d92efc1f9d9ef568342b8137a0be0eb12de7371e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Custom bindings for the contentSettings API.

var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
var validate = require('schemaUtils').validate;

chromeHidden.registerCustomType('contentSettings.ContentSetting', function() {
  function extendSchema(schema) {
    var extendedSchema = schema.slice();
    extendedSchema.unshift({'type': 'string'});
    return extendedSchema;
  }

  function ContentSetting(contentType, settingSchema) {
    this.get = function(details, callback) {
      var getSchema = this.functionSchemas.get.definition.parameters;
      validate([details, callback], getSchema);
      return sendRequest('contentSettings.get',
                         [contentType, details, callback],
                         extendSchema(getSchema));
    };
    this.set = function(details, callback) {
      var setSchema = this.functionSchemas.set.definition.parameters.slice();
      setSchema[0].properties.setting = settingSchema;
      validate([details, callback], setSchema);
      return sendRequest('contentSettings.set',
                         [contentType, details, callback],
                         extendSchema(setSchema));
    };
    this.clear = function(details, callback) {
      var clearSchema = this.functionSchemas.clear.definition.parameters;
      validate([details, callback], clearSchema);
      return sendRequest('contentSettings.clear',
                         [contentType, details, callback],
                         extendSchema(clearSchema));
    };
    this.getResourceIdentifiers = function(callback) {
      var schema =
          this.functionSchemas.getResourceIdentifiers.definition.parameters;
      validate([callback], schema);
      return sendRequest(
          'contentSettings.getResourceIdentifiers',
          [contentType, callback],
          extendSchema(schema));
    };
  }

  return ContentSetting;
});