Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" | |
| 6 | |
| 7 #include "base/prefs/pref_service.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 | |
| 12 namespace extensions { | |
| 13 namespace chromedirectsetting { | |
| 14 | |
| 15 void DirectSettingFunctionBase::CheckCalledFromComponentExtension() { | |
| 16 bool isComponentExtension = | |
| 17 (GetExtension()->location() == Manifest::COMPONENT); | |
| 18 | |
| 19 // If we've made it this far and the caller isn't a component extension, | |
| 20 // this means the API permissions system has failed. | |
|
Bernhard Bauer
2013/07/09 07:34:32
Is the API permissions system enforced on the brow
robliao
2013/07/09 17:27:45
The renderer performs the API check, so compromise
| |
| 21 // Fatal check to prevent any damage from being done. | |
| 22 CHECK(isComponentExtension); | |
| 23 } | |
| 24 | |
| 25 PrefService* DirectSettingFunctionBase::GetPrefService() { | |
| 26 return profile()->GetPrefs(); | |
| 27 } | |
| 28 | |
| 29 bool GetDirectSettingFunction::RunImpl() { | |
| 30 CheckCalledFromComponentExtension(); | |
| 31 | |
| 32 std::string pref_key; | |
| 33 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | |
| 34 | |
| 35 const PrefService::Preference* preference = | |
| 36 GetPrefService()->FindPreference(pref_key.c_str()); | |
|
Bernhard Bauer
2013/07/09 17:58:27
I'm also worried about directly using the passed i
robliao
2013/07/09 18:15:53
Isn't the JSON API declaration sufficient for limi
Bernhard Bauer
2013/07/09 18:45:41
Sorry, no :-(
The JSON API here is really just us
robliao
2013/07/09 18:53:38
I'm going to think about the best way for getting
| |
| 37 const base::Value* value = preference->GetValue(); | |
|
Bernhard Bauer
2013/07/09 07:34:32
This will crash if the pref_key isn't found. Can y
robliao
2013/07/09 17:27:45
This was a deliberate decision for the following r
Bernhard Bauer
2013/07/09 17:58:27
The preference API checks with a EXTENSION_FUNCTIO
robliao
2013/07/09 18:15:53
Take a look at
https://code.google.com/p/chromium/
Bernhard Bauer
2013/07/09 18:45:41
Thanks!
This API function won't touch ExtensionPr
robliao
2013/07/09 18:53:38
That's correct. Part of the impetus of this change
| |
| 38 | |
| 39 scoped_ptr<DictionaryValue> result(new DictionaryValue); | |
| 40 result->Set(preference_api_constants::kValue, value->DeepCopy()); | |
| 41 SetResult(result.release()); | |
| 42 | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 bool SetDirectSettingFunction::RunImpl() { | |
| 47 CheckCalledFromComponentExtension(); | |
| 48 | |
| 49 std::string pref_key; | |
| 50 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | |
| 51 | |
| 52 DictionaryValue* details = NULL; | |
| 53 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | |
| 54 | |
| 55 Value* value = NULL; | |
| 56 EXTENSION_FUNCTION_VALIDATE( | |
| 57 details->Get(preference_api_constants::kValue, &value)); | |
| 58 | |
| 59 PrefService* prefService = GetPrefService(); | |
|
Bernhard Bauer
2013/07/09 07:34:32
Local variables are named unix_hacker_style.
robliao
2013/07/09 17:27:45
Habits from a previous life. Fixed.
On 2013/07/09
| |
| 60 const PrefService::Preference* preference = | |
| 61 prefService->FindPreference(pref_key.c_str()); | |
| 62 | |
| 63 EXTENSION_FUNCTION_VALIDATE(value->GetType() == preference->GetType()); | |
| 64 | |
| 65 prefService->Set(pref_key.c_str(), *value); | |
| 66 | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 bool ClearDirectSettingFunction::RunImpl() { | |
| 71 CheckCalledFromComponentExtension(); | |
| 72 | |
| 73 std::string pref_key; | |
| 74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | |
| 75 GetPrefService()->ClearPref(pref_key.c_str()); | |
| 76 | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 } // namespace chromedirectsetting | |
| 81 } // namespace extensions | |
| 82 | |
| OLD | NEW |