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

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

Issue 2903803004: [Extensions Bindings] Fix content settings validation (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/content_settings/standard/test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Some content types have been removed and no longer correspond to a real 10 // Some content types have been removed and no longer correspond to a real
(...skipping 29 matching lines...) Expand all
40 $Function.apply(callback, undefined, [{setting: dummySetting}]); 40 $Function.apply(callback, undefined, [{setting: dummySetting}]);
41 return; 41 return;
42 } 42 }
43 43
44 return sendRequest('contentSettings.get', 44 return sendRequest('contentSettings.get',
45 [contentType, details, callback], 45 [contentType, details, callback],
46 extendSchema(getSchema)); 46 extendSchema(getSchema));
47 }; 47 };
48 48
49 this.set = function(details, callback) { 49 this.set = function(details, callback) {
50 // We check if the setting is deprecated first, since the validation will
51 // fail for deprecated types.
52 if ($Object.hasOwnProperty(DEPRECATED_CONTENT_TYPES, contentType)) {
53 console.warn('contentSettings.' + contentType + ' is deprecated; setting '
54 + 'it has no effect.');
55 $Function.apply(callback, undefined, []);
56 return;
57 }
58
50 // The set schema included in the Schema object is generic, since it varies 59 // The set schema included in the Schema object is generic, since it varies
51 // per-setting. However, this is only ever for a single setting, so we can 60 // per-setting. However, this is only ever for a single setting, so we can
52 // enforce the types more thoroughly. 61 // enforce the types more thoroughly.
53 var rawSetSchema = getFunctionParameters('set'); 62 var rawSetSchema = getFunctionParameters('set');
54 var rawSettingParam = rawSetSchema[0]; 63 var rawSettingParam = rawSetSchema[0];
55 var props = $Object.assign({}, rawSettingParam.properties); 64 var props = $Object.assign({}, rawSettingParam.properties);
56 props.setting = settingSchema; 65 props.setting = settingSchema;
57 var modSettingParam = { 66 var modSettingParam = {
58 name: rawSettingParam.name, 67 name: rawSettingParam.name,
59 type: rawSettingParam.type, 68 type: rawSettingParam.type,
60 properties: props, 69 properties: props,
61 }; 70 };
62 var modSetSchema = $Array.slice(rawSetSchema); 71 var modSetSchema = $Array.slice(rawSetSchema);
63 modSetSchema[0] = modSettingParam; 72 modSetSchema[0] = modSettingParam;
64 validate([details, callback], rawSetSchema); 73 validate([details, callback], modSetSchema);
Devlin 2017/05/26 01:36:01 This was validating only against the raw schema, w
65
66 if ($Object.hasOwnProperty(DEPRECATED_CONTENT_TYPES, contentType)) {
67 console.warn('contentSettings.' + contentType + ' is deprecated; setting '
68 + 'it has no effect.');
69 $Function.apply(callback, undefined, []);
70 return;
71 }
72 74
73 return sendRequest('contentSettings.set', 75 return sendRequest('contentSettings.set',
74 [contentType, details, callback], 76 [contentType, details, callback],
75 extendSchema(modSetSchema)); 77 extendSchema(modSetSchema));
76 }; 78 };
77 79
78 this.clear = function(details, callback) { 80 this.clear = function(details, callback) {
79 var clearSchema = getFunctionParameters('clear'); 81 var clearSchema = getFunctionParameters('clear');
80 validate([details, callback], clearSchema); 82 validate([details, callback], clearSchema);
81 83
(...skipping 19 matching lines...) Expand all
101 } 103 }
102 104
103 return sendRequest( 105 return sendRequest(
104 'contentSettings.getResourceIdentifiers', 106 'contentSettings.getResourceIdentifiers',
105 [contentType, callback], 107 [contentType, callback],
106 extendSchema(schema)); 108 extendSchema(schema));
107 }; 109 };
108 } 110 }
109 111
110 exports.$set('ContentSetting', ContentSetting); 112 exports.$set('ContentSetting', ContentSetting);
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/content_settings/standard/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698