| 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 #include "chrome/browser/extensions/extension_preference_api.h" | 5 #include "chrome/browser/extensions/api/preference/preference_api.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" |
| 15 #include "chrome/browser/extensions/api/preference/preference_helpers.h" |
| 14 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | 16 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
| 15 #include "chrome/browser/extensions/extension_preference_api_constants.h" | |
| 16 #include "chrome/browser/extensions/extension_preference_helpers.h" | |
| 17 #include "chrome/browser/extensions/extension_prefs.h" | 17 #include "chrome/browser/extensions/extension_prefs.h" |
| 18 #include "chrome/browser/extensions/extension_prefs_scope.h" | 18 #include "chrome/browser/extensions/extension_prefs_scope.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/extensions/extension_error_utils.h" | 23 #include "chrome/common/extensions/extension_error_utils.h" |
| 24 #include "chrome/common/extensions/permissions/api_permission.h" | 24 #include "chrome/common/extensions/permissions/api_permission.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 28 | 28 |
| 29 namespace keys = extension_preference_api_constants; | 29 namespace keys = extensions::preference_api_constants; |
| 30 namespace helpers = extension_preference_helpers; | 30 namespace helpers = extensions::preference_helpers; |
| 31 | 31 |
| 32 using extensions::APIPermission; | 32 namespace extensions { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 struct PrefMappingEntry { | 36 struct PrefMappingEntry { |
| 37 // Name of the preference referenced by the extension API JSON. | 37 // Name of the preference referenced by the extension API JSON. |
| 38 const char* extension_pref; | 38 const char* extension_pref; |
| 39 | 39 |
| 40 // Name of the preference in the PrefStores. | 40 // Name of the preference in the PrefStores. |
| 41 const char* browser_pref; | 41 const char* browser_pref; |
| 42 | 42 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Mapping from browser pref keys to transformers. | 231 // Mapping from browser pref keys to transformers. |
| 232 std::map<std::string, PrefTransformerInterface*> transformers_; | 232 std::map<std::string, PrefTransformerInterface*> transformers_; |
| 233 | 233 |
| 234 scoped_ptr<PrefTransformerInterface> identity_transformer_; | 234 scoped_ptr<PrefTransformerInterface> identity_transformer_; |
| 235 | 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(PrefMapping); | 236 DISALLOW_COPY_AND_ASSIGN(PrefMapping); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 } // namespace | 239 } // namespace |
| 240 | 240 |
| 241 ExtensionPreferenceEventRouter::ExtensionPreferenceEventRouter( | 241 PreferenceEventRouter::PreferenceEventRouter(Profile* profile) |
| 242 Profile* profile) : profile_(profile) { | 242 : profile_(profile) { |
| 243 registrar_.Init(profile_->GetPrefs()); | 243 registrar_.Init(profile_->GetPrefs()); |
| 244 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs()); | 244 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs()); |
| 245 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { | 245 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { |
| 246 registrar_.Add(kPrefMapping[i].browser_pref, this); | 246 registrar_.Add(kPrefMapping[i].browser_pref, this); |
| 247 incognito_registrar_.Add(kPrefMapping[i].browser_pref, this); | 247 incognito_registrar_.Add(kPrefMapping[i].browser_pref, this); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 ExtensionPreferenceEventRouter::~ExtensionPreferenceEventRouter() { } | 251 PreferenceEventRouter::~PreferenceEventRouter() { } |
| 252 | 252 |
| 253 void ExtensionPreferenceEventRouter::Observe( | 253 void PreferenceEventRouter::Observe( |
| 254 int type, | 254 int type, |
| 255 const content::NotificationSource& source, | 255 const content::NotificationSource& source, |
| 256 const content::NotificationDetails& details) { | 256 const content::NotificationDetails& details) { |
| 257 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 257 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 258 const std::string* pref_key = | 258 const std::string* pref_key = |
| 259 content::Details<const std::string>(details).ptr(); | 259 content::Details<const std::string>(details).ptr(); |
| 260 OnPrefChanged(content::Source<PrefService>(source).ptr(), *pref_key); | 260 OnPrefChanged(content::Source<PrefService>(source).ptr(), *pref_key); |
| 261 } else { | 261 } else { |
| 262 NOTREACHED(); | 262 NOTREACHED(); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 | 265 |
| 266 void ExtensionPreferenceEventRouter::OnPrefChanged( | 266 void PreferenceEventRouter::OnPrefChanged(PrefService* pref_service, |
| 267 PrefService* pref_service, | 267 const std::string& browser_pref) { |
| 268 const std::string& browser_pref) { | |
| 269 bool incognito = (pref_service != profile_->GetPrefs()); | 268 bool incognito = (pref_service != profile_->GetPrefs()); |
| 270 | 269 |
| 271 std::string event_name; | 270 std::string event_name; |
| 272 APIPermission::ID permission = APIPermission::kInvalid; | 271 APIPermission::ID permission = APIPermission::kInvalid; |
| 273 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( | 272 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( |
| 274 browser_pref, &event_name, &permission); | 273 browser_pref, &event_name, &permission); |
| 275 DCHECK(rv); | 274 DCHECK(rv); |
| 276 | 275 |
| 277 ListValue args; | 276 ListValue args; |
| 278 DictionaryValue* dict = new DictionaryValue(); | 277 DictionaryValue* dict = new DictionaryValue(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 483 |
| 485 std::string browser_pref; | 484 std::string browser_pref; |
| 486 if (!ValidateBrowserPref(pref_key, &browser_pref)) | 485 if (!ValidateBrowserPref(pref_key, &browser_pref)) |
| 487 return false; | 486 return false; |
| 488 | 487 |
| 489 extensions::ExtensionPrefs* prefs = | 488 extensions::ExtensionPrefs* prefs = |
| 490 profile_->GetExtensionService()->extension_prefs(); | 489 profile_->GetExtensionService()->extension_prefs(); |
| 491 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); | 490 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); |
| 492 return true; | 491 return true; |
| 493 } | 492 } |
| 493 |
| 494 } // namespace extensions |
| OLD | NEW |