Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Some content types have been removed and no longer correspond to a real | |
| 11 // content setting. Instead, these always return a fixed dummy value, and issue | |
| 12 // a warning when accessed. This maps the content type name to the dummy value. | |
| 13 var DEPRECATED_CONTENT_TYPES = { | |
|
Devlin
2016/09/27 15:22:36
forgot - please add __proto__: null to this object
Matt Giuca
2016/09/29 03:13:45
Done.
| |
| 14 fullscreen: 'allow', | |
| 15 mouselock: 'allow', | |
| 16 }; | |
| 17 | |
| 10 function extendSchema(schema) { | 18 function extendSchema(schema) { |
| 11 var extendedSchema = $Array.slice(schema); | 19 var extendedSchema = $Array.slice(schema); |
| 12 $Array.unshift(extendedSchema, {'type': 'string'}); | 20 $Array.unshift(extendedSchema, {'type': 'string'}); |
| 13 return extendedSchema; | 21 return extendedSchema; |
| 14 } | 22 } |
| 15 | 23 |
| 16 function ContentSetting(contentType, settingSchema, schema) { | 24 function ContentSetting(contentType, settingSchema, schema) { |
| 17 var getFunctionParameters = function(name) { | 25 var getFunctionParameters = function(name) { |
| 18 var f = $Array.filter( | 26 var f = $Array.filter( |
| 19 schema.functions, function(f) { return f.name === name; })[0]; | 27 schema.functions, function(f) { return f.name === name; })[0]; |
| 20 return f.parameters; | 28 return f.parameters; |
| 21 }; | 29 }; |
| 22 this.get = function(details, callback) { | 30 this.get = function(details, callback) { |
| 23 var getSchema = getFunctionParameters('get'); | 31 var getSchema = getFunctionParameters('get'); |
| 24 validate([details, callback], getSchema); | 32 validate([details, callback], getSchema); |
| 33 | |
| 34 var dummySetting = DEPRECATED_CONTENT_TYPES[contentType]; | |
| 35 if (dummySetting !== undefined) { | |
| 36 console.warn('contentSettings.' + contentType + ' is deprecated; it will ' | |
| 37 + 'always return \'' + dummySetting + '\'.'); | |
| 38 $Function.apply(callback, undefined, [{setting: dummySetting}]); | |
| 39 return; | |
| 40 } | |
| 41 | |
| 25 return sendRequest('contentSettings.get', | 42 return sendRequest('contentSettings.get', |
| 26 [contentType, details, callback], | 43 [contentType, details, callback], |
| 27 extendSchema(getSchema)); | 44 extendSchema(getSchema)); |
| 28 }; | 45 }; |
| 46 | |
| 29 this.set = function(details, callback) { | 47 this.set = function(details, callback) { |
| 30 // The set schema included in the Schema object is generic, since it varies | 48 // The set schema included in the Schema object is generic, since it varies |
| 31 // per-setting. However, this is only ever for a single setting, so we can | 49 // per-setting. However, this is only ever for a single setting, so we can |
| 32 // enforce the types more thoroughly. | 50 // enforce the types more thoroughly. |
| 33 var rawSetSchema = getFunctionParameters('set'); | 51 var rawSetSchema = getFunctionParameters('set'); |
| 34 var rawSettingParam = rawSetSchema[0]; | 52 var rawSettingParam = rawSetSchema[0]; |
| 35 var props = $Object.assign({}, rawSettingParam.properties); | 53 var props = $Object.assign({}, rawSettingParam.properties); |
| 36 props.setting = settingSchema; | 54 props.setting = settingSchema; |
| 37 var modSettingParam = { | 55 var modSettingParam = { |
| 38 name: rawSettingParam.name, | 56 name: rawSettingParam.name, |
| 39 type: rawSettingParam.type, | 57 type: rawSettingParam.type, |
| 40 properties: props, | 58 properties: props, |
| 41 }; | 59 }; |
| 42 var modSetSchema = $Array.slice(rawSetSchema); | 60 var modSetSchema = $Array.slice(rawSetSchema); |
| 43 modSetSchema[0] = modSettingParam; | 61 modSetSchema[0] = modSettingParam; |
| 44 validate([details, callback], rawSetSchema); | 62 validate([details, callback], rawSetSchema); |
| 63 | |
| 64 if (DEPRECATED_CONTENT_TYPES.hasOwnProperty(contentType)) { | |
|
Devlin
2016/09/26 20:30:37
Use the safe-builtin version.
Matt Giuca
2016/09/27 01:18:33
Sorry, I don't know what you want.
Do you mean to
Devlin
2016/09/27 15:22:36
Safe Builtins are cached (safe) versions of variou
Matt Giuca
2016/09/29 03:13:45
Done. OK thanks for the explanation.
| |
| 65 console.warn('contentSettings.' + contentType + ' is deprecated; setting ' | |
| 66 + 'it has no effect.'); | |
| 67 $Function.apply(callback, undefined, []); | |
| 68 return; | |
| 69 } | |
| 70 | |
| 45 return sendRequest('contentSettings.set', | 71 return sendRequest('contentSettings.set', |
| 46 [contentType, details, callback], | 72 [contentType, details, callback], |
| 47 extendSchema(modSetSchema)); | 73 extendSchema(modSetSchema)); |
| 48 }; | 74 }; |
| 75 | |
| 49 this.clear = function(details, callback) { | 76 this.clear = function(details, callback) { |
| 50 var clearSchema = getFunctionParameters('clear'); | 77 var clearSchema = getFunctionParameters('clear'); |
| 51 validate([details, callback], clearSchema); | 78 validate([details, callback], clearSchema); |
| 79 | |
| 80 if (DEPRECATED_CONTENT_TYPES.hasOwnProperty(contentType)) { | |
| 81 console.warn('contentSettings.' + contentType + ' is deprecated; ' | |
| 82 + 'clearing it has no effect.'); | |
| 83 $Function.apply(callback, undefined, []); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 52 return sendRequest('contentSettings.clear', | 87 return sendRequest('contentSettings.clear', |
| 53 [contentType, details, callback], | 88 [contentType, details, callback], |
| 54 extendSchema(clearSchema)); | 89 extendSchema(clearSchema)); |
| 55 }; | 90 }; |
| 91 | |
| 56 this.getResourceIdentifiers = function(callback) { | 92 this.getResourceIdentifiers = function(callback) { |
| 57 var schema = getFunctionParameters('getResourceIdentifiers'); | 93 var schema = getFunctionParameters('getResourceIdentifiers'); |
| 58 validate([callback], schema); | 94 validate([callback], schema); |
| 95 | |
| 96 if (DEPRECATED_CONTENT_TYPES.hasOwnProperty(contentType)) { | |
| 97 $Function.apply(callback, undefined, []); | |
| 98 return; | |
| 99 } | |
| 100 | |
| 59 return sendRequest( | 101 return sendRequest( |
| 60 'contentSettings.getResourceIdentifiers', | 102 'contentSettings.getResourceIdentifiers', |
| 61 [contentType, callback], | 103 [contentType, callback], |
| 62 extendSchema(schema)); | 104 extendSchema(schema)); |
| 63 }; | 105 }; |
| 64 } | 106 } |
| 65 | 107 |
| 66 exports.$set('ContentSetting', ContentSetting); | 108 exports.$set('ContentSetting', ContentSetting); |
| OLD | NEW |