| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_preference_api.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 const char kNotControllable[] = "NotControllable"; | 31 const char kNotControllable[] = "NotControllable"; |
| 32 const char kControlledByOtherExtensions[] = "ControlledByOtherExtensions"; | 32 const char kControlledByOtherExtensions[] = "ControlledByOtherExtensions"; |
| 33 const char kControllableByThisExtension[] = "ControllableByThisExtension"; | 33 const char kControllableByThisExtension[] = "ControllableByThisExtension"; |
| 34 const char kControlledByThisExtension[] = "ControlledByThisExtension"; | 34 const char kControlledByThisExtension[] = "ControlledByThisExtension"; |
| 35 | 35 |
| 36 const char kIncognito[] = "incognito"; | 36 const char kIncognito[] = "incognito"; |
| 37 const char kIncognitoSpecific[] = "incognitoSpecific"; | 37 const char kIncognitoSpecific[] = "incognitoSpecific"; |
| 38 const char kLevelOfControl[] = "levelOfControl"; | 38 const char kLevelOfControl[] = "levelOfControl"; |
| 39 const char kValue[] = "value"; | 39 const char kValue[] = "value"; |
| 40 | 40 |
| 41 const char kOnPrefChangeFormat[] = "experimental.preferences.%s.onChange"; | 41 const char kOnPrefChangeFormat[] = |
| 42 "experimental.preferences.%s.onChange"; |
| 42 | 43 |
| 43 const char kIncognitoErrorMessage[] = | 44 const char kIncognitoErrorMessage[] = |
| 44 "You do not have permission to access incognito preferences."; | 45 "You do not have permission to access incognito preferences."; |
| 45 | 46 |
| 46 const char kPermissionErrorMessage[] = | 47 const char kPermissionErrorMessage[] = |
| 47 "You do not have permission to access the preference '%s'. " | 48 "You do not have permission to access the preference '%s'. " |
| 48 "Be sure to declare in your manifest what permissions you need."; | 49 "Be sure to declare in your manifest what permissions you need."; |
| 49 | 50 |
| 50 PrefMappingEntry kPrefMapping[] = { | 51 PrefMappingEntry kPrefMapping[] = { |
| 51 { "blockThirdPartyCookies", | 52 { "blockThirdPartyCookies", |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 bool SetPreferenceFunction::RunImpl() { | 340 bool SetPreferenceFunction::RunImpl() { |
| 340 std::string pref_key; | 341 std::string pref_key; |
| 341 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | 342 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); |
| 342 DictionaryValue* details = NULL; | 343 DictionaryValue* details = NULL; |
| 343 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | 344 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
| 344 | 345 |
| 345 Value* value = NULL; | 346 Value* value = NULL; |
| 346 EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value)); | 347 EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value)); |
| 347 | 348 |
| 348 bool incognito = false; | 349 bool incognito = false; |
| 349 if (details->HasKey(kIncognito)) | 350 |
| 350 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); | 351 // TODO(battre): enable incognito preferences again. |
| 352 // if (details->HasKey(kIncognito)) |
| 353 // EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); |
| 351 | 354 |
| 352 if (incognito && !include_incognito()) { | 355 if (incognito && !include_incognito()) { |
| 353 error_ = kIncognitoErrorMessage; | 356 error_ = kIncognitoErrorMessage; |
| 354 return false; | 357 return false; |
| 355 } | 358 } |
| 356 | 359 |
| 357 std::string browser_pref; | 360 std::string browser_pref; |
| 358 std::string permission; | 361 std::string permission; |
| 359 EXTENSION_FUNCTION_VALIDATE( | 362 EXTENSION_FUNCTION_VALIDATE( |
| 360 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( | 363 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 388 | 391 |
| 389 ClearPreferenceFunction::~ClearPreferenceFunction() { } | 392 ClearPreferenceFunction::~ClearPreferenceFunction() { } |
| 390 | 393 |
| 391 bool ClearPreferenceFunction::RunImpl() { | 394 bool ClearPreferenceFunction::RunImpl() { |
| 392 std::string pref_key; | 395 std::string pref_key; |
| 393 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | 396 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); |
| 394 DictionaryValue* details = NULL; | 397 DictionaryValue* details = NULL; |
| 395 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | 398 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
| 396 | 399 |
| 397 bool incognito = false; | 400 bool incognito = false; |
| 398 if (details->HasKey(kIncognito)) | 401 |
| 399 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); | 402 // TODO(battre): enable incognito preferences again. |
| 403 // if (details->HasKey(kIncognito)) |
| 404 // EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); |
| 400 | 405 |
| 401 // We don't check incognito permissions here, as an extension should be always | 406 // We don't check incognito permissions here, as an extension should be always |
| 402 // allowed to clear its own settings. | 407 // allowed to clear its own settings. |
| 403 | 408 |
| 404 std::string browser_pref; | 409 std::string browser_pref; |
| 405 std::string permission; | 410 std::string permission; |
| 406 EXTENSION_FUNCTION_VALIDATE( | 411 EXTENSION_FUNCTION_VALIDATE( |
| 407 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( | 412 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( |
| 408 pref_key, &browser_pref, &permission)); | 413 pref_key, &browser_pref, &permission)); |
| 409 if (!GetExtension()->HasApiPermission(permission)) { | 414 if (!GetExtension()->HasApiPermission(permission)) { |
| 410 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); | 415 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); |
| 411 return false; | 416 return false; |
| 412 } | 417 } |
| 413 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); | 418 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); |
| 414 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, incognito); | 419 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, incognito); |
| 415 return true; | 420 return true; |
| 416 } | 421 } |
| OLD | NEW |