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 /** | 5 /** |
6 * @fileoverview Defines a class that provides some convenient wrapper methods | 6 * @fileoverview Defines a class that provides some convenient wrapper methods |
7 * around the Chrome contentSettings extension API. | 7 * around the Chrome contentSettings extension API. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('pluginSettings', function() { | 10 cr.define('pluginSettings', function() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 {}, this.didClearRules_.bind(this, callback)); | 44 {}, this.didClearRules_.bind(this, callback)); |
45 }, | 45 }, |
46 | 46 |
47 /** | 47 /** |
48 * Recreates all content settings from local storage. | 48 * Recreates all content settings from local storage. |
49 * @param {function()} callback Called when the content settings have been | 49 * @param {function()} callback Called when the content settings have been |
50 * recreated, or on error. | 50 * recreated, or on error. |
51 * @private | 51 * @private |
52 */ | 52 */ |
53 didClearRules_: function(callback) { | 53 didClearRules_: function(callback) { |
54 if (chrome.extension.lastError) { | 54 if (chrome.runtime.lastError) { |
55 console.error('Error clearing rules'); | 55 console.error('Error clearing rules'); |
56 callback(); | 56 callback(); |
57 return; | 57 return; |
58 } | 58 } |
59 var length = window.localStorage.length; | 59 var length = window.localStorage.length; |
60 if (length == 0) { | 60 if (length == 0) { |
61 cr.dispatchSimpleEvent(settings, 'change'); | 61 cr.dispatchSimpleEvent(settings, 'change'); |
62 callback(); | 62 callback(); |
63 return; | 63 return; |
64 } | 64 } |
(...skipping 23 matching lines...) Expand all Loading... |
88 * @param {string} key The local storage key under which the content | 88 * @param {string} key The local storage key under which the content |
89 * setting was stored. | 89 * setting was stored. |
90 * @param {string} value The content setting value in local storage. | 90 * @param {string} value The content setting value in local storage. |
91 * @param {{value:number}} counter Contains the number of callbacks still | 91 * @param {{value:number}} counter Contains the number of callbacks still |
92 * outstanding. | 92 * outstanding. |
93 * @param {function()} callback Called when the content settings have been | 93 * @param {function()} callback Called when the content settings have been |
94 * recreated, or on error. | 94 * recreated, or on error. |
95 * @private | 95 * @private |
96 */ | 96 */ |
97 didSetContentSetting_: function(plugin, pattern, key, counter, callback) { | 97 didSetContentSetting_: function(plugin, pattern, key, counter, callback) { |
98 if (chrome.extension.lastError) { | 98 if (chrome.runtime.lastError) { |
99 console.error( | 99 console.error( |
100 'Error restoring [' + key + ': ' + value + ']: ' + | 100 'Error restoring [' + key + ': ' + value + ']: ' + |
101 chrome.extension.lastError.message); | 101 chrome.runtime.lastError.message); |
102 window.localStorage.removeItem(key); | 102 window.localStorage.removeItem(key); |
103 } | 103 } |
104 counter.value--; | 104 counter.value--; |
105 if (counter.value == 0) { | 105 if (counter.value == 0) { |
106 cr.dispatchSimpleEvent(this, 'change'); | 106 cr.dispatchSimpleEvent(this, 'change'); |
107 callback(); | 107 callback(); |
108 } | 108 } |
109 }, | 109 }, |
110 | 110 |
111 /** | 111 /** |
112 * Creates a content setting rule and calls the passed in callback with the | 112 * Creates a content setting rule and calls the passed in callback with the |
113 * result. | 113 * result. |
114 * @param {string} pattern The content setting pattern for the rule. | 114 * @param {string} pattern The content setting pattern for the rule. |
115 * @param {string} setting The setting for the rule. | 115 * @param {string} setting The setting for the rule. |
116 * @param {function(?string)} callback Called when the content settings | 116 * @param {function(?string)} callback Called when the content settings |
117 * have been updated, or on error. | 117 * have been updated, or on error. |
118 */ | 118 */ |
119 set: function(pattern, setting, callback) { | 119 set: function(pattern, setting, callback) { |
120 var plugin = this.plugin_; | 120 var plugin = this.plugin_; |
121 var settings = this; | 121 var settings = this; |
122 chrome.contentSettings.plugins.set({ | 122 chrome.contentSettings.plugins.set({ |
123 'primaryPattern': pattern, | 123 'primaryPattern': pattern, |
124 'resourceIdentifier': { 'id': plugin }, | 124 'resourceIdentifier': { 'id': plugin }, |
125 'setting': setting, | 125 'setting': setting, |
126 }, function() { | 126 }, function() { |
127 if (chrome.extension.lastError) { | 127 if (chrome.runtime.lastError) { |
128 callback(chrome.extension.lastError.message); | 128 callback(chrome.runtime.lastError.message); |
129 } else { | 129 } else { |
130 window.localStorage.setItem(JSON.stringify([plugin, pattern]), | 130 window.localStorage.setItem(JSON.stringify([plugin, pattern]), |
131 setting); | 131 setting); |
132 cr.dispatchSimpleEvent(settings, 'change'); | 132 cr.dispatchSimpleEvent(settings, 'change'); |
133 callback(); | 133 callback(); |
134 } | 134 } |
135 }); | 135 }); |
136 }, | 136 }, |
137 | 137 |
138 /** | 138 /** |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 211 } |
212 } | 212 } |
213 return rules; | 213 return rules; |
214 } | 214 } |
215 }; | 215 }; |
216 | 216 |
217 return { | 217 return { |
218 Settings: Settings, | 218 Settings: Settings, |
219 } | 219 } |
220 }); | 220 }); |
OLD | NEW |