| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Converts the representation of the preference as stored in the browser | 159 // Converts the representation of the preference as stored in the browser |
| 160 // into a representation that is used by the extension. | 160 // into a representation that is used by the extension. |
| 161 // Returns the extension representation in case of success or NULL otherwise. | 161 // Returns the extension representation in case of success or NULL otherwise. |
| 162 // The ownership of the returned value is passed to the caller. | 162 // The ownership of the returned value is passed to the caller. |
| 163 virtual base::Value* BrowserToExtensionPref( | 163 virtual base::Value* BrowserToExtensionPref( |
| 164 const base::Value* browser_pref) = 0; | 164 const base::Value* browser_pref) = 0; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 // A base class to provide functionality common to the other *PreferenceFunction | 167 // A base class to provide functionality common to the other *PreferenceFunction |
| 168 // classes. | 168 // classes. |
| 169 class PreferenceFunction : public ChromeSyncExtensionFunction { | 169 class PreferenceFunction : public UIThreadExtensionFunction { |
| 170 protected: | 170 protected: |
| 171 enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE }; | 171 enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE }; |
| 172 | 172 |
| 173 ~PreferenceFunction() override; | 173 ~PreferenceFunction() override; |
| 174 | |
| 175 // Given an |extension_pref_key|, provides its |browser_pref_key| from the | |
| 176 // static map in preference_api.cc. Returns true if the corresponding | |
| 177 // browser pref exists and the extension has the API permission needed to | |
| 178 // modify that pref. Sets |error_| if the extension doesn't have the needed | |
| 179 // permission. | |
| 180 bool ValidateBrowserPref(const std::string& extension_pref_key, | |
| 181 PermissionType permission_type, | |
| 182 std::string* browser_pref_key); | |
| 183 }; | 174 }; |
| 184 | 175 |
| 185 class GetPreferenceFunction : public PreferenceFunction { | 176 class GetPreferenceFunction : public PreferenceFunction { |
| 186 public: | 177 public: |
| 187 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.get", TYPES_CHROMESETTING_GET) | 178 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.get", TYPES_CHROMESETTING_GET) |
| 188 | 179 |
| 189 protected: | 180 protected: |
| 190 ~GetPreferenceFunction() override; | 181 ~GetPreferenceFunction() override; |
| 191 | 182 |
| 192 // ExtensionFunction: | 183 // ExtensionFunction: |
| 193 bool RunSync() override; | 184 ResponseAction Run() override; |
| 194 }; | 185 }; |
| 195 | 186 |
| 196 class SetPreferenceFunction : public PreferenceFunction { | 187 class SetPreferenceFunction : public PreferenceFunction { |
| 197 public: | 188 public: |
| 198 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.set", TYPES_CHROMESETTING_SET) | 189 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.set", TYPES_CHROMESETTING_SET) |
| 199 | 190 |
| 200 protected: | 191 protected: |
| 201 ~SetPreferenceFunction() override; | 192 ~SetPreferenceFunction() override; |
| 202 | 193 |
| 203 // ExtensionFunction: | 194 // ExtensionFunction: |
| 204 bool RunSync() override; | 195 ResponseAction Run() override; |
| 205 }; | 196 }; |
| 206 | 197 |
| 207 class ClearPreferenceFunction : public PreferenceFunction { | 198 class ClearPreferenceFunction : public PreferenceFunction { |
| 208 public: | 199 public: |
| 209 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.clear", | 200 DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.clear", |
| 210 TYPES_CHROMESETTING_CLEAR) | 201 TYPES_CHROMESETTING_CLEAR) |
| 211 | 202 |
| 212 protected: | 203 protected: |
| 213 ~ClearPreferenceFunction() override; | 204 ~ClearPreferenceFunction() override; |
| 214 | 205 |
| 215 // ExtensionFunction: | 206 // ExtensionFunction: |
| 216 bool RunSync() override; | 207 ResponseAction Run() override; |
| 217 }; | 208 }; |
| 218 | 209 |
| 219 } // namespace extensions | 210 } // namespace extensions |
| 220 | 211 |
| 221 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 212 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
| OLD | NEW |